Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Fix time shift usability issues #102709

Merged
merged 3 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const parseTimeShift = (val: string): moment.Duration | 'previous' | 'inv
if (trimmedVal === 'previous') {
return 'previous';
}
const [, amount, unit] = trimmedVal.match(/^(\d+)(\w)$/) || [];
const [, amount, unit] = trimmedVal.match(/^(\d+)\s*(\w)$/) || [];
const parsedAmount = Number(amount);
if (Number.isNaN(parsedAmount) || !allowedUnits.includes(unit as AllowedUnit)) {
return 'invalid';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function TimeShift({
isClearable={false}
data-test-subj="indexPattern-dimension-time-shift"
placeholder={i18n.translate('xpack.lens.indexPattern.timeShiftPlaceholder', {
defaultMessage: 'Time shift (e.g. 1d)',
defaultMessage: 'Type custom values (e.g. 8w)',
})}
options={timeShiftOptions.filter(({ value }) => {
const parsedValue = parseTimeShift(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,67 +23,67 @@ import { FramePublicAPI } from '../types';
export const timeShiftOptions = [
{
label: i18n.translate('xpack.lens.indexPattern.timeShift.hour', {
defaultMessage: '1 hour (1h)',
defaultMessage: '1 hour ago (1h)',
}),
value: '1h',
},
{
label: i18n.translate('xpack.lens.indexPattern.timeShift.3hours', {
defaultMessage: '3 hours (3h)',
defaultMessage: '3 hours ago (3h)',
}),
value: '3h',
},
{
label: i18n.translate('xpack.lens.indexPattern.timeShift.6hours', {
defaultMessage: '6 hours (6h)',
defaultMessage: '6 hours ago (6h)',
}),
value: '6h',
},
{
label: i18n.translate('xpack.lens.indexPattern.timeShift.12hours', {
defaultMessage: '12 hours (12h)',
defaultMessage: '12 hours ago (12h)',
}),
value: '12h',
},
{
label: i18n.translate('xpack.lens.indexPattern.timeShift.day', {
defaultMessage: '1 day (1d)',
defaultMessage: '1 day ago (1d)',
}),
value: '1d',
},
{
label: i18n.translate('xpack.lens.indexPattern.timeShift.week', {
defaultMessage: '1 week (1w)',
defaultMessage: '1 week ago (1w)',
}),
value: '1w',
},
{
label: i18n.translate('xpack.lens.indexPattern.timeShift.month', {
defaultMessage: '1 month (1M)',
defaultMessage: '1 month ago (1M)',
}),
value: '1M',
},
{
label: i18n.translate('xpack.lens.indexPattern.timeShift.3months', {
defaultMessage: '3 months (3M)',
defaultMessage: '3 months ago (3M)',
}),
value: '3M',
},
{
label: i18n.translate('xpack.lens.indexPattern.timeShift.6months', {
defaultMessage: '6 months (6M)',
defaultMessage: '6 months ago (6M)',
}),
value: '6M',
},
{
label: i18n.translate('xpack.lens.indexPattern.timeShift.year', {
defaultMessage: '1 year (1y)',
defaultMessage: '1 year ago (1y)',
}),
value: '1y',
},
{
label: i18n.translate('xpack.lens.indexPattern.timeShift.previous', {
defaultMessage: 'Previous',
defaultMessage: 'Previous time range',
}),
value: 'previous',
},
Expand Down