import { getNewWorkflow , getWorkflowTemplate } from '@/api/workflows' ; import { DUPLICATE_POSTFFIX , MAX_WORKFLOW_NAME_LENGTH , DEFAULT_NEW_WORKFLOW_NAME } from '@/constants' ; import { ActionContext , Module } from 'vuex' ; import { IRootState , IWorkflowsState , IWorkflowTemplate , } from '../Interface' ; const module = { namespaced : true , state : { } , actions : { setNewWorkflowName : async ( context , name ? ) : Promise < void > => { let newName = '' ; try { const newWorkflow = await getNewWorkflow ( context . rootGetters . getRestApiContext , name ) ; newName = newWorkflow . name ; } catch ( e ) { newName = name || DEFAULT_NEW_WORKFLOW_NAME ; } context . commit ( 'setWorkflowName' , { newName } , { root : true } ) ; } , getDuplicateCurrentWorkflowName : async ( context ) : Promise < string > => { const currentWorkflowName = context . rootGetters . workflowName ; if ( currentWorkflowName && ( currentWorkflowName . length + DUPLICATE_POSTFFIX . length ) >= MAX_WORKFLOW_NAME_LENGTH ) { return currentWorkflowName ; } let newName = `${ currentWorkflowName }${ DUPLICATE_POSTFFIX }` ; try { const newWorkflow = await getNewWorkflow ( context . rootGetters . getRestApiContext , newName ) ; newName = newWorkflow . name ; } catch ( e ) { } return newName ; } , getWorkflowTemplate : async ( context , templateId ) : Promise < IWorkflowTemplate > => { return await getWorkflowTemplate ( templateId ) ; } , } , } ; export default module ;