forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Fix agent dashboard link accross multiple space (elastic#201280)
- Loading branch information
1 parent
a57586d
commit aa0afb0
Showing
5 changed files
with
147 additions
and
24 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
...plugins/fleet/public/applications/fleet/sections/agents/services/dashboard_helper.test.ts
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,38 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { GetInfoResponse } from '../../../../../../common'; | ||
|
||
import { getDashboardIdForSpace } from './dashboard_helpers'; | ||
|
||
const PKG_INFO = { | ||
item: { | ||
status: 'installed', | ||
installationInfo: { | ||
install_status: 'installed', | ||
installed_kibana_space_id: 'default', | ||
additional_spaces_installed_kibana: { | ||
test: [ | ||
{ | ||
id: 'test-destination-1', | ||
originId: 'test-id-1', | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
} as unknown as GetInfoResponse; | ||
|
||
describe('getDashboardIdForSpace', () => { | ||
it('return the same id if package is installed in the same space', () => { | ||
expect(() => getDashboardIdForSpace('default', PKG_INFO, 'test-id-1')); | ||
}); | ||
|
||
it('return the destination ID if package is installed in an additionnal space', () => { | ||
expect(() => getDashboardIdForSpace('test', PKG_INFO, 'test-id-1')); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
x-pack/plugins/fleet/public/applications/fleet/sections/agents/services/dashboard_helpers.ts
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,32 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common'; | ||
|
||
import type { GetInfoResponse } from '../../../../../../common'; | ||
|
||
export function getDashboardIdForSpace( | ||
spaceId: string = DEFAULT_SPACE_ID, | ||
res: GetInfoResponse | undefined, | ||
dashboardId: string | ||
) { | ||
if (res?.item?.status !== 'installed') { | ||
return dashboardId; | ||
} | ||
|
||
const installationInfo = res.item.installationInfo; | ||
|
||
if (!installationInfo || installationInfo?.installed_kibana_space_id === spaceId) { | ||
return dashboardId; | ||
} | ||
|
||
return ( | ||
installationInfo.additional_spaces_installed_kibana?.[spaceId]?.find( | ||
({ originId }) => originId === dashboardId | ||
)?.id ?? dashboardId | ||
); | ||
} |