-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add delete button for additionalProperties key-value pair #1123
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
Changes from 13 commits
b59a9eb
a748ee1
6559d1d
8f5f597
ba1181d
939209c
d4569a9
eb72a4e
759d338
c4719af
d21e0aa
7f1a7f4
a558246
967e319
73cde14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ build | |
| dist | ||
| lib | ||
| yarn.lock | ||
| .vscode | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { | |
| retrieveSchema, | ||
| getDefaultRegistry, | ||
| getUiOptions, | ||
| ADDITIONAL_PROPERTY_FLAG, | ||
| } from "../../utils"; | ||
|
|
||
| function DefaultObjectFieldTemplate(props) { | ||
|
|
@@ -79,9 +80,21 @@ class ObjectField extends Component { | |
| ); | ||
| } | ||
|
|
||
| onPropertyChange = name => { | ||
| onPropertyChange = (name, additionalProperties = false) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about naming this parameter |
||
| return (value, errorSchema) => { | ||
| const newFormData = { ...this.props.formData, [name]: value }; | ||
| let newFormData; | ||
| if (!value && additionalProperties) { | ||
| newFormData = { | ||
| ...this.props.formData, | ||
| [name]: "", | ||
| }; | ||
|
glasserc marked this conversation as resolved.
|
||
| } else { | ||
| newFormData = { | ||
| ...this.props.formData, | ||
| [name]: value, | ||
| }; | ||
| } | ||
|
|
||
| this.props.onChange( | ||
| newFormData, | ||
| errorSchema && | ||
|
|
@@ -93,6 +106,18 @@ class ObjectField extends Component { | |
| }; | ||
| }; | ||
|
|
||
| onDropIndexClick = index => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the name |
||
| return event => { | ||
| if (event) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if we need to check whether |
||
| event.preventDefault(); | ||
| } | ||
| const { onChange, formData } = this.props; | ||
| const copiedFormData = { ...formData }; | ||
| delete copiedFormData[index]; | ||
| onChange(copiedFormData); | ||
| }; | ||
| }; | ||
|
|
||
| getAvailableKey = (preferredKey, formData) => { | ||
| var index = 0; | ||
| var newKey = preferredKey; | ||
|
|
@@ -176,7 +201,6 @@ class ObjectField extends Component { | |
| const title = schema.title === undefined ? name : schema.title; | ||
| const description = uiSchema["ui:description"] || schema.description; | ||
| let orderedProperties; | ||
|
|
||
| try { | ||
| const properties = Object.keys(schema.properties); | ||
| orderedProperties = orderProperties(properties, uiSchema["ui:order"]); | ||
|
|
@@ -200,6 +224,9 @@ class ObjectField extends Component { | |
| TitleField, | ||
| DescriptionField, | ||
| properties: orderedProperties.map(name => { | ||
| const additionalPropertyFlag = schema.properties[name].hasOwnProperty( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to rename this variable too. |
||
| ADDITIONAL_PROPERTY_FLAG | ||
| ); | ||
| return { | ||
| content: ( | ||
| <SchemaField | ||
|
|
@@ -213,12 +240,13 @@ class ObjectField extends Component { | |
| idPrefix={idPrefix} | ||
| formData={formData[name]} | ||
| onKeyChange={this.onKeyChange(name)} | ||
| onChange={this.onPropertyChange(name)} | ||
| onChange={this.onPropertyChange(name, additionalPropertyFlag)} | ||
| onBlur={onBlur} | ||
| onFocus={onFocus} | ||
| registry={registry} | ||
| disabled={disabled} | ||
| readonly={readonly} | ||
| onDropIndexClick={this.onDropIndexClick} | ||
| /> | ||
| ), | ||
| name, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { ADDITIONAL_PROPERTY_FLAG } from "../../utils"; | ||
| import IconButton from "../IconButton"; | ||
| import React from "react"; | ||
| import PropTypes from "prop-types"; | ||
|
|
||
|
|
@@ -107,7 +108,6 @@ function ErrorList(props) { | |
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function DefaultTemplate(props) { | ||
| const { | ||
| id, | ||
|
|
@@ -121,35 +121,70 @@ function DefaultTemplate(props) { | |
| required, | ||
| displayLabel, | ||
| onKeyChange, | ||
| onDropIndexClick, | ||
| } = props; | ||
| if (hidden) { | ||
| return children; | ||
| } | ||
| const btnStyle = { | ||
| flex: 1, | ||
| paddingLeft: 10, | ||
| paddingRight: 10, | ||
| fontWeight: "bold", | ||
| height: "34px", | ||
| }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This project doesn't use inline styles. You can rely on Bootstrap styles. |
||
| const additional = props.schema.hasOwnProperty(ADDITIONAL_PROPERTY_FLAG); | ||
| const keyLabel = `${label} Key`; | ||
|
|
||
| const contentStyle = additional | ||
| ? { | ||
| clear: "both", | ||
| display: "flex", | ||
| marginBottom: 0, | ||
| } | ||
| : {}; | ||
|
|
||
| return ( | ||
| <div className={classNames}> | ||
| <div className={classNames} style={contentStyle}> | ||
| {additional && ( | ||
| <div className="form-group"> | ||
| <Label label={keyLabel} required={required} id={`${id}-key`} /> | ||
| <LabelInput | ||
| label={label} | ||
| required={required} | ||
| id={`${id}-key`} | ||
| onChange={onKeyChange} | ||
| /> | ||
| <div | ||
| className="col-lg-6" | ||
| style={{ | ||
| padding: 0, | ||
| }}> | ||
| <div className="form-group form-additional"> | ||
| <Label label={keyLabel} required={required} id={`${id}-key`} /> | ||
| <LabelInput | ||
| label={label} | ||
| required={required} | ||
| id={`${id}-key`} | ||
| onChange={onKeyChange} | ||
| /> | ||
| </div> | ||
| </div> | ||
| )} | ||
| {displayLabel && <Label label={label} required={required} id={id} />} | ||
| {displayLabel && description ? description : null} | ||
| {children} | ||
| {errors} | ||
| {help} | ||
|
|
||
| <div className={additional ? "col-lg-6 form-additional" : ""}> | ||
| {displayLabel && <Label label={label} required={required} id={id} />} | ||
| {displayLabel && description ? description : null} | ||
| {children} | ||
| {errors} | ||
| {help} | ||
| </div> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pieplu I agree that lines 134 and 135 of this file can surely be merged into one (mistake on my side), which would probably leave just one empty div which is in line 150, but I at the first glance I don't know how to achieve same appearence using Bootstrap 3, and have a look at this: #1123 (comment)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I can try PR a fix with bootstrap style |
||
| {additional && ( | ||
| <IconButton | ||
| type="danger" | ||
| icon="remove" | ||
| className="array-item-remove" | ||
| tabIndex="-1" | ||
| style={btnStyle} | ||
| disabled={props.disabled || props.readonly} | ||
| onClick={onDropIndexClick(props.label)} | ||
| /> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| if (process.env.NODE_ENV !== "production") { | ||
| DefaultTemplate.propTypes = { | ||
| id: PropTypes.string, | ||
|
|
@@ -186,6 +221,7 @@ function SchemaFieldRender(props) { | |
| idPrefix, | ||
| name, | ||
| onKeyChange, | ||
| onDropIndexClick, | ||
| required, | ||
| registry = getDefaultRegistry(), | ||
| } = props; | ||
|
|
@@ -285,6 +321,7 @@ function SchemaFieldRender(props) { | |
| label, | ||
| hidden, | ||
| onKeyChange, | ||
| onDropIndexClick, | ||
| required, | ||
| disabled, | ||
| readonly, | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this belongs here. It would be better to put this in your
.git/info/exclude.