The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
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.
 
 
 
 
 
 
grafana/public/app/features/dashboard/components/SubMenu/SubMenu.tsx

85 lines
2.5 KiB

import { css } from '@emotion/css';
import React, { PureComponent } from 'react';
import { connect, MapStateToProps } from 'react-redux';
import { AnnotationQuery } from '@grafana/data';
import { StoreState } from '../../../../types';
import { getSubMenuVariables, getVariablesState } from '../../../variables/state/selectors';
import { VariableModel } from '../../../variables/types';
import { DashboardModel } from '../../state';
import { DashboardLink } from '../../state/DashboardModel';
import { Annotations } from './Annotations';
import { DashboardLinks } from './DashboardLinks';
import { SubMenuItems } from './SubMenuItems';
interface OwnProps {
dashboard: DashboardModel;
links: DashboardLink[];
annotations: AnnotationQuery[];
}
interface ConnectedProps {
variables: VariableModel[];
}
interface DispatchProps {}
type Props = OwnProps & ConnectedProps & DispatchProps;
class SubMenuUnConnected extends PureComponent<Props> {
onAnnotationStateChanged = (updatedAnnotation: any) => {
// we're mutating dashboard state directly here until annotations are in Redux.
for (let index = 0; index < this.props.dashboard.annotations.list.length; index++) {
const annotation = this.props.dashboard.annotations.list[index];
if (annotation.name === updatedAnnotation.name) {
annotation.enable = !annotation.enable;
break;
}
}
this.props.dashboard.startRefresh();
this.forceUpdate();
};
render() {
const { dashboard, variables, links, annotations } = this.props;
if (!dashboard.isSubMenuVisible()) {
return null;
}
return (
<div className="submenu-controls">
<form aria-label="Template variables" className={styles}>
<SubMenuItems variables={variables} />
</form>
<Annotations
annotations={annotations}
onAnnotationChanged={this.onAnnotationStateChanged}
events={dashboard.events}
/>
<div className="gf-form gf-form--grow" />
{dashboard && <DashboardLinks dashboard={dashboard} links={links} />}
</div>
);
}
}
const mapStateToProps: MapStateToProps<ConnectedProps, OwnProps, StoreState> = (state, ownProps) => {
const { uid } = ownProps.dashboard;
const templatingState = getVariablesState(uid, state);
return {
variables: getSubMenuVariables(uid, templatingState.variables),
};
};
const styles = css`
display: flex;
flex-wrap: wrap;
display: contents;
`;
export const SubMenu = connect(mapStateToProps)(SubMenuUnConnected);
SubMenu.displayName = 'SubMenu';