Skip to content

Commit

Permalink
Merge pull request #4 from danieldong51/overviewCM
Browse files Browse the repository at this point in the history
Added Dashboards Content registration
  • Loading branch information
TackAdam authored Aug 5, 2024
2 parents 7441204 + baaa290 commit 0f7d44c
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions public/components/overview/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -112,12 +112,61 @@ configs.map((card) => {

export const Home = ({ ..._props }: HomeProps) => {
const homepage = coreRefs.contentManagement?.renderPage(HOME_PAGE_ID);
const [ids, setIds] = useState<Array<{ value: string; text: string }>>([]);
const [value, setValue] = useState('');
const [_, setIsRegistered] = useState(false);

const onChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
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 (
<div>
<HashRouter>
<Switch>
<Route exact path="/">
<EuiSelect
options={ids}
value={value}
hasNoInitialSelection={true}
onChange={(e) => onChange(e)}
/>
{homepage}
</Route>
</Switch>
Expand Down

0 comments on commit 0f7d44c

Please sign in to comment.