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

Added non editable fields support & classes on variables #399

Open
wants to merge 3 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Name|Type|Default|Description
`quotesOnKeys`|`boolean`|`true`|set to false to remove quotes from keys (eg. `"name":` vs. `name:`)
`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
`nonEditableFields`|`array`|`[]`|Array of variable names which should be explicitly set as non-editable

### Features
* `onEdit`, `onAdd` and `onDelete` props allow users to edit the `src` variable
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/DataTypes/Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class RjvObject extends React.PureComponent {

return (
<div
class="object-key-val"
class={`object-key-val ${name}`}
onMouseEnter={() =>
this.setState({ ...this.state, hovered: true })
}
Expand Down
9 changes: 5 additions & 4 deletions src/js/components/VariableEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class VariableEditor extends React.PureComponent {
onDelete,
onSelect,
displayArrayKey,
quotesOnKeys
quotesOnKeys,
nonEditableFields
} = this.props;
const { editMode } = this.state;
return (
Expand All @@ -69,7 +70,7 @@ class VariableEditor extends React.PureComponent {
onMouseLeave={() =>
this.setState({ ...this.state, hovered: false })
}
class="variable-row"
class={`variable-row ${variable.name}`}
key={variable.name}
>
{type == 'array' ? (
Expand Down Expand Up @@ -138,10 +139,10 @@ class VariableEditor extends React.PureComponent {
{...{ theme, namespace: [...namespace, variable.name] }}
/>
) : null}
{onEdit !== false && editMode == false
{onEdit !== false && !nonEditableFields.includes(variable.name) && editMode == false
? this.getEditIcon()
: null}
{onDelete !== false && editMode == false
{onDelete !== false && !nonEditableFields.includes(variable.name) && editMode == false
? this.getRemoveIcon()
: null}
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class ReactJsonView extends React.PureComponent {
style: {},
validationMessage: 'Validation Error',
defaultValue: null,
displayArrayKey: true
displayArrayKey: true,
nonEditableFields: []
};

// will trigger whenever setState() is called, or parent passes in new props.
Expand Down