mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
parent
67a343b3e4
commit
024aa5eb90
@ -9,6 +9,7 @@ import {
|
|||||||
POLYMORPHIC_TYPES,
|
POLYMORPHIC_TYPES,
|
||||||
TYPES_WITH_INPUT_COMPONENTS,
|
TYPES_WITH_INPUT_COMPONENTS,
|
||||||
} from '../types/constants';
|
} from '../types/constants';
|
||||||
|
import { getSortedFilteredFieldNames } from '../util/getSortedFilteredFieldNames';
|
||||||
|
|
||||||
export const useAnyOrDirectInputFieldNames = (nodeId: string) => {
|
export const useAnyOrDirectInputFieldNames = (nodeId: string) => {
|
||||||
const selector = useMemo(
|
const selector = useMemo(
|
||||||
@ -24,17 +25,13 @@ export const useAnyOrDirectInputFieldNames = (nodeId: string) => {
|
|||||||
if (!nodeTemplate) {
|
if (!nodeTemplate) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return map(nodeTemplate.inputs)
|
const fields = map(nodeTemplate.inputs).filter(
|
||||||
.filter(
|
|
||||||
(field) =>
|
(field) =>
|
||||||
(['any', 'direct'].includes(field.input) ||
|
(['any', 'direct'].includes(field.input) ||
|
||||||
POLYMORPHIC_TYPES.includes(field.type)) &&
|
POLYMORPHIC_TYPES.includes(field.type)) &&
|
||||||
TYPES_WITH_INPUT_COMPONENTS.includes(field.type)
|
TYPES_WITH_INPUT_COMPONENTS.includes(field.type)
|
||||||
)
|
);
|
||||||
.filter((field) => !field.ui_hidden)
|
return getSortedFilteredFieldNames(fields);
|
||||||
.sort((a, b) => (a.ui_order ?? 0) - (b.ui_order ?? 0))
|
|
||||||
.map((field) => field.name)
|
|
||||||
.filter((fieldName) => fieldName !== 'is_intermediate');
|
|
||||||
},
|
},
|
||||||
defaultSelectorOptions
|
defaultSelectorOptions
|
||||||
),
|
),
|
||||||
|
@ -9,6 +9,7 @@ import {
|
|||||||
TYPES_WITH_INPUT_COMPONENTS,
|
TYPES_WITH_INPUT_COMPONENTS,
|
||||||
} from '../types/constants';
|
} from '../types/constants';
|
||||||
import { isInvocationNode } from '../types/types';
|
import { isInvocationNode } from '../types/types';
|
||||||
|
import { getSortedFilteredFieldNames } from '../util/getSortedFilteredFieldNames';
|
||||||
|
|
||||||
export const useConnectionInputFieldNames = (nodeId: string) => {
|
export const useConnectionInputFieldNames = (nodeId: string) => {
|
||||||
const selector = useMemo(
|
const selector = useMemo(
|
||||||
@ -24,17 +25,16 @@ export const useConnectionInputFieldNames = (nodeId: string) => {
|
|||||||
if (!nodeTemplate) {
|
if (!nodeTemplate) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return map(nodeTemplate.inputs)
|
|
||||||
.filter(
|
// get the visible fields
|
||||||
|
const fields = map(nodeTemplate.inputs).filter(
|
||||||
(field) =>
|
(field) =>
|
||||||
(field.input === 'connection' &&
|
(field.input === 'connection' &&
|
||||||
!POLYMORPHIC_TYPES.includes(field.type)) ||
|
!POLYMORPHIC_TYPES.includes(field.type)) ||
|
||||||
!TYPES_WITH_INPUT_COMPONENTS.includes(field.type)
|
!TYPES_WITH_INPUT_COMPONENTS.includes(field.type)
|
||||||
)
|
);
|
||||||
.filter((field) => !field.ui_hidden)
|
|
||||||
.sort((a, b) => (a.ui_order ?? 0) - (b.ui_order ?? 0))
|
return getSortedFilteredFieldNames(fields);
|
||||||
.map((field) => field.name)
|
|
||||||
.filter((fieldName) => fieldName !== 'is_intermediate');
|
|
||||||
},
|
},
|
||||||
defaultSelectorOptions
|
defaultSelectorOptions
|
||||||
),
|
),
|
||||||
|
@ -5,6 +5,7 @@ import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
|
|||||||
import { map } from 'lodash-es';
|
import { map } from 'lodash-es';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { isInvocationNode } from '../types/types';
|
import { isInvocationNode } from '../types/types';
|
||||||
|
import { getSortedFilteredFieldNames } from '../util/getSortedFilteredFieldNames';
|
||||||
|
|
||||||
export const useOutputFieldNames = (nodeId: string) => {
|
export const useOutputFieldNames = (nodeId: string) => {
|
||||||
const selector = useMemo(
|
const selector = useMemo(
|
||||||
@ -20,11 +21,8 @@ export const useOutputFieldNames = (nodeId: string) => {
|
|||||||
if (!nodeTemplate) {
|
if (!nodeTemplate) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return map(nodeTemplate.outputs)
|
|
||||||
.filter((field) => !field.ui_hidden)
|
return getSortedFilteredFieldNames(map(nodeTemplate.outputs));
|
||||||
.sort((a, b) => (a.ui_order ?? 0) - (b.ui_order ?? 0))
|
|
||||||
.map((field) => field.name)
|
|
||||||
.filter((fieldName) => fieldName !== 'is_intermediate');
|
|
||||||
},
|
},
|
||||||
defaultSelectorOptions
|
defaultSelectorOptions
|
||||||
),
|
),
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
import { isNil } from 'lodash-es';
|
||||||
|
import { InputFieldTemplate, OutputFieldTemplate } from '../types/types';
|
||||||
|
|
||||||
|
export const getSortedFilteredFieldNames = (
|
||||||
|
fields: InputFieldTemplate[] | OutputFieldTemplate[]
|
||||||
|
): string[] => {
|
||||||
|
const visibleFields = fields.filter((field) => !field.ui_hidden);
|
||||||
|
|
||||||
|
// we want explicitly ordered fields to be before unordered fields; split the list
|
||||||
|
const orderedFields = visibleFields
|
||||||
|
.filter((f) => !isNil(f.ui_order))
|
||||||
|
.sort((a, b) => (a.ui_order ?? 0) - (b.ui_order ?? 0));
|
||||||
|
const unorderedFields = visibleFields.filter((f) => isNil(f.ui_order));
|
||||||
|
|
||||||
|
// concat the lists, and return the field names, skipping `is_intermediate`
|
||||||
|
return orderedFields
|
||||||
|
.concat(unorderedFields)
|
||||||
|
.map((f) => f.name)
|
||||||
|
.filter((fieldName) => fieldName !== 'is_intermediate');
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user