Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/@types/Endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ export type MultiValidationItem = {

export type OptionValues = {
name: string;
values: string[] | { name: string; id: string; [prop: string]: any }[];
config_default: string | { name: string; id: string };
values:
| string[]
| number[]
| { name: string; id: string; [prop: string]: any }[];
config_default: string | number | { name: string; id: string };
};

export type StorageBackend = {
Expand Down
13 changes: 12 additions & 1 deletion src/components/ui/FieldInput/FieldInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,22 @@ class FieldInput extends React.Component<Props> {
return e;
}

if (typeof e === "number") {
return {
label: String(e),
value: e,
disabled: false,
subtitleLabel: "",
};
}
return {
label:
typeof e === "string"
? useDictionary
? LabelDictionary.get(e)
: e
: e.name || e.label,
value: typeof e === "string" ? e : e.id || e.value,
value: typeof e === "string" ? e : (e.id ?? e.value),
disabled: typeof e !== "string" ? Boolean(e.disabled) : false,
subtitleLabel: typeof e !== "string" ? e.subtitleLabel || "" : false,
};
Expand Down Expand Up @@ -441,6 +449,9 @@ class FieldInput extends React.Component<Props> {
}
return this.renderTextInput();
case "integer":
if (this.props.enum && this.props.enum.length) {
return this.renderEnumDropdown(this.props.enum);
}
return this.renderIntInput();
case "radio":
return this.renderRadioInput();
Expand Down
24 changes: 15 additions & 9 deletions src/plugins/default/OptionsSchemaPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

import Utils from "@src/utils/ObjectUtils";

import { Field, isEnumSeparator } from "@src/@types/Field";
import { Field, EnumItem, isEnumSeparator } from "@src/@types/Field";
import type { OptionValues, StorageMap } from "@src/@types/Endpoint";
import type { SchemaProperties, SchemaDefinitions } from "@src/@types/Schema";
import type { NetworkMap } from "@src/@types/Network";
Expand All @@ -27,28 +27,34 @@ const migrationImageOsTypes = ["windows", "linux"];

export const defaultFillFieldValues = (field: Field, option: OptionValues) => {
if (field.type === "string") {
field.enum = [...option.values];
field.enum = [...option.values] as EnumItem[];
if (option.config_default) {
field.default =
typeof option.config_default === "string"
? option.config_default
: option.config_default.id;
: typeof option.config_default === "object"
? option.config_default.id
: String(option.config_default);
}
}
if (field.type === "array") {
field.enum = [...option.values];
field.enum = [...option.values] as EnumItem[];
}
if (field.type === "boolean" && option.config_default != null) {
field.default =
typeof option.config_default === "boolean"
? option.config_default
: option.config_default === "true";
}
if (
(field.type === "integer" || field.type === "number") &&
option.config_default != null
) {
field.default = Number(option.config_default);
if (field.type === "integer" || field.type === "number") {
if (option.values?.length) {
field.enum = option.values.map(v =>
typeof v === "number" ? { label: String(v), value: v } : v,
) as EnumItem[];
}
if (option.config_default != null) {
field.default = Number(option.config_default);
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/stores/WizardStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class WizardStore {
}
return enumItem.id != null
? enumItem.id === fieldDefault || enumItem.name === fieldDefault
: enumItem === fieldDefault;
: enumItem === fieldDefault || enumItem.value === fieldDefault;
});

// Don't use the default if it can't be found in the enum list.
Expand Down
Loading