From 86235b59ba44ef8f91014452c329ed192c4fbff3 Mon Sep 17 00:00:00 2001 From: Eugene Lee Date: Mon, 31 Jan 2022 13:21:51 -0800 Subject: [PATCH] #416: Filter panels from app analytics Signed-off-by: Eugene Lee --- .../common/types/custom_panels.ts | 1 + .../public/components/custom_panels/home.tsx | 6 +++-- .../custom_panels/custom_panel_adaptor.ts | 22 +++++++++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/dashboards-observability/common/types/custom_panels.ts b/dashboards-observability/common/types/custom_panels.ts index 8aaed6d4d..a566793cc 100644 --- a/dashboards-observability/common/types/custom_panels.ts +++ b/dashboards-observability/common/types/custom_panels.ts @@ -8,6 +8,7 @@ export type CustomPanelListType = { id: string; dateCreated: number; dateModified: number; + applicationId?: string; }; export type VisualizationType = { diff --git a/dashboards-observability/public/components/custom_panels/home.tsx b/dashboards-observability/public/components/custom_panels/home.tsx index a91eca29b..acb47a68c 100644 --- a/dashboards-observability/public/components/custom_panels/home.tsx +++ b/dashboards-observability/public/components/custom_panels/home.tsx @@ -19,7 +19,7 @@ import { OBSERVABILITY_BASE, SAVED_OBJECTS, } from '../../../common/constants/shared'; -import { CustomPanelListType } from '../../../common/types/custom_panels'; +import { CustomPanelListType, PanelType } from '../../../common/types/custom_panels'; import { ObservabilitySideBar } from '../common/side_nav'; import { CustomPanelTable } from './custom_panel_table'; import { CustomPanelView } from './custom_panel_view'; @@ -62,7 +62,9 @@ export const Home = ({ http, chrome, parentBreadcrumb, pplService, renderProps } http .get(`${CUSTOM_PANELS_API_PREFIX}/panels`) .then((res) => { - setcustomPanelData(res.panels); + // Filter out panels that do not have applicationId field + const nonAppPanels = res.panels.filter((p: PanelType) => !p.applicationId); + setcustomPanelData(nonAppPanels); }) .catch((err) => { console.error('Issue in fetching the operational panels', err.body.message); diff --git a/dashboards-observability/server/adaptors/custom_panels/custom_panel_adaptor.ts b/dashboards-observability/server/adaptors/custom_panels/custom_panel_adaptor.ts index 5d4912c3b..4bd357121 100644 --- a/dashboards-observability/server/adaptors/custom_panels/custom_panel_adaptor.ts +++ b/dashboards-observability/server/adaptors/custom_panels/custom_panel_adaptor.ts @@ -4,7 +4,7 @@ */ import { v4 as uuidv4 } from 'uuid'; -import { PanelType, VisualizationType } from '../../../common/types/custom_panels'; +import { CustomPanelListType, PanelType, VisualizationType } from '../../../common/types/custom_panels'; import { ILegacyScopedClusterClient } from '../../../../../src/core/server'; import { createDemoPanel } from '../../common/helpers/custom_panels/sample_panels'; @@ -71,12 +71,20 @@ export class CustomPanelsAdaptor { objectType: 'operationalPanel', maxItems: 10000, }); - return response.observabilityObjectList.map((panel: any) => ({ - name: panel.operationalPanel.name, - id: panel.objectId, - dateCreated: panel.createdTimeMs, - dateModified: panel.lastUpdatedTimeMs, - })); + var panelList: any[] = []; + for (const panel of response.observabilityObjectList) { + var object: CustomPanelListType = { + name: panel.operationalPanel.name, + id: panel.objectId, + dateCreated: panel.createdTimeMs, + dateModified: panel.lastUpdatedTimeMs + } + if (panel.operationalPanel.applicationId) { + object.applicationId = panel.operationalPanel.applicationId; + } + panelList.push(object); + } + return panelList; } catch (error) { throw new Error('View Panel List Error:' + error); }