|
1 | 1 | import type { FormControlProps } from '@invoke-ai/ui-library';
|
2 |
| -import { Flex, FormControl, FormControlGroup, FormLabel, Input, Textarea } from '@invoke-ai/ui-library'; |
| 2 | +import { Box, Flex, FormControl, FormControlGroup, FormLabel, Image, Input, Textarea } from '@invoke-ai/ui-library'; |
3 | 3 | import { skipToken } from '@reduxjs/toolkit/query';
|
4 | 4 | import { createMemoizedSelector } from 'app/store/createMemoizedSelector';
|
5 | 5 | import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
@@ -40,8 +40,6 @@ const WorkflowGeneralTab = () => {
|
40 | 40 | const { id, author, name, description, tags, version, contact, notes } = useAppSelector(selector);
|
41 | 41 | const dispatch = useAppDispatch();
|
42 | 42 |
|
43 |
| - const { data } = useGetWorkflowQuery(id ?? skipToken); |
44 |
| - |
45 | 43 | const handleChangeName = useCallback(
|
46 | 44 | (e: ChangeEvent<HTMLInputElement>) => {
|
47 | 45 | dispatch(workflowNameChanged(e.target.value));
|
@@ -96,17 +94,7 @@ const WorkflowGeneralTab = () => {
|
96 | 94 | <FormLabel>{t('nodes.workflowName')}</FormLabel>
|
97 | 95 | <Input variant="darkFilled" value={name} onChange={handleChangeName} />
|
98 | 96 | </FormControl>
|
99 |
| - {/* |
100 |
| - * Only saved and non-default workflows can have a thumbnail. |
101 |
| - * - Unsaved workflows have no id. |
102 |
| - * - Default workflows have a category of 'default'. |
103 |
| - */} |
104 |
| - {id && data && data.workflow.meta.category !== 'default' && ( |
105 |
| - <FormControl> |
106 |
| - <FormLabel>{t('workflows.workflowThumbnail')}</FormLabel> |
107 |
| - <WorkflowThumbnailEditor thumbnailUrl={data.thumbnail_url} workflowId={id} /> |
108 |
| - </FormControl> |
109 |
| - )} |
| 97 | + <Thumbnail id={id} /> |
110 | 98 | <FormControl>
|
111 | 99 | <FormLabel>{t('nodes.workflowVersion')}</FormLabel>
|
112 | 100 | <Input variant="darkFilled" value={version} onChange={handleChangeVersion} />
|
@@ -156,3 +144,45 @@ export default memo(WorkflowGeneralTab);
|
156 | 144 | const formControlProps: FormControlProps = {
|
157 | 145 | flexShrink: 0,
|
158 | 146 | };
|
| 147 | + |
| 148 | +const Thumbnail = ({ id }: { id?: string | null }) => { |
| 149 | + const { t } = useTranslation(); |
| 150 | + |
| 151 | + const { data } = useGetWorkflowQuery(id ?? skipToken); |
| 152 | + |
| 153 | + if (!data) { |
| 154 | + return null; |
| 155 | + } |
| 156 | + |
| 157 | + if (data.workflow.meta.category === 'default' && data.thumbnail_url) { |
| 158 | + // This is a default workflow and it has a thumbnail set. Users may only view the thumbnail. |
| 159 | + return ( |
| 160 | + <FormControl> |
| 161 | + <FormLabel>{t('workflows.workflowThumbnail')}</FormLabel> |
| 162 | + <Box position="relative" flexShrink={0}> |
| 163 | + <Image |
| 164 | + src={data.thumbnail_url} |
| 165 | + objectFit="cover" |
| 166 | + objectPosition="50% 50%" |
| 167 | + w={100} |
| 168 | + h={100} |
| 169 | + borderRadius="base" |
| 170 | + /> |
| 171 | + </Box> |
| 172 | + </FormControl> |
| 173 | + ); |
| 174 | + } |
| 175 | + |
| 176 | + if (data.workflow.meta.category !== 'default') { |
| 177 | + // This is a user workflow and they may edit the thumbnail. |
| 178 | + return ( |
| 179 | + <FormControl> |
| 180 | + <FormLabel>{t('workflows.workflowThumbnail')}</FormLabel> |
| 181 | + <WorkflowThumbnailEditor thumbnailUrl={data.thumbnail_url} workflowId={data.workflow_id} /> |
| 182 | + </FormControl> |
| 183 | + ); |
| 184 | + } |
| 185 | + |
| 186 | + // This is a default workflow and it does not have a thumbnail set. Users may not edit the thumbnail. |
| 187 | + return null; |
| 188 | +}; |
0 commit comments