-
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.
[SecuritySolution] Setup dashboard view page (#153040)
## Summary #152955 Demo link: https://kibana-pr-153040.kb.us-west2.gcp.elastic-cloud.com:9243/app/security/dashboards/6294c960-ce35-11ed-b8ca-51636b04063c?sourcerer=(default:(id:security-solution-default,selectedPatterns:!(%27auditbeat-*%27,%27logs-*%27))) https://p.elstc.co/paste/pOFVo-fV#Zgp3hnsnijsDHbki4y9Cy5F+apet-hYEcedpDzsc+f7 This create a single dashboard view under Security Solution: - Add dashboard view path: `/app/security/dashboards/:dashboardId` - Move the dashboards landing page to this new sub-plugin. - Check users' read permission to render a dashboard. - Render a dashboard with the given saved object id. - Show the dashboard name in the breadcrumbs. Dashboard not found: <img width="2363" alt="Screenshot 2023-03-23 at 13 44 01" src="https://user-images.githubusercontent.com/6295984/227477728-8d4984f2-3d8f-4f92-88ae-3337e6b3e5be.png"> Dashboard rendered: <img width="2539" alt="Screenshot 2023-03-23 at 13 44 28" src="https://user-images.githubusercontent.com/6295984/227477761-b1301b5c-1c4f-4970-bf8f-e077342c317f.png"> Interact with filters and query: https://user-images.githubusercontent.com/6295984/227477735-dc53bb85-31fb-4043-8355-22866296ebf9.mov Interact with `Open in Lens` and `Investigate in timeline` https://user-images.githubusercontent.com/6295984/228217900-5055a5d1-46f2-4d2f-98a8-289eb0f1939a.mov **Steps to verify**: 1. Create a dashboard from `/app/dashboards#/list`, save it and copy the dashboard saved object id from url. 2. Visit `/app/security/dashboards/:dashboardId` ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [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 --------- Co-authored-by: Stratoula Kalafateli <[email protected]> Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
6294b1b
commit 67af39a
Showing
42 changed files
with
1,070 additions
and
207 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
58 changes: 58 additions & 0 deletions
58
...plugins/security_solution/public/common/components/dashboards/dashboard_renderer.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,58 @@ | ||
/* | ||
* 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 { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { TestProviders } from '../../mock'; | ||
import { DashboardRenderer } from './dashboard_renderer'; | ||
|
||
jest.mock('@kbn/dashboard-plugin/public', () => { | ||
const actual = jest.requireActual('@kbn/dashboard-plugin/public'); | ||
return { | ||
...actual, | ||
LazyDashboardContainerRenderer: jest | ||
.fn() | ||
.mockImplementation(() => <div data-test-subj="dashboardRenderer" />), | ||
}; | ||
}); | ||
|
||
jest.mock('react-router-dom', () => { | ||
const actual = jest.requireActual('react-router-dom'); | ||
return { | ||
...actual, | ||
useParams: jest.fn().mockReturnValue({ | ||
detailName: '2d50f100-be6f-11ed-964a-ffa67304840e', | ||
}), | ||
}; | ||
}); | ||
|
||
describe('DashboardRenderer', () => { | ||
const props = { | ||
canReadDashboard: true, | ||
id: 'dashboard-savedObjectId', | ||
savedObjectId: 'savedObjectId', | ||
timeRange: { | ||
from: '2023-03-10T00:00:00.000Z', | ||
to: '2023-03-10T23:59:59.999Z', | ||
}, | ||
}; | ||
|
||
it('renders', () => { | ||
const { queryByTestId } = render(<DashboardRenderer {...props} />, { wrapper: TestProviders }); | ||
expect(queryByTestId(`dashboardRenderer`)).toBeInTheDocument(); | ||
}); | ||
|
||
it('does not render when No Read Permission', () => { | ||
const testProps = { | ||
...props, | ||
canReadDashboard: false, | ||
}; | ||
const { queryByTestId } = render(<DashboardRenderer {...testProps} />, { | ||
wrapper: TestProviders, | ||
}); | ||
expect(queryByTestId(`dashboardRenderer`)).not.toBeInTheDocument(); | ||
}); | ||
}); |
91 changes: 91 additions & 0 deletions
91
x-pack/plugins/security_solution/public/common/components/dashboards/dashboard_renderer.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,91 @@ | ||
/* | ||
* 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 React, { useCallback, useEffect, useState } from 'react'; | ||
import type { DashboardContainer } from '@kbn/dashboard-plugin/public'; | ||
import { LazyDashboardContainerRenderer } from '@kbn/dashboard-plugin/public'; | ||
import { ViewMode } from '@kbn/embeddable-plugin/public'; | ||
import type { Filter, Query } from '@kbn/es-query'; | ||
|
||
import { useDispatch } from 'react-redux'; | ||
import { InputsModelId } from '../../store/inputs/constants'; | ||
import { inputsActions } from '../../store/inputs'; | ||
|
||
const DashboardRendererComponent = ({ | ||
canReadDashboard, | ||
filters, | ||
id, | ||
inputId = InputsModelId.global, | ||
onDashboardContainerLoaded, | ||
query, | ||
savedObjectId, | ||
timeRange, | ||
}: { | ||
canReadDashboard: boolean; | ||
filters?: Filter[]; | ||
id: string; | ||
inputId?: InputsModelId.global | InputsModelId.timeline; | ||
onDashboardContainerLoaded?: (dashboardContainer: DashboardContainer) => void; | ||
query?: Query; | ||
savedObjectId: string | undefined; | ||
timeRange: { | ||
from: string; | ||
fromStr?: string | undefined; | ||
to: string; | ||
toStr?: string | undefined; | ||
}; | ||
}) => { | ||
const dispatch = useDispatch(); | ||
const [dashboardContainer, setDashboardContainer] = useState<DashboardContainer>(); | ||
|
||
const getCreationOptions = useCallback( | ||
() => | ||
Promise.resolve({ | ||
overrideInput: { timeRange, viewMode: ViewMode.VIEW, query, filters }, | ||
}), | ||
[filters, query, timeRange] | ||
); | ||
|
||
const refetchByForceRefresh = useCallback(() => { | ||
dashboardContainer?.forceRefresh(); | ||
}, [dashboardContainer]); | ||
|
||
useEffect(() => { | ||
dispatch( | ||
inputsActions.setQuery({ | ||
inputId, | ||
id, | ||
refetch: refetchByForceRefresh, | ||
loading: false, | ||
inspect: null, | ||
}) | ||
); | ||
return () => { | ||
dispatch(inputsActions.deleteOneQuery({ inputId, id })); | ||
}; | ||
}, [dispatch, id, inputId, refetchByForceRefresh]); | ||
|
||
useEffect(() => { | ||
dashboardContainer?.updateInput({ timeRange, query, filters }); | ||
}, [dashboardContainer, filters, query, timeRange]); | ||
|
||
const handleDashboardLoaded = useCallback( | ||
(container: DashboardContainer) => { | ||
setDashboardContainer(container); | ||
onDashboardContainerLoaded?.(container); | ||
}, | ||
[onDashboardContainerLoaded] | ||
); | ||
return savedObjectId && canReadDashboard ? ( | ||
<LazyDashboardContainerRenderer | ||
savedObjectId={savedObjectId} | ||
getCreationOptions={getCreationOptions} | ||
onDashboardContainerLoaded={handleDashboardLoaded} | ||
/> | ||
) : null; | ||
}; | ||
DashboardRendererComponent.displayName = 'DashboardRendererComponent'; | ||
export const DashboardRenderer = React.memo(DashboardRendererComponent); |
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
33 changes: 0 additions & 33 deletions
33
x-pack/plugins/security_solution/public/common/components/page_route/pageroute.test.tsx
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
x-pack/plugins/security_solution/public/common/components/page_route/pageroute.tsx
This file was deleted.
Oops, something went wrong.
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.