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 IAIButton from 'common/components/IAIButton';
|
||||||
import IAIIconButton from 'common/components/IAIIconButton';
|
import IAIIconButton from 'common/components/IAIIconButton';
|
||||||
import { useSaveWorkflowAs } from 'features/workflowLibrary/hooks/useSaveWorkflowAs';
|
import { useSaveWorkflowAs } from 'features/workflowLibrary/hooks/useSaveWorkflowAs';
|
||||||
|
import { getWorkflowCopyName } from 'features/workflowLibrary/util/getWorkflowCopyName';
|
||||||
import { ChangeEvent, memo, useCallback, useRef, useState } from 'react';
|
import { ChangeEvent, memo, useCallback, useRef, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { FaClone } from 'react-icons/fa';
|
import { FaClone } from 'react-icons/fa';
|
||||||
@ -22,10 +23,15 @@ const SaveWorkflowAsButton = () => {
|
|||||||
const currentName = useAppSelector((state) => state.workflow.name);
|
const currentName = useAppSelector((state) => state.workflow.name);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { saveWorkflowAs, isLoading } = useSaveWorkflowAs();
|
const { saveWorkflowAs, isLoading } = useSaveWorkflowAs();
|
||||||
const [name, setName] = useState(currentName.trim());
|
const [name, setName] = useState(getWorkflowCopyName(currentName));
|
||||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
|
const onOpenCallback = useCallback(() => {
|
||||||
|
setName(getWorkflowCopyName(currentName));
|
||||||
|
onOpen();
|
||||||
|
}, [currentName, onOpen]);
|
||||||
|
|
||||||
const onSave = useCallback(async () => {
|
const onSave = useCallback(async () => {
|
||||||
saveWorkflowAs({ name, onSuccess: onClose, onError: onClose });
|
saveWorkflowAs({ name, onSuccess: onClose, onError: onClose });
|
||||||
}, [name, onClose, saveWorkflowAs]);
|
}, [name, onClose, saveWorkflowAs]);
|
||||||
@ -38,7 +44,7 @@ const SaveWorkflowAsButton = () => {
|
|||||||
<>
|
<>
|
||||||
<IAIIconButton
|
<IAIIconButton
|
||||||
icon={<FaClone />}
|
icon={<FaClone />}
|
||||||
onClick={onOpen}
|
onClick={onOpenCallback}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
tooltip={t('workflows.saveWorkflowAs')}
|
tooltip={t('workflows.saveWorkflowAs')}
|
||||||
aria-label={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 { useWorkflow } from 'features/nodes/hooks/useWorkflow';
|
||||||
import { workflowLoaded } from 'features/nodes/store/workflowSlice';
|
import { workflowLoaded } from 'features/nodes/store/workflowSlice';
|
||||||
import { zWorkflowV2 } from 'features/nodes/types/workflow';
|
import { zWorkflowV2 } from 'features/nodes/types/workflow';
|
||||||
|
import { getWorkflowCopyName } from 'features/workflowLibrary/util/getWorkflowCopyName';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import {
|
import {
|
||||||
@ -38,6 +39,7 @@ export const useSaveLibraryWorkflow: UseSaveLibraryWorkflow = () => {
|
|||||||
} else {
|
} else {
|
||||||
const data = await createWorkflow(workflow).unwrap();
|
const data = await createWorkflow(workflow).unwrap();
|
||||||
const createdWorkflow = zWorkflowV2.parse(data.workflow);
|
const createdWorkflow = zWorkflowV2.parse(data.workflow);
|
||||||
|
createdWorkflow.name = getWorkflowCopyName(createdWorkflow.name);
|
||||||
dispatch(workflowLoaded(createdWorkflow));
|
dispatch(workflowLoaded(createdWorkflow));
|
||||||
toaster({
|
toaster({
|
||||||
title: t('workflows.workflowSaved'),
|
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