Skip to content

render time range selector any where, removed dead code #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions FN_README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Sankey plugin

## How to work with it?
## Sankey Plugin

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:

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

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

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

# [Graphql datasource plugin](./public/app/plugins//datasource//fifemon-graphql-datasource/)
## Local Testing

Run Grafana locally using:

```shell
make run

yarn start
```

Port forward local prometheus and druid from [cloud](https://github.com/fluxninja/cloud) repo using fn:

```shell
cd cloud

LOGURU_LEVEL=TRACE fn dev service-proxy --cluster <cluster-name> prometheus-cloud druid-router

https://github.com/fifemon/graphql-datasource/tree/v1.3.0/src
```

Release: v1.3.0
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).

# Troubleshooting
## Troubleshooting

## "Cannot find module" typescript errors (ts2307)
### "Cannot find module" typescript errors (ts2307)

Smart IDEs (such as VSCode or IntelliJ) require special configuration for TypeScript to work when using Plug'n'Play installs.
A collection of settings for each editor can be found under the (link)[https://yarnpkg.com/getting-started/editor-sdks#vscode]
Expand Down
2 changes: 1 addition & 1 deletion public/app/core/reducers/fn-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type SetFnStateAction = PayloadAction<Omit<FnGlobalState, 'hiddenVariable

export type FnPropMappedFromState = Extract<
keyof FnGlobalState,
'FNDashboard' | 'hiddenVariables' | 'mode' | 'uid' | 'queryParams' | 'slug' | 'version'
'FNDashboard' | 'hiddenVariables' | 'mode' | 'uid' | 'queryParams' | 'slug' | 'version' | 'controlsContainer'
>;
export type FnStateProp = keyof FnGlobalState;

Expand Down
26 changes: 17 additions & 9 deletions public/app/features/dashboard/containers/DashboardPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { cx } from '@emotion/css';
import { Portal } from '@mui/material';
import React, { PureComponent } from 'react';
import { connect, ConnectedProps, MapDispatchToProps, MapStateToProps } from 'react-redux';

Expand Down Expand Up @@ -71,7 +72,7 @@ export type MapStateToDashboardPageProps = MapStateToProps<
Pick<DashboardState, 'initPhase' | 'initError'> & {
dashboard: ReturnType<DashboardState['getModel']>;
navIndex: StoreState['navIndex'];
} & Pick<FnGlobalState, 'FNDashboard'>,
} & Pick<FnGlobalState, 'FNDashboard' | 'controlsContainer'>,
OwnProps,
StoreState
>;
Expand All @@ -92,6 +93,7 @@ export const mapStateToProps: MapStateToDashboardPageProps = (state) => ({
dashboard: state.dashboard.getModel(),
navIndex: state.navIndex,
FNDashboard: state.fnGlobalState.FNDashboard,
controlsContainer: state.fnGlobalState.controlsContainer,
});

