diff --git a/invokeai/frontend/web/src/features/workflowLibrary/components/SaveWorkflowAsButton.tsx b/invokeai/frontend/web/src/features/workflowLibrary/components/SaveWorkflowAsButton.tsx index a0cd3037b2..875a2e74fd 100644 --- a/invokeai/frontend/web/src/features/workflowLibrary/components/SaveWorkflowAsButton.tsx +++ b/invokeai/frontend/web/src/features/workflowLibrary/components/SaveWorkflowAsButton.tsx @@ -14,6 +14,7 @@ import { useAppSelector } from 'app/store/storeHooks'; import IAIButton from 'common/components/IAIButton'; import IAIIconButton from 'common/components/IAIIconButton'; import { useSaveWorkflowAs } from 'features/workflowLibrary/hooks/useSaveWorkflowAs'; +import { getWorkflowCopyName } from 'features/workflowLibrary/util/getWorkflowCopyName'; import { ChangeEvent, memo, useCallback, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { FaClone } from 'react-icons/fa'; @@ -22,10 +23,15 @@ const SaveWorkflowAsButton = () => { const currentName = useAppSelector((state) => state.workflow.name); const { t } = useTranslation(); const { saveWorkflowAs, isLoading } = useSaveWorkflowAs(); - const [name, setName] = useState(currentName.trim()); + const [name, setName] = useState(getWorkflowCopyName(currentName)); const { isOpen, onOpen, onClose } = useDisclosure(); const inputRef = useRef(null); + const onOpenCallback = useCallback(() => { + setName(getWorkflowCopyName(currentName)); + onOpen(); + }, [currentName, onOpen]); + const onSave = useCallback(async () => { saveWorkflowAs({ name, onSuccess: onClose, onError: onClose }); }, [name, onClose, saveWorkflowAs]); @@ -38,7 +44,7 @@ const SaveWorkflowAsButton = () => { <> } - onClick={onOpen} + onClick={onOpenCallback} isLoading={isLoading} tooltip={t('workflows.saveWorkflowAs')} aria-label={t('workflows.saveWorkflowAs')} diff --git a/invokeai/frontend/web/src/features/workflowLibrary/hooks/useSaveWorkflow.ts b/invokeai/frontend/web/src/features/workflowLibrary/hooks/useSaveWorkflow.ts index 58db407700..9867832706 100644 --- a/invokeai/frontend/web/src/features/workflowLibrary/hooks/useSaveWorkflow.ts +++ b/invokeai/frontend/web/src/features/workflowLibrary/hooks/useSaveWorkflow.ts @@ -3,6 +3,7 @@ import { useAppDispatch } from 'app/store/storeHooks'; import { useWorkflow } from 'features/nodes/hooks/useWorkflow'; import { workflowLoaded } from 'features/nodes/store/workflowSlice'; import { zWorkflowV2 } from 'features/nodes/types/workflow'; +import { getWorkflowCopyName } from 'features/workflowLibrary/util/getWorkflowCopyName'; import { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { @@ -38,6 +39,7 @@ export const useSaveLibraryWorkflow: UseSaveLibraryWorkflow = () => { } else { const data = await createWorkflow(workflow).unwrap(); const createdWorkflow = zWorkflowV2.parse(data.workflow); + createdWorkflow.name = getWorkflowCopyName(createdWorkflow.name); dispatch(workflowLoaded(createdWorkflow)); toaster({ title: t('workflows.workflowSaved'), diff --git a/invokeai/frontend/web/src/features/workflowLibrary/util/getWorkflowCopyName.ts b/invokeai/frontend/web/src/features/workflowLibrary/util/getWorkflowCopyName.ts new file mode 100644 index 0000000000..b5d990bb49 --- /dev/null +++ b/invokeai/frontend/web/src/features/workflowLibrary/util/getWorkflowCopyName.ts @@ -0,0 +1,2 @@ +export const getWorkflowCopyName = (name: string): string => + `${name.trim()} (copy)`;