Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add quotesOnValues option #349

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Name|Type|Default|Description
`onSelect`|`(select)=>{}`|`false`|When a function is passed in, clicking a value triggers the `onSelect` method to be called.
`sortKeys`|`boolean`|`false`|set to true to sort object keys
`quotesOnKeys`|`boolean`|`true`|set to false to remove quotes from keys (eg. `"name":` vs. `name:`)
`quotesOnValues`|`boolean`|`true`|set to false to remove quotes from Values (eg. `[key]: "value"` vs. `[key]: value`)
`validationMessage`|`string`|"Validation Error"|Custom message for validation failures to `onEdit`, `onAdd`, or `onDelete` callbacks
`displayArrayKey`|`boolean`|`true`|When set to `true`, the index of the elements prefix values

Expand Down Expand Up @@ -145,4 +146,4 @@ For information about contributing with Docker, see the [README in ./docker](htt
### Inspiration
I drew a ton of design ideas from [react-json-tree](https://github.com/alexkuz/react-json-tree). Thanks to the RJT contributors for putting together an awesome component!

I'm also inspired by users who come up with interesting feature requests. Reach out to me with ideas for this project or other projects you want to collaborate on. My email address is listed on my [github user page](https://github.com/mac-s-g).
I'm also inspired by users who come up with interesting feature requests. Reach out to me with ideas for this project or other projects you want to collaborate on. My email address is listed on my [github user page](https://github.com/mac-s-g).
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ export interface ReactJsonViewProps {
* Default: true
*/
quotesOnKeys?: boolean;
/**
* set to false to remove quotes from Values (eg. [key]: "value" vs. [key]: value)
*
* Default: true
*/
quotesOnValues?: boolean;
/**
* When a callback function is passed in, edit functionality is enabled.
* The callback is invoked before edits are completed. Returning false
Expand Down
11 changes: 8 additions & 3 deletions src/js/components/DataTypes/String.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ export default class extends React.PureComponent {
const type_name = 'string';
const { collapsed } = this.state;
const { props } = this;
const { collapseStringsAfterLength, theme } = props;
const {
collapseStringsAfterLength,
theme,
quotesOnValues = true
} = props;
let { value } = props;
let collapsible = toType(collapseStringsAfterLength) === 'integer';
let style = { style: { cursor: 'default' } };
Expand All @@ -57,7 +61,6 @@ export default class extends React.PureComponent {
);
}
}

return (
<div {...Theme(theme, 'string')}>
<DataTypeLabel type_name={type_name} {...props} />
Expand All @@ -66,7 +69,9 @@ export default class extends React.PureComponent {
{...style}
onClick={this.toggleCollapsed}
>
"{value}"
{quotesOnValues ? '"' : ''}
{value}
{quotesOnValues ? '"' : ''}
</span>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ReactJsonView extends React.PureComponent {
shouldCollapse: false,
sortKeys: false,
quotesOnKeys: true,
quotesOnValues: true,
groupArraysAfterLength: 100,
indentWidth: 4,
enableClipboard: true,
Expand Down
17 changes: 17 additions & 0 deletions test/tests/js/components/DataTypes/String-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,21 @@ describe("<JsonString />", function() {
.text()
).to.equal('"123456789"')
})

it("remove quotes from string value", function() {
const props = {
value: "123456789",
quotesOnValues: false,
rjvId: 1,
displayDataTypes: false,
theme: "rjv-default"
}
const component = shallow(<JsonString {...props} />)
expect(
component
.render()
.find(".string-value")
.text()
).to.equal('123456789')
})
})