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}); } }