From 18575fc558e9ba0c85141cd8f71af2880fec5571 Mon Sep 17 00:00:00 2001 From: Carlos Valente Date: Wed, 13 Nov 2024 16:10:54 +0100 Subject: [PATCH] fix: separator collides with space indicator --- .../view-params-editor/ParamInput.tsx | 12 ++++------- .../view-params-editor/ViewParamsEditor.tsx | 20 ++++++++++++++++++- .../client/src/features/operator/Operator.tsx | 6 ++---- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/apps/client/src/common/components/view-params-editor/ParamInput.tsx b/apps/client/src/common/components/view-params-editor/ParamInput.tsx index 0ebb221c7..4a85e34c7 100644 --- a/apps/client/src/common/components/view-params-editor/ParamInput.tsx +++ b/apps/client/src/common/components/view-params-editor/ParamInput.tsx @@ -109,10 +109,8 @@ function MultiOption(props: EditFormMultiOptionProps) { const { paramField } = props; const { id, defaultValue } = paramField; - const optionFromParams = (searchParams.get(id) ?? '').toLocaleLowerCase(); - const defaultOptionValue = optionFromParams || defaultValue?.toLocaleLowerCase() || ''; - - const [paramState, setParamState] = useState(defaultOptionValue); + const optionFromParams = searchParams.getAll(id); + const [paramState, setParamState] = useState(optionFromParams || defaultValue || ['']); return ( <> @@ -124,10 +122,8 @@ function MultiOption(props: EditFormMultiOptionProps) { { - setParamState(typeof value === 'object' ? value.filter((v) => v !== '').join('_') : value); - }} + value={paramState} + onChange={(value) => setParamState(Array.isArray(value) ? value : [value])} > {Object.values(paramField.values).map((option) => { const { value, label } = option; diff --git a/apps/client/src/common/components/view-params-editor/ViewParamsEditor.tsx b/apps/client/src/common/components/view-params-editor/ViewParamsEditor.tsx index 292c201a6..1a55e531e 100644 --- a/apps/client/src/common/components/view-params-editor/ViewParamsEditor.tsx +++ b/apps/client/src/common/components/view-params-editor/ViewParamsEditor.tsx @@ -55,10 +55,28 @@ const getURLSearchParamsFromObj = (paramsObj: ViewParamsObj, paramFields: ViewOp // unfortunately this means we run all the strings through the sanitation const valueWithoutHash = sanitiseColour(value); if (defaultValues[id] !== valueWithoutHash) { - newSearchParams.set(id, valueWithoutHash); + handleValueString(id, value); } } }); + + /** Utility function contains logic to add a value into the searchParams object */ + function handleValueString(id: string, value: string) { + const maybeMultipleValues = value.split(','); + + // we need to check if the value contains comma separated list, for the case of the multi-select data + if (Array.isArray(maybeMultipleValues) && maybeMultipleValues.length > 1) { + const added = new Set(); + maybeMultipleValues.forEach((v) => { + if (!added.has(v)) { + added.add(v); + newSearchParams.append(id, v); + } + }); + } else { + newSearchParams.set(id, value); + } + } return newSearchParams; }; diff --git a/apps/client/src/features/operator/Operator.tsx b/apps/client/src/features/operator/Operator.tsx index 3f928fc2b..ea9c07a96 100644 --- a/apps/client/src/features/operator/Operator.tsx +++ b/apps/client/src/features/operator/Operator.tsx @@ -114,10 +114,8 @@ export default function Operator() { // get fields which the user subscribed to const shouldEdit = searchParams.get('shouldEdit'); - const subscriptions = (searchParams.get('subscribe') ?? '') - .split('_') - .filter((value) => Object.hasOwn(customFields, value)); - + // subscriptions is a MultiSelect and may have multiple values + const subscriptions = searchParams.getAll('subscribe').filter((value) => Object.hasOwn(customFields, value)); const canEdit = shouldEdit && subscriptions; const main = searchParams.get('main') as keyof TitleFields | null;