open-vault/ui/app/components/console/log-object.js
Hamid Ghaf 27bb03bbc0
adding copyright header (#19555)
* adding copyright header

* fix fmt and a test
2023-03-15 09:00:52 -07:00

35 lines
787 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { capitalize } from '@ember/string';
import Component from '@ember/component';
import { computed } from '@ember/object';
import columnify from 'columnify';
export function stringifyObjectValues(data) {
Object.keys(data).forEach((item) => {
let val = data[item];
if (typeof val !== 'string') {
val = JSON.stringify(val);
}
data[item] = val;
});
}
export default Component.extend({
content: null,
columns: computed('content', function () {
const data = this.content;
stringifyObjectValues(data);
return columnify(data, {
preserveNewLines: true,
headingTransform: function (heading) {
return capitalize(heading);
},
});
}),
});