( state: JsonFormsState, ownProps: OwnPropsOfControl )
| 586 | * @returns {StatePropsOfControl} state props for a control |
| 587 | */ |
| 588 | export const mapStateToControlProps = ( |
| 589 | state: JsonFormsState, |
| 590 | ownProps: OwnPropsOfControl |
| 591 | ): StatePropsOfControl => { |
| 592 | const { uischema } = ownProps; |
| 593 | const rootData = getData(state); |
| 594 | const path = composeWithUi(uischema, ownProps.path); |
| 595 | const config = getConfig(state); |
| 596 | |
| 597 | const visible: boolean = |
| 598 | ownProps.visible === undefined || hasShowRule(uischema) |
| 599 | ? isVisible(uischema, rootData, ownProps.path, getAjv(state), config) |
| 600 | : ownProps.visible; |
| 601 | const controlElement = uischema as ControlElement; |
| 602 | const id = ownProps.id; |
| 603 | const rootSchema = getSchema(state); |
| 604 | const required = |
| 605 | controlElement.scope !== undefined && |
| 606 | isRequired(ownProps.schema, controlElement.scope, rootSchema); |
| 607 | const resolvedSchema = Resolve.schema( |
| 608 | ownProps.schema || rootSchema, |
| 609 | controlElement.scope, |
| 610 | rootSchema |
| 611 | ); |
| 612 | const errors = getErrorAt(path, resolvedSchema)(state); |
| 613 | |
| 614 | const description = |
| 615 | resolvedSchema !== undefined ? resolvedSchema.description : ''; |
| 616 | const data = Resolve.data(rootData, path); |
| 617 | const labelDesc = createLabelDescriptionFrom(uischema, resolvedSchema); |
| 618 | const label = labelDesc.show ? labelDesc.text : ''; |
| 619 | const enabled: boolean = isInherentlyEnabled( |
| 620 | state, |
| 621 | ownProps, |
| 622 | uischema, |
| 623 | resolvedSchema || rootSchema, |
| 624 | rootData, |
| 625 | config |
| 626 | ); |
| 627 | const readonly: boolean = isInherentlyReadonly( |
| 628 | state, |
| 629 | ownProps, |
| 630 | uischema, |
| 631 | resolvedSchema || rootSchema, |
| 632 | rootData, |
| 633 | config |
| 634 | ); |
| 635 | |
| 636 | const schema = resolvedSchema ?? rootSchema; |
| 637 | const t = getTranslator()(state); |
| 638 | const te = getErrorTranslator()(state); |
| 639 | const i18nKeyPrefix = getI18nKeyPrefix(schema, uischema, path); |
| 640 | const i18nLabel = t(getI18nKey(schema, uischema, path, 'label'), label, { |
| 641 | schema, |
| 642 | uischema, |
| 643 | path, |
| 644 | errors, |
| 645 | }); |
no test coverage detected
searching dependent graphs…