From 139421ac9ab6a7f60ad7762d1787d79533ce6831 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Tue, 12 Apr 2022 11:32:41 -0300 Subject: [PATCH] 18972: Records the last refresh click on localStorage for others to act on. Adding timestamps on the store isn't recommended as the reducers should be only pure functions so I opted to use the localStorage for this application. The DataExplorer code now also checks if the last Refresh button click timestamp changed to decide if it should show the "loading, please wait" message. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- .../refresh-button/refresh-button.test.tsx | 4 +- .../refresh-button/refresh-button.tsx | 5 ++ .../data-explorer/data-explorer.tsx | 7 +- .../main-content-bar/main-content-bar.tsx | 77 +++++++++---------- 4 files changed, 49 insertions(+), 44 deletions(-) diff --git a/src/components/refresh-button/refresh-button.test.tsx b/src/components/refresh-button/refresh-button.test.tsx index f9fa32d2..3a9292e6 100644 --- a/src/components/refresh-button/refresh-button.test.tsx +++ b/src/components/refresh-button/refresh-button.test.tsx @@ -6,7 +6,7 @@ import React from "react"; import { Button } from "@material-ui/core"; import { shallow, configure } from "enzyme"; import Adapter from "enzyme-adapter-react-16"; -import { RefreshButton } from './refresh-button'; +import { LAST_REFRESH_TIMESTAMP, RefreshButton } from './refresh-button'; configure({ adapter: new Adapter() }); @@ -31,6 +31,7 @@ describe('', () => { }); it('should pass window location to router', () => { + expect(localStorage.getItem(LAST_REFRESH_TIMESTAMP)).toBeFalsy(); // setup const wrapper = shallow(); @@ -39,5 +40,6 @@ describe('', () => { // then expect(props.history.replace).toHaveBeenCalledWith('/'); + expect(localStorage.getItem(LAST_REFRESH_TIMESTAMP)).not.toBeFalsy(); }); }); diff --git a/src/components/refresh-button/refresh-button.tsx b/src/components/refresh-button/refresh-button.tsx index 9971547b..e2fe5484 100644 --- a/src/components/refresh-button/refresh-button.tsx +++ b/src/components/refresh-button/refresh-button.tsx @@ -26,12 +26,17 @@ interface RefreshButtonProps { onClick?: () => void; } +export const LAST_REFRESH_TIMESTAMP = 'lastRefreshTimestamp'; + export const RefreshButton = ({ history, classes, onClick }: RouteComponentProps & WithStyles & RefreshButtonProps) =>