Skip to content
Closed
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
1 change: 1 addition & 0 deletions superset-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"interweave": "^11.2.0",
"jquery": "^3.4.1",
"json-bigint": "^0.3.0",
"json-stringify-pretty-compact": "^2.0.0",
"lodash": "^4.17.15",
"lodash-es": "^4.17.14",
"mathjs": "^3.20.2",
Expand Down
13 changes: 11 additions & 2 deletions superset-frontend/src/dashboard/components/PropertiesModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import AceEditor from 'react-ace';
import rison from 'rison';
import { t } from '@superset-ui/translation';
import { SupersetClient } from '@superset-ui/connection';
import stringify from 'json-stringify-pretty-compact';
import '../stylesheets/buttons.less';

import getClientErrorObject from '../../utils/getClientErrorObject';
Expand All @@ -44,6 +45,14 @@ const defaultProps = {
show: false,
};

const prettyJSON = jsonString => {
try {
return stringify(JSON.parse(jsonString));
} catch (err) {
return jsonString;
}
};

class PropertiesModal extends React.PureComponent {
constructor(props) {
super(props);
Expand Down Expand Up @@ -99,7 +108,8 @@ class PropertiesModal extends React.PureComponent {
...state.values,
dashboard_title: dashboard.dashboard_title || '',
slug: dashboard.slug || '',
json_metadata: dashboard.json_metadata || '',
// always reformat to pretty json at initial opening
json_metadata: prettyJSON(dashboard.json_metadata) || '',
},
}));
const initialSelectedOwners = dashboard.owners.map(owner => ({
Expand Down Expand Up @@ -279,7 +289,6 @@ class PropertiesModal extends React.PureComponent {
<AceEditor
mode="json"
name="json_metadata"
defaultValue={this.defaultMetadataValue}
value={values.json_metadata}
onChange={this.onMetadataChange}
theme="textmate"
Expand Down