forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement contextual actions for the workflows (twentyhq#8814)
Implemented the following actions for the workflows: - Test Workflow - Discard Draft - Activate Draft - Activate Workflow Last Published Version - Deactivate Workflow - See Workflow Executions - See Workflow Active Version - See Workflow Versions History And the following actions for the workflow versions: - Use As Draft - See Workflow Versions History - See Workflow Executions Video example: https://github.com/user-attachments/assets/016956a6-6f2e-4de5-9605-d6e14526cbb3 A few of these actions are links to the relations of the workflow object (link to a filtered table). To generalize this behavior, I will create an hook named `useSeeRelationsActionSingleRecordAction` to automatically generate links to a showPage if the relation is a Many To One or to a filtered table if the relation is a One to Many for all the record types. I will also create actions which will allow to create a relation. --------- Co-authored-by: Charles Bochet <[email protected]>
- Loading branch information
1 parent
dd14675
commit dd13a53
Showing
45 changed files
with
2,334 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
...s/record-actions/multiple-records/hooks/__tests__/useDeleteMultipleRecordsAction.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { actionMenuEntriesComponentState } from '@/action-menu/states/actionMenuEntriesComponentState'; | ||
import { ActionMenuComponentInstanceContext } from '@/action-menu/states/contexts/ActionMenuComponentInstanceContext'; | ||
import { contextStoreNumberOfSelectedRecordsComponentState } from '@/context-store/states/contextStoreNumberOfSelectedRecordsComponentState'; | ||
import { ContextStoreComponentInstanceContext } from '@/context-store/states/contexts/ContextStoreComponentInstanceContext'; | ||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2'; | ||
import { expect } from '@storybook/test'; | ||
import { renderHook } from '@testing-library/react'; | ||
import { act } from 'react'; | ||
import { getJestMetadataAndApolloMocksWrapper } from '~/testing/jest/getJestMetadataAndApolloMocksWrapper'; | ||
import { generatedMockObjectMetadataItems } from '~/testing/mock-data/generatedMockObjectMetadataItems'; | ||
import { useDeleteMultipleRecordsAction } from '../useDeleteMultipleRecordsAction'; | ||
|
||
jest.mock('@/object-record/hooks/useDeleteManyRecords', () => ({ | ||
useDeleteManyRecords: () => ({ | ||
deleteManyRecords: jest.fn(), | ||
}), | ||
})); | ||
jest.mock('@/favorites/hooks/useDeleteFavorite', () => ({ | ||
useDeleteFavorite: () => ({ | ||
deleteFavorite: jest.fn(), | ||
}), | ||
})); | ||
jest.mock('@/favorites/hooks/useFavorites', () => ({ | ||
useFavorites: () => ({ | ||
sortedFavorites: [], | ||
}), | ||
})); | ||
jest.mock('@/object-record/record-table/hooks/useRecordTable', () => ({ | ||
useRecordTable: () => ({ | ||
resetTableRowSelection: jest.fn(), | ||
}), | ||
})); | ||
|
||
const companyMockObjectMetadataItem = generatedMockObjectMetadataItems.find( | ||
(item) => item.nameSingular === 'company', | ||
)!; | ||
|
||
const JestMetadataAndApolloMocksWrapper = getJestMetadataAndApolloMocksWrapper({ | ||
apolloMocks: [], | ||
onInitializeRecoilSnapshot: ({ set }) => { | ||
set( | ||
contextStoreNumberOfSelectedRecordsComponentState.atomFamily({ | ||
instanceId: '1', | ||
}), | ||
3, | ||
); | ||
}, | ||
}); | ||
|
||
describe('useDeleteMultipleRecordsAction', () => { | ||
const wrapper = ({ children }: { children: React.ReactNode }) => ( | ||
<JestMetadataAndApolloMocksWrapper> | ||
<ContextStoreComponentInstanceContext.Provider | ||
value={{ | ||
instanceId: '1', | ||
}} | ||
> | ||
<ActionMenuComponentInstanceContext.Provider | ||
value={{ | ||
instanceId: '1', | ||
}} | ||
> | ||
{children} | ||
</ActionMenuComponentInstanceContext.Provider> | ||
</ContextStoreComponentInstanceContext.Provider> | ||
</JestMetadataAndApolloMocksWrapper> | ||
); | ||
|
||
it('should register delete action', () => { | ||
const { result } = renderHook( | ||
() => { | ||
const actionMenuEntries = useRecoilComponentValueV2( | ||
actionMenuEntriesComponentState, | ||
); | ||
|
||
return { | ||
actionMenuEntries, | ||
useDeleteMultipleRecordsAction: useDeleteMultipleRecordsAction({ | ||
objectMetadataItem: companyMockObjectMetadataItem, | ||
}), | ||
}; | ||
}, | ||
{ wrapper }, | ||
); | ||
|
||
act(() => { | ||
result.current.useDeleteMultipleRecordsAction.registerDeleteMultipleRecordsAction( | ||
{ position: 1 }, | ||
); | ||
}); | ||
|
||
expect(result.current.actionMenuEntries.size).toBe(1); | ||
expect( | ||
result.current.actionMenuEntries.get('delete-multiple-records'), | ||
).toBeDefined(); | ||
expect( | ||
result.current.actionMenuEntries.get('delete-multiple-records')?.position, | ||
).toBe(1); | ||
}); | ||
|
||
it('should unregister delete action', () => { | ||
const { result } = renderHook( | ||
() => { | ||
const actionMenuEntries = useRecoilComponentValueV2( | ||
actionMenuEntriesComponentState, | ||
); | ||
|
||
return { | ||
actionMenuEntries, | ||
useDeleteMultipleRecordsAction: useDeleteMultipleRecordsAction({ | ||
objectMetadataItem: companyMockObjectMetadataItem, | ||
}), | ||
}; | ||
}, | ||
{ wrapper }, | ||
); | ||
|
||
act(() => { | ||
result.current.useDeleteMultipleRecordsAction.registerDeleteMultipleRecordsAction( | ||
{ position: 1 }, | ||
); | ||
}); | ||
|
||
expect(result.current.actionMenuEntries.size).toBe(1); | ||
|
||
act(() => { | ||
result.current.useDeleteMultipleRecordsAction.unregisterDeleteMultipleRecordsAction(); | ||
}); | ||
|
||
expect(result.current.actionMenuEntries.size).toBe(0); | ||
}); | ||
}); |
105 changes: 105 additions & 0 deletions
105
...s/record-actions/multiple-records/hooks/__tests__/useExportMultipleRecordsAction.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { actionMenuEntriesComponentState } from '@/action-menu/states/actionMenuEntriesComponentState'; | ||
import { ActionMenuComponentInstanceContext } from '@/action-menu/states/contexts/ActionMenuComponentInstanceContext'; | ||
import { ContextStoreComponentInstanceContext } from '@/context-store/states/contexts/ContextStoreComponentInstanceContext'; | ||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2'; | ||
import { expect } from '@storybook/test'; | ||
import { renderHook } from '@testing-library/react'; | ||
import { act } from 'react'; | ||
import { JestObjectMetadataItemSetter } from '~/testing/jest/JestObjectMetadataItemSetter'; | ||
import { getJestMetadataAndApolloMocksWrapper } from '~/testing/jest/getJestMetadataAndApolloMocksWrapper'; | ||
import { generatedMockObjectMetadataItems } from '~/testing/mock-data/generatedMockObjectMetadataItems'; | ||
import { useExportMultipleRecordsAction } from '../useExportMultipleRecordsAction'; | ||
|
||
const companyMockObjectMetadataItem = generatedMockObjectMetadataItems.find( | ||
(item) => item.nameSingular === 'company', | ||
)!; | ||
|
||
const JestMetadataAndApolloMocksWrapper = getJestMetadataAndApolloMocksWrapper({ | ||
apolloMocks: [], | ||
}); | ||
|
||
describe('useExportMultipleRecordsAction', () => { | ||
const wrapper = ({ children }: { children: React.ReactNode }) => ( | ||
<JestMetadataAndApolloMocksWrapper> | ||
<JestObjectMetadataItemSetter> | ||
<ContextStoreComponentInstanceContext.Provider | ||
value={{ | ||
instanceId: '1', | ||
}} | ||
> | ||
<ActionMenuComponentInstanceContext.Provider | ||
value={{ | ||
instanceId: '1', | ||
}} | ||
> | ||
{children} | ||
</ActionMenuComponentInstanceContext.Provider> | ||
</ContextStoreComponentInstanceContext.Provider> | ||
</JestObjectMetadataItemSetter> | ||
</JestMetadataAndApolloMocksWrapper> | ||
); | ||
|
||
it('should register export multiple records action', () => { | ||
const { result } = renderHook( | ||
() => { | ||
const actionMenuEntries = useRecoilComponentValueV2( | ||
actionMenuEntriesComponentState, | ||
); | ||
|
||
return { | ||
actionMenuEntries, | ||
useExportMultipleRecordsAction: useExportMultipleRecordsAction({ | ||
objectMetadataItem: companyMockObjectMetadataItem, | ||
}), | ||
}; | ||
}, | ||
{ wrapper }, | ||
); | ||
|
||
act(() => { | ||
result.current.useExportMultipleRecordsAction.registerExportMultipleRecordsAction( | ||
{ position: 1 }, | ||
); | ||
}); | ||
|
||
expect(result.current.actionMenuEntries.size).toBe(1); | ||
expect( | ||
result.current.actionMenuEntries.get('export-multiple-records'), | ||
).toBeDefined(); | ||
expect( | ||
result.current.actionMenuEntries.get('export-multiple-records')?.position, | ||
).toBe(1); | ||
}); | ||
|
||
it('should unregister export multiple records action', () => { | ||
const { result } = renderHook( | ||
() => { | ||
const actionMenuEntries = useRecoilComponentValueV2( | ||
actionMenuEntriesComponentState, | ||
); | ||
|
||
return { | ||
actionMenuEntries, | ||
useExportMultipleRecordsAction: useExportMultipleRecordsAction({ | ||
objectMetadataItem: companyMockObjectMetadataItem, | ||
}), | ||
}; | ||
}, | ||
{ wrapper }, | ||
); | ||
|
||
act(() => { | ||
result.current.useExportMultipleRecordsAction.registerExportMultipleRecordsAction( | ||
{ position: 1 }, | ||
); | ||
}); | ||
|
||
expect(result.current.actionMenuEntries.size).toBe(1); | ||
|
||
act(() => { | ||
result.current.useExportMultipleRecordsAction.unregisterExportMultipleRecordsAction(); | ||
}); | ||
|
||
expect(result.current.actionMenuEntries.size).toBe(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.