diff --git a/packages/datalib/src/PerspectiveDisplay.ts b/packages/datalib/src/PerspectiveDisplay.ts index f7da90c53..4781ae318 100644 --- a/packages/datalib/src/PerspectiveDisplay.ts +++ b/packages/datalib/src/PerspectiveDisplay.ts @@ -3,6 +3,9 @@ import _max from 'lodash/max'; import _range from 'lodash/max'; import _fill from 'lodash/fill'; import _findIndex from 'lodash/findIndex'; +import debug from 'debug'; + +const dbg = debug('dbgate:PerspectiveDisplay'); export class PerspectiveDisplayColumn { title: string; @@ -53,6 +56,7 @@ interface CollectedPerspectiveDisplayRow { rowData: any[]; // rowSpans: number[] = null; subRowCollections: PerspectiveSubRowCollection[]; + incompleteRowsIndicator?: string[]; } export class PerspectiveDisplayRow { @@ -73,6 +77,7 @@ export class PerspectiveDisplayRow { rowData: any[] = []; rowSpans: number[] = null; + incompleteRowsIndicator: string[] = null; } export class PerspectiveDisplay { @@ -81,12 +86,15 @@ export class PerspectiveDisplay { readonly columnLevelCount: number; constructor(public root: PerspectiveTreeNode, rows: any[]) { + // dbg('source rows', rows); this.fillColumns(root.childNodes, []); this.columnLevelCount = _max(this.columns.map(x => x.parentNodes.length)) + 1; const collectedRows = this.collectRows(rows, root.childNodes); + // dbg('collected rows', collectedRows); // console.log('COLLECTED', collectedRows); // this.mergeRows(collectedRows); this.mergeRows(collectedRows); + // dbg('merged rows', this.rows); // console.log('MERGED', this.rows); } @@ -163,6 +171,7 @@ export class PerspectiveDisplay { rowData, columnIndexes, subRowCollections, + incompleteRowsIndicator: sourceRow.incompleteRowsIndicator, }); } @@ -212,6 +221,7 @@ export class PerspectiveDisplay { for (let i = 0; i < collectedRow.columnIndexes.length; i++) { resultRow.rowData[collectedRow.columnIndexes[i]] = collectedRow.rowData[i]; } + resultRow.incompleteRowsIndicator = collectedRow.incompleteRowsIndicator; for (const subrows of collectedRow.subRowCollections) { let rowIndex = 0; diff --git a/packages/web/src/perspectives/PerspectiveIntersectionObserver.svelte b/packages/web/src/perspectives/PerspectiveIntersectionObserver.svelte new file mode 100644 index 000000000..4951c7fc7 --- /dev/null +++ b/packages/web/src/perspectives/PerspectiveIntersectionObserver.svelte @@ -0,0 +1,33 @@ + + +
... data to be loaded
diff --git a/packages/web/src/perspectives/PerspectiveTable.svelte b/packages/web/src/perspectives/PerspectiveTable.svelte index 4e35a07cf..669ada76e 100644 --- a/packages/web/src/perspectives/PerspectiveTable.svelte +++ b/packages/web/src/perspectives/PerspectiveTable.svelte @@ -11,23 +11,37 @@ import { prop_dev, tick } from 'svelte/internal'; import { sleep } from '../utility/common'; import resizeObserver from '../utility/resizeObserver'; + import PerspectiveIntersectionObserver from './PerspectiveIntersectionObserver.svelte'; + import debug from 'debug'; + + const dbg = debug('dbgate:PerspectivaTable'); export let root: PerspectiveTreeNode; + export let loadedCounts; let dataRows; let domWrapper; let domTableHead; let domHeaderWrap; let theadClone; - async function loadLevelData(node: PerspectiveTreeNode, parentRows: any[]) { + async function loadLevelData(node: PerspectiveTreeNode, parentRows: any[], counts) { + dbg('load level data', counts); // const loadProps: PerspectiveDataLoadPropsWithNode[] = []; const loadChildNodes = []; const loadChildRows = []; const loadProps = node.getNodeLoadProps(parentRows); - const { rows, incomplete } = await node.dataProvider.loadData({ + let { rows, incomplete } = await node.dataProvider.loadData({ ...loadProps, - topCount: 100, + topCount: counts[node.uniqueName] || 100, }); + if (incomplete) { + rows = [ + ...rows, + { + incompleteRowsIndicator: [node.uniqueName], + }, + ]; + } // console.log('ROWS', rows, node.isRoot); if (node.isRoot) { @@ -42,7 +56,7 @@ for (const child of node.childNodes) { if (child.isExpandable && child.isChecked) { - await loadLevelData(child, rows); + await loadLevelData(child, rows, counts); // loadProps.push(child.getNodeLoadProps()); } } @@ -63,11 +77,11 @@ // } } - async function loadData(node: PerspectiveTreeNode) { + async function loadData(node: PerspectiveTreeNode, counts) { // console.log('LOADING', node); if (!node) return; const rows = []; - await loadLevelData(node, rows); + await loadLevelData(node, rows, counts); dataRows = rows; // console.log('DISPLAY ROWS', rows); @@ -102,7 +116,7 @@ onMount(() => {}); - $: loadData(root); + $: loadData(root, $loadedCounts); $: display = root && dataRows ? new PerspectiveDisplay(root, dataRows) : null; $: { @@ -137,12 +151,30 @@ {#each display.rows as row} - {#each display.columns as column} - - {#if row.rowData[column.columnIndex] !== undefined} - {row.rowData[column.columnIndex]} - {/if} - {/each} + {#if row.incompleteRowsIndicator} + { + dbg('load next', row.incompleteRowsIndicator); + loadedCounts.update(counts => { + const res = { ...counts }; + for (const id of row.incompleteRowsIndicator) { + res[id] = (res[id] || 100) + 100; + } + return res; + }); + }} + /> + {:else} + {#each display.columns as column} + + {#if row.rowData[column.columnIndex] !== undefined} + {row.rowData[column.columnIndex]} + {/if} + {/each} + {/if} {/each} diff --git a/packages/web/src/perspectives/PerspectiveView.svelte b/packages/web/src/perspectives/PerspectiveView.svelte index 4d3135fce..9a58149dc 100644 --- a/packages/web/src/perspectives/PerspectiveView.svelte +++ b/packages/web/src/perspectives/PerspectiveView.svelte @@ -35,6 +35,7 @@ export let config; export let setConfig; + export let loadedCounts; export let cache; @@ -58,7 +59,15 @@ $: dataProvider = new PerspectiveDataProvider(cache, loader); $: loader = new PerspectiveDataLoader(apiCall); $: root = $tableInfo - ? new PerspectiveTableNode($tableInfo, $dbInfo, config, setConfig, dataProvider, { conid, database }, null) + ? new PerspectiveTableNode( + $tableInfo, + $dbInfo, + config, + setConfig, + dataProvider, + { conid, database }, + null + ) : null; @@ -76,7 +85,7 @@ - + diff --git a/packages/web/src/tabs/PerspectiveTab.svelte b/packages/web/src/tabs/PerspectiveTab.svelte index 4e94a4e7f..56e1e940d 100644 --- a/packages/web/src/tabs/PerspectiveTab.svelte +++ b/packages/web/src/tabs/PerspectiveTab.svelte @@ -4,6 +4,7 @@ import PerspectiveView from '../perspectives/PerspectiveView.svelte'; import usePerspectiveConfig from '../utility/usePerspectiveConfig'; import stableStringify from 'json-stable-stringify'; + import { writable } from 'svelte/store'; export let tabid; export let conid; @@ -13,6 +14,16 @@ const config = usePerspectiveConfig(tabid); const cache = new PerspectiveCache(stableStringify); + const loadedCounts = writable({}); - + diff --git a/packages/web/src/utility/usePerspectiveConfig.ts b/packages/web/src/utility/usePerspectiveConfig.ts index f8ae08fc7..e5c210419 100644 --- a/packages/web/src/utility/usePerspectiveConfig.ts +++ b/packages/web/src/utility/usePerspectiveConfig.ts @@ -25,10 +25,3 @@ export default function usePerspectiveConfig(tabid) { onDestroy(unsubscribe); return config; } - -// export function usePerspectiveCache() { -// const cache = writable({ -// tables: {}, -// }); -// return cache; -// }