feat(ui): organize node utils

This commit is contained in:
psychedelicious 2023-11-27 00:00:44 +11:00
parent 4309f3bd58
commit 8d99113bef
60 changed files with 106 additions and 95 deletions

View File

@ -10,8 +10,8 @@ import { blobToDataURL } from 'features/canvas/util/blobToDataURL';
import { getCanvasData } from 'features/canvas/util/getCanvasData';
import { getCanvasGenerationMode } from 'features/canvas/util/getCanvasGenerationMode';
import { canvasGraphBuilt } from 'features/nodes/store/actions';
import { buildCanvasGraph } from 'features/nodes/util/graphBuilders/buildCanvasGraph';
import { prepareLinearUIBatch } from 'features/nodes/util/graphBuilders/buildLinearBatchConfig';
import { buildCanvasGraph } from 'features/nodes/util/graph/buildCanvasGraph';
import { prepareLinearUIBatch } from 'features/nodes/util/graph/buildLinearBatchConfig';
import { imagesApi } from 'services/api/endpoints/images';
import { queueApi } from 'services/api/endpoints/queue';
import { ImageDTO } from 'services/api/types';

View File

@ -1,9 +1,9 @@
import { enqueueRequested } from 'app/store/actions';
import { prepareLinearUIBatch } from 'features/nodes/util/graphBuilders/buildLinearBatchConfig';
import { buildLinearImageToImageGraph } from 'features/nodes/util/graphBuilders/buildLinearImageToImageGraph';
import { buildLinearSDXLImageToImageGraph } from 'features/nodes/util/graphBuilders/buildLinearSDXLImageToImageGraph';
import { buildLinearSDXLTextToImageGraph } from 'features/nodes/util/graphBuilders/buildLinearSDXLTextToImageGraph';
import { buildLinearTextToImageGraph } from 'features/nodes/util/graphBuilders/buildLinearTextToImageGraph';
import { prepareLinearUIBatch } from 'features/nodes/util/graph/buildLinearBatchConfig';
import { buildLinearImageToImageGraph } from 'features/nodes/util/graph/buildLinearImageToImageGraph';
import { buildLinearSDXLImageToImageGraph } from 'features/nodes/util/graph/buildLinearSDXLImageToImageGraph';
import { buildLinearSDXLTextToImageGraph } from 'features/nodes/util/graph/buildLinearSDXLTextToImageGraph';
import { buildLinearTextToImageGraph } from 'features/nodes/util/graph/buildLinearTextToImageGraph';
import { queueApi } from 'services/api/endpoints/queue';
import { startAppListening } from '..';

View File

@ -1,5 +1,5 @@
import { enqueueRequested } from 'app/store/actions';
import { buildNodesGraph } from 'features/nodes/util/graphBuilders/buildNodesGraph';
import { buildNodesGraph } from 'features/nodes/util/graph/buildNodesGraph';
import { queueApi } from 'services/api/endpoints/queue';
import { BatchConfig } from 'services/api/types';
import { startAppListening } from '..';

View File

@ -1,7 +1,7 @@
import { logger } from 'app/logging/logger';
import { parseify } from 'common/util/serialize';
import { nodeTemplatesBuilt } from 'features/nodes/store/nodesSlice';
import { parseSchema } from 'features/nodes/util/parseSchema';
import { parseSchema } from 'features/nodes/util/schema/parseSchema';
import { size } from 'lodash-es';
import { receivedOpenAPISchema } from 'services/api/thunks/schema';
import { startAppListening } from '..';

View File

@ -10,7 +10,7 @@ import { IMAGE_CATEGORIES } from 'features/gallery/store/types';
import {
LINEAR_UI_OUTPUT,
nodeIDDenyList,
} from 'features/nodes/util/graphBuilders/constants';
} from 'features/nodes/util/graph/constants';
import { boardsApi } from 'services/api/endpoints/boards';
import { imagesApi } from 'services/api/endpoints/images';
import { imagesAdapter } from 'services/api/util';

