Skip to content

Commit bf0342e

Browse files
committed
update local (#55177)
1 parent 0d10f0e commit bf0342e

1 file changed

Lines changed: 45 additions & 32 deletions

File tree

x-pack/legacy/plugins/uptime/public/components/functional/location_map/location_status_tags.tsx

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,44 +66,57 @@ export const LocationStatusTags = ({ locations }: Props) => {
6666
return a.label > b.label ? 1 : b.label > a.label ? -1 : 0;
6767
});
6868

69-
moment.updateLocale('en', {
70-
relativeTime: {
71-
future: 'in %s',
72-
past: '%s ago',
73-
s: '%ds',
74-
ss: '%ss',
75-
m: '%dm',
76-
mm: '%dm',
77-
h: '%dh',
78-
hh: '%dh',
79-
d: '%dd',
80-
dd: '%dd',
81-
M: '%d Mon',
82-
MM: '%d Mon',
83-
y: '%d Yr',
84-
yy: '%d Yr',
85-
},
86-
});
69+
const tagLabel = (item: StatusTag, ind: number, color: string) => {
70+
return (
71+
<BadgeItem key={ind}>
72+
<EuiBadge color={color}>
73+
<EuiText size="m">
74+
<TextStyle>{item.label}</TextStyle>
75+
</EuiText>
76+
</EuiBadge>
77+
<TimeStampSpan>
78+
<EuiText color="subdued">{moment(item.timestamp).fromNow()}</EuiText>
79+
</TimeStampSpan>
80+
</BadgeItem>
81+
);
82+
};
8783

88-
const tagLabel = (item: StatusTag, ind: number, color: string) => (
89-
<BadgeItem key={ind}>
90-
<EuiBadge color={color}>
91-
<EuiText size="m">
92-
<TextStyle>{item.label}</TextStyle>
93-
</EuiText>
94-
</EuiBadge>
95-
<TimeStampSpan>
96-
<EuiText color="subdued">{moment(item.timestamp).fromNow()}</EuiText>
97-
</TimeStampSpan>
98-
</BadgeItem>
99-
);
84+
const prevLocal: string = moment.locale() ?? 'en';
10085

101-
return (
102-
<>
86+
const renderTags = () => {
87+
moment.defineLocale('en-tag', {
88+
relativeTime: {
89+
future: 'in %s',
90+
past: '%s ago',
91+
s: '%ds',
92+
ss: '%ss',
93+
m: '%dm',
94+
mm: '%dm',
95+
h: '%dh',
96+
hh: '%dh',
97+
d: '%dd',
98+
dd: '%dd',
99+
M: '%d Mon',
100+
MM: '%d Mon',
101+
y: '%d Yr',
102+
yy: '%d Yr',
103+
},
104+
});
105+
const tags = (
103106
<TagContainer>
104107
<span>{downLocations.map((item, ind) => tagLabel(item, ind, danger))}</span>
105108
<span>{upLocations.map((item, ind) => tagLabel(item, ind, gray))}</span>
106109
</TagContainer>
110+
);
111+
112+
// Need to reset locale so it doesn't effect other parts of the app
113+
moment.locale(prevLocal);
114+
return tags;
115+
};
116+
117+
return (
118+
<>
119+
{renderTags()}
107120
{locations.length > 7 && (
108121
<OtherLocationsDiv>
109122
<EuiText color="subdued">

0 commit comments

Comments
 (0)