Skip to content

[WC-2838]: Implement RefreshIndicator component on Datagrid 2 #1765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
62a72ae
feat(datagrid-web): add RefreshIndicator component and styles for loa…
samuelreichert Jul 11, 2025
8214fe0
feat(datagrid-web): add refresh indicator property to Datagrid2
samuelreichert Jul 14, 2025
63b3b92
feat(datagrid-web): add refreshIndicator prop to Datagrid component
samuelreichert Jul 14, 2025
02769d0
feat(datagrid-web): add refreshIndicator prop to Widget and update Gr…
samuelreichert Jul 14, 2025
f183837
feat(datagrid-web): add refreshIndicator prop to preview function and…
samuelreichert Jul 14, 2025
9bcfbe0
refactor(datagrid-web): remove unused isLoading prop and related code…
samuelreichert Jul 14, 2025
6acb084
chore(datagrid-web): update changelog
samuelreichert Jul 14, 2025
46ee759
feat(datagrid-web): replace isLoading with isFirstLoad and update rel…
samuelreichert Jul 21, 2025
f6af148
feat(datagrid-web): add show prop to RefreshIndicator and update usag…
samuelreichert Jul 22, 2025
d79c5b5
refactor(datagrid-web): simplify RefreshIndicator usage
samuelreichert Jul 23, 2025
7899a5a
docs(datagrid-web): clarify description of the refresh indicator feat…
samuelreichert Jul 23, 2025
7738ca7
feat(datagrid-web): increase refresh indicator animation timing
samuelreichert Jul 31, 2025
b565ffe
feat(datagrid-web): dont show refresh indicator when resfreh timer is…
samuelreichert Jul 31, 2025
d4a602b
chore(datagrid-web): add disposeBatch to follow standards on controllers
samuelreichert Jul 31, 2025
259cacd
test(widget-plugin-grid): fix tests to follow more real world scenari…
samuelreichert Jul 31, 2025
eabf016
test(widget-plugin-grid): run controller setup to all test cases
samuelreichert Jul 31, 2025
0e6dbc8
feat(widget-plugin-grid): move showRefreshIndicator to DatasourceCont…
samuelreichert Jul 31, 2025
2a45a9d
refactor: change flags
iobuhov Aug 4, 2025
36edfa6
test(widget-plugin-grid): enhance DatasourceController tests for load…
samuelreichert Aug 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,86 @@ $root: ".widget-datagrid";
display: contents;
}

&-refresh-container {
grid-column: 1 / -1;
padding: 0;
position: relative;
}

