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

[Field Formats] Duration formatter should handle pluralization for single values #196761

Open
nickofthyme opened this issue Oct 17, 2024 · 1 comment · May be fixed by #196987
Open

[Field Formats] Duration formatter should handle pluralization for single values #196761

nickofthyme opened this issue Oct 17, 2024 · 1 comment · May be fixed by #196987
Labels
Feature:FieldFormatters good first issue low hanging fruit impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL.

Comments

@nickofthyme
Copy link
Contributor

nickofthyme commented Oct 17, 2024

Describe the feature:

The Friendly duration formatters should account for singular values. Currently, we only use pluralized formats.

This is where we compute the unit text and join it with the value...

const getUnitText = (method: string) => {
const type = DURATION_OUTPUT_FORMATS.find(({ method: methodT }) => method === methodT);
return useShortSuffix ? type?.shortText : type?.text.toLowerCase();
};

Here is the list of all values...

const inputFormats = [
{
text: i18n.translate('fieldFormats.duration.inputFormats.picoseconds', {
defaultMessage: 'Picoseconds',
}),
kind: 'picoseconds',
},
{
text: i18n.translate('fieldFormats.duration.inputFormats.nanoseconds', {
defaultMessage: 'Nanoseconds',
}),
kind: 'nanoseconds',
},
{
text: i18n.translate('fieldFormats.duration.inputFormats.microseconds', {
defaultMessage: 'Microseconds',
}),
kind: 'microseconds',
},
{
text: i18n.translate('fieldFormats.duration.inputFormats.milliseconds', {
defaultMessage: 'Milliseconds',
}),
kind: 'milliseconds',
},
{ ...DEFAULT_INPUT_FORMAT },
{
text: i18n.translate('fieldFormats.duration.inputFormats.minutes', {
defaultMessage: 'Minutes',
}),
kind: 'minutes',
},
{
text: i18n.translate('fieldFormats.duration.inputFormats.hours', {
defaultMessage: 'Hours',
}),
kind: 'hours',
},
{
text: i18n.translate('fieldFormats.duration.inputFormats.days', {
defaultMessage: 'Days',
}),
kind: 'days',
},
{
text: i18n.translate('fieldFormats.duration.inputFormats.weeks', {
defaultMessage: 'Weeks',
}),
kind: 'weeks',
},
{
text: i18n.translate('fieldFormats.duration.inputFormats.months', {
defaultMessage: 'Months',
}),
kind: 'months',
},
{
text: i18n.translate('fieldFormats.duration.inputFormats.years', {
defaultMessage: 'Years',
}),
kind: 'years',
},
];
const DEFAULT_OUTPUT_FORMAT = {
text: i18n.translate('fieldFormats.duration.outputFormats.humanize.approximate', {
defaultMessage: 'Human-readable (approximate)',
}),
method: 'humanize',
};
const outputFormats = [
{ ...DEFAULT_OUTPUT_FORMAT },
{
text: i18n.translate('fieldFormats.duration.outputFormats.humanize.precise', {
defaultMessage: 'Human-readable (precise)',
}),
method: 'humanizePrecise',
},
{
text: i18n.translate('fieldFormats.duration.outputFormats.asMilliseconds', {
defaultMessage: 'Milliseconds',
}),
shortText: i18n.translate('fieldFormats.duration.outputFormats.asMilliseconds.short', {
defaultMessage: 'ms',
}),
method: 'asMilliseconds',
},
{
text: i18n.translate('fieldFormats.duration.outputFormats.asSeconds', {
defaultMessage: 'Seconds',
}),
shortText: i18n.translate('fieldFormats.duration.outputFormats.asSeconds.short', {
defaultMessage: 's',
}),
method: 'asSeconds',
},
{
text: i18n.translate('fieldFormats.duration.outputFormats.asMinutes', {
defaultMessage: 'Minutes',
}),
shortText: i18n.translate('fieldFormats.duration.outputFormats.asMinutes.short', {
defaultMessage: 'min',
}),
method: 'asMinutes',
},
{
text: i18n.translate('fieldFormats.duration.outputFormats.asHours', {
defaultMessage: 'Hours',
}),
shortText: i18n.translate('fieldFormats.duration.outputFormats.asHours.short', {
defaultMessage: 'h',
}),
method: 'asHours',
},
{
text: i18n.translate('fieldFormats.duration.outputFormats.asDays', {
defaultMessage: 'Days',
}),
shortText: i18n.translate('fieldFormats.duration.outputFormats.asDays.short', {
defaultMessage: 'd',
}),
method: 'asDays',
},
{
text: i18n.translate('fieldFormats.duration.outputFormats.asWeeks', {
defaultMessage: 'Weeks',
}),
shortText: i18n.translate('fieldFormats.duration.outputFormats.asWeeks.short', {
defaultMessage: 'w',
}),
method: 'asWeeks',
},
{
text: i18n.translate('fieldFormats.duration.outputFormats.asMonths', {
defaultMessage: 'Months',
}),
shortText: i18n.translate('fieldFormats.duration.outputFormats.asMonths.short', {
defaultMessage: 'mon',
}),
method: 'asMonths',
},
{
text: i18n.translate('fieldFormats.duration.outputFormats.asYears', {
defaultMessage: 'Years',
}),
shortText: i18n.translate('fieldFormats.duration.outputFormats.asYears.short', {
defaultMessage: 'y',
}),
method: 'asYears',
},
];

This only applies to the long form text strings and not the shortText strings.

Describe a specific use case for the feature:

Image

Notice 1 seconds should be 1 second.

Pretty simple and low impact but could be nice.

@nickofthyme nickofthyme added Feature:FieldFormatters good first issue low hanging fruit impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort labels Oct 17, 2024
@botelastic botelastic bot added the needs-team Issues missing a team label label Oct 17, 2024
@bhavyarm bhavyarm added the Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. label Oct 18, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:FieldFormatters good first issue low hanging fruit impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL.
Projects
None yet
3 participants