diff --git a/superset-frontend/src/explore/components/SaveModal.test.jsx b/superset-frontend/src/explore/components/SaveModal.test.jsx index b25efdb773a8b..b3a7ac3d58b17 100644 --- a/superset-frontend/src/explore/components/SaveModal.test.jsx +++ b/superset-frontend/src/explore/components/SaveModal.test.jsx @@ -95,9 +95,36 @@ describe('SaveModal', () => { expect(wrapper.find(Radio)).toHaveLength(2); const footerWrapper = shallow(wrapper.find(StyledModal).props().footer); + expect(footerWrapper.find(Button)).toHaveLength(3); }); + it('renders the right footer buttons when an existing dashboard', () => { + const wrapper = getWrapper(); + const footerWrapper = shallow(wrapper.find(StyledModal).props().footer); + const saveAndGoDash = footerWrapper + .find('#btn_modal_save_goto_dash') + .getElement(); + const save = footerWrapper.find('#btn_modal_save').getElement(); + expect(save.props.children).toBe('Save'); + expect(saveAndGoDash.props.children).toBe('Save & go to dashboard'); + }); + + it('renders the right footer buttons when a new dashboard', () => { + const wrapper = getWrapper(); + wrapper.setState({ + saveToDashboardId: null, + newDashboardName: 'Test new dashboard', + }); + const footerWrapper = shallow(wrapper.find(StyledModal).props().footer); + const saveAndGoDash = footerWrapper + .find('#btn_modal_save_goto_dash') + .getElement(); + const save = footerWrapper.find('#btn_modal_save').getElement(); + expect(save.props.children).toBe('Save to new dashboard'); + expect(saveAndGoDash.props.children).toBe('Save & go to new dashboard'); + }); + it('overwrite radio button is disabled for new slice', () => { const wrapper = getWrapper(); wrapper.setProps({ slice: null }); diff --git a/superset-frontend/src/explore/components/SaveModal.tsx b/superset-frontend/src/explore/components/SaveModal.tsx index 9c3e01eba072b..bf2ed48701393 100644 --- a/superset-frontend/src/explore/components/SaveModal.tsx +++ b/superset-frontend/src/explore/components/SaveModal.tsx @@ -76,6 +76,11 @@ class SaveModal extends React.Component { this.onSliceNameChange = this.onSliceNameChange.bind(this); this.changeAction = this.changeAction.bind(this); this.saveOrOverwrite = this.saveOrOverwrite.bind(this); + this.isNewDashboard = this.isNewDashboard.bind(this); + } + + isNewDashboard(): boolean { + return !!(!this.state.saveToDashboardId && this.state.newDashboardName); } canOverwriteSlice(): boolean { @@ -195,7 +200,9 @@ class SaveModal extends React.Component { } onClick={() => this.saveOrOverwrite(true)} > - {t('Save & go to dashboard')} + {this.isNewDashboard() + ? t('Save & go to new dashboard') + : t('Save & go to dashboard')}