Skip to content
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
29 changes: 28 additions & 1 deletion superset-frontend/src/explore/components/SaveModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,41 @@ test('disables overwrite option for new slice', () => {
});

test('disables overwrite option for non-owner', () => {
const { getByRole } = setup(
const { getByRole, getByText } = setup(
{},
mockStore({
...initialState,
user: { userId: 2 },
}),
);
expect(getByRole('radio', { name: 'Save (Overwrite)' })).toBeDisabled();
expect(
getByText(
'Must be a chart owner to overwrite this chart. Save as a new chart instead.',
),
).toBeInTheDocument();
});

test('disables overwrite option for externally managed slice', () => {
const { getByRole, getByText } = setup(
{},
mockStore({
...initialState,
explore: {
...initialState.explore,
slice: {
...initialState.explore.slice,
is_managed_externally: true,
},
},
}),
);
expect(getByRole('radio', { name: 'Save (Overwrite)' })).toBeDisabled();
expect(
getByText(
"This chart is managed externally and can't be overwritten in Superset.",
),
).toBeInTheDocument();
});

test('updates slice name and selected dashboard', async () => {
Expand Down
17 changes: 16 additions & 1 deletion superset-frontend/src/explore/components/SaveModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
Loading,
Divider,
Flex,
Typography,
TreeSelect,
} from '@superset-ui/core/components';
import { logging } from '@apache-superset/core/utils';
Expand Down Expand Up @@ -597,18 +598,32 @@ class SaveModal extends Component<SaveModalProps, SaveModalState> {

renderSaveChartModal = () => {
const info = this.info();
const canOverwriteSlice = this.canOverwriteSlice();
return (
<Form data-test="save-modal-body" layout="vertical">
<FormItem data-test="radio-group">
<Radio
id="overwrite-radio"
disabled={!this.canOverwriteSlice()}
disabled={!canOverwriteSlice}
checked={this.state.action === 'overwrite'}
onChange={() => this.changeAction('overwrite')}
data-test="save-overwrite-radio"
>
{t('Save (Overwrite)')}
</Radio>
{this.props.slice && !canOverwriteSlice && (
<div>
<Typography.Text type="secondary">
{this.props.slice.is_managed_externally
? t(
"This chart is managed externally and can't be overwritten in Superset.",
)
: t(
'Must be a chart owner to overwrite this chart. Save as a new chart instead.',
)}
</Typography.Text>
</div>
)}
<Radio
id="saveas-radio"
data-test="saveas-radio"
Expand Down
Loading