Skip to content

Commit

Permalink
feat: add updated reloadItems method (#231)
Browse files Browse the repository at this point in the history
* feat: add updated reloadItems method

* fix: fix options argument in reloadItems
  • Loading branch information
artemipanchuk authored Dec 16, 2024
1 parent cc7c499 commit d86441c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/components/DashKit/DashKit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,8 @@ export class DashKit extends React.PureComponent<DashKitInnerProps> {
getItemsMeta() {
return this.metaRef.current?.getItemsMeta();
}

reloadItems(options?: {targetIds?: string[]; force?: boolean}) {
this.metaRef.current?.reloadItems(options);
}
}
17 changes: 14 additions & 3 deletions src/components/GridLayout/GridLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
}

Expand Down

0 comments on commit d86441c

Please sign in to comment.