• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eclipsesource / jsonforms / 8687315178

15 Apr 2024 10:10AM UTC coverage: 84.383% (-0.007%) from 84.39%
8687315178

Pull #2315

github

web-flow
Merge e3a8a9f8f into b87f5b8e3
Pull Request #2315: Refactor(material): Replace Hidden component

10062 of 22976 branches covered (43.79%)

52 of 60 new or added lines in 21 files covered. (86.67%)

1 existing line in 1 file now uncovered.

17512 of 20753 relevant lines covered (84.38%)

27.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.7
/packages/material-renderers/src/controls/MaterialBooleanControl.tsx
1
/*
2
  The MIT License
3

4
  Copyright (c) 2017-2019 EclipseSource Munich
5
  https://github.com/eclipsesource/jsonforms
6

7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
  of this software and associated documentation files (the "Software"), to deal
9
  in the Software without restriction, including without limitation the rights
10
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  copies of the Software, and to permit persons to whom the Software is
12
  furnished to do so, subject to the following conditions:
13

14
  The above copyright notice and this permission notice shall be included in
15
  all copies or substantial portions of the Software.
16

17
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
  THE SOFTWARE.
24
*/
25
import isEmpty from 'lodash/isEmpty';
31✔
26
import merge from 'lodash/merge';
31✔
27
import React from 'react';
31✔
28
import {
31✔
29
  isBooleanControl,
30
  RankedTester,
31
  rankWith,
32
  ControlProps,
33
  isDescriptionHidden,
34
} from '@jsonforms/core';
35
import { withJsonFormsControlProps } from '@jsonforms/react';
31✔
36
import { FormControlLabel, FormHelperText, Tooltip } from '@mui/material';
31✔
37
import { MuiCheckbox } from '../mui-controls/MuiCheckbox';
31✔
38

39
export const MaterialBooleanControl = ({
31✔
40
  data,
21✔
41
  visible,
21✔
42
  label,
21✔
43
  id,
21✔
44
  enabled,
21✔
45
  uischema,
21✔
46
  schema,
21✔
47
  rootSchema,
21✔
48
  handleChange,
21✔
49
  errors,
21✔
50
  path,
21✔
51
  config,
21✔
52
  description,
21✔
53
}: ControlProps) => {
54
  const isValid = errors.length === 0;
21✔
55
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
21✔
56

57
  const showDescription = !isDescriptionHidden(
21✔
58
    visible,
59
    description,
60
    // Checkboxes do not receive focus until they are used, so
61
    // we cannot rely on focus as criteria for showing descriptions.
62
    // So we pass "false" to treat it as unfocused.
63
    false,
64
    appliedUiSchemaOptions.showUnfocusedDescription
65
  );
66

67
  const showTooltip =
68
    !showDescription &&
21✔
69
    !isDescriptionHidden(
70
      visible,
71
      description,
72
      // Tooltips have their own focus handlers, so we do not need to rely
73
      // on focus state here. So we pass 'true' to treat it as focused.
74
      true,
75
      // We also pass true here for showUnfocusedDescription since it should
76
      // render regardless of that setting.
77
      true
78
    );
79

80
  const firstFormHelperText = showDescription
21!
81
    ? description
82
    : !isValid
21!
83
    ? errors
84
    : null;
85
  const secondFormHelperText = showDescription && !isValid ? errors : null;
21!
86

87
  const descriptionIds = [];
21✔
88
  const tooltipId = `${id}-tip`;
21✔
89
  const helpId1 = `${id}-help1`;
21✔
90
  const helpId2 = `${id}-help2`;
21✔
91
  if (showTooltip) {
21!
92
    descriptionIds.push(tooltipId);
×
93
  }
94
  if (firstFormHelperText) {
21!
95
    descriptionIds.push(helpId1);
×
96
  }
97
  if (secondFormHelperText) {
21!
98
    descriptionIds.push(helpId2);
×
99
  }
100
  const ariaDescribedBy = descriptionIds.join(' ');
21✔
101

102
  if (!visible) {
21!
NEW
103
    return null;
×
104
  }
105

106
  return (
21✔
107
    <>
108
      <Tooltip id={tooltipId} title={showTooltip ? description : ''}>
21!
109
        <FormControlLabel
110
          label={label}
111
          id={id}
112
          control={
113
            <MuiCheckbox
114
              id={`${id}-input`}
115
              isValid={isEmpty(errors)}
116
              data={data}
117
              enabled={enabled}
118
              visible={visible}
119
              path={path}
120
              uischema={uischema}
121
              schema={schema}
122
              rootSchema={rootSchema}
123
              handleChange={handleChange}
124
              errors={errors}
125
              config={config}
126
              inputProps={{
127
                'aria-describedby': ariaDescribedBy,
128
              }}
129
            />
130
          }
131
        />
132
      </Tooltip>
133
      <FormHelperText id={helpId1} error={!isValid && !showDescription}>
21!
134
        {firstFormHelperText}
135
      </FormHelperText>
136
      <FormHelperText id={helpId2} error={!isValid}>
137
        {secondFormHelperText}
138
      </FormHelperText>
139
    </>
140
  );
141
};
142

143
export const materialBooleanControlTester: RankedTester = rankWith(
31✔
144
  2,
145
  isBooleanControl
146
);
147
export default withJsonFormsControlProps(MaterialBooleanControl);
31✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc