• 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

97.78
/packages/material-renderers/src/complex/MaterialEnumArrayRenderer.tsx
1
import {
31✔
2
  and,
3
  ControlProps,
4
  DispatchPropsOfMultiEnumControl,
5
  hasType,
6
  isDescriptionHidden,
7
  JsonSchema,
8
  OwnPropsOfEnum,
9
  Paths,
10
  RankedTester,
11
  rankWith,
12
  resolveSchema,
13
  schemaMatches,
14
  schemaSubPathMatches,
15
  showAsRequired,
16
  uiTypeIs,
17
} from '@jsonforms/core';
18

19
import { withJsonFormsMultiEnumProps } from '@jsonforms/react';
31✔
20
import { MuiCheckbox } from '../mui-controls';
31✔
21
import {
31✔
22
  FormControl,
23
  FormControlLabel,
24
  FormGroup,
25
  FormHelperText,
26
  FormLabel,
27
} from '@mui/material';
28
import isEmpty from 'lodash/isEmpty';
31✔
29
import React from 'react';
31✔
30
import merge from 'lodash/merge';
31✔
31
import { useFocus } from '../util';
31✔
32

33
export const MaterialEnumArrayRenderer = ({
31✔
34
  config,
14✔
35
  id,
14✔
36
  schema,
14✔
37
  visible,
14✔
38
  errors,
14✔
39
  description,
14✔
40
  label,
14✔
41
  required,
14✔
42
  path,
14✔
43
  options,
14✔
44
  data,
14✔
45
  addItem,
14✔
46
  removeItem,
14✔
47
  handleChange: _handleChange,
14✔
48
  ...otherProps
14✔
49
}: ControlProps & OwnPropsOfEnum & DispatchPropsOfMultiEnumControl) => {
50
  const [focused, onFocus, onBlur] = useFocus();
14✔
51
  const isValid = errors.length === 0;
14✔
52
  const appliedUiSchemaOptions = merge({}, config, otherProps.uischema.options);
14✔
53
  const showDescription = !isDescriptionHidden(
14✔
54
    visible,
55
    description,
56
    focused,
57
    appliedUiSchemaOptions.showUnfocusedDescription
58
  );
59

60
  if (!visible) {
14!
NEW
61
    return null;
×
62
  }
63

64
  return (
14✔
65
    <FormControl
66
      component='fieldset'
67
      fullWidth={!appliedUiSchemaOptions.trim}
68
      onFocus={onFocus}
69
      onBlur={onBlur}
70
    >
71
      <FormLabel
72
        error={!isValid}
73
        component='legend'
74
        required={showAsRequired(
75
          required,
76
          appliedUiSchemaOptions.hideRequiredAsterisk
77
        )}
78
      >
79
        {label}
80
      </FormLabel>
81
      <FormGroup row>
82
        {options.map((option: any, index: number) => {
83
          const optionPath = Paths.compose(path, `${index}`);
35✔
84
          const checkboxValue = data?.includes(option.value)
35✔
85
            ? option.value
86
            : undefined;
87
          return (
35✔
88
            <FormControlLabel
89
              id={id + '-label-' + option.value}
90
              key={option.value}
91
              control={
92
                <MuiCheckbox
93
                  id={id + '-' + option.value}
94
                  key={'checkbox-' + option.value}
95
                  isValid={isEmpty(errors)}
96
                  path={optionPath}
97
                  handleChange={(_childPath, newValue) =>
98
                    newValue
2!
99
                      ? addItem(path, option.value)
100
                      : removeItem(path, option.value)
101
                  }
102
                  data={checkboxValue}
103
                  errors={errors}
104
                  schema={schema}
105
                  visible={visible}
106
                  {...otherProps}
107
                />
108
              }
109
              label={option.label}
110
            />
111
          );
112
        })}
113
      </FormGroup>
114
      <FormHelperText error={!isValid}>
115
        {!isValid ? errors : showDescription ? description : null}
24✔
116
      </FormHelperText>
117
    </FormControl>
118
  );
119
};
120

121
const hasOneOfItems = (schema: JsonSchema): boolean =>
31✔
122
  schema.oneOf !== undefined &&
25✔
123
  schema.oneOf.length > 0 &&
124
  (schema.oneOf as JsonSchema[]).every((entry: JsonSchema) => {
125
    return entry.const !== undefined;
24✔
126
  });
127

128
const hasEnumItems = (schema: JsonSchema): boolean =>
31✔
129
  schema.type === 'string' && schema.enum !== undefined;
13✔
130

131
export const materialEnumArrayRendererTester: RankedTester = rankWith(
31✔
132
  5,
133
  and(
134
    uiTypeIs('Control'),
135
    and(
136
      schemaMatches(
137
        (schema) =>
138
          hasType(schema, 'array') &&
231✔
139
          !Array.isArray(schema.items) &&
140
          schema.uniqueItems === true
141
      ),
142
      schemaSubPathMatches('items', (schema, rootSchema) => {
143
        const resolvedSchema = schema.$ref
25!
144
          ? resolveSchema(rootSchema, schema.$ref, rootSchema)
145
          : schema;
146
        return hasOneOfItems(resolvedSchema) || hasEnumItems(resolvedSchema);
25✔
147
      })
148
    )
149
  )
150
);
151

152
export default withJsonFormsMultiEnumProps(MaterialEnumArrayRenderer);
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