diff --git a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx index 9ef6064413..2daeec6eb6 100644 --- a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx +++ b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx @@ -101,6 +101,7 @@ const RETENTION_OPTIONS = [ const DEFAULT_RETENTION = 90; const DEFAULT_WORKING_TIMEOUT = 3600; +const DEFAULT_CRON_VALUE = '* * * * *'; // every minute const StyledIcon = styled(Icon)` margin: auto ${({ theme }) => theme.gridUnit * 2}px auto 0; @@ -612,7 +613,7 @@ const AlertReportModal: FunctionComponent = ({ const loadOwnerOptions = (input = '') => { const query = rison.encode({ filter: input }); return SupersetClient.get({ - endpoint: `/api/v1/dashboard/related/owners?q=${query}`, + endpoint: `/api/v1/report/related/owners?q=${query}`, }).then( response => { return response.json.result.map((item: any) => ({ @@ -629,7 +630,7 @@ const AlertReportModal: FunctionComponent = ({ const loadSourceOptions = (input = '') => { const query = rison.encode({ filter: input }); return SupersetClient.get({ - endpoint: `/api/v1/dataset/related/database?q=${query}`, + endpoint: `/api/v1/report/related/database?q=${query}`, }).then( response => { const list = response.json.result.map((item: any) => ({ @@ -678,12 +679,12 @@ const AlertReportModal: FunctionComponent = ({ const loadDashboardOptions = (input = '') => { const query = rison.encode({ filter: input }); return SupersetClient.get({ - endpoint: `/api/v1/dashboard?q=${query}`, + endpoint: `/api/v1/report/related/dashboard?q=${query}`, }).then( response => { const list = response.json.result.map((item: any) => ({ - value: item.id, - label: item.dashboard_title, + value: item.value, + label: item.text, })); setDashboardOptions(list); @@ -727,12 +728,12 @@ const AlertReportModal: FunctionComponent = ({ const loadChartOptions = (input = '') => { const query = rison.encode({ filter: input }); return SupersetClient.get({ - endpoint: `/api/v1/chart?q=${query}`, + endpoint: `/api/v1/report/related/chart?q=${query}`, }).then( response => { const list = response.json.result.map((item: any) => ({ - value: item.id, - label: item.slice_name, + value: item.value, + label: item.text, })); setChartOptions(list); @@ -771,12 +772,10 @@ const AlertReportModal: FunctionComponent = ({ // Updating alert/report state const updateAlertState = (name: string, value: any) => { - const data = { - ...currentAlert, + setCurrentAlert(currentAlertData => ({ + ...currentAlertData, [name]: value, - }; - - setCurrentAlert(data); + })); }; // Handle input/textarea updates @@ -960,7 +959,7 @@ const AlertReportModal: FunctionComponent = ({ ) { setCurrentAlert({ active: true, - crontab: '', + crontab: DEFAULT_CRON_VALUE, log_retention: DEFAULT_RETENTION, working_timeout: DEFAULT_WORKING_TIMEOUT, name: '', @@ -1047,7 +1046,7 @@ const AlertReportModal: FunctionComponent = ({
- {t('Alert Name')} + {isReport ? t('Report Name') : t('Alert Name')} *
@@ -1055,7 +1054,7 @@ const AlertReportModal: FunctionComponent = ({ type="text" name="name" value={currentAlert ? currentAlert.name : ''} - placeholder={t('Alert Name')} + placeholder={isReport ? t('Report Name') : t('Alert Name')} onChange={onTextChange} />
@@ -1189,10 +1188,16 @@ const AlertReportModal: FunctionComponent = ({ )}
-

{t('Alert Condition Schedule')}

+

+ {isReport + ? t('Report Schedule') + : t('Alert Condition Schedule')} +

updateAlertState('crontab', newVal)} /> diff --git a/superset-frontend/src/views/CRUD/alert/components/AlertReportCronScheduler.tsx b/superset-frontend/src/views/CRUD/alert/components/AlertReportCronScheduler.tsx index f3e874faea..60a2309c79 100644 --- a/superset-frontend/src/views/CRUD/alert/components/AlertReportCronScheduler.tsx +++ b/superset-frontend/src/views/CRUD/alert/components/AlertReportCronScheduler.tsx @@ -25,12 +25,12 @@ import { CronPicker, CronError } from 'src/common/components/CronPicker'; import { StyledInputContainer } from '../AlertReportModal'; interface AlertReportCronSchedulerProps { - value?: string; + value: string; onChange: (change: string) => any; } export const AlertReportCronScheduler: FunctionComponent = ({ - value = '* * * * *', + value, onChange, }) => { const theme = useTheme(); diff --git a/superset/reports/api.py b/superset/reports/api.py index 445474c7de..5928cc336a 100644 --- a/superset/reports/api.py +++ b/superset/reports/api.py @@ -161,7 +161,7 @@ class ReportScheduleRestApi(BaseSupersetModelRestApi): ] search_columns = ["name", "active", "created_by", "type", "last_state"] search_filters = {"name": [ReportScheduleAllTextFilter]} - allowed_rel_fields = {"owners", "chart", "dashboard", "database"} + allowed_rel_fields = {"owners", "chart", "dashboard", "database", "created_by"} filter_rel_fields = { "chart": [["id", ChartFilter, lambda: []]], "dashboard": [["id", DashboardFilter, lambda: []]],