Commit 45d2e70b by Torkel Ödegaard

feat(dashboard): sorting dashboard model kekeys, refactoring PR #7139

parent c472054f
......@@ -2,20 +2,14 @@ import _ from 'lodash';
export default function sortByKeys(input) {
if (_.isArray(input)) {
var newArray = [];
_.forEach(
input,
function(item) { newArray.push(sortByKeys(item)); }
);
return newArray;
return input.map(sortByKeys);
}
if (_.isPlainObject(input)) {
var sortedObject = {};
_.forEach(
_.keys(input).sort(),
function(key) { sortedObject[key] = sortByKeys(input[key]); }
);
for (let key of _.keys(input).sort()) {
sortedObject[key] = sortByKeys(input[key]);
}
return sortedObject;
}
......
......@@ -3,7 +3,6 @@
import config from 'app/core/config';
import angular from 'angular';
import _ from 'lodash';
import sortByKeys from 'app/core/utils/sort_by_keys';
import {DynamicDashboardSrv} from '../dynamic_dashboard_srv';
......@@ -152,8 +151,8 @@ export class DashboardExporter {
newObj["__requires"] = _.sortBy(requires, ['id']);
_.defaults(newObj, saveModel);
return newObj;
return sortByKeys(newObj);
}).catch(err => {
console.log('Export failed:', err);
return {
......
......@@ -8,6 +8,7 @@ import $ from 'jquery';
import {Emitter, contextSrv, appEvents} from 'app/core/core';
import {DashboardRow} from './row/row_model';
import sortByKeys from 'app/core/utils/sort_by_keys';
export class DashboardModel {
id: any;
......@@ -36,7 +37,7 @@ export class DashboardModel {
events: any;
editMode: boolean;
constructor(data, meta) {
constructor(data, meta?) {
if (!data) {
data = {};
}
......@@ -107,7 +108,10 @@ export class DashboardModel {
this.rows = _.map(rows, row => row.getSaveModel());
this.templating.list = _.map(variables, variable => variable.getSaveModel ? variable.getSaveModel() : variable);
// make clone
var copy = $.extend(true, {}, this);
// sort clone
copy = sortByKeys(copy);
// restore properties
this.events = events;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment