Commit 4616bb6
Feature - Optional Data Controls (rjsf-team#4798)
* Feature - Optional Data Controls
Added new `Optional Data Controls` feature as follows:
- In `@rjsf/utils`:
- Updated existing tests where `getDefaultFormState` is used to reflect addition of `initialDefaultsGenerated`
- Updated `types.ts` to support the new `Optional Data Controls` feature as follows:
- Added new `OptionalDataControlsTemplateProps` and refactored the common props from `ArrayFieldTemplateProps` and `ObjectFieldTemplateProps` into a new super type, `ContainerFieldTemplateProps`
- Added new `optionalDataControl?: ReactNode` to the `ArrayFieldTitleProps`, `TitleFieldProps` and `ContainerFieldTemplateProps`
- Updated `GlobalFormOptions` to add new `enableOptionalDataFieldForType?: ('object' | 'array')[]` prop
- Updated `SchemaUtilsType`'s `retrieveSchema()` function to add an additional, property `resolveAnyOfOrOneOfRefs?: boolean`
- Updated the `Templates` interface to add a new required template `OptionalDataControlsTemplate: ComponentType<OptionalDataControlsTemplateProps<T, S, F>>`
- Updated `retrieveSchema()` to add an additional property `resolveAnyOfOrOneOfRefs?: boolean` which causes `resolveAllSchemas()` to resolve `$ref`s inside of the options of `anyOf`/`oneOf` schemas
- Updated `getDefaultFormState` to fix an issue where optional array props had their default set to an empty array when they shouldn't be
- Updated the `TranslatableString` enum to add three new strings in support of the new feature: `OptionalObjectAdd`, `OptionalObjectRemove` and `OptionalObjectEmptyMsg`
- Added three new utility functions: `isFormDataAvailable()`, `isRootSchema()` and `shouldRenderOptionalField()`
- Added or updated tests to verify all of the new behaviors
- In `@rjsf/core`:
- Added a new `OptionalDataControlsField` to the `fields` that renders either undefined (when there is data for a readonly/disabled field) or gets the `OptionalDataControlsTemplate` and renders the `label` and potentially an `onAddClick` or `onRemoveClick` function
- Updated `ArrayField` and `ObjectField` to check whether it `shouldRenderOptionalData()` and if true, calls `ObjectDataControlsField` and passes the result to its associated render template as `optionalDataControl`
- Updated `ArrayFieldTemplate`, `ObjectFieldTemplate`, `TitleField` to add support for the new `optionalDataControl` feature
- Added the new `OptionalDataControlTemplate` to the theme, adding it to the `templates` list
- In the rest of the themes:
- Updated `ArrayFieldTemplate`, `ArrayFieldTitleTemplate`, `ObjectFieldTemplate`, `TitleField` to add support for the new `optionalDataControl` feature
- Added the new `OptionalDataControlTemplate` to the theme, adding it to the `templates` list
- Updated the `ButtonTemplates` classes to better support the `OptionalDataControlTemplate`
- In the doc directory:
- Updated `utility-function.me` docs to add documentation for the new functions
- Also updated docs for `retrieveSchema` and `SchemaUtilsType` for the new prop
- Updated `uiSchema.md` to add documentation for the new `enableOptionalDataFieldForType` prop
- Updated the `v6x upgrade guide.md` to document the new feature and utility functions and changes to `retrieveSchema`
- Updated the playground to add a new `Optional Data Controls` example
- Updated the snapshot and jest tests for `Form` to test the new `Optional Data Controls` feature
- Updated the `CHANGELOG.md` file accordingly
* - Added the snapsnot test for `FormTest.tsx` and ran it on all the themes
* - Added new `optionalControlsId()` function, using it to add ids to all of the data controls
* - Finished up all of the testing
* - Added/updated documentation
* Apply suggestions from code review
-Responded to reviewer feedback
Co-authored-by: Nick Grosenbacher <[email protected]>
---------
Co-authored-by: Nick Grosenbacher <[email protected]>1 parent f4cd0a5 commit 4616bb6
File tree
145 files changed
+82563
-450
lines changed- packages
- antd
- src/templates
- ArrayFieldTemplate
- IconButton
- ObjectFieldTemplate
- OptionalDataControlsTemplate
- TitleField
- test/__snapshots__
- chakra-ui
- src
- ArrayFieldTemplate
- IconButton
- ObjectFieldTemplate
- OptionalDataControlsTemplate
- Templates
- TitleField
- test/__snapshots__
- core
- src/components
- fields
- templates
- ButtonTemplates
- test
- __snapshots__
- daisyui
- src/templates
- ArrayFieldTemplate
- ArrayFieldTitleTemplate
- ButtonTemplates
- ObjectFieldTemplate
- OptionalDataControlsTemplate
- TitleField
- test/__snapshots__
- docs/docs
- advanced-customization
- api-reference
- migration-guides
- fluentui-rc
- src
- AddButton
- ArrayFieldTemplate
- IconButton
- ObjectFieldTemplate
- OptionalDataControlsTemplate
- Templates
- TitleField
- test/__snapshots__
- mantine
- src/templates
- test/__snapshots__
- mui
- src
- ArrayFieldTemplate
- ObjectFieldTemplate
- OptionalDataControlsTemplate
- Templates
- TitleField
- test/__snapshots__
- playground/src
- samples
- primereact
- src
- ArrayFieldTemplate
- ArrayFieldTitleTemplate
- IconButton
- ObjectFieldTemplate
- OptionalDataControlsTemplate
- Templates
- TitleField
- test/__snapshots__
- react-bootstrap
- src
- AddButton
- ArrayFieldTemplate
- IconButton
- ObjectFieldTemplate
- OptionalDataControlsTemplate
- Templates
- TitleField
- test/__snapshots__
- semantic-ui
- src
- AddButton
- ArrayFieldTemplate
- IconButton
- ObjectFieldTemplate
- OptionalDataControlsTemplate
- Templates
- TitleField
- test/__snapshots__
- shadcn
- src
- ArrayFieldTemplate
- IconButton
- ObjectFieldTemplate
- OptionalDataControlsTemplate
- Templates
- TitleField
- components/ui
- test/__snapshots__
- snapshot-tests/src
- utils
- src
- schema
- test
- schema
- testUtils
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
145 files changed
+82563
-450
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
20 | 32 | | |
21 | 33 | | |
22 | 34 | | |
23 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
24 | 86 | | |
25 | 87 | | |
26 | 88 | | |
27 | 89 | | |
28 | 90 | | |
29 | 91 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
34 | 112 | | |
35 | 113 | | |
36 | 114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| |||
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
| 89 | + | |
87 | 90 | | |
88 | 91 | | |
89 | 92 | | |
| |||
99 | 102 | | |
100 | 103 | | |
101 | 104 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
106 | 109 | | |
107 | | - | |
108 | 110 | | |
109 | 111 | | |
110 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
22 | | - | |
| 21 | + | |
23 | 22 | | |
24 | 23 | | |
25 | | - | |
| 24 | + | |
26 | 25 | | |
27 | | - | |
| 26 | + | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
31 | | - | |
| 30 | + | |
| 31 | + | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| |||
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
47 | | - | |
48 | | - | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| |||
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
95 | | - | |
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
| 100 | + | |
99 | 101 | | |
100 | 102 | | |
101 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| |||
126 | 128 | | |
127 | 129 | | |
128 | 130 | | |
| 131 | + | |
129 | 132 | | |
130 | 133 | | |
131 | 134 | | |
| |||
140 | 143 | | |
141 | 144 | | |
142 | 145 | | |
| 146 | + | |
143 | 147 | | |
144 | 148 | | |
145 | 149 | | |
| |||
148 | 152 | | |
149 | 153 | | |
150 | 154 | | |
151 | | - | |
152 | 155 | | |
153 | 156 | | |
154 | 157 | | |
| |||
Lines changed: 47 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | | - | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
52 | 67 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| |||
0 commit comments