From 36a1a20775032144727b6eceef7d9f8e64ec3c5b Mon Sep 17 00:00:00 2001 From: Dan Dong Date: Sat, 3 Aug 2024 11:50:49 -0700 Subject: [PATCH 1/2] Added Dashboards Content registration Signed-off-by: Dan Dong --- public/components/overview/home.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/public/components/overview/home.tsx b/public/components/overview/home.tsx index 277e59320..12a801b85 100644 --- a/public/components/overview/home.tsx +++ b/public/components/overview/home.tsx @@ -110,6 +110,20 @@ configs.map((card) => { }); }); +coreRefs.contentManagement?.registerContentProvider({ + id: '', + getContent: () => ({ + id: 'dashboard_content', + kind: 'dashboard', + order: 1000, + input: { + kind: 'dynamic', + get: () => Promise.resolve('e61829a0-48ad-11ef-9e1e-9fe5e67444b8'), + }, + }), + getTargetArea: () => HOME_CONTENT_AREAS.DASHBOARD, +}); + export const Home = ({ ..._props }: HomeProps) => { const homepage = coreRefs.contentManagement?.renderPage(HOME_PAGE_ID); From baaa2904389ce12a774751c3ae05d350fc9fc31b Mon Sep 17 00:00:00 2001 From: Dan Dong Date: Sat, 3 Aug 2024 21:50:54 -0700 Subject: [PATCH 2/2] Added data source selector Signed-off-by: Dan Dong --- public/components/overview/home.tsx | 67 ++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/public/components/overview/home.tsx b/public/components/overview/home.tsx index 12a801b85..7802dbf49 100644 --- a/public/components/overview/home.tsx +++ b/public/components/overview/home.tsx @@ -3,9 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { HashRouter, RouteComponentProps, Switch, Route } from 'react-router-dom'; -import { EuiText } from '@elastic/eui'; +import { EuiSelect, EuiText } from '@elastic/eui'; import { i18n } from '@osd/i18n'; import { TraceAnalyticsCoreDeps } from '../trace_analytics/home'; import { ChromeBreadcrumb } from '../../../../../src/core/public'; @@ -110,28 +110,63 @@ configs.map((card) => { }); }); -coreRefs.contentManagement?.registerContentProvider({ - id: '', - getContent: () => ({ - id: 'dashboard_content', - kind: 'dashboard', - order: 1000, - input: { - kind: 'dynamic', - get: () => Promise.resolve('e61829a0-48ad-11ef-9e1e-9fe5e67444b8'), - }, - }), - getTargetArea: () => HOME_CONTENT_AREAS.DASHBOARD, -}); - export const Home = ({ ..._props }: HomeProps) => { const homepage = coreRefs.contentManagement?.renderPage(HOME_PAGE_ID); + const [ids, setIds] = useState>([]); + const [value, setValue] = useState(''); + const [_, setIsRegistered] = useState(false); + + const onChange = (e: React.ChangeEvent) => { + setValue(e.target.value.toString()); + }; + + useEffect(() => { + coreRefs.savedObjectsClient + ?.find({ + type: 'dashboard', + }) + .then((response) => { + const dashboardIds = response.savedObjects.map((dashboard) => ({ + value: dashboard.id.toString(), + text: dashboard.id.toString(), + })); + setIds(dashboardIds); + setIsRegistered(true); + }) + .catch((response) => { + console.log(response); + }); + }, []); + useEffect(() => { + if (ids.length > 0) { + console.log(ids[0].value); + coreRefs.contentManagement?.registerContentProvider({ + id: '', + getContent: () => ({ + id: 'dashboard_content', + kind: 'dashboard', + order: 1000, + input: { + kind: 'dynamic', + get: () => Promise.resolve(ids[0].value), + }, + }), + getTargetArea: () => HOME_CONTENT_AREAS.DASHBOARD, + }); + } + }, [ids]); return (
+ onChange(e)} + /> {homepage}