Files
redash/client/app/visualizations/table/columns/json.jsx
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

39 lines
1.0 KiB
JavaScript

import { isString, isUndefined } from "lodash";
import React from "react";
import JsonViewInteractive from "@/components/json-view-interactive/JsonViewInteractive";
import { clientConfig } from "@/services/auth";
export default function initJsonColumn(column) {
function prepareData(row) {
const text = row[column.name];
if (isString(text) && text.length <= clientConfig.tableCellMaxJSONSize) {
try {
return { text, value: JSON.parse(text) };
} catch (e) {
// ignore `JSON.parse` error and return default value
}
}
return { text, value: undefined };
}
function JsonColumn({ row }) {
// eslint-disable-line react/prop-types
const { text, value } = prepareData(row);
if (isUndefined(value)) {
return <div className="json-cell-invalid">{"" + text}</div>;
}
return (
<div className="json-cell-valid">
<JsonViewInteractive value={value} />
</div>
);
}
JsonColumn.prepareData = prepareData;
return JsonColumn;
}
initJsonColumn.friendlyName = "JSON";