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 { useOpenRecordInCommandMenu } from '@/command-menu/hooks/useOpenRecordInCommandMenu';
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { useLazyFindOneRecord } from '@/object-record/hooks/useLazyFindOneRecord';
import { RUN_WORKFLOW_VERSION } from '@/workflow/graphql/mutations/runWorkflowVersion'; import { RUN_WORKFLOW_VERSION } from '@/workflow/graphql/mutations/runWorkflowVersion';
import { WorkflowRun } from '@/workflow/types/Workflow';
import { useApolloClient, useMutation } from '@apollo/client'; import { useApolloClient, useMutation } from '@apollo/client';
import { useTheme } from '@emotion/react';
import { useLingui } from '@lingui/react/macro';
import { import {
RunWorkflowVersionMutation, RunWorkflowVersionMutation,
RunWorkflowVersionMutationVariables, RunWorkflowVersionMutationVariables,
} from '~/generated/graphql'; } from '~/generated/graphql';
import { IconSettingsAutomation } from 'twenty-ui/display';
export const useRunWorkflowVersion = () => { export const useRunWorkflowVersion = () => {
const apolloClient = useApolloClient(); const apolloClient = useApolloClient();
@ -19,10 +18,12 @@ export const useRunWorkflowVersion = () => {
client: apolloClient, client: apolloClient,
}); });
const { enqueueSnackBar } = useSnackBar(); const { findOneRecord: findOneWorkflowRun } =
useLazyFindOneRecord<WorkflowRun>({
objectNameSingular: CoreObjectNameSingular.WorkflowRun,
});
const theme = useTheme(); const { openRecordInCommandMenu } = useOpenRecordInCommandMenu();
const { t } = useLingui();
const runWorkflowVersion = async ({ const runWorkflowVersion = async ({
workflowVersionId, workflowVersionId,
@ -37,26 +38,13 @@ export const useRunWorkflowVersion = () => {
const workflowRunId = data?.runWorkflowVersion?.workflowRunId; const workflowRunId = data?.runWorkflowVersion?.workflowRunId;
if (!workflowRunId) { await findOneWorkflowRun({
enqueueSnackBar(t`Workflow run failed`, { objectRecordId: workflowRunId,
variant: SnackBarVariant.Error, onCompleted: (workflowRun) => {
}); openRecordInCommandMenu({
return; objectNameSingular: CoreObjectNameSingular.WorkflowRun,
} recordId: workflowRun.id,
});
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`,
}, },
}); });
}; };