From 6a24965c3552ffd086dac4d385f32f74ac90ba46 Mon Sep 17 00:00:00 2001 From: heswell Date: Tue, 14 Nov 2023 13:24:10 +0000 Subject: [PATCH] ensure basket feature tables suspend and resume at right time (#969) --- .../packages/vuu-data/src/inlined-worker.js | 2 ++ .../vuu-data/src/remote-data-source.ts | 2 ++ .../layout-management/useLayoutManager.tsx | 1 - .../vuu-table/src/table-next/useDataSource.ts | 20 +++++++++---------- .../src/useFilterTable.tsx | 9 +-------- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/vuu-ui/packages/vuu-data/src/inlined-worker.js b/vuu-ui/packages/vuu-data/src/inlined-worker.js index b0715dd93..5441fd963 100644 --- a/vuu-ui/packages/vuu-data/src/inlined-worker.js +++ b/vuu-ui/packages/vuu-data/src/inlined-worker.js @@ -1876,11 +1876,13 @@ var ServerProxy = class { this.sendIfReady(request, requestId, viewport.status === "subscribed"); } disableViewport(viewport) { + console.log("disable viewport"); const requestId = nextRequestId(); const request = viewport.disable(requestId); this.sendIfReady(request, requestId, viewport.status === "subscribed"); } enableViewport(viewport) { + console.log("enable viewport"); if (viewport.disabled) { const requestId = nextRequestId(); const request = viewport.enable(requestId); diff --git a/vuu-ui/packages/vuu-data/src/remote-data-source.ts b/vuu-ui/packages/vuu-data/src/remote-data-source.ts index 4400783db..52ee46980 100644 --- a/vuu-ui/packages/vuu-data/src/remote-data-source.ts +++ b/vuu-ui/packages/vuu-data/src/remote-data-source.ts @@ -238,6 +238,7 @@ export class RemoteDataSource } suspend() { + console.log(`suspend #${this.viewport}, current status ${this.#status}`); info?.(`suspend #${this.viewport}, current status ${this.#status}`); if (this.viewport) { this.#status = "suspended"; @@ -266,6 +267,7 @@ export class RemoteDataSource } disable() { + console.log(`disable #${this.viewport}, current status ${this.#status}`); info?.(`disable #${this.viewport}, current status ${this.#status}`); if (this.viewport) { this.#status = "disabling"; diff --git a/vuu-ui/packages/vuu-shell/src/layout-management/useLayoutManager.tsx b/vuu-ui/packages/vuu-shell/src/layout-management/useLayoutManager.tsx index 11a9f71f6..9785c7c6a 100644 --- a/vuu-ui/packages/vuu-shell/src/layout-management/useLayoutManager.tsx +++ b/vuu-ui/packages/vuu-shell/src/layout-management/useLayoutManager.tsx @@ -72,7 +72,6 @@ export const LayoutManagementProvider = ( const saveApplicationLayout = useCallback( (layout: LayoutJSON) => { - console.log(`save application layout ${JSON.stringify(layout, null, 2)}`); const persistenceManager = getPersistenceManager(); setApplicationLayout(layout, false); persistenceManager.saveApplicationLayout(layout); diff --git a/vuu-ui/packages/vuu-table/src/table-next/useDataSource.ts b/vuu-ui/packages/vuu-table/src/table-next/useDataSource.ts index 7a02d8af8..0f96a7b13 100644 --- a/vuu-ui/packages/vuu-table/src/table-next/useDataSource.ts +++ b/vuu-ui/packages/vuu-table/src/table-next/useDataSource.ts @@ -44,6 +44,7 @@ export const useDataSource = ({ const setData = useCallback( (updates: DataSourceRow[]) => { + console.table(updates); for (const row of updates) { dataWindow.add(row); } @@ -51,6 +52,8 @@ export const useDataSource = ({ if (isMounted.current) { // TODO do we ever need to worry about missing updates here ? forceUpdate({}); + } else { + console.log(`ignore update as we're not mounted`); } }, [dataWindow] @@ -84,17 +87,14 @@ export const useDataSource = ({ return dataWindow.getSelectedRows(); }, [dataWindow]); - useEffect( - () => () => { - isMounted.current = true; - // if (rafHandle.current) { - // cancelAnimationFrame(rafHandle.current); - // rafHandle.current = null; - // } + useEffect(() => { + isMounted.current = true; + dataSource.resume?.(); + return () => { isMounted.current = false; - }, - [] - ); + dataSource.suspend?.(); + }; + }, [dataSource]); // Keep until we'tre sure we don't need it for updates // const refreshIfUpdated = useCallback(() => { diff --git a/vuu-ui/sample-apps/feature-filter-table/src/useFilterTable.tsx b/vuu-ui/sample-apps/feature-filter-table/src/useFilterTable.tsx index 5c7a039be..6639b420a 100644 --- a/vuu-ui/sample-apps/feature-filter-table/src/useFilterTable.tsx +++ b/vuu-ui/sample-apps/feature-filter-table/src/useFilterTable.tsx @@ -12,7 +12,7 @@ import { ActiveItemChangeHandler, useViewContext } from "@finos/vuu-layout"; import { useShellContext } from "@finos/vuu-shell"; import { applyDefaultColumnConfig } from "@finos/vuu-utils"; import { Button } from "@salt-ds/core"; -import { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import { useCallback, useMemo, useRef, useState } from "react"; import { useSessionDataSource } from "./useSessionDataSource"; import { FilterTableFeatureProps } from "./VuuFilterTableFeature"; @@ -161,13 +161,6 @@ export const useFilterTable = ({ tableSchema }: FilterTableFeatureProps) => { [load] ); - useEffect(() => { - dataSource.resume?.(); - return () => { - dataSource.suspend?.(); - }; - }, [dataSource]); - const { buildViewserverMenuOptions, handleMenuAction } = useVuuMenuActions({ dataSource, menuActionConfig,