View File

@ -4,7 +4,7 @@ import { nodeReplaced } from 'features/nodes/store/nodesSlice';
import {
getNeedsUpdate,
updateNode,
} from 'features/nodes/store/util/nodeUpdate';
} from 'features/nodes/util/node/nodeUpdate';
import { NodeUpdateError } from 'features/nodes/types/error';
import { isInvocationNode } from 'features/nodes/types/invocation';
import { addToast } from 'features/system/store/systemSlice';

View File

@ -1,7 +1,7 @@
import { createAction } from '@reduxjs/toolkit';
import { logger } from 'app/logging/logger';
import { parseify } from 'common/util/serialize';
import { buildAdHocUpscaleGraph } from 'features/nodes/util/graphBuilders/buildAdHocUpscaleGraph';
import { buildAdHocUpscaleGraph } from 'features/nodes/util/graph/buildAdHocUpscaleGraph';
import { addToast } from 'features/system/store/systemSlice';
import { t } from 'i18next';
import { queueApi } from 'services/api/endpoints/queue';

View File

@ -4,7 +4,7 @@ import { workflowLoadRequested } from 'features/nodes/store/actions';
import { workflowLoaded } from 'features/nodes/store/nodesSlice';
import { $flow } from 'features/nodes/store/reactFlowInstance';
import { WorkflowVersionError } from 'features/nodes/types/error';
import { validateWorkflow } from 'features/nodes/util/validateWorkflow';
import { validateWorkflow } from 'features/nodes/util/workflow/validateWorkflow';
import { addToast } from 'features/system/store/systemSlice';
import { makeToast } from 'features/system/util/makeToast';
import { setActiveTab } from 'features/ui/store/uiSlice';

View File

