Skip to content

Commit

Permalink
Added eslintignore file
Browse files Browse the repository at this point in the history
Added props to allow configuration of what datatypes are detected
  • Loading branch information
Callum committed May 3, 2019
1 parent 9db21d5 commit b793e4b
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 98 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -0,0 +1 @@
test
8 changes: 3 additions & 5 deletions .eslintrc.js
Expand Up @@ -19,12 +19,10 @@ module.exports = {
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
4,
{ "SwitchCase": 1 }
],
"linebreak-style": 0,
"quotes": [
"error",
"single"
Expand Down
50 changes: 27 additions & 23 deletions src/js/components/VariableEditor.js
Expand Up @@ -75,21 +75,21 @@ class VariableEditor extends React.PureComponent {
<div {...Theme(theme, 'colon')}>:</div>
</span>
) : (
<span>
<span
{...Theme(theme, 'object-name')}
class="object-key"
key={variable.name + '_' + namespace}
>
<span style={{ verticalAlign: 'top' }}>"</span>
<span style={{ display: 'inline-block' }}>
{variable.name}
</span>
<span style={{ verticalAlign: 'top' }}>"</span>
<span>
<span
{...Theme(theme, 'object-name')}
class="object-key"
key={variable.name + '_' + namespace}
>
<span style={{ verticalAlign: 'top' }}>"</span>
<span style={{ display: 'inline-block' }}>
{variable.name}
</span>
<span {...Theme(theme, 'colon')}>:</span>
<span style={{ verticalAlign: 'top' }}>"</span>
</span>
)}
<span {...Theme(theme, 'colon')}>:</span>
</span>
)}
<div
class="variable-value"
onClick={
Expand Down Expand Up @@ -189,8 +189,9 @@ class VariableEditor extends React.PureComponent {
}

getValue = (variable, editMode) => {
const type = editMode ? false : variable.type;
const { props } = this;
const type = editMode ? false : variable.type;

switch (type) {
case false:
return this.getEditInput();
Expand Down Expand Up @@ -314,12 +315,15 @@ class VariableEditor extends React.PureComponent {
}

showDetected = () => {
const { theme, variable, namespace, rjvId } = this.props;
const { theme, variable, namespace, rjvId, detectDatatypes } = this.props;
const { type, value } = this.state.parsedInput;
const detected = this.getDetectedInput();
if (detected) {
return (
<div>

// check if props allow for detection parsed type

if (detectDatatypes[type]) {
const detected = this.getDetectedInput();
if (detected) {
return (
<div {...Theme(theme, 'detected-row')} title="Submit as Datatype">
{detected}
<CheckCircle
Expand All @@ -334,8 +338,8 @@ class VariableEditor extends React.PureComponent {
}}
/>
</div>
</div>
);
);
}
}
}

Expand Down Expand Up @@ -365,7 +369,7 @@ class VariableEditor extends React.PureComponent {
}}
>
...
</span>
</span>
<span
style={{
...Theme(theme, 'brace').style,
Expand Down Expand Up @@ -394,7 +398,7 @@ class VariableEditor extends React.PureComponent {
}}
>
...
</span>
</span>
<span
style={{
...Theme(theme, 'brace').style,
Expand Down
42 changes: 21 additions & 21 deletions src/js/helpers/parseInput.js
Expand Up @@ -35,28 +35,28 @@ export default function parseInput(input) {
//run in case input was not serializable
input = input.toLowerCase();
switch (input) {
case 'undefined': {
return formatResponse('undefined', undefined);
}
case 'nan': {
return formatResponse('nan', NaN);
}
case 'null': {
return formatResponse('null', null);
}
case 'true': {
return formatResponse('boolean', true);
}
case 'false': {
return formatResponse('boolean', false);
}
default: {
//check to see if this is a date
input = Date.parse(input);
if (input) {
return (formatResponse('date', new Date(input)));
case 'undefined': {
return formatResponse('undefined', undefined);
}
case 'nan': {
return formatResponse('nan', NaN);
}
case 'null': {
return formatResponse('null', null);
}
case 'true': {
return formatResponse('boolean', true);
}
case 'false': {
return formatResponse('boolean', false);
}
default: {
//check to see if this is a date
input = Date.parse(input);
if (input) {
return (formatResponse('date', new Date(input)));
}
}
}
}

return formatResponse(false, null);
Expand Down
37 changes: 25 additions & 12 deletions src/js/index.js
@@ -1,9 +1,9 @@
import React from 'react';
import {polyfill} from 'react-lifecycles-compat';
import { polyfill } from 'react-lifecycles-compat';
import JsonViewer from './components/JsonViewer';
import AddKeyRequest from './components/ObjectKeyModal/AddKeyRequest';
import ValidationFailure from './components/ValidationFailure';
import {toType, isTheme} from './helpers/util';
import { toType, isTheme } from './helpers/util';
import ObjectAttributes from './stores/ObjectAttributes';

//global theme
Expand Down Expand Up @@ -59,6 +59,19 @@ class ReactJsonView extends React.PureComponent {
style: {},
validationMessage: 'Validation Error',
defaultValue: null,
detectDatatypes: {
object: true,
array: true,
string: true,
integer: true,
float: true,
boolean: true,
date: true,
function: true,
null: true,
nan: true,
undefined: true
}
}

// will trigger whenever setState() is called, or parent passes in new props.
Expand Down Expand Up @@ -192,7 +205,7 @@ class ReactJsonView extends React.PureComponent {
return (
<div
class="react-json-view"
style={{...Theme(theme, 'app-container').style, ...style}}
style={{ ...Theme(theme, 'app-container').style, ...style }}
>
<ValidationFailure
message={validationMessage}
Expand Down Expand Up @@ -238,15 +251,15 @@ class ReactJsonView extends React.PureComponent {
};

switch (type) {
case 'variable-added':
result = onAdd(on_edit_payload);
break;
case 'variable-edited':
result = onEdit(on_edit_payload);
break;
case 'variable-removed':
result = onDelete(on_edit_payload);
break;
case 'variable-added':
result = onAdd(on_edit_payload);
break;
case 'variable-edited':
result = onEdit(on_edit_payload);
break;
case 'variable-removed':
result = onDelete(on_edit_payload);
break;
}

if (result !== false) {
Expand Down
18 changes: 9 additions & 9 deletions test/tests/js/Index-test.js
Expand Up @@ -10,10 +10,10 @@ const { window } = new JSDOM()
global.window = window
global.document = window.document

describe("<Index />", function() {
describe("<Index />", function () {
const rjvId = 1

it("check data type labels from index", function() {
it("check data type labels from index", function () {
const wrapper = render(
<Index
src={{
Expand All @@ -22,7 +22,7 @@ describe("<Index />", function() {
int: 5,
nan: NaN,
null: null,
func: test => {},
func: test => { },
obj: {
arrChild: [1, 2, "three"],
objChild: {
Expand All @@ -39,7 +39,7 @@ describe("<Index />", function() {
expect(wrapper.find(".data-type-label")).to.have.length(14)
})

it("check object-size labels from index", function() {
it("check object-size labels from index", function () {
const wrapper = mount(
<Index
src={{
Expand All @@ -48,7 +48,7 @@ describe("<Index />", function() {
int: 5,
nan: NaN,
null: null,
func: test => {},
func: test => { },
obj: {
arrChild: [1, 2, "three"],
objChild: {
Expand All @@ -70,14 +70,14 @@ describe("<Index />", function() {
expect(wrapper.find(".object-size")).to.have.length(0)
})

it("src replaced with error message (ERROR OUTPUT EXPECTED)", function() {
it("src replaced with error message (ERROR OUTPUT EXPECTED)", function () {
const wrapper = render(
<Index src={"{jsonEncodedString:true, createError:true}"} />
)
expect(wrapper.find(".data-type-label")).to.have.length(1)
})

it("make sure copy to clipboard is displayed all properties", function() {
it("make sure copy to clipboard is displayed all properties", function () {
const wrapper = render(
<Index
src={{
Expand All @@ -92,7 +92,7 @@ describe("<Index />", function() {
expect(wrapper.find(".click-to-copy")).to.have.length(7)
})

it("index test getDerivedStateFromProps", function() {
it("index test getDerivedStateFromProps", function () {
sinon.spy(Index, "getDerivedStateFromProps")
// mount() will cause getDerivedStateFromProps to be called twice.
// 1. before first render()
Expand All @@ -107,7 +107,7 @@ describe("<Index />", function() {
)
})

it("index can have ArrayGroup root component", function() {
it("index can have ArrayGroup root component", function () {
const wrapper = render(
<Index
name="test"
Expand Down

0 comments on commit b793e4b

Please sign in to comment.