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

alkem-io / client-web / #8403

18 Jul 2024 01:52PM UTC coverage: 5.753%. First build
#8403

Pull #6620

travis-ci

Pull Request #6620: When uploading a document set the name from the file name

188 of 9955 branches covered (1.89%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 3 files covered. (0.0%)

1407 of 17772 relevant lines covered (7.92%)

0.19 hits per line

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

0.0
/src/core/ui/forms/FormikFileInput/FormikFileInput.tsx
1
import { useMemo } from 'react';
2
import { useField } from 'formik';
3
import FormikInputField, { FormikInputFieldProps } from '../FormikInputField/FormikInputField';
4
import FileUploadButton, { FileUploadEntityType, UploadedDocument } from '@/core/ui/upload/FileUpload/FileUpload';
5
import { useStorageConfigContext } from '@/domain/storage/StorageBucket/StorageConfigContext';
6

7
const DEFAULT_PROTOCOL = 'https';
×
8
const MATCH_PROTOCOL_REGEX = /^[a-z][a-z0-9+_-]{0,500}:\/\//i;
×
9

10
type FormikFileInputProps = FormikInputFieldProps & {
11
  entityID?: string;
12
  entityType?: FileUploadEntityType;
13
  defaultProtocol?: string;
14
  onChange?: (fileName: string) => void;
15
  onDocumentUploaded?: (document: UploadedDocument) => void;
16
  temporaryLocation?: boolean;
17
};
×
18

19
const FormikFileInput = ({
20
  name,
×
21
  entityID,
22
  defaultProtocol = DEFAULT_PROTOCOL,
23
  entityType,
24
  onChange,
25
  onDocumentUploaded,
×
26
  temporaryLocation = false,
27
  ...props
×
28
}: FormikFileInputProps) => {
29
  const [field, , helpers] = useField(name);
×
30

×
31
  const storageConfig = useStorageConfigContext();
×
32

33
  const updatedStorageConfig = useMemo(
×
34
    () => (storageConfig ? { ...storageConfig, temporaryLocation } : null),
×
35
    [storageConfig, temporaryLocation]
×
36
  );
×
37

38
  const checkProtocol = () => {
39
    helpers.setTouched(true);
40
    if (!defaultProtocol) {
41
      return;
×
42
    }
43
    if (field.value) {
44
      const currentValue = `${field.value}`; // make sure field.value is a string
45
      if (!currentValue.match(MATCH_PROTOCOL_REGEX)) {
46
        helpers.setValue(`${defaultProtocol}://${currentValue}`);
47
      }
×
48
    }
49
  };
50

NEW
51
  const onUpload = (fileId: string) => {
×
52
    helpers.setTouched(true);
53
    helpers.setValue(fileId);
54
  };
55

56
  return (
57
    <FormikInputField
58
      name={name}
59
      loading={!storageConfig}
60
      onBlur={checkProtocol}
61
      endAdornment={
62
        storageConfig &&
63
        storageConfig.canUpload &&
64
        updatedStorageConfig && (
65
          <FileUploadButton
66
            onUpload={onUpload}
67
            onDocumentUploaded={onDocumentUploaded}
68
            onChange={(fileName: string) => {
69
              helpers.setTouched(true);
70
              onChange?.(fileName);
71
            }}
72
            entityID={entityID}
73
            entityType={entityType}
74
            storageConfig={updatedStorageConfig}
75
          />
76
        )
77
      }
78
      {...props}
79
    />
80
  );
81
};
82

83
export default FormikFileInput;
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