Open the executed workflow run in the side panel (#12284)

> [!WARNING]
> This PR introduces a new way to interact with workflow runs. It comes
with a few known flaws that will be solved in a second time.

## Launching a Test


https://github.com/user-attachments/assets/89b0eb63-d276-4ac5-a5d8-665d0084e0c5

## Triggering a workflow with a manual trigger


https://github.com/user-attachments/assets/047975d4-a24d-4cf0-b617-525965e3bfd8

Closes https://github.com/twentyhq/core-team-issues/issues/812
This commit is contained in:
Baptiste Devessier
2025-05-27 11:34:02 +02:00
committed by GitHub
parent a83279ddce
commit 7b5d6a2ffc

View File

@ -1,14 +1,13 @@
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import { useOpenRecordInCommandMenu } from '@/command-menu/hooks/useOpenRecordInCommandMenu';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { useLazyFindOneRecord } from '@/object-record/hooks/useLazyFindOneRecord';
import { RUN_WORKFLOW_VERSION } from '@/workflow/graphql/mutations/runWorkflowVersion';
import { WorkflowRun } from '@/workflow/types/Workflow';
import { useApolloClient, useMutation } from '@apollo/client';
import { useTheme } from '@emotion/react';
import { useLingui } from '@lingui/react/macro';
import {
RunWorkflowVersionMutation,
RunWorkflowVersionMutationVariables,
} from '~/generated/graphql';
import { IconSettingsAutomation } from 'twenty-ui/display';
export const useRunWorkflowVersion = () => {
const apolloClient = useApolloClient();
@ -19,10 +18,12 @@ export const useRunWorkflowVersion = () => {
client: apolloClient,
});
const { enqueueSnackBar } = useSnackBar();
const { findOneRecord: findOneWorkflowRun } =
useLazyFindOneRecord<WorkflowRun>({
objectNameSingular: CoreObjectNameSingular.WorkflowRun,
});
const theme = useTheme();
const { t } = useLingui();
const { openRecordInCommandMenu } = useOpenRecordInCommandMenu();
const runWorkflowVersion = async ({
workflowVersionId,
@ -37,26 +38,13 @@ export const useRunWorkflowVersion = () => {
const workflowRunId = data?.runWorkflowVersion?.workflowRunId;
if (!workflowRunId) {
enqueueSnackBar(t`Workflow run failed`, {
variant: SnackBarVariant.Error,
});
return;
}
const link = `/object/workflowRun/${workflowRunId}`;
enqueueSnackBar(t`Workflow is running...`, {
variant: SnackBarVariant.Success,
icon: (
<IconSettingsAutomation
size={16}
color={theme.snackBar.success.color}
/>
),
link: {
href: link,
text: t`View execution details`,
await findOneWorkflowRun({
objectRecordId: workflowRunId,
onCompleted: (workflowRun) => {
openRecordInCommandMenu({
objectNameSingular: CoreObjectNameSingular.WorkflowRun,
recordId: workflowRun.id,
});
},
});
};