Skip to content

Commit

Permalink
format JSON values
Browse files Browse the repository at this point in the history
  • Loading branch information
olsender committed Apr 11, 2018
1 parent 33082fd commit 70bebcd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
"babel": "^6.23.0",
"babel-cli": "^6.24.1",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"mocha": "^2.2.5"
},
"dependencies": {
"d3": "^3.5.0",
"jquery": "^3.3.1",
"marked": "^0.3.3",
"react": "^0.14.9",
"react-dom": "^0.14.9",
Expand All @@ -17,6 +19,6 @@
"main": "sqldoc.js",
"scripts": {
"test": "node_modules/.bin/mocha",
"build:watch": "babel --plugins transform-react-jsx --out-dir=build src/ --watch"
"build:watch": "babel --plugins transform-react-jsx --presets es2015 --out-dir=build src/ --watch"
}
}
7 changes: 5 additions & 2 deletions src/SqlDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var SqlDoc = React.createClass({
},

componentDidUpdate: function(){
mount_charts();
this.mount_charts();
},

componentWillUnmount: function(){
Expand Down Expand Up @@ -334,6 +334,9 @@ var SqlDoc = React.createClass({

if (DataTypes.isNumeric(field_type)){
fields += '<td class="record-numeric-cell">'+val+'</td>';
} else if (DataTypes.isJSON(field_type)){
let json_view = '<pre class="record-json-value">'+JSON.stringify(JSON.parse(val), null, 2)+'</pre>'
fields += '<td>'+json_view+'</td>';
} else {
fields += '<td>'+val+'</td>';
}
Expand Down Expand Up @@ -444,7 +447,7 @@ var SqlDoc = React.createClass({
</th>);
}
});

if(rownum_column){
// render the rownum column?
out_fields.unshift(<th className="table-column-header" onClick={function(){
Expand Down
13 changes: 13 additions & 0 deletions src/datatypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,26 @@ var DataTypes = {
'float64',
],

JSONTypes: [
'json',
'jsonb',
],

isNumeric: function(datatype){
if (typeof(datatype) != "undefined" && datatype != null){
return (this.numericTypes.indexOf(datatype.toLowerCase()) > -1);
} else {
return false;
}
},

isJSON: function(datatype){
if (typeof(datatype) != "undefined" && datatype != null){
return (this.JSONTypes.indexOf(datatype.toLowerCase()) > -1);
} else {
return false;
}
}
}

try{
Expand Down

0 comments on commit 70bebcd

Please sign in to comment.