mirror of
https://github.com/jwetzell/showbridge-webui.git
synced 2026-09-10 15:49:26 +00:00
switch defaults between param options
This commit is contained in:
@@ -54,9 +54,9 @@ export class ParamsFormComponent implements OnInit {
|
|||||||
if (this.paramsSchema.properties) {
|
if (this.paramsSchema.properties) {
|
||||||
this.paramsFormInfo = this.schemaService.getFormInfoFromParamsSchema(this.paramsSchema);
|
this.paramsFormInfo = this.schemaService.getFormInfoFromParamsSchema(this.paramsSchema);
|
||||||
} else if (this.paramsSchema.oneOf) {
|
} else if (this.paramsSchema.oneOf) {
|
||||||
this.paramsOptions = this.paramsSchema.oneOf.map((oneOf: any) => {
|
this.paramsOptions = this.paramsSchema.oneOf.map((oneOf: any, index: number) => {
|
||||||
const paramsOption = {
|
const paramsOption = {
|
||||||
display: oneOf.title,
|
display: oneOf.title ? oneOf.title : `Option ${index + 1}`,
|
||||||
schema: oneOf,
|
schema: oneOf,
|
||||||
paramsFormInfo: this.schemaService.getFormInfoFromParamsSchema(oneOf),
|
paramsFormInfo: this.schemaService.getFormInfoFromParamsSchema(oneOf),
|
||||||
};
|
};
|
||||||
@@ -126,11 +126,19 @@ export class ParamsFormComponent implements OnInit {
|
|||||||
this.paramsSchema = paramsOption.schema;
|
this.paramsSchema = paramsOption.schema;
|
||||||
this.paramsFormInfo = paramsOption.paramsFormInfo;
|
this.paramsFormInfo = paramsOption.paramsFormInfo;
|
||||||
|
|
||||||
// NOTE(jwetzell): prune params that MUST change from the data when switch paramOptions
|
// NOTE(jwetzell): modify params that should change from the data when switch paramOptions
|
||||||
Object.entries(this.paramsFormInfo.paramsInfo).forEach(([paramKey, paramInfo]) => {
|
Object.entries(this.paramsFormInfo.paramsInfo).forEach(([paramKey, paramInfo]) => {
|
||||||
if (paramInfo.isConst && this.data) {
|
if (this.data !== undefined) {
|
||||||
if (this.data[paramKey]) {
|
if (paramInfo.isConst) {
|
||||||
delete this.data[paramKey];
|
if (this.data[paramKey]) {
|
||||||
|
delete this.data[paramKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (paramInfo.default) {
|
||||||
|
if (this.data[paramKey] !== undefined && this.data[paramKey] !== paramInfo.default) {
|
||||||
|
this.data[paramKey] = paramInfo.default;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,4 +24,5 @@ export type ParamInfo = {
|
|||||||
options?: string[];
|
options?: string[];
|
||||||
isConst: boolean;
|
isConst: boolean;
|
||||||
schema: any;
|
schema: any;
|
||||||
|
default?: any;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -329,6 +329,7 @@ export class SchemaService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
paramsFormInfo.paramsInfo[paramKey] = {
|
paramsFormInfo.paramsInfo[paramKey] = {
|
||||||
key: paramKey,
|
key: paramKey,
|
||||||
display: paramSchema.title ? paramSchema.title : paramKey,
|
display: paramSchema.title ? paramSchema.title : paramKey,
|
||||||
@@ -337,6 +338,7 @@ export class SchemaService {
|
|||||||
isConst: !!paramSchema.const,
|
isConst: !!paramSchema.const,
|
||||||
schema: paramSchema,
|
schema: paramSchema,
|
||||||
placeholder: '',
|
placeholder: '',
|
||||||
|
default: paramSchema.default ? paramSchema.default : undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
if (paramSchema.examples && paramSchema.examples.length > 0) {
|
if (paramSchema.examples && paramSchema.examples.length > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user