Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide multi-instance sidebar when only a single session #688

Merged
merged 5 commits into from
Mar 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/renderer/src/stories/InstanceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export class InstanceManager extends LitElement {
justify-content: space-between;
}

#instance-sidebar[hidden] {
border: unset;
}

#instance-header {
background: #e5e5e5;
border-bottom: 1px solid #c3c3c3;
Expand Down Expand Up @@ -164,6 +168,9 @@ export class InstanceManager extends LitElement {
for (let i = 0; i < path.length; i++) {
const id = path.slice(0, i + 1).join("/");
const accordion = this.#accordions[id];

if (!this.#hasMultiple()) return; // Skip status update if accordion is not rendered

target = target[path[i]]; // Progressively check the deeper nested instances
if (accordion) accordion.setStatus(checkStatus(false, false, [...Object.values(target)]));
}
Expand Down Expand Up @@ -216,6 +223,7 @@ export class InstanceManager extends LitElement {

// Correct bug where multiple instances are selected
updated = () => {
console.log(this);
const selected = Array.from(this.shadowRoot.querySelectorAll("[selected]"));
if (selected.length > 0)
selected.slice(1).forEach((element) => {
Expand Down Expand Up @@ -361,21 +369,28 @@ export class InstanceManager extends LitElement {
return list;
}

#hasMultiple = () => this.#items.length > 1;

render() {
this.#info = {};
this.#items = [];

const instances = this.#render();
console.log(this.#items);

const hasMultiple = this.#hasMultiple();

return html`
<div>
<div id="instance-sidebar">
${this.header ? html`<div id="instance-header"><h2>${this.header}</h2></div>` : ""}
<ul id="instance-list">
${instances}
</ul>
${this.onAdded
? html`<div id="new-manager">
<div id="instance-sidebar" ?hidden=${!hasMultiple}>
${hasMultiple
? html`
${this.header ? html`<div id="instance-header"><h2>${this.header}</h2></div>` : ""}
<ul id="instance-list">
${instances}
</ul>
${this.onAdded
? html`<div id="new-manager">
<div id="new-info" class="item" hidden>
<input></input>
<nwb-button size="small" primary @click=${() => {
Expand Down Expand Up @@ -424,8 +439,11 @@ export class InstanceManager extends LitElement {
}}>Add ${this.instanceType}</nwb-button>
</div>
</div>`
: ""}
`
: ""}
</div>

<div id="content">
<div class="controls">
<span id="selectedName"></span>
Expand Down
Loading