mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): better types for validateConnection
This commit is contained in:
parent
972398d203
commit
78f9f3ee95
@ -6,13 +6,19 @@ import { validateConnectionTypes } from 'features/nodes/store/util/validateConne
|
||||
import type { AnyNode } from 'features/nodes/types/invocation';
|
||||
import type { Connection as NullableConnection, Edge } from 'reactflow';
|
||||
import type { O } from 'ts-toolbelt';
|
||||
import { assert } from 'tsafe';
|
||||
|
||||
type Connection = O.NonNullable<NullableConnection>;
|
||||
|
||||
export type ValidateConnectionResult = {
|
||||
isValid: boolean;
|
||||
export type ValidateConnectionResult =
|
||||
| {
|
||||
isValid: true;
|
||||
messageTKey?: string;
|
||||
};
|
||||
}
|
||||
| {
|
||||
isValid: false;
|
||||
messageTKey: string;
|
||||
};
|
||||
|
||||
export type ValidateConnectionFunc = (
|
||||
connection: Connection,
|
||||
@ -22,10 +28,20 @@ export type ValidateConnectionFunc = (
|
||||
ignoreEdge: Edge | null
|
||||
) => ValidateConnectionResult;
|
||||
|
||||
export const buildResult = (isValid: boolean, messageTKey?: string): ValidateConnectionResult => ({
|
||||
export const buildResult = (isValid: boolean, messageTKey?: string): ValidateConnectionResult => {
|
||||
if (isValid) {
|
||||
return {
|
||||
isValid,
|
||||
messageTKey,
|
||||
});
|
||||
};
|
||||
} else {
|
||||
assert(messageTKey !== undefined);
|
||||
return {
|
||||
isValid,
|
||||
messageTKey,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const getEqualityPredicate =
|
||||
(c: Connection) =>
|
||||
|
Loading…
Reference in New Issue
Block a user