From fc15e9499532f9bd816f3c80fd7c5ac2894c5076 Mon Sep 17 00:00:00 2001 From: Joanna <65491033+joannaWebDev@users.noreply.github.com> Date: Thu, 19 Dec 2024 11:43:10 +0100 Subject: [PATCH] fix: groupBy manual applyMode (#1010) --- .../groupby/GroupByVariable.test.tsx | 20 ++++++++++++++++++- .../src/variables/groupby/GroupByVariable.tsx | 10 ++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/scenes/src/variables/groupby/GroupByVariable.test.tsx b/packages/scenes/src/variables/groupby/GroupByVariable.test.tsx index 22442bb1c..b55f9ab38 100644 --- a/packages/scenes/src/variables/groupby/GroupByVariable.test.tsx +++ b/packages/scenes/src/variables/groupby/GroupByVariable.test.tsx @@ -14,6 +14,7 @@ import { SceneVariableSet } from '../sets/SceneVariableSet'; import userEvent from '@testing-library/user-event'; import { TestContextProvider } from '../../../utils/test/TestContextProvider'; import { FiltersRequestEnricher } from '../../core/types'; +import { allActiveGroupByVariables } from './findActiveGroupByVariablesByUid'; // 11.1.2 - will use SafeSerializableSceneObject // 11.1.1 - will NOT use SafeSerializableSceneObject @@ -259,8 +260,25 @@ describe.each(['11.1.2', '11.1.1'])('GroupByVariable', (v) => { }); }); + it('does NOT call addActivationHandler when applyMode is manual', async () => { + allActiveGroupByVariables.clear(); + + const { variable } = setupTest({ + applyMode: 'manual', + }); + + const addActivationHandlerSpy = jest.spyOn(variable, 'addActivationHandler'); + + await act(async () => { + await lastValueFrom(variable.validateAndUpdate()); + }); + + expect(addActivationHandlerSpy).not.toHaveBeenCalled(); + expect(allActiveGroupByVariables.size).toBe(0); + }); + // TODO enable once this repo is using @grafana/ui@11.1.0 - it.skip('shows groups and orders according to first occurence of a group item', async () => { + it.skip('shows groups and orders according to first occurrence of a group item', async () => { const { runRequest } = setupTest({ getTagKeysProvider: async () => ({ replace: true, diff --git a/packages/scenes/src/variables/groupby/GroupByVariable.tsx b/packages/scenes/src/variables/groupby/GroupByVariable.tsx index 348a5a0ff..71a2dbb62 100644 --- a/packages/scenes/src/variables/groupby/GroupByVariable.tsx +++ b/packages/scenes/src/variables/groupby/GroupByVariable.tsx @@ -144,11 +144,13 @@ export class GroupByVariable extends MultiValueVariable { noValueOnClear: true, }); - this.addActivationHandler(() => { - allActiveGroupByVariables.add(this); + if (this.state.applyMode === 'auto') { + this.addActivationHandler(() => { + allActiveGroupByVariables.add(this); - return () => allActiveGroupByVariables.delete(this); - }); + return () => allActiveGroupByVariables.delete(this); + }); + } } /**