From 704818fd9162528ef8e6d18a1805dbe0fa292ff8 Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Mon, 26 Jun 2023 15:51:38 +0800 Subject: [PATCH] remove duplicate EuiPage (#34) * remove duplicate EuiPage Signed-off-by: Hailong Cui * fix: remove duplicate workspace template Signed-off-by: Hailong Cui --------- Signed-off-by: Hailong Cui --- .../workspace/public/components/workspace_app.tsx | 15 +++++---------- src/plugins/workspace/public/hooks.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/plugins/workspace/public/components/workspace_app.tsx b/src/plugins/workspace/public/components/workspace_app.tsx index 54c326bc551f..ae2720d75b30 100644 --- a/src/plugins/workspace/public/components/workspace_app.tsx +++ b/src/plugins/workspace/public/components/workspace_app.tsx @@ -4,7 +4,6 @@ */ import React, { useEffect } from 'react'; -import { EuiPage, EuiPageBody } from '@elastic/eui'; import { I18nProvider } from '@osd/i18n/react'; import { Route, Switch, useLocation } from 'react-router-dom'; @@ -28,15 +27,11 @@ export const WorkspaceApp = ({ appBasePath }: { appBasePath: string }) => { return ( - - - - {ROUTES.map(({ path, Component, exact }) => ( - } exact={exact ?? false} /> - ))} - - - + + {ROUTES.map(({ path, Component, exact }) => ( + } exact={exact ?? false} /> + ))} + ); }; diff --git a/src/plugins/workspace/public/hooks.ts b/src/plugins/workspace/public/hooks.ts index 636a00742146..1132aac04e73 100644 --- a/src/plugins/workspace/public/hooks.ts +++ b/src/plugins/workspace/public/hooks.ts @@ -23,13 +23,14 @@ export function useWorkspaceTemplate(application: ApplicationStart) { const applications = useObservable(application.applications$); return useMemo(() => { + const tempWsTemplates = [] as WorkspaceTemplate[]; let workspaceTemplates = [] as WorkspaceTemplate[]; const templateFeatureMap = new Map(); if (applications) { applications.forEach((app) => { const { workspaceTemplate: templates = [] } = app; - workspaceTemplates.push(...templates); + tempWsTemplates.push(...templates); for (const template of templates) { const features = templateFeatureMap.get(template.id) || []; features.push(app); @@ -37,7 +38,12 @@ export function useWorkspaceTemplate(application: ApplicationStart) { } }); - workspaceTemplates = [...new Set(workspaceTemplates)]; + workspaceTemplates = tempWsTemplates.reduce((list, curr) => { + if (!list.find((ws) => ws.id === curr.id)) { + list.push(curr); + } + return list; + }, [] as WorkspaceTemplate[]); workspaceTemplates.sort((a, b) => (a.order || 0) - (b.order || 0)); }