forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfn-dashboard.tsx
65 lines (52 loc) · 1.56 KB
/
fn-dashboard.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { pick } from 'lodash';
import React, { FC, useMemo } from 'react';
import { FnPropMappedFromState, fnPropsMappedFromState } from 'app/core/reducers/fn-slice';
import { StoreState, useSelector } from 'app/types';
import { AngularRoot } from '../../angular/AngularRoot';
import { FnAppProvider } from '../fn-app-provider';
import { FNDashboardProps } from '../types';
import { RenderPortal } from '../utils';
import { RenderFNDashboard } from './render-fn-dashboard';
type FNDashboardComponentProps = Omit<FNDashboardProps, FnPropMappedFromState>;
export const FNDashboard: FC<FNDashboardComponentProps> = (props) => {
return (
<FnAppProvider fnError={props.fnError}>
<div className="page-dashboard">
<AngularRoot />
<DashboardPortal {...props} />
</div>
</FnAppProvider>
);
};
function mapStateToProps() {
return ({ fnGlobalState }: StoreState) => pick(fnGlobalState, ...fnPropsMappedFromState);
}
export const DashboardPortal: FC<FNDashboardComponentProps> = (p) => {
const globalFnProps = useSelector(mapStateToProps());
const props = useMemo(
() => ({
...p,
...globalFnProps,
}),
[p, globalFnProps]
);
const content = useMemo(() => {
if (!props.FNDashboard) {
return null;
}
const { uid, queryParams = {} } = props;
if (!uid) {
return null;
}
return (
<RenderFNDashboard
{...{
...props,
uid,
queryParams,
}}
/>
);
}, [props]);
return <RenderPortal ID="grafana-portal">{content}</RenderPortal>;
};