add select spec to union list items

This commit is contained in:
Matt Hill
2023-03-27 22:42:38 -06:00
parent 5caa9db886
commit 53ef640ed7
4 changed files with 27 additions and 8 deletions

View File

@@ -5,9 +5,8 @@ import {
InputSpec,
UniqueBy,
ValueSpecList,
ValueSpecListOf,
} from "../config-types";
import { guardAll, typeFromProps } from "../../util";
import { guardAll } from "../../util";
/**
* Used as a subtype of Value.list
@@ -116,6 +115,11 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
default: Record<string, unknown>[];
range: string;
spec: {
select: {
name: string;
description: string | null;
warning: string | null;
}
variants: Variants<{
[key: string]: { name: string; spec: InputSpec };
}>;

View File

@@ -159,17 +159,22 @@ export interface ListValueSpecObject {
export type UniqueBy =
| null
| undefined
| string
| { any: readonly UniqueBy[] | UniqueBy[] }
| { all: readonly UniqueBy[] | UniqueBy[] };
export interface ListValueSpecUnion {
select: {
name: string
description: null | string
warning: null | string
}
variants: { [key: string]: { name: string; spec: InputSpec } };
/** this may be a handlebars template which can conditionally (on tag.id) make use of each union's entries, or if left blank will display as tag.id*/
/** a handlebars template for labeling each union list item */
displayAs: null | string;
/** indicates whether duplicates can be permitted in the list */
uniqueBy: UniqueBy;
/** this should be the variantName which one prefers a user to start with by default when creating a new union instance in a list*/
/** the default variant when creating a new union instance in the list*/
default: null | string;
}

View File

@@ -103,7 +103,6 @@ const matchVariant = object({
const recordString = dictionary([string, unknown]);
const matchDefault = object({ default: unknown });
const matchNullable = object({ nullable: literals(true) });
const matchPattern = object({ pattern: string });
const rangeRegex = /(\[|\()(\*|(\d|\.)+),(\*|(\d|\.)+)(\]|\))/;
const matchRange = object({ range: string });
const matchIntegral = object({ integral: literals(true) });

View File

@@ -253,6 +253,17 @@ export default async function makeFileContent(
name:${JSON.stringify(value.name || null)},
range:${JSON.stringify(value.range || null)},
spec: {
select: {
"name": ${JSON.stringify(
value?.spec?.tag?.["name"] || null
)},
"description": ${JSON.stringify(
value?.spec?.tag?.["description"] || null
)},
"warning": ${JSON.stringify(
value?.spec?.tag?.["warning"] || null
)},
},
variants: ${variants},
displayAs: ${JSON.stringify(
value?.spec?.["display-as"] || null