-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathCommandMenuContextProviderServerItemsWithWorkflowEnrichment.tsx
More file actions
65 lines (56 loc) · 2.13 KB
/
CommandMenuContextProviderServerItemsWithWorkflowEnrichment.tsx
File metadata and controls
65 lines (56 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { type CommandMenuContextApi } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { type CommandMenuContextType } from '@/command-menu-item/contexts/CommandMenuContext';
import { useWorkflowsWithCurrentVersions } from '@/command-menu-item/server-items/common/hooks/useWorkflowsWithCurrentVersions';
import { CommandMenuContextProviderServerItemsContent } from './CommandMenuContextProviderServerItemsContent';
type CommandMenuContextProviderServerItemsWithWorkflowEnrichmentProps = {
isInSidePanel: CommandMenuContextType['isInSidePanel'];
displayType: CommandMenuContextType['displayType'];
containerType: CommandMenuContextType['containerType'];
children: React.ReactNode;
};
export const CommandMenuContextProviderServerItemsWithWorkflowEnrichment = ({
isInSidePanel,
displayType,
containerType,
children,
commandMenuContextApi,
selectedWorkflowRecordIds,
}: CommandMenuContextProviderServerItemsWithWorkflowEnrichmentProps & {
commandMenuContextApi: CommandMenuContextApi;
selectedWorkflowRecordIds: string[];
}) => {
const workflowsWithCurrentVersions = useWorkflowsWithCurrentVersions(
selectedWorkflowRecordIds,
);
const enrichedSelectedRecords = commandMenuContextApi.selectedRecords.map(
(record) => {
const workflowWithCurrentVersion = workflowsWithCurrentVersions.find(
(workflow) => workflow.id === record.id,
);
if (!isDefined(workflowWithCurrentVersion)) {
return record;
}
return {
...record,
currentVersion: workflowWithCurrentVersion.currentVersion,
versions: workflowWithCurrentVersion.versions,
statuses: workflowWithCurrentVersion.statuses,
};
},
);
const enrichedCommandMenuContextApi = {
...commandMenuContextApi,
selectedRecords: enrichedSelectedRecords,
};
return (
<CommandMenuContextProviderServerItemsContent
isInSidePanel={isInSidePanel}
displayType={displayType}
containerType={containerType}
commandMenuContextApi={enrichedCommandMenuContextApi}
>
{children}
</CommandMenuContextProviderServerItemsContent>
);
};