Skip to content

Commit

Permalink
[shared-ui] Improve handling of imperative boards (#3840)
Browse files Browse the repository at this point in the history
Working on #3836
  • Loading branch information
paullewis authored Nov 22, 2024
1 parent fc3159e commit 057113a
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 69 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-shrimps-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@breadboard-ai/shared-ui": patch
---

Improve handling of imperative boards
154 changes: 85 additions & 69 deletions packages/shared-ui/src/elements/workspace-outline/workspace-outline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { getModuleId } from "../../utils/module-id";
type ItemIdentifier = GraphIdentifier | ModuleIdentifier;

interface Outline {
main?: string;
title: string;
items: {
nodes: InspectableNode[];
Expand Down Expand Up @@ -693,7 +694,8 @@ export class WorkspaceOutline extends LitElement {
}

return {
type: "declarative",
main: graph.main(),
type: graph.imperative() ? "imperative" : "declarative",
title: overrideTitle
? "Main Board"
: (graph.raw().title ?? "Unnamed graph"),
Expand Down Expand Up @@ -948,57 +950,63 @@ export class WorkspaceOutline extends LitElement {
}

#renderWorkspace(
type: string,
main: string | undefined,
title: string,
nodes: InspectableNode[],
ports: Map<NodeIdentifier, InspectableNodePorts>,
subItems: Map<ItemIdentifier, Outline>,
renderSubItemsInline: boolean
) {
const seenSubItems = new Set<string>();
return html`${html`<details
id=${MAIN_BOARD_ID}
class="declarative"
?open=${renderSubItemsInline || subItems.size === 0}
>
<summary>
<div class="title">
<button
class=${classMap({ "change-subitem": true })}
?disabled=${this.mode === "list" &&
this.subGraphId === null &&
this.moduleId === null}
@click=${() => {
if (this.mode === "list") {
if (this.moduleId !== null) {
this.dispatchEvent(new ModuleChosenEvent(null));
}
return html`${type === "declarative"
? html`<details
id=${MAIN_BOARD_ID}
class="declarative"
?open=${renderSubItemsInline || subItems.size === 0}
>
<summary>
<div class="title">
<button
class=${classMap({ "change-subitem": true })}
?disabled=${this.mode === "list" &&
this.subGraphId === null &&
this.moduleId === null}
@click=${() => {
if (this.mode === "list") {
if (this.moduleId !== null) {
this.dispatchEvent(new ModuleChosenEvent(null));
}
if (this.subGraphId !== null) {
this.dispatchEvent(new SubGraphChosenEvent(MAIN_BOARD_ID));
}
} else {
if (this.moduleId) {
this.dispatchEvent(new ModuleChosenEvent(null));
}
if (this.subGraphId !== null) {
this.dispatchEvent(
new SubGraphChosenEvent(MAIN_BOARD_ID)
);
}
} else {
if (this.moduleId) {
this.dispatchEvent(new ModuleChosenEvent(null));
}
this.dispatchEvent(new ZoomToGraphEvent(MAIN_BOARD_ID));
}
}}
>
${title}
</button>
</div>
</summary>
${this.#renderWorkspaceItem(
null,
nodes,
ports,
subItems,
seenSubItems,
renderSubItemsInline
)}
</details> `}
${subItems.size > seenSubItems.size
this.dispatchEvent(new ZoomToGraphEvent(MAIN_BOARD_ID));
}
}}
>
${title}
</button>
</div>
</summary>
${this.#renderWorkspaceItem(
null,
nodes,
ports,
subItems,
seenSubItems,
renderSubItemsInline
)}
</details> `
: nothing}
${type === "declarative" && subItems.size > seenSubItems.size
? html`<h1>Other items</h1>`
: nothing}
<div id="create-new">
Expand Down Expand Up @@ -1073,32 +1081,38 @@ export class WorkspaceOutline extends LitElement {
>
${subItem.title}
</button>
<button
class="delete"
@click=${() => {
if (subItem.type === "declarative") {
if (
!confirm("Are you sure you wish to delete this board?")
) {
return;
}
this.dispatchEvent(new SubGraphDeleteEvent(id));
return;
} else {
if (
!confirm("Are you sure you wish to delete this module?")
) {
return;
}
this.dispatchEvent(new ModuleDeleteEvent(id));
return;
}
}}
>
Delete
</button>
${main !== id
? html`<button
class="delete"
@click=${() => {
if (subItem.type === "declarative") {
if (
!confirm(
"Are you sure you wish to delete this board?"
)
) {
return;
}
this.dispatchEvent(new SubGraphDeleteEvent(id));
return;
} else {
if (
!confirm(
"Are you sure you wish to delete this module?"
)
) {
return;
}
this.dispatchEvent(new ModuleDeleteEvent(id));
return;
}
}}
>
Delete
</button>`
: nothing}
</div>
</summary>
${this.#renderWorkspaceItem(
Expand Down Expand Up @@ -1159,6 +1173,8 @@ export class WorkspaceOutline extends LitElement {
}
return this.#renderWorkspace(
outline.type,
outline.main,
outline.title,
nodes,
outline.items.ports,
Expand Down

0 comments on commit 057113a

Please sign in to comment.