-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): show batch group in node title
- Loading branch information
1 parent
789540d
commit 4a08374
Showing
5 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
invokeai/frontend/web/src/features/nodes/components/flow/nodes/common/BatchGroupId.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { TextProps } from '@invoke-ai/ui-library'; | ||
import { Text } from '@invoke-ai/ui-library'; | ||
import { useBatchGroupColorToken } from 'features/nodes/hooks/useBatchGroupColorToken'; | ||
import { memo } from 'react'; | ||
|
||
type Props = TextProps & { | ||
batchGroupId?: string; | ||
}; | ||
|
||
export const BatchGroupId = memo(({ batchGroupId, ...rest }: Props) => { | ||
const batchGroupColorToken = useBatchGroupColorToken(batchGroupId); | ||
|
||
if (!batchGroupColorToken || !batchGroupId) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Text fontWeight="semibold" color={batchGroupColorToken} {...rest}> | ||
{batchGroupId} | ||
</Text> | ||
); | ||
}); | ||
|
||
BatchGroupId.displayName = 'BatchGroupId'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
invokeai/frontend/web/src/features/nodes/hooks/useBatchGroupColorToken.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useMemo } from 'react'; | ||
|
||
export const useBatchGroupColorToken = (batchGroupId?: string) => { | ||
const batchGroupColorToken = useMemo(() => { | ||
switch (batchGroupId) { | ||
case 'Group 1': | ||
return 'invokeGreen.300'; | ||
case 'Group 2': | ||
return 'invokeBlue.300'; | ||
case 'Group 3': | ||
return 'invokePurple.200'; | ||
case 'Group 4': | ||
return 'invokeRed.300'; | ||
case 'Group 5': | ||
return 'invokeYellow.300'; | ||
default: | ||
return undefined; | ||
} | ||
}, [batchGroupId]); | ||
|
||
return batchGroupColorToken; | ||
}; |
19 changes: 19 additions & 0 deletions
19
invokeai/frontend/web/src/features/nodes/hooks/useBatchGroupId.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useNode } from 'features/nodes/hooks/useNode'; | ||
import { isBatchNode, isInvocationNode } from 'features/nodes/types/invocation'; | ||
import { useMemo } from 'react'; | ||
|
||
export const useBatchGroupId = (nodeId: string) => { | ||
const node = useNode(nodeId); | ||
|
||
const batchGroupId = useMemo(() => { | ||
if (!isInvocationNode(node)) { | ||
return; | ||
} | ||
if (!isBatchNode(node)) { | ||
return; | ||
} | ||
return node.data.inputs['batch_group_id']?.value as string; | ||
}, [node]); | ||
|
||
return batchGroupId; | ||
}; |