grafana/public/app/features/dashboard/components/SubMenu/SubMenu.tsx
Torkel Ödegaard 7b23ed728f
DashboardSettings: Migrates annotations list & edit view from angular to react and new forms styles (#31950)
* Initial commit, list and edit page working

* Progress

* angular and standard editors work

* Unifying more between annotations list and links list

* Remove submenu visibilty stuff

* Update packages/grafana-data/src/types/annotations.ts

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>

* Review feedback

* fixed checkbox

* Fixes

* test(annotationsettings): initial commit of tests

* delete files brought back by master merge

* update datasourcepicker import path

* update emotion import

* test(linksettings): clean up tests

* Fixed test

* test(annotationssettings): add remaining tests

* docs(grafana-data): export namespace for docs build

* docs(grafana-ui): export ColorValueEditorProps for docs build

* docs(grafana-ui): add docs annotation for ColorValueEditorProps

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
2021-04-12 09:41:07 +02:00

69 lines
2.2 KiB
TypeScript

import React, { PureComponent } from 'react';
import { connect, MapStateToProps } from 'react-redux';
import { StoreState } from '../../../../types';
import { getSubMenuVariables } from '../../../variables/state/selectors';
import { VariableModel } from '../../../variables/types';
import { DashboardModel } from '../../state';
import { DashboardLinks } from './DashboardLinks';
import { Annotations } from './Annotations';
import { SubMenuItems } from './SubMenuItems';
import { DashboardLink } from '../../state/DashboardModel';
import { AnnotationQuery } from '@grafana/data';
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">
<SubMenuItems variables={variables} />
<Annotations annotations={annotations} onAnnotationChanged={this.onAnnotationStateChanged} />
<div className="gf-form gf-form--grow" />
{dashboard && <DashboardLinks dashboard={dashboard} links={links} />}
<div className="clearfix" />
</div>
);
}
}
const mapStateToProps: MapStateToProps<ConnectedProps, OwnProps, StoreState> = (state) => {
return {
variables: getSubMenuVariables(state.templating.variables),
};
};
export const SubMenu = connect(mapStateToProps)(SubMenuUnConnected);
SubMenu.displayName = 'SubMenu';