mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): fix save/save-as workflow naming
This commit is contained in:
parent
3863bd9da3
commit
37c87affd0
@ -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<HTMLInputElement>(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 = () => {
|
||||
<>
|
||||
<IAIIconButton
|
||||
icon={<FaClone />}
|
||||
onClick={onOpen}
|
||||
onClick={onOpenCallback}
|
||||
isLoading={isLoading}
|
||||
tooltip={t('workflows.saveWorkflowAs')}
|
||||
aria-label={t('workflows.saveWorkflowAs')}
|
||||
|
@ -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'),
|
||||
|
@ -0,0 +1,2 @@
|
||||
export const getWorkflowCopyName = (name: string): string =>
|
||||
`${name.trim()} (copy)`;
|
Loading…
Reference in New Issue
Block a user