&-refresh-indicator {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background-color: var(--border-color-default, #ced0d3);
border: none;
border-radius: 2px;
color: var(--brand-primary, $dg-brand-primary);
height: 4px;
width: 100%;
position: absolute;
left: 0;
right: 0;

&::-webkit-progress-bar {
background-color: transparent;
}

&::-webkit-progress-value {
background-color: currentColor;
transition: all 0.2s;
}

&::-moz-progress-bar {
background-color: currentColor;
transition: all 0.2s;
}

&::-ms-fill {
border: none;
background-color: currentColor;
transition: all 0.2s;
}

&:indeterminate {
background-size: 200% 100%;
background-image: linear-gradient(
to right,
transparent 50%,
currentColor 50%,
currentColor 60%,
transparent 60%,
transparent 71.5%,
currentColor 71.5%,
currentColor 84%,
transparent 84%
);
animation: progress-linear 3s infinite linear;
}

&:indeterminate::-moz-progress-bar {
background-color: transparent;
}

&:indeterminate::-ms-fill {
animation-name: none;
}

@keyframes progress-linear {
0% {
background-size: 200% 100%;
background-position: left -31.25% top 0%;
}
50% {
background-size: 800% 100%;
background-position: left -49% top 0%;
}
100% {
background-size: 400% 100%;
background-position: left -102% top 0%;
}
}
}

&.widget-datagrid-selection-method-click {
.tr.tr-selected .td {
background-color: $dg-grid-selected-row-background;
Expand Down
4 changes: 4 additions & 0 deletions packages/pluggableWidgets/datagrid-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added

- We implemented a new property to show a refresh indicator. With the refresh indicator, any datasource change shows a progress bar on top of Datagrid 2.

## [3.0.1] - 2025-08-05

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,12 @@ export function preview(props: DatagridPreviewProps): ReactElement {
cellEventsController={eventsController}
checkboxEventsController={eventsController}
focusController={focusController}
isFirstLoad={false}
isLoading={false}
isFetchingNextBatch={false}
loadingType="spinner"
columnsLoading={false}
showRefreshIndicator={false}
/>
);
}
Expand Down
18 changes: 10 additions & 8 deletions packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { useOnResetFiltersEvent } from "@mendix/widget-plugin-external-events/hooks";
import { useClickActionHelper } from "@mendix/widget-plugin-grid/helpers/ClickActionHelper";
import { useFocusTargetController } from "@mendix/widget-plugin-grid/keyboard-navigation/useFocusTargetController";
import { useSelectionHelper } from "@mendix/widget-plugin-grid/selection";
import { generateUUID } from "@mendix/widget-plugin-platform/framework/generate-uuid";
import { observer } from "mobx-react-lite";
import { ReactElement, ReactNode, createElement, useCallback, useMemo } from "react";
import { DatagridContainerProps } from "../typings/DatagridProps";
import { Cell } from "./components/Cell";
import { Widget } from "./components/Widget";
import { WidgetHeaderContext } from "./components/WidgetHeaderContext";
import { useSelectActionHelper } from "./helpers/SelectActionHelper";
import { useClickActionHelper } from "@mendix/widget-plugin-grid/helpers/ClickActionHelper";
import { ProgressStore } from "./features/data-export/ProgressStore";
import { useDataExport } from "./features/data-export/useDataExport";
import { useCellEventsController } from "./features/row-interaction/CellEventsController";
import { useCheckboxEventsController } from "./features/row-interaction/CheckboxEventsController";
import { useFocusTargetController } from "@mendix/widget-plugin-grid/keyboard-navigation/useFocusTargetController";
import { useOnResetFiltersEvent } from "@mendix/widget-plugin-external-events/hooks";
import { useSelectActionHelper } from "./helpers/SelectActionHelper";
import { IColumnGroupStore } from "./helpers/state/ColumnGroupStore";
import { observer } from "mobx-react-lite";
import { RootGridStore } from "./helpers/state/RootGridStore";
import { useRootStore } from "./helpers/state/useRootStore";
import { useDataExport } from "./features/data-export/useDataExport";
import { ProgressStore } from "./features/data-export/ProgressStore";

interface Props extends DatagridContainerProps {
columnsStore: IColumnGroupStore;
Expand Down Expand Up @@ -118,10 +118,12 @@ const Container = observer((props: Props): ReactElement => {
cellEventsController={cellEventsController}
checkboxEventsController={checkboxEventsController}
focusController={focusController}
isLoading={rootStore.loaderCtrl.isLoading}
isFirstLoad={rootStore.loaderCtrl.isFirstLoad}
isFetchingNextBatch={rootStore.loaderCtrl.isFetchingNextBatch}
isLoading={props.datasource.status === "loading"}
loadingType={props.loadingType}
columnsLoading={!columnsStore.loaded}
showRefreshIndicator={rootStore.loaderCtrl.showRefreshIndicator}
/>
);
});
Expand Down
4 changes: 4 additions & 0 deletions packages/pluggableWidgets/datagrid-web/src/Datagrid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
<enumerationValue key="skeleton">Skeleton</enumerationValue>
</enumerationValues>
</property>
<property key="refreshIndicator" type="boolean" defaultValue="false">
<caption>Show refresh indicator</caption>
<description>Show a refresh indicator when the data is being loaded.</description>
</property>
</propertyGroup>
<propertyGroup caption="Columns">
<property key="columns" type="object" isList="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface Props {
className?: string;
children?: React.ReactNode;
loadingType: LoadingTypeEnum;
isLoading: boolean;
isFirstLoad: boolean;
isFetchingNextBatch?: boolean;
columnsHidable: boolean;
columnsSize: number;
Expand All @@ -20,7 +20,7 @@ export function GridBody(props: Props): ReactElement {
const { children } = props;

const content = (): React.ReactElement => {
if (props.isLoading) {
if (props.isFirstLoad) {
return <Loader {...props} rowsSize={props.rowsSize > 0 ? props.rowsSize : props.pageSize} />;
}
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createElement, ReactElement } from "react";

export function RefreshIndicator(): ReactElement {
return (
<div className="tr" role="row">
<div className="th widget-datagrid-refresh-container">
<progress className="widget-datagrid-refresh-indicator" />
</div>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { FocusTargetController } from "@mendix/widget-plugin-grid/keyboard-navig
import { observer } from "mobx-react-lite";
import { RowsRenderer } from "./RowsRenderer";
import { GridHeader } from "./GridHeader";
import { RefreshIndicator } from "./RefreshIndicator";

export interface WidgetProps<C extends GridColumn, T extends ObjectItem = ObjectItem> {
CellComponent: CellComponent<C>;
Expand Down Expand Up @@ -65,10 +66,12 @@ export interface WidgetProps<C extends GridColumn, T extends ObjectItem = Object
cancelExportLabel?: string;
selectRowLabel?: string;
selectAllRowsLabel?: string;
isFirstLoad: boolean;
isLoading: boolean;
isFetchingNextBatch: boolean;
loadingType: LoadingTypeEnum;
columnsLoading: boolean;
showRefreshIndicator: boolean;

// Helpers
cellEventsController: EventsController;
Expand Down Expand Up @@ -131,6 +134,7 @@ const Main = observer(<C extends GridColumn>(props: WidgetProps<C>): ReactElemen
paging,
pagingPosition,
preview,
showRefreshIndicator,
selectActionHelper,
setPage,
visibleColumns
Expand Down Expand Up @@ -189,8 +193,9 @@ const Main = observer(<C extends GridColumn>(props: WidgetProps<C>): ReactElemen
isLoading={props.columnsLoading}
preview={props.preview}
/>
{showRefreshIndicator ? <RefreshIndicator /> : null}
<GridBody
isLoading={props.isLoading}
isFirstLoad={props.isFirstLoad}
isFetchingNextBatch={props.isFetchingNextBatch}
loadingType={props.loadingType}
columnsHidable={columnsHidable}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import { computed, makeObservable } from "mobx";

type DerivedLoaderControllerSpec = {
showSilentRefresh: boolean;
refreshIndicator: boolean;
exp: { exporting: boolean };
cols: { loaded: boolean };
query: { isFetchingNextBatch: boolean; isLoading: boolean; isRefreshing: boolean };
query: {
isFetchingNextBatch: boolean;
isFirstLoad: boolean;
isRefreshing: boolean;
isSilentRefresh: boolean;
};
};

export class DerivedLoaderController {
constructor(private spec: DerivedLoaderControllerSpec) {
makeObservable(this, {
isLoading: computed,
isFirstLoad: computed,
isFetchingNextBatch: computed,
isRefreshing: computed
});
}

get isLoading(): boolean {
get isFirstLoad(): boolean {
const { cols, exp, query } = this.spec;
if (!cols.loaded) {
return true;
Expand All @@ -25,14 +32,28 @@ export class DerivedLoaderController {
return false;
}

return query.isLoading;
return query.isFirstLoad;
}

get isFetchingNextBatch(): boolean {
return this.spec.query.isFetchingNextBatch;
}

get isRefreshing(): boolean {
return this.spec.query.isRefreshing;
const { isSilentRefresh, isRefreshing } = this.spec.query;

if (this.spec.showSilentRefresh) {
return isSilentRefresh || isRefreshing;
}

return !isSilentRefresh && isRefreshing;
}

get showRefreshIndicator(): boolean {
if (!this.spec.refreshIndicator) {
return false;
}

return this.isRefreshing;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export class RootGridStore extends BaseControllerHost {
this.loaderCtrl = new DerivedLoaderController({
exp: exportCtrl,
cols: columns,
showSilentRefresh: props.refreshInterval > 1,
refreshIndicator: props.refreshIndicator,
query
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ export function mockWidgetProps(): WidgetProps<GridColumn, ObjectItem> {
selectActionHelper: mockSelectionProps(),
cellEventsController: { getProps: () => Object.create({}) },
checkboxEventsController: { getProps: () => Object.create({}) },
isFirstLoad: false,
isLoading: false,
isFetchingNextBatch: false,
loadingType: "spinner",
columnsLoading: false,
showRefreshIndicator: false,
focusController: new FocusTargetController(
new PositionController(),
new VirtualGridLayout(1, columns.length, 10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export interface DatagridContainerProps {
itemSelectionMode: ItemSelectionModeEnum;
showSelectAllToggle: boolean;
loadingType: LoadingTypeEnum;
refreshIndicator: boolean;
columns: ColumnsType[];
columnsFilterable: boolean;
pageSize: number;
Expand Down Expand Up @@ -144,6 +145,7 @@ export interface DatagridPreviewProps {
itemSelectionMode: ItemSelectionModeEnum;
showSelectAllToggle: boolean;
loadingType: LoadingTypeEnum;
refreshIndicator: boolean;
columns: ColumnsPreviewType[];
columnsFilterable: boolean;
pageSize: number | null;
Expand Down
Loading
Loading