From bad318432e9dba40ba05ef8e34eebe7bb96d589d Mon Sep 17 00:00:00 2001 From: Tim Sullivan Date: Mon, 21 Oct 2024 13:15:13 -0700 Subject: [PATCH] [Spaces Mgmt] Ensure space ID is used for comparison logic (#196930) Closes https://github.com/elastic/kibana/issues/192811 ## Summary When creating a space, if it's not the current, you should be able to use the switch icon from the table. This PR fixes a bug that disabled the switch icon for spaces that aren't the current, if they have the same name as the current. ### 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 (cherry picked from commit a3d216f496d319ab41855711e88c4b9c80a57152) --- .../management/spaces_grid/spaces_grid_page.test.tsx | 4 ++-- .../public/management/spaces_grid/spaces_grid_page.tsx | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.test.tsx b/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.test.tsx index c8707f8959f0c..95629248e2cbe 100644 --- a/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.test.tsx +++ b/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.test.tsx @@ -240,7 +240,7 @@ describe('SpacesGridPage', () => { wrapper.update(); const activeRow = wrapper.find('[data-test-subj="spacesListTableRow-custom-2"]'); - const switchAction = activeRow.find('EuiButtonIcon[data-test-subj="Custom 2-switchSpace"]'); + const switchAction = activeRow.find('EuiButtonIcon[data-test-subj="custom-2-switchSpace"]'); expect(switchAction.prop('isDisabled')).toBe(true); }); @@ -272,7 +272,7 @@ describe('SpacesGridPage', () => { wrapper.update(); const nonActiveRow = wrapper.find('[data-test-subj="spacesListTableRow-default"]'); - const switchAction = nonActiveRow.find('EuiButtonIcon[data-test-subj="Default-switchSpace"]'); + const switchAction = nonActiveRow.find('EuiButtonIcon[data-test-subj="default-switchSpace"]'); expect(switchAction.prop('isDisabled')).toBe(false); }); diff --git a/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.tsx b/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.tsx index 462b65f327ebc..479b2fff19964 100644 --- a/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.tsx +++ b/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.tsx @@ -428,7 +428,7 @@ export class SpacesGridPage extends Component { reactRouterNavigate(this.props.history, this.getEditSpacePath(rowRecord)).href, onClick: (rowRecord) => reactRouterNavigate(this.props.history, this.getEditSpacePath(rowRecord)).onClick, - 'data-test-subj': (rowRecord) => `${rowRecord.name}-editSpace`, + 'data-test-subj': (rowRecord) => `${rowRecord.id}-editSpace`, }, { isPrimary: true, @@ -436,7 +436,7 @@ export class SpacesGridPage extends Component { defaultMessage: 'Switch', }), description: (rowRecord) => - activeSpace?.name !== rowRecord.name + activeSpace?.id !== rowRecord.id ? i18n.translate( 'xpack.spaces.management.spacesGridPage.switchSpaceActionDescription', { @@ -460,8 +460,8 @@ export class SpacesGridPage extends Component { rowRecord.id, `${ENTER_SPACE_PATH}?next=/app/management/kibana/spaces/` ), - enabled: (rowRecord) => activeSpace?.name !== rowRecord.name, - 'data-test-subj': (rowRecord) => `${rowRecord.name}-switchSpace`, + enabled: (rowRecord) => activeSpace?.id !== rowRecord.id, + 'data-test-subj': (rowRecord) => `${rowRecord.id}-switchSpace`, }, { name: i18n.translate('xpack.spaces.management.spacesGridPage.deleteActionName', { @@ -485,7 +485,7 @@ export class SpacesGridPage extends Component { color: 'danger', onClick: (rowRecord: Space) => this.onDeleteSpaceClick(rowRecord), enabled: (rowRecord: Space) => !isReservedSpace(rowRecord), - 'data-test-subj': (rowRecord) => `${rowRecord.name}-deleteSpace`, + 'data-test-subj': (rowRecord) => `${rowRecord.id}-deleteSpace`, }, ], });