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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
import { ActivityTarget } from '@/activities/types/ActivityTarget'; import { ActivityTarget } from '@/activities/types/ActivityTarget';
import { useCreateOneObjectRecord } from '@/object-record/hooks/useCreateOneObjectRecord'; import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
import { useDeleteOneObjectRecord } from '@/object-record/hooks/useDeleteOneObjectRecord'; import { useDeleteOneRecord } from '@/object-record/hooks/useDeleteOneRecord';
export const useHandleCheckableActivityTargetChange = ({ export const useHandleCheckableActivityTargetChange = ({
activityId, activityId,
@ -9,10 +9,11 @@ export const useHandleCheckableActivityTargetChange = ({
activityId: string; activityId: string;
currentActivityTargets: any[]; currentActivityTargets: any[];
}) => { }) => {
const { createOneObject } = useCreateOneObjectRecord<ActivityTarget>({ const { createOneRecord: createOneActivityTarget } =
objectNameSingular: 'activityTarget', useCreateOneRecord<ActivityTarget>({
}); objectNameSingular: 'activityTarget',
const { deleteOneObject } = useDeleteOneObjectRecord({ });
const { deleteOneRecord: deleteOneActivityTarget } = useDeleteOneRecord({
objectNameSingular: 'activityTarget', objectNameSingular: 'activityTarget',
}); });
@ -54,7 +55,7 @@ export const useHandleCheckableActivityTargetChange = ({
: null; : null;
const entity = entityFromToSelect ?? entityFromSelected; const entity = entityFromToSelect ?? entityFromSelected;
createOneObject?.({ createOneActivityTarget?.({
activityId: activityId, activityId: activityId,
companyId: entity.record.__typename === 'Company' ? entity.id : null, companyId: entity.record.__typename === 'Company' ? entity.id : null,
personId: entity.record.__typename === 'Person' ? entity.id : null, personId: entity.record.__typename === 'Person' ? entity.id : null,
@ -67,7 +68,7 @@ export const useHandleCheckableActivityTargetChange = ({
const currentActivityTargetId = currentActivityTargets.filter( const currentActivityTargetId = currentActivityTargets.filter(
({ companyId, personId }) => companyId === id || personId === id, ({ companyId, personId }) => companyId === id || personId === id,
)[0].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 { Activity, ActivityType } from '@/activities/types/Activity';
import { ActivityTarget } from '@/activities/types/ActivityTarget'; import { ActivityTarget } from '@/activities/types/ActivityTarget';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState'; 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 { useRightDrawer } from '@/ui/layout/right-drawer/hooks/useRightDrawer';
import { RightDrawerHotkeyScope } from '@/ui/layout/right-drawer/types/RightDrawerHotkeyScope'; import { RightDrawerHotkeyScope } from '@/ui/layout/right-drawer/types/RightDrawerHotkeyScope';
import { RightDrawerPages } from '@/ui/layout/right-drawer/types/RightDrawerPages'; import { RightDrawerPages } from '@/ui/layout/right-drawer/types/RightDrawerPages';
@ -17,14 +17,13 @@ import { getTargetableEntitiesWithParents } from '../utils/getTargetableEntities
export const useOpenCreateActivityDrawer = () => { export const useOpenCreateActivityDrawer = () => {
const { openRightDrawer } = useRightDrawer(); const { openRightDrawer } = useRightDrawer();
const { createOneObject: createOneActivityTarget } = const { createOneRecord: createOneActivityTarget } =
useCreateOneObjectRecord<ActivityTarget>({ useCreateOneRecord<ActivityTarget>({
objectNameSingular: 'activityTarget', objectNameSingular: 'activityTarget',
}); });
const { createOneObject: createOneActivity } = const { createOneRecord: createOneActivity } = useCreateOneRecord<Activity>({
useCreateOneObjectRecord<Activity>({ objectNameSingular: 'activity',
objectNameSingular: 'activity', });
});
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState); const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
const setHotkeyScope = useSetHotkeyScope(); const setHotkeyScope = useSetHotkeyScope();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ import { isNonEmptyArray } from '@sniptt/guards';
import { Company } from '@/companies/types/Company'; import { Company } from '@/companies/types/Company';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem'; 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 { PeopleCard } from '@/people/components/PeopleCard';
import { AddPersonToCompany } from './AddPersonToCompany'; import { AddPersonToCompany } from './AddPersonToCompany';
@ -47,11 +47,11 @@ const StyledTitle = styled.div`
`; `;
export const CompanyTeam = ({ company }: { company: any }) => { export const CompanyTeam = ({ company }: { company: any }) => {
const { findManyQuery } = useObjectMetadataItem({ const { findManyRecordsQuery } = useObjectMetadataItem({
objectNameSingular: 'person', objectNameSingular: 'person',
}); });
const { data } = useQuery(findManyQuery, { const { data } = useQuery(findManyRecordsQuery, {
variables: { variables: {
filter: { filter: {
companyId: { companyId: {
@ -61,9 +61,9 @@ export const CompanyTeam = ({ company }: { company: any }) => {
}, },
}); });
const people = mapPaginatedObjectsToObjects({ const people = mapPaginatedRecordsToRecords({
objectNamePlural: 'people', objectNamePlural: 'people',
pagedObjects: data ?? [], pagedRecords: data ?? [],
}); });
const peopleIds = people.map((person) => person.id); 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 { useRecoilState, useRecoilValue } from 'recoil';
import { Company } from '@/companies/types/Company'; 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 { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords'; import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { PaginatedObjectTypeResults } from '@/object-record/types/PaginatedObjectTypeResults'; import { PaginatedRecordTypeResults } from '@/object-record/types/PaginatedRecordTypeResults';
import { filterAvailableTableColumns } from '@/object-record/utils/filterAvailableTableColumns'; import { filterAvailableTableColumns } from '@/object-record/utils/filterAvailableTableColumns';
import { Opportunity } from '@/pipeline/types/Opportunity'; import { Opportunity } from '@/pipeline/types/Opportunity';
import { PipelineStep } from '@/pipeline/types/PipelineStep'; import { PipelineStep } from '@/pipeline/types/PipelineStep';
@ -65,7 +65,7 @@ export const HooksCompanyBoardEffect = ({
}); });
const { columnDefinitions, filterDefinitions, sortDefinitions } = const { columnDefinitions, filterDefinitions, sortDefinitions } =
useComputeDefinitionsFromFieldMetadata(objectMetadataItem); useColumnDefinitionsFromFieldMetadata(objectMetadataItem);
const [, setIsBoardLoaded] = useRecoilState(isBoardLoadedState); const [, setIsBoardLoaded] = useRecoilState(isBoardLoadedState);
@ -84,11 +84,11 @@ export const HooksCompanyBoardEffect = ({
'company-board-view', 'company-board-view',
); );
useFindManyObjectRecords({ useFindManyRecords({
objectNamePlural: 'pipelineSteps', objectNamePlural: 'pipelineSteps',
filter: {}, filter: {},
onCompleted: useCallback( onCompleted: useCallback(
(data: PaginatedObjectTypeResults<PipelineStep>) => { (data: PaginatedRecordTypeResults<PipelineStep>) => {
setPipelineSteps(data.edges.map((edge) => edge.node)); setPipelineSteps(data.edges.map((edge) => edge.node));
}, },
[], [],
@ -105,34 +105,32 @@ export const HooksCompanyBoardEffect = ({
objectMetadataItem?.fields ?? [], objectMetadataItem?.fields ?? [],
); );
const { fetchMoreObjects: fetchMoreOpportunities } = useFindManyObjectRecords( const { fetchMoreRecords: fetchMoreOpportunities } = useFindManyRecords({
{ skip: !pipelineSteps.length,
skip: !pipelineSteps.length, objectNamePlural: 'opportunities',
objectNamePlural: 'opportunities', filter: filter,
filter: filter, orderBy: orderBy,
orderBy: orderBy, onCompleted: useCallback(
onCompleted: useCallback( (data: PaginatedRecordTypeResults<Opportunity>) => {
(data: PaginatedObjectTypeResults<Opportunity>) => { const pipelineProgresses: Array<Opportunity> = data.edges.map(
const pipelineProgresses: Array<Opportunity> = data.edges.map( (edge) => edge.node,
(edge) => edge.node, );
);
updateCompanyBoardCardIds(pipelineProgresses); updateCompanyBoardCardIds(pipelineProgresses);
setOpportunities(pipelineProgresses); setOpportunities(pipelineProgresses);
setIsBoardLoaded(true); setIsBoardLoaded(true);
}, },
[setIsBoardLoaded, updateCompanyBoardCardIds], [setIsBoardLoaded, updateCompanyBoardCardIds],
), ),
}, });
);
useEffect(() => { useEffect(() => {
if (isDefined(fetchMoreOpportunities)) { if (isDefined(fetchMoreOpportunities)) {
fetchMoreOpportunities(); fetchMoreOpportunities();
} }
}, [fetchMoreOpportunities]); }, [fetchMoreOpportunities]);
const { fetchMoreObjects: fetchMoreCompanies } = useFindManyObjectRecords({ const { fetchMoreRecords: fetchMoreCompanies } = useFindManyRecords({
skip: !opportunities.length, skip: !opportunities.length,
objectNamePlural: 'companies', objectNamePlural: 'companies',
filter: { filter: {
@ -140,7 +138,7 @@ export const HooksCompanyBoardEffect = ({
in: opportunities.map((opportunity) => opportunity.companyId || ''), in: opportunities.map((opportunity) => opportunity.companyId || ''),
}, },
}, },
onCompleted: useCallback((data: PaginatedObjectTypeResults<Company>) => { onCompleted: useCallback((data: PaginatedRecordTypeResults<Company>) => {
setCompanies(data.edges.map((edge) => edge.node)); setCompanies(data.edges.map((edge) => edge.node));
}, []), }, []),
}); });

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
import { gql } from '@apollo/client'; import { gql } from '@apollo/client';
export const CREATE_ONE_METADATA_OBJECT = gql` export const CREATE_ONE_OBJECT_METADATA_ITEM = gql`
mutation CreateOneObjectMetadataItem($input: CreateOneObjectInput!) { mutation CreateOneObjectMetadataItem($input: CreateOneObjectInput!) {
createOneObject(input: $input) { createOneObject(input: $input) {
id 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!) { mutation CreateOneFieldMetadataItem($input: CreateOneFieldInput!) {
createOneField(input: $input) { createOneField(input: $input) {
id 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!) { mutation CreateOneRelationMetadata($input: CreateOneRelationInput!) {
createOneRelation(input: $input) { createOneRelation(input: $input) {
id 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( mutation UpdateOneFieldMetadataItem(
$idToUpdate: ID! $idToUpdate: ID!
$updatePayload: UpdateFieldInput! $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( mutation UpdateOneObjectMetadataItem(
$idToUpdate: ID! $idToUpdate: ID!
$updatePayload: UpdateObjectInput! $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!) { mutation DeleteOneObjectMetadataItem($idToDelete: ID!) {
deleteOneObject(input: { id: $idToDelete }) { deleteOneObject(input: { id: $idToDelete }) {
id 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!) { mutation DeleteOneFieldMetadataItem($idToDelete: ID!) {
deleteOneField(input: { id: $idToDelete }) { deleteOneField(input: { id: $idToDelete }) {
id id

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,8 +6,8 @@ import {
DeleteOneObjectMetadataItemMutationVariables, DeleteOneObjectMetadataItemMutationVariables,
} from '~/generated-metadata/graphql'; } from '~/generated-metadata/graphql';
import { DELETE_ONE_METADATA_OBJECT } from '../graphql/mutations'; import { DELETE_ONE_OBJECT_METADATA_ITEM } from '../graphql/mutations';
import { FIND_MANY_METADATA_OBJECTS } from '../graphql/queries'; import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries';
import { useApolloMetadataClient } from './useApolloMetadataClient'; import { useApolloMetadataClient } from './useApolloMetadataClient';
@ -17,7 +17,7 @@ export const useDeleteOneObjectMetadataItem = () => {
const [mutate] = useMutation< const [mutate] = useMutation<
DeleteOneObjectMetadataItemMutation, DeleteOneObjectMetadataItemMutation,
DeleteOneObjectMetadataItemMutationVariables DeleteOneObjectMetadataItemMutationVariables
>(DELETE_ONE_METADATA_OBJECT, { >(DELETE_ONE_OBJECT_METADATA_ITEM, {
client: apolloMetadataClient ?? ({} as ApolloClient<any>), client: apolloMetadataClient ?? ({} as ApolloClient<any>),
}); });
@ -29,7 +29,7 @@ export const useDeleteOneObjectMetadataItem = () => {
idToDelete, idToDelete,
}, },
awaitRefetchQueries: true, 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 { isDeeplyEqual } from '~/utils/isDeeplyEqual';
import { logError } from '~/utils/logError'; 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 { mapPaginatedObjectMetadataItemsToObjectMetadataItems } from '../utils/mapPaginatedObjectMetadataItemsToObjectMetadataItems';
import { useApolloMetadataClient } from './useApolloMetadataClient'; import { useApolloMetadataClient } from './useApolloMetadataClient';
@ -34,7 +34,7 @@ export const useFindManyObjectMetadataItems = ({
const { data, loading, error } = useQuery< const { data, loading, error } = useQuery<
ObjectMetadataItemsQuery, ObjectMetadataItemsQuery,
ObjectMetadataItemsQueryVariables ObjectMetadataItemsQueryVariables
>(FIND_MANY_METADATA_OBJECTS, { >(FIND_MANY_OBJECT_METADATA_ITEMS, {
variables: { variables: {
objectFilter, objectFilter,
fieldFilter, 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 { useRecoilValue } from 'recoil';
import { objectMetadataItemFamilySelector } from '@/object-metadata/states/objectMetadataItemFamilySelector'; import { objectMetadataItemFamilySelector } from '@/object-metadata/states/objectMetadataItemFamilySelector';
import { useGenerateCreateOneObjectMutation } from '@/object-record/utils/generateCreateOneObjectMutation'; import { useGenerateCreateOneRecordMutation } from '@/object-record/hooks/useGenerateCreateOneRecordMutation';
import { useGenerateDeleteOneObjectMutation } from '@/object-record/utils/useGenerateDeleteOneObjectMutation'; import { useGenerateFindManyRecordsQuery } from '@/object-record/hooks/useGenerateFindManyRecordsQuery';
import { useGenerateFindManyCustomObjectsQuery } from '@/object-record/utils/useGenerateFindManyCustomObjectsQuery'; import { useGenerateFindOneRecordQuery } from '@/object-record/hooks/useGenerateFindOneRecordQuery';
import { useGenerateFindOneCustomObjectQuery } from '@/object-record/utils/useGenerateFindOneCustomObjectQuery'; import { useGenerateUpdateOneRecordMutation } from '@/object-record/hooks/useGenerateUpdateOneRecordMutation';
import { useGenerateUpdateOneObjectMutation } from '@/object-record/utils/useGenerateUpdateOneObjectMutation'; import { useGetRecordFromCache } from '@/object-record/hooks/useGetRecordFromCache';
import { useGetRecordFromCache } from '@/object-record/utils/useGetRecordFromCache'; import { useModifyRecordFromCache } from '@/object-record/hooks/useModifyRecordFromCache';
import { useModifyRecordFromCache } from '@/object-record/utils/useModifyRecordFromCache'; import { generateDeleteOneRecordMutation } from '@/object-record/utils/generateDeleteOneRecordMutation';
import { isDefined } from '~/utils/isDefined'; import { isDefined } from '~/utils/isDefined';
import { ObjectMetadataItemIdentifier } from '../types/ObjectMetadataItemIdentifier'; import { ObjectMetadataItemIdentifier } from '../types/ObjectMetadataItemIdentifier';
@ -36,7 +36,7 @@ export const useObjectMetadataItem = (
}), }),
); );
const objectNotFoundInMetadata = !isDefined(objectMetadataItem); const objectMetadataItemNotFound = !isDefined(objectMetadataItem);
const getRecordFromCache = useGetRecordFromCache({ const getRecordFromCache = useGetRecordFromCache({
objectMetadataItem, objectMetadataItem,
@ -46,25 +46,25 @@ export const useObjectMetadataItem = (
objectMetadataItem, objectMetadataItem,
}); });
const findManyQuery = useGenerateFindManyCustomObjectsQuery({ const findManyRecordsQuery = useGenerateFindManyRecordsQuery({
objectMetadataItem, objectMetadataItem,
depth, depth,
}); });
const findOneQuery = useGenerateFindOneCustomObjectQuery({ const findOneRecordQuery = useGenerateFindOneRecordQuery({
objectMetadataItem, objectMetadataItem,
depth, depth,
}); });
const createOneMutation = useGenerateCreateOneObjectMutation({ const createOneRecordMutation = useGenerateCreateOneRecordMutation({
objectMetadataItem, objectMetadataItem,
}); });
const updateOneMutation = useGenerateUpdateOneObjectMutation({ const updateOneRecordMutation = useGenerateUpdateOneRecordMutation({
objectMetadataItem, objectMetadataItem,
}); });
const deleteOneMutation = useGenerateDeleteOneObjectMutation({ const deleteOneRecordMutation = generateDeleteOneRecordMutation({
objectMetadataItem, objectMetadataItem,
}); });
@ -78,13 +78,13 @@ export const useObjectMetadataItem = (
labelIdentifierFieldMetadataId, labelIdentifierFieldMetadataId,
basePathToShowPage, basePathToShowPage,
objectMetadataItem, objectMetadataItem,
objectNotFoundInMetadata, objectMetadataItemNotFound,
getRecordFromCache, getRecordFromCache,
modifyRecordFromCache, modifyRecordFromCache,
findManyQuery, findManyRecordsQuery,
findOneQuery, findOneRecordQuery,
createOneMutation, createOneRecordMutation,
updateOneMutation, updateOneRecordMutation,
deleteOneMutation, deleteOneRecordMutation,
}; };
}; };

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
import { useEffect } from 'react'; 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 { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useRecordTableContextMenuEntries } from '@/object-record/hooks/useRecordTableContextMenuEntries'; import { useRecordTableContextMenuEntries } from '@/object-record/hooks/useRecordTableContextMenuEntries';
import { filterAvailableTableColumns } from '@/object-record/utils/filterAvailableTableColumns'; import { filterAvailableTableColumns } from '@/object-record/utils/filterAvailableTableColumns';
@ -31,7 +31,7 @@ export const RecordTableEffect = ({
}); });
const { columnDefinitions, filterDefinitions, sortDefinitions } = const { columnDefinitions, filterDefinitions, sortDefinitions } =
useComputeDefinitionsFromFieldMetadata(objectMetadataItem); useColumnDefinitionsFromFieldMetadata(objectMetadataItem);
const { const {
setAvailableSortDefinitions, 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 { RecordTableActionBar } from '@/ui/object/record-table/action-bar/components/RecordTableActionBar';
import { RecordTableContextMenu } from '@/ui/object/record-table/context-menu/components/RecordTableContextMenu'; 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'; import { RecordTableContainer } from './RecordTableContainer';
@ -33,7 +33,7 @@ export type RecordTablePageProps = Pick<
export const RecordTablePage = () => { export const RecordTablePage = () => {
const objectNamePlural = useParams().objectNamePlural ?? ''; const objectNamePlural = useParams().objectNamePlural ?? '';
const { objectNotFoundInMetadata, objectMetadataItem } = const { objectMetadataItemNotFound, objectMetadataItem } =
useObjectMetadataItem({ useObjectMetadataItem({
objectNamePlural, objectNamePlural,
}); });
@ -44,14 +44,14 @@ export const RecordTablePage = () => {
useEffect(() => { useEffect(() => {
if ( if (
objectNotFoundInMetadata && objectMetadataItemNotFound &&
onboardingStatus === OnboardingStatus.Completed onboardingStatus === OnboardingStatus.Completed
) { ) {
navigate('/'); navigate('/');
} }
}, [objectNotFoundInMetadata, navigate, onboardingStatus]); }, [objectMetadataItemNotFound, navigate, onboardingStatus]);
const { createOneObject } = useCreateOneObjectRecord({ const { createOneRecord: createOneObject } = useCreateOneRecord({
objectNameSingular: objectMetadataItem?.nameSingular, 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 { OptimisticEffectDefinition } from '@/apollo/optimistic-effect/types/OptimisticEffectDefinition';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; 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'; import { capitalize } from '~/utils/string/capitalize';
export const getRecordOptimisticEffectDefinition = ({ export const getRecordOptimisticEffectDefinition = ({
@ -21,8 +21,8 @@ export const getRecordOptimisticEffectDefinition = ({
newData: unknown; newData: unknown;
}) => { }) => {
const newRecordPaginatedCacheField = produce< const newRecordPaginatedCacheField = produce<
PaginatedObjectTypeResults<any> PaginatedRecordTypeResults<any>
>(currentData as PaginatedObjectTypeResults<any>, (draft) => { >(currentData as PaginatedRecordTypeResults<any>, (draft) => {
if (!draft) { if (!draft) {
return { return {
edges: [{ node: newData, cursor: '' }], 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 { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
import { capitalize } from '~/utils/string/capitalize'; import { capitalize } from '~/utils/string/capitalize';
export const useCreateOneObjectRecord = <T>({ export const useCreateOneRecord = <T>({
objectNameSingular, objectNameSingular,
}: Pick<ObjectMetadataItemIdentifier, 'objectNameSingular'>) => { }: Pick<ObjectMetadataItemIdentifier, 'objectNameSingular'>) => {
const { triggerOptimisticEffects } = useOptimisticEffect({ const { triggerOptimisticEffects } = useOptimisticEffect({
@ -14,22 +14,22 @@ export const useCreateOneObjectRecord = <T>({
}); });
const { const {
objectMetadataItem: foundObjectMetadataItem, objectMetadataItem,
objectNotFoundInMetadata, objectMetadataItemNotFound,
createOneMutation, createOneRecordMutation,
} = useObjectMetadataItem({ } = useObjectMetadataItem({
objectNameSingular, objectNameSingular,
}); });
// TODO: type this with a minimal type at least with Record<string, any> // 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>) => { const createOneRecord = async (input: Record<string, any>) => {
if (!foundObjectMetadataItem || !objectNameSingular) { if (!objectMetadataItem || !objectNameSingular) {
return null; return null;
} }
const createdObject = await mutate({ const createdRecord = await mutate({
variables: { variables: {
input: { ...input, id: v4() }, input: { ...input, id: v4() },
}, },
@ -37,13 +37,13 @@ export const useCreateOneObjectRecord = <T>({
triggerOptimisticEffects( triggerOptimisticEffects(
`${capitalize(objectNameSingular)}Edge`, `${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 { return {
createOneObject, createOneRecord,
objectNotFoundInMetadata, objectMetadataItemNotFound,
}; };
}; };

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@ import { EMPTY_MUTATION } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { capitalize } from '~/utils/string/capitalize'; import { capitalize } from '~/utils/string/capitalize';
export const getUpdateOneObjectMutationGraphQLField = ({ export const getUpdateOneRecordMutationGraphQLField = ({
objectNameSingular, objectNameSingular,
}: { }: {
objectNameSingular: string; objectNameSingular: string;
@ -13,7 +13,7 @@ export const getUpdateOneObjectMutationGraphQLField = ({
return `update${capitalize(objectNameSingular)}`; return `update${capitalize(objectNameSingular)}`;
}; };
export const useGenerateUpdateOneObjectMutation = ({ export const useGenerateUpdateOneRecordMutation = ({
objectMetadataItem, objectMetadataItem,
}: { }: {
objectMetadataItem: ObjectMetadataItem | undefined | null; objectMetadataItem: ObjectMetadataItem | undefined | null;
@ -26,14 +26,14 @@ export const useGenerateUpdateOneObjectMutation = ({
const capitalizedObjectName = capitalize(objectMetadataItem.nameSingular); const capitalizedObjectName = capitalize(objectMetadataItem.nameSingular);
const graphQLFieldForUpdateOneObjectMutation = const graphQLFieldForUpdateOneRecordMutation =
getUpdateOneObjectMutationGraphQLField({ getUpdateOneRecordMutationGraphQLField({
objectNameSingular: objectMetadataItem.nameSingular, objectNameSingular: objectMetadataItem.nameSingular,
}); });
return gql` return gql`
mutation UpdateOne${capitalizedObjectName}($idToUpdate: ID!, $input: ${capitalizedObjectName}UpdateInput!) { mutation UpdateOne${capitalizedObjectName}($idToUpdate: ID!, $input: ${capitalizedObjectName}UpdateInput!) {
${graphQLFieldForUpdateOneObjectMutation}(id: $idToUpdate, data: $input) { ${graphQLFieldForUpdateOneRecordMutation}(id: $idToUpdate, data: $input) {
id id
${objectMetadataItem.fields ${objectMetadataItem.fields
.map((field) => mapFieldMetadataToGraphQLQuery(field)) .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 { getRecordOptimisticEffectDefinition } from '../graphql/optimistic-effect-definition/getRecordOptimisticEffectDefinition';
import { useFindManyObjectRecords } from './useFindManyObjectRecords'; import { useFindManyRecords } from './useFindManyRecords';
export const useObjectRecordTable = () => { export const useObjectRecordTable = () => {
const { scopeId: objectNamePlural } = useRecordTable(); const { scopeId: objectNamePlural, setRecordTableData } = useRecordTable();
const { objectMetadataItem: foundObjectMetadataItem } = useObjectMetadataItem( const { objectMetadataItem: foundObjectMetadataItem } = useObjectMetadataItem(
{ {
@ -24,8 +24,6 @@ export const useObjectRecordTable = () => {
objectNameSingular: foundObjectMetadataItem?.nameSingular, objectNameSingular: foundObjectMetadataItem?.nameSingular,
}); });
const { setRecordTableData } = useRecordTable();
const { tableFiltersState, tableSortsState } = useRecordTableScopedStates(); const { tableFiltersState, tableSortsState } = useRecordTableScopedStates();
const tableFilters = useRecoilValue(tableFiltersState); const tableFilters = useRecoilValue(tableFiltersState);
@ -40,7 +38,7 @@ export const useObjectRecordTable = () => {
foundObjectMetadataItem?.fields ?? [], foundObjectMetadataItem?.fields ?? [],
); );
const { objects, loading, fetchMoreObjects } = useFindManyObjectRecords({ const { records, loading, fetchMoreRecords } = useFindManyRecords({
objectNamePlural, objectNamePlural,
filter, filter,
orderBy, orderBy,
@ -61,8 +59,8 @@ export const useObjectRecordTable = () => {
}); });
return { return {
objects, records,
loading, loading,
fetchMoreObjects, fetchMoreRecords,
}; };
}; };

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
import { QueryHookOptions, QueryResult } from '@apollo/client'; import { QueryHookOptions, QueryResult } from '@apollo/client';
import { isNonEmptyString } from '@sniptt/guards'; 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 { EntitiesForMultipleEntitySelect } from '@/ui/input/relation-picker/components/MultipleEntitySelect';
import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelect'; import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelect';
import { assertNotNull } from '~/utils/assert'; 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 // TODO: use this for all search queries, because we need selectedEntities and entitiesToSelect each time we want to search
// Filtered entities to select are // Filtered entities to select are
// TODO: replace query hooks by useFindManyRecords
export const useFilteredSearchEntityQuery = ({ export const useFilteredSearchEntityQuery = ({
queryHook, queryHook,
orderByField, orderByField,
@ -135,21 +137,21 @@ export const useFilteredSearchEntityQuery = ({
}); });
return { return {
selectedEntities: mapPaginatedObjectsToObjects({ selectedEntities: mapPaginatedRecordsToRecords({
objectNamePlural: objectNamePlural, objectNamePlural: objectNamePlural,
pagedObjects: selectedEntitiesData, pagedRecords: selectedEntitiesData,
}) })
.map(mappingFunction) .map(mappingFunction)
.filter(assertNotNull), .filter(assertNotNull),
filteredSelectedEntities: mapPaginatedObjectsToObjects({ filteredSelectedEntities: mapPaginatedRecordsToRecords({
objectNamePlural: objectNamePlural, objectNamePlural: objectNamePlural,
pagedObjects: filteredSelectedEntitiesData, pagedRecords: filteredSelectedEntitiesData,
}) })
.map(mappingFunction) .map(mappingFunction)
.filter(assertNotNull), .filter(assertNotNull),
entitiesToSelect: mapPaginatedObjectsToObjects({ entitiesToSelect: mapPaginatedRecordsToRecords({
objectNamePlural: objectNamePlural, objectNamePlural: objectNamePlural,
pagedObjects: entitiesToSelectData, pagedRecords: entitiesToSelectData,
}) })
.map(mappingFunction) .map(mappingFunction)
.filter(assertNotNull), .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'; import { assertNotNull } from '~/utils/assert';
export const useFieldPreviewValue = ({ export const useFieldPreviewValue = ({
@ -10,12 +10,12 @@ export const useFieldPreviewValue = ({
objectNamePlural: string; objectNamePlural: string;
skip?: boolean; skip?: boolean;
}) => { }) => {
const { objects } = useFindManyObjectRecords({ const { records } = useFindManyRecords({
objectNamePlural, objectNamePlural,
skip, skip,
}); });
const firstRecordWithValue = objects.find( const firstRecordWithValue = records.find(
(record) => assertNotNull(record[fieldName]) && record[fieldName] !== '', (record) => assertNotNull(record[fieldName]) && record[fieldName] !== '',
); );

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -19,11 +19,13 @@ export const ObjectFilterDropdownEntitySelect = () => {
const objectMetadataNamePlural = const objectMetadataNamePlural =
filterDefinitionUsedInDropdown?.relationObjectMetadataNamePlural ?? ''; filterDefinitionUsedInDropdown?.relationObjectMetadataNamePlural ?? '';
const { findManyQuery } = useObjectMetadataItem({ // TODO: refactor useFilteredSearchEntityQuery
const { findManyRecordsQuery } = useObjectMetadataItem({
objectNameSingular: objectMetadataNameSingular, objectNameSingular: objectMetadataNameSingular,
}); });
const useFindManyQuery = (options: any) => useQuery(findManyQuery, options); const useFindManyQuery = (options: any) =>
useQuery(findManyRecordsQuery, options);
const { identifiersMapper, searchQuery } = useRelationPicker(); 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 { 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 { useRecoilValue } from 'recoil';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord'; import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { Opportunity } from '@/pipeline/types/Opportunity'; import { Opportunity } from '@/pipeline/types/Opportunity';
import { PageHotkeyScope } from '@/types/PageHotkeyScope'; import { PageHotkeyScope } from '@/types/PageHotkeyScope';
import { BoardColumnContext } from '@/ui/object/record-board/contexts/BoardColumnContext'; import { BoardColumnContext } from '@/ui/object/record-board/contexts/BoardColumnContext';
@ -60,8 +60,8 @@ export const RecordBoard = ({
}: RecordBoardProps) => { }: RecordBoardProps) => {
const boardColumns = useRecoilValue(boardColumnsState); const boardColumns = useRecoilValue(boardColumnsState);
const { updateOneObject: updateOneOpportunity } = const { updateOneRecord: updateOneOpportunity } =
useUpdateOneObjectRecord<Opportunity>({ useUpdateOneRecord<Opportunity>({
objectNameSingular: 'opportunity', objectNameSingular: 'opportunity',
}); });

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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