From d9f42666303f4874e130b9220d56e439063d6291 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Fri, 23 Aug 2024 14:48:42 +1000 Subject: [PATCH] feat(ui): use unique id for metadata in Graph class --- .../src/features/nodes/util/graph/generation/Graph.test.ts | 2 +- .../web/src/features/nodes/util/graph/generation/Graph.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.test.ts b/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.test.ts index 3c26edc787..6fd1431c8e 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.test.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.test.ts @@ -549,7 +549,7 @@ describe('Graph', () => { it("should get the metadata node, creating it if it doesn't exist", () => { const g = new Graph(); const metadata = g.getMetadataNode(); - expect(metadata.id).toBe('core_metadata'); + expect(metadata.id).toBe(g._metadataNodeId); expect(metadata.type).toBe('core_metadata'); g.upsertMetadata({ test: 'test' }); const metadata2 = g.getMetadataNode(); diff --git a/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.ts b/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.ts index 3510d20f15..950b25d71f 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.ts @@ -1,5 +1,5 @@ +import { getPrefixedId } from 'features/controlLayers/konva/util'; import { type ModelIdentifierField, zModelIdentifierField } from 'features/nodes/types/common'; -import { METADATA } from 'features/nodes/util/graph/constants'; import { forEach, groupBy, isEqual, unset, values } from 'lodash-es'; import type { AnyInvocation, @@ -31,6 +31,7 @@ export type GraphType = { id: string; nodes: Record; edge export class Graph { _graph: GraphType; + _metadataNodeId = getPrefixedId('core_metadata'); constructor(id?: string) { this._graph = { @@ -361,11 +362,11 @@ export class Graph { */ getMetadataNode(): S['CoreMetadataInvocation'] { try { - const node = this.getNode(METADATA) as AnyInvocationIncMetadata; + const node = this.getNode(this._metadataNodeId) as AnyInvocationIncMetadata; assert(node.type === 'core_metadata'); return node; } catch { - const node: S['CoreMetadataInvocation'] = { id: METADATA, type: 'core_metadata' }; + const node: S['CoreMetadataInvocation'] = { id: this._metadataNodeId, type: 'core_metadata' }; // @ts-expect-error `Graph` excludes `core_metadata` nodes due to its excessively wide typing return this.addNode(node); }