Skip to content

Commit

Permalink
Replace entityId by recordId in the front end. (#6355)
Browse files Browse the repository at this point in the history
Hey @lucasbordeau, I replaced every `entityId` with `recordId` in the
frontend.

### Some clarifications:

1. At [this
line](ehconitin@0b207d2#diff-b4f415dd1f060307ad61f64394ee96b2912f6015e26c7fd2eab4b8c6a84d2d07L14),
I changed `recordId` to `selectedRecordId` because that component has
`entityId` defined in code at [this
line](ehconitin@0b207d2#diff-b4f415dd1f060307ad61f64394ee96b2912f6015e26c7fd2eab4b8c6a84d2d07L55)
which was to be changed to `recordId`. To avoid repeated constants, I
changed the arguments to `selectedRecordIds`.

2. At the following links:
- [File
1](ehconitin@0b207d2#diff-52b780bdd4cfc582ca7e1b457dbbd63733bfbb7790fc421054bbd2dbf0389e16)
- [File
2](ehconitin@0b207d2#diff-6d47cb9a59dfcf6b1495937084ae799a61da6afccb21208f04ce8e1f5afca0e4)
- [File
3](ehconitin@0b207d2#diff-821815783f9968f1da3cd437fc9d1d1666d12dc331d279cc5fbd9817bc2df2bf)

It seems to be the tests. As I can see, it is checking for both
`objectFilterDropdownSelectedEntityIdState` and
`objectFilterDropdownSelectedRecordIdsState`. Since `entityIds` are
supposed to be removed and `recordedId` state is already being checked,
I commented out all the `entityidState` code. If they are to be removed
or uncommented, please let me know, and I will do as expected.

---------

Co-authored-by: Félix Malfait <[email protected]>
  • Loading branch information
ehconitin and FelixMalfait authored Aug 7, 2024
1 parent 0c99bfb commit a794131
Show file tree
Hide file tree
Showing 102 changed files with 303 additions and 310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const CalendarEventDetails = ({
<StyledPropertyBox key={fieldName}>
<FieldContext.Provider
value={{
entityId: calendarEvent.id,
recordId: calendarEvent.id,
hotkeyScope: 'calendar-event-details',
recoilScopeId: `${calendarEvent.id}-${fieldName}`,
isLabelIdentifier: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const EventFieldDiffValue = ({
<StyledEventFieldDiffValue>
<FieldContext.Provider
value={{
entityId: diffArtificialRecordStoreId,
recordId: diffArtificialRecordStoreId,
isLabelIdentifier: isLabelIdentifierField({
fieldMetadataItem,
objectMetadataItem: mainObjectMetadataItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const useFieldContext = ({
basePathToShowPage: isLabelIdentifier
? basePathToShowPage
: undefined,
entityId: objectRecordId,
recordId: objectRecordId,
recoilScopeId: objectRecordId + fieldMetadataItem.id,
isLabelIdentifier,
fieldDefinition: formatFieldMetadataItemAsColumnDefinition({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,31 +178,33 @@ describe('useFilterDropdown', () => {
});
});

it('should set objectFilterDropdownSelectedEntityId', async () => {
const mockResult = 'value';
it('should set objectFilterDropdownSelectedRecordId', async () => {
const mockResult = ['value'];
const { result } = renderHook(() => {
useFilterDropdown({ filterDropdownId });
const { objectFilterDropdownSelectedEntityIdState } =
const { objectFilterDropdownSelectedRecordIdsState } =
useFilterDropdownStates(filterDropdownId);

const [
objectFilterDropdownSelectedEntityId,
setObjectFilterDropdownSelectedEntityId,
] = useRecoilState(objectFilterDropdownSelectedEntityIdState);
objectFilterDropdownSelectedRecordIds,
setObjectFilterDropdownSelectedRecordIds,
] = useRecoilState(objectFilterDropdownSelectedRecordIdsState);
return {
objectFilterDropdownSelectedEntityId,
setObjectFilterDropdownSelectedEntityId,
objectFilterDropdownSelectedRecordIds,
setObjectFilterDropdownSelectedRecordIds,
};
}, renderHookConfig);

expect(result.current.objectFilterDropdownSelectedEntityId).toBeNull();
expect(
JSON.stringify(result.current.objectFilterDropdownSelectedRecordIds),
).toBe(JSON.stringify([]));

act(() => {
result.current.setObjectFilterDropdownSelectedEntityId(mockResult);
result.current.setObjectFilterDropdownSelectedRecordIds(mockResult);
});

await waitFor(() => {
expect(result.current.objectFilterDropdownSelectedEntityId).toBe(
expect(result.current.objectFilterDropdownSelectedRecordIds).toBe(
mockResult,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const useFilterDropdown = (props?: UseFilterDropdownProps) => {
availableFilterDefinitionsState,
filterDefinitionUsedInDropdownState,
objectFilterDropdownSearchInputState,
objectFilterDropdownSelectedEntityIdState,
objectFilterDropdownSelectedRecordIdsState,
objectFilterDropdownSelectedOptionValuesState,
isObjectFilterDropdownOperandSelectUnfoldedState,
Expand All @@ -46,13 +45,11 @@ export const useFilterDropdown = (props?: UseFilterDropdownProps) => {
({ set }) =>
() => {
set(objectFilterDropdownSearchInputState, '');
set(objectFilterDropdownSelectedEntityIdState, null);
set(objectFilterDropdownSelectedRecordIdsState, []);
set(selectedFilterState, undefined);
},
[
objectFilterDropdownSearchInputState,
objectFilterDropdownSelectedEntityIdState,
objectFilterDropdownSelectedRecordIdsState,
selectedFilterState,
],
Expand All @@ -62,7 +59,6 @@ export const useFilterDropdown = (props?: UseFilterDropdownProps) => {
({ set }) =>
() => {
set(objectFilterDropdownSearchInputState, '');
set(objectFilterDropdownSelectedEntityIdState, null);
set(objectFilterDropdownSelectedRecordIdsState, []);
set(selectedFilterState, undefined);
set(filterDefinitionUsedInDropdownState, null);
Expand All @@ -71,7 +67,6 @@ export const useFilterDropdown = (props?: UseFilterDropdownProps) => {
[
filterDefinitionUsedInDropdownState,
objectFilterDropdownSearchInputState,
objectFilterDropdownSelectedEntityIdState,
objectFilterDropdownSelectedRecordIdsState,
selectedFilterState,
selectedOperandInDropdownState,
Expand All @@ -91,9 +86,6 @@ export const useFilterDropdown = (props?: UseFilterDropdownProps) => {
const setObjectFilterDropdownSearchInput = useSetRecoilState(
objectFilterDropdownSearchInputState,
);
const setObjectFilterDropdownSelectedEntityId = useSetRecoilState(
objectFilterDropdownSelectedEntityIdState,
);
const setObjectFilterDropdownSelectedRecordIds = useSetRecoilState(
objectFilterDropdownSelectedRecordIdsState,
);
Expand All @@ -117,7 +109,7 @@ export const useFilterDropdown = (props?: UseFilterDropdownProps) => {
setAvailableFilterDefinitions,
setFilterDefinitionUsedInDropdown,
setObjectFilterDropdownSearchInput,
setObjectFilterDropdownSelectedEntityId,
// setObjectFilterDropdownSelectedEntityId,
setObjectFilterDropdownSelectedRecordIds,
setObjectFilterDropdownSelectedOptionValues,
setIsObjectFilterDropdownOperandSelectUnfolded,
Expand All @@ -127,7 +119,7 @@ export const useFilterDropdown = (props?: UseFilterDropdownProps) => {
availableFilterDefinitionsState,
filterDefinitionUsedInDropdownState,
objectFilterDropdownSearchInputState,
objectFilterDropdownSelectedEntityIdState,
// objectFilterDropdownSelectedEntityIdState,
objectFilterDropdownSelectedRecordIdsState,
objectFilterDropdownSelectedOptionValuesState,
isObjectFilterDropdownOperandSelectUnfoldedState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { filterDefinitionUsedInDropdownComponentState } from '@/object-record/ob
import { isObjectFilterDropdownOperandSelectUnfoldedComponentState } from '@/object-record/object-filter-dropdown/states/isObjectFilterDropdownOperandSelectUnfoldedComponentState';
import { isObjectFilterDropdownUnfoldedComponentState } from '@/object-record/object-filter-dropdown/states/isObjectFilterDropdownUnfoldedComponentState';
import { objectFilterDropdownSearchInputComponentState } from '@/object-record/object-filter-dropdown/states/objectFilterDropdownSearchInputComponentState';
import { objectFilterDropdownSelectedEntityIdComponentState } from '@/object-record/object-filter-dropdown/states/objectFilterDropdownSelectedEntityIdComponentState';
import { objectFilterDropdownSelectedOptionValuesComponentState } from '@/object-record/object-filter-dropdown/states/objectFilterDropdownSelectedOptionValuesComponentState';
import { objectFilterDropdownSelectedRecordIdsComponentState } from '@/object-record/object-filter-dropdown/states/objectFilterDropdownSelectedRecordIdsComponentState';
import { onFilterSelectComponentState } from '@/object-record/object-filter-dropdown/states/onFilterSelectComponentState';
Expand All @@ -27,11 +26,6 @@ export const useFilterDropdownStates = (scopeId: string) => {
scopeId,
);

const objectFilterDropdownSelectedEntityIdState = extractComponentState(
objectFilterDropdownSelectedEntityIdComponentState,
scopeId,
);

const objectFilterDropdownSelectedRecordIdsState = extractComponentState(
objectFilterDropdownSelectedRecordIdsComponentState,
scopeId,
Expand Down Expand Up @@ -72,7 +66,6 @@ export const useFilterDropdownStates = (scopeId: string) => {
availableFilterDefinitionsState,
filterDefinitionUsedInDropdownState,
objectFilterDropdownSearchInputState,
objectFilterDropdownSelectedEntityIdState,
objectFilterDropdownSelectedRecordIdsState,
objectFilterDropdownSelectedOptionValuesState,
isObjectFilterDropdownOperandSelectUnfoldedState,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export const RecordBoardCard = () => {
>
<FieldContext.Provider
value={{
entityId: recordId,
recordId,
maxWidth: 156,
recoilScopeId: recordId + fieldDefinition.fieldMetadataId,
isLabelIdentifier: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type RecordUpdateHook = () => [
export type GenericFieldContextType = {
fieldDefinition: FieldDefinition<FieldMetadata>;
useUpdateRecord?: RecordUpdateHook;
entityId: string;
recordId: string;
recoilScopeId?: string;
hotkeyScope: string;
isLabelIdentifier: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import { useGetButtonIcon } from '@/object-record/record-field/hooks/useGetButto
import { FieldDefinition } from '@/object-record/record-field/types/FieldDefinition';
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';

const entityId = 'entityId';
const recordId = 'recordId';

const getWrapper =
(fieldDefinition: FieldDefinition<FieldMetadata>) =>
({ children }: { children: ReactNode }) => (
<FieldContext.Provider
value={{
fieldDefinition,
entityId,
recordId,
hotkeyScope: 'hotkeyScope',
isLabelIdentifier: false,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { FieldContext } from '@/object-record/record-field/contexts/FieldContext
import { useIsFieldEmpty } from '@/object-record/record-field/hooks/useIsFieldEmpty';
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';

const entityId = 'entityId';
const recordId = 'recordId';

const Wrapper = ({ children }: { children: ReactNode }) => (
<FieldContext.Provider
value={{
fieldDefinition: phoneFieldDefinition,
entityId,
recordId,
hotkeyScope: 'hotkeyScope',
isLabelIdentifier: false,
}}
Expand All @@ -27,7 +27,7 @@ describe('useIsFieldEmpty', () => {
const { result } = renderHook(
() => {
const setFieldState = useSetRecoilState(
recordStoreFamilyState(entityId),
recordStoreFamilyState(recordId),
);
return {
setFieldState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import { useIsFieldInputOnly } from '@/object-record/record-field/hooks/useIsFie
import { FieldDefinition } from '@/object-record/record-field/types/FieldDefinition';
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';

const entityId = 'entityId';
const recordId = 'recordId';

const getWrapper =
(fieldDefinition: FieldDefinition<FieldMetadata>) =>
({ children }: { children: ReactNode }) => (
<FieldContext.Provider
value={{
fieldDefinition,
entityId,
recordId,
hotkeyScope: 'hotkeyScope',
isLabelIdentifier: false,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ const mocks: MockedResponse[] = [
{
request: {
query,
variables: { idToUpdate: 'entityId', input: { phone: '+1 123 456' } },
variables: { idToUpdate: 'recordId', input: { phone: '+1 123 456' } },
},
result: jest.fn(() => ({
data: {
updatePerson: {
id: 'entityId',
id: 'recordId',
},
},
})),
Expand All @@ -69,21 +69,21 @@ const mocks: MockedResponse[] = [
request: {
query,
variables: {
idToUpdate: 'entityId',
idToUpdate: 'recordId',
input: { companyId: 'companyId' },
},
},
result: jest.fn(() => ({
data: {
updatePerson: {
id: 'entityId',
id: 'recordId',
},
},
})),
},
];

const entityId = 'entityId';
const recordId = 'recordId';

const getWrapper =
(fieldDefinition: FieldDefinition<FieldMetadata>) =>
Expand All @@ -108,7 +108,7 @@ const getWrapper =
<FieldContext.Provider
value={{
fieldDefinition,
entityId,
recordId,
hotkeyScope: 'hotkeyScope',
isLabelIdentifier: false,
useUpdateRecord: useUpdateOneRecordMutation,
Expand All @@ -128,7 +128,7 @@ describe('usePersistField', () => {
const { result } = renderHook(
() => {
const entityFields = useRecoilValue(
recordStoreFamilySelector({ recordId: entityId, fieldName: 'phone' }),
recordStoreFamilySelector({ recordId, fieldName: 'phone' }),
);

return {
Expand All @@ -153,7 +153,7 @@ describe('usePersistField', () => {
() => {
const entityFields = useRecoilValue(
recordStoreFamilySelector({
recordId: entityId,
recordId,
fieldName: 'company',
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '@/object-record/record-field/contexts/FieldContext';
import { useToggleEditOnlyInput } from '@/object-record/record-field/hooks/useToggleEditOnlyInput';

const entityId = 'entityId';
const recordId = 'recordId';

const mocks: MockedResponse[] = [
{
Expand Down Expand Up @@ -66,14 +66,14 @@ const mocks: MockedResponse[] = [
}
`,
variables: {
idToUpdate: 'entityId',
idToUpdate: 'recordId',
input: { idealCustomerProfile: true },
},
},
result: jest.fn(() => ({
data: {
updateWorkspaceMember: {
id: 'entityId',
id: 'recordId',
},
},
})),
Expand Down Expand Up @@ -101,7 +101,7 @@ const Wrapper = ({ children }: { children: ReactNode }) => {
<FieldContext.Provider
value={{
fieldDefinition: booleanFieldDefinition,
entityId,
recordId,
hotkeyScope: 'hotkeyScope',
isLabelIdentifier: false,
useUpdateRecord: useUpdateOneRecordMutation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { FieldContext } from '../contexts/FieldContext';

export const useClearField = () => {
const {
entityId,
recordId,
fieldDefinition,
useUpdateRecord = () => [],
} = useContext(FieldContext);
Expand Down Expand Up @@ -45,22 +45,22 @@ export const useClearField = () => {
const emptyFieldValue = generateEmptyFieldValue(foundFieldMetadataItem);

set(
recordStoreFamilySelector({ recordId: entityId, fieldName }),
recordStoreFamilySelector({ recordId, fieldName }),
emptyFieldValue,
);

setRecordFieldValue(entityId, fieldName, emptyFieldValue);
setRecordFieldValue(recordId, fieldName, emptyFieldValue);

updateRecord?.({
variables: {
where: { id: entityId },
where: { id: recordId },
updateOneRecordInput: {
[fieldName]: emptyFieldValue,
},
},
});
},
[entityId, fieldDefinition, updateRecord, setRecordFieldValue],
[recordId, fieldDefinition, updateRecord, setRecordFieldValue],
);

return clearField;
Expand Down
Loading

0 comments on commit a794131

Please sign in to comment.