Files
redash/client/app/components/dynamic-table/json-cell/index.js
swfz afaedb9062 [Feature] Table visualization: Raise the upper limit of MAX_JSON_SIZE (#3310)
* move constant value to clientConfig
* change name maxJsonSize to tableCellMaxJSONSize
* value from environment. default is 50000
2019-02-13 11:42:40 +02:00

45 lines
1.1 KiB
JavaScript

import { isUndefined, isString } from 'lodash';
import renderJsonView from './json-view-interactive';
import template from './template.html';
function parseValue(value, clientConfig) {
if (isString(value) && value.length <= clientConfig.tableCellMaxJSONSize) {
try {
return JSON.parse(value);
} catch (e) {
return undefined;
}
}
}
function DynamicTableJsonCell(clientConfig) {
return {
template,
restrict: 'E',
replace: true,
scope: {
column: '=',
value: '=',
},
link: ($scope, $element) => {
const container = $element.find('.json-cell-valid');
$scope.isValid = false;
$scope.parsedValue = null;
$scope.$watch('value', () => {
$scope.parsedValue = parseValue($scope.value, clientConfig);
$scope.isValid = !isUndefined($scope.parsedValue);
container.empty();
renderJsonView(container, $scope.parsedValue);
});
},
};
}
export default function init(ngModule) {
ngModule.directive('dynamicTableJsonCell', DynamicTableJsonCell);
}
init.init = true;