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

Bug Fix empty html useless added by PR #1123 / v1.2.0 #1158

Merged
merged 15 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from 13 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: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ dist
lib
yarn.lock

# IDE
.vscode

# Code coverage
coverage
.nyc_output
104 changes: 59 additions & 45 deletions src/components/fields/SchemaField.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ function ErrorList(props) {
function DefaultTemplate(props) {
const {
id,
classNames,
label,
children,
errors,
Expand All @@ -129,56 +128,19 @@ function DefaultTemplate(props) {
hidden,
required,
displayLabel,
onKeyChange,
onDropPropertyClick,
} = props;
if (hidden) {
return <div className="hidden">{children}</div>;
}

const additional = props.schema.hasOwnProperty(ADDITIONAL_PROPERTY_FLAG);
const keyLabel = `${label} Key`;

return (
<div className={classNames}>
<div className={additional ? "row" : ""}>
{additional && (
<div className="col-xs-5 form-additional">
<div className="form-group">
<Label label={keyLabel} required={required} id={`${id}-key`} />
<LabelInput
label={label}
required={required}
id={`${id}-key`}
onChange={onKeyChange}
/>
</div>
</div>
)}

<div
className={additional ? "form-additional form-group col-xs-5" : ""}>
{displayLabel && <Label label={label} required={required} id={id} />}
{displayLabel && description ? description : null}
{children}
{errors}
{help}
</div>
<div className="col-xs-2">
{additional && (
<IconButton
type="danger"
icon="remove"
className="array-item-remove btn-block"
tabIndex="-1"
style={{ border: "0" }}
disabled={props.disabled || props.readonly}
onClick={onDropPropertyClick(props.label)}
/>
)}
</div>
</div>
</div>
<WrapIfAdditional parentProps={props}>
pieplu marked this conversation as resolved.
Show resolved Hide resolved
{displayLabel && <Label label={label} required={required} id={id} />}
{displayLabel && description ? description : null}
{children}
{errors}
{help}
</WrapIfAdditional>
);
}
if (process.env.NODE_ENV !== "production") {
Expand Down Expand Up @@ -209,6 +171,58 @@ DefaultTemplate.defaultProps = {
displayLabel: true,
};

function WrapIfAdditional(props) {
const {
id,
classNames,
disabled,
label,
onKeyChange,
onDropPropertyClick,
readonly,
required,
schema,
} = props.parentProps;
pieplu marked this conversation as resolved.
Show resolved Hide resolved
const keyLabel = `${label} Key`; // i18n ?
const additional = schema.hasOwnProperty(ADDITIONAL_PROPERTY_FLAG);

if (!additional) {
return <div className={classNames}>{props.children}</div>;
}

return (
<div className={classNames}>
<div className="row">
<div className="col-xs-5 form-additional">
<div className="form-group">
<Label label={keyLabel} required={required} id={`${id}-key`} />
<LabelInput
label={label}
required={required}
id={`${id}-key`}
onChange={onKeyChange}
/>
</div>
</div>
<div className="form-additional form-group col-xs-5">
{props.children}
</div>
<div className="col-xs-2">
<IconButton
type="danger"
icon="remove"
className="array-item-remove btn-block"
tabIndex="-1"
style={{ border: "0" }}
disabled={disabled || readonly}
onClick={onDropPropertyClick(label)}
/>
</div>
</div>
</div>
);
}

function SchemaFieldRender(props) {
const {
uiSchema,
Expand Down
2 changes: 1 addition & 1 deletion test/ArrayFieldTemplate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("ArrayFieldTemplate", () => {
ArrayFieldTemplate,
});

expect(node.querySelectorAll(".field-array div")).to.have.length.of(6);
expect(node.querySelectorAll(".field-array div")).to.have.length.of(3);
});
});

Expand Down
3 changes: 1 addition & 2 deletions test/ArrayField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ describe("ArrayField", () => {
const { node } = createFormComponent({ schema: { type: "array" } });

expect(
node.querySelector(".field-array > div > div > .unsupported-field")
.textContent
node.querySelector(".field-array > .unsupported-field").textContent
).to.contain("Missing items definition");
});
});
Expand Down
26 changes: 17 additions & 9 deletions test/ObjectField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe("ObjectField", () => {
},
});
const labels = [].map.call(
node.querySelectorAll(".field > div > div > label"),
node.querySelectorAll(".field > label"),
l => l.textContent
);

Expand All @@ -224,7 +224,7 @@ describe("ObjectField", () => {
},
});
const labels = [].map.call(
node.querySelectorAll(".field > div > div> label"),
node.querySelectorAll(".field > label"),
l => l.textContent
);

Expand Down Expand Up @@ -289,7 +289,7 @@ describe("ObjectField", () => {
},
});
const labels = [].map.call(
node.querySelectorAll(".field > div > div > label"),
node.querySelectorAll(".field > label"),
l => l.textContent
);

Expand Down Expand Up @@ -322,7 +322,7 @@ describe("ObjectField", () => {
},
});
const labels = [].map.call(
node.querySelectorAll(".field > div > div > label"),
node.querySelectorAll(".field > label"),
l => l.textContent
);

Expand Down Expand Up @@ -720,13 +720,18 @@ describe("ObjectField", () => {
});

expect(
node.querySelector(".form-group > .row > .col-xs-2 .btn-danger")
node.querySelector(
".form-group > .form-additional > .form-additional-actions .btn-danger"
pieplu marked this conversation as resolved.
Show resolved Hide resolved
)
).eql(null);

Simulate.click(node.querySelector(".object-property-expand button"));

expect(node.querySelector(".form-group > .row > .col-xs-2 > .btn-danger"))
.to.not.be.null;
expect(
node.querySelector(
".form-group > .row > .form-additional + .col-xs-2 > .btn-danger"
)
).to.not.be.null;
});

it("delete button should delete key-value pair", () => {
Expand All @@ -736,7 +741,9 @@ describe("ObjectField", () => {
});
expect(node.querySelector("#root_first-key").value).to.eql("first");
Simulate.click(
node.querySelector(".form-group > .row > .col-xs-2 > .btn-danger")
node.querySelector(
".form-group > .row > .form-additional + .col-xs-2 > .btn-danger"
)
);
expect(node.querySelector("#root_first-key")).to.not.exist;
});
Expand All @@ -746,7 +753,8 @@ describe("ObjectField", () => {
schema,
formData: { first: 1, second: 2, third: 3 },
});
const selector = ".form-group > .row > .col-xs-2 > .btn-danger";
const selector =
".form-group > .row > .form-additional + .col-xs-2 > .btn-danger";
expect(node.querySelectorAll(selector).length).to.eql(3);
Simulate.click(node.querySelectorAll(selector)[1]);
expect(node.querySelector("#root_second-key")).to.not.exist;
Expand Down
2 changes: 1 addition & 1 deletion test/SchemaField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ describe("SchemaField", () => {
submit(node);

const matches = node.querySelectorAll(
"form > .form-group > div > div > div > .error-detail .text-danger"
"form > .form-group > div > .error-detail .text-danger"
);
expect(matches).to.have.length.of(1);
expect(matches[0].textContent).to.eql("container");
Expand Down