From ad9c954a58e5392c4dc7e0fa816afa4894d4adf5 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sun, 26 Nov 2023 21:06:38 +1100 Subject: [PATCH] feat(ui): move field output template builder to own file --- .../nodes/util/buildFieldOutputTemplate.ts | 24 +++++++++++++++++++ .../src/features/nodes/util/parseSchema.ts | 23 +++++++----------- 2 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 invokeai/frontend/web/src/features/nodes/util/buildFieldOutputTemplate.ts diff --git a/invokeai/frontend/web/src/features/nodes/util/buildFieldOutputTemplate.ts b/invokeai/frontend/web/src/features/nodes/util/buildFieldOutputTemplate.ts new file mode 100644 index 0000000000..05e3c66386 --- /dev/null +++ b/invokeai/frontend/web/src/features/nodes/util/buildFieldOutputTemplate.ts @@ -0,0 +1,24 @@ +import { startCase } from 'lodash-es'; +import { FieldOutputTemplate, FieldType } from '../types/field'; +import { InvocationFieldSchema } from '../types/openapi'; + +export const buildFieldOutputTemplate = ( + fieldSchema: InvocationFieldSchema, + fieldName: string, + fieldType: FieldType +): FieldOutputTemplate => { + const { title, description, ui_hidden, ui_type, ui_order } = fieldSchema; + + const fieldOutputTemplate: FieldOutputTemplate = { + fieldKind: 'output', + name: fieldName, + title: title ?? (fieldName ? startCase(fieldName) : ''), + description: description ?? '', + type: fieldType, + ui_hidden, + ui_type, + ui_order, + }; + + return fieldOutputTemplate; +}; diff --git a/invokeai/frontend/web/src/features/nodes/util/parseSchema.ts b/invokeai/frontend/web/src/features/nodes/util/parseSchema.ts index 2c59b6cb14..81d79d2976 100644 --- a/invokeai/frontend/web/src/features/nodes/util/parseSchema.ts +++ b/invokeai/frontend/web/src/features/nodes/util/parseSchema.ts @@ -1,7 +1,9 @@ import { logger } from 'app/logging/logger'; import { parseify } from 'common/util/serialize'; -import { reduce, startCase } from 'lodash-es'; +import { t } from 'i18next'; +import { reduce } from 'lodash-es'; import { OpenAPIV3_1 } from 'openapi-types'; +import { FieldTypeParseError, UnsupportedFieldTypeError } from '../types/error'; import { FieldInputTemplate, FieldOutputTemplate } from '../types/field'; import { InvocationTemplate } from '../types/invocation'; import { @@ -11,9 +13,8 @@ import { isInvocationSchemaObject, } from '../types/openapi'; import { buildFieldInputTemplate } from './buildFieldInputTemplate'; +import { buildFieldOutputTemplate } from './buildFieldOutputTemplate'; import { parseFieldType } from './parseFieldType'; -import { FieldTypeParseError, UnsupportedFieldTypeError } from '../types/error'; -import { t } from 'i18next'; const RESERVED_INPUT_FIELD_NAMES = ['id', 'type', 'use_cache']; const RESERVED_OUTPUT_FIELD_NAMES = ['type']; @@ -209,17 +210,11 @@ export const parseSchema = ( return outputsAccumulator; } - const fieldOutputTemplate: FieldOutputTemplate = { - fieldKind: 'output', - name: propertyName, - title: - property.title ?? (propertyName ? startCase(propertyName) : ''), - description: property.description ?? '', - type: fieldType, - ui_hidden: property.ui_hidden ?? false, - ui_type: property.ui_type, - ui_order: property.ui_order, - }; + const fieldOutputTemplate = buildFieldOutputTemplate( + property, + propertyName, + fieldType + ); outputsAccumulator[propertyName] = fieldOutputTemplate; } catch (e) {