From d86441cac8f49ab302a39b2ba2484b1a21dcb6e5 Mon Sep 17 00:00:00 2001 From: "Artem I. Panchuk" Date: Mon, 16 Dec 2024 17:37:50 +0300 Subject: [PATCH] feat: add updated reloadItems method (#231) * feat: add updated reloadItems method * fix: fix options argument in reloadItems --- src/components/DashKit/DashKit.tsx | 4 ++++ src/components/GridLayout/GridLayout.js | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/components/DashKit/DashKit.tsx b/src/components/DashKit/DashKit.tsx index 4818018..e063078 100644 --- a/src/components/DashKit/DashKit.tsx +++ b/src/components/DashKit/DashKit.tsx @@ -222,4 +222,8 @@ export class DashKit extends React.PureComponent { getItemsMeta() { return this.metaRef.current?.getItemsMeta(); } + + reloadItems(options?: {targetIds?: string[]; force?: boolean}) { + this.metaRef.current?.reloadItems(options); + } } diff --git a/src/components/GridLayout/GridLayout.js b/src/components/GridLayout/GridLayout.js index 6c65d8f..0ba6f22 100644 --- a/src/components/GridLayout/GridLayout.js +++ b/src/components/GridLayout/GridLayout.js @@ -204,27 +204,38 @@ export default class GridLayout extends React.PureComponent { }); } - reloadItems() { + reloadItems(options) { + const {targetIds, force} = options || {}; + const { editMode, settings: {autoupdateInterval, silentLoading} = {}, reloadItems, } = this.context; + const {isPageHidden} = this.state; + const autoupdateIntervalMs = Number(autoupdateInterval) * 1000; + + const targetPlugins = targetIds + ? this.pluginsRefs.filter((plugin) => targetIds.includes(plugin.props.id)) + : this.pluginsRefs; + if (autoupdateIntervalMs) { const timeSinceLastReload = new Date().getTime() - (this._lastReloadAt || 0); const reloadIntervalRemains = autoupdateIntervalMs - timeSinceLastReload; - if (!isPageHidden && !editMode && reloadIntervalRemains <= 0) { + if (force || (!isPageHidden && !editMode && reloadIntervalRemains <= 0)) { this._lastReloadAt = new Date().getTime(); - reloadItems(this.pluginsRefs, {silentLoading, noVeil: true}); + reloadItems(targetPlugins, {silentLoading, noVeil: true}); } this._timeout = setTimeout( () => this.reloadItems(), reloadIntervalRemains <= 0 ? autoupdateIntervalMs : reloadIntervalRemains, ); + } else if (force || (!isPageHidden && !editMode)) { + reloadItems(targetPlugins, {silentLoading, noVeil: true}); } }