Skip to content

Commit d90ade2

Browse files
authored
Loading dashboards with update function (#58)
* changed dashboard loading to use update fn * removed extra package
1 parent 5cf053f commit d90ade2

File tree

10 files changed

+28
-73
lines changed

10 files changed

+28
-73
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@
361361
"prismjs": "1.29.0",
362362
"prop-types": "15.8.1",
363363
"pseudoizer": "^0.1.0",
364-
"query-string": "^7.1.1",
365364
"rc-cascader": "3.7.0",
366365
"rc-drawer": "4.4.3",
367366
"rc-slider": "10.0.1",

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;

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

@@ -17,6 +18,7 @@ import { getNavModel } from 'app/core/selectors/navModel';
1718
import { PanelModel } from 'app/features/dashboard/state';
1819
import { dashboardWatcher } from 'app/features/live/dashboard/dashboardWatcher';
1920
import { getPageNavFromSlug, getRootContentNavModel } from 'app/features/storage/StorageFolderPage';
21+
import { FNDashboardProps } from 'app/fn-app/types';
2022
import { RenderPortal } from 'app/fn-app/utils';
2123
import { DashboardRoutes, DashboardState, KioskMode, StoreState } from 'app/types';
2224
import { PanelEditEnteredEvent, PanelEditExitedEvent } from 'app/types/events';
@@ -37,8 +39,6 @@ import { liveTimer } from '../dashgrid/liveTimer';
3739
import { getTimeSrv } from '../services/TimeSrv';
3840
import { cleanUpDashboardAndVariables } from '../state/actions';
3941
import { initDashboard } from '../state/initDashboard';
40-
import { FNDashboardProps } from 'app/fn-app/types';
41-
import { isUndefined, isEmpty, noop } from 'lodash';
4242

4343
export interface DashboardPageRouteParams {
4444
uid?: string;

public/app/features/dashboard/dashgrid/DashboardPanel.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const mapStateToProps = (state: StoreState, props: OwnProps) => {
3232
return {
3333
plugin: panelState.plugin,
3434
instanceState: panelState.instanceState,
35+
fnGlobalState: state.fnGlobalState
3536
};
3637
};
3738

@@ -43,8 +44,8 @@ const mapDispatchToProps = {
4344
const connector = connect(mapStateToProps, mapDispatchToProps);
4445

4546
export type Props = OwnProps & ConnectedProps<typeof connector>;
46-
4747
export class DashboardPanelUnconnected extends PureComponent<Props> {
48+
4849
static defaultProps: Partial<Props> = {
4950
lazy: true,
5051
};
@@ -71,8 +72,10 @@ export class DashboardPanelUnconnected extends PureComponent<Props> {
7172
};
7273

7374
renderPanel = (isInView: boolean) => {
74-
const { dashboard, panel, isViewing, isEditing, width, height, plugin, timezone } = this.props;
75+
const { dashboard, panel, isViewing, isEditing, width, height, plugin, timezone, fnGlobalState } = this.props;
7576

77+
// console.log(this.props, "on render panel")
78+
7679
if (!plugin) {
7780
return null;
7881
}
@@ -104,6 +107,8 @@ export class DashboardPanelUnconnected extends PureComponent<Props> {
104107
height={height}
105108
onInstanceStateChange={this.onInstanceStateChange}
106109
timezone={timezone}
110+
mode={fnGlobalState.mode}
111+
FNDashboard={fnGlobalState.FNDashboard}
107112
/>
108113
);
109114
};

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 {
@@ -36,7 +35,6 @@ import { PANEL_BORDER } from 'app/core/constants';
3635
import { profiler } from 'app/core/profiler';
3736
import { applyPanelTimeOverrides } from 'app/features/dashboard/utils/panel';
3837
import { changeSeriesColorConfigFactory } from 'app/plugins/panel/timeseries/overrides/colorSeriesConfigFactory';
39-
import { StoreState } from 'app/types';
4038
import { RenderEvent } from 'app/types/events';
4139

4240
import { isSoloRoute } from '../../../routes/utils';
@@ -65,6 +63,7 @@ export interface Props {
6563
onInstanceStateChange: (value: any) => void;
6664
timezone?: string;
6765
FNDashboard?: boolean;
66+
mode?: "light" | "dark";
6867
}
6968

7069
export interface State {
@@ -271,6 +270,7 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
271270
if (width !== prevProps.width) {
272271
liveTimer.updateInterval(this);
273272
}
273+
274274
}
275275

276276
// Updates the response with information from the stream
@@ -626,8 +626,7 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
626626
aria-label={selectors.components.Panels.Panel.containerByTitle(panel.title)}
627627
>
628628
{FNDashboard ? (
629-
// TODO: Avoid divology. Use HTML5, i.e. wrap texts with p or h element instead of div.
630-
<div style={FN_TITLE_STYLE}>{panel.title}</div>
629+
<p style={FN_TITLE_STYLE}>{panel.title}</p>
631630
) : (
632631
<PanelHeader
633632
panel={panel}
@@ -659,9 +658,3 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
659658
}
660659
}
661660
}
662-
663-
const mapStateToProps = (state: StoreState) => {
664-
return { ...state.fnGlobalState };
665-
};
666-
const connector = connect(mapStateToProps);
667-
export const PanelChrome = connector(PanelStateWrapper);

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
}

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
};

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} />;

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 }) => {

yarn.lock

+1-35
Original file line numberDiff line numberDiff line change
@@ -16258,7 +16258,7 @@ __metadata:
1625816258
languageName: node
1625916259
linkType: hard
1626016260

16261-
"decode-uri-component@npm:^0.2.0, decode-uri-component@npm:^0.2.2":
16261+
"decode-uri-component@npm:^0.2.0":
1626216262
version: 0.2.2
1626316263
resolution: "decode-uri-component@npm:0.2.2"
1626416264
checksum: 95476a7d28f267292ce745eac3524a9079058bbb35767b76e3ee87d42e34cd0275d2eb19d9d08c3e167f97556e8a2872747f5e65cbebcac8b0c98d83e285f139
@@ -18973,13 +18973,6 @@ __metadata:
1897318973
languageName: node
1897418974
linkType: hard
1897518975

18976-
"filter-obj@npm:^1.1.0":
18977-
version: 1.1.0
18978-
resolution: "filter-obj@npm:1.1.0"
18979-
checksum: cf2104a7c45ff48e7f505b78a3991c8f7f30f28bd8106ef582721f321f1c6277f7751aacd5d83026cb079d9d5091082f588d14a72e7c5d720ece79118fa61e10
18980-
languageName: node
18981-
linkType: hard
18982-
1898318976
"finalhandler@npm:1.2.0":
1898418977
version: 1.2.0
1898518978
resolution: "finalhandler@npm:1.2.0"
@@ -20292,7 +20285,6 @@ __metadata:
2029220285
prismjs: 1.29.0
2029320286
prop-types: 15.8.1
2029420287
pseudoizer: ^0.1.0
20295-
query-string: ^7.1.1
2029620288
rc-cascader: 3.7.0
2029720289
rc-drawer: 4.4.3
2029820290
rc-slider: 10.0.1
@@ -29562,18 +29554,6 @@ __metadata:
2956229554
languageName: node
2956329555
linkType: hard
2956429556

29565-
"query-string@npm:^7.1.1":
29566-
version: 7.1.3
29567-
resolution: "query-string@npm:7.1.3"
29568-
dependencies:
29569-
decode-uri-component: ^0.2.2
29570-
filter-obj: ^1.1.0
29571-
split-on-first: ^1.0.0
29572-
strict-uri-encode: ^2.0.0
29573-
checksum: 91af02dcd9cc9227a052841d5c2eecb80a0d6489d05625df506a097ef1c59037cfb5e907f39b84643cbfd535c955abec3e553d0130a7b510120c37d06e0f4346
29574-
languageName: node
29575-
linkType: hard
29576-
2957729557
"querystringify@npm:^2.1.1":
2957829558
version: 2.2.0
2957929559
resolution: "querystringify@npm:2.2.0"
@@ -33133,13 +33113,6 @@ __metadata:
3313333113
languageName: node
3313433114
linkType: hard
3313533115

33136-
"split-on-first@npm:^1.0.0":
33137-
version: 1.1.0
33138-
resolution: "split-on-first@npm:1.1.0"
33139-
checksum: 16ff85b54ddcf17f9147210a4022529b343edbcbea4ce977c8f30e38408b8d6e0f25f92cd35b86a524d4797f455e29ab89eb8db787f3c10708e0b47ebf528d30
33140-
languageName: node
33141-
linkType: hard
33142-
3314333116
"split-string@npm:^3.0.1, split-string@npm:^3.0.2":
3314433117
version: 3.1.0
3314533118
resolution: "split-string@npm:3.1.0"
@@ -33453,13 +33426,6 @@ __metadata:
3345333426
languageName: node
3345433427
linkType: hard
3345533428

33456-
"strict-uri-encode@npm:^2.0.0":
33457-
version: 2.0.0
33458-
resolution: "strict-uri-encode@npm:2.0.0"
33459-
checksum: eaac4cf978b6fbd480f1092cab8b233c9b949bcabfc9b598dd79a758f7243c28765ef7639c876fa72940dac687181b35486ea01ff7df3e65ce3848c64822c581
33460-
languageName: node
33461-
linkType: hard
33462-
3346333429
"string-argv@npm:^0.3.1, string-argv@npm:~0.3.1":
3346433430
version: 0.3.1
3346533431
resolution: "string-argv@npm:0.3.1"

0 commit comments

Comments
 (0)