Skip to content

Commit

Permalink
[TSVB] Adds ignore DST switch for timeseries (#98484) (#99343)
Browse files Browse the repository at this point in the history
* [TSVB] add ignore DST switch

* [TSVB] move YesNo component to timeseries panel, get rid of getTimezone call

* [TSVB] reduce formatter creation number

* [TSVB] add usage EuFormRow, remove redundant translations

* [TSVB] use boolean instead of number

* [TSVB] use number for YesNo

* [TSVB] resolve YesNo value type

* [TSVB] replace number with boolean

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Dmitry Tomashevich <[email protected]>
  • Loading branch information
kibanamachine and dimaanj authored May 5, 2021
1 parent 64f6c70 commit d800252
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/plugins/vis_type_timeseries/common/vis_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export const panel = schema.object({
background_color_rules: schema.maybe(schema.arrayOf(backgroundColorRulesItems)),
drilldown_url: stringOptional,
drop_last_bucket: numberIntegerOptional,
ignore_daylight_time: schema.boolean(),
filter: schema.maybe(queryObject),
gauge_color_rules: schema.maybe(schema.arrayOf(gaugeColorRulesItems)),
gauge_width: schema.nullable(schema.oneOf([stringOptionalNullable, numberOptional])),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface LastValueModeIndicatorProps {
seriesData?: PanelData['data'];
panelInterval: number;
modelInterval: string;
ignoreDaylightTime: boolean;
}

const lastValueLabel = i18n.translate('visTypeTimeseries.lastValueModeIndicator.lastValue', {
Expand All @@ -29,6 +30,7 @@ export const LastValueModeIndicator = ({
seriesData,
panelInterval,
modelInterval,
ignoreDaylightTime,
}: LastValueModeIndicatorProps) => {
if (!seriesData?.length) return <EuiBadge>{lastValueLabel}</EuiBadge>;

Expand All @@ -40,7 +42,12 @@ export const LastValueModeIndicator = ({
return interval && `${interval.unitValue}${interval.unitString}`;
};

const formatter = createIntervalBasedFormatter(panelInterval, scaledDataFormat, dateFormat);
const formatter = createIntervalBasedFormatter(
panelInterval,
scaledDataFormat,
dateFormat,
ignoreDaylightTime
);
const lastBucketDate = formatter(seriesData[seriesData.length - 1][0]);
const formattedPanelInterval =
(isAutoInterval(modelInterval) || isGteInterval(modelInterval)) && getFormattedPanelInterval();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import moment from 'moment';

const JANUARY_MOMENT_CONFIG = { M: 0, d: 1 };

function getFormat(interval: number, rules: string[][] = []) {
for (let i = rules.length - 1; i >= 0; i--) {
const rule = rules[i];
Expand All @@ -20,9 +22,15 @@ function getFormat(interval: number, rules: string[][] = []) {
export function createIntervalBasedFormatter(
interval: number,
rules: string[][],
dateFormat: string
dateFormat: string,
ignoreDaylightTime: boolean
) {
return (val: moment.MomentInput): string => {
return moment(val).format(getFormat(interval, rules) ?? dateFormat);
const fixedOffset = moment(JANUARY_MOMENT_CONFIG).utcOffset();
return (val: moment.MomentInput) => {
const momentVal = moment(val);
if (ignoreDaylightTime) {
momentVal.utcOffset(fixedOffset);
}
return momentVal.format(getFormat(interval, rules) ?? dateFormat);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export class TimeseriesPanelConfig extends Component<
legend_position: 'right',
show_grid: 1,
tooltip_mode: 'show_all',
ignore_daylight_time: false,
};
const model = { ...defaults, ...this.props.model };
const { selectedTab } = this.state;
Expand Down Expand Up @@ -227,6 +228,22 @@ export class TimeseriesPanelConfig extends Component<
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiFormRow
label={i18n.translate(
'visTypeTimeseries.timeseries.optionsTab.ignoreDaylightTimeLabel',
{
defaultMessage: 'Ignore daylight time?',
}
)}
>
<YesNo
value={model.ignore_daylight_time}
name="ignore_daylight_time"
onChange={this.props.onChange}
/>
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function SeriesConfigQueryBarWithIgnoreGlobalFilter({
const htmlId = htmlIdGenerator();
const yesNoOption = (
<YesNo
disabled={Boolean(panel.ignore_global_filter)}
disabled={panel.ignore_global_filter}
value={model.ignore_global_filter}
name="ignore_global_filter"
onChange={onChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ function TimeseriesVisualization({
`${isVisSeriesData(visData) ? model.id : 'series[0]'}.series[0].data`,
undefined
)}
ignoreDaylightTime={model.ignore_daylight_time}
panelInterval={getInterval(visData, model)}
modelInterval={model.interval ?? AUTO_INTERVAL}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ class TimeseriesVisualization extends Component {
scaledDataFormat = this.props.getConfig('dateFormat:scaled');
dateFormat = this.props.getConfig('dateFormat');

xAxisFormatter = (interval) => (val) => {
xAxisFormatter = (interval) => {
const formatter = createIntervalBasedFormatter(
interval,
this.scaledDataFormat,
this.dateFormat
this.dateFormat,
this.props.model.ignore_daylight_time
);
return formatter(val);
return (val) => formatter(val);
};

yAxisStackedByPercentFormatter = (val) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { TimeseriesVisParams } from '../../types';

interface YesNoProps<ParamName extends keyof TimeseriesVisParams> {
name: ParamName;
value: TimeseriesVisParams[ParamName];
value: boolean | number | undefined;
disabled?: boolean;
'data-test-subj'?: string;
onChange: (partialModel: Partial<TimeseriesVisParams>) => void;
Expand Down

0 comments on commit d800252

Please sign in to comment.