From 7b43330f0755aab1e9f1fdf520f3502a4cf6f93b Mon Sep 17 00:00:00 2001 From: Dennis Oelkers Date: Tue, 31 Oct 2023 10:06:39 +0100 Subject: [PATCH] Properly select new active dashboard tab when tab is removed. (#17081) --- graylog2-web-interface/src/views/logic/slices/viewSlice.ts | 4 ++-- .../src/views/logic/views/FindNewActiveQuery.test.ts | 4 +++- .../src/views/logic/views/FindNewActiveQuery.ts | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/graylog2-web-interface/src/views/logic/slices/viewSlice.ts b/graylog2-web-interface/src/views/logic/slices/viewSlice.ts index 68775a7eb4ab..3ffc9f9737cb 100644 --- a/graylog2-web-interface/src/views/logic/slices/viewSlice.ts +++ b/graylog2-web-interface/src/views/logic/slices/viewSlice.ts @@ -16,7 +16,7 @@ */ import type { PayloadAction } from '@reduxjs/toolkit'; import { createSlice } from '@reduxjs/toolkit'; -import type * as Immutable from 'immutable'; +import * as Immutable from 'immutable'; import type { AppDispatch } from 'stores/useAppDispatch'; import type { ViewState, RootState, GetState } from 'views/types'; @@ -217,7 +217,7 @@ export const removeQuery = (queryId: string) => async (dispatch: AppDispatch, ge .build(); const indexedQueryIds = search.queries.map((query) => query.id).toList(); - const newActiveQuery = FindNewActiveQueryId(indexedQueryIds, activeQuery); + const newActiveQuery = FindNewActiveQueryId(indexedQueryIds, activeQuery, Immutable.List([queryId])); await dispatch(selectQuery(newActiveQuery)); await dispatch(updateView(newView, true)); diff --git a/graylog2-web-interface/src/views/logic/views/FindNewActiveQuery.test.ts b/graylog2-web-interface/src/views/logic/views/FindNewActiveQuery.test.ts index aacade763ab1..212caa75a331 100644 --- a/graylog2-web-interface/src/views/logic/views/FindNewActiveQuery.test.ts +++ b/graylog2-web-interface/src/views/logic/views/FindNewActiveQuery.test.ts @@ -18,9 +18,11 @@ import * as Immutable from 'immutable'; import FindNewActiveQuery from 'views/logic/views/FindNewActiveQuery'; +const emptyList = Immutable.List(); + describe('FindNewActiveQuery', () => { it('does not break when there are no queries left', () => { - expect(FindNewActiveQuery(Immutable.List(), 'deadbeef')).toBeUndefined(); + expect(FindNewActiveQuery(emptyList, 'deadbeef', emptyList)).toBeUndefined(); expect(FindNewActiveQuery(Immutable.List(['foo']), 'deadbeef', Immutable.List(['foo']))).toBeUndefined(); }); diff --git a/graylog2-web-interface/src/views/logic/views/FindNewActiveQuery.ts b/graylog2-web-interface/src/views/logic/views/FindNewActiveQuery.ts index 516d14e12412..7d73ab511554 100644 --- a/graylog2-web-interface/src/views/logic/views/FindNewActiveQuery.ts +++ b/graylog2-web-interface/src/views/logic/views/FindNewActiveQuery.ts @@ -16,9 +16,9 @@ */ // Returns a new query ID, in case the active query gets deleted. -import { List } from 'immutable'; +import type { List } from 'immutable'; -const FindNewActiveQueryId = (queryIds: List, activeQueryId: string, removedQueryIds: List = List()) => { +const FindNewActiveQueryId = (queryIds: List, activeQueryId: string, removedQueryIds: List) => { const currentQueryIdIndex = queryIds.indexOf(activeQueryId); const priorQueryIds = queryIds.slice(0, currentQueryIdIndex).toList(); const listToPickNewIdFrom = priorQueryIds.isEmpty()