Skip to content

Commit 7380d83

Browse files
gurinder39GurinderRawala
authored andcommitted
render time range selector any where, removed dead code (#103)
* removed graphql data source, updated local test info in fn readme * portal for time range selector
1 parent 979264a commit 7380d83

19 files changed

+76
-414
lines changed

FN_README.md

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Sankey plugin
2-
3-
## How to work with it?
1+
## Sankey Plugin
42

53
We created our fork of [snakey-panel](https://github.com/IsmaelMasharo/sankey-panel) ---> [our fork](https://github.com/fluxninja/sankey-panel) and if we want to add some changes to it we need to:
64

@@ -10,19 +8,34 @@ We created our fork of [snakey-panel](https://github.com/IsmaelMasharo/sankey-pa
108
- copy-paste builded version of plugin into grafana `public/app/plugins/panel/sankey-panel-0.5.0`
119
- refresh grafana
1210

13-
# [Grafadruid-druid datasource plugin](./public/app/plugins/datasource//grafadruid-druid-datasource/)
11+
## [Grafadruid-druid datasource plugin](./public/app/plugins/datasource//grafadruid-druid-datasource/)
1412

1513
https://github.com/grafadruid/druid-grafana/tree/master/src
1614

17-
# [Graphql datasource plugin](./public/app/plugins//datasource//fifemon-graphql-datasource/)
15+
## Local Testing
16+
17+
Run Grafana locally using:
18+
19+
```shell
20+
make run
21+
22+
yarn start
23+
```
24+
25+
Port forward local prometheus and druid from [cloud](https://github.com/fluxninja/cloud) repo using fn:
26+
27+
```shell
28+
cd cloud
29+
30+
LOGURU_LEVEL=TRACE fn dev service-proxy --cluster <cluster-name> prometheus-cloud druid-router
1831

19-
https://github.com/fifemon/graphql-datasource/tree/v1.3.0/src
32+
```
2033

21-
Release: v1.3.0
34+
Connect to druid and prometheus on locally running Grafana UI. For this go to connection tab and select Data Source. Add new data source and make a connection. To test micro frontend make a connection with UI follow this [MFE Grafana](https://github.com/fluxninja/cloud/tree/main/services/cloud/ui#running-grafana-locally-for-development).
2235

23-
# Troubleshooting
36+
## Troubleshooting
2437

25-
## "Cannot find module" typescript errors (ts2307)
38+
### "Cannot find module" typescript errors (ts2307)
2639

2740
Smart IDEs (such as VSCode or IntelliJ) require special configuration for TypeScript to work when using Plug'n'Play installs.
2841
A collection of settings for each editor can be found under the (link)[https://yarnpkg.com/getting-started/editor-sdks#vscode]

public/app/core/reducers/fn-slice.ts

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

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

24-
export type FnPropMappedFromState = Extract<keyof FnGlobalState, 'FNDashboard' | 'hiddenVariables' | 'mode' | 'uid' | 'queryParams' | 'slug' | 'version'>;
24+
export type FnPropMappedFromState = Extract<
25+
keyof FnGlobalState,
26+
'FNDashboard' | 'hiddenVariables' | 'mode' | 'uid' | 'queryParams' | 'slug' | 'version' | 'controlsContainer'
27+
>;
2528
export type FnStateProp = keyof FnGlobalState;
2629

2730
export type FnPropsMappedFromState = Pick<FnGlobalState, FnPropMappedFromState>;

public/app/features/plugins/built_in_plugins.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ const postgresPlugin = async () =>
2121
await import(/* webpackChunkName: "postgresPlugin" */ 'app/plugins/datasource/postgres/module');
2222
const grafadruidDruidDatasourcePlugin = async () =>
2323
await import(/* webpackChunkName: "druidPlugin" */ 'app/plugins/datasource/grafadruid-druid-datasource/module');
24-
const fifemonGraphqlDatasourcePlugin = async () =>
25-
await import(/* webpackChunkName: "graphqlPlugin" */ 'app/plugins/datasource/fifemon-graphql-datasource/module');
2624
const prometheusPlugin = async () =>
2725
await import(/* webpackChunkName: "prometheusPlugin" */ 'app/plugins/datasource/prometheus/module');
2826
const mssqlPlugin = async () =>
@@ -93,8 +91,8 @@ const builtInPlugins: any = {
9391
'app/plugins/datasource/mysql/module': mysqlPlugin,
9492
'app/plugins/datasource/postgres/module': postgresPlugin,
9593
'app/plugins/datasource/mssql/module': mssqlPlugin,
94+
// Default FluxNinja Druid datasource
9695
'app/plugins/datasource/grafadruid-druid-datasource/module': grafadruidDruidDatasourcePlugin,
97-
'app/plugins/datasource/fifemon-graphql-datasource/module': fifemonGraphqlDatasourcePlugin,
9896
'app/plugins/datasource/prometheus/module': prometheusPlugin,
9997
'app/plugins/datasource/testdata/module': testDataDSPlugin,
10098
'app/plugins/datasource/cloud-monitoring/module': cloudMonitoringPlugin,

public/app/fn-app/create-mfe.ts

+20-38
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ declare let __webpack_public_path__: string;
44
window.__grafana_public_path__ =
55
__webpack_public_path__.substring(0, __webpack_public_path__.lastIndexOf('build/')) || __webpack_public_path__;
66

7-
import { isNull, merge, noop, omit, pick } from 'lodash';
7+
import { isNull, merge, noop, pick } from 'lodash';
88
import React, { ComponentType } from 'react';
99
import ReactDOM from 'react-dom';
1010

1111
import { createTheme, GrafanaThemeType } from '@grafana/data';
12-
import { createFnColors } from '@grafana/data/src/themes/fnCreateColors';
12+
import { createColors } from '@grafana/data/src/themes/createColors';
1313
import { GrafanaTheme2 } from '@grafana/data/src/themes/types';
1414
import { ThemeChangedEvent } from '@grafana/runtime';
1515
import { GrafanaBootConfig } from '@grafana/runtime/src/config';
@@ -60,18 +60,14 @@ type DeepPartial<T> = {
6060

6161
class createMfe {
6262
private static readonly containerSelector = '#grafanaRoot';
63-
64-
private static readonly logPrefix = '[FN Grafana]';
63+
private static logger = FnLoggerService;
6564

6665
mode: FNDashboardProps['mode'];
6766
static Component: ComponentType<Omit<FNDashboardProps, FnPropMappedFromState>>;
6867
constructor(readonly props: FNDashboardProps) {
6968
this.mode = props.mode;
7069
}
7170

72-
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
73-
private static logger = (...args: any[]) => console.log(createMfe.logPrefix, ...args);
74-
7571
static getLifeCycles(component: ComponentType<Omit<FNDashboardProps, FnPropMappedFromState>>) {
7672
const lifeCycles: FrameworkLifeCycles = {
7773
bootstrap: this.boot(),
@@ -113,7 +109,7 @@ class createMfe {
113109
},
114110
});
115111

116-
config.theme2.colors = createFnColors({ mode });
112+
config.theme2.colors = createColors({ mode });
117113

118114
config.theme2.v1 = getTheme(mode);
119115

@@ -168,7 +164,7 @@ class createMfe {
168164
* If isRuntimeOnly then the stylesheets of the turned off theme are not removed
169165
*/
170166
private static loadFnTheme = (mode: FNDashboardProps['mode'] = GrafanaThemeType.Light, isRuntimeOnly = false) => {
171-
createMfe.logger('Trying to load theme.', { mode });
167+
createMfe.logger.info('Trying to load theme.', { mode });
172168

173169
const grafanaTheme2 = createMfe.createGrafanaTheme2(mode);
174170

@@ -179,7 +175,7 @@ class createMfe {
179175
createMfe.publishTheme(bootConfigWithTheme.theme2);
180176

181177
if (isRuntimeOnly) {
182-
createMfe.logger('Successfully loaded theme', { mode });
178+
createMfe.logger.info('Successfully loaded theme', { mode });
183179

184180
return;
185181
}
@@ -190,7 +186,7 @@ class createMfe {
190186
newCssLink.href = config.bootData.themePaths[mode];
191187
document.body.appendChild(newCssLink);
192188

193-
createMfe.logger('Successfully loaded theme.', { mode });
189+
createMfe.logger.info('Successfully loaded theme.', { mode });
194190
};
195191

196192
private static getContainer(props: FNDashboardProps) {
@@ -201,8 +197,6 @@ class createMfe {
201197

202198
static mountFnApp(Component: ComponentType<Omit<FNDashboardProps, FnPropMappedFromState>>) {
203199
const lifeCycleFn: FrameworkLifeCycles['mount'] = (props: FNDashboardProps) => {
204-
createMfe.logger('Trying to mount grafana...');
205-
206200
return new Promise((res, rej) => {
207201
try {
208202
createMfe.loadFnTheme(props.mode);
@@ -214,19 +208,19 @@ class createMfe {
214208
...pick(props, ...fnStateProps),
215209
};
216210

217-
FnLoggerService.log(null, '[FN Grafana] Dispatching initial state.', { initialState });
211+
createMfe.logger.info('[FN Grafana] Dispatching initial state.', { initialState });
218212

219213
dispatch(updateFnState(initialState));
220214

221215
createMfe.renderMfeComponent(props, () => {
222-
createMfe.logger('Mounted grafana.', { props });
216+
createMfe.logger.info('Mounted grafana.', { props });
223217

224218
return res(true);
225219
});
226220
} catch (err) {
227221
const message = `[FN Grafana]: Failed to mount grafana. ${err}`;
228222

229-
FnLoggerService.log(null, message);
223+
FnLoggerService.info(null, message);
230224

231225
const fnError = new Error(message);
232226

@@ -246,13 +240,13 @@ class createMfe {
246240
const container = createMfe.getContainer(props);
247241

248242
if (container) {
249-
createMfe.logger('Trying to unmount grafana...');
243+
createMfe.logger.info('Trying to unmount grafana...');
250244

251245
ReactDOM.unmountComponentAtNode(container);
252246

253-
createMfe.logger('Successfully unmounted grafana.');
247+
createMfe.logger.info('Successfully unmounted grafana.');
254248
} else {
255-
createMfe.logger('Failed to unmount grafana. Container does not exist.');
249+
createMfe.logger.error('Failed to unmount grafana. Container does not exist.');
256250
}
257251

258252
backendSrv.cancelAllInFlightRequests();
@@ -266,26 +260,17 @@ class createMfe {
266260
static updateFnApp() {
267261
const lifeCycleFn: FrameworkLifeCycles['update'] = ({ mode, ...other }: FNDashboardProps) => {
268262
if (mode) {
269-
createMfe.logger('Trying to update grafana with theme.', { mode });
270-
271263
dispatch(
272264
updatePartialFnStates({
273265
mode,
274266
})
275267
);
276-
/**
277-
* NOTE:
278-
* Here happens the theme change.
279-
*
280-
* TODO:
281-
* We could probably made the theme change smoother
282-
* if we use state to update the theme
283-
*/
268+
284269
createMfe.loadFnTheme(mode);
285270
}
286271

287272
if (other.uid) {
288-
createMfe.logger('Trying to update grafana with hidden variables.', { updatedProps: other });
273+
createMfe.logger.info('Trying to render dashboard using update: ', { updatedProps: other });
289274

290275
dispatch(
291276
updatePartialFnStates({
@@ -294,6 +279,7 @@ class createMfe {
294279
slug: other.slug,
295280
version: other.version,
296281
queryParams: other.queryParams,
282+
controlsContainer: other.controlsContainer,
297283
})
298284
);
299285
}
@@ -308,14 +294,10 @@ class createMfe {
308294
static renderMfeComponent(props: FNDashboardProps, onSuccess = noop) {
309295
const container = createMfe.getContainer(props);
310296

311-
ReactDOM.render(
312-
React.createElement(createMfe.Component, omit(props, 'hiddenVariables', 'FNDashboard')),
313-
container,
314-
() => {
315-
createMfe.logger('Created mfe component.', { props, container });
316-
onSuccess();
317-
}
318-
);
297+
ReactDOM.render(React.createElement(createMfe.Component, props), container, () => {
298+
createMfe.logger.info('Created mfe component.', { props, container });
299+
onSuccess();
300+
});
319301
}
320302
}
321303

Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
import { pick } from 'lodash';
22
import React, { FC, useMemo } from 'react';
3-
import { connect, MapStateToProps } from 'react-redux';
43

5-
import {
6-
FnGlobalState,
7-
FN_STATE_KEY,
8-
FnPropMappedFromState,
9-
fnPropsMappedFromState,
10-
FnPropsMappedFromState,
11-
} from 'app/core/reducers/fn-slice';
4+
import { FnPropMappedFromState, fnPropsMappedFromState } from 'app/core/reducers/fn-slice';
5+
import { StoreState, useSelector } from 'app/types';
126

13-
import { AngularRoot } from '../../angular/AngularRoot';
147
import { FnAppProvider } from '../fn-app-provider';
158
import { FNDashboardProps } from '../types';
169
import { RenderPortal } from '../utils';
@@ -22,33 +15,34 @@ type FNDashboardComponentProps = Omit<FNDashboardProps, FnPropMappedFromState>;
2215
export const FNDashboard: FC<FNDashboardComponentProps> = (props) => {
2316
return (
2417
<FnAppProvider fnError={props.fnError}>
25-
<div className="page-dashboard">
26-
<AngularRoot />
27-
<DashboardPortal {...props} />
28-
</div>
18+
<DashboardPortal {...props} />
2919
</FnAppProvider>
3020
);
3121
};
3222

33-
function mapStateToProps(): MapStateToProps<
34-
FnPropsMappedFromState,
35-
Omit<FNDashboardProps, FnPropMappedFromState>,
36-
{ [K in typeof FN_STATE_KEY]: FnGlobalState }
37-
> {
38-
return ({ fnGlobalState }) => pick(fnGlobalState, ...fnPropsMappedFromState);
23+
function mapStateToProps() {
24+
return ({ fnGlobalState }: StoreState) => pick(fnGlobalState, ...fnPropsMappedFromState);
3925
}
4026

41-
export const DashboardPortalComponent: FC<FNDashboardComponentProps & FnPropsMappedFromState> = (props) => {
27+
export const DashboardPortal: FC<FNDashboardComponentProps> = (p) => {
28+
const globalFnProps = useSelector(mapStateToProps());
29+
30+
const props = useMemo(
31+
() => ({
32+
...p,
33+
...globalFnProps,
34+
}),
35+
[p, globalFnProps]
36+
);
37+
4238
const content = useMemo(() => {
4339
if (!props.FNDashboard) {
44-
// TODO Use no data
4540
return null;
4641
}
4742

48-
const { uid, slug, queryParams = {} } = props;
43+
const { uid, queryParams = {} } = props;
4944

50-
if (!uid || !slug) {
51-
// TODO Use no data
45+
if (!uid) {
5246
return null;
5347
}
5448

@@ -57,14 +51,15 @@ export const DashboardPortalComponent: FC<FNDashboardComponentProps & FnPropsMap
5751
{...{
5852
...props,
5953
uid,
60-
slug,
6154
queryParams,
6255
}}
6356
/>
6457
);
6558
}, [props]);
6659

67-
return <RenderPortal ID="grafana-portal">{content}</RenderPortal>;
60+
return (
61+
<RenderPortal ID="grafana-portal">
62+
<div className="page-dashboard">{content}</div>
63+
</RenderPortal>
64+
);
6865
};
69-
70-
export const DashboardPortal = connect(mapStateToProps())(DashboardPortalComponent);

public/app/fn-app/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface FNDashboardProps {
2727
queryParams: ParsedQuery<string>;
2828
fnError?: ReactNode;
2929
pageTitle?: string;
30-
controlsContainer: string;
30+
controlsContainer: string | null;
3131
isLoading: (isLoading: boolean) => void;
3232
setErrors: (errors?: { [K: number | string]: string }) => void;
3333
hiddenVariables: readonly string[];

public/app/fn-app/utils.tsx

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
import { FC, PropsWithChildren } from 'react';
2-
import ReactDOM from 'react-dom';
1+
import { Portal } from '@mui/material';
2+
import React, { FC, PropsWithChildren } from 'react';
33

44
export interface RenderPortalProps {
55
ID: string;
66
}
77

8-
export const getPortalContainer = (ID: string): HTMLElement | null => document.getElementById(ID);
9-
108
export const RenderPortal: FC<PropsWithChildren<RenderPortalProps>> = ({ ID, children }) => {
11-
const portalDiv = getPortalContainer(ID);
9+
const container = document.getElementById(ID);
1210

13-
if (!portalDiv) {
11+
if (!container) {
1412
return null;
1513
}
1614

17-
return ReactDOM.createPortal(children, portalDiv);
15+
return <Portal container={container}>{children}</Portal>;
1816
};

public/app/plugins/datasource/fifemon-graphql-datasource/GraphQLAnnotationsQueryCtrl.tsx

-5
This file was deleted.

public/app/plugins/datasource/fifemon-graphql-datasource/img/README

-4
This file was deleted.
Binary file not shown.

0 commit comments

Comments
 (0)