fix(explore): update overwrite button on perm change (#16437)

* fix(explore): update overwrite on perm change

* remove redundant user_id prop

* fix types

* fix user type

* fix tests

* fix lint
This commit is contained in:
Ville Brofeldt
2021-08-26 06:24:33 +03:00
committed by GitHub
parent db11c3e6c8
commit 18be181946
9 changed files with 27 additions and 26 deletions

View File

@@ -620,7 +620,6 @@ function mapStateToProps(state) {
timeout: explore.common.conf.SUPERSET_WEBSERVER_TIMEOUT,
ownState: dataMask[form_data.slice_id ?? 0]?.ownState, // 0 - unsaved chart
impressionId,
userId: explore.user_id,
user: explore.user,
reports,
};

View File

@@ -175,7 +175,7 @@ export default function PropertiesModal({
buttonStyle="primary"
// @ts-ignore
onClick={onSubmit}
disabled={!owners || submitting || !name}
disabled={submitting || !name}
cta
>
{t('Save')}

View File

@@ -34,11 +34,10 @@ const SK_DASHBOARD_ID = 'save_chart_recent_dashboard';
const SELECT_PLACEHOLDER = t('**Select** a dashboard OR **create** a new one');
type SaveModalProps = {
can_overwrite?: boolean;
onHide: () => void;
actions: Record<string, any>;
form_data?: Record<string, any>;
userId: string;
userId: number;
dashboards: Array<any>;
alert?: string;
sliceName?: string;
@@ -70,7 +69,7 @@ class SaveModal extends React.Component<SaveModalProps, SaveModalState> {
saveToDashboardId: null,
newSliceName: props.sliceName,
alert: null,
action: props.can_overwrite ? 'overwrite' : 'saveas',
action: this.canOverwriteSlice() ? 'overwrite' : 'saveas',
};
this.onDashboardSelectChange = this.onDashboardSelectChange.bind(this);
this.onSliceNameChange = this.onSliceNameChange.bind(this);
@@ -78,6 +77,10 @@ class SaveModal extends React.Component<SaveModalProps, SaveModalState> {
this.saveOrOverwrite = this.saveOrOverwrite.bind(this);
}
canOverwriteSlice(): boolean {
return this.props.slice?.owners?.includes(this.props.userId);
}
componentDidMount() {
this.props.actions.fetchDashboards(this.props.userId).then(() => {
const dashboardIds = this.props.dashboards.map(
@@ -196,7 +199,7 @@ class SaveModal extends React.Component<SaveModalProps, SaveModalState> {
disabled={!this.state.newSliceName}
data-test="btn-modal-save"
>
{!this.props.can_overwrite && this.props.slice
{!this.canOverwriteSlice() && this.props.slice
? t('Save as new chart')
: t('Save')}
</Button>
@@ -225,7 +228,7 @@ class SaveModal extends React.Component<SaveModalProps, SaveModalState> {
<FormItem data-test="radio-group">
<Radio
id="overwrite-radio"
disabled={!(this.props.can_overwrite && this.props.slice)}
disabled={!this.canOverwriteSlice()}
checked={this.state.action === 'overwrite'}
onChange={() => this.changeAction('overwrite')}
data-test="save-overwrite-radio"
@@ -289,8 +292,7 @@ function mapStateToProps({
return {
datasource: explore.datasource,
slice: explore.slice,
can_overwrite: explore.can_overwrite,
userId: explore.user_id,
userId: explore.user?.userId,
dashboards: saveModal.dashboards,
alert: saveModal.saveModalAlert,
};