Fix filter by url (#9247)
Filters coming from url should be parsed properly when using the new relation schema format
This commit is contained in:
@ -94,7 +94,7 @@ export const ObjectFilterDropdownRecordSelect = ({
|
|||||||
const currentWorkspaceMemberSelectableItem: SelectableItem = {
|
const currentWorkspaceMemberSelectableItem: SelectableItem = {
|
||||||
id: CURRENT_WORKSPACE_MEMBER_SELECTABLE_ITEM_ID,
|
id: CURRENT_WORKSPACE_MEMBER_SELECTABLE_ITEM_ID,
|
||||||
name: 'Me',
|
name: 'Me',
|
||||||
isSelected: isCurrentWorkspaceMemberSelected,
|
isSelected: isCurrentWorkspaceMemberSelected ?? false,
|
||||||
AvatarIcon: IconUserCircle,
|
AvatarIcon: IconUserCircle,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { useApolloClient } from '@apollo/client';
|
import { useApolloClient } from '@apollo/client';
|
||||||
import { isNonEmptyString } from '@sniptt/guards';
|
import { isNonEmptyString, isObject } from '@sniptt/guards';
|
||||||
import qs from 'qs';
|
import qs from 'qs';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useParams, useSearchParams } from 'react-router-dom';
|
import { useParams, useSearchParams } from 'react-router-dom';
|
||||||
@ -16,6 +16,7 @@ import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
|||||||
import { generateFindManyRecordsQuery } from '@/object-record/utils/generateFindManyRecordsQuery';
|
import { generateFindManyRecordsQuery } from '@/object-record/utils/generateFindManyRecordsQuery';
|
||||||
import { ViewFilter } from '@/views/types/ViewFilter';
|
import { ViewFilter } from '@/views/types/ViewFilter';
|
||||||
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
|
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
|
||||||
|
import { relationFilterValueSchemaObject } from '@/views/view-filter-value/validation-schemas/relationFilterValueSchema';
|
||||||
import { isDefined } from '~/utils/isDefined';
|
import { isDefined } from '~/utils/isDefined';
|
||||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ const filterQueryParamsSchema = z.object({
|
|||||||
.record(
|
.record(
|
||||||
z.record(
|
z.record(
|
||||||
z.nativeEnum(ViewFilterOperand),
|
z.nativeEnum(ViewFilterOperand),
|
||||||
z.string().or(z.array(z.string())),
|
z.string().or(z.array(z.string())).or(relationFilterValueSchemaObject),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.optional(),
|
.optional(),
|
||||||
@ -143,9 +144,11 @@ export const useViewFromQueryParams = () => {
|
|||||||
relationRecordNames.push(...relationRecordNamesFromQuery);
|
relationRecordNames.push(...relationRecordNamesFromQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
const filterValueAsString = Array.isArray(filterValueFromURL)
|
const filterValueAsString =
|
||||||
? JSON.stringify(filterValueFromURL)
|
Array.isArray(filterValueFromURL) ||
|
||||||
: filterValueFromURL;
|
isObject(filterValueFromURL)
|
||||||
|
? JSON.stringify(filterValueFromURL)
|
||||||
|
: filterValueFromURL;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
__typename: 'ViewFilter',
|
__typename: 'ViewFilter',
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
export const relationFilterValueSchemaObject = z.object({
|
||||||
|
isCurrentWorkspaceMemberSelected: z.boolean().optional(),
|
||||||
|
selectedRecordIds: z.array(z.string()),
|
||||||
|
});
|
||||||
|
|
||||||
export const relationFilterValueSchema = z
|
export const relationFilterValueSchema = z
|
||||||
.string()
|
.string()
|
||||||
.transform((value, ctx) => {
|
.transform((value, ctx) => {
|
||||||
@ -13,9 +18,4 @@ export const relationFilterValueSchema = z
|
|||||||
return z.NEVER;
|
return z.NEVER;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.pipe(
|
.pipe(relationFilterValueSchemaObject);
|
||||||
z.object({
|
|
||||||
isCurrentWorkspaceMemberSelected: z.boolean(),
|
|
||||||
selectedRecordIds: z.array(z.string()),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user