mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* feat(dashboard): initial commit of general settings migration to react * fix(dashboardsettings): force update of general settings when selects change * feat(dashboardsettings): initial commit of delete dashboard button and modal * feat(dashboardsettings): introduce useDashboardDelete hook * feat(dashboardsettings): add tags and editable inputs * refactor(dashboardsettings): fix typescript error in general settings * refactor(dashboardsettings): use grafana-ui form components for general settings * refactor(dashboardsettings): use ConfirmModal and move provisioned modal to own component * refactor(dashboardsettings): revertDashboardModal uses ConfirmModal * test(autorefreshintervals): remove renderCount prop to fix test * test(dashboardsettings): put back aria-label for e2e tests * chore(dashboardsettings): remove redundant generl settings angular code * test: change references to now deleted SettingsCtrl to GeneralSettings * refactor(dashboardsettings): swap out switch for inlineswitch component * chore(timepickersettings): remove timePickerSettings angular directive definition * feat(dashboardsettings): add tooltips, fix description field name * refactor(dashboardsettings): remove redundant await Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com> * refactor(usedashboarddelete): clean up Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
97 lines
3.1 KiB
TypeScript
97 lines
3.1 KiB
TypeScript
import React, { PureComponent } from 'react';
|
|
import { InlineField, Input, InlineSwitch, TimeZonePicker, Tooltip } from '@grafana/ui';
|
|
import { rangeUtil, TimeZone } from '@grafana/data';
|
|
import isEmpty from 'lodash/isEmpty';
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
import { AutoRefreshIntervals } from './AutoRefreshIntervals';
|
|
|
|
interface Props {
|
|
onTimeZoneChange: (timeZone: TimeZone) => void;
|
|
onRefreshIntervalChange: (interval: string[]) => void;
|
|
onNowDelayChange: (nowDelay: string) => void;
|
|
onHideTimePickerChange: (hide: boolean) => void;
|
|
refreshIntervals: string[];
|
|
timePickerHidden: boolean;
|
|
nowDelay: string;
|
|
timezone: TimeZone;
|
|
}
|
|
|
|
interface State {
|
|
isNowDelayValid: boolean;
|
|
}
|
|
|
|
export class TimePickerSettings extends PureComponent<Props, State> {
|
|
state: State = { isNowDelayValid: true };
|
|
|
|
onNowDelayChange = (event: React.FormEvent<HTMLInputElement>) => {
|
|
const value = event.currentTarget.value;
|
|
|
|
if (isEmpty(value)) {
|
|
this.setState({ isNowDelayValid: true });
|
|
return this.props.onNowDelayChange(value);
|
|
}
|
|
|
|
if (rangeUtil.isValidTimeSpan(value)) {
|
|
this.setState({ isNowDelayValid: true });
|
|
return this.props.onNowDelayChange(value);
|
|
}
|
|
|
|
this.setState({ isNowDelayValid: false });
|
|
};
|
|
|
|
onHideTimePickerChange = () => {
|
|
this.props.onHideTimePickerChange(!this.props.timePickerHidden);
|
|
};
|
|
|
|
onTimeZoneChange = (timeZone: string) => {
|
|
if (typeof timeZone !== 'string') {
|
|
return;
|
|
}
|
|
this.props.onTimeZoneChange(timeZone);
|
|
};
|
|
|
|
render() {
|
|
return (
|
|
<div className="editor-row">
|
|
<h5 className="section-heading">Time Options</h5>
|
|
<div className="gf-form-group">
|
|
<div className="gf-form" aria-label={selectors.components.TimeZonePicker.container}>
|
|
<label className="gf-form-label width-7">Timezone</label>
|
|
<TimeZonePicker
|
|
includeInternal={true}
|
|
value={this.props.timezone}
|
|
onChange={this.onTimeZoneChange}
|
|
width={40}
|
|
/>
|
|
</div>
|
|
<AutoRefreshIntervals
|
|
refreshIntervals={this.props.refreshIntervals}
|
|
onRefreshIntervalChange={this.props.onRefreshIntervalChange}
|
|
/>
|
|
<div className="gf-form">
|
|
<span className="gf-form-label width-7">Now delay now-</span>
|
|
<Tooltip
|
|
placement="right"
|
|
content={'Enter 1m to ignore the last minute (because it can contain incomplete metrics)'}
|
|
>
|
|
<Input
|
|
width={60}
|
|
invalid={!this.state.isNowDelayValid}
|
|
placeholder="0m"
|
|
onChange={this.onNowDelayChange}
|
|
defaultValue={this.props.nowDelay}
|
|
/>
|
|
</Tooltip>
|
|
</div>
|
|
|
|
<div className="gf-form">
|
|
<InlineField labelWidth={14} label="Hide time picker">
|
|
<InlineSwitch value={!!this.props.timePickerHidden} onChange={this.onHideTimePickerChange} />
|
|
</InlineField>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
}
|