From: Lucas Di Pentima Date: Fri, 8 Apr 2022 19:58:05 +0000 (-0300) Subject: 18972: Avoids data table flickering when reloading data on the same route. X-Git-Tag: 2.4.1~4^2~2 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/3dd4b3bc31fea7f614290131d0ade5c0e0ffc595 18972: Avoids data table flickering when reloading data on the same route. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/src/components/data-table/data-table.tsx b/src/components/data-table/data-table.tsx index e8a6ce69..14dfdaca 100644 --- a/src/components/data-table/data-table.tsx +++ b/src/components/data-table/data-table.tsx @@ -86,7 +86,7 @@ type DataTableProps = DataTableDataProps & WithStyles; export const DataTable = withStyles(styles)( class Component extends React.Component> { render() { - const { items, classes } = this.props; + const { items, classes, working } = this.props; return
@@ -96,16 +96,16 @@ export const DataTable = withStyles(styles)( - { this.props.working !== undefined && !this.props.working && items.map(this.renderBodyRow) } + { !working && items.map(this.renderBodyRow) }
- { this.props.working && + { !!working &&
} - {items.length === 0 && this.props.working !== undefined && !this.props.working && this.renderNoItemsPlaceholder()} + {items.length === 0 && !working && this.renderNoItemsPlaceholder()}
; } diff --git a/src/views-components/data-explorer/data-explorer.tsx b/src/views-components/data-explorer/data-explorer.tsx index 900ab94e..8db551e8 100644 --- a/src/views-components/data-explorer/data-explorer.tsx +++ b/src/views-components/data-explorer/data-explorer.tsx @@ -21,8 +21,9 @@ interface Props { working?: boolean; } -let data: any[] = []; -let href: string = ''; +let prevRoute = ''; +let routeChanged = false; +let isWorking = false; const mapStateToProps = (state: RootState, { id }: Props) => { const progress = state.progressIndicator.find(p => p.id === id); @@ -30,16 +31,20 @@ const mapStateToProps = (state: RootState, { id }: Props) => { const currentRoute = state.router.location ? state.router.location.pathname : ''; const currentItemUuid = currentRoute === '/workflows' ? state.properties.workflowPanelDetailsUuid : state.detailsPanel.resourceUuid; - let loading = false; - - if (dataExplorerState.items.length > 0 && data === dataExplorerState.items && href !== window.location.href) { - loading = true - } else { - href = window.location.href; - data = dataExplorerState.items; + if (currentRoute !== prevRoute) { + routeChanged = true; + prevRoute = currentRoute; + } + if (progress?.working) { + isWorking = true; } - const working = (progress && progress.working) || loading; + const working = routeChanged && isWorking; + + if (working && !progress?.working) { + routeChanged = false; + isWorking = false; + } return { ...dataExplorerState, working, paperKey: currentRoute, currentItemUuid }; }; @@ -86,5 +91,5 @@ const mapDispatchToProps = () => { }); }; -export const DataExplorer = connect(mapStateToProps, mapDispatchToProps())(DataExplorerComponent); +export const DataExplorer = connect(mapStateToProps, mapDispatchToProps)(DataExplorerComponent);