@gravity-ui/dashkit 6.5.1 → 6.6.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/build/cjs/components/GridLayout/GridLayout.d.ts +4 -0
- package/build/cjs/components/GridLayout/GridLayout.js +35 -12
- package/build/cjs/hocs/withContext.js +2 -1
- package/build/cjs/typings/common.d.ts +3 -1
- package/build/esm/components/GridLayout/GridLayout.d.ts +4 -0
- package/build/esm/components/GridLayout/GridLayout.js +35 -12
- package/build/esm/hocs/withContext.js +2 -1
- package/build/esm/typings/common.d.ts +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,6 +120,21 @@ Before using `DashKit` as a react component, it must be configured.
|
|
|
120
120
|
});
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
+
## Settings
|
|
124
|
+
|
|
125
|
+
### Autoupdate
|
|
126
|
+
|
|
127
|
+
This functionality allows you to automatically update the items of the Dash. All items that should participate in the auto-update cycle must have the `reload` method.
|
|
128
|
+
There are two auto-update scenarios available, the first - the classic interval to enable which is enough to pass the `autoupdateInterval` parameter and the second - the so-called `realtimeMode`.
|
|
129
|
+
`realtimeMode` is useful in cases where dash items are updated at different rates and you cannot guarantee data consistency at a given time. `realtimeMode` is based on `Promise.allSettled`.
|
|
130
|
+
|
|
131
|
+
| Name | Description | Type | Default |
|
|
132
|
+
|:--------------------|:---------------------------------------------------------------------------------------|:---------:|:-------:|
|
|
133
|
+
| autoupdateInterval | The time, in **seconds**, the dash should delay in between executions auto-update | `number` | |
|
|
134
|
+
| realtimeMode | Enable realtime mode | `boolean` | |
|
|
135
|
+
| realtimeModeDelayMs | The time, in **milliseconds**, the dash should delay after all items have been updated | `number` | 5000 |
|
|
136
|
+
| silentLoading | Items update status indicator. It will be passed into the Item `reload` method | `boolean` | false |
|
|
137
|
+
|
|
123
138
|
### Config
|
|
124
139
|
|
|
125
140
|
```ts
|
|
@@ -18,6 +18,10 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
|
|
|
18
18
|
adjustedWidgetLayout: any;
|
|
19
19
|
}) => void;
|
|
20
20
|
getItemsMeta: () => any;
|
|
21
|
+
getAutoupdateIntervalMs(): number;
|
|
22
|
+
startReloadItems(): any;
|
|
23
|
+
startReloadItemsTimeout(timeoutMs: any): void;
|
|
24
|
+
forceReloadItems(): void;
|
|
21
25
|
reloadItems(): void;
|
|
22
26
|
_onStart: () => void;
|
|
23
27
|
_onStop: (newLayout: any) => void;
|
|
@@ -50,25 +50,48 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
50
50
|
document.addEventListener('visibilitychange', this.onVisibilityChange);
|
|
51
51
|
}
|
|
52
52
|
componentDidUpdate() {
|
|
53
|
-
|
|
54
|
-
this.reloadItems();
|
|
53
|
+
this.forceReloadItems();
|
|
55
54
|
}
|
|
56
55
|
componentWillUnmount() {
|
|
57
56
|
clearTimeout(this._timeout);
|
|
58
57
|
document.removeEventListener('visibilitychange', this.onVisibilityChange);
|
|
59
58
|
}
|
|
60
|
-
|
|
61
|
-
const {
|
|
62
|
-
const { isPageHidden } = this.state;
|
|
59
|
+
getAutoupdateIntervalMs() {
|
|
60
|
+
const { settings: { autoupdateInterval } = {} } = this.context;
|
|
63
61
|
const autoupdateIntervalMs = Number(autoupdateInterval) * 1000;
|
|
62
|
+
return autoupdateIntervalMs;
|
|
63
|
+
}
|
|
64
|
+
startReloadItems() {
|
|
65
|
+
const { editMode, settings: { silentLoading } = {}, reloadItems } = this.context;
|
|
66
|
+
const { isPageHidden } = this.state;
|
|
67
|
+
if (!isPageHidden && !editMode) {
|
|
68
|
+
this._lastReloadAt = new Date().getTime();
|
|
69
|
+
return reloadItems(this.pluginsRefs, { silentLoading, noVeil: true });
|
|
70
|
+
}
|
|
71
|
+
return Promise.resolve();
|
|
72
|
+
}
|
|
73
|
+
startReloadItemsTimeout(timeoutMs) {
|
|
74
|
+
this._timeout = setTimeout(() => this.forceReloadItems(), timeoutMs);
|
|
75
|
+
}
|
|
76
|
+
forceReloadItems() {
|
|
77
|
+
clearTimeout(this._timeout);
|
|
78
|
+
this._timeout = undefined;
|
|
79
|
+
this.reloadItems();
|
|
80
|
+
}
|
|
81
|
+
reloadItems() {
|
|
82
|
+
if (this._timeout)
|
|
83
|
+
return;
|
|
84
|
+
const { settings: { realtimeMode, realtimeModeDelayMs = 5000 } = {} } = this.context;
|
|
85
|
+
if (realtimeMode) {
|
|
86
|
+
this.startReloadItems().then(() => {
|
|
87
|
+
this.startReloadItemsTimeout(realtimeModeDelayMs);
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const autoupdateIntervalMs = this.getAutoupdateIntervalMs();
|
|
64
92
|
if (autoupdateIntervalMs) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (!isPageHidden && !editMode && reloadIntervalRemains <= 0) {
|
|
68
|
-
this._lastReloadAt = new Date().getTime();
|
|
69
|
-
reloadItems(this.pluginsRefs, { silentLoading, noVeil: true });
|
|
70
|
-
}
|
|
71
|
-
this._timeout = setTimeout(() => this.reloadItems(), reloadIntervalRemains <= 0 ? autoupdateIntervalMs : reloadIntervalRemains);
|
|
93
|
+
this.startReloadItems();
|
|
94
|
+
this.startReloadItemsTimeout(autoupdateIntervalMs);
|
|
72
95
|
}
|
|
73
96
|
}
|
|
74
97
|
render() {
|
|
@@ -121,7 +121,8 @@ function useMemoStateContext(props) {
|
|
|
121
121
|
});
|
|
122
122
|
}, [props.layout, layoutUpdateCounter]);
|
|
123
123
|
const reloadItems = react_1.default.useCallback((pluginsRefs, data) => {
|
|
124
|
-
pluginsRefs.
|
|
124
|
+
const promises = pluginsRefs.map((ref) => ref && ref.reload && ref.reload(data));
|
|
125
|
+
return Promise.allSettled(promises);
|
|
125
126
|
}, []);
|
|
126
127
|
return react_1.default.useMemo(() => ({
|
|
127
128
|
layout: resultLayout,
|
|
@@ -9,8 +9,10 @@ export interface Settings {
|
|
|
9
9
|
}
|
|
10
10
|
export type MenuItem = (typeof MenuItems)[keyof typeof MenuItems] | OverlayCustomControlItem;
|
|
11
11
|
export interface SettingsProps {
|
|
12
|
-
autoupdateInterval
|
|
12
|
+
autoupdateInterval?: number;
|
|
13
13
|
silentLoading: boolean;
|
|
14
|
+
realtimeMode?: boolean;
|
|
15
|
+
realtimeModeDelayMs?: number;
|
|
14
16
|
}
|
|
15
17
|
export interface ContextProps {
|
|
16
18
|
[key: string]: any;
|
|
@@ -18,6 +18,10 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
|
|
|
18
18
|
adjustedWidgetLayout: any;
|
|
19
19
|
}) => void;
|
|
20
20
|
getItemsMeta: () => any;
|
|
21
|
+
getAutoupdateIntervalMs(): number;
|
|
22
|
+
startReloadItems(): any;
|
|
23
|
+
startReloadItemsTimeout(timeoutMs: any): void;
|
|
24
|
+
forceReloadItems(): void;
|
|
21
25
|
reloadItems(): void;
|
|
22
26
|
_onStart: () => void;
|
|
23
27
|
_onStop: (newLayout: any) => void;
|
|
@@ -47,25 +47,48 @@ export default class GridLayout extends React.PureComponent {
|
|
|
47
47
|
document.addEventListener('visibilitychange', this.onVisibilityChange);
|
|
48
48
|
}
|
|
49
49
|
componentDidUpdate() {
|
|
50
|
-
|
|
51
|
-
this.reloadItems();
|
|
50
|
+
this.forceReloadItems();
|
|
52
51
|
}
|
|
53
52
|
componentWillUnmount() {
|
|
54
53
|
clearTimeout(this._timeout);
|
|
55
54
|
document.removeEventListener('visibilitychange', this.onVisibilityChange);
|
|
56
55
|
}
|
|
57
|
-
|
|
58
|
-
const {
|
|
59
|
-
const { isPageHidden } = this.state;
|
|
56
|
+
getAutoupdateIntervalMs() {
|
|
57
|
+
const { settings: { autoupdateInterval } = {} } = this.context;
|
|
60
58
|
const autoupdateIntervalMs = Number(autoupdateInterval) * 1000;
|
|
59
|
+
return autoupdateIntervalMs;
|
|
60
|
+
}
|
|
61
|
+
startReloadItems() {
|
|
62
|
+
const { editMode, settings: { silentLoading } = {}, reloadItems } = this.context;
|
|
63
|
+
const { isPageHidden } = this.state;
|
|
64
|
+
if (!isPageHidden && !editMode) {
|
|
65
|
+
this._lastReloadAt = new Date().getTime();
|
|
66
|
+
return reloadItems(this.pluginsRefs, { silentLoading, noVeil: true });
|
|
67
|
+
}
|
|
68
|
+
return Promise.resolve();
|
|
69
|
+
}
|
|
70
|
+
startReloadItemsTimeout(timeoutMs) {
|
|
71
|
+
this._timeout = setTimeout(() => this.forceReloadItems(), timeoutMs);
|
|
72
|
+
}
|
|
73
|
+
forceReloadItems() {
|
|
74
|
+
clearTimeout(this._timeout);
|
|
75
|
+
this._timeout = undefined;
|
|
76
|
+
this.reloadItems();
|
|
77
|
+
}
|
|
78
|
+
reloadItems() {
|
|
79
|
+
if (this._timeout)
|
|
80
|
+
return;
|
|
81
|
+
const { settings: { realtimeMode, realtimeModeDelayMs = 5000 } = {} } = this.context;
|
|
82
|
+
if (realtimeMode) {
|
|
83
|
+
this.startReloadItems().then(() => {
|
|
84
|
+
this.startReloadItemsTimeout(realtimeModeDelayMs);
|
|
85
|
+
});
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const autoupdateIntervalMs = this.getAutoupdateIntervalMs();
|
|
61
89
|
if (autoupdateIntervalMs) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (!isPageHidden && !editMode && reloadIntervalRemains <= 0) {
|
|
65
|
-
this._lastReloadAt = new Date().getTime();
|
|
66
|
-
reloadItems(this.pluginsRefs, { silentLoading, noVeil: true });
|
|
67
|
-
}
|
|
68
|
-
this._timeout = setTimeout(() => this.reloadItems(), reloadIntervalRemains <= 0 ? autoupdateIntervalMs : reloadIntervalRemains);
|
|
90
|
+
this.startReloadItems();
|
|
91
|
+
this.startReloadItemsTimeout(autoupdateIntervalMs);
|
|
69
92
|
}
|
|
70
93
|
}
|
|
71
94
|
render() {
|
|
@@ -117,7 +117,8 @@ function useMemoStateContext(props) {
|
|
|
117
117
|
});
|
|
118
118
|
}, [props.layout, layoutUpdateCounter]);
|
|
119
119
|
const reloadItems = React.useCallback((pluginsRefs, data) => {
|
|
120
|
-
pluginsRefs.
|
|
120
|
+
const promises = pluginsRefs.map((ref) => ref && ref.reload && ref.reload(data));
|
|
121
|
+
return Promise.allSettled(promises);
|
|
121
122
|
}, []);
|
|
122
123
|
return React.useMemo(() => ({
|
|
123
124
|
layout: resultLayout,
|
|
@@ -9,8 +9,10 @@ export interface Settings {
|
|
|
9
9
|
}
|
|
10
10
|
export type MenuItem = (typeof MenuItems)[keyof typeof MenuItems] | OverlayCustomControlItem;
|
|
11
11
|
export interface SettingsProps {
|
|
12
|
-
autoupdateInterval
|
|
12
|
+
autoupdateInterval?: number;
|
|
13
13
|
silentLoading: boolean;
|
|
14
|
+
realtimeMode?: boolean;
|
|
15
|
+
realtimeModeDelayMs?: number;
|
|
14
16
|
}
|
|
15
17
|
export interface ContextProps {
|
|
16
18
|
[key: string]: any;
|