Skip to content

Commit

Permalink
feat: Show object keys alphabetically rather than in jsonb style [DHI…
Browse files Browse the repository at this point in the history
…S2-7523] (#16)
  • Loading branch information
myanghua authored Feb 12, 2021
1 parent 39a044f commit 151e89f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
9 changes: 7 additions & 2 deletions webapp/js/components/utils/JSONEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as dialogTypes from 'constants/dialogTypes';
import {jsonEditorChangeMode} from 'actions/jsonEditorActions';
import {openDialog} from 'actions/dialogActions';
import '../../../style/vendor/jsoneditor.css';
import { sortObjectKeys } from '../../utils/utils';

export class JSONEditor extends Component {

Expand Down Expand Up @@ -37,8 +38,12 @@ export class JSONEditor extends Component {
}
}

updateValue(value) {
this.editor.set(sortObjectKeys(value))
}

componentWillUpdate(nextProps) {
this.editor.set(nextProps.value);
this.updateValue(nextProps.value);
this.handleJsonEditor(nextProps);
}

Expand Down Expand Up @@ -119,7 +124,7 @@ export class JSONEditor extends Component {
};
this.editor = new JSEditor(this.editorContainer, opts);
this.removeBuiltInMenu();
this.editor.set(this.props.value);
this.updateValue(this.props.value);
}
}

Expand Down
2 changes: 1 addition & 1 deletion webapp/js/constants/apiUrls.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const API_URL = 'https://play.dhis2.org/test/api';
export const API_URL = 'https://debug.dhis2.org/dev/api';
17 changes: 16 additions & 1 deletion webapp/js/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,19 @@ export function debounce(func, wait, immediate) {
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
};

export const sortObjectKeys = obj => {
if (!obj || typeof obj !== 'object') {
return obj
}
if (Array.isArray(obj)) {
return obj.map(sortObjectKeys)
}
return Object.keys(obj)
.sort()
.reduce((res, key) => {
res[key] = sortObjectKeys(obj[key])
return res
}, {})
}

0 comments on commit 151e89f

Please sign in to comment.