Fix/object record and metadata naming (#2763)

* Fixed object-record and object-metadata naming

* Fix post merge

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Lucas Bordeau 2023-11-29 13:45:57 +01:00 committed by GitHub
parent 3617abb0e6
commit d855a42eca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
99 changed files with 614 additions and 691 deletions

View File

@ -6,7 +6,7 @@ import { isNonEmptyString } from '@sniptt/guards';
import debounce from 'lodash.debounce';
import { Activity } from '@/activities/types/Activity';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { BlockEditor } from '@/ui/input/editor/components/BlockEditor';
const StyledBlockNoteStyledContainer = styled.div`
@ -23,7 +23,7 @@ export const ActivityBodyEditor = ({
onChange,
}: ActivityBodyEditorProps) => {
const [body, setBody] = useState<string | null>(null);
const { updateOneObject } = useUpdateOneObjectRecord({
const { updateOneRecord } = useUpdateOneRecord({
objectNameSingular: 'activity',
});
@ -36,7 +36,7 @@ export const ActivityBodyEditor = ({
const debounceOnChange = useMemo(() => {
const onInternalChange = (activityBody: string) => {
setBody(activityBody);
updateOneObject?.({
updateOneRecord?.({
idToUpdate: activity.id,
input: {
body: activityBody,
@ -45,7 +45,7 @@ export const ActivityBodyEditor = ({
};
return debounce(onInternalChange, 200);
}, [updateOneObject, activity.id]);
}, [updateOneRecord, activity.id]);
const editor: BlockNoteEditor | null = useBlockNote({
initialContent:

View File

@ -7,8 +7,8 @@ import { Comment } from '@/activities/comment/Comment';
import { Activity } from '@/activities/types/Activity';
import { Comment as CommentType } from '@/activities/types/Comment';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { useCreateOneObjectRecord } from '@/object-record/hooks/useCreateOneObjectRecord';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import {
AutosizeTextInput,
AutosizeTextInputVariant,
@ -60,13 +60,13 @@ export const ActivityComments = ({
activity,
scrollableContainerRef,
}: ActivityCommentsProps) => {
const { createOneObject } = useCreateOneObjectRecord({
const { createOneRecord: createOneComment } = useCreateOneRecord({
objectNameSingular: 'comment',
});
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
const { objects: comments } = useFindManyObjectRecords({
const { records: comments } = useFindManyRecords({
objectNamePlural: 'comments',
filter: {
activityId: {
@ -84,7 +84,7 @@ export const ActivityComments = ({
return;
}
createOneObject?.({
createOneComment?.({
id: v4(),
authorId: currentWorkspaceMember?.id ?? '',
activityId: activity?.id ?? '',

View File

@ -10,7 +10,7 @@ import { ActivityTarget } from '@/activities/types/ActivityTarget';
import { Comment } from '@/activities/types/Comment';
import { GraphQLActivity } from '@/activities/types/GraphQLActivity';
import { useFieldContext } from '@/object-record/hooks/useFieldContext';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { RecordInlineCell } from '@/ui/object/record-inline-cell/components/RecordInlineCell';
import { PropertyBox } from '@/ui/object/record-inline-cell/property-box/components/PropertyBox';
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
@ -80,7 +80,7 @@ export const ActivityEditor = ({
const [title, setTitle] = useState<string | null>(activity.title ?? '');
const containerRef = useRef<HTMLDivElement>(null);
const { updateOneObject } = useUpdateOneObjectRecord<Activity>({
const { updateOneRecord: updateOneActivity } = useUpdateOneRecord<Activity>({
objectNameSingular: 'activity',
});
@ -103,18 +103,18 @@ export const ActivityEditor = ({
const updateTitle = useCallback(
(newTitle: string) => {
updateOneObject?.({
updateOneActivity?.({
idToUpdate: activity.id,
input: {
title: newTitle ?? '',
},
});
},
[activity.id, updateOneObject],
[activity.id, updateOneActivity],
);
const handleActivityCompletionChange = useCallback(
(value: boolean) => {
updateOneObject?.({
updateOneActivity?.({
idToUpdate: activity.id,
input: {
completedAt: value ? new Date().toISOString() : null,
@ -122,7 +122,7 @@ export const ActivityEditor = ({
forceRefetch: true,
});
},
[activity.id, updateOneObject],
[activity.id, updateOneActivity],
);
const debouncedUpdateTitle = debounce(updateTitle, 200);

View File

@ -1,6 +1,6 @@
import { ActivityTarget } from '@/activities/types/ActivityTarget';
import { useCreateOneObjectRecord } from '@/object-record/hooks/useCreateOneObjectRecord';
import { useDeleteOneObjectRecord } from '@/object-record/hooks/useDeleteOneObjectRecord';
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
import { useDeleteOneRecord } from '@/object-record/hooks/useDeleteOneRecord';
export const useHandleCheckableActivityTargetChange = ({
activityId,
@ -9,10 +9,11 @@ export const useHandleCheckableActivityTargetChange = ({
activityId: string;
currentActivityTargets: any[];
}) => {
const { createOneObject } = useCreateOneObjectRecord<ActivityTarget>({
objectNameSingular: 'activityTarget',
});
const { deleteOneObject } = useDeleteOneObjectRecord({
const { createOneRecord: createOneActivityTarget } =
useCreateOneRecord<ActivityTarget>({
objectNameSingular: 'activityTarget',
});
const { deleteOneRecord: deleteOneActivityTarget } = useDeleteOneRecord({
objectNameSingular: 'activityTarget',
});
@ -54,7 +55,7 @@ export const useHandleCheckableActivityTargetChange = ({
: null;
const entity = entityFromToSelect ?? entityFromSelected;
createOneObject?.({
createOneActivityTarget?.({
activityId: activityId,
companyId: entity.record.__typename === 'Company' ? entity.id : null,
personId: entity.record.__typename === 'Person' ? entity.id : null,
@ -67,7 +68,7 @@ export const useHandleCheckableActivityTargetChange = ({
const currentActivityTargetId = currentActivityTargets.filter(
({ companyId, personId }) => companyId === id || personId === id,
)[0].id;
deleteOneObject?.(currentActivityTargetId);
deleteOneActivityTarget?.(currentActivityTargetId);
});
}
};

View File

@ -4,7 +4,7 @@ import { useRecoilState, useRecoilValue } from 'recoil';
import { Activity, ActivityType } from '@/activities/types/Activity';
import { ActivityTarget } from '@/activities/types/ActivityTarget';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { useCreateOneObjectRecord } from '@/object-record/hooks/useCreateOneObjectRecord';
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
import { useRightDrawer } from '@/ui/layout/right-drawer/hooks/useRightDrawer';
import { RightDrawerHotkeyScope } from '@/ui/layout/right-drawer/types/RightDrawerHotkeyScope';
import { RightDrawerPages } from '@/ui/layout/right-drawer/types/RightDrawerPages';
@ -17,14 +17,13 @@ import { getTargetableEntitiesWithParents } from '../utils/getTargetableEntities
export const useOpenCreateActivityDrawer = () => {
const { openRightDrawer } = useRightDrawer();
const { createOneObject: createOneActivityTarget } =
useCreateOneObjectRecord<ActivityTarget>({
const { createOneRecord: createOneActivityTarget } =
useCreateOneRecord<ActivityTarget>({
objectNameSingular: 'activityTarget',
});
const { createOneObject: createOneActivity } =
useCreateOneObjectRecord<Activity>({
objectNameSingular: 'activity',
});
const { createOneRecord: createOneActivity } = useCreateOneRecord<Activity>({
objectNameSingular: 'activity',
});
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
const setHotkeyScope = useSetHotkeyScope();

View File

@ -55,13 +55,14 @@ export const ActivityTargetInlineCellEditMode = ({
[initialPeopleIds, initialCompanyIds],
);
const { findManyQuery: findManyPeopleQuery } = useObjectMetadataItem({
const { findManyRecordsQuery: findManyPeopleQuery } = useObjectMetadataItem({
objectNameSingular: 'person',
});
const { findManyQuery: findManyCompaniesQuery } = useObjectMetadataItem({
objectNameSingular: 'company',
});
const { findManyRecordsQuery: findManyCompaniesQuery } =
useObjectMetadataItem({
objectNameSingular: 'company',
});
const useFindManyPeopleQuery = (options: any) =>
useQuery(findManyPeopleQuery, options);

View File

@ -2,7 +2,7 @@ import { ActivityTargetChips } from '@/activities/components/ActivityTargetChips
import { ActivityTargetInlineCellEditMode } from '@/activities/inline-cell/components/ActivityTargetInlineCellEditMode';
import { ActivityTarget } from '@/activities/types/ActivityTarget';
import { GraphQLActivity } from '@/activities/types/GraphQLActivity';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { IconArrowUpRight, IconPencil } from '@/ui/display/icon';
import { RelationPickerHotkeyScope } from '@/ui/input/relation-picker/types/RelationPickerHotkeyScope';
import { RecordInlineCellContainer } from '@/ui/object/record-inline-cell/components/RecordInlineCellContainer';
@ -27,12 +27,10 @@ export const ActivityTargetsInlineCell = ({
(activityTarget) => activityTarget.node.id,
) ?? [];
const { objects: activityTargets } = useFindManyObjectRecords<ActivityTarget>(
{
objectNamePlural: 'activityTargets',
filter: { id: { in: activityTargetIds } },
},
);
const { records: activityTargets } = useFindManyRecords<ActivityTarget>({
objectNamePlural: 'activityTargets',
filter: { id: { in: activityTargetIds } },
});
return (
<RecoilScope CustomRecoilScopeContext={FieldRecoilScopeContext}>

View File

@ -1,10 +1,10 @@
import { Note } from '@/activities/types/Note';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { ActivityTargetableEntity } from '../../types/ActivityTargetableEntity';
export const useNotes = (entity: ActivityTargetableEntity) => {
const { objects: activityTargets } = useFindManyObjectRecords({
const { records: activityTargets } = useFindManyRecords({
objectNamePlural: 'activityTargets',
filter: {
[entity.type === 'Company' ? 'companyId' : 'personId']: { eq: entity.id },
@ -21,7 +21,7 @@ export const useNotes = (entity: ActivityTargetableEntity) => {
createdAt: 'AscNullsFirst',
};
const { objects: notes } = useFindManyObjectRecords({
const { records: notes } = useFindManyRecords({
skip: !activityTargets?.length,
objectNamePlural: 'activities',
filter,

View File

@ -1,6 +1,6 @@
import { useRecoilState } from 'recoil';
import { useDeleteOneObjectRecord } from '@/object-record/hooks/useDeleteOneObjectRecord';
import { useDeleteOneRecord } from '@/object-record/hooks/useDeleteOneRecord';
import { IconTrash } from '@/ui/display/icon';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
import { isRightDrawerOpenState } from '@/ui/layout/right-drawer/states/isRightDrawerOpenState';
@ -11,12 +11,12 @@ type ActivityActionBarProps = {
export const ActivityActionBar = ({ activityId }: ActivityActionBarProps) => {
const [, setIsRightDrawerOpen] = useRecoilState(isRightDrawerOpenState);
const { deleteOneObject } = useDeleteOneObjectRecord({
const { deleteOneRecord: deleteOneActivity } = useDeleteOneRecord({
objectNameSingular: 'activity',
});
const deleteActivity = () => {
deleteOneObject?.(activityId);
deleteOneActivity?.(activityId);
setIsRightDrawerOpen(false);
};

View File

@ -4,7 +4,7 @@ import { useRecoilState } from 'recoil';
import { ActivityEditor } from '@/activities/components/ActivityEditor';
import { Activity } from '@/activities/types/Activity';
import { useFindOneObjectRecord } from '@/object-record/hooks/useFindOneObjectRecord';
import { useFindOneRecord } from '@/object-record/hooks/useFindOneRecord';
import { entityFieldsFamilyState } from '@/ui/object/field/states/entityFieldsFamilyState';
import '@blocknote/core/style.css';
@ -34,7 +34,7 @@ export const RightDrawerActivity = ({
entityFieldsFamilyState(activityId),
);
const { object: activity } = useFindOneObjectRecord({
const { record: activity } = useFindOneRecord({
objectNameSingular: 'activity',
objectRecordId: activityId,
skip: !activityId,

View File

@ -6,7 +6,7 @@ import { ActivityTargetChips } from '@/activities/components/ActivityTargetChips
import { useOpenActivityRightDrawer } from '@/activities/hooks/useOpenActivityRightDrawer';
import { ActivityTarget } from '@/activities/types/ActivityTarget';
import { GraphQLActivity } from '@/activities/types/GraphQLActivity';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { IconCalendar, IconComment } from '@/ui/display/icon';
import { OverflowingTextWithTooltip } from '@/ui/display/tooltip/OverflowingTextWithTooltip';
import { Checkbox, CheckboxShape } from '@/ui/input/components/Checkbox';
@ -81,12 +81,10 @@ export const TaskRow = ({
(activityTarget) => activityTarget.node.id,
) ?? [];
const { objects: activityTargets } = useFindManyObjectRecords<ActivityTarget>(
{
objectNamePlural: 'activityTargets',
filter: { id: { in: activityTargetIds } },
},
);
const { records: activityTargets } = useFindManyRecords<ActivityTarget>({
objectNamePlural: 'activityTargets',
filter: { id: { in: activityTargetIds } },
});
return (
<StyledContainer

View File

@ -1,19 +1,19 @@
import { useCallback } from 'react';
import { Activity } from '@/activities/types/Activity';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
type Task = Pick<Activity, 'id' | 'completedAt'>;
export const useCompleteTask = (task: Task) => {
const { updateOneObject } = useUpdateOneObjectRecord({
const { updateOneRecord: updateOneActivity } = useUpdateOneRecord({
objectNameSingular: 'activity',
});
const completeTask = useCallback(
(value: boolean) => {
const completedAt = value ? new Date().toISOString() : null;
updateOneObject?.({
updateOneActivity?.({
idToUpdate: task.id,
input: {
completedAt,
@ -21,7 +21,7 @@ export const useCompleteTask = (task: Task) => {
forceRefetch: true,
});
},
[task.id, updateOneObject],
[task.id, updateOneActivity],
);
return {

View File

@ -2,13 +2,13 @@ import { DateTime } from 'luxon';
import { useRecoilValue } from 'recoil';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { parseDate } from '~/utils/date-utils';
export const useCurrentUserTaskCount = () => {
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
const { objects } = useFindManyObjectRecords({
const { records: tasks } = useFindManyRecords({
objectNamePlural: 'activities',
filter: {
type: { eq: 'Task' },
@ -17,7 +17,7 @@ export const useCurrentUserTaskCount = () => {
},
});
const currentUserDueTaskCount = objects.filter((task) => {
const currentUserDueTaskCount = tasks.filter((task) => {
if (!task.dueAt) {
return false;
}

View File

@ -4,7 +4,7 @@ import { undefined } from 'zod';
import { Activity } from '@/activities/types/Activity';
import { ActivityTargetableEntity } from '@/activities/types/ActivityTargetableEntity';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { useFilterDropdown } from '@/ui/object/object-filter-dropdown/hooks/useFilterDropdown';
import { parseDate } from '~/utils/date-utils';
import { isDefined } from '~/utils/isDefined';
@ -21,7 +21,7 @@ export const useTasks = (props?: UseTasksProps) => {
filterDropdownId: filterDropdownId,
});
const { objects: activityTargets } = useFindManyObjectRecords({
const { records: activityTargets } = useFindManyRecords({
objectNamePlural: 'activityTargets',
filter: isDefined(entity)
? {
@ -32,7 +32,7 @@ export const useTasks = (props?: UseTasksProps) => {
: undefined,
});
const { objects: completeTasksData } = useFindManyObjectRecords({
const { records: completeTasksData } = useFindManyRecords({
objectNamePlural: 'activities',
skip: !entity && !selectedFilter,
filter: {
@ -56,7 +56,7 @@ export const useTasks = (props?: UseTasksProps) => {
},
});
const { objects: incompleteTaskData } = useFindManyObjectRecords({
const { records: incompleteTaskData } = useFindManyRecords({
objectNamePlural: 'activities',
skip: !entity && !selectedFilter,
filter: {

View File

@ -5,7 +5,7 @@ import { ActivityCreateButton } from '@/activities/components/ActivityCreateButt
import { useOpenCreateActivityDrawer } from '@/activities/hooks/useOpenCreateActivityDrawer';
import { Activity } from '@/activities/types/Activity';
import { ActivityTargetableEntity } from '@/activities/types/ActivityTargetableEntity';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
import { TimelineItemsContainer } from './TimelineItemsContainer';
@ -48,14 +48,14 @@ const StyledEmptyTimelineSubTitle = styled.div`
`;
export const Timeline = ({ entity }: { entity: ActivityTargetableEntity }) => {
const { objects: activityTargets, loading } = useFindManyObjectRecords({
const { records: activityTargets, loading } = useFindManyRecords({
objectNamePlural: 'activityTargets',
filter: {
[entity.type === 'Company' ? 'companyId' : 'personId']: { eq: entity.id },
},
});
const { objects: activities } = useFindManyObjectRecords({
const { records: activities } = useFindManyRecords({
skip: !activityTargets?.length,
objectNamePlural: 'activities',
filter: {

View File

@ -23,7 +23,7 @@ export const useOptimisticEffect = ({
objectNameSingular: string | undefined;
}) => {
const apolloClient = useApolloClient();
const { findManyQuery } = useObjectMetadataItem({
const { findManyRecordsQuery } = useObjectMetadataItem({
objectNameSingular,
});
@ -36,7 +36,7 @@ export const useOptimisticEffect = ({
variables: OperationVariables;
definition: OptimisticEffectDefinition;
}) => {
if (findManyQuery === EMPTY_QUERY) {
if (findManyRecordsQuery === EMPTY_QUERY) {
throw new Error(
`Trying to register an optimistic effect for unknown object ${objectNameSingular}`,
);
@ -62,7 +62,7 @@ export const useOptimisticEffect = ({
}) => {
if (objectMetadataItem) {
const existingData = cache.readQuery({
query: findManyQuery,
query: findManyRecordsQuery,
variables,
});
@ -71,7 +71,7 @@ export const useOptimisticEffect = ({
}
cache.writeQuery({
query: findManyQuery,
query: findManyRecordsQuery,
variables,
data: {
[objectMetadataItem.namePlural]: definition.resolver({

View File

@ -4,7 +4,7 @@ import { useRecoilValue } from 'recoil';
import { useOpenActivityRightDrawer } from '@/activities/hooks/useOpenActivityRightDrawer';
import { CommandMenuSelectableListEffect } from '@/command-menu/components/CommandMenuSelectableListEffect';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { Person } from '@/people/types/Person';
import { IconNotes } from '@/ui/display/icon';
import { SelectableItem } from '@/ui/layout/selectable-list/components/SelectableItem';
@ -114,7 +114,7 @@ export const CommandMenu = () => {
[toggleCommandMenu, setSearch],
);
const { objects: people } = useFindManyObjectRecords<Person>({
const { records: people } = useFindManyRecords<Person>({
skip: !isCommandMenuOpened,
objectNamePlural: 'people',
filter: {
@ -126,7 +126,7 @@ export const CommandMenu = () => {
limit: 3,
});
const { objects: companies } = useFindManyObjectRecords<Person>({
const { records: companies } = useFindManyRecords<Person>({
skip: !isCommandMenuOpened,
objectNamePlural: 'companies',
filter: {
@ -135,7 +135,7 @@ export const CommandMenu = () => {
limit: 3,
});
const { objects: activities } = useFindManyObjectRecords<Person>({
const { records: activities } = useFindManyRecords<Person>({
skip: !isCommandMenuOpened,
objectNamePlural: 'activities',
filter: {

View File

@ -68,13 +68,16 @@ export const AddPersonToCompany = ({
goBackToPreviousHotkeyScope,
} = usePreviousHotkeyScope();
const { findManyQuery, updateOneMutation, createOneMutation } =
useObjectMetadataItem({
objectNameSingular: 'person',
});
const {
findManyRecordsQuery,
updateOneRecordMutation,
createOneRecordMutation,
} = useObjectMetadataItem({
objectNameSingular: 'person',
});
const [updatePerson] = useMutation(updateOneMutation);
const [createPerson] = useMutation(createOneMutation);
const [updatePerson] = useMutation(updateOneRecordMutation);
const [createPerson] = useMutation(createOneRecordMutation);
const handlePersonSelected =
(companyId: string) => async (newPerson: EntityForSelect | null) => {
@ -86,7 +89,7 @@ export const AddPersonToCompany = ({
companyId: companyId,
},
},
refetchQueries: [getOperationName(findManyQuery) ?? ''],
refetchQueries: [getOperationName(findManyRecordsQuery) ?? ''],
});
handleClosePicker();
@ -126,7 +129,7 @@ export const AddPersonToCompany = ({
},
},
},
refetchQueries: [getOperationName(findManyQuery) ?? ''],
refetchQueries: [getOperationName(findManyRecordsQuery) ?? ''],
});
setIsCreationDropdownOpen(false);

View File

@ -2,7 +2,7 @@ import { ReactNode, useContext } from 'react';
import styled from '@emotion/styled';
import { useRecoilState } from 'recoil';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { EntityChipVariant } from '@/ui/display/chip/components/EntityChip';
import { IconEye } from '@/ui/display/icon/index';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
@ -150,8 +150,8 @@ export const CompanyBoardCard = () => {
BoardRecoilScopeContext,
);
const useUpdateOneObjectMutation: () => [(params: any) => any, any] = () => {
const { updateOneObject } = useUpdateOneObjectRecord({
const useUpdateOneRecordMutation: () => [(params: any) => any, any] = () => {
const { updateOneRecord: updateOneOpportunity } = useUpdateOneRecord({
objectNameSingular: 'opportunity',
});
@ -165,7 +165,7 @@ export const CompanyBoardCard = () => {
};
};
}) => {
updateOneObject?.({
updateOneOpportunity?.({
idToUpdate: variables.where.id,
input: variables.data,
});
@ -247,7 +247,7 @@ export const CompanyBoardCard = () => {
type: viewField.type,
metadata: viewField.metadata,
},
useUpdateEntityMutation: useUpdateOneObjectMutation,
useUpdateEntityMutation: useUpdateOneRecordMutation,
hotkeyScope: InlineCellHotkeyScope.InlineCell,
}}
>

View File

@ -4,7 +4,7 @@ import { isNonEmptyArray } from '@sniptt/guards';
import { Company } from '@/companies/types/Company';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { mapPaginatedObjectsToObjects } from '@/object-record/utils/mapPaginatedObjectsToObjects';
import { mapPaginatedRecordsToRecords } from '@/object-record/utils/mapPaginatedRecordsToRecords';
import { PeopleCard } from '@/people/components/PeopleCard';
import { AddPersonToCompany } from './AddPersonToCompany';
@ -47,11 +47,11 @@ const StyledTitle = styled.div`
`;
export const CompanyTeam = ({ company }: { company: any }) => {
const { findManyQuery } = useObjectMetadataItem({
const { findManyRecordsQuery } = useObjectMetadataItem({
objectNameSingular: 'person',
});
const { data } = useQuery(findManyQuery, {
const { data } = useQuery(findManyRecordsQuery, {
variables: {
filter: {
companyId: {
@ -61,9 +61,9 @@ export const CompanyTeam = ({ company }: { company: any }) => {
},
});
const people = mapPaginatedObjectsToObjects({
const people = mapPaginatedRecordsToRecords({
objectNamePlural: 'people',
pagedObjects: data ?? [],
pagedRecords: data ?? [],
});
const peopleIds = people.map((person) => person.id);

View File

@ -2,10 +2,10 @@ import { useCallback, useEffect, useState } from 'react';
import { useRecoilState, useRecoilValue } from 'recoil';
import { Company } from '@/companies/types/Company';
import { useComputeDefinitionsFromFieldMetadata } from '@/object-metadata/hooks/useComputeDefinitionsFromFieldMetadata';
import { useColumnDefinitionsFromFieldMetadata } from '@/object-metadata/hooks/useColumnDefinitionsFromFieldMetadata';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { PaginatedObjectTypeResults } from '@/object-record/types/PaginatedObjectTypeResults';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { PaginatedRecordTypeResults } from '@/object-record/types/PaginatedRecordTypeResults';
import { filterAvailableTableColumns } from '@/object-record/utils/filterAvailableTableColumns';
import { Opportunity } from '@/pipeline/types/Opportunity';
import { PipelineStep } from '@/pipeline/types/PipelineStep';
@ -65,7 +65,7 @@ export const HooksCompanyBoardEffect = ({
});
const { columnDefinitions, filterDefinitions, sortDefinitions } =
useComputeDefinitionsFromFieldMetadata(objectMetadataItem);
useColumnDefinitionsFromFieldMetadata(objectMetadataItem);
const [, setIsBoardLoaded] = useRecoilState(isBoardLoadedState);
@ -84,11 +84,11 @@ export const HooksCompanyBoardEffect = ({
'company-board-view',
);
useFindManyObjectRecords({
useFindManyRecords({
objectNamePlural: 'pipelineSteps',
filter: {},
onCompleted: useCallback(
(data: PaginatedObjectTypeResults<PipelineStep>) => {
(data: PaginatedRecordTypeResults<PipelineStep>) => {
setPipelineSteps(data.edges.map((edge) => edge.node));
},
[],
@ -105,34 +105,32 @@ export const HooksCompanyBoardEffect = ({
objectMetadataItem?.fields ?? [],
);
const { fetchMoreObjects: fetchMoreOpportunities } = useFindManyObjectRecords(
{
skip: !pipelineSteps.length,
objectNamePlural: 'opportunities',
filter: filter,
orderBy: orderBy,
onCompleted: useCallback(
(data: PaginatedObjectTypeResults<Opportunity>) => {
const pipelineProgresses: Array<Opportunity> = data.edges.map(
(edge) => edge.node,
);
const { fetchMoreRecords: fetchMoreOpportunities } = useFindManyRecords({
skip: !pipelineSteps.length,
objectNamePlural: 'opportunities',
filter: filter,
orderBy: orderBy,
onCompleted: useCallback(
(data: PaginatedRecordTypeResults<Opportunity>) => {
const pipelineProgresses: Array<Opportunity> = data.edges.map(
(edge) => edge.node,
);
updateCompanyBoardCardIds(pipelineProgresses);
updateCompanyBoardCardIds(pipelineProgresses);
setOpportunities(pipelineProgresses);
setIsBoardLoaded(true);
},
[setIsBoardLoaded, updateCompanyBoardCardIds],
),
},
);
setOpportunities(pipelineProgresses);
setIsBoardLoaded(true);
},
[setIsBoardLoaded, updateCompanyBoardCardIds],
),
});
useEffect(() => {
if (isDefined(fetchMoreOpportunities)) {
fetchMoreOpportunities();
}
}, [fetchMoreOpportunities]);
const { fetchMoreObjects: fetchMoreCompanies } = useFindManyObjectRecords({
const { fetchMoreRecords: fetchMoreCompanies } = useFindManyRecords({
skip: !opportunities.length,
objectNamePlural: 'companies',
filter: {
@ -140,7 +138,7 @@ export const HooksCompanyBoardEffect = ({
in: opportunities.map((opportunity) => opportunity.companyId || ''),
},
},
onCompleted: useCallback((data: PaginatedObjectTypeResults<Company>) => {
onCompleted: useCallback((data: PaginatedRecordTypeResults<Company>) => {
setCompanies(data.edges.map((edge) => edge.node));
}, []),
});

View File

@ -59,10 +59,12 @@ export const NewOpportunityButton = () => {
relationPickerSearchFilterScopedState,
);
const { findManyQuery } = useObjectMetadataItem({
// TODO: refactor useFilteredSearchEntityQuery
const { findManyRecordsQuery } = useObjectMetadataItem({
objectNameSingular: 'company',
});
const useFindManyQuery = (options: any) => useQuery(findManyQuery, options);
const useFindManyQuery = (options: any) =>
useQuery(findManyRecordsQuery, options);
const { identifiersMapper, searchQuery } = useRelationPicker();
const filteredSearchEntityResults = useFilteredSearchEntityQuery({

View File

@ -35,10 +35,12 @@ export const OpportunityPicker = ({
const { searchFilter, handleSearchFilterChange } = useEntitySelectSearch();
const { findManyQuery } = useObjectMetadataItem({
// TODO: refactor useFilteredSearchEntityQuery
const { findManyRecordsQuery: findManyCompanies } = useObjectMetadataItem({
objectNameSingular: 'company',
});
const useFindManyQuery = (options: any) => useQuery(findManyQuery, options);
const useFindManyQuery = (options: any) =>
useQuery(findManyCompanies, options);
const { identifiersMapper, searchQuery } = useRelationPicker();
const filteredSearchEntityResults = useFilteredSearchEntityQuery({

View File

@ -1,13 +1,13 @@
import { useRecoilCallback } from 'recoil';
import { v4 } from 'uuid';
import { useCreateOneObjectRecord } from '@/object-record/hooks/useCreateOneObjectRecord';
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
import { Opportunity } from '@/pipeline/types/Opportunity';
import { boardCardIdsByColumnIdFamilyState } from '@/ui/object/record-board/states/boardCardIdsByColumnIdFamilyState';
export const useCreateOpportunity = () => {
const { createOneObject: createOneOpportunity } =
useCreateOneObjectRecord<Opportunity>({
const { createOneRecord: createOneOpportunity } =
useCreateOneRecord<Opportunity>({
objectNameSingular: 'opportunity',
});

View File

@ -9,8 +9,8 @@ import { Favorite } from '@/favorites/types/Favorite';
import { mapFavorites } from '@/favorites/utils/mapFavorites';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { getRecordOptimisticEffectDefinition } from '@/object-record/graphql/optimistic-effect-definition/getRecordOptimisticEffectDefinition';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { PaginatedObjectTypeResults } from '@/object-record/types/PaginatedObjectTypeResults';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { PaginatedRecordTypeResults } from '@/object-record/types/PaginatedRecordTypeResults';
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
import { favoritesState } from '../states/favoritesState';
@ -25,9 +25,9 @@ export const useFavorites = ({
const [favorites, setFavorites] = useRecoilState(favoritesState);
const {
updateOneMutation,
createOneMutation,
deleteOneMutation,
updateOneRecordMutation: updateOneFavoriteMutation,
createOneRecordMutation: createOneFavoriteMutation,
deleteOneRecordMutation: deleteOneFavoriteMutation,
objectMetadataItem: favoriteObjectMetadataItem,
} = useObjectMetadataItem({
objectNamePlural: 'favorites',
@ -46,11 +46,11 @@ export const useFavorites = ({
const apolloClient = useApolloClient();
useFindManyObjectRecords({
useFindManyRecords({
objectNamePlural: 'favorites',
onCompleted: useRecoilCallback(
({ snapshot, set }) =>
async (data: PaginatedObjectTypeResults<Required<Favorite>>) => {
async (data: PaginatedRecordTypeResults<Required<Favorite>>) => {
const favorites = snapshot.getLoadable(favoritesState).getValue();
const queriedFavorites = mapFavorites(
@ -87,7 +87,7 @@ export const useFavorites = ({
const targetObjectName = favoriteTargetObjectMetadataItem.nameSingular;
const result = await apolloClient.mutate({
mutation: createOneMutation,
mutation: createOneFavoriteMutation,
variables: {
input: {
[`${targetObjectName}Id`]: favoriteTargetObjectId,
@ -114,7 +114,7 @@ export const useFavorites = ({
},
[
apolloClient,
createOneMutation,
createOneFavoriteMutation,
currentWorkspaceMember?.id,
favoriteTargetObjectMetadataItem,
triggerOptimisticEffects,
@ -127,7 +127,7 @@ export const useFavorites = ({
const favoritesStateFromSnapshot = snapshot.getLoadable(favoritesState);
const favorites = favoritesStateFromSnapshot.getValue();
const result = await apolloClient.mutate({
mutation: updateOneMutation,
mutation: updateOneFavoriteMutation,
variables: {
input: {
position: favoriteToUpdate?.position,
@ -146,7 +146,7 @@ export const useFavorites = ({
);
}
},
[apolloClient, updateOneMutation],
[apolloClient, updateOneFavoriteMutation],
);
const deleteFavorite = useRecoilCallback(
@ -159,7 +159,7 @@ export const useFavorites = ({
)?.id;
await apolloClient.mutate({
mutation: deleteOneMutation,
mutation: deleteOneFavoriteMutation,
variables: {
idToDelete: idToDelete,
},
@ -172,7 +172,7 @@ export const useFavorites = ({
favorites.filter((favorite: Favorite) => favorite.id !== idToDelete),
);
},
[apolloClient, deleteOneMutation, performOptimisticEvict],
[apolloClient, deleteOneFavoriteMutation, performOptimisticEvict],
);
const computeNewPosition = (destIndex: number, sourceIndex: number) => {

View File

@ -1,6 +1,6 @@
import { gql } from '@apollo/client';
export const CREATE_ONE_METADATA_OBJECT = gql`
export const CREATE_ONE_OBJECT_METADATA_ITEM = gql`
mutation CreateOneObjectMetadataItem($input: CreateOneObjectInput!) {
createOneObject(input: $input) {
id
@ -19,7 +19,7 @@ export const CREATE_ONE_METADATA_OBJECT = gql`
}
`;
export const CREATE_ONE_METADATA_FIELD = gql`
export const CREATE_ONE_FIELD_METADATA_ITEM = gql`
mutation CreateOneFieldMetadataItem($input: CreateOneFieldInput!) {
createOneField(input: $input) {
id
@ -38,7 +38,7 @@ export const CREATE_ONE_METADATA_FIELD = gql`
}
`;
export const CREATE_ONE_RELATION_METADATA = gql`
export const CREATE_ONE_RELATION_METADATA_ITEM = gql`
mutation CreateOneRelationMetadata($input: CreateOneRelationInput!) {
createOneRelation(input: $input) {
id
@ -53,7 +53,7 @@ export const CREATE_ONE_RELATION_METADATA = gql`
}
`;
export const UPDATE_ONE_METADATA_FIELD = gql`
export const UPDATE_ONE_FIELD_METADATA_ITEM = gql`
mutation UpdateOneFieldMetadataItem(
$idToUpdate: ID!
$updatePayload: UpdateFieldInput!
@ -75,7 +75,7 @@ export const UPDATE_ONE_METADATA_FIELD = gql`
}
`;
export const UPDATE_ONE_METADATA_OBJECT = gql`
export const UPDATE_ONE_OBJECT_METADATA_ITEM = gql`
mutation UpdateOneObjectMetadataItem(
$idToUpdate: ID!
$updatePayload: UpdateObjectInput!
@ -97,7 +97,7 @@ export const UPDATE_ONE_METADATA_OBJECT = gql`
}
`;
export const DELETE_ONE_METADATA_OBJECT = gql`
export const DELETE_ONE_OBJECT_METADATA_ITEM = gql`
mutation DeleteOneObjectMetadataItem($idToDelete: ID!) {
deleteOneObject(input: { id: $idToDelete }) {
id
@ -116,7 +116,7 @@ export const DELETE_ONE_METADATA_OBJECT = gql`
}
`;
export const DELETE_ONE_METADATA_FIELD = gql`
export const DELETE_ONE_FIELD_METADATA_ITEM = gql`
mutation DeleteOneFieldMetadataItem($idToDelete: ID!) {
deleteOneField(input: { id: $idToDelete }) {
id

View File

@ -1,6 +1,6 @@
import { gql } from '@apollo/client';
export const FIND_MANY_METADATA_OBJECTS = gql`
export const FIND_MANY_OBJECT_METADATA_ITEMS = gql`
query ObjectMetadataItems(
$objectFilter: objectFilter
$fieldFilter: fieldFilter

View File

@ -9,7 +9,7 @@ import { formatFieldMetadataItemAsColumnDefinition } from '../utils/formatFieldM
import { formatFieldMetadataItemsAsFilterDefinitions } from '../utils/formatFieldMetadataItemsAsFilterDefinitions';
import { formatFieldMetadataItemsAsSortDefinitions } from '../utils/formatFieldMetadataItemsAsSortDefinitions';
export const useComputeDefinitionsFromFieldMetadata = (
export const useColumnDefinitionsFromFieldMetadata = (
objectMetadataItem?: Nullable<ObjectMetadataItem>,
) => {
const activeFieldMetadataItems = useMemo(

View File

@ -8,8 +8,8 @@ import {
CreateOneFieldMetadataItemMutationVariables,
} from '~/generated-metadata/graphql';
import { CREATE_ONE_METADATA_FIELD } from '../graphql/mutations';
import { FIND_MANY_METADATA_OBJECTS } from '../graphql/queries';
import { CREATE_ONE_FIELD_METADATA_ITEM } from '../graphql/mutations';
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries';
import { useApolloMetadataClient } from './useApolloMetadataClient';
@ -26,7 +26,7 @@ export const useCreateOneFieldMetadataItem = () => {
const [mutate] = useMutation<
CreateOneFieldMetadataItemMutation,
CreateOneFieldMetadataItemMutationVariables
>(CREATE_ONE_METADATA_FIELD, {
>(CREATE_ONE_FIELD_METADATA_ITEM, {
client: apolloMetadataClient ?? ({} as ApolloClient<any>),
});
@ -43,7 +43,7 @@ export const useCreateOneFieldMetadataItem = () => {
},
},
awaitRefetchQueries: true,
refetchQueries: [getOperationName(FIND_MANY_METADATA_OBJECTS) ?? ''],
refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''],
});
};

View File

@ -6,8 +6,8 @@ import {
CreateOneObjectMetadataItemMutationVariables,
} from '~/generated-metadata/graphql';
import { CREATE_ONE_METADATA_OBJECT } from '../graphql/mutations';
import { FIND_MANY_METADATA_OBJECTS } from '../graphql/queries';
import { CREATE_ONE_OBJECT_METADATA_ITEM } from '../graphql/mutations';
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries';
import { useApolloMetadataClient } from './useApolloMetadataClient';
@ -17,7 +17,7 @@ export const useCreateOneObjectRecordMetadataItem = () => {
const [mutate] = useMutation<
CreateOneObjectMetadataItemMutation,
CreateOneObjectMetadataItemMutationVariables
>(CREATE_ONE_METADATA_OBJECT, {
>(CREATE_ONE_OBJECT_METADATA_ITEM, {
client: apolloMetadataClient ?? ({} as ApolloClient<any>),
});
@ -33,7 +33,7 @@ export const useCreateOneObjectRecordMetadataItem = () => {
},
},
awaitRefetchQueries: true,
refetchQueries: [getOperationName(FIND_MANY_METADATA_OBJECTS) ?? ''],
refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''],
});
};

View File

@ -6,8 +6,8 @@ import {
CreateOneRelationMetadataMutationVariables,
} from '~/generated-metadata/graphql';
import { CREATE_ONE_RELATION_METADATA } from '../graphql/mutations';
import { FIND_MANY_METADATA_OBJECTS } from '../graphql/queries';
import { CREATE_ONE_RELATION_METADATA_ITEM } from '../graphql/mutations';
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries';
import {
formatRelationMetadataInput,
FormatRelationMetadataInputParams,
@ -15,27 +15,27 @@ import {
import { useApolloMetadataClient } from './useApolloMetadataClient';
export const useCreateOneRelationMetadata = () => {
export const useCreateOneRelationMetadataItem = () => {
const apolloMetadataClient = useApolloMetadataClient();
const [mutate] = useMutation<
CreateOneRelationMetadataMutation,
CreateOneRelationMetadataMutationVariables
>(CREATE_ONE_RELATION_METADATA, {
>(CREATE_ONE_RELATION_METADATA_ITEM, {
client: apolloMetadataClient ?? ({} as ApolloClient<any>),
});
const createOneRelationMetadata = async (
const createOneRelationMetadataItem = async (
input: FormatRelationMetadataInputParams,
) => {
return await mutate({
variables: { input: { relation: formatRelationMetadataInput(input) } },
awaitRefetchQueries: true,
refetchQueries: [getOperationName(FIND_MANY_METADATA_OBJECTS) ?? ''],
refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''],
});
};
return {
createOneRelationMetadata,
createOneRelationMetadataItem,
};
};

View File

@ -6,8 +6,8 @@ import {
DeleteOneFieldMetadataItemMutationVariables,
} from '~/generated-metadata/graphql';
import { DELETE_ONE_METADATA_FIELD } from '../graphql/mutations';
import { FIND_MANY_METADATA_OBJECTS } from '../graphql/queries';
import { DELETE_ONE_FIELD_METADATA_ITEM } from '../graphql/mutations';
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries';
import { useApolloMetadataClient } from './useApolloMetadataClient';
@ -17,7 +17,7 @@ export const useDeleteOneFieldMetadataItem = () => {
const [mutate] = useMutation<
DeleteOneFieldMetadataItemMutation,
DeleteOneFieldMetadataItemMutationVariables
>(DELETE_ONE_METADATA_FIELD, {
>(DELETE_ONE_FIELD_METADATA_ITEM, {
client: apolloMetadataClient ?? ({} as ApolloClient<any>),
});
@ -29,7 +29,7 @@ export const useDeleteOneFieldMetadataItem = () => {
idToDelete,
},
awaitRefetchQueries: true,
refetchQueries: [getOperationName(FIND_MANY_METADATA_OBJECTS) ?? ''],
refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''],
});
};

View File

@ -6,8 +6,8 @@ import {
DeleteOneObjectMetadataItemMutationVariables,
} from '~/generated-metadata/graphql';
import { DELETE_ONE_METADATA_OBJECT } from '../graphql/mutations';
import { FIND_MANY_METADATA_OBJECTS } from '../graphql/queries';
import { DELETE_ONE_OBJECT_METADATA_ITEM } from '../graphql/mutations';
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries';
import { useApolloMetadataClient } from './useApolloMetadataClient';
@ -17,7 +17,7 @@ export const useDeleteOneObjectMetadataItem = () => {
const [mutate] = useMutation<
DeleteOneObjectMetadataItemMutation,
DeleteOneObjectMetadataItemMutationVariables
>(DELETE_ONE_METADATA_OBJECT, {
>(DELETE_ONE_OBJECT_METADATA_ITEM, {
client: apolloMetadataClient ?? ({} as ApolloClient<any>),
});
@ -29,7 +29,7 @@ export const useDeleteOneObjectMetadataItem = () => {
idToDelete,
},
awaitRefetchQueries: true,
refetchQueries: [getOperationName(FIND_MANY_METADATA_OBJECTS) ?? ''],
refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''],
});
};

View File

@ -13,7 +13,7 @@ import {
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
import { logError } from '~/utils/logError';
import { FIND_MANY_METADATA_OBJECTS } from '../graphql/queries';
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries';
import { mapPaginatedObjectMetadataItemsToObjectMetadataItems } from '../utils/mapPaginatedObjectMetadataItemsToObjectMetadataItems';
import { useApolloMetadataClient } from './useApolloMetadataClient';
@ -34,7 +34,7 @@ export const useFindManyObjectMetadataItems = ({
const { data, loading, error } = useQuery<
ObjectMetadataItemsQuery,
ObjectMetadataItemsQueryVariables
>(FIND_MANY_METADATA_OBJECTS, {
>(FIND_MANY_OBJECT_METADATA_ITEMS, {
variables: {
objectFilter,
fieldFilter,

View File

@ -1,74 +0,0 @@
import { useMemo } from 'react';
import { useQuery } from '@apollo/client';
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import {
ObjectFilter,
ObjectMetadataItemsQuery,
ObjectMetadataItemsQueryVariables,
} from '~/generated-metadata/graphql';
import { logError } from '~/utils/logError';
import { FIND_MANY_METADATA_OBJECTS } from '../graphql/queries';
import { mapPaginatedObjectMetadataItemsToObjectMetadataItems } from '../utils/mapPaginatedObjectMetadataItemsToObjectMetadataItems';
import { useApolloMetadataClient } from './useApolloMetadataClient';
// TODO: test fetchMore
export const useFindManyObjectMetadataItems = ({
skip,
filter,
}: { skip?: boolean; filter?: ObjectFilter } = {}) => {
const apolloMetadataClient = useApolloMetadataClient();
const { enqueueSnackBar } = useSnackBar();
const {
data,
fetchMore: fetchMoreInternal,
loading,
error,
} = useQuery<ObjectMetadataItemsQuery, ObjectMetadataItemsQueryVariables>(
FIND_MANY_METADATA_OBJECTS,
{
variables: {
objectFilter: filter,
},
client: apolloMetadataClient ?? undefined,
skip: skip || !apolloMetadataClient,
onError: (error) => {
logError('useFindManyObjectMetadataItems error : ' + error);
enqueueSnackBar(
`Error during useFindManyObjectMetadataItems, ${error.message}`,
{
variant: 'error',
},
);
},
onCompleted: () => {},
},
);
const hasMore = data?.objects?.pageInfo?.hasNextPage;
const fetchMore = () =>
fetchMoreInternal({
variables: {
afterCursor: data?.objects?.pageInfo?.endCursor,
},
});
const objectMetadataItems = useMemo(() => {
return mapPaginatedObjectMetadataItemsToObjectMetadataItems({
pagedObjectMetadataItems: data,
});
}, [data]);
return {
objectMetadataItems,
hasMore,
fetchMore,
loading,
error,
};
};

View File

@ -2,13 +2,13 @@ import { gql } from '@apollo/client';
import { useRecoilValue } from 'recoil';
import { objectMetadataItemFamilySelector } from '@/object-metadata/states/objectMetadataItemFamilySelector';
import { useGenerateCreateOneObjectMutation } from '@/object-record/utils/generateCreateOneObjectMutation';
import { useGenerateDeleteOneObjectMutation } from '@/object-record/utils/useGenerateDeleteOneObjectMutation';
import { useGenerateFindManyCustomObjectsQuery } from '@/object-record/utils/useGenerateFindManyCustomObjectsQuery';
import { useGenerateFindOneCustomObjectQuery } from '@/object-record/utils/useGenerateFindOneCustomObjectQuery';
import { useGenerateUpdateOneObjectMutation } from '@/object-record/utils/useGenerateUpdateOneObjectMutation';
import { useGetRecordFromCache } from '@/object-record/utils/useGetRecordFromCache';
import { useModifyRecordFromCache } from '@/object-record/utils/useModifyRecordFromCache';
import { useGenerateCreateOneRecordMutation } from '@/object-record/hooks/useGenerateCreateOneRecordMutation';
import { useGenerateFindManyRecordsQuery } from '@/object-record/hooks/useGenerateFindManyRecordsQuery';
import { useGenerateFindOneRecordQuery } from '@/object-record/hooks/useGenerateFindOneRecordQuery';
import { useGenerateUpdateOneRecordMutation } from '@/object-record/hooks/useGenerateUpdateOneRecordMutation';
import { useGetRecordFromCache } from '@/object-record/hooks/useGetRecordFromCache';
import { useModifyRecordFromCache } from '@/object-record/hooks/useModifyRecordFromCache';
import { generateDeleteOneRecordMutation } from '@/object-record/utils/generateDeleteOneRecordMutation';
import { isDefined } from '~/utils/isDefined';
import { ObjectMetadataItemIdentifier } from '../types/ObjectMetadataItemIdentifier';
@ -36,7 +36,7 @@ export const useObjectMetadataItem = (
}),
);
const objectNotFoundInMetadata = !isDefined(objectMetadataItem);
const objectMetadataItemNotFound = !isDefined(objectMetadataItem);
const getRecordFromCache = useGetRecordFromCache({
objectMetadataItem,
@ -46,25 +46,25 @@ export const useObjectMetadataItem = (
objectMetadataItem,
});
const findManyQuery = useGenerateFindManyCustomObjectsQuery({
const findManyRecordsQuery = useGenerateFindManyRecordsQuery({
objectMetadataItem,
depth,
});
const findOneQuery = useGenerateFindOneCustomObjectQuery({
const findOneRecordQuery = useGenerateFindOneRecordQuery({
objectMetadataItem,
depth,
});
const createOneMutation = useGenerateCreateOneObjectMutation({
const createOneRecordMutation = useGenerateCreateOneRecordMutation({
objectMetadataItem,
});
const updateOneMutation = useGenerateUpdateOneObjectMutation({
const updateOneRecordMutation = useGenerateUpdateOneRecordMutation({
objectMetadataItem,
});
const deleteOneMutation = useGenerateDeleteOneObjectMutation({
const deleteOneRecordMutation = generateDeleteOneRecordMutation({
objectMetadataItem,
});
@ -78,13 +78,13 @@ export const useObjectMetadataItem = (
labelIdentifierFieldMetadataId,
basePathToShowPage,
objectMetadataItem,
objectNotFoundInMetadata,
objectMetadataItemNotFound,
getRecordFromCache,
modifyRecordFromCache,
findManyQuery,
findOneQuery,
createOneMutation,
updateOneMutation,
deleteOneMutation,
findManyRecordsQuery,
findOneRecordQuery,
createOneRecordMutation,
updateOneRecordMutation,
deleteOneRecordMutation,
};
};

View File

@ -6,8 +6,8 @@ import {
UpdateOneFieldMetadataItemMutationVariables,
} from '~/generated-metadata/graphql';
import { UPDATE_ONE_METADATA_FIELD } from '../graphql/mutations';
import { FIND_MANY_METADATA_OBJECTS } from '../graphql/queries';
import { UPDATE_ONE_FIELD_METADATA_ITEM } from '../graphql/mutations';
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries';
import { useApolloMetadataClient } from './useApolloMetadataClient';
@ -17,7 +17,7 @@ export const useUpdateOneFieldMetadataItem = () => {
const [mutate] = useMutation<
UpdateOneFieldMetadataItemMutation,
UpdateOneFieldMetadataItemMutationVariables
>(UPDATE_ONE_METADATA_FIELD, {
>(UPDATE_ONE_FIELD_METADATA_ITEM, {
client: apolloMetadataClient ?? undefined,
});
@ -40,7 +40,7 @@ export const useUpdateOneFieldMetadataItem = () => {
},
},
awaitRefetchQueries: true,
refetchQueries: [getOperationName(FIND_MANY_METADATA_OBJECTS) ?? ''],
refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''],
});
};

View File

@ -6,8 +6,8 @@ import {
UpdateOneObjectMetadataItemMutationVariables,
} from '~/generated-metadata/graphql';
import { UPDATE_ONE_METADATA_OBJECT } from '../graphql/mutations';
import { FIND_MANY_METADATA_OBJECTS } from '../graphql/queries';
import { UPDATE_ONE_OBJECT_METADATA_ITEM } from '../graphql/mutations';
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries';
import { useApolloMetadataClient } from './useApolloMetadataClient';
@ -18,7 +18,7 @@ export const useUpdateOneObjectMetadataItem = () => {
const [mutate] = useMutation<
UpdateOneObjectMetadataItemMutation,
UpdateOneObjectMetadataItemMutationVariables
>(UPDATE_ONE_METADATA_OBJECT, {
>(UPDATE_ONE_OBJECT_METADATA_ITEM, {
client: apolloClientMetadata ?? undefined,
});
@ -44,7 +44,7 @@ export const useUpdateOneObjectMetadataItem = () => {
updatePayload,
},
awaitRefetchQueries: true,
refetchQueries: [getOperationName(FIND_MANY_METADATA_OBJECTS) ?? ''],
refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''],
});
};

View File

@ -28,13 +28,13 @@ import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope'
import { FileFolder, useUploadImageMutation } from '~/generated/graphql';
import { getLogoUrlFromDomainName } from '~/utils';
import { useFindOneObjectRecord } from '../hooks/useFindOneObjectRecord';
import { useUpdateOneObjectRecord } from '../hooks/useUpdateOneObjectRecord';
import { useFindOneRecord } from '../hooks/useFindOneRecord';
import { useUpdateOneRecord } from '../hooks/useUpdateOneRecord';
export const RecordShowPage = () => {
const { objectNameSingular, objectMetadataId } = useParams<{
const { objectNameSingular, objectRecordId } = useParams<{
objectNameSingular: string;
objectMetadataId: string;
objectRecordId: string;
}>();
const { objectMetadataItem } = useObjectMetadataItem({
@ -48,11 +48,11 @@ export const RecordShowPage = () => {
});
const [, setEntityFields] = useRecoilState(
entityFieldsFamilyState(objectMetadataId ?? ''),
entityFieldsFamilyState(objectRecordId ?? ''),
);
const { object } = useFindOneObjectRecord({
objectRecordId: objectMetadataId,
const { record } = useFindOneRecord({
objectRecordId,
objectNameSingular,
onCompleted: (data) => {
setEntityFields(data);
@ -60,11 +60,14 @@ export const RecordShowPage = () => {
});
const [uploadImage] = useUploadImageMutation();
const { updateOneObject } = useUpdateOneObjectRecord({
const { updateOneRecord } = useUpdateOneRecord({
objectNameSingular,
});
const useUpdateOneObjectMutation: () => [(params: any) => any, any] = () => {
const useUpdateOneObjectRecordMutation: () => [
(params: any) => any,
any,
] = () => {
const updateEntity = ({
variables,
}: {
@ -75,7 +78,7 @@ export const RecordShowPage = () => {
};
};
}) => {
updateOneObject?.({
updateOneRecord?.({
idToUpdate: variables.where.id,
input: variables.data,
});
@ -85,45 +88,45 @@ export const RecordShowPage = () => {
};
const isFavorite = objectNameSingular
? favorites.some((favorite) => favorite.recordId === object?.id)
? favorites.some((favorite) => favorite.recordId === record?.id)
: false;
const handleFavoriteButtonClick = async () => {
if (!objectNameSingular || !object) return;
if (isFavorite) deleteFavorite(object?.id);
if (!objectNameSingular || !record) return;
if (isFavorite) deleteFavorite(record?.id);
else {
const additionalData =
objectNameSingular === 'person'
? {
labelIdentifier:
object.name.firstName + ' ' + object.name.lastName,
avatarUrl: object.avatarUrl,
record.name.firstName + ' ' + record.name.lastName,
avatarUrl: record.avatarUrl,
avatarType: 'rounded',
link: `/object/personV2/${object.id}`,
recordId: object.id,
link: `/object/personV2/${record.id}`,
recordId: record.id,
}
: objectNameSingular === 'company'
? {
labelIdentifier: object.name,
avatarUrl: getLogoUrlFromDomainName(object.domainName ?? ''),
labelIdentifier: record.name,
avatarUrl: getLogoUrlFromDomainName(record.domainName ?? ''),
avatarType: 'squared',
link: `/object/companyV2/${object.id}`,
recordId: object.id,
link: `/object/companyV2/${record.id}`,
recordId: record.id,
}
: {};
createFavorite(object.id, additionalData);
createFavorite(record.id, additionalData);
}
};
if (!object) return <></>;
if (!record) return <></>;
const pageName =
objectNameSingular === 'person'
? object.name.firstName + ' ' + object.name.lastName
: object.name;
? record.name.firstName + ' ' + record.name.lastName
: record.name;
const recordIdentifiers = identifiersMapper?.(
object,
record,
objectMetadataItem?.nameSingular ?? '',
);
@ -144,12 +147,12 @@ export const RecordShowPage = () => {
if (!avatarUrl) {
return;
}
if (!updateOneObject) {
if (!updateOneRecord) {
return;
}
await updateOneObject({
idToUpdate: object?.id,
await updateOneRecord({
idToUpdate: record?.id,
input: {
avatarUrl,
},
@ -171,7 +174,7 @@ export const RecordShowPage = () => {
<ShowPageAddButton
key="add"
entity={{
id: object.id,
id: record.id,
type:
objectMetadataItem?.nameSingular === 'company'
? 'Company'
@ -186,10 +189,10 @@ export const RecordShowPage = () => {
<ShowPageContainer>
<ShowPageLeftContainer>
<ShowPageSummaryCard
id={object.id}
id={record.id}
logoOrAvatar={recordIdentifiers?.avatarUrl}
title={recordIdentifiers?.name ?? 'No name'}
date={object.createdAt ?? ''}
date={record.createdAt ?? ''}
renderTitleEditComponent={() => <></>}
avatarType={recordIdentifiers?.avatarType ?? 'rounded'}
onUploadPicture={
@ -206,10 +209,10 @@ export const RecordShowPage = () => {
.map((metadataField, index) => {
return (
<FieldContext.Provider
key={object.id + metadataField.id}
key={record.id + metadataField.id}
value={{
entityId: object.id,
recoilScopeId: object.id + metadataField.id,
entityId: record.id,
recoilScopeId: record.id + metadataField.id,
isLabelIdentifier: false,
fieldDefinition:
formatFieldMetadataItemAsColumnDefinition({
@ -217,7 +220,8 @@ export const RecordShowPage = () => {
position: index,
objectMetadataItem,
}),
useUpdateEntityMutation: useUpdateOneObjectMutation,
useUpdateEntityMutation:
useUpdateOneObjectRecordMutation,
hotkeyScope: InlineCellHotkeyScope.InlineCell,
}}
>
@ -228,7 +232,7 @@ export const RecordShowPage = () => {
</PropertyBox>
{objectNameSingular === 'company' ? (
<>
<CompanyTeam company={object} />
<CompanyTeam company={record} />
</>
) : (
<></>
@ -236,7 +240,7 @@ export const RecordShowPage = () => {
</ShowPageLeftContainer>
<ShowPageRightContainer
entity={{
id: object.id,
id: record.id,
// TODO: refacto
type:
objectMetadataItem?.nameSingular === 'company'

View File

@ -1,6 +1,6 @@
import styled from '@emotion/styled';
import { useComputeDefinitionsFromFieldMetadata } from '@/object-metadata/hooks/useComputeDefinitionsFromFieldMetadata';
import { useColumnDefinitionsFromFieldMetadata } from '@/object-metadata/hooks/useColumnDefinitionsFromFieldMetadata';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { RecordTable } from '@/ui/object/record-table/components/RecordTable';
import { TableOptionsDropdownId } from '@/ui/object/record-table/constants/TableOptionsDropdownId';
@ -11,7 +11,7 @@ import { mapViewFieldsToColumnDefinitions } from '@/views/utils/mapViewFieldsToC
import { mapViewFiltersToFilters } from '@/views/utils/mapViewFiltersToFilters';
import { mapViewSortsToSorts } from '@/views/utils/mapViewSortsToSorts';
import { useUpdateOneObjectRecord } from '../hooks/useUpdateOneObjectRecord';
import { useUpdateOneRecord } from '../hooks/useUpdateOneRecord';
import { RecordTableEffect } from './RecordTableEffect';
@ -32,11 +32,11 @@ export const RecordTableContainer = ({
objectNamePlural,
},
);
const { columnDefinitions } = useComputeDefinitionsFromFieldMetadata(
const { columnDefinitions } = useColumnDefinitionsFromFieldMetadata(
foundObjectMetadataItem,
);
const { updateOneObject } = useUpdateOneObjectRecord({
const { updateOneRecord } = useUpdateOneRecord({
objectNameSingular: foundObjectMetadataItem?.nameSingular,
});
@ -57,7 +57,7 @@ export const RecordTableContainer = ({
};
};
}) => {
updateOneObject?.({
updateOneRecord?.({
idToUpdate: variables.where.id,
input: variables.data,
});

View File

@ -1,6 +1,6 @@
import { useEffect } from 'react';
import { useComputeDefinitionsFromFieldMetadata } from '@/object-metadata/hooks/useComputeDefinitionsFromFieldMetadata';
import { useColumnDefinitionsFromFieldMetadata } from '@/object-metadata/hooks/useColumnDefinitionsFromFieldMetadata';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useRecordTableContextMenuEntries } from '@/object-record/hooks/useRecordTableContextMenuEntries';
import { filterAvailableTableColumns } from '@/object-record/utils/filterAvailableTableColumns';
@ -31,7 +31,7 @@ export const RecordTableEffect = ({
});
const { columnDefinitions, filterDefinitions, sortDefinitions } =
useComputeDefinitionsFromFieldMetadata(objectMetadataItem);
useColumnDefinitionsFromFieldMetadata(objectMetadataItem);
const {
setAvailableSortDefinitions,

View File

@ -15,7 +15,7 @@ import { PageHotkeysEffect } from '@/ui/layout/page/PageHotkeysEffect';
import { RecordTableActionBar } from '@/ui/object/record-table/action-bar/components/RecordTableActionBar';
import { RecordTableContextMenu } from '@/ui/object/record-table/context-menu/components/RecordTableContextMenu';
import { useCreateOneObjectRecord } from '../hooks/useCreateOneObjectRecord';
import { useCreateOneRecord } from '../hooks/useCreateOneRecord';
import { RecordTableContainer } from './RecordTableContainer';
@ -33,7 +33,7 @@ export type RecordTablePageProps = Pick<
export const RecordTablePage = () => {
const objectNamePlural = useParams().objectNamePlural ?? '';
const { objectNotFoundInMetadata, objectMetadataItem } =
const { objectMetadataItemNotFound, objectMetadataItem } =
useObjectMetadataItem({
objectNamePlural,
});
@ -44,14 +44,14 @@ export const RecordTablePage = () => {
useEffect(() => {
if (
objectNotFoundInMetadata &&
objectMetadataItemNotFound &&
onboardingStatus === OnboardingStatus.Completed
) {
navigate('/');
}
}, [objectNotFoundInMetadata, navigate, onboardingStatus]);
}, [objectMetadataItemNotFound, navigate, onboardingStatus]);
const { createOneObject } = useCreateOneObjectRecord({
const { createOneRecord: createOneObject } = useCreateOneRecord({
objectNameSingular: objectMetadataItem?.nameSingular,
});

View File

@ -1,13 +0,0 @@
import { gql } from '@apollo/client';
export const CREATE_ONE_WORKSPACE_MEMBER_V2 = gql`
mutation CreateOneWorkspaceMember($input: WorkspaceMemberCreateInput!) {
createWorkspaceMember(data: $input) {
id
name {
firstName
lastName
}
}
}
`;

View File

@ -2,7 +2,7 @@ import { produce } from 'immer';
import { OptimisticEffectDefinition } from '@/apollo/optimistic-effect/types/OptimisticEffectDefinition';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { PaginatedObjectTypeResults } from '@/object-record/types/PaginatedObjectTypeResults';
import { PaginatedRecordTypeResults } from '@/object-record/types/PaginatedRecordTypeResults';
import { capitalize } from '~/utils/string/capitalize';
export const getRecordOptimisticEffectDefinition = ({
@ -21,8 +21,8 @@ export const getRecordOptimisticEffectDefinition = ({
newData: unknown;
}) => {
const newRecordPaginatedCacheField = produce<
PaginatedObjectTypeResults<any>
>(currentData as PaginatedObjectTypeResults<any>, (draft) => {
PaginatedRecordTypeResults<any>
>(currentData as PaginatedRecordTypeResults<any>, (draft) => {
if (!draft) {
return {
edges: [{ node: newData, cursor: '' }],

View File

@ -6,7 +6,7 @@ import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadata
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
import { capitalize } from '~/utils/string/capitalize';
export const useCreateOneObjectRecord = <T>({
export const useCreateOneRecord = <T>({
objectNameSingular,
}: Pick<ObjectMetadataItemIdentifier, 'objectNameSingular'>) => {
const { triggerOptimisticEffects } = useOptimisticEffect({
@ -14,22 +14,22 @@ export const useCreateOneObjectRecord = <T>({
});
const {
objectMetadataItem: foundObjectMetadataItem,
objectNotFoundInMetadata,
createOneMutation,
objectMetadataItem,
objectMetadataItemNotFound,
createOneRecordMutation,
} = useObjectMetadataItem({
objectNameSingular,
});
// TODO: type this with a minimal type at least with Record<string, any>
const [mutate] = useMutation(createOneMutation);
const [mutate] = useMutation(createOneRecordMutation);
const createOneObject = async (input: Record<string, any>) => {
if (!foundObjectMetadataItem || !objectNameSingular) {
const createOneRecord = async (input: Record<string, any>) => {
if (!objectMetadataItem || !objectNameSingular) {
return null;
}
const createdObject = await mutate({
const createdRecord = await mutate({
variables: {
input: { ...input, id: v4() },
},
@ -37,13 +37,13 @@ export const useCreateOneObjectRecord = <T>({
triggerOptimisticEffects(
`${capitalize(objectNameSingular)}Edge`,
createdObject.data[`create${capitalize(objectNameSingular)}`],
createdRecord.data[`create${capitalize(objectNameSingular)}`],
);
return createdObject.data[`create${capitalize(objectNameSingular)}`] as T;
return createdRecord.data[`create${capitalize(objectNameSingular)}`] as T;
};
return {
createOneObject,
objectNotFoundInMetadata,
createOneRecord,
objectMetadataItemNotFound,
};
};

View File

@ -6,29 +6,29 @@ import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadata
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
import { capitalize } from '~/utils/string/capitalize';
export const useDeleteOneObjectRecord = <T>({
export const useDeleteOneRecord = <T>({
objectNameSingular,
}: Pick<ObjectMetadataItemIdentifier, 'objectNameSingular'>) => {
const { performOptimisticEvict } = useOptimisticEvict();
const {
objectMetadataItem: foundObjectMetadataItem,
objectNotFoundInMetadata,
deleteOneMutation,
objectMetadataItem,
objectMetadataItemNotFound,
deleteOneRecordMutation,
} = useObjectMetadataItem({
objectNameSingular,
});
// TODO: type this with a minimal type at least with Record<string, any>
const [mutate] = useMutation(deleteOneMutation);
const [mutate] = useMutation(deleteOneRecordMutation);
const deleteOneObject = useCallback(
const deleteOneRecord = useCallback(
async (idToDelete: string) => {
if (!foundObjectMetadataItem || !objectNameSingular) {
if (!objectMetadataItem || !objectNameSingular) {
return null;
}
const deletedObject = await mutate({
const deletedRecord = await mutate({
variables: {
idToDelete,
},
@ -36,18 +36,13 @@ export const useDeleteOneObjectRecord = <T>({
performOptimisticEvict(capitalize(objectNameSingular), 'id', idToDelete);
return deletedObject.data[`create${capitalize(objectNameSingular)}`] as T;
return deletedRecord.data[`create${capitalize(objectNameSingular)}`] as T;
},
[
performOptimisticEvict,
foundObjectMetadataItem,
mutate,
objectNameSingular,
],
[performOptimisticEvict, objectMetadataItem, mutate, objectNameSingular],
);
return {
deleteOneObject,
objectNotFoundInMetadata,
deleteOneRecord,
objectMetadataItemNotFound,
};
};

View File

@ -2,7 +2,7 @@ import { ReactNode } from 'react';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { formatFieldMetadataItemAsColumnDefinition } from '@/object-metadata/utils/formatFieldMetadataItemAsColumnDefinition';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { FieldContext } from '@/ui/object/field/contexts/FieldContext';
import { InlineCellHotkeyScope } from '@/ui/object/record-inline-cell/types/InlineCellHotkeyScope';
@ -28,7 +28,7 @@ export const useFieldContext = ({
);
const useUpdateOneObjectMutation: () => [(params: any) => any, any] = () => {
const { updateOneObject } = useUpdateOneObjectRecord({
const { updateOneRecord } = useUpdateOneRecord({
objectNameSingular,
});
@ -42,7 +42,7 @@ export const useFieldContext = ({
};
};
}) => {
updateOneObject?.({
updateOneRecord?.({
idToUpdate: variables.where.id,
input: variables.data,
forceRefetch,

View File

@ -8,6 +8,7 @@ import { useOptimisticEffect } from '@/apollo/optimistic-effect/hooks/useOptimis
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
import { getRecordOptimisticEffectDefinition } from '@/object-record/graphql/optimistic-effect-definition/getRecordOptimisticEffectDefinition';
import { filterUniqueRecordEdgesByCursor } from '@/object-record/utils/filterUniqueRecordEdgesByCursor';
import { DEFAULT_SEARCH_REQUEST_LIMIT } from '@/search/hooks/useFilteredSearchEntityQuery';
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import { logError } from '~/utils/logError';
@ -15,18 +16,16 @@ import { capitalize } from '~/utils/string/capitalize';
import { cursorFamilyState } from '../states/cursorFamilyState';
import { hasNextPageFamilyState } from '../states/hasNextPageFamilyState';
import { isFetchingMoreObjectsFamilyState } from '../states/isFetchingMoreObjectsFamilyState';
import { PaginatedObjectType } from '../types/PaginatedObjectType';
import { isFetchingMoreRecordsFamilyState } from '../states/isFetchingMoreRecordsFamilyState';
import { PaginatedRecordType } from '../types/PaginatedRecordType';
import {
PaginatedObjectTypeEdge,
PaginatedObjectTypeResults,
} from '../types/PaginatedObjectTypeResults';
import { mapPaginatedObjectsToObjects } from '../utils/mapPaginatedObjectsToObjects';
PaginatedRecordTypeEdge,
PaginatedRecordTypeResults,
} from '../types/PaginatedRecordTypeResults';
import { mapPaginatedRecordsToRecords } from '../utils/mapPaginatedRecordsToRecords';
// TODO: test with a wrong name
// TODO: add zod to validate that we have at least id on each object
export const useFindManyObjectRecords = <
ObjectType extends { id: string } & Record<string, any>,
export const useFindManyRecords = <
RecordType extends { id: string } & Record<string, any>,
>({
objectNamePlural,
filter,
@ -38,7 +37,7 @@ export const useFindManyObjectRecords = <
filter?: any;
orderBy?: any;
limit?: number;
onCompleted?: (data: PaginatedObjectTypeResults<ObjectType>) => void;
onCompleted?: (data: PaginatedRecordTypeResults<RecordType>) => void;
skip?: boolean;
}) => {
const findManyQueryStateIdentifier =
@ -53,13 +52,16 @@ export const useFindManyObjectRecords = <
);
const [, setIsFetchingMoreObjects] = useRecoilState(
isFetchingMoreObjectsFamilyState(findManyQueryStateIdentifier),
isFetchingMoreRecordsFamilyState(findManyQueryStateIdentifier),
);
const { objectMetadataItem, objectNotFoundInMetadata, findManyQuery } =
useObjectMetadataItem({
objectNamePlural,
});
const {
objectMetadataItem,
objectMetadataItemNotFound,
findManyRecordsQuery,
} = useObjectMetadataItem({
objectNamePlural,
});
const { registerOptimisticEffect } = useOptimisticEffect({
objectNameSingular: objectMetadataItem?.nameSingular,
@ -68,8 +70,8 @@ export const useFindManyObjectRecords = <
const { enqueueSnackBar } = useSnackBar();
const { data, loading, error, fetchMore } = useQuery<
PaginatedObjectType<ObjectType>
>(findManyQuery, {
PaginatedRecordType<RecordType>
>(findManyRecordsQuery, {
skip: skip || !objectMetadataItem || !objectNamePlural,
variables: {
filter: filter ?? {},
@ -112,7 +114,7 @@ export const useFindManyObjectRecords = <
},
});
const fetchMoreObjects = useCallback(async () => {
const fetchMoreRecords = useCallback(async () => {
if (objectNamePlural && hasNextPage) {
setIsFetchingMoreObjects(true);
@ -124,27 +126,13 @@ export const useFindManyObjectRecords = <
lastCursor: isNonEmptyString(lastCursor) ? lastCursor : undefined,
},
updateQuery: (prev, { fetchMoreResult }) => {
const uniqueByCursor = (
a: PaginatedObjectTypeEdge<ObjectType>[],
) => {
const seenCursors = new Set();
return a.filter((item) => {
const currentCursor = item.cursor;
return seenCursors.has(currentCursor)
? false
: seenCursors.add(currentCursor);
});
};
const previousEdges = prev?.[objectNamePlural]?.edges;
const nextEdges = fetchMoreResult?.[objectNamePlural]?.edges;
let newEdges: any[] = [];
let newEdges: PaginatedRecordTypeEdge<RecordType>[] = [];
if (isNonEmptyArray(previousEdges) && isNonEmptyArray(nextEdges)) {
newEdges = uniqueByCursor([
newEdges = filterUniqueRecordEdgesByCursor([
...prev?.[objectNamePlural]?.edges,
...fetchMoreResult?.[objectNamePlural]?.edges,
]);
@ -158,7 +146,7 @@ export const useFindManyObjectRecords = <
edges: newEdges,
pageInfo: fetchMoreResult?.[objectNamePlural].pageInfo,
},
} as PaginatedObjectType<ObjectType>);
} as PaginatedRecordType<RecordType>);
},
});
} catch (error) {
@ -185,11 +173,11 @@ export const useFindManyObjectRecords = <
enqueueSnackBar,
]);
const objects = useMemo(
const records = useMemo(
() =>
objectNamePlural
? mapPaginatedObjectsToObjects({
pagedObjects: data,
? mapPaginatedRecordsToRecords({
pagedRecords: data,
objectNamePlural,
})
: [],
@ -198,10 +186,10 @@ export const useFindManyObjectRecords = <
return {
objectMetadataItem,
objects,
records,
loading,
error,
objectNotFoundInMetadata,
fetchMoreObjects,
objectMetadataItemNotFound,
fetchMoreRecords,
};
};

View File

@ -3,7 +3,7 @@ import { useQuery } from '@apollo/client';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
export const useFindOneObjectRecord = <
export const useFindOneRecord = <
ObjectType extends { id: string } & Record<string, any>,
>({
objectNameSingular,
@ -17,22 +17,19 @@ export const useFindOneObjectRecord = <
skip?: boolean;
depth?: number;
}) => {
const {
objectMetadataItem: foundObjectMetadataItem,
objectNotFoundInMetadata,
findOneQuery,
} = useObjectMetadataItem(
{
objectNameSingular,
},
depth,
);
const { objectMetadataItem, objectMetadataItemNotFound, findOneRecordQuery } =
useObjectMetadataItem(
{
objectNameSingular,
},
depth,
);
const { data, loading, error } = useQuery<
{ [nameSingular: string]: ObjectType },
{ objectRecordId: string }
>(findOneQuery, {
skip: !foundObjectMetadataItem || !objectRecordId || skip,
>(findOneRecordQuery, {
skip: !objectMetadataItem || !objectRecordId || skip,
variables: {
objectRecordId: objectRecordId ?? '',
},
@ -43,13 +40,13 @@ export const useFindOneObjectRecord = <
},
});
const object =
const record =
objectNameSingular && data ? data[objectNameSingular] : undefined;
return {
object,
record,
loading,
error,
objectNotFoundInMetadata,
objectMetadataItemNotFound,
};
};

View File

@ -5,7 +5,7 @@ import { EMPTY_MUTATION } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { capitalize } from '~/utils/string/capitalize';
export const useGenerateCreateOneObjectMutation = ({
export const useGenerateCreateOneRecordMutation = ({
objectMetadataItem,
}: {
objectMetadataItem: ObjectMetadataItem | undefined | null;

View File

@ -5,7 +5,7 @@ import { EMPTY_QUERY } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { capitalize } from '~/utils/string/capitalize';
export const useGenerateFindManyCustomObjectsQuery = ({
export const useGenerateFindManyRecordsQuery = ({
objectMetadataItem,
depth,
}: {

View File

@ -4,7 +4,7 @@ import { useMapFieldMetadataToGraphQLQuery } from '@/object-metadata/hooks/useMa
import { EMPTY_QUERY } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
export const useGenerateFindOneCustomObjectQuery = ({
export const useGenerateFindOneRecordQuery = ({
objectMetadataItem,
depth,
}: {

View File

@ -5,7 +5,7 @@ import { EMPTY_MUTATION } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { capitalize } from '~/utils/string/capitalize';
export const getUpdateOneObjectMutationGraphQLField = ({
export const getUpdateOneRecordMutationGraphQLField = ({
objectNameSingular,
}: {
objectNameSingular: string;
@ -13,7 +13,7 @@ export const getUpdateOneObjectMutationGraphQLField = ({
return `update${capitalize(objectNameSingular)}`;
};
export const useGenerateUpdateOneObjectMutation = ({
export const useGenerateUpdateOneRecordMutation = ({
objectMetadataItem,
}: {
objectMetadataItem: ObjectMetadataItem | undefined | null;
@ -26,14 +26,14 @@ export const useGenerateUpdateOneObjectMutation = ({
const capitalizedObjectName = capitalize(objectMetadataItem.nameSingular);
const graphQLFieldForUpdateOneObjectMutation =
getUpdateOneObjectMutationGraphQLField({
const graphQLFieldForUpdateOneRecordMutation =
getUpdateOneRecordMutationGraphQLField({
objectNameSingular: objectMetadataItem.nameSingular,
});
return gql`
mutation UpdateOne${capitalizedObjectName}($idToUpdate: ID!, $input: ${capitalizedObjectName}UpdateInput!) {
${graphQLFieldForUpdateOneObjectMutation}(id: $idToUpdate, data: $input) {
${graphQLFieldForUpdateOneRecordMutation}(id: $idToUpdate, data: $input) {
id
${objectMetadataItem.fields
.map((field) => mapFieldMetadataToGraphQLQuery(field))

View File

@ -9,10 +9,10 @@ import { useRecordTable } from '@/ui/object/record-table/hooks/useRecordTable';
import { getRecordOptimisticEffectDefinition } from '../graphql/optimistic-effect-definition/getRecordOptimisticEffectDefinition';
import { useFindManyObjectRecords } from './useFindManyObjectRecords';
import { useFindManyRecords } from './useFindManyRecords';
export const useObjectRecordTable = () => {
const { scopeId: objectNamePlural } = useRecordTable();
const { scopeId: objectNamePlural, setRecordTableData } = useRecordTable();
const { objectMetadataItem: foundObjectMetadataItem } = useObjectMetadataItem(
{
@ -24,8 +24,6 @@ export const useObjectRecordTable = () => {
objectNameSingular: foundObjectMetadataItem?.nameSingular,
});
const { setRecordTableData } = useRecordTable();
const { tableFiltersState, tableSortsState } = useRecordTableScopedStates();
const tableFilters = useRecoilValue(tableFiltersState);
@ -40,7 +38,7 @@ export const useObjectRecordTable = () => {
foundObjectMetadataItem?.fields ?? [],
);
const { objects, loading, fetchMoreObjects } = useFindManyObjectRecords({
const { records, loading, fetchMoreRecords } = useFindManyRecords({
objectNamePlural,
filter,
orderBy,
@ -61,8 +59,8 @@ export const useObjectRecordTable = () => {
});
return {
objects,
records,
loading,
fetchMoreObjects,
fetchMoreRecords,
};
};

View File

@ -4,10 +4,11 @@ import { useRecoilCallback, useRecoilValue, useSetRecoilState } from 'recoil';
import { useFavorites } from '@/favorites/hooks/useFavorites';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useDeleteOneObjectRecord } from '@/object-record/hooks/useDeleteOneObjectRecord';
import { useDeleteOneRecord } from '@/object-record/hooks/useDeleteOneRecord';
import { IconHeart, IconHeartOff, IconTrash } from '@/ui/display/icon';
import { actionBarEntriesState } from '@/ui/navigation/action-bar/states/actionBarEntriesState';
import { contextMenuEntriesState } from '@/ui/navigation/context-menu/states/contextMenuEntriesState';
import { ContextMenuEntry } from '@/ui/navigation/context-menu/types/ContextMenuEntry';
import { useRecordTable } from '@/ui/object/record-table/hooks/useRecordTable';
import { RecordTableScopeInternalContext } from '@/ui/object/record-table/scopes/scope-internal-context/RecordTableScopeInternalContext';
import { selectedRowIdsSelector } from '@/ui/object/record-table/states/selectors/selectedRowIdsSelector';
@ -37,11 +38,9 @@ export const useRecordTableContextMenuEntries = (
recordTableScopeId: scopeId,
});
const { objectMetadataItem: foundObjectMetadataItem } = useObjectMetadataItem(
{
objectNamePlural,
},
);
const { objectMetadataItem } = useObjectMetadataItem({
objectNamePlural,
});
const { createFavorite, deleteFavorite, favorites } = useFavorites({
objectNamePlural,
@ -67,8 +66,8 @@ export const useRecordTableContextMenuEntries = (
}
});
const { deleteOneObject } = useDeleteOneObjectRecord({
objectNameSingular: foundObjectMetadataItem?.nameSingular,
const { deleteOneRecord } = useDeleteOneRecord({
objectNameSingular: objectMetadataItem?.nameSingular,
});
const handleDeleteClick = useRecoilCallback(({ snapshot }) => async () => {
@ -78,9 +77,9 @@ export const useRecordTableContextMenuEntries = (
resetTableRowSelection();
if (deleteOneObject) {
if (deleteOneRecord) {
for (const rowId of rowIdsToDelete) {
await deleteOneObject(rowId);
await deleteOneRecord(rowId);
}
setTableRowIds((tableRowIds) =>
@ -109,24 +108,24 @@ export const useRecordTableContextMenuEntries = (
// Icon: IconNotes,
// onClick: () => {},
// },
{
label: isFavorite ? 'Remove from favorites' : 'Add to favorites',
Icon: isFavorite ? IconHeartOff : IconHeart,
onClick: () => handleFavoriteButtonClick(),
},
{
label: 'Delete',
Icon: IconTrash,
accent: 'danger',
onClick: () => handleDeleteClick(),
},
];
] as ContextMenuEntry[];
if (selectedRowIds.length > 1) {
contextMenuEntries.splice(2, 1);
if (selectedRowIds.length === 1) {
contextMenuEntries.unshift({
label: isFavorite ? 'Remove from favorites' : 'Add to favorites',
Icon: isFavorite ? IconHeartOff : IconHeart,
onClick: () => handleFavoriteButtonClick(),
});
}
setContextMenuEntries(contextMenuEntries as any);
setContextMenuEntries(contextMenuEntries);
}, [
selectedRowIds,
favorites,

View File

@ -5,23 +5,22 @@ import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadata
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
import { capitalize } from '~/utils/string/capitalize';
export const useUpdateOneObjectRecord = <T>({
export const useUpdateOneRecord = <T>({
objectNameSingular,
}: Pick<ObjectMetadataItemIdentifier, 'objectNameSingular'>) => {
const {
objectMetadataItem: foundObjectMetadataItem,
objectNotFoundInMetadata,
updateOneMutation,
objectMetadataItem,
objectMetadataItemNotFound,
updateOneRecordMutation,
getRecordFromCache,
findManyQuery,
findManyRecordsQuery,
} = useObjectMetadataItem({
objectNameSingular,
});
// TODO: type this with a minimal type at least with Record<string, any>
const [mutate] = useMutation(updateOneMutation);
const [mutateUpdateOneRecord] = useMutation(updateOneRecordMutation);
const updateOneObject = async ({
const updateOneRecord = async ({
idToUpdate,
input,
forceRefetch,
@ -30,13 +29,13 @@ export const useUpdateOneObjectRecord = <T>({
input: Record<string, any>;
forceRefetch?: boolean;
}) => {
if (!foundObjectMetadataItem || !objectNameSingular) {
if (!objectMetadataItem || !objectNameSingular) {
return null;
}
const cachedRecord = getRecordFromCache(idToUpdate);
const updatedObject = await mutate({
const updatedRecord = await mutateUpdateOneRecord({
variables: {
idToUpdate: idToUpdate,
input: {
@ -50,16 +49,16 @@ export const useUpdateOneObjectRecord = <T>({
},
},
refetchQueries: forceRefetch
? [getOperationName(findManyQuery) ?? '']
? [getOperationName(findManyRecordsQuery) ?? '']
: undefined,
awaitRefetchQueries: forceRefetch,
});
return updatedObject.data[`update${capitalize(objectNameSingular)}`] as T;
return updatedRecord.data[`update${capitalize(objectNameSingular)}`] as T;
};
return {
updateOneObject,
objectNotFoundInMetadata,
updateOneRecord,
objectMetadataItemNotFound,
};
};

View File

@ -1,9 +0,0 @@
import { atomFamily } from 'recoil';
export const isFetchingMoreObjectsFamilyState = atomFamily<
boolean,
string | undefined
>({
key: 'isFetchingMoreObjectsFamilyState',
default: false,
});

View File

@ -0,0 +1,9 @@
import { atomFamily } from 'recoil';
export const isFetchingMoreRecordsFamilyState = atomFamily<
boolean,
string | undefined
>({
key: 'isFetchingMoreRecordsFamilyState',
default: false,
});

View File

@ -1,5 +0,0 @@
import { PaginatedObjectTypeResults } from './PaginatedObjectTypeResults';
export type PaginatedObjectType<ObjectType extends { id: string }> = {
[objectNamePlural: string]: PaginatedObjectTypeResults<ObjectType>;
};

View File

@ -1,14 +0,0 @@
export type PaginatedObjectTypeEdge<ObjectType extends { id: string }> = {
node: ObjectType;
cursor: string;
};
export type PaginatedObjectTypeResults<ObjectType extends { id: string }> = {
__typename?: string;
edges: PaginatedObjectTypeEdge<ObjectType>[];
pageInfo: {
hasNextPage: boolean;
startCursor: string;
endCursor: string;
};
};

View File

@ -0,0 +1,5 @@
import { PaginatedRecordTypeResults } from './PaginatedRecordTypeResults';
export type PaginatedRecordType<RecordType extends { id: string }> = {
[objectNamePlural: string]: PaginatedRecordTypeResults<RecordType>;
};

View File

@ -0,0 +1,14 @@
export type PaginatedRecordTypeEdge<RecordType extends { id: string }> = {
node: RecordType;
cursor: string;
};
export type PaginatedRecordTypeResults<RecordType extends { id: string }> = {
__typename?: string;
edges: PaginatedRecordTypeEdge<RecordType>[];
pageInfo: {
hasNextPage: boolean;
startCursor: string;
endCursor: string;
};
};

View File

@ -0,0 +1,17 @@
import { PaginatedRecordTypeEdge } from '@/object-record/types/PaginatedRecordTypeResults';
export const filterUniqueRecordEdgesByCursor = <
RecordType extends { id: string },
>(
arrayToFilter: PaginatedRecordTypeEdge<RecordType>[],
) => {
const seenCursors = new Set();
return arrayToFilter.filter((item) => {
const currentCursor = item.cursor;
return seenCursors.has(currentCursor)
? false
: seenCursors.add(currentCursor);
});
};

View File

@ -4,7 +4,7 @@ import { EMPTY_MUTATION } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { capitalize } from '~/utils/string/capitalize';
export const useGenerateDeleteOneObjectMutation = ({
export const generateDeleteOneRecordMutation = ({
objectMetadataItem,
}: {
objectMetadataItem: ObjectMetadataItem | undefined | null;

View File

@ -1,24 +0,0 @@
export const mapPaginatedObjectsToObjects = <
ObjectType extends { id: string } & Record<string, any>,
ObjectTypeQuery extends {
[objectNamePlural: string]: {
edges: ObjectEdge[];
};
},
ObjectEdge extends {
node: ObjectType;
},
>({
pagedObjects,
objectNamePlural,
}: {
pagedObjects: ObjectTypeQuery | undefined;
objectNamePlural: string;
}) => {
const formattedObjects: ObjectType[] =
pagedObjects?.[objectNamePlural]?.edges?.map((objectEdge: ObjectEdge) => ({
...objectEdge.node,
})) ?? [];
return formattedObjects;
};

View File

@ -0,0 +1,24 @@
export const mapPaginatedRecordsToRecords = <
RecordType extends { id: string } & Record<string, any>,
RecordTypeQuery extends {
[objectNamePlural: string]: {
edges: RecordEdge[];
};
},
RecordEdge extends {
node: RecordType;
},
>({
pagedRecords,
objectNamePlural,
}: {
pagedRecords: RecordTypeQuery | undefined;
objectNamePlural: string;
}) => {
const formattedRecords: RecordType[] =
pagedRecords?.[objectNamePlural]?.edges?.map((recordEdge: RecordEdge) => ({
...recordEdge.node,
})) ?? [];
return formattedRecords;
};

View File

@ -108,13 +108,16 @@ export const PeopleCard = ({
};
// TODO: refactor with useObjectMetadataItem V2 with typed hooks
const { findManyQuery, updateOneMutation, deleteOneMutation } =
useObjectMetadataItem({
objectNameSingular: 'person',
});
const {
findManyRecordsQuery,
updateOneRecordMutation,
deleteOneRecordMutation,
} = useObjectMetadataItem({
objectNameSingular: 'person',
});
const [updatePerson] = useMutation(updateOneMutation);
const [deletePerson] = useMutation(deleteOneMutation);
const [updatePerson] = useMutation(updateOneRecordMutation);
const [deletePerson] = useMutation(deleteOneRecordMutation);
const handleDetachPerson = async () => {
await updatePerson({
@ -124,7 +127,7 @@ export const PeopleCard = ({
companyId: null,
},
},
refetchQueries: [getOperationName(findManyQuery) ?? ''],
refetchQueries: [getOperationName(findManyRecordsQuery) ?? ''],
});
};
@ -133,7 +136,7 @@ export const PeopleCard = ({
variables: {
idToDelete: person.id,
},
refetchQueries: [getOperationName(findManyQuery) ?? ''],
refetchQueries: [getOperationName(findManyRecordsQuery) ?? ''],
});
};

View File

@ -1,19 +1,19 @@
import { useRecoilCallback } from 'recoil';
import { useCreateOneObjectRecord } from '@/object-record/hooks/useCreateOneObjectRecord';
import { useDeleteOneObjectRecord } from '@/object-record/hooks/useDeleteOneObjectRecord';
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
import { useDeleteOneRecord } from '@/object-record/hooks/useDeleteOneRecord';
import { currentPipelineState } from '@/pipeline/states/currentPipelineState';
import { PipelineStep } from '@/pipeline/types/PipelineStep';
import { BoardColumnDefinition } from '@/ui/object/record-board/types/BoardColumnDefinition';
export const usePipelineSteps = () => {
const { createOneObject: createOnePipelineStep } =
useCreateOneObjectRecord<PipelineStep>({
const { createOneRecord: createOnePipelineStep } =
useCreateOneRecord<PipelineStep>({
objectNameSingular: 'pipelineStep',
});
const { deleteOneObject: deleteOnePipelineStep } =
useDeleteOneObjectRecord<PipelineStep>({
const { deleteOneRecord: deleteOnePipelineStep } =
useDeleteOneRecord<PipelineStep>({
objectNameSingular: 'pipelineStep',
});

View File

@ -1,7 +1,7 @@
import { QueryHookOptions, QueryResult } from '@apollo/client';
import { isNonEmptyString } from '@sniptt/guards';
import { mapPaginatedObjectsToObjects } from '@/object-record/utils/mapPaginatedObjectsToObjects';
import { mapPaginatedRecordsToRecords } from '@/object-record/utils/mapPaginatedRecordsToRecords';
import { EntitiesForMultipleEntitySelect } from '@/ui/input/relation-picker/components/MultipleEntitySelect';
import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelect';
import { assertNotNull } from '~/utils/assert';
@ -19,6 +19,8 @@ export const DEFAULT_SEARCH_REQUEST_LIMIT = 60;
// TODO: use this for all search queries, because we need selectedEntities and entitiesToSelect each time we want to search
// Filtered entities to select are
// TODO: replace query hooks by useFindManyRecords
export const useFilteredSearchEntityQuery = ({
queryHook,
orderByField,
@ -135,21 +137,21 @@ export const useFilteredSearchEntityQuery = ({
});
return {
selectedEntities: mapPaginatedObjectsToObjects({
selectedEntities: mapPaginatedRecordsToRecords({
objectNamePlural: objectNamePlural,
pagedObjects: selectedEntitiesData,
pagedRecords: selectedEntitiesData,
})
.map(mappingFunction)
.filter(assertNotNull),
filteredSelectedEntities: mapPaginatedObjectsToObjects({
filteredSelectedEntities: mapPaginatedRecordsToRecords({
objectNamePlural: objectNamePlural,
pagedObjects: filteredSelectedEntitiesData,
pagedRecords: filteredSelectedEntitiesData,
})
.map(mappingFunction)
.filter(assertNotNull),
entitiesToSelect: mapPaginatedObjectsToObjects({
entitiesToSelect: mapPaginatedRecordsToRecords({
objectNamePlural: objectNamePlural,
pagedObjects: entitiesToSelectData,
pagedRecords: entitiesToSelectData,
})
.map(mappingFunction)
.filter(assertNotNull),

View File

@ -1,4 +1,4 @@
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { assertNotNull } from '~/utils/assert';
export const useFieldPreviewValue = ({
@ -10,12 +10,12 @@ export const useFieldPreviewValue = ({
objectNamePlural: string;
skip?: boolean;
}) => {
const { objects } = useFindManyObjectRecords({
const { records } = useFindManyRecords({
objectNamePlural,
skip,
});
const firstRecordWithValue = objects.find(
const firstRecordWithValue = records.find(
(record) => assertNotNull(record[fieldName]) && record[fieldName] !== '',
);

View File

@ -1,5 +1,5 @@
import { useObjectMetadataItemForSettings } from '@/object-metadata/hooks/useObjectMetadataItemForSettings';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
export const useRelationFieldPreviewValue = ({
relationObjectMetadataId,
@ -14,7 +14,7 @@ export const useRelationFieldPreviewValue = ({
? findObjectMetadataItemById(relationObjectMetadataId)
: undefined;
const { objects: relationObjects } = useFindManyObjectRecords({
const { records: relationObjects } = useFindManyRecords({
objectNamePlural: relationObjectMetadataItem?.namePlural,
skip: skip || !relationObjectMetadataItem,
});

View File

@ -3,7 +3,7 @@ import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { Tag } from '@/ui/display/tag/components/Tag';
import { useLazyLoadIcon } from '@/ui/input/hooks/useLazyLoadIcon';
import { TableCell } from '@/ui/layout/table/components/TableCell';
@ -36,7 +36,7 @@ export const SettingsObjectItemTableRow = ({
}: SettingsObjectItemTableRowProps) => {
const theme = useTheme();
const { objects } = useFindManyObjectRecords({
const { records } = useFindManyRecords({
objectNamePlural: objectItem.namePlural,
});
@ -58,7 +58,7 @@ export const SettingsObjectItemTableRow = ({
<TableCell align="right">
{objectItem.fields.filter((field) => !field.isSystem).length}
</TableCell>
<TableCell align="right">{objects.length}</TableCell>
<TableCell align="right">{records.length}</TableCell>
<StyledActionTableCell>{action}</StyledActionTableCell>
</StyledObjectTableRow>
);

View File

@ -5,7 +5,7 @@ import { useRecoilState, useRecoilValue } from 'recoil';
import { currentUserState } from '@/auth/states/currentUserState';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { TextInput } from '@/ui/input/components/TextInput';
import { logError } from '~/utils/logError';
@ -40,10 +40,9 @@ export const NameFields = ({
currentWorkspaceMember?.name?.lastName ?? '',
);
const { updateOneObject, objectNotFoundInMetadata } =
useUpdateOneObjectRecord({
objectNameSingular: 'workspaceMember',
});
const { updateOneRecord, objectMetadataItemNotFound } = useUpdateOneRecord({
objectNameSingular: 'workspaceMember',
});
// TODO: Enhance this with react-web-hook-form (https://www.react-hook-form.com)
const debouncedUpdate = debounce(async () => {
@ -59,10 +58,10 @@ export const NameFields = ({
}
if (autoSave) {
if (!updateOneObject || objectNotFoundInMetadata) {
if (!updateOneRecord || objectMetadataItemNotFound) {
throw new Error('Object not found in metadata');
}
await updateOneObject({
await updateOneRecord({
idToUpdate: currentWorkspaceMember?.id,
input: {
name: {

View File

@ -2,7 +2,7 @@ import { useState } from 'react';
import { useRecoilState } from 'recoil';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { ImageInput } from '@/ui/input/components/ImageInput';
import { getImageAbsoluteURIOrBase64 } from '@/users/utils/getProfilePictureAbsoluteURI';
import { useUploadProfilePictureMutation } from '~/generated/graphql';
@ -19,10 +19,9 @@ export const ProfilePictureUploader = () => {
useState<AbortController | null>(null);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const { updateOneObject, objectNotFoundInMetadata } =
useUpdateOneObjectRecord({
objectNameSingular: 'workspaceMember',
});
const { updateOneRecord, objectMetadataItemNotFound } = useUpdateOneRecord({
objectNameSingular: 'workspaceMember',
});
const handleUpload = async (file: File) => {
if (!file) {
@ -55,10 +54,10 @@ export const ProfilePictureUploader = () => {
if (!avatarUrl) {
throw new Error('Avatar URL not found');
}
if (!updateOneObject || objectNotFoundInMetadata) {
if (!updateOneRecord || objectMetadataItemNotFound) {
throw new Error('Object not found in metadata');
}
await updateOneObject({
await updateOneRecord({
idToUpdate: currentWorkspaceMember?.id,
input: {
avatarUrl,
@ -81,13 +80,13 @@ export const ProfilePictureUploader = () => {
};
const handleRemove = async () => {
if (!updateOneObject || objectNotFoundInMetadata) {
if (!updateOneRecord || objectMetadataItemNotFound) {
throw new Error('Object not found in metadata');
}
if (!currentWorkspaceMember?.id) {
throw new Error('User is not logged in');
}
await updateOneObject({
await updateOneRecord({
idToUpdate: currentWorkspaceMember?.id,
input: {
avatarUrl: null,

View File

@ -15,7 +15,7 @@ export enum AppPath {
OpportunitiesPage = '/objects/opportunities',
RecordTablePage = '/objects/:objectNamePlural',
RecordShowPage = '/object/:objectNameSingular/:objectMetadataId',
RecordShowPage = '/object/:objectNameSingular/:objectRecordId',
SettingsCatchAll = `/settings/*`,
DevelopersCatchAll = `/developers/*`,

View File

@ -38,12 +38,14 @@ export const RelationPicker = ({
setRelationPickerSearchFilter(initialSearchFilter ?? '');
}, [initialSearchFilter, setRelationPickerSearchFilter]);
const { findManyQuery } = useObjectMetadataItem({
// TODO: refactor useFilteredSearchEntityQuery
const { findManyRecordsQuery } = useObjectMetadataItem({
objectNameSingular:
fieldDefinition.metadata.relationObjectMetadataNameSingular,
});
const useFindManyQuery = (options: any) => useQuery(findManyQuery, options);
const useFindManyQuery = (options: any) =>
useQuery(findManyRecordsQuery, options);
const { identifiersMapper, searchQuery } = useRelationPicker();

View File

@ -19,11 +19,13 @@ export const ObjectFilterDropdownEntitySelect = () => {
const objectMetadataNamePlural =
filterDefinitionUsedInDropdown?.relationObjectMetadataNamePlural ?? '';
const { findManyQuery } = useObjectMetadataItem({
// TODO: refactor useFilteredSearchEntityQuery
const { findManyRecordsQuery } = useObjectMetadataItem({
objectNameSingular: objectMetadataNameSingular,
});
const useFindManyQuery = (options: any) => useQuery(findManyQuery, options);
const useFindManyQuery = (options: any) =>
useQuery(findManyRecordsQuery, options);
const { identifiersMapper, searchQuery } = useRelationPicker();

View File

@ -3,7 +3,7 @@ import styled from '@emotion/styled';
import { DragDropContext, OnDragEndResponder } from '@hello-pangea/dnd'; // Atlassian dnd does not support StrictMode from RN 18, so we use a fork @hello-pangea/dnd https://github.com/atlassian/react-beautiful-dnd/issues/2350
import { useRecoilValue } from 'recoil';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { Opportunity } from '@/pipeline/types/Opportunity';
import { PageHotkeyScope } from '@/types/PageHotkeyScope';
import { BoardColumnContext } from '@/ui/object/record-board/contexts/BoardColumnContext';
@ -60,8 +60,8 @@ export const RecordBoard = ({
}: RecordBoardProps) => {
const boardColumns = useRecoilValue(boardColumnsState);
const { updateOneObject: updateOneOpportunity } =
useUpdateOneObjectRecord<Opportunity>({
const { updateOneRecord: updateOneOpportunity } =
useUpdateOneRecord<Opportunity>({
objectNameSingular: 'opportunity',
});

View File

@ -1,6 +1,6 @@
import { useRecoilState } from 'recoil';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { PipelineStep } from '@/pipeline/types/PipelineStep';
import { useMoveViewColumns } from '@/views/hooks/useMoveViewColumns';
@ -12,8 +12,8 @@ export const useBoardColumns = () => {
const { handleColumnMove } = useMoveViewColumns();
const { updateOneObject: updateOnePipelineStep } =
useUpdateOneObjectRecord<PipelineStep>({
const { updateOneRecord: updateOnePipelineStep } =
useUpdateOneRecord<PipelineStep>({
objectNameSingular: 'pipelineStep',
});

View File

@ -1,7 +1,7 @@
import { useApolloClient } from '@apollo/client';
import { useRecoilCallback } from 'recoil';
import { useDeleteOneObjectRecord } from '@/object-record/hooks/useDeleteOneObjectRecord';
import { useDeleteOneRecord } from '@/object-record/hooks/useDeleteOneRecord';
import { Opportunity } from '@/pipeline/types/Opportunity';
import { selectedCardIdsSelector } from '../states/selectors/selectedCardIdsSelector';
@ -12,8 +12,8 @@ export const useDeleteSelectedBoardCards = () => {
const removeCardIds = useRemoveCardIds();
const apolloClient = useApolloClient();
const { deleteOneObject: deleteOneOpportunity } =
useDeleteOneObjectRecord<Opportunity>({
const { deleteOneRecord: deleteOneOpportunity } =
useDeleteOneRecord<Opportunity>({
objectNameSingular: 'opportunity',
});

View File

@ -4,7 +4,7 @@ import { useRecoilState, useRecoilValue } from 'recoil';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useObjectRecordTable } from '@/object-record/hooks/useObjectRecordTable';
import { isFetchingMoreObjectsFamilyState } from '@/object-record/states/isFetchingMoreObjectsFamilyState';
import { isFetchingMoreRecordsFamilyState } from '@/object-record/states/isFetchingMoreRecordsFamilyState';
import { isDefined } from '~/utils/isDefined';
import { RowIdContext } from '../contexts/RowIdContext';
@ -29,14 +29,14 @@ export const RecordTableBody = () => {
);
const [isFetchingMoreObjects] = useRecoilState(
isFetchingMoreObjectsFamilyState(foundObjectMetadataItem?.namePlural),
isFetchingMoreRecordsFamilyState(foundObjectMetadataItem?.namePlural),
);
const isFetchingRecordTableData = useRecoilValue(
isFetchingRecordTableDataState,
);
const { fetchMoreObjects } = useObjectRecordTable();
const { fetchMoreRecords: fetchMoreObjects } = useObjectRecordTable();
useEffect(() => {
if (lastTableRowIsVisible && isDefined(fetchMoreObjects)) {

View File

@ -2,7 +2,7 @@ import { useCallback } from 'react';
import { useRecoilState } from 'recoil';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { ColorScheme } from '@/workspace-member/types/WorkspaceMember';
export const useColorScheme = () => {
@ -10,10 +10,9 @@ export const useColorScheme = () => {
currentWorkspaceMemberState,
);
const { updateOneObject: updateOneWorkspaceMember } =
useUpdateOneObjectRecord({
objectNameSingular: 'workspaceMember',
});
const { updateOneRecord: updateOneWorkspaceMember } = useUpdateOneRecord({
objectNameSingular: 'workspaceMember',
});
const colorScheme = currentWorkspaceMember?.colorScheme ?? 'System';

View File

@ -2,8 +2,8 @@ import { useEffect } from 'react';
import { useSearchParams } from 'react-router-dom';
import { useRecoilCallback, useRecoilValue } from 'recoil';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { PaginatedObjectTypeResults } from '@/object-record/types/PaginatedObjectTypeResults';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { PaginatedRecordTypeResults } from '@/object-record/types/PaginatedRecordTypeResults';
import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';
import { useViewBar } from '@/views/hooks/useViewBar';
import { GraphQLView } from '@/views/types/GraphQLView';
@ -30,7 +30,7 @@ export const ViewBarEffect = () => {
const viewType = useRecoilValue(viewTypeState);
const viewObjectMetadataId = useRecoilValue(viewObjectMetadataIdState);
useFindManyObjectRecords({
useFindManyRecords({
skip: !viewObjectMetadataId,
objectNamePlural: 'views',
filter: {
@ -39,7 +39,7 @@ export const ViewBarEffect = () => {
},
onCompleted: useRecoilCallback(
({ snapshot, set }) =>
async (data: PaginatedObjectTypeResults<GraphQLView>) => {
async (data: PaginatedRecordTypeResults<GraphQLView>) => {
const nextViews = data.edges.map(({ node }) => node);
const { viewsState, currentViewIdState } =

View File

@ -7,9 +7,10 @@ import { getViewScopedStatesFromSnapshot } from '@/views/utils/getViewScopedStat
import { getViewScopedStateValuesFromSnapshot } from '@/views/utils/getViewScopedStateValuesFromSnapshot';
export const useViewFields = (viewScopeId: string) => {
const { updateOneMutation, createOneMutation } = useObjectMetadataItem({
objectNameSingular: 'viewField',
});
const { updateOneRecordMutation, createOneRecordMutation } =
useObjectMetadataItem({
objectNameSingular: 'viewField',
});
const { modifyRecordFromCache } = useObjectMetadataItem({
objectNameSingular: 'view',
@ -56,7 +57,7 @@ export const useViewFields = (viewScopeId: string) => {
return Promise.all(
viewFieldsToCreate.map((viewField) =>
apolloClient.mutate({
mutation: createOneMutation,
mutation: createOneRecordMutation,
variables: {
input: {
fieldMetadataId: viewField.fieldMetadataId,
@ -79,7 +80,7 @@ export const useViewFields = (viewScopeId: string) => {
return Promise.all(
viewFieldsToUpdate.map((viewField) =>
apolloClient.mutate({
mutation: updateOneMutation,
mutation: updateOneRecordMutation,
variables: {
idToUpdate: viewField.id,
input: {
@ -145,8 +146,8 @@ export const useViewFields = (viewScopeId: string) => {
viewScopeId,
modifyRecordFromCache,
apolloClient,
createOneMutation,
updateOneMutation,
createOneRecordMutation,
updateOneRecordMutation,
],
);

View File

@ -11,10 +11,13 @@ import { getViewScopedStateValuesFromSnapshot } from '@/views/utils/getViewScope
import { useViewScopedStates } from './useViewScopedStates';
export const useViewFilters = (viewScopeId: string) => {
const { updateOneMutation, createOneMutation, deleteOneMutation } =
useObjectMetadataItem({
objectNameSingular: 'viewFilter',
});
const {
updateOneRecordMutation,
createOneRecordMutation,
deleteOneRecordMutation,
} = useObjectMetadataItem({
objectNameSingular: 'viewFilter',
});
const { modifyRecordFromCache } = useObjectMetadataItem({
objectNameSingular: 'view',
@ -55,7 +58,7 @@ export const useViewFilters = (viewScopeId: string) => {
return Promise.all(
viewFiltersToCreate.map((viewFilter) =>
apolloClient.mutate({
mutation: createOneMutation,
mutation: createOneRecordMutation,
variables: {
input: {
fieldMetadataId: viewFilter.fieldMetadataId,
@ -76,7 +79,7 @@ export const useViewFilters = (viewScopeId: string) => {
return Promise.all(
viewFiltersToUpdate.map((viewFilter) =>
apolloClient.mutate({
mutation: updateOneMutation,
mutation: updateOneRecordMutation,
variables: {
idToUpdate: viewFilter.id,
input: {
@ -96,7 +99,7 @@ export const useViewFilters = (viewScopeId: string) => {
return Promise.all(
viewFilterIdsToDelete.map((viewFilterId) =>
apolloClient.mutate({
mutation: deleteOneMutation,
mutation: deleteOneRecordMutation,
variables: {
idToDelete: viewFilterId,
},
@ -163,10 +166,10 @@ export const useViewFilters = (viewScopeId: string) => {
},
[
apolloClient,
createOneMutation,
deleteOneMutation,
createOneRecordMutation,
deleteOneRecordMutation,
modifyRecordFromCache,
updateOneMutation,
updateOneRecordMutation,
viewScopeId,
],
);

View File

@ -11,10 +11,13 @@ import { getViewScopedStateValuesFromSnapshot } from '@/views/utils/getViewScope
import { useViewScopedStates } from './useViewScopedStates';
export const useViewSorts = (viewScopeId: string) => {
const { updateOneMutation, createOneMutation, deleteOneMutation } =
useObjectMetadataItem({
objectNameSingular: 'viewSort',
});
const {
updateOneRecordMutation,
createOneRecordMutation,
deleteOneRecordMutation,
} = useObjectMetadataItem({
objectNameSingular: 'viewSort',
});
const { modifyRecordFromCache } = useObjectMetadataItem({
objectNameSingular: 'view',
@ -51,7 +54,7 @@ export const useViewSorts = (viewScopeId: string) => {
return Promise.all(
viewSortsToCreate.map((viewSort) =>
apolloClient.mutate({
mutation: createOneMutation,
mutation: createOneRecordMutation,
variables: {
input: {
fieldMetadataId: viewSort.fieldMetadataId,
@ -70,7 +73,7 @@ export const useViewSorts = (viewScopeId: string) => {
return Promise.all(
viewSortsToUpdate.map((viewSort) =>
apolloClient.mutate({
mutation: updateOneMutation,
mutation: updateOneRecordMutation,
variables: {
idToUpdate: viewSort.id,
input: {
@ -88,7 +91,7 @@ export const useViewSorts = (viewScopeId: string) => {
return Promise.all(
viewSortIdsToDelete.map((viewSortId) =>
apolloClient.mutate({
mutation: deleteOneMutation,
mutation: deleteOneRecordMutation,
variables: {
idToDelete: viewSortId,
},
@ -150,10 +153,10 @@ export const useViewSorts = (viewScopeId: string) => {
},
[
apolloClient,
createOneMutation,
deleteOneMutation,
createOneRecordMutation,
deleteOneRecordMutation,
modifyRecordFromCache,
updateOneMutation,
updateOneRecordMutation,
viewScopeId,
],
);

View File

@ -7,10 +7,10 @@ import { getViewScopedStateValuesFromSnapshot } from '@/views/utils/getViewScope
export const useViews = (scopeId: string) => {
const {
updateOneMutation,
createOneMutation,
deleteOneMutation,
findManyQuery,
updateOneRecordMutation: updateOneMutation,
createOneRecordMutation: createOneMutation,
deleteOneRecordMutation: deleteOneMutation,
findManyRecordsQuery: findManyQuery,
} = useObjectMetadataItem({
objectNameSingular: 'view',
});

View File

@ -3,7 +3,7 @@ import { useSearchParams } from 'react-router-dom';
import { useRecoilCallback, useRecoilState, useSetRecoilState } from 'recoil';
import { v4 } from 'uuid';
import { PaginatedObjectTypeResults } from '@/object-record/types/PaginatedObjectTypeResults';
import { PaginatedRecordTypeResults } from '@/object-record/types/PaginatedRecordTypeResults';
import { useAvailableScopeIdOrThrow } from '@/ui/utilities/recoil-scope/scopes-internal/hooks/useAvailableScopeId';
import { ViewField } from '@/views/types/ViewField';
import { ViewFilter } from '@/views/types/ViewFilter';
@ -94,7 +94,7 @@ export const useViewBar = (props?: UseViewProps) => {
const loadViewFields = useRecoilCallback(
({ snapshot, set }) =>
async (
data: PaginatedObjectTypeResults<ViewField>,
data: PaginatedRecordTypeResults<ViewField>,
currentViewId: string,
) => {
const {
@ -139,7 +139,7 @@ export const useViewBar = (props?: UseViewProps) => {
const loadViewFilters = useRecoilCallback(
({ snapshot, set }) =>
async (
data: PaginatedObjectTypeResults<Required<ViewFilter>>,
data: PaginatedRecordTypeResults<Required<ViewFilter>>,
currentViewId: string,
) => {
const {
@ -192,7 +192,7 @@ export const useViewBar = (props?: UseViewProps) => {
const loadViewSorts = useRecoilCallback(
({ snapshot, set }) =>
async (
data: PaginatedObjectTypeResults<Required<ViewSort>>,
data: PaginatedRecordTypeResults<Required<ViewSort>>,
currentViewId: string,
) => {
const { availableSortDefinitions, savedViewSorts, onViewSortsChange } =

View File

@ -1,4 +1,4 @@
import { PaginatedObjectTypeResults } from '@/object-record/types/PaginatedObjectTypeResults';
import { PaginatedRecordTypeResults } from '@/object-record/types/PaginatedRecordTypeResults';
import { ViewField } from '@/views/types/ViewField';
import { ViewFilter } from '@/views/types/ViewFilter';
import { ViewSort } from '@/views/types/ViewSort';
@ -7,7 +7,7 @@ export type GraphQLView = {
id: string;
name: string;
objectMetadataId: string;
viewFields: PaginatedObjectTypeResults<ViewField>;
viewFilters: PaginatedObjectTypeResults<ViewFilter>;
viewSorts: PaginatedObjectTypeResults<ViewSort>;
viewFields: PaginatedRecordTypeResults<ViewField>;
viewFilters: PaginatedRecordTypeResults<ViewFilter>;
viewSorts: PaginatedRecordTypeResults<ViewSort>;
};

View File

@ -12,7 +12,7 @@ import { Title } from '@/auth/components/Title';
import { useOnboardingStatus } from '@/auth/hooks/useOnboardingStatus';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { OnboardingStatus } from '@/auth/utils/getOnboardingStatus';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { ProfilePictureUploader } from '@/settings/profile/components/ProfilePictureUploader';
import { PageHotkeyScope } from '@/types/PageHotkeyScope';
import { H2Title } from '@/ui/display/typography/components/H2Title';
@ -62,8 +62,8 @@ export const CreateProfile = () => {
currentWorkspaceMemberState,
);
const { updateOneObject, objectNotFoundInMetadata } =
useUpdateOneObjectRecord<WorkspaceMember>({
const { updateOneRecord, objectMetadataItemNotFound } =
useUpdateOneRecord<WorkspaceMember>({
objectNameSingular: 'workspaceMember',
});
@ -91,11 +91,11 @@ export const CreateProfile = () => {
if (!data.firstName || !data.lastName) {
throw new Error('First name or last name is missing');
}
if (!updateOneObject || objectNotFoundInMetadata) {
if (!updateOneRecord || objectMetadataItemNotFound) {
throw new Error('Object not found in metadata');
}
await updateOneObject({
await updateOneRecord({
idToUpdate: currentWorkspaceMember?.id,
input: {
name: {
@ -127,9 +127,9 @@ export const CreateProfile = () => {
currentWorkspaceMember?.id,
enqueueSnackBar,
navigate,
objectNotFoundInMetadata,
objectMetadataItemNotFound,
setCurrentWorkspaceMember,
updateOneObject,
updateOneRecord,
],
);

View File

@ -2,7 +2,7 @@ import styled from '@emotion/styled';
import { CompanyBoard } from '@/companies/board/components/CompanyBoard';
import { CompanyBoardRecoilScopeContext } from '@/companies/states/recoil-scope-contexts/CompanyBoardRecoilScopeContext';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { PipelineAddButton } from '@/pipeline/components/PipelineAddButton';
import { usePipelineSteps } from '@/pipeline/hooks/usePipelineSteps';
import { PipelineStep } from '@/pipeline/types/PipelineStep';
@ -24,8 +24,8 @@ export const Opportunities = () => {
const { handlePipelineStepAdd, handlePipelineStepDelete } =
usePipelineSteps();
const { updateOneObject: updateOnePipelineStep } =
useUpdateOneObjectRecord<PipelineStep>({
const { updateOneRecord: updateOnePipelineStep } =
useUpdateOneRecord<PipelineStep>({
objectNameSingular: 'pipelineStep',
});

View File

@ -3,8 +3,8 @@ import styled from '@emotion/styled';
import { useRecoilValue } from 'recoil';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { useDeleteOneObjectRecord } from '@/object-record/hooks/useDeleteOneObjectRecord';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { useDeleteOneRecord } from '@/object-record/hooks/useDeleteOneRecord';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
import { IconSettings, IconTrash } from '@/ui/display/icon';
import { H1Title } from '@/ui/display/typography/components/H1Title';
@ -34,12 +34,11 @@ export const SettingsWorkspaceMembers = () => {
string | undefined
>();
const { objects: workspaceMembers } =
useFindManyObjectRecords<WorkspaceMember>({
objectNamePlural: 'workspaceMembers',
});
const { deleteOneObject: deleteOneWorkspaceMember } =
useDeleteOneObjectRecord<WorkspaceMember>({
const { records: workspaceMembers } = useFindManyRecords<WorkspaceMember>({
objectNamePlural: 'workspaceMembers',
});
const { deleteOneRecord: deleteOneWorkspaceMember } =
useDeleteOneRecord<WorkspaceMember>({
objectNameSingular: 'workspaceMember',
});
const currentWorkspace = useRecoilValue(currentWorkspaceState);

View File

@ -1,12 +1,12 @@
import { useEffect, useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { useCreateOneRelationMetadata } from '@/object-metadata/hooks/useCreateOneRelationMetadata';
import { useCreateOneRelationMetadataItem } from '@/object-metadata/hooks/useCreateOneRelationMetadataItem';
import { useFieldMetadataItem } from '@/object-metadata/hooks/useFieldMetadataItem';
import { useObjectMetadataItemForSettings } from '@/object-metadata/hooks/useObjectMetadataItemForSettings';
import { useCreateOneObjectRecord } from '@/object-record/hooks/useCreateOneObjectRecord';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { PaginatedObjectTypeResults } from '@/object-record/types/PaginatedObjectTypeResults';
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { PaginatedRecordTypeResults } from '@/object-record/types/PaginatedRecordTypeResults';
import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons';
import { SettingsHeaderContainer } from '@/settings/components/SettingsHeaderContainer';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
@ -69,17 +69,17 @@ export const SettingsObjectNewFieldStep2 = () => {
const [objectViews, setObjectViews] = useState<View[]>([]);
const [relationObjectViews, setRelationObjectViews] = useState<View[]>([]);
const { createOneObject: createOneViewField } = useCreateOneObjectRecord({
const { createOneRecord: createOneViewField } = useCreateOneRecord({
objectNameSingular: 'viewField',
});
useFindManyObjectRecords({
useFindManyRecords({
objectNamePlural: 'views',
filter: {
type: { eq: ViewType.Table },
objectMetadataId: { eq: activeObjectMetadataItem?.id },
},
onCompleted: async (data: PaginatedObjectTypeResults<View>) => {
onCompleted: async (data: PaginatedRecordTypeResults<View>) => {
const views = data.edges;
if (!views) return;
@ -88,14 +88,14 @@ export const SettingsObjectNewFieldStep2 = () => {
},
});
useFindManyObjectRecords({
useFindManyRecords({
objectNamePlural: 'views',
skip: !formValues.relation?.objectMetadataId,
filter: {
type: { eq: ViewType.Table },
objectMetadataId: { eq: formValues.relation?.objectMetadataId },
},
onCompleted: async (data: PaginatedObjectTypeResults<View>) => {
onCompleted: async (data: PaginatedRecordTypeResults<View>) => {
const views = data.edges;
if (!views) return;
@ -104,7 +104,8 @@ export const SettingsObjectNewFieldStep2 = () => {
},
});
const { createOneRelationMetadata } = useCreateOneRelationMetadata();
const { createOneRelationMetadataItem: createOneRelationMetadata } =
useCreateOneRelationMetadataItem();
if (!activeObjectMetadataItem) return null;

View File

@ -5,9 +5,9 @@ import { DateTime } from 'luxon';
import { useRecoilState } from 'recoil';
import { useOptimisticEvict } from '@/apollo/optimistic-effect/hooks/useOptimisticEvict';
import { useCreateOneObjectRecord } from '@/object-record/hooks/useCreateOneObjectRecord';
import { useFindOneObjectRecord } from '@/object-record/hooks/useFindOneObjectRecord';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
import { useFindOneRecord } from '@/object-record/hooks/useFindOneRecord';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { SettingsHeaderContainer } from '@/settings/components/SettingsHeaderContainer';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
import { ApiKeyInput } from '@/settings/developers/components/ApiKeyInput';
@ -50,16 +50,14 @@ export const SettingsDevelopersApiKeyDetail = () => {
const { performOptimisticEvict } = useOptimisticEvict();
const [generateOneApiKeyToken] = useGenerateApiKeyTokenMutation();
const { createOneObject: createOneApiKey } = useCreateOneObjectRecord<ApiKey>(
{
objectNameSingular: 'apiKey',
},
);
const { updateOneObject: updateApiKey } = useUpdateOneObjectRecord<ApiKey>({
const { createOneRecord: createOneApiKey } = useCreateOneRecord<ApiKey>({
objectNameSingular: 'apiKey',
});
const { updateOneRecord: updateApiKey } = useUpdateOneRecord<ApiKey>({
objectNameSingular: 'apiKey',
});
const { object: apiKeyData } = useFindOneObjectRecord({
const { record: apiKeyData } = useFindOneRecord({
objectNameSingular: 'apiKey',
objectRecordId: apiKeyId,
});

View File

@ -2,7 +2,7 @@ import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import styled from '@emotion/styled';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { objectSettingsWidth } from '@/settings/data-model/constants/objectSettings';
import { SettingsApiKeysFieldItemTableRow } from '@/settings/developers/components/SettingsApiKeysFieldItemTableRow';
import { ApiFieldItem } from '@/settings/developers/types/ApiFieldItem';
@ -43,7 +43,7 @@ export const SettingsDevelopersApiKeys = () => {
const [apiKeys, setApiKeys] = useState<Array<ApiFieldItem>>([]);
const filter = { revokedAt: { is: 'NULL' } };
useFindManyObjectRecords({
useFindManyRecords({
objectNamePlural: 'apiKeys',
filter,
orderBy: {},

View File

@ -2,7 +2,7 @@ import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { DateTime } from 'luxon';
import { useCreateOneObjectRecord } from '@/object-record/hooks/useCreateOneObjectRecord';
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons';
import { SettingsHeaderContainer } from '@/settings/components/SettingsHeaderContainer';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
@ -30,9 +30,9 @@ export const SettingsDevelopersApiKeysNew = () => {
name: '',
});
const { createOneObject: createOneApiKey } = useCreateOneObjectRecord<ApiKey>(
{ objectNameSingular: 'apiKey' },
);
const { createOneRecord: createOneApiKey } = useCreateOneRecord<ApiKey>({
objectNameSingular: 'apiKey',
});
const onSave = async () => {
const expiresAt = DateTime.now()
.plus({ days: formValues.expirationDate ?? 30 })

View File

@ -3,7 +3,7 @@ import { graphql } from 'msw';
import { CREATE_EVENT } from '@/analytics/graphql/queries/createEvent';
import { GET_CLIENT_CONFIG } from '@/client-config/graphql/queries/getClientConfig';
import { FIND_MANY_METADATA_OBJECTS } from '@/object-metadata/graphql/queries';
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '@/object-metadata/graphql/queries';
import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser';
import { mockedActivities } from '~/testing/mock-data/activities';
@ -56,7 +56,7 @@ export const graphqlMocks = {
},
),
metadataGraphql.query(
getOperationName(FIND_MANY_METADATA_OBJECTS) ?? '',
getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? '',
(req, res, ctx) => {
return res(ctx.data({ objects: mockedObjectMetadataItems }));
},