Skip to content

Commit

Permalink
Fix use as draft (#9718)
Browse files Browse the repository at this point in the history
- remove delete serverless function when archiving workflow version
- update copy serverless function to reset serverless function to old
version
- remove createNewWorkflowVersion and use createDraftFromWorkflowVersion
- fix step update issue and optimistic rendering when generate draft
from active version
  • Loading branch information
martmull authored Jan 21, 2025
1 parent d8815d7 commit ed7c48e
Show file tree
Hide file tree
Showing 22 changed files with 207 additions and 309 deletions.
7 changes: 6 additions & 1 deletion packages/twenty-front/src/generated-metadata/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ export type Mutation = {
challenge: LoginToken;
checkoutSession: SessionEntity;
computeStepOutputSchema: Scalars['JSON']['output'];
createDraftFromWorkflowVersion: Scalars['Boolean']['output'];
createDraftFromWorkflowVersion: WorkflowVersion;
createOIDCIdentityProvider: SetupSsoOutput;
createOneAppToken: AppToken;
createOneField: Field;
Expand Down Expand Up @@ -1711,6 +1711,11 @@ export type WorkflowRun = {
workflowRunId: Scalars['UUID']['output'];
};

export type WorkflowVersion = {
__typename?: 'WorkflowVersion';
workflowVersionId: Scalars['UUID']['output'];
};

export type Workspace = {
__typename?: 'Workspace';
activationStatus: WorkspaceActivationStatus;
Expand Down
85 changes: 46 additions & 39 deletions packages/twenty-front/src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ export type Mutation = {
challenge: LoginToken;
checkoutSession: SessionEntity;
computeStepOutputSchema: Scalars['JSON'];
createDraftFromWorkflowVersion: Scalars['Boolean'];
createDraftFromWorkflowVersion: WorkflowVersion;
createOIDCIdentityProvider: SetupSsoOutput;
createOneAppToken: AppToken;
createOneField: Field;
Expand Down Expand Up @@ -1508,6 +1508,11 @@ export type WorkflowRun = {
workflowRunId: Scalars['UUID'];
};

export type WorkflowVersion = {
__typename?: 'WorkflowVersion';
id: Scalars['UUID'];
};

export type Workspace = {
__typename?: 'Workspace';
activationStatus: WorkspaceActivationStatus;
Expand Down Expand Up @@ -2131,6 +2136,13 @@ export type ComputeStepOutputSchemaMutationVariables = Exact<{

export type ComputeStepOutputSchemaMutation = { __typename?: 'Mutation', computeStepOutputSchema: any };

export type CreateDraftFromWorkflowVersionMutationVariables = Exact<{
input: CreateDraftFromWorkflowVersionInput;
}>;


export type CreateDraftFromWorkflowVersionMutation = { __typename?: 'Mutation', createDraftFromWorkflowVersion: { __typename?: 'WorkflowVersion', id: any } };

export type CreateWorkflowVersionStepMutationVariables = Exact<{
input: CreateWorkflowVersionStepInput;
}>;
Expand All @@ -2152,13 +2164,6 @@ export type DeleteWorkflowVersionStepMutationVariables = Exact<{

export type DeleteWorkflowVersionStepMutation = { __typename?: 'Mutation', deleteWorkflowVersionStep: { __typename?: 'WorkflowAction', id: any, name: string, type: string, settings: any, valid: boolean } };

export type CreateDraftFromWorkflowVersionMutationVariables = Exact<{
input: CreateDraftFromWorkflowVersionInput;
}>;


export type CreateDraftFromWorkflowVersionMutation = { __typename?: 'Mutation', createDraftFromWorkflowVersion: boolean };

export type RunWorkflowVersionMutationVariables = Exact<{
input: RunWorkflowVersionInput;
}>;
Expand Down Expand Up @@ -4092,6 +4097,39 @@ export function useComputeStepOutputSchemaMutation(baseOptions?: Apollo.Mutation
export type ComputeStepOutputSchemaMutationHookResult = ReturnType<typeof useComputeStepOutputSchemaMutation>;
export type ComputeStepOutputSchemaMutationResult = Apollo.MutationResult<ComputeStepOutputSchemaMutation>;
export type ComputeStepOutputSchemaMutationOptions = Apollo.BaseMutationOptions<ComputeStepOutputSchemaMutation, ComputeStepOutputSchemaMutationVariables>;
export const CreateDraftFromWorkflowVersionDocument = gql`
mutation CreateDraftFromWorkflowVersion($input: CreateDraftFromWorkflowVersionInput!) {
createDraftFromWorkflowVersion(input: $input) {
id
}
}
`;
export type CreateDraftFromWorkflowVersionMutationFn = Apollo.MutationFunction<CreateDraftFromWorkflowVersionMutation, CreateDraftFromWorkflowVersionMutationVariables>;

/**
* __useCreateDraftFromWorkflowVersionMutation__
*
* To run a mutation, you first call `useCreateDraftFromWorkflowVersionMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useCreateDraftFromWorkflowVersionMutation` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [createDraftFromWorkflowVersionMutation, { data, loading, error }] = useCreateDraftFromWorkflowVersionMutation({
* variables: {
* input: // value for 'input'
* },
* });
*/
export function useCreateDraftFromWorkflowVersionMutation(baseOptions?: Apollo.MutationHookOptions<CreateDraftFromWorkflowVersionMutation, CreateDraftFromWorkflowVersionMutationVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useMutation<CreateDraftFromWorkflowVersionMutation, CreateDraftFromWorkflowVersionMutationVariables>(CreateDraftFromWorkflowVersionDocument, options);
}
export type CreateDraftFromWorkflowVersionMutationHookResult = ReturnType<typeof useCreateDraftFromWorkflowVersionMutation>;
export type CreateDraftFromWorkflowVersionMutationResult = Apollo.MutationResult<CreateDraftFromWorkflowVersionMutation>;
export type CreateDraftFromWorkflowVersionMutationOptions = Apollo.BaseMutationOptions<CreateDraftFromWorkflowVersionMutation, CreateDraftFromWorkflowVersionMutationVariables>;
export const CreateWorkflowVersionStepDocument = gql`
mutation CreateWorkflowVersionStep($input: CreateWorkflowVersionStepInput!) {
createWorkflowVersionStep(input: $input) {
Expand Down Expand Up @@ -4197,37 +4235,6 @@ export function useDeleteWorkflowVersionStepMutation(baseOptions?: Apollo.Mutati
export type DeleteWorkflowVersionStepMutationHookResult = ReturnType<typeof useDeleteWorkflowVersionStepMutation>;
export type DeleteWorkflowVersionStepMutationResult = Apollo.MutationResult<DeleteWorkflowVersionStepMutation>;
export type DeleteWorkflowVersionStepMutationOptions = Apollo.BaseMutationOptions<DeleteWorkflowVersionStepMutation, DeleteWorkflowVersionStepMutationVariables>;
export const CreateDraftFromWorkflowVersionDocument = gql`
mutation CreateDraftFromWorkflowVersion($input: CreateDraftFromWorkflowVersionInput!) {
createDraftFromWorkflowVersion(input: $input)
}
`;
export type CreateDraftFromWorkflowVersionMutationFn = Apollo.MutationFunction<CreateDraftFromWorkflowVersionMutation, CreateDraftFromWorkflowVersionMutationVariables>;

/**
* __useCreateDraftFromWorkflowVersionMutation__
*
* To run a mutation, you first call `useCreateDraftFromWorkflowVersionMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useCreateDraftFromWorkflowVersionMutation` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [createDraftFromWorkflowVersionMutation, { data, loading, error }] = useCreateDraftFromWorkflowVersionMutation({
* variables: {
* input: // value for 'input'
* },
* });
*/
export function useCreateDraftFromWorkflowVersionMutation(baseOptions?: Apollo.MutationHookOptions<CreateDraftFromWorkflowVersionMutation, CreateDraftFromWorkflowVersionMutationVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useMutation<CreateDraftFromWorkflowVersionMutation, CreateDraftFromWorkflowVersionMutationVariables>(CreateDraftFromWorkflowVersionDocument, options);
}
export type CreateDraftFromWorkflowVersionMutationHookResult = ReturnType<typeof useCreateDraftFromWorkflowVersionMutation>;
export type CreateDraftFromWorkflowVersionMutationResult = Apollo.MutationResult<CreateDraftFromWorkflowVersionMutation>;
export type CreateDraftFromWorkflowVersionMutationOptions = Apollo.BaseMutationOptions<CreateDraftFromWorkflowVersionMutation, CreateDraftFromWorkflowVersionMutationVariables>;
export const RunWorkflowVersionDocument = gql`
mutation RunWorkflowVersion($input: RunWorkflowVersionInput!) {
runWorkflowVersion(input: $input) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { gql } from '@apollo/client';

export const OVERRIDE_WORKFLOW_DRAFT_VERSION = gql`
export const CREATE_DRAFT_FROM_WORKFLOW_VERSION = gql`
mutation CreateDraftFromWorkflowVersion(
$input: CreateDraftFromWorkflowVersionInput!
) {
createDraftFromWorkflowVersion(input: $input)
createDraftFromWorkflowVersion(input: $input) {
id
}
}
`;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@ import { renderHook } from '@testing-library/react';
import { useGetUpdatableWorkflowVersion } from '@/workflow/hooks/useGetUpdatableWorkflowVersion';
import { WorkflowWithCurrentVersion } from '@/workflow/types/Workflow';

const mockCreateNewWorkflowVersion = jest.fn().mockResolvedValue({
id: '457',
name: 'toto',
createdAt: '2024-07-03T20:03:35.064Z',
updatedAt: '2024-07-03T20:03:35.064Z',
workflowId: '123',
__typename: 'WorkflowVersion',
status: 'DRAFT',
steps: [],
trigger: null,
});
const mockCreateDraftFromWorkflowVersion = jest.fn().mockResolvedValue('457');

jest.mock('@/workflow/hooks/useCreateNewWorkflowVersion', () => ({
useCreateNewWorkflowVersion: () => ({
createNewWorkflowVersion: mockCreateNewWorkflowVersion,
jest.mock('@/workflow/hooks/useCreateDraftFromWorkflowVersion', () => ({
useCreateDraftFromWorkflowVersion: () => ({
createDraftFromWorkflowVersion: mockCreateDraftFromWorkflowVersion,
}),
}));

Expand Down Expand Up @@ -44,19 +34,19 @@ describe('useGetUpdatableWorkflowVersion', () => {

it('should not create workflow version if draft version exists', async () => {
const { result } = renderHook(() => useGetUpdatableWorkflowVersion());
const workflowVersion = await result.current.getUpdatableWorkflowVersion(
const workflowVersionId = await result.current.getUpdatableWorkflowVersion(
mockWorkflow('DRAFT'),
);
expect(mockCreateNewWorkflowVersion).not.toHaveBeenCalled();
expect(workflowVersion.id === '456');
expect(mockCreateDraftFromWorkflowVersion).not.toHaveBeenCalled();
expect(workflowVersionId).toEqual('456');
});

it('should create workflow version if no draft version exists', async () => {
const { result } = renderHook(() => useGetUpdatableWorkflowVersion());
const workflowVersion = await result.current.getUpdatableWorkflowVersion(
const workflowVersionId = await result.current.getUpdatableWorkflowVersion(
mockWorkflow('ACTIVE'),
);
expect(mockCreateNewWorkflowVersion).toHaveBeenCalled();
expect(workflowVersion.id === '457');
expect(mockCreateDraftFromWorkflowVersion).toHaveBeenCalled();
expect(workflowVersionId).toEqual('457');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const useCreateDraftFromWorkflowVersion = () => {
const createDraftFromWorkflowVersion = async (
input: CreateDraftFromWorkflowVersionInput,
) => {
await mutate({
const result = await mutate({
variables: { input },
awaitRefetchQueries: true,
refetchQueries: [
Expand All @@ -40,6 +40,8 @@ export const useCreateDraftFromWorkflowVersion = () => {
},
],
});

return result?.data?.createDraftFromWorkflowVersion.id;
};

return {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { WorkflowWithCurrentVersion } from '@/workflow/types/Workflow';
import { useCreateNewWorkflowVersion } from '@/workflow/hooks/useCreateNewWorkflowVersion';
import { useCreateDraftFromWorkflowVersion } from '@/workflow/hooks/useCreateDraftFromWorkflowVersion';

export const useGetUpdatableWorkflowVersion = () => {
const { createNewWorkflowVersion } = useCreateNewWorkflowVersion();
const { createDraftFromWorkflowVersion } =
useCreateDraftFromWorkflowVersion();
const getUpdatableWorkflowVersion = async (
workflow: WorkflowWithCurrentVersion,
) => {
if (workflow.currentVersion.status === 'DRAFT') {
return workflow.currentVersion;
return workflow.currentVersion.id;
}

return await createNewWorkflowVersion({
return await createDraftFromWorkflowVersion({
workflowId: workflow.id,
name: `v${workflow.versions.length + 1}`,
status: 'DRAFT',
trigger: workflow.currentVersion.trigger,
steps: workflow.currentVersion.steps,
workflowVersionIdToCopy: workflow.currentVersion.id,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { renderHook } from '@testing-library/react';
import { useCreateStep } from '../useCreateStep';

const mockOpenRightDrawer = jest.fn();
const mockCreateNewWorkflowVersion = jest.fn();
const mockCreateDraftFromWorkflowVersion = jest.fn().mockResolvedValue('457');
const mockCreateWorkflowVersionStep = jest.fn().mockResolvedValue({
data: { createWorkflowVersionStep: { id: '1' } },
});
Expand All @@ -29,9 +29,9 @@ jest.mock(
}),
);

jest.mock('@/workflow/hooks/useCreateNewWorkflowVersion', () => ({
useCreateNewWorkflowVersion: () => ({
createNewWorkflowVersion: mockCreateNewWorkflowVersion,
jest.mock('@/workflow/hooks/useCreateDraftFromWorkflowVersion', () => ({
useCreateDraftFromWorkflowVersion: () => ({
createDraftFromWorkflowVersion: mockCreateDraftFromWorkflowVersion,
}),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { renderHook } from '@testing-library/react';
import { RecoilRoot } from 'recoil';

const mockCloseRightDrawer = jest.fn();
const mockCreateNewWorkflowVersion = jest.fn();
const mockDeleteWorkflowVersionStep = jest.fn();
const updateOneRecordMock = jest.fn();
const mockCreateDraftFromWorkflowVersion = jest.fn().mockResolvedValue('457');

jest.mock('@/object-record/hooks/useUpdateOneRecord', () => ({
useUpdateOneRecord: () => ({
Expand All @@ -26,9 +26,9 @@ jest.mock('@/workflow/hooks/useDeleteWorkflowVersionStep', () => ({
}),
}));

jest.mock('@/workflow/hooks/useCreateNewWorkflowVersion', () => ({
useCreateNewWorkflowVersion: () => ({
createNewWorkflowVersion: mockCreateNewWorkflowVersion,
jest.mock('@/workflow/hooks/useCreateDraftFromWorkflowVersion', () => ({
useCreateDraftFromWorkflowVersion: () => ({
createDraftFromWorkflowVersion: mockCreateDraftFromWorkflowVersion,
}),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { WorkflowWithCurrentVersion } from '@/workflow/types/Workflow';
import { useUpdateStep } from '@/workflow/workflow-steps/hooks/useUpdateStep';
import { renderHook } from '@testing-library/react';

const mockCreateNewWorkflowVersion = jest.fn();
const mockUpdateWorkflowVersionStep = jest.fn();
const mockCreateDraftFromWorkflowVersion = jest.fn().mockResolvedValue('457');

jest.mock('recoil', () => ({
useRecoilValue: () => 'parent-step-id',
Expand All @@ -20,9 +20,9 @@ jest.mock(
}),
);

jest.mock('@/workflow/hooks/useCreateNewWorkflowVersion', () => ({
useCreateNewWorkflowVersion: () => ({
createNewWorkflowVersion: mockCreateNewWorkflowVersion,
jest.mock('@/workflow/hooks/useCreateDraftFromWorkflowVersion', () => ({
useCreateDraftFromWorkflowVersion: () => ({
createDraftFromWorkflowVersion: mockCreateDraftFromWorkflowVersion,
}),
}));

Expand Down
Loading

0 comments on commit ed7c48e

Please sign in to comment.