chore: remove redundant duplicate flow mutation
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import duplicateFlow from './mutations/duplicate-flow.js';
|
|
||||||
import updateFlowStatus from './mutations/update-flow-status.js';
|
import updateFlowStatus from './mutations/update-flow-status.js';
|
||||||
import updateStep from './mutations/update-step.js';
|
import updateStep from './mutations/update-step.js';
|
||||||
|
|
||||||
@@ -24,7 +23,6 @@ const mutationResolvers = {
|
|||||||
deleteCurrentUser,
|
deleteCurrentUser,
|
||||||
deleteFlow,
|
deleteFlow,
|
||||||
deleteStep,
|
deleteStep,
|
||||||
duplicateFlow,
|
|
||||||
executeFlow,
|
executeFlow,
|
||||||
generateAuthUrl,
|
generateAuthUrl,
|
||||||
resetConnection,
|
resetConnection,
|
||||||
|
@@ -1,78 +0,0 @@
|
|||||||
function updateStepId(value, newStepIds) {
|
|
||||||
let newValue = value;
|
|
||||||
|
|
||||||
const stepIdEntries = Object.entries(newStepIds);
|
|
||||||
for (const stepIdEntry of stepIdEntries) {
|
|
||||||
const [oldStepId, newStepId] = stepIdEntry;
|
|
||||||
const partialOldVariable = `{{step.${oldStepId}.`;
|
|
||||||
const partialNewVariable = `{{step.${newStepId}.`;
|
|
||||||
|
|
||||||
newValue = newValue.replace(partialOldVariable, partialNewVariable);
|
|
||||||
}
|
|
||||||
|
|
||||||
return newValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateStepVariables(parameters, newStepIds) {
|
|
||||||
const entries = Object.entries(parameters);
|
|
||||||
return entries.reduce((result, [key, value]) => {
|
|
||||||
if (typeof value === 'string') {
|
|
||||||
return {
|
|
||||||
...result,
|
|
||||||
[key]: updateStepId(value, newStepIds),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Array.isArray(value)) {
|
|
||||||
return {
|
|
||||||
...result,
|
|
||||||
[key]: value.map((item) => updateStepVariables(item, newStepIds)),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...result,
|
|
||||||
[key]: value,
|
|
||||||
};
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
const duplicateFlow = async (_parent, params, context) => {
|
|
||||||
context.currentUser.can('create', 'Flow');
|
|
||||||
|
|
||||||
const flow = await context.currentUser
|
|
||||||
.authorizedFlows
|
|
||||||
.withGraphJoined('[steps]')
|
|
||||||
.orderBy('steps.position', 'asc')
|
|
||||||
.findOne({ 'flows.id': params.input.id })
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
const duplicatedFlow = await context.currentUser
|
|
||||||
.$relatedQuery('flows')
|
|
||||||
.insert({
|
|
||||||
name: `Copy of ${flow.name}`,
|
|
||||||
active: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
const newStepIds = {};
|
|
||||||
for (const step of flow.steps) {
|
|
||||||
const duplicatedStep = await duplicatedFlow.$relatedQuery('steps').insert({
|
|
||||||
key: step.key,
|
|
||||||
appKey: step.appKey,
|
|
||||||
type: step.type,
|
|
||||||
connectionId: step.connectionId,
|
|
||||||
position: step.position,
|
|
||||||
parameters: updateStepVariables(step.parameters, newStepIds),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (duplicatedStep.isTrigger) {
|
|
||||||
await duplicatedStep.updateWebhookUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
newStepIds[step.id] = duplicatedStep.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return duplicatedFlow;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default duplicateFlow;
|
|
@@ -8,7 +8,6 @@ type Mutation {
|
|||||||
deleteCurrentUser: Boolean
|
deleteCurrentUser: Boolean
|
||||||
deleteFlow(input: DeleteFlowInput): Boolean
|
deleteFlow(input: DeleteFlowInput): Boolean
|
||||||
deleteStep(input: DeleteStepInput): Step
|
deleteStep(input: DeleteStepInput): Step
|
||||||
duplicateFlow(input: DuplicateFlowInput): Flow
|
|
||||||
executeFlow(input: ExecuteFlowInput): executeFlowType
|
executeFlow(input: ExecuteFlowInput): executeFlowType
|
||||||
generateAuthUrl(input: GenerateAuthUrlInput): AuthLink
|
generateAuthUrl(input: GenerateAuthUrlInput): AuthLink
|
||||||
resetConnection(input: ResetConnectionInput): Connection
|
resetConnection(input: ResetConnectionInput): Connection
|
||||||
@@ -259,10 +258,6 @@ input DeleteFlowInput {
|
|||||||
id: String!
|
id: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
input DuplicateFlowInput {
|
|
||||||
id: String!
|
|
||||||
}
|
|
||||||
|
|
||||||
input UpdateStepInput {
|
input UpdateStepInput {
|
||||||
id: String
|
id: String
|
||||||
previousStepId: String
|
previousStepId: String
|
||||||
|
@@ -11,7 +11,6 @@ import { Link } from 'react-router-dom';
|
|||||||
import Can from 'components/Can';
|
import Can from 'components/Can';
|
||||||
import * as URLS from 'config/urls';
|
import * as URLS from 'config/urls';
|
||||||
import { DELETE_FLOW } from 'graphql/mutations/delete-flow';
|
import { DELETE_FLOW } from 'graphql/mutations/delete-flow';
|
||||||
import { DUPLICATE_FLOW } from 'graphql/mutations/duplicate-flow';
|
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
import useDuplicateFlow from 'hooks/useDuplicateFlow';
|
import useDuplicateFlow from 'hooks/useDuplicateFlow';
|
||||||
|
|
||||||
|
@@ -1,27 +0,0 @@
|
|||||||
import { gql } from '@apollo/client';
|
|
||||||
export const DUPLICATE_FLOW = gql`
|
|
||||||
mutation DuplicateFlow($input: DuplicateFlowInput) {
|
|
||||||
duplicateFlow(input: $input) {
|
|
||||||
id
|
|
||||||
name
|
|
||||||
active
|
|
||||||
status
|
|
||||||
steps {
|
|
||||||
id
|
|
||||||
type
|
|
||||||
key
|
|
||||||
appKey
|
|
||||||
iconUrl
|
|
||||||
webhookUrl
|
|
||||||
status
|
|
||||||
position
|
|
||||||
connection {
|
|
||||||
id
|
|
||||||
verified
|
|
||||||
createdAt
|
|
||||||
}
|
|
||||||
parameters
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
Reference in New Issue
Block a user