Skip to content

Commit 7caf019

Browse files
gurinder39GurinderRawala
authored andcommitted
Loading dashboards with update function (#58)
* changed dashboard loading to use update fn * removed extra package
1 parent 366cb22 commit 7caf019

File tree

8 files changed

+28
-50
lines changed

8 files changed

+28
-50
lines changed

Diff for: public/app/core/reducers/fn-slice.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type UpdateFNGlobalStateAction = PayloadAction<Partial<FnGlobalState>>;
2020

2121
export type SetFnStateAction = PayloadAction<Omit<FnGlobalState, 'hiddenVariables'>>;
2222

23-
export type FnPropMappedFromState = Extract<keyof FnGlobalState, 'FNDashboard' | 'hiddenVariables' | 'mode'>;
23+
export type FnPropMappedFromState = Extract<keyof FnGlobalState, 'FNDashboard' | 'hiddenVariables' | 'mode' | 'uid' | 'queryParams' | 'slug'>;
2424
export type FnStateProp = keyof FnGlobalState;
2525

2626
export type FnPropsMappedFromState = Pick<FnGlobalState, FnPropMappedFromState>;
@@ -40,6 +40,9 @@ export const fnPropsMappedFromState: readonly FnPropMappedFromState[] = [
4040
'FNDashboard',
4141
'hiddenVariables',
4242
'mode',
43+
'uid',
44+
'queryParams',
45+
'slug',
4346
] as const;
4447

4548
const INITIAL_MODE = GrafanaThemeType.Light;

Diff for: public/app/features/dashboard/containers/DashboardPage.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { cx } from '@emotion/css';
2+
import { isUndefined, isEmpty, noop } from 'lodash';
23
import React, { PureComponent, } from 'react';
34
import { connect, ConnectedProps, MapDispatchToProps, MapStateToProps } from 'react-redux';
45

@@ -22,6 +23,7 @@ import { dashboardWatcher } from 'app/features/live/dashboard/dashboardWatcher';
2223
import { AngularDeprecationNotice } from 'app/features/plugins/angularDeprecation/AngularDeprecationNotice';
2324
import { AngularMigrationNotice } from 'app/features/plugins/angularDeprecation/AngularMigrationNotice';
2425
import { getPageNavFromSlug, getRootContentNavModel } from 'app/features/storage/StorageFolderPage';
26+
import { FNDashboardProps } from 'app/fn-app/types';
2527
import { RenderPortal } from 'app/fn-app/utils';
2628
import { DashboardRoutes, DashboardState, KioskMode, StoreState } from 'app/types';
2729
import { PanelEditEnteredEvent, PanelEditExitedEvent } from 'app/types/events';
@@ -44,8 +46,6 @@ import { getTimeSrv } from '../services/TimeSrv';
4446
import { explicitlyControlledMigrationPanels, autoMigrateAngular } from '../state/PanelModel';
4547
import { cleanUpDashboardAndVariables } from '../state/actions';
4648
import { initDashboard } from '../state/initDashboard';
47-
import { FNDashboardProps } from 'app/fn-app/types';
48-
import { isUndefined, isEmpty, noop } from 'lodash';
4949

5050
import { DashboardPageRouteParams, DashboardPageRouteSearchParams } from './types';
5151

Diff for: public/app/features/dashboard/dashgrid/DashboardPanel.tsx

+8-15
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const mapStateToProps = (state: StoreState, props: OwnProps) => {
3434
return {
3535
plugin: panelState.plugin,
3636
instanceState: panelState.instanceState,
37+
fnGlobalState: state.fnGlobalState
3738
};
3839
};
3940

@@ -45,8 +46,8 @@ const mapDispatchToProps = {
4546
const connector = connect(mapStateToProps, mapDispatchToProps);
4647

4748
export type Props = OwnProps & ConnectedProps<typeof connector>;
48-
4949
export class DashboardPanelUnconnected extends PureComponent<Props> {
50+
5051
static defaultProps: Partial<Props> = {
5152
lazy: true,
5253
};
@@ -72,19 +73,10 @@ export class DashboardPanelUnconnected extends PureComponent<Props> {
7273
}
7374
};
7475

75-
renderPanel = ({ isInView }: { isInView: boolean }) => {
76-
const {
77-
dashboard,
78-
panel,
79-
isViewing,
80-
isEditing,
81-
width,
82-
height,
83-
plugin,
84-
timezone,
85-
hideMenu,
86-
isDraggable = true,
87-
} = this.props;
76+
renderPanel = (isInView: boolean) => {
77+
const { dashboard, panel, isViewing, isEditing, width, height, plugin, timezone, fnGlobalState, isDraggable = true } = this.props;
78+
79+
// console.log(this.props, "on render panel")
8880

8981
if (!plugin) {
9082
return null;
@@ -119,7 +111,8 @@ export class DashboardPanelUnconnected extends PureComponent<Props> {
119111
height={height}
120112
onInstanceStateChange={this.onInstanceStateChange}
121113
timezone={timezone}
122-
hideMenu={hideMenu}
114+
mode={fnGlobalState.mode}
115+
FNDashboard={fnGlobalState.FNDashboard}
123116
/>
124117
);
125118
};

Diff for: public/app/features/dashboard/dashgrid/PanelStateWrapper.tsx

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import classNames from 'classnames';
22
import React, { PureComponent, CSSProperties } from 'react';
3-
import { connect } from 'react-redux';
43
import { Subscription } from 'rxjs';
54

65
import {
@@ -41,7 +40,6 @@ import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
4140
import { applyFilterFromTable } from 'app/features/variables/adhoc/actions';
4241
import { onUpdatePanelSnapshotData } from 'app/plugins/datasource/grafana/utils';
4342
import { changeSeriesColorConfigFactory } from 'app/plugins/panel/timeseries/overrides/colorSeriesConfigFactory';
44-
import { StoreState } from 'app/types';
4543
import { RenderEvent } from 'app/types/events';
4644

4745
import { deleteAnnotation, saveAnnotation, updateAnnotation } from '../../annotations/api';
@@ -73,6 +71,7 @@ export interface Props {
7371
timezone?: string;
7472
hideMenu?: boolean;
7573
FNDashboard?: boolean;
74+
mode?: "light" | "dark";
7675
}
7776

7877
export interface State {
@@ -296,6 +295,7 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
296295
if (width !== prevProps.width) {
297296
liveTimer.updateInterval(this);
298297
}
298+
299299
}
300300

301301
// Updates the response with information from the stream
@@ -613,8 +613,7 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
613613
aria-label={selectors.components.Panels.Panel.containerByTitle(panel.title)}
614614
>
615615
{FNDashboard ? (
616-
// TODO: Avoid divology. Use HTML5, i.e. wrap texts with p or h element instead of div.
617-
<div style={FN_TITLE_STYLE}>{panel.title}</div>
616+
<p style={FN_TITLE_STYLE}>{panel.title}</p>
618617
) : (
619618
<PanelHeader
620619
panel={panel}
@@ -646,9 +645,3 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
646645
}
647646
}
648647
}
649-
650-
const mapStateToProps = (state: StoreState) => {
651-
return { ...state.fnGlobalState };
652-
};
653-
const connector = connect(mapStateToProps);
654-
export const PanelChrome = connector(PanelStateWrapper);

Diff for: public/app/fn-app/create-mfe.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,10 @@ class createMfe {
264264
}
265265

266266
static updateFnApp() {
267-
const lifeCycleFn: FrameworkLifeCycles['update'] = ({ mode, hiddenVariables }: FNDashboardProps) => {
267+
const lifeCycleFn: FrameworkLifeCycles['update'] = ({ mode, ...other }: FNDashboardProps) => {
268268
if (mode) {
269269
createMfe.logger('Trying to update grafana with theme.', { mode });
270-
/**
271-
* NOTE
272-
* We do not use the "mode" state right now,
273-
* but I believe that as long as we store the "mode, we should update it
274-
*/
270+
275271
dispatch(
276272
updatePartialFnStates({
277273
mode,
@@ -288,12 +284,15 @@ class createMfe {
288284
createMfe.loadFnTheme(mode);
289285
}
290286

291-
if (hiddenVariables) {
292-
createMfe.logger('Trying to update grafana with hidden variables.', { hiddenVariables });
287+
if (other.uid) {
288+
createMfe.logger('Trying to update grafana with hidden variables.', { updatedProps: other });
293289

294290
dispatch(
295291
updatePartialFnStates({
296-
hiddenVariables,
292+
uid: other.uid,
293+
hiddenVariables: other.hiddenVariables,
294+
slug: other.slug,
295+
queryParams: other.queryParams,
297296
})
298297
);
299298
}

Diff for: public/app/fn-app/fn-dashboard-page/fn-dashboard.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { pick } from 'lodash';
2-
import { parse as parseQueryParams } from 'query-string';
32
import React, { FC, Suspense, useMemo } from 'react';
43
import { lazily } from 'react-lazily';
54
import { connect, MapStateToProps } from 'react-redux';
6-
import { useLocation } from 'react-router-dom';
75

86
import {
97
FnGlobalState,
@@ -44,18 +42,14 @@ function mapStateToProps(): MapStateToProps<
4442
}
4543

4644
export const DashboardPortalComponent: FC<FNDashboardComponentProps & FnPropsMappedFromState> = (props) => {
47-
const location = useLocation();
4845

4946
const content = useMemo(() => {
5047
if (!props.FNDashboard) {
5148
// TODO Use no data
5249
return null;
5350
}
5451

55-
const { search } = location;
56-
const queryParams = parseQueryParams(search);
57-
58-
const { dashboardUID: uid, slug } = queryParams as { dashboardUID?: string; slug?: string };
52+
const { uid, slug, queryParams = {} } = props;
5953

6054
if (!uid || !slug) {
6155
// TODO Use no data
@@ -72,7 +66,7 @@ export const DashboardPortalComponent: FC<FNDashboardComponentProps & FnPropsMap
7266
}}
7367
/>
7468
);
75-
}, [location, props]);
69+
}, [props]);
7670

7771
return <RenderPortal ID="grafana-portal">{content}</RenderPortal>;
7872
};

Diff for: public/app/fn-app/fn-dashboard-page/render-fn-dashboard.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const RenderFNDashboard: FC<FNDashboardProps> = (props) => {
6969
fnLoader,
7070
isLoading
7171
}),
72-
[controlsContainer, fnLoader, hiddenVariables, props, queryParams]
72+
[controlsContainer, fnLoader, hiddenVariables, isLoading, props, queryParams]
7373
);
7474

7575
return <DashboardPage {...dashboardPageProps} />;

Diff for: public/app/fn-app/utils.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ export interface RenderPortalProps {
55
ID: string;
66
}
77

8-
export declare type PortalEffectReturn = {
9-
portalDiv: HTMLElement | null;
10-
}
11-
128
export const getPortalContainer = (ID: string): HTMLElement | null => document.getElementById(ID);
139

1410
export const RenderPortal: FC<RenderPortalProps> = ({ ID, children }) => {

0 commit comments

Comments
 (0)