8191 command k workflow trigger for selected record (#8315)

Closes #8191 


https://github.com/user-attachments/assets/694da229-cc91-4df2-97a0-49cd5dabcf12
This commit is contained in:
Raphaël Bosi
2024-11-05 13:37:29 +01:00
committed by GitHub
parent 0893774cc1
commit d1531aa1b6
44 changed files with 543 additions and 209 deletions

View File

@ -0,0 +1,9 @@
import { gql } from '@apollo/client';
export const RUN_WORKFLOW_VERSION = gql`
mutation RunWorkflowVersion($input: RunWorkflowVersionInput!) {
runWorkflowVersion(input: $input) {
workflowRunId
}
}
`;

View File

@ -1,5 +1,5 @@
import { useApolloMetadataClient } from '@/object-metadata/hooks/useApolloMetadataClient';
import { ApolloClient, useApolloClient, useMutation } from '@apollo/client';
import { useApolloClient, useMutation } from '@apollo/client';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
@ -18,7 +18,7 @@ export const useActivateWorkflowVersion = () => {
ActivateWorkflowVersionMutation,
ActivateWorkflowVersionMutationVariables
>(ACTIVATE_WORKFLOW_VERSION, {
client: apolloMetadataClient ?? ({} as ApolloClient<any>),
client: apolloMetadataClient,
});
const { objectMetadataItem: objectMetadataItemWorkflowVersion } =

View File

@ -0,0 +1,52 @@
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { generateDepthOneRecordGqlFields } from '@/object-record/graphql/utils/generateDepthOneRecordGqlFields';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import {
Workflow,
WorkflowTriggerType,
WorkflowVersion,
} from '@/workflow/types/Workflow';
export const useAllActiveWorkflowVersionsForObject = ({
objectNameSingular,
triggerType,
}: {
objectNameSingular: string;
triggerType: WorkflowTriggerType;
}) => {
const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular,
});
const { records } = useFindManyRecords<
WorkflowVersion & { workflow: Workflow }
>({
objectNameSingular: CoreObjectNameSingular.WorkflowVersion,
filter: {
and: [
{
status: {
eq: 'ACTIVE',
},
},
{
trigger: {
like: `%"type": "${triggerType}"%`,
},
},
{
trigger: {
like: `%"objectType": "${objectNameSingular}"%`,
},
},
],
},
recordGqlFields: {
...generateDepthOneRecordGqlFields({ objectMetadataItem }),
workflow: true,
},
});
return { records };
};

View File

@ -1,11 +1,11 @@
import { useApolloMetadataClient } from '@/object-metadata/hooks/useApolloMetadataClient';
import { ApolloClient, useMutation } from '@apollo/client';
import { COMPUTE_STEP_OUTPUT_SCHEMA } from '@/workflow/graphql/mutations/computeStepOutputSchema';
import { useMutation } from '@apollo/client';
import {
ComputeStepOutputSchemaInput,
ComputeStepOutputSchemaMutation,
ComputeStepOutputSchemaMutationVariables,
} from '~/generated/graphql';
import { COMPUTE_STEP_OUTPUT_SCHEMA } from '@/workflow/graphql/mutations/computeStepOutputSchema';
export const useComputeStepOutputSchema = () => {
const apolloMetadataClient = useApolloMetadataClient();
@ -13,7 +13,7 @@ export const useComputeStepOutputSchema = () => {
ComputeStepOutputSchemaMutation,
ComputeStepOutputSchemaMutationVariables
>(COMPUTE_STEP_OUTPUT_SCHEMA, {
client: apolloMetadataClient ?? ({} as ApolloClient<any>),
client: apolloMetadataClient,
});
const computeStepOutputSchema = async (

View File

@ -1,5 +1,5 @@
import { useApolloMetadataClient } from '@/object-metadata/hooks/useApolloMetadataClient';
import { ApolloClient, useApolloClient, useMutation } from '@apollo/client';
import { useApolloClient, useMutation } from '@apollo/client';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
@ -17,7 +17,7 @@ export const useDeactivateWorkflowVersion = () => {
ActivateWorkflowVersionMutation,
ActivateWorkflowVersionMutationVariables
>(DEACTIVATE_WORKFLOW_VERSION, {
client: apolloMetadataClient ?? ({} as ApolloClient<any>),
client: apolloMetadataClient,
});
const { objectMetadataItem: objectMetadataItemWorkflowVersion } =

View File

@ -0,0 +1,28 @@
import { useApolloMetadataClient } from '@/object-metadata/hooks/useApolloMetadataClient';
import { RUN_WORKFLOW_VERSION } from '@/workflow/graphql/mutations/runWorkflowVersion';
import { useMutation } from '@apollo/client';
import {
RunWorkflowVersionMutation,
RunWorkflowVersionMutationVariables,
} from '~/generated/graphql';
export const useRunWorkflowVersion = () => {
const apolloMetadataClient = useApolloMetadataClient();
const [mutate] = useMutation<
RunWorkflowVersionMutation,
RunWorkflowVersionMutationVariables
>(RUN_WORKFLOW_VERSION, {
client: apolloMetadataClient,
});
const runWorkflowVersion = async (
workflowVersionId: string,
payload: Record<string, any>,
) => {
await mutate({
variables: { input: { workflowVersionId, payload } },
});
};
return { runWorkflowVersion };
};