TimeZonePicker: Replace underscores with space (#104891)

* TimeZonePicker: Replace underscores with space

* add name to search

* update e2e test
pull/105066/head
Josh Hunt 1 week ago committed by GitHub
parent 82bbbf1a98
commit 7345ba35a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      e2e/old-arch/dashboards-suite/dashboard-time-zone.spec.ts
  2. 49
      packages/grafana-ui/src/components/DateTimePickers/TimeZonePicker.tsx

@ -198,7 +198,7 @@ describe('Dashboard time zone support', () => {
e2e.flows.setTimeRange({
from: 'now-6h',
to: 'now',
zone: 'America/Los_Angeles',
zone: 'America/Los Angeles',
});
// Need to wait for 2 calls as there's 2 panels
cy.wait(['@dataQuery', '@dataQuery']);

@ -86,28 +86,33 @@ interface SelectableZoneGroup extends SelectableValue<string> {
const useTimeZones = (includeInternal: boolean | InternalTimeZones[]): SelectableZoneGroup[] => {
const now = Date.now();
const timeZoneGroups = getTimeZoneGroups(includeInternal).map((group: GroupedTimeZones) => {
const options = group.zones.reduce((options: SelectableZone[], zone) => {
const info = getTimeZoneInfo(zone, now);
const timeZoneGroups = useMemo(() => {
return getTimeZoneGroups(includeInternal).map((group: GroupedTimeZones) => {
const options = group.zones.reduce((options: SelectableZone[], zone) => {
const info = getTimeZoneInfo(zone, now);
if (!info) {
return options;
}
if (!info) {
return options;
}
const name = info.name.replace(/_/g, ' ');
options.push({
label: name,
value: info.zone,
searchIndex: getSearchIndex(name, info, now),
});
options.push({
label: info.name,
value: info.zone,
searchIndex: getSearchIndex(info, now),
});
return options;
}, []);
return options;
}, []);
return {
label: group.name,
options,
};
});
}, [includeInternal, now]);
return {
label: group.name,
options,
};
});
return timeZoneGroups;
};
@ -159,13 +164,17 @@ const useFilterBySearchIndex = () => {
}, []);
};
const getSearchIndex = (info: TimeZoneInfo, timestamp: number): string => {
const getSearchIndex = (label: string, info: TimeZoneInfo, timestamp: number): string => {
const parts: string[] = [
toLower(info.name),
toLower(info.zone),
toLower(info.abbreviation),
toLower(formatUtcOffset(timestamp, info.zone)),
];
if (label !== info.zone) {
parts.push(toLower(label));
}
for (const country of info.countries) {
parts.push(toLower(country.name));
parts.push(toLower(country.code));

Loading…
Cancel
Save