Skip to content

Commit b6a3b8b

Browse files
authored
[WC-1054]: refresh on interval for data grid 2 (#179)
2 parents 08c30c6 + 5efc470 commit b6a3b8b

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

packages/pluggableWidgets/datagrid-web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- We added _Refresh time_ setting to Datagrid, this allows automatic data refresh.
12+
913
### Changed
1014

1115
- We improved structure preview of the widget in Studio Pro 9.20 and above.

packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ export default function Datagrid(props: DatagridContainerProps): ReactElement {
4242
}
4343
}, [props.datasource, props.configurationAttribute, filtered]);
4444

45+
useEffect(() => {
46+
if (props.refreshInterval > 0) {
47+
setTimeout(() => {
48+
props.datasource.reload();
49+
}, props.refreshInterval * 1000);
50+
}
51+
}, [props.datasource, props.refreshInterval]);
52+
4553
const setPage = useCallback(
4654
computePage => {
4755
const newPage = computePage(currentPage);

packages/pluggableWidgets/datagrid-web/src/Datagrid.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
<caption>Data source</caption>
1717
<description />
1818
</property>
19+
<property key="refreshInterval" type="integer" defaultValue="0">
20+
<caption>Refresh time (in seconds)</caption>
21+
<description />
22+
</property>
1923
</propertyGroup>
2024
<propertyGroup caption="Columns">
2125
<property key="columns" type="object" isList="true">

packages/pluggableWidgets/datagrid-web/typings/DatagridProps.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export interface DatagridContainerProps {
7474
tabIndex?: number;
7575
advanced: boolean;
7676
datasource: ListValue;
77+
refreshInterval: number;
7778
columns: ColumnsType[];
7879
columnsFilterable: boolean;
7980
pageSize: number;
@@ -105,6 +106,7 @@ export interface DatagridPreviewProps {
105106
readOnly: boolean;
106107
advanced: boolean;
107108
datasource: {} | { type: string } | null;
109+
refreshInterval: number | null;
108110
columns: ColumnsPreviewType[];
109111
columnsFilterable: boolean;
110112
pageSize: number | null;

0 commit comments

Comments
 (0)