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

[Uptime] Update Moment Locale to keep it localized to the component #55177

Merged
Changes from all commits
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 @@ -66,44 +66,57 @@ export const LocationStatusTags = ({ locations }: Props) => {
return a.label > b.label ? 1 : b.label > a.label ? -1 : 0;
});

moment.updateLocale('en', {
relativeTime: {
future: 'in %s',
past: '%s ago',
s: '%ds',
ss: '%ss',
m: '%dm',
mm: '%dm',
h: '%dh',
hh: '%dh',
d: '%dd',
dd: '%dd',
M: '%d Mon',
MM: '%d Mon',
y: '%d Yr',
yy: '%d Yr',
},
});
const tagLabel = (item: StatusTag, ind: number, color: string) => {
return (
<BadgeItem key={ind}>
<EuiBadge color={color}>
<EuiText size="m">
<TextStyle>{item.label}</TextStyle>
</EuiText>
</EuiBadge>
<TimeStampSpan>
<EuiText color="subdued">{moment(item.timestamp).fromNow()}</EuiText>
</TimeStampSpan>
</BadgeItem>
);
};

const tagLabel = (item: StatusTag, ind: number, color: string) => (
<BadgeItem key={ind}>
<EuiBadge color={color}>
<EuiText size="m">
<TextStyle>{item.label}</TextStyle>
</EuiText>
</EuiBadge>
<TimeStampSpan>
<EuiText color="subdued">{moment(item.timestamp).fromNow()}</EuiText>
</TimeStampSpan>
</BadgeItem>
);
const prevLocal: string = moment.locale() ?? 'en';

return (
<>
const renderTags = () => {
moment.defineLocale('en-tag', {
relativeTime: {
future: 'in %s',
past: '%s ago',
s: '%ds',
ss: '%ss',
m: '%dm',
mm: '%dm',
h: '%dh',
hh: '%dh',
d: '%dd',
dd: '%dd',
M: '%d Mon',
MM: '%d Mon',
y: '%d Yr',
yy: '%d Yr',
},
});
const tags = (
<TagContainer>
<span>{downLocations.map((item, ind) => tagLabel(item, ind, danger))}</span>
<span>{upLocations.map((item, ind) => tagLabel(item, ind, gray))}</span>
</TagContainer>
);

// Need to reset locale so it doesn't effect other parts of the app
moment.locale(prevLocal);
return tags;
};

return (
<>
{renderTags()}
{locations.length > 7 && (
<OtherLocationsDiv>
<EuiText color="subdued">
Expand Down