From 1d0fc9c40c73260d837a7c08dace9f559a490554 Mon Sep 17 00:00:00 2001 From: sanjalkatiyar Date: Wed, 22 Sep 2021 12:22:21 +0530 Subject: [PATCH] fix issue with standalone dashboards --- .../dashboards/ocs-system-dashboard.tsx | 2 +- .../dashboards/odf-system-dashboard.tsx | 21 ++++++++++++++----- .../ceph-storage-plugin/src/plugin.ts | 11 ++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/frontend/packages/ceph-storage-plugin/src/components/dashboards/ocs-system-dashboard.tsx b/frontend/packages/ceph-storage-plugin/src/components/dashboards/ocs-system-dashboard.tsx index e2969a253b3..1a23543c646 100644 --- a/frontend/packages/ceph-storage-plugin/src/components/dashboards/ocs-system-dashboard.tsx +++ b/frontend/packages/ceph-storage-plugin/src/components/dashboards/ocs-system-dashboard.tsx @@ -48,7 +48,7 @@ const isPagePresent = (pages: Page[], page: Page): boolean => pages.some((p) => page.href === p.href); export const BLOCK_FILE = 'block-file'; -const OBJECT = 'object'; +export const OBJECT = 'object'; const sortPages = (a: Page, b: Page): number => { if (a.href === BLOCK_FILE || a.href === `overview/${BLOCK_FILE}`) return -1; diff --git a/frontend/packages/ceph-storage-plugin/src/components/dashboards/odf-system-dashboard.tsx b/frontend/packages/ceph-storage-plugin/src/components/dashboards/odf-system-dashboard.tsx index b534b2b2f51..e16ac96c4fc 100644 --- a/frontend/packages/ceph-storage-plugin/src/components/dashboards/odf-system-dashboard.tsx +++ b/frontend/packages/ceph-storage-plugin/src/components/dashboards/odf-system-dashboard.tsx @@ -8,11 +8,13 @@ import { } from '@console/internal/components/dashboard/dashboards-page/dashboards'; import { Page, HorizontalNav, LoadingBox, PageHeading } from '@console/internal/components/utils'; import { referenceForModel } from '@console/internal/module/k8s'; +import { useFlag } from '@console/shared/src/hooks/flag'; // eslint-disable-next-line import/no-named-default -import { default as OCSOverview, BLOCK_FILE } from './ocs-system-dashboard'; +import { default as OCSOverview, BLOCK_FILE, OBJECT } from './ocs-system-dashboard'; import { BlockPoolListPage } from '../block-pool/block-pool-list-page'; import { CEPH_STORAGE_NAMESPACE } from '../../constants'; import { CephBlockPoolModel } from '../../models'; +import { MCG_FLAG, CEPH_FLAG } from '../../features'; type ODFSystemDashboardPageProps = Omit & { match: Match<{ systemName: string }>; @@ -24,11 +26,16 @@ const ODFSystemDashboard: React.FC = ({ ...rest }) => { const { t } = useTranslation(); + const isObjectServiceAvailable = useFlag(MCG_FLAG); + const isCephAvailable = useFlag(CEPH_FLAG); const { systemName } = rest.match.params; + const dashboardTab = isCephAvailable === false && isObjectServiceAvailable ? OBJECT : BLOCK_FILE; + const defaultDashboard = React.useRef(dashboardTab); + const pages: Page[] = [ { path: 'overview/:dashboard', - href: 'overview/block-file', + href: `overview/${defaultDashboard.current}`, name: t('ceph-storage-plugin~Overview'), component: OCSOverview, }, @@ -56,11 +63,15 @@ const ODFSystemDashboard: React.FC = ({ React.useEffect(() => { if (location.pathname.endsWith(systemName)) { - rest.history.push(`${location.pathname}/overview/${BLOCK_FILE}`); + rest.history.push(`${location.pathname}/overview/${defaultDashboard.current}`); } else if (location.pathname.endsWith('overview')) { - rest.history.push(`${location.pathname}/${BLOCK_FILE}`); + rest.history.push(`${location.pathname}/${defaultDashboard.current}`); + } else if (defaultDashboard.current !== dashboardTab) { + const pathname = location.pathname.substring(0, location.pathname.lastIndexOf('/overview')); + rest.history.push(`${pathname}/overview/${dashboardTab}`); + defaultDashboard.current = dashboardTab; } - }, [rest.history, location.pathname, systemName]); + }, [rest.history, location.pathname, systemName, dashboardTab]); return kindsInFlight && k8sModels.size === 0 ? ( diff --git a/frontend/packages/ceph-storage-plugin/src/plugin.ts b/frontend/packages/ceph-storage-plugin/src/plugin.ts index 50d5b24f97f..43ed5c38c12 100644 --- a/frontend/packages/ceph-storage-plugin/src/plugin.ts +++ b/frontend/packages/ceph-storage-plugin/src/plugin.ts @@ -408,6 +408,17 @@ const plugin: Plugin = [ disallowed: [ODF_MANAGED_FLAG, ODF_MODEL_FLAG], }, }, + { + type: 'Page/Route', + properties: { + path: `/ocs-dashboards`, + loader: () => import('./components/dashboards/ocs-system-dashboard').then((m) => m.default), + }, + flags: { + required: [MCG_FLAG], + disallowed: [OCS_FLAG, ODF_MODEL_FLAG], + }, + }, { type: 'Project/Dashboard/Inventory/Item', properties: {