Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix qs parse on loadRulesFromUrl #1313

Merged
1 commit merged into from Jun 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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