From bc810355559f855580578d1da09284972ea86310 Mon Sep 17 00:00:00 2001 From: Egor Savkin Date: Mon, 29 Jan 2024 17:26:59 +0800 Subject: [PATCH] Prototype crate and order options Signed-off-by: Egor Savkin --- static/js/shop/options/Options.jsx | 19 ++++++++++ static/js/shop/shop_store.js | 27 ++++++++++---- static/js/shop_data.js | 58 ++++++++++++++++++++++++++---- 3 files changed, 91 insertions(+), 13 deletions(-) diff --git a/static/js/shop/options/Options.jsx b/static/js/shop/options/Options.jsx index 09937708..5fffb4fa 100644 --- a/static/js/shop/options/Options.jsx +++ b/static/js/shop/options/Options.jsx @@ -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) + } +} \ No newline at end of file diff --git a/static/js/shop/shop_store.js b/static/js/shop/shop_store.js index 1ad1f26b..02f78ba9 100644 --- a/static/js/shop/shop_store.js +++ b/static/js/shop/shop_store.js @@ -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), })) \ No newline at end of file diff --git a/static/js/shop_data.js b/static/js/shop_data.js index 0b0b94cc..9862564f 100644 --- a/static/js/shop_data.js +++ b/static/js/shop_data.js @@ -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: {