fix(ui): fix image nodes losing image

This commit is contained in:
psychedelicious 2023-05-22 20:05:20 +10:00 committed by Kent Keirsey
parent 6aebe1614d
commit 4a7a5234df
3 changed files with 8 additions and 17 deletions

View File

@ -21,7 +21,7 @@ const ImageInputFieldComponent = (
const getImageByNameAndType = useGetImageByNameAndType(); const getImageByNameAndType = useGetImageByNameAndType();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const [url, setUrl] = useState<string>(); const [url, setUrl] = useState<string | undefined>(field.value?.image_url);
const { getUrl } = useGetUrl(); const { getUrl } = useGetUrl();
const handleDrop = useCallback( const handleDrop = useCallback(
@ -39,16 +39,13 @@ const ImageInputFieldComponent = (
return; return;
} }
setUrl(image.url); setUrl(image.image_url);
dispatch( dispatch(
fieldValueChanged({ fieldValueChanged({
nodeId, nodeId,
fieldName: field.name, fieldName: field.name,
value: { value: image,
image_name: name,
image_type: type,
},
}) })
); );
}, },

View File

@ -11,7 +11,7 @@ import {
NodeChange, NodeChange,
OnConnectStartParams, OnConnectStartParams,
} from 'reactflow'; } from 'reactflow';
import { ImageField } from 'services/api'; import { ImageDTO } from 'services/api';
import { receivedOpenAPISchema } from 'services/thunks/schema'; import { receivedOpenAPISchema } from 'services/thunks/schema';
import { InvocationTemplate, InvocationValue } from '../types/types'; import { InvocationTemplate, InvocationValue } from '../types/types';
import { parseSchema } from '../util/parseSchema'; import { parseSchema } from '../util/parseSchema';
@ -65,13 +65,7 @@ const nodesSlice = createSlice({
action: PayloadAction<{ action: PayloadAction<{
nodeId: string; nodeId: string;
fieldName: string; fieldName: string;
value: value: string | number | boolean | ImageDTO | RgbaColor | undefined;
| string
| number
| boolean
| Pick<ImageField, 'image_name' | 'image_type'>
| RgbaColor
| undefined;
}> }>
) => { ) => {
const { nodeId, fieldName, value } = action.payload; const { nodeId, fieldName, value } = action.payload;

View File

@ -1,6 +1,6 @@
import { OpenAPIV3 } from 'openapi-types'; import { OpenAPIV3 } from 'openapi-types';
import { RgbaColor } from 'react-colorful'; import { RgbaColor } from 'react-colorful';
import { ImageField } from 'services/api'; import { ImageDTO } from 'services/api';
import { AnyInvocationType } from 'services/events/types'; import { AnyInvocationType } from 'services/events/types';
export type InvocationValue = { export type InvocationValue = {
@ -179,7 +179,7 @@ export type ConditioningInputFieldValue = FieldValueBase & {
export type ImageInputFieldValue = FieldValueBase & { export type ImageInputFieldValue = FieldValueBase & {
type: 'image'; type: 'image';
value?: Pick<ImageField, 'image_name' | 'image_type'>; value?: ImageDTO;
}; };
export type ModelInputFieldValue = FieldValueBase & { export type ModelInputFieldValue = FieldValueBase & {
@ -245,7 +245,7 @@ export type BooleanInputFieldTemplate = InputFieldTemplateBase & {
}; };
export type ImageInputFieldTemplate = InputFieldTemplateBase & { export type ImageInputFieldTemplate = InputFieldTemplateBase & {
default: Pick<ImageField, 'image_name' | 'image_type'>; default: ImageDTO;
type: 'image'; type: 'image';
}; };