Remove viewGroup v1 implem (#16178)
# Introduction Removing v1 implementation of view groups and both view group and view field relicas front fetchers Related https://github.com/twentyhq/core-team-issues/issues/1911
This commit is contained in:
@@ -4,18 +4,14 @@ import { useMetadataErrorHandler } from '@/metadata-error-handler/hooks/useMetad
|
||||
import { type MetadataRequestResult } from '@/object-metadata/types/MetadataRequestResult.type';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { useTriggerViewFieldOptimisticEffect } from '@/views/optimistic-effects/hooks/useTriggerViewFieldOptimisticEffect';
|
||||
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
|
||||
import { ApolloError } from '@apollo/client';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import {
|
||||
type CreateCoreViewFieldMutationVariables,
|
||||
type CreateManyCoreViewFieldsMutationVariables,
|
||||
type DeleteCoreViewFieldMutationVariables,
|
||||
type DestroyCoreViewFieldMutationVariables,
|
||||
FeatureFlagKey,
|
||||
type UpdateCoreViewFieldMutationVariables,
|
||||
useCreateCoreViewFieldMutation,
|
||||
useCreateManyCoreViewFieldsMutation,
|
||||
useDeleteCoreViewFieldMutation,
|
||||
useDestroyCoreViewFieldMutation,
|
||||
@@ -25,11 +21,6 @@ export const usePersistViewField = () => {
|
||||
const { triggerViewFieldOptimisticEffect } =
|
||||
useTriggerViewFieldOptimisticEffect();
|
||||
|
||||
const isWorkspaceMigrationV2Enabled = useIsFeatureEnabled(
|
||||
FeatureFlagKey.IS_WORKSPACE_MIGRATION_V2_ENABLED,
|
||||
);
|
||||
|
||||
const [createCoreViewFieldMutation] = useCreateCoreViewFieldMutation();
|
||||
const [createManyCoreViewFieldsMutation] =
|
||||
useCreateManyCoreViewFieldsMutation();
|
||||
const [updateCoreViewFieldMutation] = useUpdateCoreViewFieldMutation();
|
||||
@@ -39,77 +30,13 @@ export const usePersistViewField = () => {
|
||||
const { handleMetadataError } = useMetadataErrorHandler();
|
||||
const { enqueueErrorSnackBar } = useSnackBar();
|
||||
|
||||
const oldCreateViewFields = useCallback(
|
||||
async (
|
||||
createCoreViewFieldInputs: CreateCoreViewFieldMutationVariables[],
|
||||
): Promise<
|
||||
MetadataRequestResult<
|
||||
Awaited<ReturnType<typeof createCoreViewFieldMutation>>[]
|
||||
>
|
||||
> => {
|
||||
if (createCoreViewFieldInputs.length === 0) {
|
||||
return {
|
||||
status: 'successful',
|
||||
response: [],
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const results = await Promise.all(
|
||||
createCoreViewFieldInputs.map(async (variables) =>
|
||||
createCoreViewFieldMutation({
|
||||
variables,
|
||||
update: (_cache, { data }) => {
|
||||
const createdViewField = data?.createCoreViewField;
|
||||
if (!isDefined(createdViewField)) {
|
||||
return;
|
||||
}
|
||||
|
||||
triggerViewFieldOptimisticEffect({
|
||||
createdViewFields: [createdViewField],
|
||||
});
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
return {
|
||||
status: 'successful',
|
||||
response: results,
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof ApolloError) {
|
||||
handleMetadataError(error, {
|
||||
primaryMetadataName: 'viewField',
|
||||
});
|
||||
} else {
|
||||
enqueueErrorSnackBar({ message: t`An error occurred.` });
|
||||
}
|
||||
|
||||
return {
|
||||
status: 'failed',
|
||||
error,
|
||||
};
|
||||
}
|
||||
},
|
||||
[
|
||||
triggerViewFieldOptimisticEffect,
|
||||
createCoreViewFieldMutation,
|
||||
handleMetadataError,
|
||||
enqueueErrorSnackBar,
|
||||
],
|
||||
);
|
||||
|
||||
const createViewFields = useCallback(
|
||||
async (
|
||||
createCoreViewFieldInputs: CreateManyCoreViewFieldsMutationVariables,
|
||||
): Promise<
|
||||
| MetadataRequestResult<Awaited<
|
||||
ReturnType<typeof createManyCoreViewFieldsMutation>
|
||||
> | null>
|
||||
| MetadataRequestResult<
|
||||
Awaited<ReturnType<typeof createCoreViewFieldMutation>>[]
|
||||
>
|
||||
MetadataRequestResult<Awaited<
|
||||
ReturnType<typeof createManyCoreViewFieldsMutation>
|
||||
> | null>
|
||||
> => {
|
||||
if (
|
||||
!Array.isArray(createCoreViewFieldInputs.inputs) ||
|
||||
@@ -121,12 +48,6 @@ export const usePersistViewField = () => {
|
||||
};
|
||||
}
|
||||
|
||||
if (!isWorkspaceMigrationV2Enabled) {
|
||||
const oldFormatInputs: CreateCoreViewFieldMutationVariables[] =
|
||||
createCoreViewFieldInputs.inputs.map((input) => ({ input }));
|
||||
return await oldCreateViewFields(oldFormatInputs);
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await createManyCoreViewFieldsMutation({
|
||||
variables: createCoreViewFieldInputs,
|
||||
@@ -162,8 +83,6 @@ export const usePersistViewField = () => {
|
||||
}
|
||||
},
|
||||
[
|
||||
isWorkspaceMigrationV2Enabled,
|
||||
oldCreateViewFields,
|
||||
triggerViewFieldOptimisticEffect,
|
||||
createManyCoreViewFieldsMutation,
|
||||
handleMetadataError,
|
||||
|
||||
@@ -4,18 +4,14 @@ import { useMetadataErrorHandler } from '@/metadata-error-handler/hooks/useMetad
|
||||
import { type MetadataRequestResult } from '@/object-metadata/types/MetadataRequestResult.type';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { useTriggerViewGroupOptimisticEffect } from '@/views/optimistic-effects/hooks/useTriggerViewGroupOptimisticEffect';
|
||||
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
|
||||
import { ApolloError } from '@apollo/client';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import {
|
||||
type CreateCoreViewGroupMutationVariables,
|
||||
type CreateManyCoreViewGroupsMutationVariables,
|
||||
type DeleteCoreViewGroupMutationVariables,
|
||||
type DestroyCoreViewGroupMutationVariables,
|
||||
FeatureFlagKey,
|
||||
type UpdateCoreViewGroupMutationVariables,
|
||||
useCreateCoreViewGroupMutation,
|
||||
useCreateManyCoreViewGroupsMutation,
|
||||
useDeleteCoreViewGroupMutation,
|
||||
useDestroyCoreViewGroupMutation,
|
||||
@@ -26,11 +22,6 @@ export const usePersistViewGroupRecords = () => {
|
||||
const { triggerViewGroupOptimisticEffect } =
|
||||
useTriggerViewGroupOptimisticEffect();
|
||||
|
||||
const isWorkspaceMigrationV2Enabled = useIsFeatureEnabled(
|
||||
FeatureFlagKey.IS_WORKSPACE_MIGRATION_V2_ENABLED,
|
||||
);
|
||||
|
||||
const [createCoreViewGroupMutation] = useCreateCoreViewGroupMutation();
|
||||
const [createManyCoreViewGroupsMutation] =
|
||||
useCreateManyCoreViewGroupsMutation();
|
||||
const [updateCoreViewGroupMutation] = useUpdateCoreViewGroupMutation();
|
||||
@@ -40,77 +31,13 @@ export const usePersistViewGroupRecords = () => {
|
||||
const { handleMetadataError } = useMetadataErrorHandler();
|
||||
const { enqueueErrorSnackBar } = useSnackBar();
|
||||
|
||||
const oldCreateViewGroups = useCallback(
|
||||
async (
|
||||
createCoreViewGroupInputs: CreateCoreViewGroupMutationVariables[],
|
||||
): Promise<
|
||||
MetadataRequestResult<
|
||||
Awaited<ReturnType<typeof createCoreViewGroupMutation>>[]
|
||||
>
|
||||
> => {
|
||||
if (createCoreViewGroupInputs.length === 0) {
|
||||
return {
|
||||
status: 'successful',
|
||||
response: [],
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const results = await Promise.all(
|
||||
createCoreViewGroupInputs.map(async (variables) =>
|
||||
createCoreViewGroupMutation({
|
||||
variables,
|
||||
update: (_cache, { data }) => {
|
||||
const createdViewGroup = data?.createCoreViewGroup;
|
||||
if (!isDefined(createdViewGroup)) {
|
||||
return;
|
||||
}
|
||||
|
||||
triggerViewGroupOptimisticEffect({
|
||||
createdViewGroups: [createdViewGroup],
|
||||
});
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
return {
|
||||
status: 'successful',
|
||||
response: results,
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof ApolloError) {
|
||||
handleMetadataError(error, {
|
||||
primaryMetadataName: 'viewGroup',
|
||||
});
|
||||
} else {
|
||||
enqueueErrorSnackBar({ message: t`An error occurred.` });
|
||||
}
|
||||
|
||||
return {
|
||||
status: 'failed',
|
||||
error,
|
||||
};
|
||||
}
|
||||
},
|
||||
[
|
||||
triggerViewGroupOptimisticEffect,
|
||||
createCoreViewGroupMutation,
|
||||
handleMetadataError,
|
||||
enqueueErrorSnackBar,
|
||||
],
|
||||
);
|
||||
|
||||
const createViewGroups = useCallback(
|
||||
async (
|
||||
createCoreViewGroupInputs: CreateManyCoreViewGroupsMutationVariables,
|
||||
): Promise<
|
||||
| MetadataRequestResult<Awaited<
|
||||
ReturnType<typeof createManyCoreViewGroupsMutation>
|
||||
> | null>
|
||||
| MetadataRequestResult<
|
||||
Awaited<ReturnType<typeof createCoreViewGroupMutation>>[]
|
||||
>
|
||||
MetadataRequestResult<Awaited<
|
||||
ReturnType<typeof createManyCoreViewGroupsMutation>
|
||||
> | null>
|
||||
> => {
|
||||
if (
|
||||
!Array.isArray(createCoreViewGroupInputs.inputs) ||
|
||||
@@ -122,12 +49,6 @@ export const usePersistViewGroupRecords = () => {
|
||||
};
|
||||
}
|
||||
|
||||
if (!isWorkspaceMigrationV2Enabled) {
|
||||
const oldFormatInputs: CreateCoreViewGroupMutationVariables[] =
|
||||
createCoreViewGroupInputs.inputs.map((input) => ({ input }));
|
||||
return await oldCreateViewGroups(oldFormatInputs);
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await createManyCoreViewGroupsMutation({
|
||||
variables: createCoreViewGroupInputs,
|
||||
@@ -163,8 +84,6 @@ export const usePersistViewGroupRecords = () => {
|
||||
}
|
||||
},
|
||||
[
|
||||
isWorkspaceMigrationV2Enabled,
|
||||
oldCreateViewGroups,
|
||||
triggerViewGroupOptimisticEffect,
|
||||
createManyCoreViewGroupsMutation,
|
||||
handleMetadataError,
|
||||
|
||||
Reference in New Issue
Block a user