const mapDispatchToProps: MapDispatchToDashboardPageProps = {
Expand Down Expand Up @@ -376,7 +378,7 @@ export class UnthemedDashboardPage extends PureComponent<Props, State> {
}

render() {
const { dashboard, initError, queryParams, FNDashboard } = this.props;
const { dashboard, initError, queryParams, FNDashboard, controlsContainer } = this.props;
const { editPanel, viewPanel, updateScrollTop, pageNav, sectionNav } = this.state;
const kioskMode = getKioskMode(this.props.queryParams);

Expand All @@ -402,6 +404,18 @@ export class UnthemedDashboardPage extends PureComponent<Props, State> {
);
}

const FNTimeRange = !controlsContainer ? (
<ToolbarButtonRow alignment="right" style={{ marginBottom: '16px' }}>
<DashNavTimeControls dashboard={dashboard} onChangeTimeZone={updateTimeZoneForSession} key="time-controls" />
</ToolbarButtonRow>
) : (
<Portal container={document.getElementById(controlsContainer)!}>
<ToolbarButtonRow>
<DashNavTimeControls dashboard={dashboard} onChangeTimeZone={updateTimeZoneForSession} key="time-controls" />
</ToolbarButtonRow>
</Portal>
);

return (
<React.Fragment>
<Page
Expand All @@ -416,13 +430,7 @@ export class UnthemedDashboardPage extends PureComponent<Props, State> {
{showToolbar && (
<header data-testid={selectors.pages.Dashboard.DashNav.navV2}>
{FNDashboard ? (
<ToolbarButtonRow alignment="right" style={{ marginBottom: '16px' }}>
<DashNavTimeControls
dashboard={dashboard}
onChangeTimeZone={updateTimeZoneForSession}
key="time-controls"
/>
</ToolbarButtonRow>
FNTimeRange
) : (
<DashNav
dashboard={dashboard}
Expand Down
4 changes: 1 addition & 3 deletions public/app/features/plugins/built_in_plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const postgresPlugin = async () =>
await import(/* webpackChunkName: "postgresPlugin" */ 'app/plugins/datasource/postgres/module');
const grafadruidDruidDatasourcePlugin = async () =>
await import(/* webpackChunkName: "druidPlugin" */ 'app/plugins/datasource/grafadruid-druid-datasource/module');
const fifemonGraphqlDatasourcePlugin = async () =>
await import(/* webpackChunkName: "graphqlPlugin" */ 'app/plugins/datasource/fifemon-graphql-datasource/module');
const prometheusPlugin = async () =>
await import(/* webpackChunkName: "prometheusPlugin" */ 'app/plugins/datasource/prometheus/module');
const mssqlPlugin = async () =>
Expand Down Expand Up @@ -102,8 +100,8 @@ const builtInPlugins: any = {
'app/plugins/datasource/mysql/module': mysqlPlugin,
'app/plugins/datasource/postgres/module': postgresPlugin,
'app/plugins/datasource/mssql/module': mssqlPlugin,
// Default FluxNinja Druid datasource
'app/plugins/datasource/grafadruid-druid-datasource/module': grafadruidDruidDatasourcePlugin,
'app/plugins/datasource/fifemon-graphql-datasource/module': fifemonGraphqlDatasourcePlugin,
'app/plugins/datasource/prometheus/module': prometheusPlugin,
'app/plugins/datasource/testdata/module': testDataDSPlugin,
'app/plugins/datasource/cloud-monitoring/module': cloudMonitoringPlugin,
Expand Down
16 changes: 6 additions & 10 deletions public/app/fn-app/create-mfe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare let __webpack_public_path__: string;
window.__grafana_public_path__ =
__webpack_public_path__.substring(0, __webpack_public_path__.lastIndexOf('build/')) || __webpack_public_path__;

import { isNull, merge, noop, omit, pick } from 'lodash';
import { isNull, merge, noop, pick } from 'lodash';
import React, { ComponentType } from 'react';
import ReactDOM from 'react-dom';

Expand Down Expand Up @@ -294,6 +294,7 @@ class createMfe {
slug: other.slug,
version: other.version,
queryParams: other.queryParams,
controlsContainer: other.controlsContainer,
})
);
}
Expand All @@ -308,15 +309,10 @@ class createMfe {
static renderMfeComponent(props: FNDashboardProps, onSuccess = noop) {
const container = createMfe.getContainer(props);

ReactDOM.render(
// @ts-ignore
React.createElement(createMfe.Component, omit(props, 'hiddenVariables', 'FNDashboard')),
container,
() => {
createMfe.logger('Created mfe component.', { props, container });
onSuccess();
}
);
ReactDOM.render(React.createElement(createMfe.Component, props), container, () => {
createMfe.logger('Created mfe component.', { props, container });
onSuccess();
});
}
}

Expand Down
37 changes: 17 additions & 20 deletions public/app/fn-app/fn-dashboard-page/fn-dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { pick } from 'lodash';
import React, { FC, useMemo } from 'react';
import { connect, MapStateToProps } from 'react-redux';

import {
FnGlobalState,
FN_STATE_KEY,
FnPropMappedFromState,
fnPropsMappedFromState,
FnPropsMappedFromState,
} from 'app/core/reducers/fn-slice';
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';
Expand All @@ -30,23 +24,29 @@ export const FNDashboard: FC<FNDashboardComponentProps> = (props) => {
);
};

function mapStateToProps(): MapStateToProps<
FnPropsMappedFromState,
Omit<FNDashboardProps, FnPropMappedFromState>,
{ [K in typeof FN_STATE_KEY]: FnGlobalState }
> {
return ({ fnGlobalState }) => pick(fnGlobalState, ...fnPropsMappedFromState);
function mapStateToProps() {
return ({ fnGlobalState }: StoreState) => pick(fnGlobalState, ...fnPropsMappedFromState);
}

export const DashboardPortalComponent: FC<FNDashboardComponentProps & FnPropsMappedFromState> = (props) => {
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, slug, queryParams = {} } = props;
const { uid, queryParams = {} } = props;

if (!uid || !slug) {
if (!uid) {
return null;
}

Expand All @@ -55,7 +55,6 @@ export const DashboardPortalComponent: FC<FNDashboardComponentProps & FnPropsMap
{...{
...props,
uid,
slug,
queryParams,
}}
/>
Expand All @@ -64,5 +63,3 @@ export const DashboardPortalComponent: FC<FNDashboardComponentProps & FnPropsMap

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

export const DashboardPortal = connect(mapStateToProps())(DashboardPortalComponent);
2 changes: 1 addition & 1 deletion public/app/fn-app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface FNDashboardProps {
queryParams: ParsedQuery<string>;
fnError?: ReactNode;
pageTitle?: string;
controlsContainer: string;
controlsContainer: string | null;
isLoading: (isLoading: boolean) => void;
setErrors: (errors?: { [K: number | string]: string }) => void;
hiddenVariables: readonly string[];
Expand Down
12 changes: 5 additions & 7 deletions public/app/fn-app/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { FC, PropsWithChildren } from 'react';
import ReactDOM from 'react-dom';
import { Portal } from '@mui/material';
import React, { FC, PropsWithChildren } from 'react';

export interface RenderPortalProps {
ID: string;
}

export const getPortalContainer = (ID: string): HTMLElement | null => document.getElementById(ID);

export const RenderPortal: FC<PropsWithChildren<RenderPortalProps>> = ({ ID, children }) => {
const portalDiv = getPortalContainer(ID);
const container = document.getElementById(ID);

if (!portalDiv) {
if (!container) {
return null;
}

return ReactDOM.createPortal(children, portalDiv);
return <Portal container={container}>{children}</Portal>;
};

This file was deleted.

Loading