Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark iterated inputs/outputs as sequenced in docs #2495

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
270 changes: 147 additions & 123 deletions src/renderer/components/NodeDocumentation/NodeDocs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,151 +81,173 @@ const getTextLength = (input: TextInput): string => {

interface InputOutputItemProps {
schema: NodeSchema;
item: Input | Output;
type: Type;
condition?: Condition;
}
interface InputItemProps extends InputOutputItemProps {
schema: NodeSchema;
kind: 'input';
item: Input;
type: Type;
condition?: Condition;
}
interface OutputItemProps extends InputOutputItemProps {
schema: NodeSchema;
kind: 'output';
item: Output;
type: Type;
condition?: Condition;
}

const InputOutputItem = memo(({ type, item, condition, schema }: InputOutputItemProps) => {
const isOptional = 'optional' in item && item.optional;
if (isOptional) {
// eslint-disable-next-line no-param-reassign
type = withoutNull(type);
}
const InputOutputItem = memo(
({ type, kind, item, condition, schema }: InputItemProps | OutputItemProps) => {
const isOptional = 'optional' in item && item.optional;
if (isOptional) {
// eslint-disable-next-line no-param-reassign
type = withoutNull(type);
}

const handleColors = getTypeAccentColors(type);
const isIterated =
kind === 'input'
? schema.iteratorInputs.some((i) => i.inputs.includes(item.id))
: schema.iteratorOutputs.some((i) => i.outputs.includes(item.id));

const isFileInput = item.kind === 'file';
const supportedFileTypes = isFileInput ? item.filetypes : [];
const isPrimaryInput = isFileInput && item.primaryInput;
const handleColors = getTypeAccentColors(type);

const isTextInput = item.kind === 'text';
const isDropdownInput = item.kind === 'dropdown';
const isFileInput = item.kind === 'file';
const supportedFileTypes = isFileInput ? item.filetypes : [];
const isPrimaryInput = isFileInput && item.primaryInput;

return (
<SupportHighlighting>
<ListItem
mb={4}
mt={2}
>
<HStack mb={1}>
<Text
fontWeight="bold"
userSelect="text"
>
{item.label}
</Text>
{isOptional && (
<TypeTag
isOptional
fontSize="small"
height="auto"
mt="-0.2rem"
verticalAlign="middle"
>
optional
</TypeTag>
)}
{item.hasHandle &&
handleColors.map((color) => (
<Box
bgColor={color}
borderRadius="100%"
h="0.5rem"
key={color}
w="0.5rem"
/>
))}
</HStack>
<VStack
alignItems="start"
spacing={1}
w="full"
>
{item.description && (
<NoHighlighting>
<Markdown>{item.description}</Markdown>
</NoHighlighting>
)}

{isFileInput && supportedFileTypes.length > 0 && (
<Text
fontSize="md"
userSelect="text"
>
Supported file types:
{supportedFileTypes.map((fileType) => (
<TypeTag
fontSize="small"
height="auto"
key={fileType}
mt="-0.2rem"
verticalAlign="middle"
>
{fileType}
</TypeTag>
))}
</Text>
)}
const isTextInput = item.kind === 'text';
const isDropdownInput = item.kind === 'dropdown';

{isFileInput && isPrimaryInput && (
return (
<SupportHighlighting>
<ListItem
mb={4}
mt={2}
>
<HStack mb={1}>
<Text
fontSize="md"
fontWeight="bold"
userSelect="text"
>
This input is the primary input for its supported file types. This means
that you can drag and drop supported files into chaiNNer, and it will
create a node with this input filled in automatically.
{item.label}
</Text>
)}

{condition && !isTautology(condition) && (
<ConditionExplanation
condition={condition}
schema={schema}
/>
)}
{isOptional && (
<TypeTag
isOptional
fontSize="small"
height="auto"
mt="-0.2rem"
verticalAlign="middle"
>
optional
</TypeTag>
)}
{item.hasHandle &&
handleColors.map((color) => (
<Box
bgColor={color}
borderRadius="100%"
h="0.5rem"
key={color}
w="0.5rem"
/>
))}
{isIterated && <Text>(Sequenced)</Text>}
</HStack>
<VStack
alignItems="start"
spacing={1}
w="full"
>
{item.description && (
<NoHighlighting>
<Markdown>{item.description}</Markdown>
</NoHighlighting>
)}

{isTextInput && !((item.minLength ?? 0) === 0 && item.maxLength == null) && (
<Text
fontSize="md"
userSelect="text"
>
{getTextLength(item)}
</Text>
)}
{isFileInput && supportedFileTypes.length > 0 && (
<Text
fontSize="md"
userSelect="text"
>
Supported file types:
{supportedFileTypes.map((fileType) => (
<TypeTag
fontSize="small"
height="auto"
key={fileType}
mt="-0.2rem"
verticalAlign="middle"
>
{fileType}
</TypeTag>
))}
</Text>
)}

{isDropdownInput && (
<Text
fontSize="md"
userSelect="text"
>
{isFileInput && isPrimaryInput && (
<Text
as="i"
pr={1}
fontSize="md"
userSelect="text"
>
Options:
This input is the primary input for its supported file types. This
means that you can drag and drop supported files into chaiNNer, and
it will create a node with this input filled in automatically.
</Text>
<DropDownOptions options={item.options} />
</Text>
)}
)}

{condition && !isTautology(condition) && (
<ConditionExplanation
condition={condition}
schema={schema}
/>
)}

{isTextInput &&
!((item.minLength ?? 0) === 0 && item.maxLength == null) && (
<Text
fontSize="md"
userSelect="text"
>
{getTextLength(item)}
</Text>
)}

{!isDropdownInput && (
<Box whiteSpace="nowrap">
{isDropdownInput && (
<Text
as="i"
pr={1}
fontSize="md"
userSelect="text"
>
Type:
<Text
as="i"
pr={1}
>
Options:
</Text>
<DropDownOptions options={item.options} />
</Text>
<TypeView type={type} />
</Box>
)}
</VStack>
</ListItem>
</SupportHighlighting>
);
});
)}

{!isDropdownInput && (
<Box whiteSpace="nowrap">
<Text
as="i"
pr={1}
>
Type:
</Text>
<TypeView type={type} />
</Box>
)}
</VStack>
</ListItem>
</SupportHighlighting>
);
}
);

interface NodeInfoProps {
schema: NodeSchema;
Expand Down Expand Up @@ -292,6 +314,7 @@ const SingleNodeInfo = memo(({ schema, accentColor, functionDefinition }: NodeIn
condition={getInputCondition(schema, input.id)}
item={input}
key={input.id}
kind="input"
schema={schema}
type={
functionDefinition?.inputDefaults.get(input.id) ??
Expand Down Expand Up @@ -326,6 +349,7 @@ const SingleNodeInfo = memo(({ schema, accentColor, functionDefinition }: NodeIn
<InputOutputItem
item={output}
key={output.id}
kind="output"
schema={schema}
type={
functionDefinition?.outputDefaults.get(output.id) ??
Expand Down