mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
handle case where selected union enum is invalid after migration (#1658)
* handle case where selected union enum is invalid after migration * revert necessary ternary and fix types Co-authored-by: Lucy Cifferello <12953208+elvece@users.noreply.github.com>
This commit is contained in:
@@ -43,7 +43,7 @@ export class FormService {
|
||||
getUnionObject(
|
||||
spec: ValueSpecUnion | ListValueSpecUnion,
|
||||
selection: string,
|
||||
current?: { [key: string]: any },
|
||||
current?: { [key: string]: any } | null,
|
||||
): FormGroup {
|
||||
const { variants, tag } = spec
|
||||
const { name, description, warning } = isFullUnion(spec)
|
||||
@@ -84,7 +84,7 @@ export class FormService {
|
||||
private getFormGroup(
|
||||
config: ConfigSpec,
|
||||
validators: ValidatorFn[] = [],
|
||||
current: { [key: string]: any } = {},
|
||||
current?: { [key: string]: any } | null,
|
||||
): FormGroup {
|
||||
let group: Record<string, FormGroup | FormArray | FormControl> = {}
|
||||
Object.entries(config).map(([key, spec]) => {
|
||||
@@ -128,10 +128,13 @@ export class FormService {
|
||||
})
|
||||
return this.formBuilder.array(mapped, validators)
|
||||
case 'union':
|
||||
const currentSelection = currentValue?.[spec.tag.id]
|
||||
const isValid = !!spec.variants[currentSelection]
|
||||
|
||||
return this.getUnionObject(
|
||||
spec,
|
||||
currentValue?.[spec.tag.id] || spec.default,
|
||||
currentValue,
|
||||
isValid ? currentSelection : spec.default,
|
||||
isValid ? currentValue : undefined,
|
||||
)
|
||||
case 'boolean':
|
||||
case 'enum':
|
||||
|
||||
Reference in New Issue
Block a user