Add external data for use per every card. Apply it for TTL and Suservo

Signed-off-by: esavkin <es@m-labs.hk>
Egor Savkin 2023-09-08 18:27:23 +08:00 committed by esavkin
parent 3494af9808
commit 019036ca5f
3 changed files with 68 additions and 10 deletions

View File

@ -6,7 +6,7 @@ import { createRoot } from "react-dom/client";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd"; import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { OptionsDialogPopup, OptionsSummaryPopup } from "./shop_components.jsx"; import { OptionsDialogPopup, OptionsSummaryPopup, fill_ext_data } from "./shop_components.jsx";
const data = window.shop_data; const data = window.shop_data;
const itemsUnfoldedList = Array.from(data.columns.backlog.categories.map(groupId => groupId.itemIds).flat()); const itemsUnfoldedList = Array.from(data.columns.backlog.categories.map(groupId => groupId.itemIds).flat());
@ -535,6 +535,7 @@ class ProductCartItem extends React.PureComponent {
index: PropTypes.number.isRequired, index: PropTypes.number.isRequired,
model: PropTypes.object.isRequired, model: PropTypes.object.isRequired,
data: PropTypes.object, data: PropTypes.object,
ext_data: PropTypes.array,
onToggleProgress: PropTypes.func, onToggleProgress: PropTypes.func,
onToggleWarning: PropTypes.func, onToggleWarning: PropTypes.func,
onToggleOverlayRemove: PropTypes.func, onToggleOverlayRemove: PropTypes.func,
@ -620,6 +621,7 @@ class ProductCartItem extends React.PureComponent {
model, model,
data, data,
index, index,
ext_data,
shouldTooltipWarningClassInverted, shouldTooltipWarningClassInverted,
} = this.props; } = this.props;
@ -638,6 +640,7 @@ class ProductCartItem extends React.PureComponent {
options = data.options; options = data.options;
if (!data.options_data) data.options_data = {}; if (!data.options_data) data.options_data = {};
options_data = data.options_data; options_data = data.options_data;
options_data.ext_data = ext_data;
} }
let render_progress; let render_progress;
@ -715,7 +718,7 @@ class ProductCartItem extends React.PureComponent {
data={options_data} data={options_data}
key={"popover" + index} key={"popover" + index}
id={"popover" + index} id={"popover" + index}
big={data.size == "big"} big={data.size === "big"}
target={{ target={{
construct: ((outvar, value) => { construct: ((outvar, value) => {
//console.log("construct", outvar, value, options_data); //console.log("construct", outvar, value, options_data);
@ -879,6 +882,7 @@ class Cart extends React.PureComponent {
const products = data.items.map((item, index) => { const products = data.items.map((item, index) => {
let itemData; let itemData;
let ext_data = fill_ext_data(data.itemsData, index);
if (data.itemsData && index in data.itemsData) { if (data.itemsData && index in data.itemsData) {
itemData = data.itemsData[index]; itemData = data.itemsData[index];
} }
@ -891,6 +895,7 @@ class Cart extends React.PureComponent {
id={item.id} id={item.id}
index={index} index={index}
data={itemData} data={itemData}
ext_data={ext_data}
shouldTooltipWarningClassInverted={shouldTooltipWarningClassInverted && index > 10} shouldTooltipWarningClassInverted={shouldTooltipWarningClassInverted && index > 10}
onToggleProgress={onToggleProgress} onToggleProgress={onToggleProgress}
onToggleWarning={onToggleWarning} onToggleWarning={onToggleWarning}

View File

@ -309,6 +309,7 @@ const componentsList = {
export function ProcessOptions({options, data, target, id}) { export function ProcessOptions({options, data, target, id}) {
let options_t = trueTypeOf(options); let options_t = trueTypeOf(options);
console.log(data)
if (options_t === "array") { if (options_t === "array") {
return Array.from( return Array.from(
@ -436,12 +437,22 @@ export function OptionsSummaryPopup({id, data}) {
className="overlayVariant card border rounded" className="overlayVariant card border rounded"
id={id}> id={id}>
<div className="card-body"> <div className="card-body">
{Array.from(Object.entries(data).map(([key, value], _) => { {Array.from(Object.entries(data)
return (<p className="card-text" key={id + key}><i>{key}</i>: {stringify(value)}</p>); .filter(([key, value], _) => key !== "ext_data")
}))} .map(([key, value], _) => {
return (<p className="card-text" key={id + key}><i>{key}</i>: {stringify(value)}</p>);
}))}
</div> </div>
</div> </div>
</div> </div>
); );
} }
export function fill_ext_data(data, index) {
return {
has_other_dio: data.filter((value, item_index) => index !== item_index && value.name.endsWith("-TTL")).length > 0,
has_dds: data.filter(((value, _) => value.name === "DDS" )).length > 0,
has_sampler: data.filter(((value, _) => value.name === "Sampler" )).length > 0
}
}

View File

@ -287,7 +287,17 @@ const shop_data = {
slotOccupied: 1, slotOccupied: 1,
clockOccupied: 0, clockOccupied: 0,
options: [ options: [
{type: "Switch", args: {title: "Output first group", outvar: "out_first_group", tip: "Switch connectors 0-3 to output"}}, {
"if": [
{"var": "ext_data.has_other_dio"},
[
{type: "Switch", args: {title: "Output first group", fallback: true, outvar: "out_first_group", tip: "Switch connectors 0-3 to output"}}
],
[
{type: "Switch", args: {title: "Output first group", outvar: "out_first_group", tip: "Switch connectors 0-3 to output"}}
]
]
},
{type: "Switch", args: {title: "Output second group", outvar: "out_second_group", fallback: true, tip: "Switch connectors 4-7 to output"}} {type: "Switch", args: {title: "Output second group", outvar: "out_second_group", fallback: true, tip: "Switch connectors 4-7 to output"}}
], ],
rules: { rules: {
@ -312,7 +322,17 @@ const shop_data = {
datasheet_file: '/docs/sinara-datasheets/2118-2128.pdf', datasheet_file: '/docs/sinara-datasheets/2118-2128.pdf',
datasheet_name: '2118/2128 BNC/SMA-TTL datasheet', datasheet_name: '2118/2128 BNC/SMA-TTL datasheet',
options: [ options: [
{type: "Switch", args: {title: "Output first group", outvar: "out_first_group", tip: "Switch connectors 0-3 to output"}}, {
"if": [
{"var": "ext_data.has_other_dio"},
[
{type: "Switch", args: {title: "Output first group", fallback: true, outvar: "out_first_group", tip: "Switch connectors 0-3 to output"}}
],
[
{type: "Switch", args: {title: "Output first group", outvar: "out_first_group", tip: "Switch connectors 0-3 to output"}}
]
]
},
{type: "Switch", args: {title: "Output second group", outvar: "out_second_group", fallback: true, tip: "Switch connectors 4-7 to output"}} {type: "Switch", args: {title: "Output second group", outvar: "out_second_group", fallback: true, tip: "Switch connectors 4-7 to output"}}
], ],
size: 'small', size: 'small',
@ -349,7 +369,17 @@ const shop_data = {
datasheet_file: '/docs/sinara-datasheets/2238.pdf', datasheet_file: '/docs/sinara-datasheets/2238.pdf',
datasheet_name: '2238 MCX-TTL datasheet', datasheet_name: '2238 MCX-TTL datasheet',
options: [ options: [
{type: "Switch", args: {title: "Output first group", outvar: "out_first_group", tip: "Switch connectors 0-3 to output"}}, {
"if": [
{"var": "ext_data.has_other_dio"},
[
{type: "Switch", args: {title: "Output first group", fallback: true, outvar: "out_first_group", tip: "Switch connectors 0-3 to output"}}
],
[
{type: "Switch", args: {title: "Output first group", outvar: "out_first_group", tip: "Switch connectors 0-3 to output"}}
]
]
},
{type: "Switch", args: {title: "Output second group", outvar: "out_second_group", fallback: true, tip: "Switch connectors 4-7 to output"}}, {type: "Switch", args: {title: "Output second group", outvar: "out_second_group", fallback: true, tip: "Switch connectors 4-7 to output"}},
{type: "Switch", args: {title: "Output third group", outvar: "out_third_group", fallback: true, tip: "Switch connectors 8-11 to output"}}, {type: "Switch", args: {title: "Output third group", outvar: "out_third_group", fallback: true, tip: "Switch connectors 8-11 to output"}},
{type: "Switch", args: {title: "Output fourth group", outvar: "out_fourth_group", fallback: true, tip: "Switch connectors 12-15 to output"}} {type: "Switch", args: {title: "Output fourth group", outvar: "out_fourth_group", fallback: true, tip: "Switch connectors 12-15 to output"}}
@ -440,7 +470,13 @@ const shop_data = {
null, null,
[ [
{type: "SwitchLine", args: {title: "Ext CLK", outvar: "ext_clk", fallback: {text: "125 MHz", checked: false}}}, {type: "SwitchLine", args: {title: "Ext CLK", outvar: "ext_clk", fallback: {text: "125 MHz", checked: false}}},
{type: "Switch", args: {title: "SUServo mode", outvar: "suservo", }} {
"if": [
{"var": "ext_data.has_sampler"},
{type: "Switch", args: {title: "SUServo mode", outvar: "suservo"}},
null
]
}
] ]
] ]
} }
@ -750,7 +786,13 @@ const shop_data = {
'Supports SU-Servo laser intensity stabilization servo in conjunction with Urukul.' 'Supports SU-Servo laser intensity stabilization servo in conjunction with Urukul.'
], ],
options: [ options: [
{type: "Switch", args: {title: "SUServo mode", outvar: "suservo"}} {
"if": [
{"var": "ext_data.has_dds"},
{type: "Switch", args: {title: "SUServo mode", outvar: "suservo"}},
null
]
}
], ],
size: 'big', size: 'big',
type: 'novo', type: 'novo',