mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
disable certain actions on images and boards in UI according to actions object on DTO
This commit is contained in:
parent
770cd36167
commit
c25e6777ff
@ -7,10 +7,11 @@ type Props = {
|
|||||||
tooltip: string;
|
tooltip: string;
|
||||||
icon?: ReactElement;
|
icon?: ReactElement;
|
||||||
styleOverrides?: SystemStyleObject;
|
styleOverrides?: SystemStyleObject;
|
||||||
|
isDisabled?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const IAIDndImageIcon = (props: Props) => {
|
const IAIDndImageIcon = (props: Props) => {
|
||||||
const { onClick, tooltip, icon, styleOverrides } = props;
|
const { onClick, tooltip, icon, styleOverrides, isDisabled = false } = props;
|
||||||
|
|
||||||
const resetIconShadow = useColorModeValue(
|
const resetIconShadow = useColorModeValue(
|
||||||
`drop-shadow(0px 0px 0.1rem var(--invokeai-colors-base-600))`,
|
`drop-shadow(0px 0px 0.1rem var(--invokeai-colors-base-600))`,
|
||||||
@ -18,6 +19,7 @@ const IAIDndImageIcon = (props: Props) => {
|
|||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<IAIIconButton
|
<IAIIconButton
|
||||||
|
isDisabled={isDisabled}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
aria-label={tooltip}
|
aria-label={tooltip}
|
||||||
tooltip={tooltip}
|
tooltip={tooltip}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { MenuItem } from '@chakra-ui/react';
|
import { MenuItem } from '@chakra-ui/react';
|
||||||
import { memo, useCallback } from 'react';
|
import { memo, useCallback, useMemo } from 'react';
|
||||||
import { FaTrash } from 'react-icons/fa';
|
import { FaTrash } from 'react-icons/fa';
|
||||||
import { BoardDTO } from 'services/api/types';
|
import { BoardDTO } from 'services/api/types';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@ -17,23 +17,21 @@ const GalleryBoardContextMenuItems = ({ board, setBoardToDelete }: Props) => {
|
|||||||
setBoardToDelete(board);
|
setBoardToDelete(board);
|
||||||
}, [board, setBoardToDelete]);
|
}, [board, setBoardToDelete]);
|
||||||
|
|
||||||
|
const isDeleteDisabled = useMemo(() => {
|
||||||
|
if (board?.actions) {
|
||||||
|
return board.actions.delete === false;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}, [board]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{board.image_count > 0 && (
|
|
||||||
<>
|
|
||||||
{/* <MenuItem
|
|
||||||
isDisabled={!board.image_count}
|
|
||||||
icon={<FaImages />}
|
|
||||||
onClickCapture={handleAddBoardToBatch}
|
|
||||||
>
|
|
||||||
Add Board to Batch
|
|
||||||
</MenuItem> */}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<MenuItem
|
<MenuItem
|
||||||
sx={{ color: 'error.600', _dark: { color: 'error.300' } }}
|
sx={{ color: 'error.600', _dark: { color: 'error.300' } }}
|
||||||
icon={<FaTrash />}
|
icon={<FaTrash />}
|
||||||
onClick={handleDelete}
|
onClick={handleDelete}
|
||||||
|
isDisabled={isDeleteDisabled}
|
||||||
>
|
>
|
||||||
{t('boards.deleteBoard')}
|
{t('boards.deleteBoard')}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
@ -15,7 +15,7 @@ import { initialImageSelected } from 'features/parameters/store/actions';
|
|||||||
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
|
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
|
||||||
import { useCopyImageToClipboard } from 'common/hooks/useCopyImageToClipboard';
|
import { useCopyImageToClipboard } from 'common/hooks/useCopyImageToClipboard';
|
||||||
import { setActiveTab } from 'features/ui/store/uiSlice';
|
import { setActiveTab } from 'features/ui/store/uiSlice';
|
||||||
import { memo, useCallback } from 'react';
|
import { memo, useCallback, useMemo } from 'react';
|
||||||
import { flushSync } from 'react-dom';
|
import { flushSync } from 'react-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import {
|
import {
|
||||||
@ -153,6 +153,22 @@ const SingleSelectionMenuItems = (props: SingleSelectionMenuItemsProps) => {
|
|||||||
}
|
}
|
||||||
}, [unstarImages, imageDTO]);
|
}, [unstarImages, imageDTO]);
|
||||||
|
|
||||||
|
const isDeleteDisabled = useMemo(() => {
|
||||||
|
if (imageDTO?.actions) {
|
||||||
|
return imageDTO.actions.delete === false;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}, [imageDTO]);
|
||||||
|
|
||||||
|
const isUnstarDisabled = useMemo(() => {
|
||||||
|
if (imageDTO?.actions) {
|
||||||
|
return imageDTO.actions.unstar === false;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}, [imageDTO]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
@ -233,6 +249,7 @@ const SingleSelectionMenuItems = (props: SingleSelectionMenuItemsProps) => {
|
|||||||
<MenuItem
|
<MenuItem
|
||||||
icon={customStarUi ? customStarUi.off.icon : <MdStar />}
|
icon={customStarUi ? customStarUi.off.icon : <MdStar />}
|
||||||
onClickCapture={handleUnstarImage}
|
onClickCapture={handleUnstarImage}
|
||||||
|
isDisabled={isUnstarDisabled}
|
||||||
>
|
>
|
||||||
{customStarUi ? customStarUi.off.text : t('gallery.unstarImage')}
|
{customStarUi ? customStarUi.off.text : t('gallery.unstarImage')}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
@ -248,6 +265,7 @@ const SingleSelectionMenuItems = (props: SingleSelectionMenuItemsProps) => {
|
|||||||
sx={{ color: 'error.600', _dark: { color: 'error.300' } }}
|
sx={{ color: 'error.600', _dark: { color: 'error.300' } }}
|
||||||
icon={<FaTrash />}
|
icon={<FaTrash />}
|
||||||
onClickCapture={handleDelete}
|
onClickCapture={handleDelete}
|
||||||
|
isDisabled={isDeleteDisabled}
|
||||||
>
|
>
|
||||||
{t('gallery.deleteImage')}
|
{t('gallery.deleteImage')}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
@ -112,6 +112,14 @@ const GalleryImage = (props: HoverableImageProps) => {
|
|||||||
return '';
|
return '';
|
||||||
}, [imageDTO?.starred, customStarUi]);
|
}, [imageDTO?.starred, customStarUi]);
|
||||||
|
|
||||||
|
const isUnstarDisabled = useMemo(() => {
|
||||||
|
if (imageDTO?.actions) {
|
||||||
|
return imageDTO?.starred && imageDTO.actions.unstar === false;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}, [imageDTO]);
|
||||||
|
|
||||||
if (!imageDTO) {
|
if (!imageDTO) {
|
||||||
return <IAIFillSkeleton />;
|
return <IAIFillSkeleton />;
|
||||||
}
|
}
|
||||||
@ -149,6 +157,13 @@ const GalleryImage = (props: HoverableImageProps) => {
|
|||||||
onClick={toggleStarredState}
|
onClick={toggleStarredState}
|
||||||
icon={starIcon}
|
icon={starIcon}
|
||||||
tooltip={starTooltip}
|
tooltip={starTooltip}
|
||||||
|
isDisabled={isUnstarDisabled}
|
||||||
|
styleOverrides={{
|
||||||
|
_disabled: {
|
||||||
|
cursor: 'not-allowed',
|
||||||
|
opacity: 1,
|
||||||
|
},
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{isHovered && shift && (
|
{isHovered && shift && (
|
||||||
|
483
invokeai/frontend/web/src/services/api/schema.d.ts
vendored
483
invokeai/frontend/web/src/services/api/schema.d.ts
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user