You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1.0 KiB
29 lines
1.0 KiB
import { FC, ReactElement, useEffect, useState } from 'react';
|
|
import { useSelector } from 'react-redux';
|
|
import { PanelMenuItem } from '@grafana/data';
|
|
|
|
import { DashboardModel, PanelModel } from '../../state';
|
|
import { StoreState } from '../../../../types';
|
|
import { getPanelMenu } from '../../utils/getPanelMenu';
|
|
import { getPanelStateForModel } from 'app/features/panel/state/selectors';
|
|
|
|
interface PanelHeaderMenuProviderApi {
|
|
items: PanelMenuItem[];
|
|
}
|
|
|
|
interface Props {
|
|
panel: PanelModel;
|
|
dashboard: DashboardModel;
|
|
children: (props: PanelHeaderMenuProviderApi) => ReactElement;
|
|
}
|
|
|
|
export const PanelHeaderMenuProvider: FC<Props> = ({ panel, dashboard, children }) => {
|
|
const [items, setItems] = useState<PanelMenuItem[]>([]);
|
|
const angularComponent = useSelector((state: StoreState) => getPanelStateForModel(state, panel)?.angularComponent);
|
|
|
|
useEffect(() => {
|
|
setItems(getPanelMenu(dashboard, panel, angularComponent));
|
|
}, [dashboard, panel, angularComponent, setItems]);
|
|
|
|
return children({ items });
|
|
};
|
|
|