Skip to content

Commit

Permalink
Properly select new active dashboard tab when tab is removed. (#17081)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisoelkers authored Oct 31, 2023
1 parent b383be0 commit 7b43330
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions graylog2-web-interface/src/views/logic/slices/viewSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import * as Immutable from 'immutable';

import FindNewActiveQuery from 'views/logic/views/FindNewActiveQuery';

const emptyList = Immutable.List<string>();

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();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>, activeQueryId: string, removedQueryIds: List<string> = List()) => {
const FindNewActiveQueryId = (queryIds: List<string>, activeQueryId: string, removedQueryIds: List<string>) => {
const currentQueryIdIndex = queryIds.indexOf(activeQueryId);
const priorQueryIds = queryIds.slice(0, currentQueryIdIndex).toList();
const listToPickNewIdFrom = priorQueryIds.isEmpty()
Expand Down

0 comments on commit 7b43330

Please sign in to comment.