Files
redash/client/app/lib/utils.js
Arik Fraimovich 56d3be2248 Prettier all the Javascript code & GitHub Action (#4433)
* Prettier all the JS files

* Add GitHub Action to autoformat code pushed to master

* Fix eslint violation due to formatting.

* Remove GitHub actions for styling

* Add restyled.io config
2019-12-11 17:05:38 +02:00

43 lines
1.1 KiB
JavaScript

import { isObject, cloneDeep, each, extend } from "lodash";
export function routesToAngularRoutes(routes, template) {
const result = {};
template = extend({}, template); // convert to object
each(routes, ({ path, title, key, ...resolve }) => {
// Convert to functions
each(resolve, (value, prop) => {
resolve[prop] = () => value;
});
result[path] = {
...template,
title,
// keep `resolve` from `template` (if exists)
resolve: {
...template.resolve,
...resolve,
currentPage: () => key,
},
};
});
return result;
}
// ANGULAR_REMOVE_ME
export function cleanAngularProps(value) {
// remove all props that start with '$$' - that's what `angular.toJson` does
const omitAngularProps = obj => {
each(obj, (v, k) => {
if (("" + k).startsWith("$$")) {
delete obj[k];
} else {
obj[k] = isObject(v) ? omitAngularProps(v) : v;
}
});
return obj;
};
const result = cloneDeep(value);
return isObject(result) ? omitAngularProps(result) : result;
}