Display tag for workflow version status (#6972)
- Move where we fetch workflow data. We now fetch them in the `Workflow` component directly. That's useful to access it in the `WorkflowShowPageEffect` and `WorkflowDiagramCanvas` components. 
This commit is contained in:
committed by
GitHub
parent
31c02202bd
commit
e9f8e6e718
@ -1,14 +1,17 @@
|
|||||||
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
|
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
|
||||||
import { WorkflowDiagramCanvas } from '@/workflow/components/WorkflowDiagramCanvas';
|
import { WorkflowDiagramCanvas } from '@/workflow/components/WorkflowDiagramCanvas';
|
||||||
import { WorkflowEffect } from '@/workflow/components/WorkflowEffect';
|
import { WorkflowEffect } from '@/workflow/components/WorkflowEffect';
|
||||||
|
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||||
import { workflowDiagramState } from '@/workflow/states/workflowDiagramState';
|
import { workflowDiagramState } from '@/workflow/states/workflowDiagramState';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import '@xyflow/react/dist/style.css';
|
import '@xyflow/react/dist/style.css';
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
|
import { isDefined } from 'twenty-ui';
|
||||||
|
|
||||||
const StyledFlowContainer = styled.div`
|
const StyledFlowContainer = styled.div`
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
/* Below we reset the default styling of Reactflow */
|
/* Below we reset the default styling of Reactflow */
|
||||||
.react-flow__node-input,
|
.react-flow__node-input,
|
||||||
@ -32,16 +35,23 @@ export const Workflow = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const workflowId = targetableObject.id;
|
const workflowId = targetableObject.id;
|
||||||
|
|
||||||
|
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(workflowId);
|
||||||
const workflowDiagram = useRecoilValue(workflowDiagramState);
|
const workflowDiagram = useRecoilValue(workflowDiagramState);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WorkflowEffect workflowId={workflowId} />
|
<WorkflowEffect
|
||||||
|
workflowId={workflowId}
|
||||||
|
workflowWithCurrentVersion={workflowWithCurrentVersion}
|
||||||
|
/>
|
||||||
|
|
||||||
<StyledFlowContainer>
|
<StyledFlowContainer>
|
||||||
{workflowDiagram === undefined ? null : (
|
{isDefined(workflowDiagram) && isDefined(workflowWithCurrentVersion) ? (
|
||||||
<WorkflowDiagramCanvas diagram={workflowDiagram} />
|
<WorkflowDiagramCanvas
|
||||||
)}
|
diagram={workflowDiagram}
|
||||||
|
workflowWithCurrentVersion={workflowWithCurrentVersion}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
</StyledFlowContainer>
|
</StyledFlowContainer>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -2,13 +2,16 @@ import { WorkflowDiagramCanvasEffect } from '@/workflow/components/WorkflowDiagr
|
|||||||
import { WorkflowDiagramCreateStepNode } from '@/workflow/components/WorkflowDiagramCreateStepNode';
|
import { WorkflowDiagramCreateStepNode } from '@/workflow/components/WorkflowDiagramCreateStepNode';
|
||||||
import { WorkflowDiagramEmptyTrigger } from '@/workflow/components/WorkflowDiagramEmptyTrigger';
|
import { WorkflowDiagramEmptyTrigger } from '@/workflow/components/WorkflowDiagramEmptyTrigger';
|
||||||
import { WorkflowDiagramStepNode } from '@/workflow/components/WorkflowDiagramStepNode';
|
import { WorkflowDiagramStepNode } from '@/workflow/components/WorkflowDiagramStepNode';
|
||||||
|
import { WorkflowVersionStatusTag } from '@/workflow/components/WorkflowVersionStatusTag';
|
||||||
import { workflowDiagramState } from '@/workflow/states/workflowDiagramState';
|
import { workflowDiagramState } from '@/workflow/states/workflowDiagramState';
|
||||||
|
import { WorkflowWithCurrentVersion } from '@/workflow/types/Workflow';
|
||||||
import {
|
import {
|
||||||
WorkflowDiagram,
|
WorkflowDiagram,
|
||||||
WorkflowDiagramEdge,
|
WorkflowDiagramEdge,
|
||||||
WorkflowDiagramNode,
|
WorkflowDiagramNode,
|
||||||
} from '@/workflow/types/WorkflowDiagram';
|
} from '@/workflow/types/WorkflowDiagram';
|
||||||
import { getOrganizedDiagram } from '@/workflow/utils/getOrganizedDiagram';
|
import { getOrganizedDiagram } from '@/workflow/utils/getOrganizedDiagram';
|
||||||
|
import styled from '@emotion/styled';
|
||||||
import {
|
import {
|
||||||
applyEdgeChanges,
|
applyEdgeChanges,
|
||||||
applyNodeChanges,
|
applyNodeChanges,
|
||||||
@ -22,10 +25,19 @@ import { useMemo } from 'react';
|
|||||||
import { useSetRecoilState } from 'recoil';
|
import { useSetRecoilState } from 'recoil';
|
||||||
import { GRAY_SCALE, isDefined } from 'twenty-ui';
|
import { GRAY_SCALE, isDefined } from 'twenty-ui';
|
||||||
|
|
||||||
|
const StyledStatusTagContainer = styled.div`
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
position: absolute;
|
||||||
|
padding: ${({ theme }) => theme.spacing(2)};
|
||||||
|
`;
|
||||||
|
|
||||||
export const WorkflowDiagramCanvas = ({
|
export const WorkflowDiagramCanvas = ({
|
||||||
diagram,
|
diagram,
|
||||||
|
workflowWithCurrentVersion,
|
||||||
}: {
|
}: {
|
||||||
diagram: WorkflowDiagram;
|
diagram: WorkflowDiagram;
|
||||||
|
workflowWithCurrentVersion: WorkflowWithCurrentVersion;
|
||||||
}) => {
|
}) => {
|
||||||
const { nodes, edges } = useMemo(
|
const { nodes, edges } = useMemo(
|
||||||
() => getOrganizedDiagram(diagram),
|
() => getOrganizedDiagram(diagram),
|
||||||
@ -69,21 +81,29 @@ export const WorkflowDiagramCanvas = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactFlow
|
<>
|
||||||
nodeTypes={{
|
<ReactFlow
|
||||||
default: WorkflowDiagramStepNode,
|
nodeTypes={{
|
||||||
'create-step': WorkflowDiagramCreateStepNode,
|
default: WorkflowDiagramStepNode,
|
||||||
'empty-trigger': WorkflowDiagramEmptyTrigger,
|
'create-step': WorkflowDiagramCreateStepNode,
|
||||||
}}
|
'empty-trigger': WorkflowDiagramEmptyTrigger,
|
||||||
fitView
|
}}
|
||||||
nodes={nodes.map((node) => ({ ...node, draggable: false }))}
|
fitView
|
||||||
edges={edges}
|
nodes={nodes.map((node) => ({ ...node, draggable: false }))}
|
||||||
onNodesChange={handleNodesChange}
|
edges={edges}
|
||||||
onEdgesChange={handleEdgesChange}
|
onNodesChange={handleNodesChange}
|
||||||
>
|
onEdgesChange={handleEdgesChange}
|
||||||
<WorkflowDiagramCanvasEffect />
|
>
|
||||||
|
<WorkflowDiagramCanvasEffect />
|
||||||
|
|
||||||
<Background color={GRAY_SCALE.gray25} size={2} />
|
<Background color={GRAY_SCALE.gray25} size={2} />
|
||||||
</ReactFlow>
|
</ReactFlow>
|
||||||
|
|
||||||
|
<StyledStatusTagContainer>
|
||||||
|
<WorkflowVersionStatusTag
|
||||||
|
versionStatus={workflowWithCurrentVersion.currentVersion.status}
|
||||||
|
/>
|
||||||
|
</StyledStatusTagContainer>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
|
||||||
import { workflowDiagramState } from '@/workflow/states/workflowDiagramState';
|
import { workflowDiagramState } from '@/workflow/states/workflowDiagramState';
|
||||||
import { workflowIdState } from '@/workflow/states/workflowIdState';
|
import { workflowIdState } from '@/workflow/states/workflowIdState';
|
||||||
|
import { WorkflowWithCurrentVersion } from '@/workflow/types/Workflow';
|
||||||
import { addCreateStepNodes } from '@/workflow/utils/addCreateStepNodes';
|
import { addCreateStepNodes } from '@/workflow/utils/addCreateStepNodes';
|
||||||
import { getWorkflowVersionDiagram } from '@/workflow/utils/getWorkflowVersionDiagram';
|
import { getWorkflowVersionDiagram } from '@/workflow/utils/getWorkflowVersionDiagram';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
@ -9,11 +9,13 @@ import { isDefined } from 'twenty-ui';
|
|||||||
|
|
||||||
type WorkflowEffectProps = {
|
type WorkflowEffectProps = {
|
||||||
workflowId: string;
|
workflowId: string;
|
||||||
|
workflowWithCurrentVersion: WorkflowWithCurrentVersion | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const WorkflowEffect = ({ workflowId }: WorkflowEffectProps) => {
|
export const WorkflowEffect = ({
|
||||||
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(workflowId);
|
workflowId,
|
||||||
|
workflowWithCurrentVersion,
|
||||||
|
}: WorkflowEffectProps) => {
|
||||||
const setWorkflowId = useSetRecoilState(workflowIdState);
|
const setWorkflowId = useSetRecoilState(workflowIdState);
|
||||||
const setWorkflowDiagram = useSetRecoilState(workflowDiagramState);
|
const setWorkflowDiagram = useSetRecoilState(workflowDiagramState);
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,22 @@
|
|||||||
|
import { WorkflowVersionStatus } from '@/workflow/types/Workflow';
|
||||||
|
import { Tag } from 'twenty-ui';
|
||||||
|
|
||||||
|
export const WorkflowVersionStatusTag = ({
|
||||||
|
versionStatus,
|
||||||
|
}: {
|
||||||
|
versionStatus: WorkflowVersionStatus;
|
||||||
|
}) => {
|
||||||
|
if (versionStatus === 'ACTIVE') {
|
||||||
|
return <Tag color="green" text="Active" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (versionStatus === 'DRAFT') {
|
||||||
|
return <Tag color="yellow" text="Draft" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (versionStatus === 'ARCHIVED') {
|
||||||
|
return <Tag color="gray" text="Archived" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Tag color="gray" text="Deactivated" />;
|
||||||
|
};
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
import { Meta, StoryObj } from '@storybook/react';
|
||||||
|
import { CatalogDecorator, CatalogStory, ComponentDecorator } from 'twenty-ui';
|
||||||
|
|
||||||
|
import { WorkflowVersionStatus } from '@/workflow/types/Workflow';
|
||||||
|
import { WorkflowVersionStatusTag } from '../WorkflowVersionStatusTag';
|
||||||
|
|
||||||
|
const meta: Meta<typeof WorkflowVersionStatusTag> = {
|
||||||
|
title: 'Modules/Workflow/WorkflowVersionStatusTag',
|
||||||
|
component: WorkflowVersionStatusTag,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof WorkflowVersionStatusTag>;
|
||||||
|
|
||||||
|
export const Default: Story = {
|
||||||
|
args: {
|
||||||
|
versionStatus: 'DRAFT',
|
||||||
|
},
|
||||||
|
decorators: [ComponentDecorator],
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Catalog: CatalogStory<Story, typeof WorkflowVersionStatusTag> = {
|
||||||
|
argTypes: {
|
||||||
|
versionStatus: { table: { disable: true } },
|
||||||
|
},
|
||||||
|
parameters: {
|
||||||
|
catalog: {
|
||||||
|
dimensions: [
|
||||||
|
{
|
||||||
|
name: 'version status',
|
||||||
|
values: [
|
||||||
|
'DRAFT',
|
||||||
|
'ACTIVE',
|
||||||
|
'DEACTIVATED',
|
||||||
|
'ARCHIVED',
|
||||||
|
] satisfies WorkflowVersionStatus[],
|
||||||
|
props: (versionStatus: WorkflowVersionStatus) => ({ versionStatus }),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
decorators: [CatalogDecorator],
|
||||||
|
};
|
||||||
@ -78,5 +78,5 @@ export type Workflow = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type WorkflowWithCurrentVersion = Workflow & {
|
export type WorkflowWithCurrentVersion = Workflow & {
|
||||||
currentVersion: WorkflowVersion | undefined;
|
currentVersion: WorkflowVersion;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user