From 151e89ffe555d63d85a85d60f172b04f3ec24c2e Mon Sep 17 00:00:00 2001 From: Mickey Young Date: Fri, 12 Feb 2021 16:43:22 -0500 Subject: [PATCH] feat: Show object keys alphabetically rather than in jsonb style [DHIS2-7523] (#16) --- webapp/js/components/utils/JSONEditor.js | 9 +++++++-- webapp/js/constants/apiUrls.js | 2 +- webapp/js/utils/utils.js | 17 ++++++++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/webapp/js/components/utils/JSONEditor.js b/webapp/js/components/utils/JSONEditor.js index fc4df70..b435ea2 100644 --- a/webapp/js/components/utils/JSONEditor.js +++ b/webapp/js/components/utils/JSONEditor.js @@ -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 { @@ -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); } @@ -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); } } diff --git a/webapp/js/constants/apiUrls.js b/webapp/js/constants/apiUrls.js index 6c7b47b..9e6f9ac 100644 --- a/webapp/js/constants/apiUrls.js +++ b/webapp/js/constants/apiUrls.js @@ -1 +1 @@ -export const API_URL = 'https://play.dhis2.org/test/api'; +export const API_URL = 'https://debug.dhis2.org/dev/api'; diff --git a/webapp/js/utils/utils.js b/webapp/js/utils/utils.js index 169c3ec..b812ac4 100644 --- a/webapp/js/utils/utils.js +++ b/webapp/js/utils/utils.js @@ -12,4 +12,19 @@ export function debounce(func, wait, immediate) { timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; -}; \ No newline at end of file +}; + +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 + }, {}) +}