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

Fix box visibility changed #410

Merged
merged 10 commits into from
Sep 5, 2024
2 changes: 1 addition & 1 deletion src/app/Marine2/components/views/RootView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const RootView = () => {

setBoxes(visibleBoxes)
setInitialBoxes(hiddenBoxes)
}, [visibleWidgetsStore.visibleElements, visibleWidgetsStore.visibleElements.size])
}, [visibleWidgetsStore.visibleElements])

const getBoxByType = (type: BOX_TYPES) => {
switch (type) {
Expand Down
16 changes: 13 additions & 3 deletions src/app/Marine2/modules/MetricsWidgets/VisibleWidgets.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,25 @@ export class VisibleWidgets {
}

notifyVisibility(element: notifyParams) {
if (element.visible) {
let isDirty = false
if (element.visible && !this.visibleElements.has(element.widgetName)) {
this.visibleElements.add(element.widgetName)
} else {
isDirty = true
} else if (this.visibleElements.has(element.widgetName)) {
this.visibleElements.delete(element.widgetName)
isDirty = true
}

// React compares complex types like Set or Array by reference
// when computing dependency changes.
// Duplicate the Set when its elements change to indicate we should re-render.
if (isDirty) {
this.visibleElements = new Set(this.visibleElements)
}
}

get noVisibleElements() {
return !this.visibleElements.size
return this.visibleElements.size === 0
}

clearVisibleElements() {
Expand Down
Loading