From 47f74eb199ed889b15f973f2c477123ada7753e7 Mon Sep 17 00:00:00 2001 From: Tim Sullivan Date: Wed, 28 Aug 2024 08:07:14 -0700 Subject: [PATCH] [Spaces] Create Space: show features picker only when solution not "classic" (#191528) ## Summary Users may only choose visible features of a Space when their solution view is set to "classic" (or empty). ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [x] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [x] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) --- .../edit_space/manage_space_page.test.tsx | 45 +++++++++++++++++++ .../edit_space/manage_space_page.tsx | 17 ++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/spaces/public/management/edit_space/manage_space_page.test.tsx b/x-pack/plugins/spaces/public/management/edit_space/manage_space_page.test.tsx index 3b82be30c6026..f169395688de1 100644 --- a/x-pack/plugins/spaces/public/management/edit_space/manage_space_page.test.tsx +++ b/x-pack/plugins/spaces/public/management/edit_space/manage_space_page.test.tsx @@ -237,6 +237,51 @@ describe('ManageSpacePage', () => { expect(wrapper.find(EnabledFeatures)).toHaveLength(0); }); + it('hides feature visibility controls when solution view is not "classic"', async () => { + const spacesManager = spacesManagerMock.create(); + + const wrapper = mountWithIntl( + + ); + + await waitFor(async () => { + await Promise.resolve(); + + wrapper.update(); + + // default for create space: expect visible features table to exist + expect(wrapper.find(EnabledFeatures)).toHaveLength(1); + }); + + await waitFor(() => { + // switch to observability view + updateSpace(wrapper, false, 'oblt'); + // expect visible features table to not exist + expect(wrapper.find(EnabledFeatures)).toHaveLength(0); + }); + + await waitFor(() => { + // switch to classic + updateSpace(wrapper, false, 'classic'); + // expect visible features table to exist again + expect(wrapper.find(EnabledFeatures)).toHaveLength(1); + }); + }); + it('allows a space to be updated', async () => { const spaceToUpdate = { id: 'existing-space', diff --git a/x-pack/plugins/spaces/public/management/edit_space/manage_space_page.tsx b/x-pack/plugins/spaces/public/management/edit_space/manage_space_page.tsx index b34d2eec88e48..cb81ae9304260 100644 --- a/x-pack/plugins/spaces/public/management/edit_space/manage_space_page.tsx +++ b/x-pack/plugins/spaces/public/management/edit_space/manage_space_page.tsx @@ -66,6 +66,7 @@ interface State { features: KibanaFeature[]; originalSpace?: Partial; showAlteringActiveSpaceDialog: boolean; + showVisibleFeaturesPicker: boolean; haveDisabledFeaturesChanged: boolean; hasSolutionViewChanged: boolean; isLoading: boolean; @@ -85,6 +86,7 @@ export class ManageSpacePage extends Component { this.state = { isLoading: true, showAlteringActiveSpaceDialog: false, + showVisibleFeaturesPicker: !!props.allowFeatureVisibility, saveInProgress: false, space: { color: getSpaceColor({}), @@ -203,7 +205,7 @@ export class ManageSpacePage extends Component { { )} - {this.props.allowFeatureVisibility && ( + {this.state.showVisibleFeaturesPicker && ( <> { return null; }; + private onSolutionViewChange = (space: Partial) => { + if (this.props.allowFeatureVisibility) { + let showVisibleFeaturesPicker = false; + if (space.solution === 'classic' || space.solution == null) { + showVisibleFeaturesPicker = true; + } + this.setState((state) => ({ ...state, showVisibleFeaturesPicker })); + } + this.onSpaceChange(space); + }; + public onSpaceChange = (updatedSpace: FormValues) => { this.setState({ space: updatedSpace,