Refactored all single record actions (#9045)

## Context

Refactored all single record actions so they can be defined by a config
file.
This refactoring is made with the idea that later the actions will be
stored in the database, so we needed a way to serialize them.
For each object we can define a config file, if an object has no config
file, it falls back to the default config.
I introduced action hooks, which return:
- `shouldBeRegistered`: `boolean` Whether the action should be
registered.
- `onClick`: `() => void` The code that will be executed when we click
on an action
- `ConfirmationModal`?: `React.ReactNode` (optional) The confirmation
modal which will be displayed on click

This PR also closes #8973 

## Next steps

- Refactor multiple records actions
- Refactor no selection actions
- Add tests
This commit is contained in:
Raphaël Bosi
2024-12-16 16:30:18 +01:00
committed by GitHub
parent 5d51a826ea
commit 8ce6f6daea
57 changed files with 1868 additions and 1893 deletions

View File

@ -14,7 +14,7 @@ import { ViewType } from '@/views/types/ViewType';
import { MockedResponse } from '@apollo/client/testing';
import { expect } from '@storybook/test';
import gql from 'graphql-tag';
import { getJestMetadataAndApolloMocksAndContextStoreWrapper } from '~/testing/jest/getJestMetadataAndApolloMocksAndContextStoreWrapper';
import { getJestMetadataAndApolloMocksAndActionMenuWrapper } from '~/testing/jest/getJestMetadataAndApolloMocksAndContextStoreWrapper';
import { generatedMockObjectMetadataItems } from '~/testing/mock-data/generatedMockObjectMetadataItems';
const defaultResponseData = {
@ -130,17 +130,15 @@ const mocks: MockedResponse[] = [
},
];
const WrapperWithResponse = getJestMetadataAndApolloMocksAndContextStoreWrapper(
{
apolloMocks: mocks,
componentInstanceId: 'recordIndexId',
contextStoreTargetedRecordsRule: {
mode: 'selection',
selectedRecordIds: [],
},
contextStoreCurrentObjectMetadataNameSingular: 'person',
const WrapperWithResponse = getJestMetadataAndApolloMocksAndActionMenuWrapper({
apolloMocks: mocks,
componentInstanceId: 'recordIndexId',
contextStoreTargetedRecordsRule: {
mode: 'selection',
selectedRecordIds: [],
},
);
contextStoreCurrentObjectMetadataNameSingular: 'person',
});
const graphqlEmptyResponse = [
{
@ -157,7 +155,7 @@ const graphqlEmptyResponse = [
];
const WrapperWithEmptyResponse =
getJestMetadataAndApolloMocksAndContextStoreWrapper({
getJestMetadataAndApolloMocksAndActionMenuWrapper({
apolloMocks: graphqlEmptyResponse,
componentInstanceId: 'recordIndexId',
contextStoreTargetedRecordsRule: {