Refactored useFindOneObjectMetadataItem and useFindManyObjectMetadataItems (#2600)

* Refactored useFindOneObjectMetadataItem and useFindManyObjectMetadataItems to rely on a recoil family selector

* Removed console.log

* Cleaned

* Removed unused hook

* Fixed seeds
This commit is contained in:
Lucas Bordeau 2023-11-20 16:34:06 +01:00 committed by GitHub
parent 3ad30a0498
commit 189586830e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 190 additions and 239 deletions

View File

@ -9,8 +9,8 @@ import { useRecoilCallback } from 'recoil';
import {
EMPTY_QUERY,
useFindOneObjectMetadataItem,
} from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
useObjectMetadataItem,
} from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { optimisticEffectState } from '../states/optimisticEffectState';
@ -23,7 +23,7 @@ export const useOptimisticEffect = ({
objectNameSingular: string | undefined;
}) => {
const apolloClient = useApolloClient();
const { findManyQuery } = useFindOneObjectMetadataItem({
const { findManyQuery } = useObjectMetadataItem({
objectNameSingular,
});

View File

@ -33,15 +33,13 @@ export const HooksCompanyBoardEffect = () => {
setViewType,
} = useView();
const { currentViewFiltersState, currentViewFieldsState } =
useViewScopedStates();
const { currentViewFieldsState } = useViewScopedStates();
const [pipelineSteps, setPipelineSteps] = useState<PipelineStep[]>([]);
const [opportunities, setOpportunities] = useState<Opportunity[]>([]);
const [companies, setCompanies] = useState<Company[]>([]);
const currentViewFields = useRecoilValue(currentViewFieldsState);
const currentViewFilters = useRecoilValue(currentViewFiltersState);
const [, setIsBoardLoaded] = useRecoilState(isBoardLoadedState);

View File

@ -7,7 +7,7 @@ import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMembe
import { Company } from '@/companies/types/Company';
import { Favorite } from '@/favorites/types/Favorite';
import { mapFavorites } from '@/favorites/utils/mapFavorites';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { PaginatedObjectTypeResults } from '@/object-record/types/PaginatedObjectTypeResults';
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
@ -24,12 +24,12 @@ export const useFavorites = ({
const [favorites, setFavorites] = useRecoilState(favoritesState);
const { updateOneMutation, createOneMutation, deleteOneMutation } =
useFindOneObjectMetadataItem({
useObjectMetadataItem({
objectNamePlural: 'favorites',
});
const { foundObjectMetadataItem: favoriteTargetObjectMetadataItem } =
useFindOneObjectMetadataItem({
const { objectMetadataItem: favoriteTargetObjectMetadataItem } =
useObjectMetadataItem({
objectNamePlural,
});

View File

@ -1,13 +1,14 @@
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { FieldMetadata } from '@/ui/object/field/types/FieldMetadata';
import { ColumnDefinition } from '@/ui/object/record-table/types/ColumnDefinition';
import { Nullable } from '~/types/Nullable';
import { formatFieldMetadataItemAsColumnDefinition } from '../utils/formatFieldMetadataItemAsColumnDefinition';
import { formatFieldMetadataItemsAsFilterDefinitions } from '../utils/formatFieldMetadataItemsAsFilterDefinitions';
import { formatFieldMetadataItemsAsSortDefinitions } from '../utils/formatFieldMetadataItemsAsSortDefinitions';
export const useComputeDefinitionsFromFieldMetadata = (
objectMetadataItem?: ObjectMetadataItem,
objectMetadataItem?: Nullable<ObjectMetadataItem>,
) => {
if (!objectMetadataItem) {
return {

View File

@ -1,6 +1,8 @@
import { useMemo } from 'react';
import { useQuery } from '@apollo/client';
import { useRecoilCallback } from 'recoil';
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
import { useSnackBar } from '@/ui/feedback/snack-bar/hooks/useSnackBar';
import {
FieldFilter,
@ -8,6 +10,7 @@ import {
ObjectMetadataItemsQuery,
ObjectMetadataItemsQueryVariables,
} from '~/generated-metadata/graphql';
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
import { logError } from '~/utils/logError';
import { FIND_MANY_METADATA_OBJECTS } from '../graphql/queries';
@ -15,7 +18,6 @@ import { mapPaginatedObjectMetadataItemsToObjectMetadataItems } from '../utils/m
import { useApolloMetadataClient } from './useApolloMetadataClient';
// TODO: test fetchMore
export const useFindManyObjectMetadataItems = ({
skip,
objectFilter,
@ -29,41 +31,44 @@ export const useFindManyObjectMetadataItems = ({
const { enqueueSnackBar } = useSnackBar();
const {
data,
fetchMore: fetchMoreInternal,
loading,
error,
} = useQuery<ObjectMetadataItemsQuery, ObjectMetadataItemsQueryVariables>(
FIND_MANY_METADATA_OBJECTS,
{
variables: {
objectFilter,
fieldFilter,
},
client: apolloMetadataClient ?? undefined,
skip: skip || !apolloMetadataClient,
onError: (error) => {
logError('useFindManyObjectMetadataItems error : ' + error);
enqueueSnackBar(
`Error during useFindManyObjectMetadataItems, ${error.message}`,
{
variant: 'error',
},
);
},
onCompleted: () => {},
const { data, loading, error } = useQuery<
ObjectMetadataItemsQuery,
ObjectMetadataItemsQueryVariables
>(FIND_MANY_METADATA_OBJECTS, {
variables: {
objectFilter,
fieldFilter,
},
);
client: apolloMetadataClient ?? undefined,
skip: skip || !apolloMetadataClient,
onError: (error) => {
logError('useFindManyObjectMetadataItems error : ' + error);
enqueueSnackBar(
`Error during useFindManyObjectMetadataItems, ${error.message}`,
{
variant: 'error',
},
);
},
onCompleted: useRecoilCallback(
({ snapshot, set }) =>
(data) => {
const objectMetadataItems =
mapPaginatedObjectMetadataItemsToObjectMetadataItems({
pagedObjectMetadataItems: data,
});
const hasMore = data?.objects?.pageInfo?.hasNextPage;
const actualObjectMetadataItems = snapshot
.getLoadable(objectMetadataItemsState)
.getValue();
const fetchMore = () =>
fetchMoreInternal({
variables: {
afterCursor: data?.objects?.pageInfo?.endCursor,
},
});
if (!isDeeplyEqual(objectMetadataItems, actualObjectMetadataItems)) {
set(objectMetadataItemsState, objectMetadataItems);
}
},
[],
),
});
const objectMetadataItems = useMemo(() => {
return mapPaginatedObjectMetadataItemsToObjectMetadataItems({
@ -73,8 +78,6 @@ export const useFindManyObjectMetadataItems = ({
return {
objectMetadataItems,
hasMore,
fetchMore,
loading,
error,
};

View File

@ -1,74 +0,0 @@
import { useMemo } from 'react';
import { useQuery } from '@apollo/client';
import { useSnackBar } from '@/ui/feedback/snack-bar/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

@ -1,10 +1,12 @@
import { useFindManyObjectMetadataItems } from '@/object-metadata/hooks/useFindManyObjectMetadataItems';
import { useRecoilValue } from 'recoil';
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
import { FieldType } from '@/ui/object/field/types/FieldType';
import { FieldMetadataItem } from '../types/FieldMetadataItem';
export const useMapFieldMetadataToGraphQLQuery = () => {
const { objectMetadataItems } = useFindManyObjectMetadataItems();
const objectMetadataItems = useRecoilValue(objectMetadataItemsState);
const mapFieldMetadataToGraphQLQuery = (
field: FieldMetadataItem,
@ -19,6 +21,7 @@ export const useMapFieldMetadataToGraphQLQuery = () => {
const fieldIsSimpleValue = (
[
'UUID',
'TEXT',
'PHONE',
'DATE',

View File

@ -1,8 +1,9 @@
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { MainIdentifierMapper } from '@/ui/object/field/types/MainIdentifierMapper';
import { Nullable } from '~/types/Nullable';
export const useObjectMainIdentifier = (
objectMetadataItem?: ObjectMetadataItem,
objectMetadataItem?: Nullable<ObjectMetadataItem>,
) => {
if (!objectMetadataItem) {
return {

View File

@ -1,15 +1,16 @@
import { gql } from '@apollo/client';
import { useRecoilValue } from 'recoil';
import { objectMetadataItemFamilySelector } from '@/object-metadata/states/objectMetadataItemFamilySelector';
import { useGenerateCreateOneObjectMutation } from '@/object-record/utils/generateCreateOneObjectMutation';
import { useGenerateDeleteOneObjectMutation } from '@/object-record/utils/useGenerateDeleteOneObjectMutation';
import { useGenerateFindManyCustomObjectsQuery } from '@/object-record/utils/useGenerateFindManyCustomObjectsQuery';
import { useGenerateFindOneCustomObjectQuery } from '@/object-record/utils/useGenerateFindOneCustomObjectQuery';
import { useGenerateUpdateOneObjectMutation } from '@/object-record/utils/useGenerateUpdateOneObjectMutation';
import { isDefined } from '~/utils/isDefined';
import { ObjectMetadataItemIdentifier } from '../types/ObjectMetadataItemIdentifier';
import { useFindManyObjectMetadataItems } from './useFindManyObjectMetadataItems';
export const EMPTY_QUERY = gql`
query EmptyQuery {
empty
@ -22,53 +23,46 @@ export const EMPTY_MUTATION = gql`
}
`;
export const useFindOneObjectMetadataItem = ({
export const useObjectMetadataItem = ({
objectNamePlural,
objectNameSingular,
skip,
}: ObjectMetadataItemIdentifier & { skip?: boolean }) => {
const { objectMetadataItems, loading } = useFindManyObjectMetadataItems({
skip,
});
const foundObjectMetadataItem = objectMetadataItems.find(
(object) =>
object.namePlural === objectNamePlural ||
object.nameSingular === objectNameSingular,
const objectMetadataItem = useRecoilValue(
objectMetadataItemFamilySelector({
objectNamePlural,
objectNameSingular,
}),
);
const objectNotFoundInMetadata =
objectMetadataItems.length === 0 ||
(objectMetadataItems.length > 0 && !foundObjectMetadataItem);
const objectNotFoundInMetadata = !isDefined(objectMetadataItem);
const findManyQuery = useGenerateFindManyCustomObjectsQuery({
objectMetadataItem: foundObjectMetadataItem,
objectMetadataItem,
});
const findOneQuery = useGenerateFindOneCustomObjectQuery({
objectMetadataItem: foundObjectMetadataItem,
objectMetadataItem,
});
const createOneMutation = useGenerateCreateOneObjectMutation({
objectMetadataItem: foundObjectMetadataItem,
objectMetadataItem,
});
const updateOneMutation = useGenerateUpdateOneObjectMutation({
objectMetadataItem: foundObjectMetadataItem,
objectMetadataItem,
});
const deleteOneMutation = useGenerateDeleteOneObjectMutation({
objectMetadataItem: foundObjectMetadataItem,
objectMetadataItem,
});
return {
foundObjectMetadataItem,
objectMetadataItem,
objectNotFoundInMetadata,
findManyQuery,
findOneQuery,
createOneMutation,
updateOneMutation,
deleteOneMutation,
loading,
};
};

View File

@ -1,14 +1,17 @@
import { useRecoilValue } from 'recoil';
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
import { ObjectMetadataItem } from '../types/ObjectMetadataItem';
import { formatObjectMetadataItemInput } from '../utils/formatObjectMetadataItemInput';
import { getObjectSlug } from '../utils/getObjectSlug';
import { useCreateOneObjectRecordMetadataItem } from './useCreateOneObjectMetadataItem';
import { useDeleteOneObjectMetadataItem } from './useDeleteOneObjectMetadataItem';
import { useFindManyObjectMetadataItems } from './useFindManyObjectMetadataItems';
import { useUpdateOneObjectMetadataItem } from './useUpdateOneObjectMetadataItem';
export const useObjectMetadataItemForSettings = () => {
const { objectMetadataItems, loading } = useFindManyObjectMetadataItems();
const objectMetadataItems = useRecoilValue(objectMetadataItemsState);
const activeObjectMetadataItems = objectMetadataItems.filter(
({ isActive, isSystem }) => isActive && !isSystem,
@ -87,7 +90,6 @@ export const useObjectMetadataItemForSettings = () => {
findActiveObjectMetadataItemBySlug,
findObjectMetadataItemById,
findObjectMetadataItemByNamePlural,
loading,
objectMetadataItems,
};
};

View File

@ -0,0 +1,30 @@
import { selectorFamily } from 'recoil';
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
export const objectMetadataItemFamilySelector = selectorFamily<
ObjectMetadataItem | null,
{ objectNameSingular?: string; objectNamePlural?: string }
>({
key: 'objectMetadataItemFamilySelector',
get:
({
objectNameSingular,
objectNamePlural,
}: {
objectNameSingular?: string;
objectNamePlural?: string;
}) =>
({ get }) => {
const objectMetadataItems = get(objectMetadataItemsState);
return (
objectMetadataItems.find(
(objectMetadataItem) =>
objectMetadataItem.nameSingular === objectNameSingular ||
objectMetadataItem.namePlural === objectNamePlural,
) ?? null
);
},
});

View File

@ -0,0 +1,8 @@
import { atom } from 'recoil';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
export const objectMetadataItemsState = atom<ObjectMetadataItem[]>({
key: 'objectMetadataItemsState',
default: [],
});

View File

@ -3,7 +3,7 @@ import { DateTime } from 'luxon';
import { useRecoilState } from 'recoil';
import { useFavorites } from '@/favorites/hooks/useFavorites';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { formatFieldMetadataItemAsColumnDefinition } from '@/object-metadata/utils/formatFieldMetadataItemAsColumnDefinition';
import { filterAvailableFieldMetadataItem } from '@/object-record/utils/filterAvailableFieldMetadataItem';
import { IconBuildingSkyscraper } from '@/ui/display/icon';
@ -35,7 +35,7 @@ export const RecordShowPage = () => {
objectMetadataId: string;
}>();
const { foundObjectMetadataItem } = useFindOneObjectMetadataItem({
const { objectMetadataItem: foundObjectMetadataItem } = useObjectMetadataItem({
objectNameSingular,
});

View File

@ -2,7 +2,7 @@ import styled from '@emotion/styled';
import { useRecoilCallback } from 'recoil';
import { useComputeDefinitionsFromFieldMetadata } from '@/object-metadata/hooks/useComputeDefinitionsFromFieldMetadata';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { RecordTable } from '@/ui/object/record-table/components/RecordTable';
import { TableOptionsDropdownId } from '@/ui/object/record-table/constants/TableOptionsDropdownId';
import { useRecordTable } from '@/ui/object/record-table/hooks/useRecordTable';
@ -32,7 +32,7 @@ export const RecordTableContainer = ({
}: {
objectNamePlural: string;
}) => {
const { foundObjectMetadataItem } = useFindOneObjectMetadataItem({
const { objectMetadataItem: foundObjectMetadataItem } = useObjectMetadataItem({
objectNamePlural,
});
const { columnDefinitions } = useComputeDefinitionsFromFieldMetadata(

View File

@ -1,8 +1,8 @@
import { useEffect } from 'react';
import { useComputeDefinitionsFromFieldMetadata } from '@/object-metadata/hooks/useComputeDefinitionsFromFieldMetadata';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMainIdentifier } from '@/object-metadata/hooks/useObjectMainIdentifier';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useRecordTableContextMenuEntries } from '@/object-record/hooks/useRecordTableContextMenuEntries';
import { filterAvailableTableColumns } from '@/object-record/utils/filterAvailableTableColumns';
import { useRecordTable } from '@/ui/object/record-table/hooks/useRecordTable';
@ -17,7 +17,7 @@ export const RecordTableEffect = () => {
setObjectMetadataConfig,
} = useRecordTable();
const { foundObjectMetadataItem } = useFindOneObjectMetadataItem({
const { objectMetadataItem } = useObjectMetadataItem({
objectNamePlural,
});
@ -25,10 +25,10 @@ export const RecordTableEffect = () => {
mainIdentifierMapper,
basePathToShowPage,
mainIdentifierFieldMetadataId,
} = useObjectMainIdentifier(foundObjectMetadataItem);
} = useObjectMainIdentifier(objectMetadataItem);
const { columnDefinitions, filterDefinitions, sortDefinitions } =
useComputeDefinitionsFromFieldMetadata(foundObjectMetadataItem);
useComputeDefinitionsFromFieldMetadata(objectMetadataItem);
const {
setAvailableSortDefinitions,
@ -53,17 +53,17 @@ export const RecordTableEffect = () => {
}
}, [
basePathToShowPage,
foundObjectMetadataItem,
objectMetadataItem,
mainIdentifierFieldMetadataId,
mainIdentifierMapper,
setObjectMetadataConfig,
]);
useEffect(() => {
if (!foundObjectMetadataItem) {
if (!objectMetadataItem) {
return;
}
setViewObjectMetadataId?.(foundObjectMetadataItem.id);
setViewObjectMetadataId?.(objectMetadataItem.id);
setViewType?.(ViewType.Table);
setAvailableSortDefinitions?.(sortDefinitions);
@ -82,7 +82,7 @@ export const RecordTableEffect = () => {
setAvailableSortDefinitions,
setAvailableFilterDefinitions,
setAvailableFieldDefinitions,
foundObjectMetadataItem,
objectMetadataItem,
sortDefinitions,
filterDefinitions,
setAvailableTableColumns,

View File

@ -2,7 +2,7 @@ import { useEffect } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import styled from '@emotion/styled';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
import { IconBuildingSkyscraper } from '@/ui/display/icon';
import { PageAddButton } from '@/ui/layout/page/PageAddButton';
@ -31,26 +31,25 @@ export type RecordTablePageProps = Pick<
export const RecordTablePage = () => {
const objectNamePlural = useParams().objectNamePlural ?? '';
const { objectNotFoundInMetadata, loading, foundObjectMetadataItem } =
useFindOneObjectMetadataItem({
const { objectNotFoundInMetadata, objectMetadataItem } =
useObjectMetadataItem({
objectNamePlural,
});
const navigate = useNavigate();
useEffect(() => {
if (!loading && objectNotFoundInMetadata) {
if (objectNotFoundInMetadata) {
navigate('/');
}
}, [objectNotFoundInMetadata, loading, navigate]);
}, [objectNotFoundInMetadata, navigate]);
const { createOneObject } = useCreateOneObjectRecord({
objectNameSingular: foundObjectMetadataItem?.nameSingular,
objectNameSingular: objectMetadataItem?.nameSingular,
});
const handleAddButtonClick = async () => {
const createdObject = await createOneObject?.({});
console.log(createdObject);
await createOneObject?.({});
};
return (

View File

@ -2,7 +2,7 @@ import { useMutation } from '@apollo/client';
import { v4 } from 'uuid';
import { useOptimisticEffect } from '@/apollo/optimistic-effect/hooks/useOptimisticEffect';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
import { capitalize } from '~/utils/string/capitalize';
@ -14,10 +14,10 @@ export const useCreateOneObjectRecord = <T>({
});
const {
foundObjectMetadataItem,
objectMetadataItem: foundObjectMetadataItem,
objectNotFoundInMetadata,
createOneMutation,
} = useFindOneObjectMetadataItem({
} = useObjectMetadataItem({
objectNameSingular,
});

View File

@ -1,7 +1,7 @@
import { useMutation } from '@apollo/client';
import { getOperationName } from '@apollo/client/utilities';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
import { capitalize } from '~/utils/string/capitalize';
@ -9,11 +9,11 @@ export const useDeleteOneObjectRecord = <T>({
objectNameSingular,
}: Pick<ObjectMetadataItemIdentifier, 'objectNameSingular'>) => {
const {
foundObjectMetadataItem,
objectMetadataItem: foundObjectMetadataItem,
objectNotFoundInMetadata,
findManyQuery,
deleteOneMutation,
} = useFindOneObjectMetadataItem({
} = useObjectMetadataItem({
objectNameSingular,
});

View File

@ -4,7 +4,7 @@ import { isNonEmptyArray } from '@apollo/client/utilities';
import { isNonEmptyString } from '@sniptt/guards';
import { useRecoilState } from 'recoil';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
import { useSnackBar } from '@/ui/feedback/snack-bar/hooks/useSnackBar';
import { logError } from '~/utils/logError';
@ -48,8 +48,8 @@ export const useFindManyObjectRecords = <
isFetchingMoreObjectsFamilyState(objectNamePlural),
);
const { foundObjectMetadataItem, objectNotFoundInMetadata, findManyQuery } =
useFindOneObjectMetadataItem({
const { objectMetadataItem: foundObjectMetadataItem, objectNotFoundInMetadata, findManyQuery } =
useObjectMetadataItem({
objectNamePlural,
skip,
});

View File

@ -1,6 +1,6 @@
import { useQuery } from '@apollo/client';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
export const useFindOneObjectRecord = <
@ -15,8 +15,8 @@ export const useFindOneObjectRecord = <
onCompleted?: (data: ObjectType) => void;
skip?: boolean;
}) => {
const { foundObjectMetadataItem, objectNotFoundInMetadata, findOneQuery } =
useFindOneObjectMetadataItem({
const { objectMetadataItem: foundObjectMetadataItem, objectNotFoundInMetadata, findOneQuery } =
useObjectMetadataItem({
objectNameSingular,
});

View File

@ -1,7 +1,7 @@
import { useRecoilValue } from 'recoil';
import { useOptimisticEffect } from '@/apollo/optimistic-effect/hooks/useOptimisticEffect';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { turnFiltersIntoWhereClauseV2 } from '@/ui/object/object-filter-dropdown/utils/turnFiltersIntoWhereClauseV2';
import { turnSortsIntoOrderByV2 } from '@/ui/object/object-sort-dropdown/utils/turnSortsIntoOrderByV2';
import { useRecordTableScopedStates } from '@/ui/object/record-table/hooks/internal/useRecordTableScopedStates';
@ -14,7 +14,7 @@ import { useFindManyObjectRecords } from './useFindManyObjectRecords';
export const useObjectRecordTable = () => {
const { scopeId: objectNamePlural } = useRecordTable();
const { foundObjectMetadataItem } = useFindOneObjectMetadataItem({
const { objectMetadataItem: foundObjectMetadataItem } = useObjectMetadataItem({
objectNamePlural,
});

View File

@ -3,7 +3,7 @@ import { isNonEmptyString } from '@sniptt/guards';
import { useRecoilCallback, useRecoilValue, useSetRecoilState } from 'recoil';
import { useFavorites } from '@/favorites/hooks/useFavorites';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useDeleteOneObjectRecord } from '@/object-record/hooks/useDeleteOneObjectRecord';
import {
IconCheckbox,
@ -29,7 +29,7 @@ export const useRecordTableContextMenuEntries = () => {
const { scopeId: objectNamePlural, resetTableRowSelection } =
useRecordTable();
const { foundObjectMetadataItem } = useFindOneObjectMetadataItem({
const { objectMetadataItem: foundObjectMetadataItem } = useObjectMetadataItem({
objectNamePlural,
});

View File

@ -1,6 +1,6 @@
import { useMutation } from '@apollo/client';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItemIdentifier } from '@/object-metadata/types/ObjectMetadataItemIdentifier';
import { capitalize } from '~/utils/string/capitalize';
@ -8,10 +8,10 @@ export const useUpdateOneObjectRecord = <T>({
objectNameSingular,
}: Pick<ObjectMetadataItemIdentifier, 'objectNameSingular'>) => {
const {
foundObjectMetadataItem,
objectMetadataItem: foundObjectMetadataItem,
objectNotFoundInMetadata,
updateOneMutation,
} = useFindOneObjectMetadataItem({
} = useObjectMetadataItem({
objectNameSingular,
});

View File

@ -1,7 +1,7 @@
import { gql } from '@apollo/client';
import { EMPTY_MUTATION } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useMapFieldMetadataToGraphQLQuery } from '@/object-metadata/hooks/useMapFieldMetadataToGraphQLQuery';
import { EMPTY_MUTATION } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { capitalize } from '~/utils/string/capitalize';
@ -23,7 +23,7 @@ export const useGenerateCreateOneObjectMutation = ({
create${capitalizedObjectName}(data: $input) {
id
${objectMetadataItem.fields
.map(mapFieldMetadataToGraphQLQuery)
.map((field) => mapFieldMetadataToGraphQLQuery(field))
.join('\n')}
}
}

View File

@ -1,6 +1,6 @@
import { gql } from '@apollo/client';
import { EMPTY_MUTATION } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { EMPTY_MUTATION } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { capitalize } from '~/utils/string/capitalize';

View File

@ -1,7 +1,7 @@
import { gql } from '@apollo/client';
import { EMPTY_QUERY } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useMapFieldMetadataToGraphQLQuery } from '@/object-metadata/hooks/useMapFieldMetadataToGraphQLQuery';
import { EMPTY_QUERY } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { capitalize } from '~/utils/string/capitalize';

View File

@ -1,7 +1,7 @@
import { gql } from '@apollo/client';
import { EMPTY_QUERY } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useMapFieldMetadataToGraphQLQuery } from '@/object-metadata/hooks/useMapFieldMetadataToGraphQLQuery';
import { EMPTY_QUERY } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
export const useGenerateFindOneCustomObjectQuery = ({

View File

@ -1,7 +1,7 @@
import { gql } from '@apollo/client';
import { EMPTY_MUTATION } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useMapFieldMetadataToGraphQLQuery } from '@/object-metadata/hooks/useMapFieldMetadataToGraphQLQuery';
import { EMPTY_MUTATION } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { capitalize } from '~/utils/string/capitalize';
@ -36,7 +36,7 @@ export const useGenerateUpdateOneObjectMutation = ({
${graphQLFieldForUpdateOneObjectMutation}(id: $idToUpdate, data: $input) {
id
${objectMetadataItem.fields
.map(mapFieldMetadataToGraphQLQuery)
.map((field) => mapFieldMetadataToGraphQLQuery(field))
.join('\n')}
}
}

View File

@ -1,7 +1,7 @@
import { useEffect } from 'react';
import { useQuery } from '@apollo/client';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useFilteredSearchEntityQuery } from '@/search/hooks/useFilteredSearchEntityQuery';
import { IconUserCircle } from '@/ui/display/icon';
import { SingleEntitySelect } from '@/ui/input/relation-picker/components/SingleEntitySelect';
@ -35,7 +35,7 @@ export const RelationPicker = ({
setRelationPickerSearchFilter(initialSearchFilter ?? '');
}, [initialSearchFilter, setRelationPickerSearchFilter]);
const { findManyQuery } = useFindOneObjectMetadataItem({
const { findManyQuery } = useObjectMetadataItem({
objectNameSingular: fieldDefinition.metadata.objectMetadataNameSingular,
});

View File

@ -2,7 +2,7 @@ import { useEffect } from 'react';
import { useInView } from 'react-intersection-observer';
import { useRecoilState, useRecoilValue } from 'recoil';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useObjectRecordTable } from '@/object-record/hooks/useObjectRecordTable';
import { isFetchingMoreObjectsFamilyState } from '@/object-record/states/isFetchingMoreObjectsFamilyState';
import { isDefined } from '~/utils/isDefined';
@ -22,7 +22,7 @@ export const RecordTableBody = () => {
const { scopeId: objectNamePlural } = useRecordTable();
const { foundObjectMetadataItem } = useFindOneObjectMetadataItem({
const { objectMetadataItem: foundObjectMetadataItem } = useObjectMetadataItem({
objectNamePlural,
});

View File

@ -1,6 +1,6 @@
import { useQuery } from '@apollo/client';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useFilteredSearchEntityQuery } from '@/search/hooks/useFilteredSearchEntityQuery';
import { ObjectFilterDropdownEntitySearchSelect } from '@/ui/object/object-filter-dropdown/components/ObjectFilterDropdownEntitySearchSelect';
import { useFilter } from '@/ui/object/object-filter-dropdown/hooks/useFilter';
@ -11,7 +11,7 @@ export const FilterDropdownUserSearchSelect = () => {
objectFilterDropdownSelectedEntityId,
} = useFilter();
const { findManyQuery } = useFindOneObjectMetadataItem({
const { findManyQuery } = useObjectMetadataItem({
objectNameSingular: 'workspaceMember',
});

View File

@ -1,13 +1,13 @@
import { useApolloClient } from '@apollo/client';
import { useRecoilCallback } from 'recoil';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { ViewField } from '@/views/types/ViewField';
import { getViewScopedStateValuesFromSnapshot } from '@/views/utils/getViewScopedStateValuesFromSnapshot';
export const useViewFields = (viewScopeId: string) => {
const { updateOneMutation, createOneMutation, findManyQuery } =
useFindOneObjectMetadataItem({
useObjectMetadataItem({
objectNameSingular: 'viewField',
});

View File

@ -2,7 +2,7 @@ import { useApolloClient } from '@apollo/client';
import { produce } from 'immer';
import { useRecoilCallback } from 'recoil';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { Filter } from '@/ui/object/object-filter-dropdown/types/Filter';
import { savedViewFiltersScopedFamilyState } from '@/views/states/savedViewFiltersScopedFamilyState';
import { ViewFilter } from '@/views/types/ViewFilter';
@ -16,7 +16,7 @@ export const useViewFilters = (viewScopeId: string) => {
createOneMutation,
deleteOneMutation,
findManyQuery,
} = useFindOneObjectMetadataItem({
} = useObjectMetadataItem({
objectNameSingular: 'viewFilter',
});
const apolloClient = useApolloClient();

View File

@ -2,7 +2,7 @@ import { useApolloClient } from '@apollo/client';
import { produce } from 'immer';
import { useRecoilCallback } from 'recoil';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { Sort } from '@/ui/object/object-sort-dropdown/types/Sort';
import { savedViewSortsScopedFamilyState } from '@/views/states/savedViewSortsScopedFamilyState';
import { ViewSort } from '@/views/types/ViewSort';
@ -16,7 +16,7 @@ export const useViewSorts = (viewScopeId: string) => {
createOneMutation,
deleteOneMutation,
findManyQuery,
} = useFindOneObjectMetadataItem({
} = useObjectMetadataItem({
objectNameSingular: 'viewSort',
});
const apolloClient = useApolloClient();

View File

@ -1,7 +1,7 @@
import { useApolloClient } from '@apollo/client';
import { useRecoilCallback } from 'recoil';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { View } from '@/views/types/View';
import { getViewScopedStateValuesFromSnapshot } from '@/views/utils/getViewScopedStateValuesFromSnapshot';
@ -11,7 +11,7 @@ export const useViews = (scopeId: string) => {
createOneMutation,
deleteOneMutation,
findManyQuery,
} = useFindOneObjectMetadataItem({
} = useObjectMetadataItem({
objectNameSingular: 'view',
});
const apolloClient = useApolloClient();

View File

@ -3,7 +3,7 @@ import styled from '@emotion/styled';
import { CompanyBoard } from '@/companies/board/components/CompanyBoard';
import { CompanyBoardRecoilScopeContext } from '@/companies/states/recoil-scope-contexts/CompanyBoardRecoilScopeContext';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useUpdateOneObjectRecord } from '@/object-record/hooks/useUpdateOneObjectRecord';
import { PipelineAddButton } from '@/pipeline/components/PipelineAddButton';
import { usePipelineStages } from '@/pipeline/hooks/usePipelineStages';
@ -45,9 +45,9 @@ export const Opportunities = () => {
});
};
const opportunitiesV2MetadataId = useFindOneObjectMetadataItem({
const opportunitiesV2MetadataId = useObjectMetadataItem({
objectNameSingular: 'opportunity',
}).foundObjectMetadataItem?.id;
}).objectMetadataItem?.id;
const { setViewObjectMetadataId } = useView({
viewScopeId: 'company-board-view',

View File

@ -34,19 +34,15 @@ export const SettingsObjectDetail = () => {
const navigate = useNavigate();
const { objectSlug = '' } = useParams();
const {
disableObjectMetadataItem,
findActiveObjectMetadataItemBySlug,
loading,
} = useObjectMetadataItemForSettings();
const { disableObjectMetadataItem, findActiveObjectMetadataItemBySlug } =
useObjectMetadataItemForSettings();
const activeObjectMetadataItem =
findActiveObjectMetadataItemBySlug(objectSlug);
useEffect(() => {
if (loading) return;
if (!activeObjectMetadataItem) navigate(AppPath.NotFound);
}, [activeObjectMetadataItem, loading, navigate]);
}, [activeObjectMetadataItem, navigate]);
const { activateMetadataField, disableMetadataField, eraseMetadataField } =
useFieldMetadataItem();

View File

@ -24,7 +24,6 @@ export const SettingsObjectEdit = () => {
disableObjectMetadataItem,
editObjectMetadataItem,
findActiveObjectMetadataItemBySlug,
loading,
} = useObjectMetadataItemForSettings();
const activeObjectMetadataItem =
@ -40,8 +39,6 @@ export const SettingsObjectEdit = () => {
>({});
useEffect(() => {
if (loading) return;
if (!activeObjectMetadataItem) {
navigate(AppPath.NotFound);
return;
@ -55,7 +52,7 @@ export const SettingsObjectEdit = () => {
description: activeObjectMetadataItem.description ?? undefined,
});
}
}, [activeObjectMetadataItem, formValues, loading, navigate]);
}, [activeObjectMetadataItem, formValues, navigate]);
if (!activeObjectMetadataItem) return null;

View File

@ -24,7 +24,7 @@ export const SettingsObjectFieldEdit = () => {
const navigate = useNavigate();
const { objectSlug = '', fieldSlug = '' } = useParams();
const { findActiveObjectMetadataItemBySlug, loading } =
const { findActiveObjectMetadataItemBySlug } =
useObjectMetadataItemForSettings();
const activeObjectMetadataItem =
@ -54,8 +54,6 @@ export const SettingsObjectFieldEdit = () => {
} = useFieldMetadataForm();
useEffect(() => {
if (loading) return;
if (!activeObjectMetadataItem || !activeMetadataField) {
navigate(AppPath.NotFound);
return;
@ -79,7 +77,6 @@ export const SettingsObjectFieldEdit = () => {
activeMetadataField,
activeObjectMetadataItem,
initForm,
loading,
navigate,
relationFieldMetadataItem?.icon,
relationFieldMetadataItem?.label,

View File

@ -37,7 +37,7 @@ export const SettingsObjectNewFieldStep1 = () => {
const navigate = useNavigate();
const { objectSlug = '' } = useParams();
const { findActiveObjectMetadataItemBySlug, loading } =
const { findActiveObjectMetadataItemBySlug } =
useObjectMetadataItemForSettings();
const activeObjectMetadataItem =
@ -60,8 +60,6 @@ export const SettingsObjectNewFieldStep1 = () => {
);
useEffect(() => {
if (loading) return;
if (!activeObjectMetadataItem) {
navigate(AppPath.NotFound);
return;
@ -69,7 +67,7 @@ export const SettingsObjectNewFieldStep1 = () => {
if (!metadataFields.length)
setMetadataFields(activeObjectMetadataItem.fields);
}, [activeObjectMetadataItem, metadataFields.length, loading, navigate]);
}, [activeObjectMetadataItem, metadataFields.length, navigate]);
if (!activeObjectMetadataItem) return null;

View File

@ -29,7 +29,6 @@ export const SettingsObjectNewFieldStep2 = () => {
findActiveObjectMetadataItemBySlug,
findObjectMetadataItemById,
findObjectMetadataItemByNamePlural,
loading,
} = useObjectMetadataItemForSettings();
const activeObjectMetadataItem =
@ -45,7 +44,6 @@ export const SettingsObjectNewFieldStep2 = () => {
} = useFieldMetadataForm();
useEffect(() => {
if (loading) return;
if (!activeObjectMetadataItem) {
navigate(AppPath.NotFound);
return;
@ -61,7 +59,7 @@ export const SettingsObjectNewFieldStep2 = () => {
activeObjectMetadataItem,
findObjectMetadataItemByNamePlural,
initForm,
loading,
navigate,
]);

View File

@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom';
import styled from '@emotion/styled';
import { useOptimisticEffect } from '@/apollo/optimistic-effect/hooks/useOptimisticEffect';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { getRecordOptimisticEffectDefinition } from '@/object-record/graphql/optimistic-effect-definition/getRecordOptimisticEffectDefinition';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
import { objectSettingsWidth } from '@/settings/data-model/constants/objectSettings';
@ -47,7 +47,7 @@ export const SettingsDevelopersApiKeys = () => {
const { registerOptimisticEffect } = useOptimisticEffect({
objectNameSingular: 'apiKey',
});
const { foundObjectMetadataItem } = useFindOneObjectMetadataItem({
const { objectMetadataItem: foundObjectMetadataItem } = useObjectMetadataItem({
objectNameSingular: 'apiKey',
});
const filter = { revokedAt: { is: 'NULL' } };

View File

@ -274,7 +274,7 @@ export const seedPersonFieldMetadata = async (
targetColumnMap: {},
description: 'Contacts company',
icon: 'IconBuildingSkyscraper',
isNullable: false,
isNullable: true,
isSystem: false,
defaultValue: undefined,
},
@ -290,7 +290,7 @@ export const seedPersonFieldMetadata = async (
targetColumnMap: {},
description: 'Foreign key for company',
icon: undefined,
isNullable: false,
isNullable: true,
isSystem: true,
defaultValue: undefined,
},

View File

@ -128,7 +128,7 @@ const personMetadata = {
targetColumnMap: {},
description: 'Contacts company',
icon: 'IconBuildingSkyscraper',
isNullable: false,
isNullable: true,
isSystem: false,
},
{
@ -140,7 +140,7 @@ const personMetadata = {
targetColumnMap: {},
description: 'Foreign key for company',
icon: undefined,
isNullable: false,
isNullable: true,
isSystem: true,
},
{