diff --git a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx index 3a0d25d600695..c62a1f74fb861 100644 --- a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx +++ b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx @@ -66,9 +66,13 @@ const createProps = (): HeaderDropdownProps => ({ userCanCurate: false, lastModifiedTime: 0, isDropdownVisible: true, + setIsDropdownVisible: jest.fn(), + directPathToChild: [], manageEmbedded: jest.fn(), dataMask: {}, logEvent: jest.fn(), + refreshLimit: 0, + refreshWarning: '', }); const editModeOnProps = { diff --git a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.tsx similarity index 77% rename from superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx rename to superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.tsx index 50cdb67813568..d5ae7aaee2a00 100644 --- a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx +++ b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.tsx @@ -17,7 +17,6 @@ * under the License. */ import { PureComponent } from 'react'; -import PropTypes from 'prop-types'; import { isEmpty } from 'lodash'; import { connect } from 'react-redux'; import { t } from '@superset-ui/core'; @@ -35,73 +34,38 @@ import FilterScopeModal from 'src/dashboard/components/filterscope/FilterScopeMo import getDashboardUrl from 'src/dashboard/util/getDashboardUrl'; import { getActiveFilters } from 'src/dashboard/util/activeDashboardFilters'; import { getUrlParam } from 'src/utils/urlUtils'; -import { MenuKeys } from 'src/dashboard/types'; +import { MenuKeys, RootState } from 'src/dashboard/types'; +import { HeaderDropdownProps } from 'src/dashboard/components/Header/types'; -const propTypes = { - addSuccessToast: PropTypes.func.isRequired, - addDangerToast: PropTypes.func.isRequired, - dashboardInfo: PropTypes.object.isRequired, - dashboardId: PropTypes.number, - dashboardTitle: PropTypes.string, - dataMask: PropTypes.object.isRequired, - customCss: PropTypes.string, - colorNamespace: PropTypes.string, - colorScheme: PropTypes.string, - directPathToChild: PropTypes.array, - onChange: PropTypes.func.isRequired, - updateCss: PropTypes.func.isRequired, - forceRefreshAllCharts: PropTypes.func.isRequired, - refreshFrequency: PropTypes.number, - shouldPersistRefreshFrequency: PropTypes.bool.isRequired, - setRefreshFrequency: PropTypes.func.isRequired, - startPeriodicRender: PropTypes.func.isRequired, - editMode: PropTypes.bool.isRequired, - userCanEdit: PropTypes.bool, - userCanShare: PropTypes.bool, - userCanSave: PropTypes.bool, - userCanCurate: PropTypes.bool.isRequired, - isLoading: PropTypes.bool.isRequired, - layout: PropTypes.object.isRequired, - expandedSlices: PropTypes.object, - onSave: PropTypes.func.isRequired, - showPropertiesModal: PropTypes.func.isRequired, - manageEmbedded: PropTypes.func.isRequired, - logEvent: PropTypes.func, - refreshLimit: PropTypes.number, - refreshWarning: PropTypes.string, - lastModifiedTime: PropTypes.number.isRequired, -}; - -const defaultProps = { - colorNamespace: undefined, - colorScheme: undefined, - refreshLimit: 0, - refreshWarning: null, -}; - -const mapStateToProps = state => ({ +const mapStateToProps = (state: RootState) => ({ directPathToChild: state.dashboardState.directPathToChild, }); -export class HeaderActionsDropdown extends PureComponent { - static discardChanges() { - window.location.reload(); - } +interface HeaderActionsDropdownState { + css: string; + showReportSubMenu: boolean | null; +} - constructor(props) { +export class HeaderActionsDropdown extends PureComponent< + HeaderDropdownProps, + HeaderActionsDropdownState +> { + static defaultProps = { + colorNamespace: undefined, + colorScheme: undefined, + refreshLimit: 0, + refreshWarning: null, + }; + + constructor(props: HeaderDropdownProps) { super(props); this.state = { - css: props.customCss, + css: props.customCss || '', showReportSubMenu: null, }; - - this.changeCss = this.changeCss.bind(this); - this.changeRefreshInterval = this.changeRefreshInterval.bind(this); - this.handleMenuClick = this.handleMenuClick.bind(this); - this.setShowReportSubMenu = this.setShowReportSubMenu.bind(this); } - UNSAFE_componentWillReceiveProps(nextProps) { + UNSAFE_componentWillReceiveProps(nextProps: HeaderDropdownProps) { if (this.props.customCss !== nextProps.customCss) { this.setState({ css: nextProps.customCss }, () => { injectCustomCss(nextProps.customCss); @@ -109,23 +73,21 @@ export class HeaderActionsDropdown extends PureComponent { } } - setShowReportSubMenu(show) { - this.setState({ - showReportSubMenu: show, - }); - } + setShowReportSubMenu = (show: boolean) => { + this.setState({ showReportSubMenu: show }); + }; - changeCss(css) { + changeCss = (css: string) => { this.props.onChange(); this.props.updateCss(css); - } + }; - changeRefreshInterval(refreshInterval, isPersistent) { + changeRefreshInterval = (refreshInterval: number, isPersistent: boolean) => { this.props.setRefreshFrequency(refreshInterval, isPersistent); this.props.startPeriodicRender(refreshInterval * 1000); - } + }; - handleMenuClick({ key }) { + handleMenuClick = ({ key }: Record) => { switch (key) { case MenuKeys.RefreshDashboard: this.props.forceRefreshAllCharts(); @@ -139,7 +101,7 @@ export class HeaderActionsDropdown extends PureComponent { pathname: window.location.pathname, filters: getActiveFilters(), hash: window.location.hash, - standalone: !getUrlParam(URL_PARAMS.standalone), + standalone: getUrlParam(URL_PARAMS.standalone), }); window.location.replace(url); break; @@ -151,7 +113,7 @@ export class HeaderActionsDropdown extends PureComponent { default: break; } - } + }; render() { const { @@ -244,8 +206,8 @@ export class HeaderActionsDropdown extends PureComponent { {userCanSave && ( {userCanShare && ( @@ -338,15 +300,16 @@ export class HeaderActionsDropdown extends PureComponent { {editMode && !isEmpty(dashboardInfo?.metadata?.filter_scopes) && ( {t('Set filter mapping')} + } /> )} void; + addSuccessToast: (msg: string) => void; addDangerToast: () => void; customCss: string; colorNamespace?: string; @@ -47,20 +47,24 @@ export interface HeaderDropdownProps { onChange: () => void; onSave: () => void; refreshFrequency: number; - setRefreshFrequency: () => void; + setRefreshFrequency: (refreshInterval: number, isPersistent: boolean) => void; shouldPersistRefreshFrequency: boolean; showPropertiesModal: () => void; - startPeriodicRender: () => void; - updateCss: () => void; + startPeriodicRender: (interval: number) => void; + updateCss: (css: string) => void; userCanEdit: boolean; userCanSave: boolean; userCanShare: boolean; userCanCurate: boolean; - isDropdownVisible: boolean; manageEmbedded: () => void; dataMask: any; lastModifiedTime: number; logEvent: () => void; + setIsDropdownVisible: (visible: boolean) => void; + isDropdownVisible: boolean; + refreshLimit: number; + refreshWarning: string; + directPathToChild: string[]; } export interface HeaderProps { diff --git a/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadMenuItems.test.tsx b/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadMenuItems.test.tsx index fe453bb397b38..cbee1765c9ab0 100644 --- a/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadMenuItems.test.tsx +++ b/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadMenuItems.test.tsx @@ -24,7 +24,7 @@ const createProps = () => ({ imageMenuItemTitle: 'Download as Image', dashboardTitle: 'Test Dashboard', logEvent: jest.fn(), - dashboardId: '123', + dashboardId: 123, }); const renderComponent = () => { diff --git a/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadScreenshot.test.tsx b/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadScreenshot.test.tsx index 01d756403a463..e1851e6199db3 100644 --- a/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadScreenshot.test.tsx +++ b/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadScreenshot.test.tsx @@ -42,7 +42,7 @@ jest.mock('src/components/MessageToasts/withToasts', () => ({ const defaultProps = () => ({ text: 'Download', - dashboardId: '123', + dashboardId: 123, format: DownloadScreenshotFormat.PDF, logEvent: mockLogEvent, }); diff --git a/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadScreenshot.tsx b/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadScreenshot.tsx index 2d182e31fc754..88e333abf9e7d 100644 --- a/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadScreenshot.tsx +++ b/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadScreenshot.tsx @@ -45,7 +45,7 @@ export default function DownloadScreenshot({ ...rest }: { text: string; - dashboardId: string; + dashboardId: number; logEvent?: Function; format: string; }) { diff --git a/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/index.tsx b/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/index.tsx index c17fc0d0265d7..e0ec06d9b24eb 100644 --- a/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/index.tsx +++ b/superset-frontend/src/dashboard/components/menu/DownloadMenuItems/index.tsx @@ -25,7 +25,7 @@ export interface DownloadMenuItemProps { imageMenuItemTitle: string; dashboardTitle: string; logEvent?: Function; - dashboardId: string; + dashboardId: number; } const DownloadMenuItems = (props: DownloadMenuItemProps) => {