Introduce main identifier to power RelationFieldDisplay (#2577)
* Introduce main identifier to power RelationFieldDisplay, FilterDrodown, TableFirstColumn * Apply to RelationPicker
This commit is contained in:
@ -1,23 +0,0 @@
|
||||
import { useFilteredSearchPeopleQuery } from '@/people/hooks/useFilteredSearchPeopleQuery';
|
||||
import { ObjectFilterDropdownEntitySearchSelect } from '@/ui/object/object-filter-dropdown/components/ObjectFilterDropdownEntitySearchSelect';
|
||||
import { useFilter } from '@/ui/object/object-filter-dropdown/hooks/useFilter';
|
||||
|
||||
export const FilterDropdownPeopleSearchSelect = () => {
|
||||
const {
|
||||
objectFilterDropdownSearchInput,
|
||||
objectFilterDropdownSelectedEntityId,
|
||||
} = useFilter();
|
||||
|
||||
const peopleForSelect = useFilteredSearchPeopleQuery({
|
||||
searchFilter: objectFilterDropdownSearchInput,
|
||||
selectedIds: objectFilterDropdownSelectedEntityId
|
||||
? [objectFilterDropdownSelectedEntityId]
|
||||
: [],
|
||||
});
|
||||
|
||||
return (
|
||||
<ObjectFilterDropdownEntitySearchSelect
|
||||
entitiesForSelect={peopleForSelect}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@ -1,96 +0,0 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useQuery } from '@apollo/client';
|
||||
|
||||
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
|
||||
import { useFilteredSearchEntityQueryV2 } from '@/search/hooks/useFilteredSearchEntityQueryV2';
|
||||
import { SingleEntitySelect } from '@/ui/input/relation-picker/components/SingleEntitySelect';
|
||||
import { relationPickerSearchFilterScopedState } from '@/ui/input/relation-picker/states/relationPickerSearchFilterScopedState';
|
||||
import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelect';
|
||||
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
||||
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
||||
|
||||
export type PeoplePickerProps = {
|
||||
personId: string | null;
|
||||
companyId?: string;
|
||||
onSubmit: (newPersonId: PersonForSelect | null) => void;
|
||||
onCancel?: () => void;
|
||||
onCreate?: () => void;
|
||||
excludePersonIds?: string[];
|
||||
initialSearchFilter?: string | null;
|
||||
};
|
||||
|
||||
export type PersonForSelect = EntityForSelect & {
|
||||
entityType: Entity.Person;
|
||||
};
|
||||
|
||||
export const PeoplePicker = ({
|
||||
personId,
|
||||
companyId,
|
||||
onSubmit,
|
||||
onCancel,
|
||||
onCreate,
|
||||
excludePersonIds,
|
||||
initialSearchFilter,
|
||||
}: PeoplePickerProps) => {
|
||||
const [relationPickerSearchFilter, setRelationPickerSearchFilter] =
|
||||
useRecoilScopedState(relationPickerSearchFilterScopedState);
|
||||
|
||||
useEffect(() => {
|
||||
setRelationPickerSearchFilter(initialSearchFilter ?? '');
|
||||
}, [initialSearchFilter, setRelationPickerSearchFilter]);
|
||||
|
||||
const queryFilters = [
|
||||
{
|
||||
fieldNames: ['name.firstName', 'name.lastName'],
|
||||
filter: relationPickerSearchFilter,
|
||||
},
|
||||
];
|
||||
|
||||
if (companyId) {
|
||||
queryFilters.push({
|
||||
fieldNames: ['companyId'],
|
||||
filter: companyId,
|
||||
});
|
||||
}
|
||||
|
||||
const { findManyQuery } = useFindOneObjectMetadataItem({
|
||||
objectNameSingular: 'person',
|
||||
});
|
||||
|
||||
const useFindManyPeople = (options: any) => useQuery(findManyQuery, options);
|
||||
|
||||
const people = useFilteredSearchEntityQueryV2({
|
||||
queryHook: useFindManyPeople,
|
||||
filters: queryFilters,
|
||||
orderByField: 'createdAt',
|
||||
mappingFunction: (workspaceMember) => ({
|
||||
entityType: Entity.WorkspaceMember,
|
||||
id: workspaceMember.id,
|
||||
name:
|
||||
workspaceMember.name.firstName + ' ' + workspaceMember.name.lastName,
|
||||
avatarType: 'rounded',
|
||||
avatarUrl: '',
|
||||
originalEntity: workspaceMember,
|
||||
}),
|
||||
selectedIds: [personId ?? ''],
|
||||
excludeEntityIds: excludePersonIds,
|
||||
objectNamePlural: 'people',
|
||||
});
|
||||
|
||||
const handleEntitySelected = async (
|
||||
selectedPerson: any | null | undefined,
|
||||
) => {
|
||||
onSubmit(selectedPerson ?? null);
|
||||
};
|
||||
|
||||
return (
|
||||
<SingleEntitySelect
|
||||
entitiesToSelect={people.entitiesToSelect}
|
||||
loading={people.loading}
|
||||
onCancel={onCancel}
|
||||
onCreate={onCreate}
|
||||
onEntitySelected={handleEntitySelected}
|
||||
selectedEntity={people.selectedEntities[0]}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@ -6,14 +6,14 @@ import {
|
||||
export type PersonChipProps = {
|
||||
id: string;
|
||||
name: string;
|
||||
pictureUrl?: string;
|
||||
avatarUrl?: string;
|
||||
variant?: EntityChipVariant;
|
||||
};
|
||||
|
||||
export const PersonChip = ({
|
||||
id,
|
||||
name,
|
||||
pictureUrl,
|
||||
avatarUrl,
|
||||
variant,
|
||||
}: PersonChipProps) => (
|
||||
<EntityChip
|
||||
@ -21,7 +21,7 @@ export const PersonChip = ({
|
||||
linkToEntity={`/person/${id}`}
|
||||
name={name}
|
||||
avatarType="rounded"
|
||||
pictureUrl={pictureUrl}
|
||||
avatarUrl={avatarUrl}
|
||||
variant={variant}
|
||||
/>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user