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

alkem-io / client-web / #9731

03 Jan 2025 01:52PM UTC coverage: 5.781%. First build
#9731

Pull #7386

travis-ci

Pull Request #7386: Ability to select SpaceLevel2 on create VC

190 of 10868 branches covered (1.75%)

Branch coverage included in aggregate %.

1 of 44 new or added lines in 4 files covered. (2.27%)

1524 of 18780 relevant lines covered (8.12%)

0.18 hits per line

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

0.0
/src/core/ui/forms/FormikAutocomplete.tsx
1
import { Autocomplete, AutocompleteValue, TextField, TextFieldProps } from '@mui/material';
2
import { useField } from 'formik';
3
import { useMemo, ReactElement, SyntheticEvent } from 'react';
4
import { useValidationMessageTranslation } from '@/domain/shared/i18n/ValidationMessageTranslation';
5
import TranslationKey from '@/core/i18n/utils/TranslationKey';
6

7
export interface FormikSelectValue {
8
  id: string;
9
  name: string;
10
  icon?: ReactElement;
11
}
12

13
export type FormikAutocompleteProps = TextFieldProps & {
14
  name: string;
15
  values: readonly FormikSelectValue[];
16
  helpText?: string;
17
  disablePortal?: boolean;
18
  disabled?: boolean;
19
  onChange?: (value: FormikSelectValue | undefined) => void;
20
};
21

22
export const FormikAutocomplete = ({
×
23
  name,
24
  values,
25
  helpText,
26
  sx,
27
  disablePortal = true,
×
28
  disabled,
29
  onChange,
30
  ...textFieldProps
31
}: FormikAutocompleteProps) => {
32
  const tErr = useValidationMessageTranslation();
×
33

34
  const [field, meta, helpers] = useField(name);
×
35

NEW
36
  const isError = Boolean(meta.error) && meta.touched;
×
37

38
  const helperText = useMemo(() => {
×
39
    if (!isError) {
×
40
      return helpText;
×
41
    }
42

43
    return tErr(meta.error as TranslationKey, { field: name });
×
44
  }, [isError, meta.error, helpText, name, tErr]);
45

46
  const handleChange = (
×
47
    event: SyntheticEvent,
48
    value: AutocompleteValue<FormikSelectValue | undefined, false, false, false>
49
  ) => {
50
    helpers.setValue(value?.id);
×
51
    onChange?.(value ?? undefined);
×
52
  };
53

54
  return (
×
55
    <Autocomplete
56
      disablePortal={disablePortal}
57
      value={values.find(option => option.id === field.value) ?? null}
×
58
      options={values}
59
      onBlur={e => {
NEW
60
        helpers.setTouched(true);
×
NEW
61
        field.onBlur(e);
×
62
      }}
63
      onChange={handleChange}
64
      getOptionLabel={option => option?.name}
×
65
      sx={sx}
66
      disabled={disabled}
67
      renderInput={params => (
68
        <TextField
×
69
          variant="outlined"
70
          {...textFieldProps}
71
          {...params}
72
          InputLabelProps={{ shrink: true }}
73
          helperText={Boolean(helperText) ? <>{helperText}</> : null}
74
          error={isError}
75
        />
76
      )}
77
    />
78
  );
79
};
80

81
export default FormikAutocomplete;
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

© 2025 Coveralls, Inc