Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(Explore): Change text when saving a chart in a new dashboard #19467

Merged
merged 2 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions superset-frontend/src/explore/components/SaveModal.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
11 changes: 10 additions & 1 deletion superset-frontend/src/explore/components/SaveModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class SaveModal extends React.Component<SaveModalProps, SaveModalState> {
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);
kgabryje marked this conversation as resolved.
Show resolved Hide resolved
}

canOverwriteSlice(): boolean {
Expand Down Expand Up @@ -195,7 +200,9 @@ class SaveModal extends React.Component<SaveModalProps, SaveModalState> {
}
onClick={() => this.saveOrOverwrite(true)}
>
{t('Save & go to dashboard')}
{this.isNewDashboard()
? t('Save & go to new dashboard')
: t('Save & go to dashboard')}
</Button>
<Button
id="btn_modal_save"
Expand All @@ -207,6 +214,8 @@ class SaveModal extends React.Component<SaveModalProps, SaveModalState> {
>
{!this.canOverwriteSlice() && this.props.slice
? t('Save as new chart')
: this.isNewDashboard()
? t('Save to new dashboard')
: t('Save')}
</Button>
</div>
Expand Down