refactor: param type colour

This commit is contained in:
Carlos Valente
2024-10-11 13:24:44 +02:00
committed by Carlos Valente
parent 24b0cfd24e
commit 089eba3877
7 changed files with 99 additions and 86 deletions
@@ -19,6 +19,16 @@ import style from './ViewParamsEditor.module.scss';
type ViewParamsObj = { [key: string]: string | FormDataEntryValue };
/**
* Utility remove the # character from a hex string
*/
function sanitiseColour(colour: string) {
if (colour.startsWith('#')) {
return colour.substring(1);
}
return colour;
}
/**
* Makes a new URLSearchParams object from the given params object
*/
@@ -41,7 +51,9 @@ const getURLSearchParamsFromObj = (paramsObj: ViewParamsObj, paramFields: ViewOp
// compare which values are different from the default values
Object.entries(paramsObj).forEach(([id, value]) => {
if (typeof value === 'string' && value.length && defaultValues[id] !== value) {
newSearchParams.set(id, value);
// we dont know which values contain colours
// unfortunately this means we run all the strings through the sanitation
newSearchParams.set(id, sanitiseColour(value));
}
});
return newSearchParams;