Skip to content

Commit f61fd0a

Browse files
committed
fix: code improvements
1 parent a94f093 commit f61fd0a

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

site/src/modules/workspaces/DynamicParameter/DynamicParameter.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,34 @@ const ParameterField: FC<ParameterFieldProps> = ({
198198
);
199199

200200
case "multi-select": {
201+
let values: string[] = [];
202+
203+
if (value) {
204+
try {
205+
const parsed = JSON.parse(value);
206+
if (Array.isArray(parsed)) {
207+
values = parsed;
208+
}
209+
} catch (e) {
210+
console.error("Error parsing parameter value with form_type multi-select", e);
211+
}
212+
}
213+
201214
// Map parameter options to MultiSelectCombobox options format
202215
const options: Option[] = parameter.options.map((opt) => ({
203216
value: opt.value.value,
204217
label: opt.name,
205218
disable: false,
206219
}));
207220

208-
const selectedOptions: Option[] = JSON.parse(value).map((val: string) => {
209-
const option = parameter.options.find((o) => o.value.value === val);
221+
const optionMap = new Map(
222+
parameter.options.map(opt => [opt.value.value, opt.name])
223+
);
224+
225+
const selectedOptions: Option[] = values.map((val) => {
210226
return {
211227
value: val,
212-
label: option?.name || val,
228+
label: optionMap.get(val) || val,
213229
disable: false,
214230
};
215231
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy