Skip to content

Commit

Permalink
update local (#55177) (#55318)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored Jan 20, 2020
1 parent d31dea3 commit 6f249ea
Showing 1 changed file with 45 additions and 32 deletions.
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

0 comments on commit 6f249ea

Please sign in to comment.