From 3f6c81b6215f74e171b02c63771f264638a47c82 Mon Sep 17 00:00:00 2001 From: Elizabeth Thompson Date: Wed, 28 Jul 2021 10:02:00 -0700 Subject: [PATCH] add timezone selector to alerts and reports (#15920) --- .../src/components/CronPicker/CronPicker.tsx | 4 +-- .../CRUD/alert/AlertReportModal.test.jsx | 8 ++--- .../src/views/CRUD/alert/AlertReportModal.tsx | 31 ++++++++++++++----- .../src/views/CRUD/alert/types.ts | 1 + 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/superset-frontend/src/components/CronPicker/CronPicker.tsx b/superset-frontend/src/components/CronPicker/CronPicker.tsx index d8596406440..631f7f24b43 100644 --- a/superset-frontend/src/components/CronPicker/CronPicker.tsx +++ b/superset-frontend/src/components/CronPicker/CronPicker.tsx @@ -31,7 +31,7 @@ export const LOCALE: Locale = { emptyWeekDays: t('every day of the week'), emptyWeekDaysShort: t('day of the week'), emptyHours: t('every hour'), - emptyMinutes: t('every minute UTC'), + emptyMinutes: t('every minute'), emptyMinutesForHourPeriod: t('every'), yearOption: t('year'), monthOption: t('month'), @@ -48,7 +48,7 @@ export const LOCALE: Locale = { prefixHours: t('at'), prefixMinutes: t(':'), prefixMinutesForHourPeriod: t('at'), - suffixMinutesForHourPeriod: t('minute(s) UTC'), + suffixMinutesForHourPeriod: t('minute(s)'), errorInvalidCron: t('Invalid cron expression'), clearButtonText: t('Clear'), weekDays: [ diff --git a/superset-frontend/src/views/CRUD/alert/AlertReportModal.test.jsx b/superset-frontend/src/views/CRUD/alert/AlertReportModal.test.jsx index 37412343322..8575a526a37 100644 --- a/superset-frontend/src/views/CRUD/alert/AlertReportModal.test.jsx +++ b/superset-frontend/src/views/CRUD/alert/AlertReportModal.test.jsx @@ -226,12 +226,12 @@ describe('AlertReportModal', () => { expect(input.props().value).toEqual('SELECT NaN'); }); - it('renders one select element when in report mode', () => { + it('renders two select element when in report mode', () => { expect(wrapper.find(Select)).toExist(); - expect(wrapper.find(Select)).toHaveLength(1); + expect(wrapper.find(Select)).toHaveLength(2); }); - it('renders two select elements when in alert mode', async () => { + it('renders three select elements when in alert mode', async () => { const props = { ...mockedProps, isReport: false, @@ -240,7 +240,7 @@ describe('AlertReportModal', () => { const addWrapper = await mountAndWait(props); expect(addWrapper.find(Select)).toExist(); - expect(addWrapper.find(Select)).toHaveLength(2); + expect(addWrapper.find(Select)).toHaveLength(3); }); it('renders value input element when in alert mode', async () => { diff --git a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx index f973943241b..fa1610bc0b1 100644 --- a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx +++ b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx @@ -30,6 +30,7 @@ import { useSingleViewResource } from 'src/views/CRUD/hooks'; import Icons from 'src/components/Icons'; import { Switch } from 'src/components/Switch'; import Modal from 'src/components/Modal'; +import TimezoneSelector from 'src/components/TimezoneSelector'; import { Radio } from 'src/components/Radio'; import { AsyncSelect, NativeGraySelect as Select } from 'src/components/Select'; import { FeatureFlag, isFeatureEnabled } from 'src/featureFlags'; @@ -314,6 +315,7 @@ export const StyledInputContainer = styled.div` border-style: none; border: 1px solid ${({ theme }) => theme.colors.grayscale.light2}; border-radius: ${({ theme }) => theme.gridUnit}px; + width: 425px; .ant-select-selection-placeholder, .ant-select-selection-item { @@ -358,6 +360,10 @@ const StyledNotificationAddButton = styled.div` } `; +const timezoneHeaderStyle = (theme: SupersetTheme) => css` + margin: ${theme.gridUnit * 3}px 0; +`; + type NotificationAddStatus = 'active' | 'disabled' | 'hidden'; interface NotificationMethodAddProps { @@ -821,6 +827,10 @@ const AlertReportModal: FunctionComponent = ({ updateAlertState('log_retention', retention); }; + const onTimezoneChange = (timezone: string) => { + updateAlertState('timezone', timezone); + }; + const onContentTypeChange = (event: any) => { const { target } = event; @@ -883,10 +893,7 @@ const AlertReportModal: FunctionComponent = ({ useEffect(() => { if ( isEditMode && - (!currentAlert || - !currentAlert.id || - (alert && alert.id !== currentAlert.id) || - (isHidden && show)) + (!currentAlert?.id || alert?.id !== currentAlert.id || (isHidden && show)) ) { if (alert && alert.id !== null && !loading && !fetchError) { const id = alert.id || 0; @@ -1104,7 +1111,7 @@ const AlertReportModal: FunctionComponent = ({ = ({ * updateAlertState('crontab', newVal)} /> +
{t('Timezone')}
+
timezoneHeaderStyle(theme)} + > + +

{t('Schedule settings')}

diff --git a/superset-frontend/src/views/CRUD/alert/types.ts b/superset-frontend/src/views/CRUD/alert/types.ts index 1fc033b5673..f67a6042dfe 100644 --- a/superset-frontend/src/views/CRUD/alert/types.ts +++ b/superset-frontend/src/views/CRUD/alert/types.ts @@ -74,6 +74,7 @@ export type AlertObject = { name?: string; owners?: Array; sql?: string; + timezone?: string; recipients?: Array; report_format?: 'PNG' | 'CSV' | 'TEXT'; type?: string;