From 684d2edd90b884fe75972af3d0c707aa63161a3a Mon Sep 17 00:00:00 2001 From: semd Date: Thu, 20 Apr 2023 13:54:55 +0200 Subject: [PATCH 1/2] page title with dashboard name --- .../public/dashboards/pages/details/index.tsx | 29 +++++++++++++------ .../dashboards/pages/details/translations.ts | 7 +++++ .../public/dashboards/pages/translations.ts | 4 --- .../public/dashboards/pages/utils.ts | 16 +++------- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/x-pack/plugins/security_solution/public/dashboards/pages/details/index.tsx b/x-pack/plugins/security_solution/public/dashboards/pages/details/index.tsx index aeb7dfcf63420..f87d4b1d71f07 100644 --- a/x-pack/plugins/security_solution/public/dashboards/pages/details/index.tsx +++ b/x-pack/plugins/security_solution/public/dashboards/pages/details/index.tsx @@ -12,7 +12,8 @@ import type { DashboardAPI } from '@kbn/dashboard-plugin/public'; import type { DashboardCapabilities } from '@kbn/dashboard-plugin/common/types'; import { useParams } from 'react-router-dom'; -import { isEmpty, pick } from 'lodash/fp'; +import { pick } from 'lodash/fp'; +import { EuiLoadingSpinner } from '@elastic/eui'; import { SecurityPageName } from '../../../../common/constants'; import { SpyRoute } from '../../../common/utils/route/spy_routes'; import { useCapabilities } from '../../../common/lib/kibana'; @@ -25,12 +26,12 @@ import { FiltersGlobal } from '../../../common/components/filters_global'; import { InputsModelId } from '../../../common/store/inputs/constants'; import { useSourcererDataView } from '../../../common/containers/sourcerer'; import { HeaderPage } from '../../../common/components/header_page'; -import { DASHBOARD_PAGE_TITLE } from '../translations'; +import { DASHBOARD_NOT_FOUND_TITLE } from './translations'; import { inputsSelectors } from '../../../common/store'; import { useDeepEqualSelector } from '../../../common/hooks/use_selector'; import { EditDashboardButton } from '../../components/edit_dashboard_button'; -type DashboardDetails = Record; +type DashboardDetails = Record; const DashboardViewComponent: React.FC = () => { const { fromStr, toStr, from, to } = useDeepEqualSelector((state) => @@ -51,13 +52,20 @@ const DashboardViewComponent: React.FC = () => { const [currentState, setCurrentState] = useState( canReadDashboard ? null : DashboardViewPromptState.NoReadPermission ); - const [dashboardDetails, setDashboardDetails] = useState(); + const [dashboardDetails, setDashboardDetails] = useState(); const onDashboardContainerLoaded = useCallback((dashboard: DashboardAPI) => { - const dashboardTitle = dashboard?.getTitle().trim(); - setDashboardDetails({ dashboardTitle }); + if (dashboard) { + const title = dashboard.getTitle().trim(); + if (title) { + setDashboardDetails({ title }); + } else { + setDashboardDetails({ title: DASHBOARD_NOT_FOUND_TITLE }); + } + } }, []); + + const dashboardExists = useMemo(() => dashboardDetails != null, [dashboardDetails]); const { detailName: savedObjectId } = useParams<{ detailName?: string }>(); - const dashboardExists = !isEmpty(dashboardDetails?.dashboardTitle); useEffect(() => { if (!indicesExist) { @@ -73,7 +81,7 @@ const DashboardViewComponent: React.FC = () => { )} - + }> {showWriteControls && dashboardExists && ( { )} - + ); diff --git a/x-pack/plugins/security_solution/public/dashboards/pages/details/translations.ts b/x-pack/plugins/security_solution/public/dashboards/pages/details/translations.ts index dfd25dcbe8512..ddfa94bd75584 100644 --- a/x-pack/plugins/security_solution/public/dashboards/pages/details/translations.ts +++ b/x-pack/plugins/security_solution/public/dashboards/pages/details/translations.ts @@ -27,6 +27,13 @@ export const DASHBOARD_INDICES_NOT_FOUND_TITLE = i18n.translate( } ); +export const DASHBOARD_NOT_FOUND_TITLE = i18n.translate( + 'xpack.securitySolution.dashboards.dashboard.notFound.title', + { + defaultMessage: 'Not found', + } +); + export const EDIT_DASHBOARD_BUTTON_TITLE = i18n.translate( 'xpack.securitySolution.dashboards.dashboard.editDashboardButtonTitle', { diff --git a/x-pack/plugins/security_solution/public/dashboards/pages/translations.ts b/x-pack/plugins/security_solution/public/dashboards/pages/translations.ts index 716b5a6d3a81d..2cdcc156e2946 100644 --- a/x-pack/plugins/security_solution/public/dashboards/pages/translations.ts +++ b/x-pack/plugins/security_solution/public/dashboards/pages/translations.ts @@ -9,7 +9,3 @@ import { i18n } from '@kbn/i18n'; export const DASHBOARDS_PAGE_TITLE = i18n.translate('xpack.securitySolution.dashboards.pageTitle', { defaultMessage: 'Dashboards', }); - -export const DASHBOARD_PAGE_TITLE = i18n.translate('xpack.securitySolution.dashboard.pageTitle', { - defaultMessage: 'Dashboard', -}); diff --git a/x-pack/plugins/security_solution/public/dashboards/pages/utils.ts b/x-pack/plugins/security_solution/public/dashboards/pages/utils.ts index 8db389553c523..c71eedbec0264 100644 --- a/x-pack/plugins/security_solution/public/dashboards/pages/utils.ts +++ b/x-pack/plugins/security_solution/public/dashboards/pages/utils.ts @@ -6,21 +6,13 @@ */ import type { ChromeBreadcrumb } from '@kbn/core/public'; -import { isEmpty } from 'lodash/fp'; import type { RouteSpyState } from '../../common/utils/route/types'; export const getTrailingBreadcrumbs = (params: RouteSpyState): ChromeBreadcrumb[] => { - let breadcrumb: ChromeBreadcrumb[] = []; - - const dashboardTitle = params?.state?.dashboardTitle?.trim(); - if (params?.state?.dashboardTitle || params.detailName) { - breadcrumb = [ - ...breadcrumb, - { - text: !isEmpty(dashboardTitle) ? dashboardTitle : params.detailName, - }, - ]; + const breadcrumbName = params?.state?.dashboardName; + if (breadcrumbName) { + return [{ text: breadcrumbName }]; } - return breadcrumb; + return []; }; From 458fd65cca6b8b4e5aa608e3affe0b60d669f7b1 Mon Sep 17 00:00:00 2001 From: semd Date: Thu, 20 Apr 2023 14:06:18 +0200 Subject: [PATCH 2/2] add codeowner to the dashboard sub-plugin --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 270c2ce5d2b48..e6cd6ff041cd0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1058,6 +1058,7 @@ packages/kbn-yarn-lock-validator @elastic/kibana-operations /x-pack/plugins/security_solution/public/cases @elastic/security-threat-hunting-explore /x-pack/plugins/security_solution/public/explore @elastic/security-threat-hunting-explore /x-pack/plugins/security_solution/public/overview @elastic/security-threat-hunting-explore +/x-pack/plugins/security_solution/public/dashboards @elastic/security-threat-hunting-explore /x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/hosts @elastic/security-threat-hunting-explore /x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/matrix_histogram @elastic/security-threat-hunting-explore