Skip to content

Commit 8105355

Browse files
committed
refactor: simplify promoted widget handling
1 parent 5e05924 commit 8105355

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/components/rightSidePanel/parameters/WidgetActions.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@ describe('WidgetActions', () => {
236236
type: 'TestNode',
237237
rootGraph: { id: 'graph-test' },
238238
isSubgraphNode: () => true,
239-
getSlotFromWidget: () => ({ widgetId: 'graph-test:1:test_widget' })
239+
getSlotFromWidget: (candidate: IBaseWidget) =>
240+
candidate.name === 'test_widget'
241+
? { widgetId: 'graph-test:1:test_widget' }
242+
: undefined
240243
})
241244
const host = fromAny<SubgraphNode, unknown>({ id: 2 })
242245

@@ -247,11 +250,12 @@ describe('WidgetActions', () => {
247250
).not.toBeInTheDocument()
248251
})
249252

250-
it('toggles the favorite for the host node itself', async () => {
253+
it("toggles the favorite for the row's node", async () => {
251254
const widget = createMockWidget()
252255
const node = createMockNode()
256+
const host = fromAny<SubgraphNode, unknown>({ id: 2 })
253257

254-
const { user } = renderWidgetActions(widget, node)
258+
const { user } = renderWidgetActions(widget, node, { host })
255259

256260
await user.click(screen.getByRole('button', { name: /Favorite/ }))
257261

src/components/rightSidePanel/subgraph/SubgraphEditor.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ function rowDisplayName(row: ActiveRow): string {
248248
}
249249
250250
function isRowLinked(row: ActiveRow): boolean {
251-
return row.kind === 'promoted' && row.input.widgetId != null
251+
return row.kind === 'promoted'
252252
}
253253
254254
function promotedRowKey(row: PromotedRow): string {
@@ -269,10 +269,10 @@ function demoteRow(row: ActiveRow) {
269269
const subgraphNode = activeNode.value
270270
if (!subgraphNode) return
271271
if (row.kind === 'promoted') {
272-
const linkedInput = row.input._subgraphSlot
273-
if (linkedInput) {
274-
if (row.input.link != null) linkedInput.disconnect()
275-
else subgraphNode.subgraph.removeInput(linkedInput)
272+
const subgraphSlot = row.input._subgraphSlot
273+
if (subgraphSlot) {
274+
if (row.input.link != null) subgraphSlot.disconnect()
275+
else subgraphNode.subgraph.removeInput(subgraphSlot)
276276
}
277277
refreshPromotedWidgetRendering()
278278
return

0 commit comments

Comments
 (0)