@ -11,7 +11,7 @@ import { stateSelector } from 'app/store/store';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
import IAIMantineSearchableSelect from 'common/components/IAIMantineSearchableSelect';
import { useBuildNodeData } from 'features/nodes/hooks/useBuildNodeData';
import { useBuildNode } from 'features/nodes/hooks/useBuildNode';
import {
addNodePopoverClosed,
addNodePopoverOpened,
@ -51,7 +51,7 @@ const selectFilter = (value: string, item: NodeTemplate) => {
const AddNodePopover = () => {
const dispatch = useAppDispatch();
const buildInvocation = useBuildNodeData();
const buildInvocation = useBuildNode();
const toaster = useAppToaster();
const { t } = useTranslation();

View File

@ -11,7 +11,7 @@ import { stateSelector } from 'app/store/store';
import { useAppSelector } from 'app/store/storeHooks';
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
import { IAINoContentFallback } from 'common/components/IAIImageFallback';
import { getNeedsUpdate } from 'features/nodes/store/util/nodeUpdate';
import { getNeedsUpdate } from 'features/nodes/util/node/nodeUpdate';
import {
InvocationNodeData,
InvocationTemplate,

View File

@ -5,8 +5,8 @@ import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
import { keys, map } from 'lodash-es';
import { useMemo } from 'react';
import { isInvocationNode } from '../types/invocation';
import { getSortedFilteredFieldNames } from '../util/getSortedFilteredFieldNames';
import { TEMPLATE_BUILDER_MAP } from '../util/buildFieldInputTemplate';
import { getSortedFilteredFieldNames } from '../util/node/getSortedFilteredFieldNames';
import { TEMPLATE_BUILDER_MAP } from '../util/schema/buildFieldInputTemplate';
export const useAnyOrDirectInputFieldNames = (nodeId: string) => {
const selector = useMemo(

View File

@ -3,13 +3,12 @@ import { RootState } from 'app/store/store';
import { useAppSelector } from 'app/store/storeHooks';
import { useCallback } from 'react';
import { Node, useReactFlow } from 'reactflow';
import {
buildCurrentImageNode,
buildInvocationNode,
buildNotesNode,
} from '../store/util/buildNodeData';
import { DRAG_HANDLE_CLASSNAME, NODE_WIDTH } from '../types/constants';
import { AnyNode, InvocationTemplate } from '../types/invocation';
import { buildCurrentImageNode } from '../util/node/buildCurrentImageNode';
import { buildInvocationNode } from '../util/node/buildInvocationNode';
import { buildNotesNode } from '../util/node/buildNotesNode';
const templatesSelector = createSelector(
[(state: RootState) => state.nodes],
(nodes) => nodes.nodeTemplates
@ -19,7 +18,7 @@ export const SHARED_NODE_PROPERTIES: Partial<Node> = {
dragHandle: `.${DRAG_HANDLE_CLASSNAME}`,
};
export const useBuildNodeData = () => {
export const useBuildNode = () => {
const nodeTemplates = useAppSelector(templatesSelector);
const flow = useReactFlow();

View File

@ -5,8 +5,8 @@ import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
import { keys, map } from 'lodash-es';
import { useMemo } from 'react';
import { isInvocationNode } from '../types/invocation';
import { getSortedFilteredFieldNames } from '../util/getSortedFilteredFieldNames';
import { TEMPLATE_BUILDER_MAP } from '../util/buildFieldInputTemplate';
import { getSortedFilteredFieldNames } from '../util/node/getSortedFilteredFieldNames';
import { TEMPLATE_BUILDER_MAP } from '../util/schema/buildFieldInputTemplate';
export const useConnectionInputFieldNames = (nodeId: string) => {
const selector = useMemo(

View File

@ -2,7 +2,7 @@ import { createSelector } from '@reduxjs/toolkit';
import { stateSelector } from 'app/store/store';
import { useAppSelector } from 'app/store/storeHooks';
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
import { getNeedsUpdate } from '../store/util/nodeUpdate';
import { getNeedsUpdate } from '../util/node/nodeUpdate';
import { isInvocationNode } from '../types/invocation';
const selector = createSelector(

View File

@ -4,7 +4,7 @@ import { useAppSelector } from 'app/store/storeHooks';
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
import { useMemo } from 'react';
import { isInvocationNode } from '../types/invocation';
import { getNeedsUpdate } from '../store/util/nodeUpdate';
import { getNeedsUpdate } from '../util/node/nodeUpdate';
export const useNodeNeedsUpdate = (nodeId: string) => {
const selector = useMemo(

View File

@ -5,7 +5,7 @@ import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
import { map } from 'lodash-es';
import { useMemo } from 'react';
import { isInvocationNode } from '../types/invocation';
import { getSortedFilteredFieldNames } from '../util/getSortedFilteredFieldNames';
import { getSortedFilteredFieldNames } from '../util/node/getSortedFilteredFieldNames';
export const useOutputFieldNames = (nodeId: string) => {
const selector = useMemo(

View File

@ -1,6 +1,6 @@
import { RootState } from 'app/store/store';
import { useAppSelector } from 'app/store/storeHooks';
import { buildWorkflow } from 'features/nodes/util/buildWorkflow';
import { buildWorkflow } from 'features/nodes/util/workflow/buildWorkflow';
import { useMemo } from 'react';
import { useDebounce } from 'use-debounce';

View File

@ -4,7 +4,7 @@ import { cloneDeep, omit, reduce } from 'lodash-es';
import { Graph } from 'services/api/types';
import { AnyInvocation } from 'services/events/types';
import { v4 as uuidv4 } from 'uuid';
import { buildWorkflow } from '../buildWorkflow';
import { buildWorkflow } from '../workflow/buildWorkflow';
import {
FieldInputInstance,
isColorFieldInputInstance,

View File

@ -0,0 +1,23 @@
import { SHARED_NODE_PROPERTIES } from 'features/nodes/types/constants';
import { CurrentImageNode } from 'features/nodes/types/invocation';
import { XYPosition } from 'reactflow';
import { v4 as uuidv4 } from 'uuid';
export const buildCurrentImageNode = (
position: XYPosition
): CurrentImageNode => {
const nodeId = uuidv4();
const node: CurrentImageNode = {
...SHARED_NODE_PROPERTIES,
id: nodeId,
type: 'current_image',
position,
data: {
id: nodeId,
type: 'current_image',
isOpen: true,
label: 'Current Image',
},
};
return node;
};

View File

@ -4,57 +4,18 @@ import {
FieldOutputInstance,
} from 'features/nodes/types/field';
import {
CurrentImageNodeData,
InvocationNodeData,
InvocationNode,
InvocationTemplate,
NotesNodeData,
} from 'features/nodes/types/invocation';
import { buildFieldInputInstance } from 'features/nodes/util/buildFieldInputInstance';
import { buildFieldInputInstance } from 'features/nodes/util/schema/buildFieldInputInstance';
import { reduce } from 'lodash-es';
import { Node, XYPosition } from 'reactflow';
import { XYPosition } from 'reactflow';
import { v4 as uuidv4 } from 'uuid';
export const buildNotesNode = (position: XYPosition): Node<NotesNodeData> => {
const nodeId = uuidv4();
const node: Node<NotesNodeData> = {
...SHARED_NODE_PROPERTIES,
id: nodeId,
type: 'notes',
position,
data: {
id: nodeId,
isOpen: true,
label: 'Notes',
notes: '',
type: 'notes',
},
};
return node;
};
export const buildCurrentImageNode = (
position: XYPosition
): Node<CurrentImageNodeData> => {
const nodeId = uuidv4();
const node: Node<CurrentImageNodeData> = {
...SHARED_NODE_PROPERTIES,
id: nodeId,
type: 'current_image',
position,
data: {
id: nodeId,
type: 'current_image',
isOpen: true,
label: 'Current Image',
},
};
return node;
};
export const buildInvocationNode = (
position: XYPosition,
template: InvocationTemplate
): Node<InvocationNodeData> => {
): InvocationNode => {
const nodeId = uuidv4();
const { type } = template;
@ -94,7 +55,7 @@ export const buildInvocationNode = (
{} as Record<string, FieldOutputInstance>
);
const node: Node<InvocationNodeData> = {
const node: InvocationNode = {
...SHARED_NODE_PROPERTIES,
id: nodeId,
type: 'invocation',

View File

@ -0,0 +1,22 @@
import { SHARED_NODE_PROPERTIES } from 'features/nodes/types/constants';
import { NotesNode } from 'features/nodes/types/invocation';
import { XYPosition } from 'reactflow';
import { v4 as uuidv4 } from 'uuid';
export const buildNotesNode = (position: XYPosition): NotesNode => {
const nodeId = uuidv4();
const node: NotesNode = {
...SHARED_NODE_PROPERTIES,
id: nodeId,
type: 'notes',
position,
data: {
id: nodeId,
isOpen: true,
label: 'Notes',
notes: '',
type: 'notes',
},
};
return node;
};

View File

@ -1,5 +1,5 @@
import { isNil } from 'lodash-es';
import { FieldInputTemplate, FieldOutputTemplate } from '../types/field';
import { FieldInputTemplate, FieldOutputTemplate } from '../../types/field';
export const getSortedFilteredFieldNames = (
fields: FieldInputTemplate[] | FieldOutputTemplate[]

View File

@ -7,7 +7,7 @@ import {
import { zParsedSemver } from 'features/nodes/types/semver';
import { cloneDeep, defaultsDeep } from 'lodash-es';
import { Node } from 'reactflow';
import { buildInvocationNode } from './buildNodeData';
import { buildInvocationNode } from './buildInvocationNode';
export const getNeedsUpdate = (
node: Node<InvocationNodeData>,

View File

@ -1,5 +1,5 @@
import { get } from 'lodash-es';
import { FieldInputInstance, FieldInputTemplate } from '../types/field';
import { FieldInputInstance, FieldInputTemplate } from '../../types/field';
const FIELD_VALUE_FALLBACK_MAP = {
EnumField: '',

View File

@ -22,8 +22,8 @@ import {
T2IAdapterModelFieldInputTemplate,
VAEModelFieldInputTemplate,
isStatefulFieldType,
} from '../types/field';
import { InvocationFieldSchema } from '../types/openapi';
} from '../../types/field';
import { InvocationFieldSchema } from '../../types/openapi';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type FieldInputTemplateBuilder<T extends FieldInputTemplate = any> = // valid `any`!

View File

@ -1,6 +1,6 @@
import { startCase } from 'lodash-es';
import { FieldOutputTemplate, FieldType } from '../types/field';
import { InvocationFieldSchema } from '../types/openapi';
import { FieldOutputTemplate, FieldType } from '../../types/field';
import { InvocationFieldSchema } from '../../types/openapi';
export const buildFieldOutputTemplate = (
fieldSchema: InvocationFieldSchema,

View File

@ -1,8 +1,11 @@
import { t } from 'i18next';
import { isArray } from 'lodash-es';
import { OpenAPIV3_1 } from 'openapi-types';
import { FieldTypeParseError, UnsupportedFieldTypeError } from '../types/error';
import { FieldType } from '../types/field';
import {
FieldTypeParseError,
UnsupportedFieldTypeError,
} from '../../types/error';
import { FieldType } from '../../types/field';
import {
OpenAPIV3_1SchemaOrRef,
isArraySchemaObject,
@ -10,7 +13,7 @@ import {
isNonArraySchemaObject,
isRefObject,
isSchemaObject,
} from '../types/openapi';
} from '../../types/openapi';
/**
* Transforms an invocation output ref object to field type.

View File

@ -3,15 +3,18 @@ import { parseify } from 'common/util/serialize';
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 {
FieldTypeParseError,
UnsupportedFieldTypeError,
} from '../../types/error';
import { FieldInputTemplate, FieldOutputTemplate } from '../../types/field';
import { InvocationTemplate } from '../../types/invocation';
import {
InvocationSchemaObject,
isInvocationFieldSchema,
isInvocationOutputSchemaObject,
isInvocationSchemaObject,
} from '../types/openapi';
} from '../../types/openapi';
import { buildFieldInputTemplate } from './buildFieldInputTemplate';
import { buildFieldOutputTemplate } from './buildFieldOutputTemplate';
import { parseFieldType } from './parseFieldType';

View File

@ -1,6 +1,6 @@
import { logger } from 'app/logging/logger';
import { NodesState } from '../store/types';
import { WorkflowV2, zWorkflowEdge, zWorkflowNode } from '../types/workflow';
import { NodesState } from '../../store/types';
import { WorkflowV2, zWorkflowEdge, zWorkflowNode } from '../../types/workflow';
import { fromZodError } from 'zod-validation-error';
import { parseify } from 'common/util/serialize';
import i18n from 'i18next';

View File

@ -2,10 +2,10 @@ import { parseify } from 'common/util/serialize';
import { t } from 'i18next';
import { keyBy } from 'lodash-es';
import { JsonObject } from 'type-fest';
import { getNeedsUpdate } from '../store/util/nodeUpdate';
import { InvocationTemplate } from '../types/invocation';
import { parseAndMigrateWorkflow } from '../types/migration/migrations';
import { WorkflowV2, isWorkflowInvocationNode } from '../types/workflow';
import { getNeedsUpdate } from '../node/nodeUpdate';
import { InvocationTemplate } from '../../types/invocation';
import { parseAndMigrateWorkflow } from '../../types/migration/migrations';
import { WorkflowV2, isWorkflowInvocationNode } from '../../types/workflow';
type WorkflowWarning = {
message: string;