Prototype crate and order options

Signed-off-by: Egor Savkin <es@m-labs.hk>
This commit is contained in:
Egor Savkin 2024-01-29 17:26:59 +08:00
parent cbe61efc1d
commit bc81035555
3 changed files with 91 additions and 13 deletions

View File

@ -41,3 +41,22 @@ export function ProcessOptions({options, data, target, id}) {
}
}
export function ProcessOptionsToData({options, data}) {
let options_t = true_type_of(options);
if (options_t === "array") {
return Array.from(
options.map((option_item, i) => ProcessOptionsToData({
options: option_item,
data: data,
}))
).flat();
} else if (options_t === "object") {
if (true_type_of(options.title) === "string") {
return options;
} else {
return ProcessOptionsToData({options: json_logic_apply(options, data), data: data});
}
} else {
throw Error("Incompatible type for the option: " + options_t)
}
}

View File

@ -34,11 +34,25 @@ const useCrateModes = ((set, get) => ({
crateParams: mode => get().crate_modes[mode],
}));
const useFanTray = ((set, get) => ({
fanTray: shared_data.fanTray,
fanTrayAvailableForMode: (crate_mode) => {
return get().fanTray.crateModesAvailable[crate_mode] === true;
},
const useCrateOptions = ((set, get) => ({
crate_options: shared_data.crateOptions.options,
crate_prices: shared_data.crateOptions.prices,
}));
const useOrderOptions = ((set, get) => ({
orderOptions: shared_data.crateOptions.options,
orderPrices: shared_data.crateOptions.prices,
order_options_data: {},
fillOrderExtData: _ => {},
_updateOrderOption: (new_options) => set(state => ({
order_options_data: {
...state.order_options_data,
...new_options
}
}))
}));
const useLayout = ((set, get) => ({
@ -495,5 +509,6 @@ export const useShopStore = createWithEqualityFn((...params) => ({
...useLayout(...params),
...useHighlighted(...params),
...useImportJSON(...params),
...useFanTray(...params),
...useCrateOptions(...params),
...useOrderOptions(...params),
}))

View File

@ -28,13 +28,57 @@ const shop_data = {
"rack", "desktop"
],
fanTray: {
price: 470,
crateModesAvailable: {
'rack': true
},
optionTitle: "Add fan tray",
tip: "Add 1U 84hp fan tray (to be mounted under the crate) to improve cooling. Fans need 220VAC 50/60Hz power. 3 fans, 167m³/h air flow."
crateOptions: {
options: [
{"if": [
{"==": [{"var": "ext_data.crate_mode"}, "rack",]},
{type: "Switch", args: {
title: "Add fan tray",
outvar: "nuc",
tip: "Add 1U 84hp fan tray (to be mounted under the crate) to improve cooling. " +
"Fans need 220VAC 50/60Hz power. 3 fans, 167m³/h air flow.",
fallback: false,
}}
]},
],
prices: [{"if": [{"and": [{"var": "fan_tray"}, {"==": [{"var": "ext_data.crate_mode"}, "rack",]}]}, {title: "Add fan tray", price: 470}]}]
},
orderOptions: {
options: [
{type: "Switch", args: {
title: "Include optional pre-installed Intel® NUC mini-computer",
outvar: "nuc",
tip: "OS: latest stable NixOS with Gnome or KDE with pre-installed ARTIQ software. " +
"Hardware (other choices available): Intel® NUC 13 Pro Kit NUC13ANKi7, i7-1360P CPU, " +
"32GB RAM from reputable vendor, 1TB M.2 NVM Express SSD from reputable vendor.",
fallback: true,
}},
{
"if": [
{"var": "nuc"},
[
{
type: "Radio",
args: {
title: "Desktop Environment",
outvar: "nuc_desktop",
variants: ["Gnome", "KDE"],
tip: "Gnome vs KDE",
fallback: 0
}
},
{type: "Line", args: {title: "Additional software to be pre-installed", outvar: "software", fallback: "",
tip: "Pre-install additional software, if needed"}},
],
]
},
],
prices: [{
"if": [{"var": "nuc"}, {title: "Include optional pre-installed Intel® NUC mini-computer", price: 1300}, 0],
}]
},
items: {