Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
thomtrp committed Nov 28, 2024
1 parent 464a3a4 commit 414b586
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ export const ActivityTargetInlineCellEditMode = ({
<RecordPickerComponentInstanceContext.Provider
value={{ instanceId: recordPickerInstanceId }}
>
{' '}
<ActivityTargetObjectRecordEffect
activityTargetWithTargetRecords={activityTargetWithTargetRecords}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const ObjectMetadataItemsProvider = ({
{shouldDisplayChildren ? (
<PreComputedChipGeneratorsProvider>
<RecordPickerComponentInstanceContext.Provider
value={{ instanceId: 'relation-picker' }}
value={{ instanceId: 'record-picker' }}
>
{children}
</RecordPickerComponentInstanceContext.Provider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const RecordBoardColumnNewOpportunity = ({
}
objectNameSingular={CoreObjectNameSingular.Company}
recordPickerInstanceId="relation-picker"
selectedRelationRecordIds={[]}
selectedRecordIds={[]}
/>
</StyledCompanyPickerContainer>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const useAddNewCard = () => {
const { createOneRecord, selectFieldMetadataItem, objectMetadataItem } =
useContext(RecordBoardContext);
const { resetSearchFilter } = useRecordSelectSearch({
recordPickerInstanceId: 'relation-picker',
recordPickerInstanceId: 'record-picker',
});

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const RelationFromManyFieldInput = ({
<RecordPickerComponentInstanceContext.Provider
value={{ instanceId: recordPickerInstanceId }}
>
{' '}
<RelationFromManyFieldInputMultiRecordsEffect />
<MultiRecordSelect
onSubmit={handleSubmit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { recordStoreFamilySelector } from '@/object-record/record-store/states/s
import { MultiRecordSelect } from '@/object-record/relation-picker/components/MultiRecordSelect';
import { SingleRecordSelectMenuItemsWithSearch } from '@/object-record/relation-picker/components/SingleRecordSelectMenuItemsWithSearch';
import { useAddNewRecordAndOpenRightDrawer } from '@/object-record/relation-picker/hooks/useAddNewRecordAndOpenRightDrawer';
import { useRelationPicker } from '@/object-record/relation-picker/hooks/useRecordPicker';
import { useRecordPicker } from '@/object-record/relation-picker/hooks/useRecordPicker';
import { RecordPickerComponentInstanceContext } from '@/object-record/relation-picker/states/contexts/RecordPickerComponentInstanceContext';
import { RecordForSelect } from '@/object-record/relation-picker/types/RecordForSelect';
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
Expand Down Expand Up @@ -84,7 +84,7 @@ export const RecordDetailRelationSection = ({
const { closeDropdown, isDropdownOpen, dropdownPlacement } =
useDropdown(dropdownId);

const { setRecordPickerSearchFilter } = useRelationPicker({
const { setRecordPickerSearchFilter } = useRecordPicker({
recordPickerInstanceId: dropdownId,
});

Expand Down Expand Up @@ -200,7 +200,7 @@ export const RecordDetailRelationSection = ({
<SingleRecordSelectMenuItemsWithSearch
EmptyIcon={IconForbid}
onRecordSelected={handleRelationPickerEntitySelected}
selectedRelationRecordIds={relationRecordIds}
selectedRecordIds={relationRecordIds}
objectNameSingular={relationObjectMetadataNameSingular}
recordPickerInstanceId={dropdownId}
onCreate={createNewRecordAndOpenRightDrawer}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { RecordForSelect } from '@/object-record/relation-picker/types/RecordFor

export type RelationPickerProps = {
selectedRecordId?: string;
onSubmit: (selectedEntity: RecordForSelect | null) => void;
onSubmit: (selectedRecord: RecordForSelect | null) => void;
onCancel?: () => void;
width?: number;
excludeRecordIds?: string[];
excludedRecordIds?: string[];
initialSearchFilter?: string | null;
fieldDefinition: FieldDefinition<FieldRelationMetadata>;
};
Expand All @@ -24,16 +24,16 @@ export const RelationPicker = ({
selectedRecordId,
onSubmit,
onCancel,
excludeRecordIds,
excludedRecordIds,
width,
initialSearchFilter,
fieldDefinition,
}: RelationPickerProps) => {
const recordPickerInstanceId = 'relation-picker';

const handleRecordSelected = (
selectedEntity: RecordForSelect | null | undefined,
) => onSubmit(selectedEntity ?? null);
selectedRecord: RecordForSelect | null | undefined,
) => onSubmit(selectedRecord ?? null);

const { objectMetadataItem: relationObjectMetadataItem } =
useObjectMetadataItem({
Expand Down Expand Up @@ -73,8 +73,8 @@ export const RelationPicker = ({
fieldDefinition.metadata.relationObjectMetadataNameSingular
}
recordPickerInstanceId={recordPickerInstanceId}
selectedRelationRecordIds={selectedRecordId ? [selectedRecordId] : []}
excludedRelationRecordIds={excludeRecordIds}
selectedRecordIds={selectedRecordId ? [selectedRecordId] : []}
excludedRecordIds={excludedRecordIds}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export const SingleRecordSelect = ({
disableBackgroundBlur = false,
EmptyIcon,
emptyLabel,
excludedRelationRecordIds,
excludedRecordIds,
onCancel,
onCreate,
onRecordSelected,
objectNameSingular,
recordPickerInstanceId,
selectedRelationRecordIds,
selectedRecordIds,
width = 200,
}: SingleRecordSelectProps) => {
const containerRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -54,13 +54,13 @@ export const SingleRecordSelect = ({
{...{
EmptyIcon,
emptyLabel,
excludedRelationRecordIds,
excludedRecordIds,
onCancel,
onCreate,
onRecordSelected,
objectNameSingular,
recordPickerInstanceId,
selectedRelationRecordIds,
selectedRecordIds,
}}
/>
</DropdownMenu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { isDefined } from '~/utils/isDefined';
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';

export type SingleRecordSelectMenuItemsWithSearchProps = {
excludedRelationRecordIds?: string[];
excludedRecordIds?: string[];
onCreate?: ((searchInput?: string) => void) | (() => void);
objectNameSingular: string;
recordPickerInstanceId?: string;
selectedRelationRecordIds: string[];
selectedRecordIds: string[];
dropdownPlacement?: Placement | null;
} & Pick<
SingleRecordSelectMenuItemsProps,
Expand All @@ -32,13 +32,13 @@ export type SingleRecordSelectMenuItemsWithSearchProps = {
export const SingleRecordSelectMenuItemsWithSearch = ({
EmptyIcon,
emptyLabel,
excludedRelationRecordIds,
excludedRecordIds,
onCancel,
onCreate,
onRecordSelected,
objectNameSingular,
recordPickerInstanceId = 'relation-picker',
selectedRelationRecordIds,
recordPickerInstanceId = 'record-picker',
selectedRecordIds,
dropdownPlacement,
}: SingleRecordSelectMenuItemsWithSearchProps) => {
const { handleSearchFilterChange } = useRecordSelectSearch({
Expand All @@ -47,8 +47,8 @@ export const SingleRecordSelectMenuItemsWithSearch = ({

const { records, recordPickerSearchFilter } = useRecordPickerRecordsOptions({
objectNameSingular,
selectedRelationRecordIds,
excludedRelationRecordIds,
selectedRecordIds,
excludedRecordIds,
});

const createNewButton = isDefined(onCreate) && (
Expand All @@ -68,7 +68,7 @@ export const SingleRecordSelectMenuItemsWithSearch = ({
? records.recordsToSelect[0]
: undefined
}
shouldSelectEmptyOption={selectedRelationRecordIds?.length === 0}
shouldSelectEmptyOption={selectedRecordIds?.length === 0}
hotkeyScope={recordPickerInstanceId}
isFiltered={!!recordPickerSearchFilter}
{...{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const meta: Meta<typeof SingleRecordSelect> = {
],
args: {
objectNameSingular: CoreObjectNameSingular.WorkspaceMember,
selectedRelationRecordIds: [],
selectedRecordIds: [],
},
argTypes: {
selectedRecord: {
Expand All @@ -57,7 +57,7 @@ type Story = StoryObj<typeof SingleRecordSelect>;

export const Default: Story = {};

export const WithSelectedEntity: Story = {
export const WithSelectedRecord: Story = {
args: { selectedRecord: records[2] },
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ describe('useRecordSelectSearch', () => {
it('should update searchFilter after change event', async () => {
const { result } = renderHook(
() => {
const entitySelectSearchHook = useRecordSelectSearch({
const recordSelectSearchHook = useRecordSelectSearch({
recordPickerInstanceId: instanceId,
});
const internallyStoredFilter = useRecoilComponentValueV2(
recordPickerSearchFilterComponentState,
instanceId,
);
return { entitySelectSearchHook, internallyStoredFilter };
return { recordSelectSearchHook, internallyStoredFilter };
},
{
wrapper: Wrapper,
Expand All @@ -35,7 +35,7 @@ describe('useRecordSelectSearch', () => {
const filter = 'value';

act(() => {
result.current.entitySelectSearchHook.handleSearchFilterChange({
result.current.recordSelectSearchHook.handleSearchFilterChange({
currentTarget: { value: filter },
} as ChangeEvent<HTMLInputElement>);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { recordPickerPreselectedIdComponentState } from '@/object-record/relatio
import { recordPickerSearchFilterComponentState } from '@/object-record/relation-picker/states/recordPickerSearchFilterComponentState';
import { useSetRecoilComponentStateV2 } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentStateV2';

export const useRelationPicker = ({
export const useRecordPicker = ({
recordPickerInstanceId,
}: {
recordPickerInstanceId?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
import { RecordPickerComponentInstanceContext } from '@/object-record/relation-picker/states/contexts/RecordPickerComponentInstanceContext';
import { recordPickerSearchFilterComponentState } from '@/object-record/relation-picker/states/recordPickerSearchFilterComponentState';
import { useFilteredSearchRecordQuery } from '@/search/hooks/useFilteredSearchRecordQuery';
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';

export const useRecordPickerRecordsOptions = ({
objectNameSingular,
selectedRelationRecordIds = [],
excludedRelationRecordIds = [],
selectedRecordIds = [],
excludedRecordIds = [],
}: {
objectNameSingular: string;
selectedRelationRecordIds?: string[];
excludedRelationRecordIds?: string[];
selectedRecordIds?: string[];
excludedRecordIds?: string[];
}) => {
const instanceId = useAvailableComponentInstanceIdOrThrow(
RecordPickerComponentInstanceContext,
);

const recordPickerSearchFilter = useRecoilComponentValueV2(
recordPickerSearchFilterComponentState,
instanceId,
);

const records = useFilteredSearchRecordQuery({
searchFilter: recordPickerSearchFilter,
selectedIds: selectedRelationRecordIds,
excludeRecordIds: excludedRelationRecordIds,
selectedIds: selectedRecordIds,
excludedRecordIds: excludedRecordIds,
objectNameSingular,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useDebouncedCallback } from 'use-debounce';

import { useRelationPicker } from '@/object-record/relation-picker/hooks/useRecordPicker';
import { useRecordPicker } from '@/object-record/relation-picker/hooks/useRecordPicker';

export const useRecordSelectSearch = ({
recordPickerInstanceId,
}: {
recordPickerInstanceId?: string;
} = {}) => {
const { setRecordPickerSearchFilter, setRecordPickerPreselectedId } =
useRelationPicker({ recordPickerInstanceId });
useRecordPicker({ recordPickerInstanceId });

const debouncedSetSearchFilter = useDebouncedCallback(
setRecordPickerSearchFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ export const getRecordChipGenerators = (
labelIdentifierFieldMetadataItem?.id === fieldMetadataItem.id;

const currentObjectNameSingular = objectMetadataItem.nameSingular;
const fieldobjectNameSingular =
const fieldObjectNameSingular =
fieldMetadataItem.relationDefinition?.targetObjectMetadata
.nameSingular ?? undefined;

const objectNameSingularToFind = isLabelIdentifier
? currentObjectNameSingular
: fieldobjectNameSingular;
: fieldObjectNameSingular;

const objectMetadataItemToUse = objectMetadataItems.find(
(objectMetadataItem) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { isDefined } from '~/utils/isDefined';
export const useFilteredSearchRecordQuery = ({
selectedIds,
limit,
excludeRecordIds = [],
excludedRecordIds = [],
objectNameSingular,
searchFilter,
}: {
selectedIds: string[];
limit?: number;
excludeRecordIds?: string[];
excludedRecordIds?: string[];
objectNameSingular: string;
searchFilter?: string;
}): RecordsForMultipleRecordSelect<RecordForSelect> => {
Expand Down Expand Up @@ -50,7 +50,7 @@ export const useFilteredSearchRecordQuery = ({
searchInput: searchFilter,
});

const notFilterIds = [...selectedIds, ...excludeRecordIds];
const notFilterIds = [...selectedIds, ...excludedRecordIds];
const notFilter = notFilterIds.length
? { not: { id: { in: notFilterIds } } }
: undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RecordPickerComponentInstanceContext } from '@/object-record/relation-p

export const RecordPickerDecorator: Decorator = (Story) => (
<RecordPickerComponentInstanceContext.Provider
value={{ instanceId: 'relation-picker' }}
value={{ instanceId: 'record-picker' }}
>
<Story />
</RecordPickerComponentInstanceContext.Provider>
Expand Down

0 comments on commit 414b586

Please sign in to comment.