( state: JsonFormsState, ownProps: OwnPropsOfCell )
| 107 | * @returns {StatePropsOfCell} state props of a cell |
| 108 | */ |
| 109 | export const mapStateToCellProps = ( |
| 110 | state: JsonFormsState, |
| 111 | ownProps: OwnPropsOfCell |
| 112 | ): StatePropsOfCell => { |
| 113 | const { id, schema, path, uischema, renderers, cells } = ownProps; |
| 114 | const rootData = getData(state); |
| 115 | const config = getConfig(state); |
| 116 | const visible = |
| 117 | ownProps.visible !== undefined |
| 118 | ? ownProps.visible |
| 119 | : isVisible(uischema, rootData, undefined, getAjv(state), config); |
| 120 | |
| 121 | const rootSchema = getSchema(state); |
| 122 | |
| 123 | /* When determining the enabled state of cells we take a shortcut: At the |
| 124 | * moment it's only possible to configure enablement and disablement at the |
| 125 | * control level. Therefore the renderer using the cell, for example a |
| 126 | * table renderer, determines whether a cell is enabled and should hand |
| 127 | * over the prop themselves. If that prop was given, we prefer it over |
| 128 | * anything else to save evaluation effort (except for the global readonly |
| 129 | * flag when separateReadonlyFromDisabled is disabled). |
| 130 | * For example it would be quite expensive to evaluate the same ui schema |
| 131 | * rule again and again for each cell of a table. */ |
| 132 | let enabled; |
| 133 | if ( |
| 134 | !config?.separateReadonlyFromDisabled && |
| 135 | state.jsonforms.readonly === true |
| 136 | ) { |
| 137 | enabled = false; |
| 138 | } else if (typeof ownProps.enabled === 'boolean') { |
| 139 | enabled = ownProps.enabled; |
| 140 | } else { |
| 141 | enabled = isInherentlyEnabled( |
| 142 | state, |
| 143 | ownProps, |
| 144 | uischema, |
| 145 | schema || rootSchema, |
| 146 | rootData, |
| 147 | config |
| 148 | ); |
| 149 | } |
| 150 | |
| 151 | /* Similar to enabled, we take a shortcut for readonly state. The parent |
| 152 | * renderer can pass the readonly prop directly if it has already computed it, |
| 153 | * saving re-evaluation for each cell. */ |
| 154 | let readonly; |
| 155 | if (typeof ownProps.readonly === 'boolean') { |
| 156 | readonly = ownProps.readonly; |
| 157 | } else { |
| 158 | readonly = isInherentlyReadonly( |
| 159 | state, |
| 160 | ownProps, |
| 161 | uischema, |
| 162 | schema || rootSchema, |
| 163 | rootData, |
| 164 | config |
| 165 | ); |
| 166 | } |
no test coverage detected
searching dependent graphs…