From f0d3892b2675eca532fb64e54894bbf77ebd2dc2 Mon Sep 17 00:00:00 2001
From: David Aaron Suddjian <1858430+suddjian@users.noreply.github.com>
Date: Thu, 6 Feb 2020 10:00:27 -0800
Subject: [PATCH] [dashboard] Fix metadata state (#9088)
* use the full metadata object
* use ace editor for json
---
.../dashboard/components/PropertiesModal.jsx | 38 ++++++++++++-------
.../src/dashboard/reducers/getInitialState.js | 5 +--
2 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/superset/assets/src/dashboard/components/PropertiesModal.jsx b/superset/assets/src/dashboard/components/PropertiesModal.jsx
index 9b2fffe47..bf736e17f 100644
--- a/superset/assets/src/dashboard/components/PropertiesModal.jsx
+++ b/superset/assets/src/dashboard/components/PropertiesModal.jsx
@@ -21,6 +21,7 @@ import PropTypes from 'prop-types';
import { Row, Col, Button, Modal, FormControl } from 'react-bootstrap';
import Dialog from 'react-bootstrap-dialog';
import Select from 'react-select';
+import AceEditor from 'react-ace';
import { t } from '@superset-ui/translation';
import { SupersetClient } from '@superset-ui/connection';
@@ -49,19 +50,25 @@ const defaultProps = {
class PropertiesModal extends React.PureComponent {
constructor(props) {
super(props);
+ this.defaultMetadataValue = JSON.stringify(
+ props.dashboardInfo.metadata,
+ null,
+ 2,
+ );
this.state = {
errors: [],
values: {
dashboard_title: props.dashboardTitle,
slug: props.dashboardInfo.slug,
owners: props.owners || [],
- json_metadata: JSON.stringify(props.dashboardInfo.metadata),
+ json_metadata: this.defaultMetadataValue,
},
isOwnersLoaded: false,
userOptions: null,
isAdvancedOpen: false,
};
this.onChange = this.onChange.bind(this);
+ this.onMetadataChange = this.onMetadataChange.bind(this);
this.onOwnersChange = this.onOwnersChange.bind(this);
this.save = this.save.bind(this);
this.toggleAdvanced = this.toggleAdvanced.bind(this);
@@ -91,16 +98,19 @@ class PropertiesModal extends React.PureComponent {
}
onOwnersChange(value) {
- this.setState(state => ({
- values: {
- ...state.values,
- owners: value,
- },
- }));
+ this.updateFormState('owners', value);
+ }
+
+ onMetadataChange(metadata) {
+ this.updateFormState('json_metadata', metadata);
}
onChange(e) {
const { name, value } = e.target;
+ this.updateFormState(name, value);
+ }
+
+ updateFormState(name, value) {
this.setState(state => ({
values: {
...state.values,
@@ -245,14 +255,16 @@ class PropertiesModal extends React.PureComponent {
-
{t( diff --git a/superset/assets/src/dashboard/reducers/getInitialState.js b/superset/assets/src/dashboard/reducers/getInitialState.js index 4596f6361..b9ec8e68b 100644 --- a/superset/assets/src/dashboard/reducers/getInitialState.js +++ b/superset/assets/src/dashboard/reducers/getInitialState.js @@ -280,10 +280,7 @@ export default function(bootstrapData) { dashboardInfo: { id: dashboard.id, slug: dashboard.slug, - metadata: { - timed_refresh_immune_slices: - dashboard.metadata.timed_refresh_immune_slices, - }, + metadata: dashboard.metadata, userId: user_id, dash_edit_perm: dashboard.dash_edit_perm, dash_save_perm: dashboard.dash_save_perm,