diff --git a/superset-frontend/src/common/components/index.tsx b/superset-frontend/src/common/components/index.tsx index 93e3d6f573b..632b525790a 100644 --- a/superset-frontend/src/common/components/index.tsx +++ b/superset-frontend/src/common/components/index.tsx @@ -51,6 +51,7 @@ export { Switch, Tabs, Tooltip, + Input as AntdInput, } from 'antd'; export { TreeProps } from 'antd/lib/tree'; export { FormInstance } from 'antd/lib/form'; diff --git a/superset-frontend/src/views/CRUD/alert/AlertList.tsx b/superset-frontend/src/views/CRUD/alert/AlertList.tsx index 83d352b871a..88c46d2740a 100644 --- a/superset-frontend/src/views/CRUD/alert/AlertList.tsx +++ b/superset-frontend/src/views/CRUD/alert/AlertList.tsx @@ -17,7 +17,7 @@ * under the License. */ -import React, { useState, useMemo, useEffect } from 'react'; +import React, { useState, useMemo } from 'react'; import { useHistory } from 'react-router-dom'; import { t, SupersetClient, makeApi, styled } from '@superset-ui/core'; import moment from 'moment'; @@ -183,10 +183,6 @@ function AlertList({ } }; - useEffect(() => { - refreshData(); - }, [isReportEnabled]); - const columns = useMemo( () => [ { @@ -303,7 +299,7 @@ function AlertList({ canEdit ? { label: 'edit-action', - tooltip: t('Edit Alert'), + tooltip: t('Edit'), placement: 'bottom', icon: 'edit' as IconName, onClick: handleEdit, @@ -312,7 +308,7 @@ function AlertList({ canDelete ? { label: 'delete-action', - tooltip: t('Delete Alert'), + tooltip: t('Delete'), placement: 'bottom', icon: 'trash' as IconName, onClick: handleDelete, diff --git a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx index ce900b4cb8b..23d5acbd31f 100644 --- a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx +++ b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx @@ -554,6 +554,7 @@ const AlertReportModal: FunctionComponent = ({ const data: any = { ...currentAlert, + type: isReport ? 'Report' : 'Alert', validator_type: conditionNotNull ? 'not null' : 'operator', validator_config_json: conditionNotNull ? {} @@ -973,7 +974,6 @@ const AlertReportModal: FunctionComponent = ({ owners: [], recipients: [], sql: '', - type: isReport ? 'Report' : 'Alert', validator_config_json: {}, validator_type: '', }); diff --git a/superset-frontend/src/views/CRUD/alert/components/AlertReportCronScheduler.tsx b/superset-frontend/src/views/CRUD/alert/components/AlertReportCronScheduler.tsx index 5bbb9bf803a..74bdccfee0c 100644 --- a/superset-frontend/src/views/CRUD/alert/components/AlertReportCronScheduler.tsx +++ b/superset-frontend/src/views/CRUD/alert/components/AlertReportCronScheduler.tsx @@ -19,7 +19,7 @@ import React, { useState, useCallback, useRef, FunctionComponent } from 'react'; import { t, useTheme } from '@superset-ui/core'; -import { Input } from 'src/common/components'; +import { Input, AntdInput } from 'src/common/components'; import { Radio } from 'src/common/components/Radio'; import { CronPicker, CronError } from 'src/common/components/CronPicker'; import { StyledInputContainer } from '../AlertReportModal'; @@ -34,8 +34,7 @@ export const AlertReportCronScheduler: FunctionComponent { const theme = useTheme(); - // @ts-ignore - const inputRef = useRef(null); + const inputRef = useRef(null); const [scheduleFormat, setScheduleFormat] = useState<'picker' | 'input'>( 'picker', ); diff --git a/superset-frontend/src/views/CRUD/hooks.ts b/superset-frontend/src/views/CRUD/hooks.ts index 9799eac5754..4a1d044d0d3 100644 --- a/superset-frontend/src/views/CRUD/hooks.ts +++ b/superset-frontend/src/views/CRUD/hooks.ts @@ -206,119 +206,128 @@ export function useSingleViewResource( setState(currentState => ({ ...currentState, ...update })); } - const fetchResource = useCallback((resourceID: number) => { - // Set loading state - updateState({ - loading: true, - }); - - return SupersetClient.get({ - endpoint: `/api/v1/${resourceName}/${resourceID}`, - }) - .then( - ({ json = {} }) => { - updateState({ - resource: json.result, - error: null, - }); - return json.result; - }, - createErrorHandler(errMsg => { - handleErrorMsg( - t( - 'An error occurred while fetching %ss: %s', - resourceLabel, - JSON.stringify(errMsg), - ), - ); - - updateState({ - error: errMsg, - }); - }), - ) - .finally(() => { - updateState({ loading: false }); + const fetchResource = useCallback( + (resourceID: number) => { + // Set loading state + updateState({ + loading: true, }); - }, []); - const createResource = useCallback((resource: D) => { - // Set loading state - updateState({ - loading: true, - }); + return SupersetClient.get({ + endpoint: `/api/v1/${resourceName}/${resourceID}`, + }) + .then( + ({ json = {} }) => { + updateState({ + resource: json.result, + error: null, + }); + return json.result; + }, + createErrorHandler(errMsg => { + handleErrorMsg( + t( + 'An error occurred while fetching %ss: %s', + resourceLabel, + JSON.stringify(errMsg), + ), + ); - return SupersetClient.post({ - endpoint: `/api/v1/${resourceName}/`, - body: JSON.stringify(resource), - headers: { 'Content-Type': 'application/json' }, - }) - .then( - ({ json = {} }) => { - updateState({ - resource: json.result, - error: null, - }); - return json.id; - }, - createErrorHandler(errMsg => { - handleErrorMsg( - t( - 'An error occurred while creating %ss: %s', - resourceLabel, - JSON.stringify(errMsg), - ), - ); + updateState({ + error: errMsg, + }); + }), + ) + .finally(() => { + updateState({ loading: false }); + }); + }, + [handleErrorMsg, resourceName, resourceLabel], + ); - updateState({ - error: errMsg, - }); - }), - ) - .finally(() => { - updateState({ loading: false }); + const createResource = useCallback( + (resource: D) => { + // Set loading state + updateState({ + loading: true, }); - }, []); - const updateResource = useCallback((resourceID: number, resource: D) => { - // Set loading state - updateState({ - loading: true, - }); + return SupersetClient.post({ + endpoint: `/api/v1/${resourceName}/`, + body: JSON.stringify(resource), + headers: { 'Content-Type': 'application/json' }, + }) + .then( + ({ json = {} }) => { + updateState({ + resource: json.result, + error: null, + }); + return json.id; + }, + createErrorHandler(errMsg => { + handleErrorMsg( + t( + 'An error occurred while creating %ss: %s', + resourceLabel, + JSON.stringify(errMsg), + ), + ); - return SupersetClient.put({ - endpoint: `/api/v1/${resourceName}/${resourceID}`, - body: JSON.stringify(resource), - headers: { 'Content-Type': 'application/json' }, - }) - .then( - ({ json = {} }) => { - updateState({ - resource: json.result, - error: null, - }); - return json.result; - }, - createErrorHandler(errMsg => { - handleErrorMsg( - t( - 'An error occurred while fetching %ss: %s', - resourceLabel, - JSON.stringify(errMsg), - ), - ); + updateState({ + error: errMsg, + }); + }), + ) + .finally(() => { + updateState({ loading: false }); + }); + }, + [handleErrorMsg, resourceName, resourceLabel], + ); - updateState({ - error: errMsg, - }); - - return errMsg; - }), - ) - .finally(() => { - updateState({ loading: false }); + const updateResource = useCallback( + (resourceID: number, resource: D) => { + // Set loading state + updateState({ + loading: true, }); - }, []); + + return SupersetClient.put({ + endpoint: `/api/v1/${resourceName}/${resourceID}`, + body: JSON.stringify(resource), + headers: { 'Content-Type': 'application/json' }, + }) + .then( + ({ json = {} }) => { + updateState({ + resource: json.result, + error: null, + }); + return json.result; + }, + createErrorHandler(errMsg => { + handleErrorMsg( + t( + 'An error occurred while fetching %ss: %s', + resourceLabel, + JSON.stringify(errMsg), + ), + ); + + updateState({ + error: errMsg, + }); + + return errMsg; + }), + ) + .finally(() => { + updateState({ loading: false }); + }); + }, + [handleErrorMsg, resourceName, resourceLabel], + ); return { state,