-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] feat: [Dashboards] Hide clear control button in floating action…
…s when no filters are selected (#200177) (#201927) # Backport This will backport the following commits from `main` to `8.x`: - [feat: [Dashboards] Hide clear control button in floating actions when no filters are selected (#200177)](#200177) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Paulina Shakirova","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-26T19:36:12Z","message":"feat: [Dashboards] Hide clear control button in floating actions when no filters are selected (#200177)\n\n## Summary\nThis PR resolves the issue [[Controls] Show clear option only when\nvalues have been\nselected](https://github.com/elastic/kibana/issues/192619).\n\nPreviously, the clear button would be visible at all times, regardless\nof whether any filters were applied.\n\n![Screenshot 2024-11-19 at 09 33\n21](https://github.com/user-attachments/assets/6122225b-8497-4bef-953e-efbfc70b4276)\n\nWith this PR, the clear control button will only be visible if there are\nany filters applied and will dynamically disappear when the user clears\ntheir filters.\n\n![Screenshot 2024-11-19 at 09 37\n35](https://github.com/user-attachments/assets/2f4c8d0e-85f6-47d9-affb-590a5812f16f)\n\n---------\n\nCo-authored-by: kibanamachine <[email protected]>","sha":"95ef95c9f23f8d0d4ed8db3f3b91786622ac2935","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Presentation","v9.0.0","backport:prev-minor","papercut","v8.17.0"],"number":200177,"url":"https://github.com/elastic/kibana/pull/200177","mergeCommit":{"message":"feat: [Dashboards] Hide clear control button in floating actions when no filters are selected (#200177)\n\n## Summary\nThis PR resolves the issue [[Controls] Show clear option only when\nvalues have been\nselected](https://github.com/elastic/kibana/issues/192619).\n\nPreviously, the clear button would be visible at all times, regardless\nof whether any filters were applied.\n\n![Screenshot 2024-11-19 at 09 33\n21](https://github.com/user-attachments/assets/6122225b-8497-4bef-953e-efbfc70b4276)\n\nWith this PR, the clear control button will only be visible if there are\nany filters applied and will dynamically disappear when the user clears\ntheir filters.\n\n![Screenshot 2024-11-19 at 09 37\n35](https://github.com/user-attachments/assets/2f4c8d0e-85f6-47d9-affb-590a5812f16f)\n\n---------\n\nCo-authored-by: kibanamachine <[email protected]>","sha":"95ef95c9f23f8d0d4ed8db3f3b91786622ac2935"}},"sourceBranch":"main","suggestedTargetBranches":["8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200177","number":200177,"mergeCommit":{"message":"feat: [Dashboards] Hide clear control button in floating actions when no filters are selected (#200177)\n\n## Summary\nThis PR resolves the issue [[Controls] Show clear option only when\nvalues have been\nselected](https://github.com/elastic/kibana/issues/192619).\n\nPreviously, the clear button would be visible at all times, regardless\nof whether any filters were applied.\n\n![Screenshot 2024-11-19 at 09 33\n21](https://github.com/user-attachments/assets/6122225b-8497-4bef-953e-efbfc70b4276)\n\nWith this PR, the clear control button will only be visible if there are\nany filters applied and will dynamically disappear when the user clears\ntheir filters.\n\n![Screenshot 2024-11-19 at 09 37\n35](https://github.com/user-attachments/assets/2f4c8d0e-85f6-47d9-affb-590a5812f16f)\n\n---------\n\nCo-authored-by: kibanamachine <[email protected]>","sha":"95ef95c9f23f8d0d4ed8db3f3b91786622ac2935"}},{"branch":"8.17","label":"v8.17.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
- Loading branch information
1 parent
f7a222f
commit 242981d
Showing
11 changed files
with
217 additions
and
37 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/plugins/controls/public/actions/clear_control_action.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { BehaviorSubject } from 'rxjs'; | ||
import { getMockedControlGroupApi } from '../controls/mocks/control_mocks'; | ||
import { ClearControlAction } from './clear_control_action'; | ||
|
||
import type { ViewMode } from '@kbn/presentation-publishing'; | ||
|
||
const dashboardApi = { | ||
viewMode: new BehaviorSubject<ViewMode>('view'), | ||
}; | ||
const controlGroupApi = getMockedControlGroupApi(dashboardApi, { | ||
removePanel: jest.fn(), | ||
replacePanel: jest.fn(), | ||
addNewPanel: jest.fn(), | ||
children$: new BehaviorSubject({}), | ||
}); | ||
|
||
const clearControlAction = new ClearControlAction(); | ||
const hasSelections$ = new BehaviorSubject<boolean | undefined>(undefined); | ||
|
||
const controlApi = { | ||
type: 'test', | ||
uuid: '1', | ||
parentApi: controlGroupApi, | ||
hasSelections$, | ||
clearSelections: jest.fn(), | ||
}; | ||
beforeEach(() => { | ||
hasSelections$.next(false); | ||
}); | ||
|
||
describe('ClearControlAction', () => { | ||
test('should throw an error when called with an embeddable not in a parent', async () => { | ||
const noParentApi = { ...controlApi, parentApi: undefined }; | ||
|
||
await expect(async () => { | ||
await clearControlAction.execute({ embeddable: noParentApi }); | ||
}).rejects.toThrow(Error); | ||
}); | ||
|
||
test('should call onChange when isCompatible changes', () => { | ||
const onChange = jest.fn(); | ||
|
||
hasSelections$.next(true); | ||
clearControlAction.subscribeToCompatibilityChanges({ embeddable: controlApi }, onChange); | ||
|
||
expect(onChange).toHaveBeenCalledWith(true, clearControlAction); | ||
}); | ||
|
||
describe('Clear control button compatibility', () => { | ||
test('should be incompatible if there is no selection', async () => { | ||
const nothingIsSelected = { ...controlApi, hasSelections$: false }; | ||
|
||
expect(await clearControlAction.isCompatible({ embeddable: nothingIsSelected })).toBe(false); | ||
}); | ||
|
||
test('should be compatible if there is a selection', async () => { | ||
const hasSelections = { ...controlApi, hasSelections$: true }; | ||
|
||
expect(await clearControlAction.isCompatible({ embeddable: hasSelections })).toBe(true); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.