mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Geomap: use panel context editor state (#39920)
This commit is contained in:
parent
816d70a7e5
commit
9f93a81bee
@ -25,7 +25,7 @@ import { centerPointRegistry, MapCenterID } from './view';
|
|||||||
import { fromLonLat, toLonLat } from 'ol/proj';
|
import { fromLonLat, toLonLat } from 'ol/proj';
|
||||||
import { Coordinate } from 'ol/coordinate';
|
import { Coordinate } from 'ol/coordinate';
|
||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import { Portal, stylesFactory, VizTooltipContainer } from '@grafana/ui';
|
import { PanelContext, PanelContextRoot, Portal, stylesFactory, VizTooltipContainer } from '@grafana/ui';
|
||||||
import { GeomapOverlay, OverlayProps } from './GeomapOverlay';
|
import { GeomapOverlay, OverlayProps } from './GeomapOverlay';
|
||||||
import { DebugOverlay } from './components/DebugOverlay';
|
import { DebugOverlay } from './components/DebugOverlay';
|
||||||
import { getGlobalStyles } from './globalStyles';
|
import { getGlobalStyles } from './globalStyles';
|
||||||
@ -41,7 +41,6 @@ interface MapLayerState {
|
|||||||
|
|
||||||
// Allows multiple panels to share the same view instance
|
// Allows multiple panels to share the same view instance
|
||||||
let sharedView: View | undefined = undefined;
|
let sharedView: View | undefined = undefined;
|
||||||
export let lastGeomapPanelInstance: GeomapPanel | undefined = undefined;
|
|
||||||
|
|
||||||
type Props = PanelProps<GeomapPanelOptions>;
|
type Props = PanelProps<GeomapPanelOptions>;
|
||||||
interface State extends OverlayProps {
|
interface State extends OverlayProps {
|
||||||
@ -49,6 +48,9 @@ interface State extends OverlayProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class GeomapPanel extends Component<Props, State> {
|
export class GeomapPanel extends Component<Props, State> {
|
||||||
|
static contextType = PanelContextRoot;
|
||||||
|
panelContext: PanelContext = {} as PanelContext;
|
||||||
|
|
||||||
globalCSS = getGlobalStyles(config.theme2);
|
globalCSS = getGlobalStyles(config.theme2);
|
||||||
|
|
||||||
counter = 0;
|
counter = 0;
|
||||||
@ -66,7 +68,10 @@ export class GeomapPanel extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
lastGeomapPanelInstance = this;
|
this.panelContext = this.context as PanelContext;
|
||||||
|
if (this.panelContext.onInstanceStateChange) {
|
||||||
|
this.panelContext.onInstanceStateChange(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps: Props) {
|
shouldComponentUpdate(nextProps: Props) {
|
||||||
|
@ -4,10 +4,10 @@ import { Button, InlineField, InlineFieldRow, Select, VerticalGroup } from '@gra
|
|||||||
import { GeomapPanelOptions, MapViewConfig } from '../types';
|
import { GeomapPanelOptions, MapViewConfig } from '../types';
|
||||||
import { centerPointRegistry, MapCenterID } from '../view';
|
import { centerPointRegistry, MapCenterID } from '../view';
|
||||||
import { NumberInput } from 'app/features/dimensions/editors/NumberInput';
|
import { NumberInput } from 'app/features/dimensions/editors/NumberInput';
|
||||||
import { lastGeomapPanelInstance } from '../GeomapPanel';
|
|
||||||
import { toLonLat } from 'ol/proj';
|
import { toLonLat } from 'ol/proj';
|
||||||
|
import { GeomapPanel } from '../GeomapPanel';
|
||||||
|
|
||||||
export const MapViewEditor: FC<StandardEditorProps<MapViewConfig, any, GeomapPanelOptions>> = ({
|
export const MapViewEditor: FC<StandardEditorProps<MapViewConfig, any, GeomapPanelOptions, GeomapPanel>> = ({
|
||||||
value,
|
value,
|
||||||
onChange,
|
onChange,
|
||||||
context,
|
context,
|
||||||
@ -25,7 +25,7 @@ export const MapViewEditor: FC<StandardEditorProps<MapViewConfig, any, GeomapPan
|
|||||||
}, [value?.id]);
|
}, [value?.id]);
|
||||||
|
|
||||||
const onSetCurrentView = useCallback(() => {
|
const onSetCurrentView = useCallback(() => {
|
||||||
const map = lastGeomapPanelInstance?.map;
|
const map = context.instanceState?.map;
|
||||||
if (map) {
|
if (map) {
|
||||||
const view = map.getView();
|
const view = map.getView();
|
||||||
const coords = view.getCenter();
|
const coords = view.getCenter();
|
||||||
@ -40,7 +40,7 @@ export const MapViewEditor: FC<StandardEditorProps<MapViewConfig, any, GeomapPan
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [value, onChange]);
|
}, [value, onChange, context.instanceState]);
|
||||||
|
|
||||||
const onSelectView = useCallback(
|
const onSelectView = useCallback(
|
||||||
(selection: SelectableValue<string>) => {
|
(selection: SelectableValue<string>) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user