diff --git a/ui/presets-page.ts b/ui/presets-page.ts index e81b3e1..d185bf3 100644 --- a/ui/presets-page.ts +++ b/ui/presets-page.ts @@ -212,30 +212,30 @@ export const component: ClosureComponent = (): Component => { const count = store.count("presets", filter); const userDefinedProvisions: Set = new Set(); + + const provisionIds = new Set([ + "refresh", + "value", + "tag", + "reboot", + "reset", + "download", + "instances" + ]); + const provisions = store.fetch("provisions", true); if (provisions.fulfilled) { - const provisionAttr = attributes.find(attr => { - return attr.id === "provision"; - }); - - const provisionIds = new Set([ - "refresh", - "value", - "tag", - "reboot", - "reset", - "download", - "instances" - ]); - for (const p of provisions.value) { userDefinedProvisions.add(p["_id"]); provisionIds.add(p["_id"]); } - - provisionAttr["options"] = Array.from(provisionIds); } + const provisionAttr = attributes.find(attr => { + return attr.id === "provision"; + }); + provisionAttr["options"] = Array.from(provisionIds); + const downloadUrl = getDownloadUrl(filter); const valueCallback = (attr, preset): {} => { diff --git a/ui/put-form-component.ts b/ui/put-form-component.ts index 9cf2c51..f16ef5b 100644 --- a/ui/put-form-component.ts +++ b/ui/put-form-component.ts @@ -32,12 +32,18 @@ const singular = { function createField(current, attr, focus): Children { if (attr.type === "combo") { - const options = [m("option", { value: "" }, "--Please choose--")]; - for (const op of attr.options) options.push(m("option", { value: op }, op)); - let selected = ""; - if (attr.options.includes(current.object[attr.id])) + let optionsValues = attr.options; + if (current.object[attr.id] != null) { + if (!optionsValues.includes(current.object[attr.id])) + optionsValues = optionsValues.concat([current.object[attr.id]]); selected = current.object[attr.id]; + } + + const options = [m("option", { value: "" }, "")]; + for (const op of optionsValues) + options.push(m("option", { value: op }, op)); + return m( "select", { @@ -56,8 +62,11 @@ function createField(current, attr, focus): Children { options ); } else if (attr.type === "multi") { + const optionsValues = Array.from( + new Set(attr.options.concat(current.object[attr.id] || [])) + ); const currentSelected = new Set(current.object[attr.id]); - const options = attr.options.map(op => { + const options = optionsValues.map(op => { const id = `${attr.id}-${op}`; const opts = { type: "checkbox",