Skip to content

Commit

Permalink
Remove hidden field feature in favor of feature added in rjsf-team#2405
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgros committed Jun 18, 2021
1 parent 62ffd68 commit 42aebfd
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 179 deletions.
5 changes: 0 additions & 5 deletions packages/bootstrap-4/src/FieldTemplate/FieldTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ const FieldTemplate = ({
rawDescription,
classNames,
disabled,
hidden,
label,
onDropPropertyClick,
onKeyChange,
readonly,
required,
schema,
}: FieldTemplateProps) => {
if (hidden) {
return <div className="hidden">{children}</div>;
}

return (
<WrapIfAdditional
classNames={classNames}
Expand Down
25 changes: 7 additions & 18 deletions packages/bootstrap-4/test/AdditionalProperties.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,14 @@ import { JSONSchema7 } from "json-schema";
import renderer from "react-test-renderer";

describe("AdditionalProperties tests", () => {
test("show hidden fields if additional properties is true", () => {
const schema: JSONSchema7 = {
additionalProperties: true,
};
const formData: any = {
"additionalProperty": 'myValue'

}
const tree = renderer.create(<Form schema={schema} formData={formData} />).toJSON();
expect(tree).toMatchSnapshot();
});
test("don't show hidden fields if additionalProperties is false", () => {
test("show add button and fields if additionalProperties is true", () => {
const schema: JSONSchema7 = {
additionalProperties: false,
};
const formData: any = {
"additionalProperty": 'should not appear'
}
additionalProperties: true,
};
const formData: any = {
"additionalProperty": 'should appear'
}
const tree = renderer.create(<Form schema={schema} formData={formData} />).toJSON();
expect(tree).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AdditionalProperties tests don't show hidden fields if additionalProperties is false 1`] = `
exports[`AdditionalProperties tests show add button and fields if additionalProperties is true 1`] = `
<form
className="rjsf"
noValidate={false}
Expand All @@ -10,181 +10,154 @@ exports[`AdditionalProperties tests don't show hidden fields if additionalProper
className="form-group"
>
<div
className="unsupported-field"
className="p-0 container-fluid"
>
<p>
Unsupported field schema
<span>
for
field
<code>
root
</code>
</span>
<em>
:
Unknown field type undefined
</em>
.
</p>
<pre>
{
"additionalProperties": false
}
</pre>
</div>
</div>
<div>
<button
className="btn btn-primary"
disabled={false}
type="submit"
>
Submit
</button>
</div>
</form>
`;

exports[`AdditionalProperties tests show hidden fields if additional properties is true 1`] = `
<form
className="rjsf"
noValidate={false}
onSubmit={[Function]}
>
<div
className="form-group"
>
<div
className="row"
>
<div
className="col-5"
>
<div
className="form-group"
>
<label
className="form-label"
>
additionalProperty Key
</label>
<input
className="form-control"
defaultValue="additionalProperty"
disabled={false}
id="root-key"
name="root-key"
onBlur={[Function]}
required={false}
type="text"
/>
</div>
</div>
<div
className="col-6"
className="row"
style={
Object {
"marginBottom": "10px",
}
}
>
<div
className="form-group"
className="col-12"
>
<div
className="mb-0 form-group"
className="row"
>
<label
className="form-label"
<div
className="col-5"
>
additionalProperty
</label>
<input
autoFocus={false}
className="form-control"
disabled={false}
id="root"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
readOnly={false}
required={false}
type="text"
value="myValue"
/>
<div
className="form-group"
>
<label
className="form-label"
>
additionalProperty Key
</label>
<input
className="form-control"
defaultValue="additionalProperty"
disabled={false}
id="root-key"
name="root-key"
onBlur={[Function]}
required={false}
type="text"
/>
</div>
</div>
<div
className="col-6"
>
<div
className="form-group"
>
<div
className="mb-0 form-group"
>
<label
className="form-label"
>
additionalProperty
</label>
<input
autoFocus={false}
className="form-control"
disabled={false}
id="root"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
placeholder=""
readOnly={false}
required={false}
type="text"
value="should appear"
/>
</div>
</div>
</div>
<div
className="py-4 col-1"
>
<button
className="btn btn-light btn-sm"
disabled={false}
onClick={[Function]}
tabIndex={-1}
type="button"
>
<svg
fill="currentColor"
height="1em"
stroke="currentColor"
strokeWidth="0"
style={
Object {
"color": undefined,
}
}
viewBox="0 0 512 512"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M368.5 240h-225c-8.8 0-16 7.2-16 16 0 4.4 1.8 8.4 4.7 11.3 2.9 2.9 6.9 4.7 11.3 4.7h225c8.8 0 16-7.2 16-16s-7.2-16-16-16z"
/>
</svg>
</button>
</div>
</div>
</div>
</div>
<div
className="py-4 col-1"
className="row"
>
<button
className="btn btn-light btn-sm"
disabled={false}
onClick={[Function]}
tabIndex={-1}
type="button"
<div
className="py-4 col-3 offset-9"
>
<svg
fill="currentColor"
height="1em"
stroke="currentColor"
strokeWidth="0"
<button
className="object-property-expand ml-1 btn btn-primary"
disabled={false}
onClick={[Function]}
style={
Object {
"color": undefined,
"width": "100%",
}
}
viewBox="0 0 512 512"
width="1em"
xmlns="http://www.w3.org/2000/svg"
type="button"
>
<path
d="M368.5 240h-225c-8.8 0-16 7.2-16 16 0 4.4 1.8 8.4 4.7 11.3 2.9 2.9 6.9 4.7 11.3 4.7h225c8.8 0 16-7.2 16-16s-7.2-16-16-16z"
/>
</svg>
</button>
</div>
</div>
<div
className="row"
>
<div
className="py-4 col-3 offset-9"
>
<button
className="object-property-expand ml-1 btn btn-primary"
disabled={false}
onClick={[Function]}
style={
Object {
"width": "100%",
}
}
type="button"
>
<svg
fill="currentColor"
height="1em"
stroke="currentColor"
strokeWidth="0"
style={
Object {
"color": undefined,
<svg
fill="currentColor"
height="1em"
stroke="currentColor"
strokeWidth="0"
style={
Object {
"color": undefined,
}
}
}
viewBox="0 0 16 16"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path
clipRule="evenodd"
d="M8 3.5a.5.5 0 01.5.5v4a.5.5 0 01-.5.5H4a.5.5 0 010-1h3.5V4a.5.5 0 01.5-.5z"
fillRule="evenodd"
/>
<path
clipRule="evenodd"
d="M7.5 8a.5.5 0 01.5-.5h4a.5.5 0 010 1H8.5V12a.5.5 0 01-1 0V8z"
fillRule="evenodd"
/>
</svg>
</button>
viewBox="0 0 16 16"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path
clipRule="evenodd"
d="M8 3.5a.5.5 0 01.5.5v4a.5.5 0 01-.5.5H4a.5.5 0 010-1h3.5V4a.5.5 0 01.5-.5z"
fillRule="evenodd"
/>
<path
clipRule="evenodd"
d="M7.5 8a.5.5 0 01.5-.5h4a.5.5 0 010 1H8.5V12a.5.5 0 01-1 0V8z"
fillRule="evenodd"
/>
</svg>
</button>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 42aebfd

Please sign in to comment.