remove subtype from list spec

This commit is contained in:
Matt Hill
2023-04-03 14:16:41 -06:00
committed by Aiden McClelland
parent e4cd4d64d7
commit bb50beb7ab
8 changed files with 30 additions and 33 deletions

View File

@@ -49,7 +49,7 @@
"patch-db-client": "file: ../../../patch-db/client", "patch-db-client": "file: ../../../patch-db/client",
"pbkdf2": "^3.1.2", "pbkdf2": "^3.1.2",
"rxjs": "^7.5.6", "rxjs": "^7.5.6",
"start-sdk": "^0.4.0-lib0.beta6", "start-sdk": "^0.4.0-lib0.beta9",
"swiper": "^8.2.4", "swiper": "^8.2.4",
"ts-matches": "^5.2.1", "ts-matches": "^5.2.1",
"tslib": "^2.3.0", "tslib": "^2.3.0",
@@ -13771,9 +13771,9 @@
} }
}, },
"node_modules/start-sdk": { "node_modules/start-sdk": {
"version": "0.4.0-lib0.beta6", "version": "0.4.0-lib0.beta9",
"resolved": "https://registry.npmjs.org/start-sdk/-/start-sdk-0.4.0-lib0.beta6.tgz", "resolved": "https://registry.npmjs.org/start-sdk/-/start-sdk-0.4.0-lib0.beta9.tgz",
"integrity": "sha512-9dR2noD/rJ4u/Xuhs5S0+lv95nqpERWzxbXlpXDbtjXzMKzX8v1zmKKMNfTir1oxaZC820llLlaCeuPG2VGNpg==", "integrity": "sha512-gTpvFG9HARW1XlljA3It+L1NdNEp8OZrTJjc9vTJpgKn14U9HCYI/+XZC+UzGvP2AJpfR+1bBKSv2UAfElfw9A==",
"dependencies": { "dependencies": {
"@iarna/toml": "^2.2.5", "@iarna/toml": "^2.2.5",
"lodash": "^4.17.21", "lodash": "^4.17.21",

View File

@@ -74,7 +74,7 @@
"patch-db-client": "file: ../../../patch-db/client", "patch-db-client": "file: ../../../patch-db/client",
"pbkdf2": "^3.1.2", "pbkdf2": "^3.1.2",
"rxjs": "^7.5.6", "rxjs": "^7.5.6",
"start-sdk": "^0.4.0-lib0.beta6", "start-sdk": "^0.4.0-lib0.beta9",
"swiper": "^8.2.4", "swiper": "^8.2.4",
"ts-matches": "^5.2.1", "ts-matches": "^5.2.1",
"tslib": "^2.3.0", "tslib": "^2.3.0",

View File

@@ -26,7 +26,7 @@
[class.input_redacted]=" [class.input_redacted]="
spec.type === 'string' && control.value && spec.masked && !unmasked spec.type === 'string' && control.value && spec.masked && !unmasked
" "
[inputmode]="spec.type === 'number' ? 'tel' : 'text'" [inputmode]="spec.type === 'string' ? spec.inputmode : 'tel'"
[placeholder]="spec.placeholder" [placeholder]="spec.placeholder"
[formControl]="control" [formControl]="control"
(ionFocus)="warning.onChange(name, spec)" (ionFocus)="warning.onChange(name, spec)"

View File

@@ -95,7 +95,7 @@
" "
> >
<!-- object --> <!-- object -->
<ng-container *ngIf="spec.subtype === 'object'"> <ng-container *ngIf="spec.spec.type === 'object'">
<!-- object label --> <!-- object label -->
<ion-item <ion-item
button button
@@ -130,7 +130,7 @@
[id]="objectId | toElementId : entry.key : i" [id]="objectId | toElementId : entry.key : i"
> >
<form-object <form-object
*ngIf="spec.subtype === 'object'" *ngIf="spec.spec.type === 'object'"
[objectSpec]="$any(spec.spec).spec" [objectSpec]="$any(spec.spec).spec"
[formGroup]="abstractControl" [formGroup]="abstractControl"
[current]="current?.[entry.key]?.[i]" [current]="current?.[entry.key]?.[i]"
@@ -153,7 +153,9 @@
</ng-container> </ng-container>
<!-- string or number --> <!-- string or number -->
<div <div
*ngIf="spec.subtype === 'string' || spec.subtype === 'number'" *ngIf="
spec.spec.type === 'string' || spec.spec.type === 'number'
"
[id]="objectId | toElementId : entry.key : i" [id]="objectId | toElementId : entry.key : i"
> >
<ion-item <ion-item
@@ -161,7 +163,9 @@
> >
<ion-input <ion-input
type="text" type="text"
[inputmode]="spec.subtype === 'number' ? 'tel' : 'text'" [inputmode]="
spec.spec.type === 'string' ? spec.spec.inputmode : 'tel'
"
[placeholder]=" [placeholder]="
$any(spec.spec).placeholder || 'Enter ' + spec.name $any(spec.spec).placeholder || 'Enter ' + spec.name
" "

View File

@@ -82,7 +82,7 @@ export class FormObjectComponent {
Object.keys(this.objectSpec).forEach(key => { Object.keys(this.objectSpec).forEach(key => {
const spec = this.objectSpec[key] const spec = this.objectSpec[key]
if (spec.type === 'list' && ['object', 'union'].includes(spec.subtype)) { if (spec.type === 'list' && spec.spec.type === 'object') {
this.objectListDisplay[key] = [] this.objectListDisplay[key] = []
this.formGroup.get(key)?.value.forEach((obj: any, index: number) => { this.formGroup.get(key)?.value.forEach((obj: any, index: number) => {
const displayAs = (spec.spec as ListValueSpecOf<'object'>).displayAs const displayAs = (spec.spec as ListValueSpecOf<'object'>).displayAs
@@ -209,8 +209,8 @@ export class FormObjectComponent {
const index = arr.length const index = arr.length
arr.insert(index, newItem) arr.insert(index, newItem)
if (['object', 'union'].includes(listSpec.subtype)) { if (listSpec.spec.type === 'object') {
const displayAs = (listSpec.spec as ListValueSpecOf<'object'>).displayAs const displayAs = listSpec.spec.displayAs
this.objectListDisplay[key].push({ this.objectListDisplay[key].push({
expanded: false, expanded: false,
displayAs: displayAs ? Mustache.render(displayAs, newItem.value) : '', displayAs: displayAs ? Mustache.render(displayAs, newItem.value) : '',
@@ -223,7 +223,7 @@ export class FormObjectComponent {
) )
element?.parentElement?.scrollIntoView({ behavior: 'smooth' }) element?.parentElement?.scrollIntoView({ behavior: 'smooth' })
if (['object', 'union'].includes(listSpec.subtype)) { if (listSpec.spec.type === 'object') {
pauseFor(250).then(() => this.toggleExpandListObject(key, index)) pauseFor(250).then(() => this.toggleExpandListObject(key, index))
} }
}, 100) }, 100)

View File

@@ -235,7 +235,6 @@ const SAMPLE_CONFIG: InputSpec = {
'sample-number': { 'sample-number': {
type: 'number', type: 'number',
name: 'Example Number Input', name: 'Example Number Input',
inputmode: 'decimal',
required: true, required: true,
range: '[5,1000000]', range: '[5,1000000]',
integral: true, integral: true,

View File

@@ -746,7 +746,6 @@ export module Mock {
}, },
'p2p-port': { 'p2p-port': {
type: 'number', type: 'number',
inputmode: 'numeric',
name: 'P2P Port', name: 'P2P Port',
description: description:
'The port that your Bitcoin Core P2P server is bound to', 'The port that your Bitcoin Core P2P server is bound to',
@@ -866,7 +865,6 @@ export module Mock {
'object-list': { 'object-list': {
name: 'Object List', name: 'Object List',
type: 'list', type: 'list',
subtype: 'object',
description: 'This is a list of objects, like users or something', description: 'This is a list of objects, like users or something',
warning: null, warning: null,
range: '[0,4]', range: '[0,4]',
@@ -885,6 +883,7 @@ export module Mock {
// the outer spec here, at the list level, says that what's inside (the inner spec) pertains to its inner elements. // the outer spec here, at the list level, says that what's inside (the inner spec) pertains to its inner elements.
// it just so happens that ValueSpecObject's have the field { spec: InputSpec } // it just so happens that ValueSpecObject's have the field { spec: InputSpec }
spec: { spec: {
type: 'object',
uniqueBy: 'last-name', uniqueBy: 'last-name',
displayAs: `I'm {{last-name}}, {{first-name}} {{last-name}}`, displayAs: `I'm {{last-name}}, {{first-name}} {{last-name}}`,
spec: { spec: {
@@ -919,7 +918,6 @@ export module Mock {
}, },
age: { age: {
name: 'Age', name: 'Age',
inputmode: 'numeric',
type: 'number', type: 'number',
description: 'The age of the user', description: 'The age of the user',
required: false, required: false,
@@ -963,7 +961,6 @@ export module Mock {
}, },
'favorite-number': { 'favorite-number': {
name: 'Favorite Number', name: 'Favorite Number',
inputmode: 'decimal',
type: 'number', type: 'number',
integral: false, integral: false,
description: 'Your favorite number of all time', description: 'Your favorite number of all time',
@@ -978,11 +975,10 @@ export module Mock {
'unlucky-numbers': { 'unlucky-numbers': {
name: 'Unlucky Numbers', name: 'Unlucky Numbers',
type: 'list', type: 'list',
subtype: 'number',
description: 'Numbers that you like but are not your top favorite.', description: 'Numbers that you like but are not your top favorite.',
warning: null, warning: null,
spec: { spec: {
inputmode: 'decimal', type: 'number',
integral: false, integral: false,
range: '[-100,200)', range: '[-100,200)',
units: null, units: null,
@@ -1034,12 +1030,12 @@ export module Mock {
rulemakers: { rulemakers: {
name: 'Rule Makers', name: 'Rule Makers',
type: 'list', type: 'list',
subtype: 'object',
description: 'the people who make the rules', description: 'the people who make the rules',
warning: null, warning: null,
range: '[0,2]', range: '[0,2]',
default: [], default: [],
spec: { spec: {
type: 'object',
uniqueBy: null, uniqueBy: null,
displayAs: null, displayAs: null,
spec: { spec: {
@@ -1185,7 +1181,6 @@ export module Mock {
}, },
port: { port: {
name: 'Port', name: 'Port',
inputmode: 'numeric',
type: 'number', type: 'number',
integral: true, integral: true,
description: description:
@@ -1214,7 +1209,6 @@ export module Mock {
rpcallowip: { rpcallowip: {
name: 'RPC Allowed IPs', name: 'RPC Allowed IPs',
type: 'list', type: 'list',
subtype: 'string',
description: description:
'external ip addresses that are authorized to access your Bitcoin node', 'external ip addresses that are authorized to access your Bitcoin node',
warning: warning:
@@ -1222,6 +1216,7 @@ export module Mock {
range: '[1,10]', range: '[1,10]',
default: ['192.168.1.1'], default: ['192.168.1.1'],
spec: { spec: {
type: 'string',
inputmode: 'text', inputmode: 'text',
masked: false, masked: false,
placeholder: null, placeholder: null,
@@ -1233,12 +1228,12 @@ export module Mock {
rpcauth: { rpcauth: {
name: 'RPC Auth', name: 'RPC Auth',
type: 'list', type: 'list',
subtype: 'string',
description: 'api keys that are authorized to access your Bitcoin node.', description: 'api keys that are authorized to access your Bitcoin node.',
warning: null, warning: null,
range: '[0,*)', range: '[0,*)',
default: [], default: [],
spec: { spec: {
type: 'string',
inputmode: 'text', inputmode: 'text',
masked: false, masked: false,
placeholder: null, placeholder: null,
@@ -1307,12 +1302,12 @@ export module Mock {
law3: { law3: {
name: 'Third Law', name: 'Third Law',
type: 'list', type: 'list',
subtype: 'object',
description: 'the third law', description: 'the third law',
warning: null, warning: null,
range: '[0,2]', range: '[0,2]',
default: [], default: [],
spec: { spec: {
type: 'object',
uniqueBy: null, uniqueBy: null,
displayAs: null, displayAs: null,
spec: { spec: {
@@ -1368,12 +1363,12 @@ export module Mock {
rulemakers: { rulemakers: {
name: 'Rule Makers', name: 'Rule Makers',
type: 'list', type: 'list',
subtype: 'object',
description: 'the people who make the rules', description: 'the people who make the rules',
warning: null, warning: null,
range: '[0,2]', range: '[0,2]',
default: [], default: [],
spec: { spec: {
type: 'object',
uniqueBy: null, uniqueBy: null,
displayAs: null, displayAs: null,
spec: { spec: {

View File

@@ -337,13 +337,12 @@ export function listUnique(spec: ValueSpecList): ValidatorFn {
function listItemEquals(spec: ValueSpecList, val1: any, val2: any): boolean { function listItemEquals(spec: ValueSpecList, val1: any, val2: any): boolean {
// TODO: fix types // TODO: fix types
switch (spec.subtype) { switch (spec.spec.type) {
case 'string': case 'string':
case 'number': case 'number':
return val1 == val2 return val1 == val2
case 'object': case 'object':
const obj: ListValueSpecObject = spec.spec as any const obj = spec.spec
return listObjEquals(obj.uniqueBy, obj, val1, val2) return listObjEquals(obj.uniqueBy, obj, val1, val2)
default: default:
return false return false
@@ -553,15 +552,15 @@ export function convertValuesRecursive(
const formArr = group.get(key) as UntypedFormArray const formArr = group.get(key) as UntypedFormArray
const { controls } = formArr const { controls } = formArr
if (valueSpec.subtype === 'number') { if (valueSpec.spec.type === 'number') {
controls.forEach(control => { controls.forEach(control => {
control.setValue(control.value ? Number(control.value) : null) control.setValue(control.value ? Number(control.value) : null)
}) })
} else if (valueSpec.subtype === 'string') { } else if (valueSpec.spec.type === 'string') {
controls.forEach(control => { controls.forEach(control => {
if (!control.value) control.setValue(null) if (!control.value) control.setValue(null)
}) })
} else if (valueSpec.subtype === 'object') { } else if (valueSpec.spec.type === 'object') {
controls.forEach(formGroup => { controls.forEach(formGroup => {
const objectSpec = valueSpec.spec as ListValueSpecObject const objectSpec = valueSpec.spec as ListValueSpecObject
convertValuesRecursive(objectSpec.spec, formGroup as UntypedFormGroup) convertValuesRecursive(objectSpec.spec, formGroup as UntypedFormGroup)