[SharedUX] Export timezone list from Core UI (#154742)

## Summary

Exports the list of valid Kibana timezones from the Core UI package, so
that it can be used in the snooze scheduler UI.

Previously we were using the same moment.tz list, but didn't have the
compatibility filter from Core UI. This will ensure the list of valid
timezones is synced up everywhere we need to show them.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Zacqary Adam Xeper 2023-04-17 12:01:23 -05:00 committed by GitHub
parent 8360064a39
commit 0bd81d8da1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 14 deletions

View file

@ -13,3 +13,5 @@ export type {
UserProvidedValues,
UiSettingsScope,
} from './src/ui_settings';
export { TIMEZONE_OPTIONS } from './src/timezones';

View file

@ -0,0 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import moment from 'moment-timezone';
export const TIMEZONE_OPTIONS = [
...moment.tz
.names()
// We need to filter out some time zones, that moment.js knows about, but Elasticsearch
// does not understand and would fail thus with a 400 bad request when using them.
.filter((tz) => !['America/Nuuk', 'EST', 'HST', 'ROC', 'MST'].includes(tz)),
];

View file

@ -9,20 +9,13 @@
import moment from 'moment-timezone';
import { schema } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n';
import type { UiSettingsParams } from '@kbn/core-ui-settings-common';
import { UiSettingsParams, TIMEZONE_OPTIONS } from '@kbn/core-ui-settings-common';
export const getDateFormatSettings = (): Record<string, UiSettingsParams> => {
const weekdays = moment.weekdays().slice();
const [defaultWeekday] = weekdays;
const timezones = [
'Browser',
...moment.tz
.names()
// We need to filter out some time zones, that moment.js knows about, but Elasticsearch
// does not understand and would fail thus with a 400 bad request when using them.
.filter((tz) => !['America/Nuuk', 'EST', 'HST', 'ROC', 'MST'].includes(tz)),
];
const timezones = ['Browser', ...TIMEZONE_OPTIONS];
return {
dateFormat: {

View file

@ -9,6 +9,7 @@ import React, { useState, useCallback, useMemo } from 'react';
import moment, { Moment } from 'moment';
import { i18n } from '@kbn/i18n';
import { useUiSetting } from '@kbn/kibana-react-plugin/public';
import { TIMEZONE_OPTIONS as UI_TIMEZONE_OPTIONS } from '@kbn/core-ui-settings-common';
import { v4 as uuidv4 } from 'uuid';
import {
EuiDatePicker,
@ -47,7 +48,7 @@ export interface ComponentOpts extends PanelOpts {
hasTitle: boolean;
}
const TIMEZONE_OPTIONS = moment.tz?.names().map((n) => ({ label: n })) ?? [{ label: 'UTC' }];
const TIMEZONE_OPTIONS = UI_TIMEZONE_OPTIONS.map((n) => ({ label: n })) ?? [{ label: 'UTC' }];
const useDefaultTimzezone = () => {
const kibanaTz: string = useUiSetting('dateFormat:tz');

View file

@ -51,9 +51,8 @@
"@kbn/cases-components",
"@kbn/field-types",
"@kbn/ecs",
"@kbn/alerts-as-data-utils"
"@kbn/alerts-as-data-utils",
"@kbn/core-ui-settings-common"
],
"exclude": [
"target/**/*"
]
"exclude": ["target/**/*"]
}