Fix Filter search dynamic objectMetadataName (#2659)

This commit is contained in:
Charles Bochet 2023-11-22 19:22:14 +01:00 committed by GitHub
parent 02e60da923
commit 41c0cebf48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 11 deletions

View File

@ -46,6 +46,10 @@ const formatFieldMetadataItemAsFilterDefinition = ({
fieldMetadataId: field.id,
label: field.label,
iconName: field.icon ?? 'Icon123',
relationObjectMetadataNamePlural:
field.toRelationMetadata?.fromObjectMetadata.namePlural,
relationObjectMetadataNameSingular:
field.toRelationMetadata?.fromObjectMetadata.nameSingular,
type:
field.type === FieldMetadataType.DateTime
? 'DATE_TIME'

View File

@ -14,8 +14,14 @@ export const ObjectFilterDropdownEntitySelect = () => {
objectFilterDropdownSelectedEntityId,
} = useFilter();
const objectMetadataNameSingular =
filterDefinitionUsedInDropdown?.relationObjectMetadataNameSingular ?? '';
const objectMetadataNamePlural =
filterDefinitionUsedInDropdown?.relationObjectMetadataNamePlural ?? '';
const { findManyQuery } = useObjectMetadataItem({
objectNameSingular: 'company',
objectNameSingular: objectMetadataNameSingular,
});
const useFindManyQuery = (options: any) => useQuery(findManyQuery, options);
@ -26,7 +32,8 @@ export const ObjectFilterDropdownEntitySelect = () => {
queryHook: useFindManyQuery,
filters: [
{
fieldNames: searchQuery?.computeFilterFields?.('company') ?? [],
fieldNames:
searchQuery?.computeFilterFields?.(objectMetadataNameSingular) ?? [],
filter: objectFilterDropdownSearchInput,
},
],
@ -34,8 +41,9 @@ export const ObjectFilterDropdownEntitySelect = () => {
selectedIds: objectFilterDropdownSelectedEntityId
? [objectFilterDropdownSelectedEntityId]
: [],
mappingFunction: (record: any) => identifiersMapper?.(record, 'company'),
objectNamePlural: 'companies',
mappingFunction: (record: any) =>
identifiersMapper?.(record, objectMetadataNameSingular),
objectNamePlural: objectMetadataNamePlural,
});
if (filterDefinitionUsedInDropdown?.type !== 'RELATION') {

View File

@ -7,7 +7,8 @@ export type FilterDefinition = {
label: string;
iconName: string;
type: FilterType;
entitySelectComponent?: JSX.Element;
relationObjectMetadataNamePlural?: string;
relationObjectMetadataNameSingular?: string;
selectAllLabel?: string;
SelectAllIcon?: IconComponent;
};

View File

@ -100,8 +100,9 @@ export const ObjectSortDropdownButton = ({
</DropdownMenuHeader>
<DropdownMenuSeparator />
<DropdownMenuItemsContainer>
{availableSortDefinitions.map(
(availableSortDefinition, index) => (
{[...availableSortDefinitions]
.sort((a, b) => a.label.localeCompare(b.label))
.map((availableSortDefinition, index) => (
<MenuItem
testId={`select-sort-${index}`}
key={index}
@ -109,8 +110,7 @@ export const ObjectSortDropdownButton = ({
LeftIcon={icons[availableSortDefinition.iconName]}
text={availableSortDefinition.label}
/>
),
)}
))}
</DropdownMenuItemsContainer>
</>
)}

View File

@ -1,7 +1,6 @@
import { Activity } from '@/activities/types/Activity';
import { IconUserCircle } from '@/ui/display/icon';
import { FilterDefinitionByEntity } from '@/ui/object/object-filter-dropdown/types/FilterDefinitionByEntity';
import { FilterDropdownUserSearchSelect } from '@/users/components/FilterDropdownUserSearchSelect';
export const tasksFilterDefinitions: FilterDefinitionByEntity<Activity>[] = [
{
@ -9,7 +8,8 @@ export const tasksFilterDefinitions: FilterDefinitionByEntity<Activity>[] = [
label: 'Assignee',
iconName: 'IconUser',
type: 'RELATION',
entitySelectComponent: <FilterDropdownUserSearchSelect />,
relationObjectMetadataNamePlural: 'workspaceMembers',
relationObjectMetadataNameSingular: 'workspaceMember',
selectAllLabel: 'All assignees',
SelectAllIcon: IconUserCircle,
},