fix: separator collides with space indicator

This commit is contained in:
Carlos Valente
2024-11-13 16:10:54 +01:00
committed by Carlos Valente
parent 04e2593939
commit 18575fc558
3 changed files with 25 additions and 13 deletions
@@ -109,10 +109,8 @@ function MultiOption(props: EditFormMultiOptionProps) {
const { paramField } = props; const { paramField } = props;
const { id, defaultValue } = paramField; const { id, defaultValue } = paramField;
const optionFromParams = (searchParams.get(id) ?? '').toLocaleLowerCase(); const optionFromParams = searchParams.getAll(id);
const defaultOptionValue = optionFromParams || defaultValue?.toLocaleLowerCase() || ''; const [paramState, setParamState] = useState<string[]>(optionFromParams || defaultValue || ['']);
const [paramState, setParamState] = useState<string>(defaultOptionValue);
return ( return (
<> <>
@@ -124,10 +122,8 @@ function MultiOption(props: EditFormMultiOptionProps) {
<MenuList> <MenuList>
<MenuOptionGroup <MenuOptionGroup
type='checkbox' type='checkbox'
value={paramState.split('_')} value={paramState}
onChange={(value) => { onChange={(value) => setParamState(Array.isArray(value) ? value : [value])}
setParamState(typeof value === 'object' ? value.filter((v) => v !== '').join('_') : value);
}}
> >
{Object.values(paramField.values).map((option) => { {Object.values(paramField.values).map((option) => {
const { value, label } = option; const { value, label } = option;
@@ -55,10 +55,28 @@ const getURLSearchParamsFromObj = (paramsObj: ViewParamsObj, paramFields: ViewOp
// unfortunately this means we run all the strings through the sanitation // unfortunately this means we run all the strings through the sanitation
const valueWithoutHash = sanitiseColour(value); const valueWithoutHash = sanitiseColour(value);
if (defaultValues[id] !== valueWithoutHash) { 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; return newSearchParams;
}; };
@@ -114,10 +114,8 @@ export default function Operator() {
// get fields which the user subscribed to // get fields which the user subscribed to
const shouldEdit = searchParams.get('shouldEdit'); const shouldEdit = searchParams.get('shouldEdit');
const subscriptions = (searchParams.get('subscribe') ?? '') // subscriptions is a MultiSelect and may have multiple values
.split('_') const subscriptions = searchParams.getAll('subscribe').filter((value) => Object.hasOwn(customFields, value));
.filter((value) => Object.hasOwn(customFields, value));
const canEdit = shouldEdit && subscriptions; const canEdit = shouldEdit && subscriptions;
const main = searchParams.get('main') as keyof TitleFields | null; const main = searchParams.get('main') as keyof TitleFields | null;