diff --git a/ui/src/Components/Fetcher/index.js b/ui/src/Components/Fetcher/index.js index 3b61906a0..c32d21f7b 100644 --- a/ui/src/Components/Fetcher/index.js +++ b/ui/src/Components/Fetcher/index.js @@ -25,20 +25,16 @@ const Fetcher = observer( }, markCompleted() { this.completedAt = moment(); - }, - forceUpdate() { - this.time = moment(0); } }, { update: action, - markCompleted: action, - forceUpdate: action + markCompleted: action } ); getSortSettings = () => { - const { alertStore, settingsStore } = this.props; + const { settingsStore } = this.props; let sortSettings = { useDefaults: false, @@ -55,7 +51,7 @@ const Fetcher = observer( return sortSettings; } - sortSettings.sortOrder = alertStore.settings.values.sorting.grid.order; + sortSettings.sortOrder = settingsStore.gridConfig.config.sortOrder; // don't sort if sorting is disabled if ( @@ -71,7 +67,7 @@ const Fetcher = observer( : "0" : ""; - if (settingsStore.gridConfig.config.sortLabel === null) { + if (settingsStore.gridConfig.config.sortLabel !== null) { sortSettings.sortLabel = settingsStore.gridConfig.config.sortLabel; } diff --git a/ui/src/Components/Fetcher/index.test.js b/ui/src/Components/Fetcher/index.test.js index 26245a425..ada3c8fce 100644 --- a/ui/src/Components/Fetcher/index.test.js +++ b/ui/src/Components/Fetcher/index.test.js @@ -139,6 +139,88 @@ describe("", () => { expect(fetchSpy).toHaveBeenCalledTimes(4); }); + it("calls alertStore.fetchWithThrottle with empty sort arguments when sortOrder=default", () => { + MockEmptyAPIResponseWithoutFilters(); + const fetchSpy = jest.spyOn(alertStore, "fetchWithThrottle"); + settingsStore.gridConfig.config.sortOrder = + settingsStore.gridConfig.options.default.value; + MountedFetcher(); + expect(fetchSpy).toHaveBeenCalledWith("", "", ""); + }); + + it("calls alertStore.fetchWithThrottle with correct sort arguments when sortOrder=disabled reverseSort=false", () => { + MockEmptyAPIResponseWithoutFilters(); + const fetchSpy = jest.spyOn(alertStore, "fetchWithThrottle"); + settingsStore.gridConfig.config.sortOrder = + settingsStore.gridConfig.options.disabled.value; + settingsStore.gridConfig.config.reverseSort = false; + MountedFetcher(); + expect(fetchSpy).toHaveBeenCalledWith("disabled", "", ""); + }); + + it("calls alertStore.fetchWithThrottle with correct sort arguments when sortOrder=disabled reverseSort=true", () => { + MockEmptyAPIResponseWithoutFilters(); + const fetchSpy = jest.spyOn(alertStore, "fetchWithThrottle"); + settingsStore.gridConfig.config.sortOrder = + settingsStore.gridConfig.options.disabled.value; + settingsStore.gridConfig.config.reverseSort = true; + MountedFetcher(); + expect(fetchSpy).toHaveBeenCalledWith("disabled", "", ""); + }); + + it("calls alertStore.fetchWithThrottle with correct sort arguments when sortOrder=startsAt reverseSort=false", () => { + MockEmptyAPIResponseWithoutFilters(); + const fetchSpy = jest.spyOn(alertStore, "fetchWithThrottle"); + settingsStore.gridConfig.config.sortOrder = + settingsStore.gridConfig.options.startsAt.value; + settingsStore.gridConfig.config.reverseSort = false; + MountedFetcher(); + expect(fetchSpy).toHaveBeenCalledWith("startsAt", "", "0"); + }); + + it("calls alertStore.fetchWithThrottle with correct sort arguments when sortOrder=startsAt reverseSort=true", () => { + MockEmptyAPIResponseWithoutFilters(); + const fetchSpy = jest.spyOn(alertStore, "fetchWithThrottle"); + settingsStore.gridConfig.config.sortOrder = + settingsStore.gridConfig.options.startsAt.value; + settingsStore.gridConfig.config.reverseSort = true; + MountedFetcher(); + expect(fetchSpy).toHaveBeenCalledWith("startsAt", "", "1"); + }); + + it("calls alertStore.fetchWithThrottle with correct sort arguments when sortOrder=label sortLabel=cluster reverseSort=false", () => { + MockEmptyAPIResponseWithoutFilters(); + const fetchSpy = jest.spyOn(alertStore, "fetchWithThrottle"); + settingsStore.gridConfig.config.sortOrder = + settingsStore.gridConfig.options.label.value; + settingsStore.gridConfig.config.sortLabel = "cluster"; + settingsStore.gridConfig.config.reverseSort = false; + MountedFetcher(); + expect(fetchSpy).toHaveBeenCalledWith("label", "cluster", "0"); + }); + + it("calls alertStore.fetchWithThrottle with correct sort arguments when sortOrder=label sortLabel=job reverseSort=true", () => { + MockEmptyAPIResponseWithoutFilters(); + const fetchSpy = jest.spyOn(alertStore, "fetchWithThrottle"); + settingsStore.gridConfig.config.sortOrder = + settingsStore.gridConfig.options.label.value; + settingsStore.gridConfig.config.sortLabel = "job"; + settingsStore.gridConfig.config.reverseSort = true; + MountedFetcher(); + expect(fetchSpy).toHaveBeenCalledWith("label", "job", "1"); + }); + + it("calls alertStore.fetchWithThrottle with correct sort arguments when sortOrder=label sortLabel=instance reverseSort=null", () => { + MockEmptyAPIResponseWithoutFilters(); + const fetchSpy = jest.spyOn(alertStore, "fetchWithThrottle"); + settingsStore.gridConfig.config.sortOrder = + settingsStore.gridConfig.options.label.value; + settingsStore.gridConfig.config.sortLabel = "instance"; + settingsStore.gridConfig.config.reverseSort = null; + MountedFetcher(); + expect(fetchSpy).toHaveBeenCalledWith("label", "instance", ""); + }); + it("internal timer is armed after render", () => { const tree = MountedFetcher(); const instance = tree.instance();