Skip to content

Commit

Permalink
Merge pull request #1313 from balena-io-modules/fix-load-rules-from-url
Browse files Browse the repository at this point in the history
Fix qs parse on loadRulesFromUrl
  • Loading branch information
bulldozer-balena[bot] committed Jun 30, 2021
2 parents 08454d5 + 6941a67 commit bb6b735
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/extra/AutoUi/Collection/PersistentFilters.tsx
Expand Up @@ -53,6 +53,7 @@ const listFilterQuery = (schema: JSONSchema, rules: JSONSchema[]) => {
flatSchema,
flattenFilter,
) as FilterSignature[];
console.log(flatSchema, flattenFilter, signatures);
return signatures.map<ListQueryStringFilterObject>(
({ field, operator, value }) => ({
n: field,
Expand All @@ -71,7 +72,7 @@ const loadRulesFromUrl = (
if (!searchLocation) {
return [];
}
const parsed = qs.parse(searchLocation.replace(/^\?/, '')) || {};
const parsed = qs.parse(searchLocation) || {};
const rules = filter(parsed, isQueryStringFilterRuleset).map(
// @ts-expect-error
(rules: ListQueryStringFilterObject[]) => {
Expand All @@ -89,8 +90,10 @@ const loadRulesFromUrl = (
// TODO: fix in rendition => this should be handled by Rendition, calling the
// createFilter function handle the case.
if (signatures[0].operator === FULL_TEXT_SLUG) {
console.log('createFullTextSearchFilter', signatures);
return createFullTextSearchFilter(schema, signatures[0].value);
}
console.log('create', signatures);
return createFilter(schema, signatures);
},
);
Expand Down Expand Up @@ -124,7 +127,7 @@ export const PersistentFilters = ({
return !!urlRules?.length
? urlRules
: getFromLocalStorage<JSONSchema[]>(filtersRestorationKey) ?? [];
}, [history?.location?.search, schema, filtersRestorationKey]);
}, [schema, filtersRestorationKey]);

React.useEffect(() => {
updateUrl(storedFilters);
Expand All @@ -141,7 +144,7 @@ export const PersistentFilters = ({

const updateUrl = (filters: JSONSchema[]) => {
const { pathname } = window.location;

console.log(schema, filters);
history?.replace?.({
pathname,
search: listFilterQuery(schema, filters),
Expand Down

0 comments on commit bb6b735

Please sign in to comment.