Remove dead code linked to quick actions (#6587)
Removing dead code, we'll take another approach to build this
This commit is contained in:
@ -1,16 +0,0 @@
|
||||
import { PERSON_FRAGMENT } from '@/object-record/hooks/__mocks__/personFragment';
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export { responseData } from './useUpdateOneRecord';
|
||||
|
||||
export const query = gql`
|
||||
mutation ExecuteQuickActionOnOnePerson($idToExecuteQuickActionOn: ID!) {
|
||||
executeQuickActionOnPerson(id: $idToExecuteQuickActionOn) {
|
||||
${PERSON_FRAGMENT}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const variables = {
|
||||
idToExecuteQuickActionOn: 'a7286b9a-c039-4a89-9567-2dfa7953cda9',
|
||||
};
|
||||
@ -1,62 +0,0 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import { RecoilRoot } from 'recoil';
|
||||
|
||||
import {
|
||||
query,
|
||||
responseData,
|
||||
variables,
|
||||
} from '@/object-record/hooks/__mocks__/useExecuteQuickActionOnOneRecord';
|
||||
import { useExecuteQuickActionOnOneRecord } from '@/object-record/hooks/useExecuteQuickActionOnOneRecord';
|
||||
|
||||
const idToExecuteQuickActionOn = 'a7286b9a-c039-4a89-9567-2dfa7953cda9';
|
||||
|
||||
const mocks = [
|
||||
{
|
||||
request: {
|
||||
query,
|
||||
variables,
|
||||
},
|
||||
result: jest.fn(() => ({
|
||||
data: {
|
||||
executeQuickActionOnPerson: {
|
||||
...responseData,
|
||||
id: idToExecuteQuickActionOn,
|
||||
},
|
||||
},
|
||||
})),
|
||||
},
|
||||
];
|
||||
|
||||
const Wrapper = ({ children }: { children: ReactNode }) => (
|
||||
<RecoilRoot>
|
||||
<MockedProvider mocks={mocks} addTypename={false}>
|
||||
{children}
|
||||
</MockedProvider>
|
||||
</RecoilRoot>
|
||||
);
|
||||
|
||||
describe('useExecuteQuickActionOnOneRecord', () => {
|
||||
it('should work as expected', async () => {
|
||||
const { result } = renderHook(
|
||||
() =>
|
||||
useExecuteQuickActionOnOneRecord({
|
||||
objectNameSingular: 'person',
|
||||
}),
|
||||
{
|
||||
wrapper: Wrapper,
|
||||
},
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
const res = await result.current.executeQuickActionOnOneRecord(
|
||||
idToExecuteQuickActionOn,
|
||||
);
|
||||
|
||||
expect(res).toHaveProperty('id', idToExecuteQuickActionOn);
|
||||
});
|
||||
|
||||
expect(mocks[0].result).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@ -1,40 +0,0 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { print } from 'graphql';
|
||||
import { RecoilRoot } from 'recoil';
|
||||
|
||||
import { PERSON_FRAGMENT } from '@/object-record/hooks/__mocks__/personFragment';
|
||||
import { useExecuteQuickActionOnOneRecordMutation } from '@/object-record/hooks/useExecuteQuickActionOnOneRecordMutation';
|
||||
|
||||
const expectedQueryTemplate = `
|
||||
mutation ExecuteQuickActionOnOnePerson($idToExecuteQuickActionOn: ID!) {
|
||||
executeQuickActionOnPerson(id: $idToExecuteQuickActionOn) {
|
||||
${PERSON_FRAGMENT}
|
||||
}
|
||||
}
|
||||
`.replace(/\s/g, '');
|
||||
|
||||
describe('useExecuteQuickActionOnOneRecordMutation', () => {
|
||||
it('should return a valid executeQuickActionOnOneRecordMutation', () => {
|
||||
const objectNameSingular = 'person';
|
||||
|
||||
const { result } = renderHook(
|
||||
() =>
|
||||
useExecuteQuickActionOnOneRecordMutation({
|
||||
objectNameSingular,
|
||||
}),
|
||||
{
|
||||
wrapper: RecoilRoot,
|
||||
},
|
||||
);
|
||||
|
||||
const { executeQuickActionOnOneRecordMutation } = result.current;
|
||||
|
||||
expect(executeQuickActionOnOneRecordMutation).toBeDefined();
|
||||
|
||||
const printedReceivedQuery = print(
|
||||
executeQuickActionOnOneRecordMutation,
|
||||
).replace(/\s/g, '');
|
||||
|
||||
expect(printedReceivedQuery).toEqual(expectedQueryTemplate);
|
||||
});
|
||||
});
|
||||
@ -1,57 +0,0 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useApolloClient } from '@apollo/client';
|
||||
import { getOperationName } from '@apollo/client/utilities';
|
||||
|
||||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { useExecuteQuickActionOnOneRecordMutation } from '@/object-record/hooks/useExecuteQuickActionOnOneRecordMutation';
|
||||
import { useFindManyRecordsQuery } from '@/object-record/hooks/useFindManyRecordsQuery';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
type useExecuteQuickActionOnOneRecordProps = {
|
||||
objectNameSingular: string;
|
||||
};
|
||||
|
||||
export const useExecuteQuickActionOnOneRecord = <T>({
|
||||
objectNameSingular,
|
||||
}: useExecuteQuickActionOnOneRecordProps) => {
|
||||
const { objectMetadataItem } = useObjectMetadataItem({
|
||||
objectNameSingular,
|
||||
});
|
||||
|
||||
const { executeQuickActionOnOneRecordMutation } =
|
||||
useExecuteQuickActionOnOneRecordMutation({
|
||||
objectNameSingular,
|
||||
});
|
||||
|
||||
const { findManyRecordsQuery } = useFindManyRecordsQuery({
|
||||
objectNameSingular,
|
||||
});
|
||||
|
||||
const apolloClient = useApolloClient();
|
||||
|
||||
const executeQuickActionOnOneRecord = useCallback(
|
||||
async (idToExecuteQuickActionOn: string) => {
|
||||
const executeQuickActionOnRecord = await apolloClient.mutate({
|
||||
mutation: executeQuickActionOnOneRecordMutation,
|
||||
variables: {
|
||||
idToExecuteQuickActionOn,
|
||||
},
|
||||
refetchQueries: [getOperationName(findManyRecordsQuery) ?? ''],
|
||||
});
|
||||
|
||||
return executeQuickActionOnRecord.data[
|
||||
`executeQuickActionOn${capitalize(objectMetadataItem.nameSingular)}`
|
||||
] as T;
|
||||
},
|
||||
[
|
||||
objectMetadataItem.nameSingular,
|
||||
apolloClient,
|
||||
executeQuickActionOnOneRecordMutation,
|
||||
findManyRecordsQuery,
|
||||
],
|
||||
);
|
||||
|
||||
return {
|
||||
executeQuickActionOnOneRecord,
|
||||
};
|
||||
};
|
||||
@ -1,53 +0,0 @@
|
||||
import { gql } from '@apollo/client';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
|
||||
import { mapObjectMetadataToGraphQLQuery } from '@/object-metadata/utils/mapObjectMetadataToGraphQLQuery';
|
||||
import { EMPTY_MUTATION } from '@/object-record/constants/EmptyMutation';
|
||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
export const getExecuteQuickActionOnOneRecordMutationGraphQLField = ({
|
||||
objectNameSingular,
|
||||
}: {
|
||||
objectNameSingular: string;
|
||||
}) => {
|
||||
return `executeQuickActionOn${capitalize(objectNameSingular)}`;
|
||||
};
|
||||
|
||||
export const useExecuteQuickActionOnOneRecordMutation = ({
|
||||
objectNameSingular,
|
||||
}: {
|
||||
objectNameSingular: string;
|
||||
}) => {
|
||||
const { objectMetadataItem } = useObjectMetadataItem({
|
||||
objectNameSingular,
|
||||
});
|
||||
|
||||
const objectMetadataItems = useRecoilValue(objectMetadataItemsState);
|
||||
|
||||
if (isUndefinedOrNull(objectMetadataItem)) {
|
||||
return { executeQuickActionOnOneRecordMutation: EMPTY_MUTATION };
|
||||
}
|
||||
|
||||
const capitalizedObjectName = capitalize(objectMetadataItem.nameSingular);
|
||||
|
||||
const graphQLFieldForExecuteQuickActionOnOneRecordMutation =
|
||||
getExecuteQuickActionOnOneRecordMutationGraphQLField({
|
||||
objectNameSingular: objectMetadataItem.nameSingular,
|
||||
});
|
||||
|
||||
const executeQuickActionOnOneRecordMutation = gql`
|
||||
mutation ExecuteQuickActionOnOne${capitalizedObjectName}($idToExecuteQuickActionOn: ID!) {
|
||||
${graphQLFieldForExecuteQuickActionOnOneRecordMutation}(id: $idToExecuteQuickActionOn) ${mapObjectMetadataToGraphQLQuery(
|
||||
{
|
||||
objectMetadataItems,
|
||||
objectMetadataItem,
|
||||
},
|
||||
)}
|
||||
}
|
||||
`;
|
||||
|
||||
return { executeQuickActionOnOneRecordMutation };
|
||||
};
|
||||
@ -1,20 +1,11 @@
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { useRecoilCallback, useSetRecoilState } from 'recoil';
|
||||
import {
|
||||
IconClick,
|
||||
IconFileExport,
|
||||
IconHeart,
|
||||
IconHeartOff,
|
||||
IconMail,
|
||||
IconPuzzle,
|
||||
IconTrash,
|
||||
} from 'twenty-ui';
|
||||
import { IconFileExport, IconHeart, IconHeartOff, IconTrash } from 'twenty-ui';
|
||||
|
||||
import { useFavorites } from '@/favorites/hooks/useFavorites';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { DELETE_MAX_COUNT } from '@/object-record/constants/DeleteMaxCount';
|
||||
import { useExecuteQuickActionOnOneRecord } from '@/object-record/hooks/useExecuteQuickActionOnOneRecord';
|
||||
import { useDeleteTableData } from '@/object-record/record-index/options/hooks/useDeleteTableData';
|
||||
import {
|
||||
displayedExportProgress,
|
||||
@ -25,7 +16,6 @@ import { ConfirmationModal } from '@/ui/layout/modal/components/ConfirmationModa
|
||||
import { actionBarEntriesState } from '@/ui/navigation/action-bar/states/actionBarEntriesState';
|
||||
import { contextMenuEntriesState } from '@/ui/navigation/context-menu/states/contextMenuEntriesState';
|
||||
import { ContextMenuEntry } from '@/ui/navigation/context-menu/types/ContextMenuEntry';
|
||||
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
type useRecordActionBarProps = {
|
||||
@ -48,10 +38,6 @@ export const useRecordActionBar = ({
|
||||
|
||||
const { createFavorite, favorites, deleteFavorite } = useFavorites();
|
||||
|
||||
const { executeQuickActionOnOneRecord } = useExecuteQuickActionOnOneRecord({
|
||||
objectNameSingular: objectMetadataItem.nameSingular,
|
||||
});
|
||||
|
||||
const handleFavoriteButtonClick = useRecoilCallback(
|
||||
({ snapshot }) =>
|
||||
() => {
|
||||
@ -99,15 +85,6 @@ export const useRecordActionBar = ({
|
||||
deleteTableData(selectedRecordIds);
|
||||
}, [deleteTableData, selectedRecordIds]);
|
||||
|
||||
const handleExecuteQuickActionOnClick = useCallback(async () => {
|
||||
callback?.();
|
||||
await Promise.all(
|
||||
selectedRecordIds.map(async (recordId) => {
|
||||
await executeQuickActionOnOneRecord(recordId);
|
||||
}),
|
||||
);
|
||||
}, [callback, executeQuickActionOnOneRecord, selectedRecordIds]);
|
||||
|
||||
const { progress, download } = useExportTableData({
|
||||
...baseTableDataParams,
|
||||
filename: `${objectMetadataItem.nameSingular}.csv`,
|
||||
@ -168,10 +145,6 @@ export const useRecordActionBar = ({
|
||||
],
|
||||
);
|
||||
|
||||
const dataExecuteQuickActionOnmentEnabled = useIsFeatureEnabled(
|
||||
'IS_QUICK_ACTIONS_ENABLED',
|
||||
);
|
||||
|
||||
const hasOnlyOneRecordSelected = selectedRecordIds.length === 1;
|
||||
|
||||
const isFavorite =
|
||||
@ -212,12 +185,13 @@ export const useRecordActionBar = ({
|
||||
|
||||
setActionBarEntries: useCallback(() => {
|
||||
setActionBarEntriesState([
|
||||
...(dataExecuteQuickActionOnmentEnabled
|
||||
? [
|
||||
/*
|
||||
{
|
||||
label: 'Actions',
|
||||
Icon: IconClick,
|
||||
subActions: [
|
||||
subActions:
|
||||
|
||||
/* [
|
||||
{
|
||||
label: 'Enrich',
|
||||
Icon: IconPuzzle,
|
||||
@ -228,16 +202,9 @@ export const useRecordActionBar = ({
|
||||
Icon: IconMail,
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
: []),
|
||||
*/
|
||||
...menuActions,
|
||||
]);
|
||||
}, [
|
||||
menuActions,
|
||||
dataExecuteQuickActionOnmentEnabled,
|
||||
handleExecuteQuickActionOnClick,
|
||||
setActionBarEntriesState,
|
||||
]),
|
||||
}, [menuActions, setActionBarEntriesState]),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user