mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 05:43:00 +08:00

* Replace icons in dashboard and settings * Replace icons in alerting * Update batch of icons * Implement icons accross various files * Style updates * Search: Fix recent and starred icons * Update styling and details * Replace new icon created by unicons * Fix e2e test, styling * Minor styling updates Co-authored-by: Clarity-89 <homes89@ukr.net>
113 lines
3.3 KiB
TypeScript
113 lines
3.3 KiB
TypeScript
import React from 'react';
|
|
import classNames from 'classnames';
|
|
import { Icon } from '@grafana/ui';
|
|
import { PanelModel } from '../../state/PanelModel';
|
|
import { DashboardModel } from '../../state/DashboardModel';
|
|
import templateSrv from 'app/features/templating/template_srv';
|
|
import appEvents from 'app/core/app_events';
|
|
import { CoreEvents } from 'app/types';
|
|
|
|
export interface DashboardRowProps {
|
|
panel: PanelModel;
|
|
dashboard: DashboardModel;
|
|
}
|
|
|
|
export class DashboardRow extends React.Component<DashboardRowProps, any> {
|
|
constructor(props: DashboardRowProps) {
|
|
super(props);
|
|
|
|
this.state = {
|
|
collapsed: this.props.panel.collapsed,
|
|
};
|
|
|
|
this.props.dashboard.on(CoreEvents.templateVariableValueUpdated, this.onVariableUpdated);
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
this.props.dashboard.off(CoreEvents.templateVariableValueUpdated, this.onVariableUpdated);
|
|
}
|
|
|
|
onVariableUpdated = () => {
|
|
this.forceUpdate();
|
|
};
|
|
|
|
onToggle = () => {
|
|
this.props.dashboard.toggleRow(this.props.panel);
|
|
|
|
this.setState((prevState: any) => {
|
|
return { collapsed: !prevState.collapsed };
|
|
});
|
|
};
|
|
|
|
onUpdate = () => {
|
|
this.props.dashboard.processRepeats();
|
|
this.forceUpdate();
|
|
};
|
|
|
|
onOpenSettings = () => {
|
|
appEvents.emit(CoreEvents.showModal, {
|
|
templateHtml: `<row-options row="model.row" on-updated="model.onUpdated()" dismiss="dismiss()"></row-options>`,
|
|
modalClass: 'modal--narrow',
|
|
model: {
|
|
row: this.props.panel,
|
|
onUpdated: this.onUpdate,
|
|
},
|
|
});
|
|
};
|
|
|
|
onDelete = () => {
|
|
appEvents.emit(CoreEvents.showConfirmModal, {
|
|
title: 'Delete Row',
|
|
text: 'Are you sure you want to remove this row and all its panels?',
|
|
altActionText: 'Delete row only',
|
|
icon: 'fa-trash',
|
|
onConfirm: () => {
|
|
this.props.dashboard.removeRow(this.props.panel, true);
|
|
},
|
|
onAltAction: () => {
|
|
this.props.dashboard.removeRow(this.props.panel, false);
|
|
},
|
|
});
|
|
};
|
|
|
|
render() {
|
|
const classes = classNames({
|
|
'dashboard-row': true,
|
|
'dashboard-row--collapsed': this.state.collapsed,
|
|
});
|
|
|
|
const title = templateSrv.replaceWithText(this.props.panel.title, this.props.panel.scopedVars);
|
|
const count = this.props.panel.panels ? this.props.panel.panels.length : 0;
|
|
const panels = count === 1 ? 'panel' : 'panels';
|
|
const canEdit = this.props.dashboard.meta.canEdit === true;
|
|
|
|
return (
|
|
<div className={classes}>
|
|
<a className="dashboard-row__title pointer" onClick={this.onToggle}>
|
|
<Icon name={this.state.collapsed ? 'angle-right' : 'angle-down'} />
|
|
{title}
|
|
<span className="dashboard-row__panel_count">
|
|
({count} {panels})
|
|
</span>
|
|
</a>
|
|
{canEdit && (
|
|
<div className="dashboard-row__actions">
|
|
<a className="pointer" onClick={this.onOpenSettings}>
|
|
<Icon name="cog" />
|
|
</a>
|
|
<a className="pointer" onClick={this.onDelete}>
|
|
<Icon name="trash-alt" />
|
|
</a>
|
|
</div>
|
|
)}
|
|
{this.state.collapsed === true && (
|
|
<div className="dashboard-row__toggle-target" onClick={this.onToggle}>
|
|
|
|
</div>
|
|
)}
|
|
{canEdit && <div className="dashboard-row__drag grid-drag-handle" />}
|
|
</div>
|
|
);
|
|
}
|
|
}
|