({
field, accessPath, dataDispatch, viewHelperProps, controlClassName,
})
| 23 | |
| 24 | |
| 25 | export default function FieldSetView({ |
| 26 | field, accessPath, dataDispatch, viewHelperProps, controlClassName, |
| 27 | }) { |
| 28 | const [, setKey] = useState(0); |
| 29 | const subscriberManager = useSchemaStateSubscriber(setKey); |
| 30 | const schema = field.schema; |
| 31 | const schemaState = useContext(SchemaStateContext); |
| 32 | const value = useFieldValue(accessPath, schemaState); |
| 33 | const options = useFieldSchema( |
| 34 | field, accessPath, value, viewHelperProps, schemaState, subscriberManager |
| 35 | ); |
| 36 | |
| 37 | const label = field.label; |
| 38 | |
| 39 | listenDepChanges( |
| 40 | accessPath, field, schemaState, () => subscriberManager.current?.signal() |
| 41 | ); |
| 42 | |
| 43 | const fieldGroups = useMemo( |
| 44 | () => createFieldControls({ |
| 45 | schema, schemaState, accessPath, viewHelperProps, dataDispatch |
| 46 | }), |
| 47 | [schema, schemaState, accessPath, viewHelperProps, dataDispatch] |
| 48 | ); |
| 49 | |
| 50 | // We won't show empty feldset too. |
| 51 | if(!options.visible || !fieldGroups.length) { |
| 52 | return <></>; |
| 53 | } |
| 54 | |
| 55 | return ( |
| 56 | <FieldSet title={label} className={controlClassName}> |
| 57 | {fieldGroups.map( |
| 58 | (fieldGroup, gidx) => ( |
| 59 | <React.Fragment key={`${fieldGroup.id}-${gidx}`}> |
| 60 | {fieldGroup.controls.map( |
| 61 | (item, idx) => <FieldControl |
| 62 | item={item} key={`${item.controlProps.id}-${idx}`} schemaId={schema._id} /> |
| 63 | )} |
| 64 | </React.Fragment> |
| 65 | ) |
| 66 | )} |
| 67 | </FieldSet> |
| 68 | ); |
| 69 | } |
| 70 | |
| 71 | FieldSetView.propTypes = { |
| 72 | viewHelperProps: PropTypes.object, |
nothing calls this directly
no test coverage detected