@aehrc/smart-forms-renderer 0.13.2 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/FormComponents/AttachmentItem/AttachmentField.d.ts +13 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentField.js +39 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentField.js.map +1 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentFieldWrapper.d.ts +14 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentFieldWrapper.js +34 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentFieldWrapper.js.map +1 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentFileCollector.d.ts +8 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentFileCollector.js +61 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentFileCollector.js.map +1 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentFileDropBox.d.ts +11 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentFileDropBox.js +49 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentFileDropBox.js.map +1 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentFileDropBox.styles.d.ts +7 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentFileDropBox.styles.js +30 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentFileDropBox.styles.js.map +1 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentItem.d.ts +14 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentItem.js +86 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentItem.js.map +1 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentUrlField.d.ts +10 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentUrlField.js +39 -0
- package/lib/components/FormComponents/AttachmentItem/AttachmentUrlField.js.map +1 -0
- package/lib/components/FormComponents/ChoiceItems/ChoiceAutocompleteField.d.ts +1 -1
- package/lib/components/FormComponents/ChoiceItems/ChoiceAutocompleteField.js +2 -2
- package/lib/components/FormComponents/ChoiceItems/ChoiceAutocompleteField.js.map +1 -1
- package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetFields.d.ts +2 -1
- package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetFields.js +6 -3
- package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetFields.js.map +1 -1
- package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetItem.js +3 -3
- package/lib/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetItem.js.map +1 -1
- package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetFields.d.ts +2 -1
- package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetFields.js +6 -3
- package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetFields.js.map +1 -1
- package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetItem.js +3 -3
- package/lib/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetItem.js.map +1 -1
- package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionFields.js +2 -1
- package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionFields.js.map +1 -1
- package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerValueSetFields.d.ts +2 -1
- package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerValueSetFields.js +8 -5
- package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerValueSetFields.js.map +1 -1
- package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerValueSetItem.js +3 -3
- package/lib/components/FormComponents/ChoiceItems/ChoiceSelectAnswerValueSetItem.js.map +1 -1
- package/lib/components/FormComponents/DateItem/DateField.js +2 -1
- package/lib/components/FormComponents/DateItem/DateField.js.map +1 -1
- package/lib/components/FormComponents/DateTimeItem/DateTimeField.js +2 -1
- package/lib/components/FormComponents/DateTimeItem/DateTimeField.js.map +1 -1
- package/lib/components/FormComponents/GridGroup/GridRow.js +1 -1
- package/lib/components/FormComponents/GridGroup/GridRow.js.map +1 -1
- package/lib/components/FormComponents/GroupItem/GroupItemSwitcher.js +2 -2
- package/lib/components/FormComponents/GroupItem/GroupItemSwitcher.js.map +1 -1
- package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteField.js +2 -2
- package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteField.js.map +1 -1
- package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerOptionField.js +2 -2
- package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerOptionField.js.map +1 -1
- package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerValueSetField.d.ts +2 -1
- package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerValueSetField.js +7 -4
- package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerValueSetField.js.map +1 -1
- package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerValueSetItem.js +3 -3
- package/lib/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerValueSetItem.js.map +1 -1
- package/lib/components/FormComponents/RepeatGroup/AddItemButton.js +2 -1
- package/lib/components/FormComponents/RepeatGroup/AddItemButton.js.map +1 -1
- package/lib/components/FormComponents/RepeatItem/AddItemButton.js +2 -1
- package/lib/components/FormComponents/RepeatItem/AddItemButton.js.map +1 -1
- package/lib/components/FormComponents/RepeatItem/RepeatField.d.ts +1 -0
- package/lib/components/FormComponents/RepeatItem/RepeatField.js +2 -2
- package/lib/components/FormComponents/RepeatItem/RepeatField.js.map +1 -1
- package/lib/components/FormComponents/RepeatItem/RepeatItem.d.ts +1 -0
- package/lib/components/FormComponents/RepeatItem/RepeatItem.js +3 -3
- package/lib/components/FormComponents/RepeatItem/RepeatItem.js.map +1 -1
- package/lib/components/FormComponents/SingleItem/SingleItem.d.ts +1 -0
- package/lib/components/FormComponents/SingleItem/SingleItem.js +15 -3
- package/lib/components/FormComponents/SingleItem/SingleItem.js.map +1 -1
- package/lib/components/FormComponents/SingleItem/SingleItemSwitcher.js +28 -16
- package/lib/components/FormComponents/SingleItem/SingleItemSwitcher.js.map +1 -1
- package/lib/components/FormComponents/SingleItem/SingleNestedItems.d.ts +10 -0
- package/lib/components/FormComponents/SingleItem/SingleNestedItems.js +52 -0
- package/lib/components/FormComponents/SingleItem/SingleNestedItems.js.map +1 -0
- package/lib/components/FormComponents/SliderItem/SliderField.js +2 -1
- package/lib/components/FormComponents/SliderItem/SliderField.js.map +1 -1
- package/lib/components/FormComponents/Tables/GroupTableRowCells.js +1 -1
- package/lib/components/FormComponents/Tables/GroupTableRowCells.js.map +1 -1
- package/lib/components/FormComponents/Textfield.styles.d.ts +1 -0
- package/lib/components/FormComponents/Textfield.styles.js +2 -1
- package/lib/components/FormComponents/Textfield.styles.js.map +1 -1
- package/lib/components/FormComponents/TimeItem/TimeField.js +2 -1
- package/lib/components/FormComponents/TimeItem/TimeField.js.map +1 -1
- package/lib/components/Renderer/FormTopLevelItem.js +1 -1
- package/lib/components/Renderer/FormTopLevelItem.js.map +1 -1
- package/lib/hooks/UseFileDrop.d.ts +10 -0
- package/lib/hooks/UseFileDrop.js +40 -0
- package/lib/hooks/UseFileDrop.js.map +1 -0
- package/lib/hooks/useAttachmentUrlValidation.d.ts +2 -0
- package/lib/hooks/useAttachmentUrlValidation.js +27 -0
- package/lib/hooks/useAttachmentUrlValidation.js.map +1 -0
- package/lib/hooks/useValueSetCodings.d.ts +5 -1
- package/lib/hooks/useValueSetCodings.js +1 -1
- package/lib/hooks/useValueSetCodings.js.map +1 -1
- package/lib/utils/fileUtils.d.ts +3 -0
- package/lib/utils/fileUtils.js +64 -0
- package/lib/utils/fileUtils.js.map +1 -0
- package/lib/utils/validateQuestionnaire.d.ts +3 -5
- package/lib/utils/validateQuestionnaire.js +8 -5
- package/lib/utils/validateQuestionnaire.js.map +1 -1
- package/package.json +3 -1
- package/src/components/FormComponents/AttachmentItem/AttachmentField.tsx +96 -0
- package/src/components/FormComponents/AttachmentItem/AttachmentFieldWrapper.tsx +87 -0
- package/src/components/FormComponents/AttachmentItem/AttachmentFileCollector.tsx +101 -0
- package/src/components/FormComponents/AttachmentItem/AttachmentFileDropBox.styles.ts +31 -0
- package/src/components/FormComponents/AttachmentItem/AttachmentFileDropBox.tsx +66 -0
- package/src/components/FormComponents/AttachmentItem/AttachmentItem.tsx +123 -0
- package/src/components/FormComponents/AttachmentItem/AttachmentUrlField.tsx +78 -0
- package/src/components/FormComponents/ChoiceItems/ChoiceAutocompleteField.tsx +3 -3
- package/src/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetFields.tsx +6 -4
- package/src/components/FormComponents/ChoiceItems/ChoiceCheckboxAnswerValueSetItem.tsx +3 -3
- package/src/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetFields.tsx +7 -4
- package/src/components/FormComponents/ChoiceItems/ChoiceRadioAnswerValueSetItem.tsx +3 -3
- package/src/components/FormComponents/ChoiceItems/ChoiceSelectAnswerOptionFields.tsx +2 -1
- package/src/components/FormComponents/ChoiceItems/ChoiceSelectAnswerValueSetFields.tsx +9 -6
- package/src/components/FormComponents/ChoiceItems/ChoiceSelectAnswerValueSetItem.tsx +3 -3
- package/src/components/FormComponents/DateItem/DateField.tsx +2 -1
- package/src/components/FormComponents/DateTimeItem/DateTimeField.tsx +2 -1
- package/src/components/FormComponents/GridGroup/GridRow.tsx +1 -0
- package/src/components/FormComponents/GroupItem/GroupItemSwitcher.tsx +2 -0
- package/src/components/FormComponents/OpenChoiceItems/OpenChoiceAutocompleteField.tsx +2 -2
- package/src/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerOptionField.tsx +2 -2
- package/src/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerValueSetField.tsx +9 -6
- package/src/components/FormComponents/OpenChoiceItems/OpenChoiceSelectAnswerValueSetItem.tsx +3 -3
- package/src/components/FormComponents/RepeatGroup/AddItemButton.tsx +1 -1
- package/src/components/FormComponents/RepeatItem/AddItemButton.tsx +1 -1
- package/src/components/FormComponents/RepeatItem/RepeatField.tsx +3 -0
- package/src/components/FormComponents/RepeatItem/RepeatItem.tsx +5 -1
- package/src/components/FormComponents/SingleItem/SingleItem.tsx +47 -12
- package/src/components/FormComponents/SingleItem/SingleItemSwitcher.tsx +67 -31
- package/src/components/FormComponents/SingleItem/SingleNestedItems.tsx +91 -0
- package/src/components/FormComponents/SliderItem/SliderField.tsx +2 -1
- package/src/components/FormComponents/Tables/GroupTableRowCells.tsx +1 -0
- package/src/components/FormComponents/Textfield.styles.ts +3 -1
- package/src/components/FormComponents/TimeItem/TimeField.tsx +2 -1
- package/src/components/Renderer/FormTopLevelItem.tsx +1 -0
- package/src/hooks/UseFileDrop.ts +53 -0
- package/src/hooks/useAttachmentUrlValidation.ts +27 -0
- package/src/hooks/useValueSetCodings.ts +10 -2
- package/src/utils/fileUtils.ts +66 -0
- package/src/utils/validateQuestionnaire.ts +17 -13
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { QuestionnaireResponse } from 'fhir/r4';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { RegexValidation } from '../interfaces/regex.interface';
|
|
1
|
+
import type { Questionnaire, QuestionnaireResponse } from 'fhir/r4';
|
|
2
|
+
import type { EnableWhenExpression, EnableWhenItems } from '../interfaces/enableWhen.interface';
|
|
3
|
+
import type { RegexValidation } from '../interfaces/regex.interface';
|
|
5
4
|
export type InvalidType = 'regex' | 'minLength' | 'maxLength' | 'required';
|
|
6
5
|
interface ValidateQuestionnaireParams {
|
|
7
6
|
questionnaire: Questionnaire;
|
|
@@ -14,7 +13,6 @@ interface ValidateQuestionnaireParams {
|
|
|
14
13
|
/**
|
|
15
14
|
* Recursively go through the questionnaireResponse and check for un-filled required qItems
|
|
16
15
|
* At the moment item.required for group items are not checked
|
|
17
|
-
* FIXME will eventually be renamed to validate questionnaire
|
|
18
16
|
*
|
|
19
17
|
* @author Sean Fong
|
|
20
18
|
*/
|
|
@@ -21,7 +21,6 @@ import { structuredDataCapture } from 'fhir-sdc-helpers';
|
|
|
21
21
|
/**
|
|
22
22
|
* Recursively go through the questionnaireResponse and check for un-filled required qItems
|
|
23
23
|
* At the moment item.required for group items are not checked
|
|
24
|
-
* FIXME will eventually be renamed to validate questionnaire
|
|
25
24
|
*
|
|
26
25
|
* @author Sean Fong
|
|
27
26
|
*/
|
|
@@ -72,7 +71,7 @@ function validateItemRecursive(params) {
|
|
|
72
71
|
}
|
|
73
72
|
// FIXME repeat groups not working
|
|
74
73
|
if (qItem.type === 'group' && qItem.repeats) {
|
|
75
|
-
return
|
|
74
|
+
return;
|
|
76
75
|
}
|
|
77
76
|
const childQItems = qItem.item;
|
|
78
77
|
if (childQItems && childQItems.length > 0) {
|
|
@@ -148,9 +147,13 @@ function validateSingleItem(qItem, qrItem, invalidItems) {
|
|
|
148
147
|
}
|
|
149
148
|
return invalidItems;
|
|
150
149
|
}
|
|
151
|
-
function validateRepeatGroup(
|
|
152
|
-
|
|
153
|
-
|
|
150
|
+
// function validateRepeatGroup(
|
|
151
|
+
// qItem: QuestionnaireItem,
|
|
152
|
+
// qrItems: QuestionnaireResponseItem,
|
|
153
|
+
// invalidLinkIds: Record<string, InvalidType>
|
|
154
|
+
// ) {
|
|
155
|
+
// return;
|
|
156
|
+
// }
|
|
154
157
|
function getInputInString(answer) {
|
|
155
158
|
if (answer.valueString) {
|
|
156
159
|
return answer.valueString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateQuestionnaire.js","sourceRoot":"","sources":["../../src/utils/validateQuestionnaire.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;
|
|
1
|
+
{"version":3,"file":"validateQuestionnaire.js","sourceRoot":"","sources":["../../src/utils/validateQuestionnaire.ts"],"names":[],"mappings":"AAAA;;;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b,eAAuC,EACvC,SAAwB,EACxB,SAAwB;IAExB,IAAI,KAAK,EAAE;QACT,IAAI,eAAe,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YAC9D,OAAO,OAAO,CAAC;SAChB;QAED,IAAI,SAAS,IAAI,KAAK,CAAC,MAAM,GAAG,SAAS,EAAE;YACzC,OAAO,WAAW,CAAC;SACpB;QAED,IAAI,SAAS,IAAI,KAAK,CAAC,MAAM,GAAG,SAAS,EAAE;YACzC,OAAO,WAAW,CAAC;SACpB;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aehrc/smart-forms-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "FHIR Structured Data Captured (SDC) rendering engine for Smart Forms",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -35,6 +35,8 @@
|
|
|
35
35
|
"lodash.debounce": "^4.0.8",
|
|
36
36
|
"nanoid": "^5.0.1",
|
|
37
37
|
"react-beautiful-dnd": "^13.1.1",
|
|
38
|
+
"react-dnd": "^16.0.1",
|
|
39
|
+
"react-dnd-html5-backend": "^16.0.1",
|
|
38
40
|
"react-markdown": "^8.0.7",
|
|
39
41
|
"zustand": "^4.4.6"
|
|
40
42
|
},
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import React from 'react';
|
|
19
|
+
import type { PropsWithIsTabledAttribute } from '../../../interfaces/renderProps.interface';
|
|
20
|
+
import { StandardTextField } from '../Textfield.styles';
|
|
21
|
+
import AttachmentFileCollector from './AttachmentFileCollector';
|
|
22
|
+
import Typography from '@mui/material/Typography';
|
|
23
|
+
import Box from '@mui/material/Box';
|
|
24
|
+
import Stack from '@mui/material/Stack';
|
|
25
|
+
import type { AttachmentValues } from './AttachmentItem';
|
|
26
|
+
import AttachmentUrlField from './AttachmentUrlField';
|
|
27
|
+
|
|
28
|
+
interface AttachmentFieldProps extends PropsWithIsTabledAttribute {
|
|
29
|
+
linkId: string;
|
|
30
|
+
attachmentValues: AttachmentValues;
|
|
31
|
+
readOnly: boolean;
|
|
32
|
+
onUploadFile: (file: File | null) => void;
|
|
33
|
+
onUrlChange: (url: string) => void;
|
|
34
|
+
onFileNameChange: (fileName: string) => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function AttachmentField(props: AttachmentFieldProps) {
|
|
38
|
+
const {
|
|
39
|
+
linkId,
|
|
40
|
+
attachmentValues,
|
|
41
|
+
readOnly,
|
|
42
|
+
isTabled,
|
|
43
|
+
onUploadFile,
|
|
44
|
+
onUrlChange,
|
|
45
|
+
onFileNameChange
|
|
46
|
+
} = props;
|
|
47
|
+
|
|
48
|
+
const { uploadedFile, url, fileName } = attachmentValues;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<>
|
|
52
|
+
<Stack rowGap={1}>
|
|
53
|
+
<Typography variant="subtitle2">
|
|
54
|
+
An attachment must either have a file or a URL, or both.
|
|
55
|
+
</Typography>
|
|
56
|
+
<Box>
|
|
57
|
+
<AttachmentFileCollector
|
|
58
|
+
uploadedFile={uploadedFile}
|
|
59
|
+
isTabled={isTabled}
|
|
60
|
+
onUploadFile={onUploadFile}
|
|
61
|
+
/>
|
|
62
|
+
</Box>
|
|
63
|
+
|
|
64
|
+
<AttachmentUrlField
|
|
65
|
+
linkId={linkId}
|
|
66
|
+
url={url}
|
|
67
|
+
readOnly={readOnly}
|
|
68
|
+
isTabled={isTabled}
|
|
69
|
+
onUrlChange={onUrlChange}
|
|
70
|
+
/>
|
|
71
|
+
|
|
72
|
+
<Box>
|
|
73
|
+
<Typography variant="body2">File name (optional)</Typography>
|
|
74
|
+
<StandardTextField
|
|
75
|
+
fullWidth
|
|
76
|
+
isTabled={isTabled}
|
|
77
|
+
id={linkId}
|
|
78
|
+
value={fileName}
|
|
79
|
+
onChange={(event) => onFileNameChange(event.target.value)}
|
|
80
|
+
disabled={readOnly}
|
|
81
|
+
size="small"
|
|
82
|
+
data-test="q-item-attachment-field"
|
|
83
|
+
/>
|
|
84
|
+
</Box>
|
|
85
|
+
|
|
86
|
+
{uploadedFile && url ? (
|
|
87
|
+
<Typography variant="subtitle2">
|
|
88
|
+
Ensure that the attached file and URL has the same content.
|
|
89
|
+
</Typography>
|
|
90
|
+
) : null}
|
|
91
|
+
</Stack>
|
|
92
|
+
</>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default AttachmentField;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// import { HTML5Backend } from 'react-dnd-html5-backend';
|
|
19
|
+
//
|
|
20
|
+
// <DndProvider backend={HTML5Backend}>
|
|
21
|
+
|
|
22
|
+
import React from 'react';
|
|
23
|
+
import AttachmentField from './AttachmentField';
|
|
24
|
+
import { FullWidthFormComponentBox } from '../../Box.styles';
|
|
25
|
+
import ItemFieldGrid from '../ItemParts/ItemFieldGrid';
|
|
26
|
+
import type {
|
|
27
|
+
PropsWithIsRepeatedAttribute,
|
|
28
|
+
PropsWithIsTabledAttribute
|
|
29
|
+
} from '../../../interfaces/renderProps.interface';
|
|
30
|
+
import type { QuestionnaireItem } from 'fhir/r4';
|
|
31
|
+
import type { AttachmentValues } from './AttachmentItem';
|
|
32
|
+
|
|
33
|
+
interface AttachmentFieldWrapperProps
|
|
34
|
+
extends PropsWithIsRepeatedAttribute,
|
|
35
|
+
PropsWithIsTabledAttribute {
|
|
36
|
+
qItem: QuestionnaireItem;
|
|
37
|
+
attachmentValues: AttachmentValues;
|
|
38
|
+
readOnly: boolean;
|
|
39
|
+
onUploadFile: (file: File | null) => void;
|
|
40
|
+
onUrlChange: (url: string) => void;
|
|
41
|
+
onFileNameChange: (fileName: string) => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function AttachmentFieldWrapper(props: AttachmentFieldWrapperProps) {
|
|
45
|
+
const {
|
|
46
|
+
qItem,
|
|
47
|
+
attachmentValues,
|
|
48
|
+
readOnly,
|
|
49
|
+
isRepeated,
|
|
50
|
+
isTabled,
|
|
51
|
+
onUploadFile,
|
|
52
|
+
onUrlChange,
|
|
53
|
+
onFileNameChange
|
|
54
|
+
} = props;
|
|
55
|
+
|
|
56
|
+
if (isRepeated) {
|
|
57
|
+
return (
|
|
58
|
+
<AttachmentField
|
|
59
|
+
linkId={qItem.linkId}
|
|
60
|
+
attachmentValues={attachmentValues}
|
|
61
|
+
readOnly={readOnly}
|
|
62
|
+
isTabled={isTabled}
|
|
63
|
+
onUploadFile={onUploadFile}
|
|
64
|
+
onUrlChange={onUrlChange}
|
|
65
|
+
onFileNameChange={onFileNameChange}
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<FullWidthFormComponentBox data-test="q-item-attachment-box">
|
|
72
|
+
<ItemFieldGrid qItem={qItem} readOnly={readOnly}>
|
|
73
|
+
<AttachmentField
|
|
74
|
+
linkId={qItem.linkId}
|
|
75
|
+
attachmentValues={attachmentValues}
|
|
76
|
+
readOnly={readOnly}
|
|
77
|
+
isTabled={isTabled}
|
|
78
|
+
onUploadFile={onUploadFile}
|
|
79
|
+
onUrlChange={onUrlChange}
|
|
80
|
+
onFileNameChange={onFileNameChange}
|
|
81
|
+
/>
|
|
82
|
+
</ItemFieldGrid>
|
|
83
|
+
</FullWidthFormComponentBox>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export default AttachmentFieldWrapper;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { ChangeEvent } from 'react';
|
|
19
|
+
import React, { memo, useCallback } from 'react';
|
|
20
|
+
import { Box, IconButton, Stack, Tooltip } from '@mui/material';
|
|
21
|
+
import { useSnackbar } from 'notistack';
|
|
22
|
+
import AttachmentFileDropBox from './AttachmentFileDropBox';
|
|
23
|
+
import Iconify from '../../Iconify/Iconify';
|
|
24
|
+
import type { PropsWithIsTabledAttribute } from '../../../interfaces/renderProps.interface';
|
|
25
|
+
|
|
26
|
+
interface AttachmentFileCollectorProps extends PropsWithIsTabledAttribute {
|
|
27
|
+
uploadedFile: File | null;
|
|
28
|
+
onUploadFile: (file: File | null) => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const AttachmentFileCollector = memo(function AttachmentFileCollector(
|
|
32
|
+
props: AttachmentFileCollectorProps
|
|
33
|
+
) {
|
|
34
|
+
const { uploadedFile, isTabled, onUploadFile } = props;
|
|
35
|
+
|
|
36
|
+
const { enqueueSnackbar } = useSnackbar();
|
|
37
|
+
|
|
38
|
+
const handleFileDrop = useCallback(
|
|
39
|
+
(item: { files: any[] }) => {
|
|
40
|
+
if (item) {
|
|
41
|
+
const files = item.files;
|
|
42
|
+
|
|
43
|
+
if (files.length > 1) {
|
|
44
|
+
enqueueSnackbar('Only one file allowed', {
|
|
45
|
+
variant: 'warning',
|
|
46
|
+
preventDuplicate: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (files[0] instanceof File) {
|
|
51
|
+
const file = files[0];
|
|
52
|
+
|
|
53
|
+
onUploadFile(file);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
[onUploadFile, enqueueSnackbar]
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
function handleAttachFile(event: ChangeEvent<HTMLInputElement>) {
|
|
61
|
+
const file = event.target.files?.[0];
|
|
62
|
+
|
|
63
|
+
if (file instanceof File) {
|
|
64
|
+
onUploadFile(file);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<AttachmentFileDropBox
|
|
71
|
+
onDrop={handleFileDrop}
|
|
72
|
+
file={uploadedFile}
|
|
73
|
+
errorMessage={''}
|
|
74
|
+
isTabled={isTabled}
|
|
75
|
+
/>
|
|
76
|
+
<Stack direction="row" justifyContent="space-between" pt={0.5}>
|
|
77
|
+
<Box>
|
|
78
|
+
<Tooltip title="Attach file">
|
|
79
|
+
<IconButton component="label" size="small">
|
|
80
|
+
<Iconify icon="fluent:attach-24-regular" />
|
|
81
|
+
<input type="file" hidden onChange={handleAttachFile} />
|
|
82
|
+
</IconButton>
|
|
83
|
+
</Tooltip>
|
|
84
|
+
<Tooltip title="Remove file">
|
|
85
|
+
<span>
|
|
86
|
+
<IconButton
|
|
87
|
+
disabled={!uploadedFile}
|
|
88
|
+
color="error"
|
|
89
|
+
size="small"
|
|
90
|
+
onClick={() => onUploadFile(null)}>
|
|
91
|
+
<Iconify icon="ant-design:delete" />
|
|
92
|
+
</IconButton>
|
|
93
|
+
</span>
|
|
94
|
+
</Tooltip>
|
|
95
|
+
</Box>
|
|
96
|
+
</Stack>
|
|
97
|
+
</>
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
export default AttachmentFileCollector;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { styled } from '@mui/material/styles';
|
|
19
|
+
import { Box } from '@mui/material';
|
|
20
|
+
import { TEXT_FIELD_WIDTH } from '../Textfield.styles';
|
|
21
|
+
|
|
22
|
+
export const AttachmentFileDropBoxWrapper = styled(Box, {
|
|
23
|
+
shouldForwardProp: (prop) => prop !== 'isActive' && prop !== 'isTabled'
|
|
24
|
+
})<{ isActive: boolean; isTabled: boolean }>(({ theme, isActive, isTabled }) => ({
|
|
25
|
+
backgroundColor: theme.palette.background.paper,
|
|
26
|
+
border: '2px dashed',
|
|
27
|
+
borderColor: isActive ? theme.palette.secondary.main : theme.palette.primary.main,
|
|
28
|
+
borderRadius: '4px',
|
|
29
|
+
maxWidth: !isTabled ? TEXT_FIELD_WIDTH : 3000,
|
|
30
|
+
minWidth: 160
|
|
31
|
+
}));
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { Box, Typography } from '@mui/material';
|
|
19
|
+
import useFileDrop from '../../../hooks/UseFileDrop';
|
|
20
|
+
import { AttachmentFileDropBoxWrapper } from './AttachmentFileDropBox.styles';
|
|
21
|
+
import React from 'react';
|
|
22
|
+
import type { PropsWithIsTabledAttribute } from '../../../interfaces/renderProps.interface';
|
|
23
|
+
import { getFileSize } from '../../../utils/fileUtils';
|
|
24
|
+
|
|
25
|
+
export interface AttachmentFileDropBoxProps extends PropsWithIsTabledAttribute {
|
|
26
|
+
file: File | null;
|
|
27
|
+
onDrop: (item: { files: any[] }) => void;
|
|
28
|
+
errorMessage: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function AttachmentFileDropBox(props: AttachmentFileDropBoxProps) {
|
|
32
|
+
const { file, onDrop, errorMessage, isTabled } = props;
|
|
33
|
+
|
|
34
|
+
const { canDrop, isOver, dropTarget } = useFileDrop(onDrop);
|
|
35
|
+
|
|
36
|
+
const isActive = canDrop && isOver;
|
|
37
|
+
|
|
38
|
+
let boxMessage = 'No file selected';
|
|
39
|
+
if (isActive) {
|
|
40
|
+
boxMessage = 'Release to drop file';
|
|
41
|
+
} else if (errorMessage) {
|
|
42
|
+
boxMessage = errorMessage;
|
|
43
|
+
} else if (file) {
|
|
44
|
+
boxMessage = file.name;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<AttachmentFileDropBoxWrapper
|
|
49
|
+
ref={dropTarget}
|
|
50
|
+
display="flex"
|
|
51
|
+
isActive={isActive}
|
|
52
|
+
isTabled={isTabled}>
|
|
53
|
+
<Box p={1.5}>
|
|
54
|
+
<Typography>{boxMessage}</Typography>
|
|
55
|
+
{file ? (
|
|
56
|
+
<Box pt={1}>
|
|
57
|
+
<Typography fontSize={10}>Size: {getFileSize(file.size.toString() ?? '0')}</Typography>
|
|
58
|
+
<Typography fontSize={10}>Type: {file.type}</Typography>
|
|
59
|
+
</Box>
|
|
60
|
+
) : null}
|
|
61
|
+
</Box>
|
|
62
|
+
</AttachmentFileDropBoxWrapper>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default AttachmentFileDropBox;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import React, { useCallback, useState } from 'react';
|
|
19
|
+
import type {
|
|
20
|
+
PropsWithIsRepeatedAttribute,
|
|
21
|
+
PropsWithIsTabledAttribute,
|
|
22
|
+
PropsWithParentIsReadOnlyAttribute,
|
|
23
|
+
PropsWithQrItemChangeHandler
|
|
24
|
+
} from '../../../interfaces/renderProps.interface';
|
|
25
|
+
import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';
|
|
26
|
+
import debounce from 'lodash.debounce';
|
|
27
|
+
import { createEmptyQrItem } from '../../../utils/qrItem';
|
|
28
|
+
import { DEBOUNCE_DURATION } from '../../../utils/debounce';
|
|
29
|
+
import useStringInput from '../../../hooks/useStringInput';
|
|
30
|
+
import useReadOnly from '../../../hooks/useReadOnly';
|
|
31
|
+
import AttachmentFieldWrapper from './AttachmentFieldWrapper';
|
|
32
|
+
import { HTML5Backend } from 'react-dnd-html5-backend';
|
|
33
|
+
import { DndProvider } from 'react-dnd';
|
|
34
|
+
import { createAttachmentAnswer } from '../../../utils/fileUtils';
|
|
35
|
+
|
|
36
|
+
export interface AttachmentValues {
|
|
37
|
+
uploadedFile: File | null;
|
|
38
|
+
url: string;
|
|
39
|
+
fileName: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface AttachmentItemProps
|
|
43
|
+
extends PropsWithQrItemChangeHandler,
|
|
44
|
+
PropsWithIsRepeatedAttribute,
|
|
45
|
+
PropsWithIsTabledAttribute,
|
|
46
|
+
PropsWithParentIsReadOnlyAttribute {
|
|
47
|
+
qItem: QuestionnaireItem;
|
|
48
|
+
qrItem: QuestionnaireResponseItem | null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function AttachmentItem(props: AttachmentItemProps) {
|
|
52
|
+
const { qItem, qrItem, isRepeated, isTabled, parentIsReadOnly, onQrItemChange } = props;
|
|
53
|
+
|
|
54
|
+
const readOnly = useReadOnly(qItem, parentIsReadOnly);
|
|
55
|
+
|
|
56
|
+
// Init input value
|
|
57
|
+
let valueString = '';
|
|
58
|
+
if (qrItem?.answer && qrItem?.answer[0].valueString) {
|
|
59
|
+
valueString = qrItem.answer[0].valueString;
|
|
60
|
+
}
|
|
61
|
+
const [uploadedFile, setUploadedFile] = useState<File | null>(null);
|
|
62
|
+
const [url, setUrl] = useStringInput(valueString);
|
|
63
|
+
const [fileName, setFileName] = useStringInput(valueString);
|
|
64
|
+
|
|
65
|
+
// Event handlers
|
|
66
|
+
async function handleUploadFile(newUploadedFile: File | null) {
|
|
67
|
+
setUploadedFile(newUploadedFile);
|
|
68
|
+
|
|
69
|
+
const attachment = await createAttachmentAnswer(newUploadedFile, url, fileName);
|
|
70
|
+
if (attachment) {
|
|
71
|
+
onQrItemChange({
|
|
72
|
+
...createEmptyQrItem(qItem),
|
|
73
|
+
answer: [{ valueAttachment: attachment }]
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
onQrItemChange(createEmptyQrItem(qItem));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function handleUrlChange(newUrl: string) {
|
|
81
|
+
setUrl(newUrl);
|
|
82
|
+
await updateQrItemWithDebounce(uploadedFile, newUrl, fileName);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function handleFileNameChange(newFileName: string) {
|
|
86
|
+
setFileName(newFileName);
|
|
87
|
+
await updateQrItemWithDebounce(uploadedFile, url, newFileName);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
91
|
+
const updateQrItemWithDebounce = useCallback(
|
|
92
|
+
debounce(async (file: File | null, url: string, fileName: string) => {
|
|
93
|
+
const attachment = await createAttachmentAnswer(file, url, fileName);
|
|
94
|
+
|
|
95
|
+
if (attachment) {
|
|
96
|
+
onQrItemChange({
|
|
97
|
+
...createEmptyQrItem(qItem),
|
|
98
|
+
answer: [{ valueAttachment: attachment }]
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
onQrItemChange(createEmptyQrItem(qItem));
|
|
102
|
+
}
|
|
103
|
+
}, DEBOUNCE_DURATION),
|
|
104
|
+
[onQrItemChange, qItem]
|
|
105
|
+
); // Dependencies are tested, debounce is causing eslint to not recognise dependencies
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<DndProvider backend={HTML5Backend} context={window}>
|
|
109
|
+
<AttachmentFieldWrapper
|
|
110
|
+
qItem={qItem}
|
|
111
|
+
attachmentValues={{ uploadedFile: uploadedFile, url: url, fileName: fileName }}
|
|
112
|
+
readOnly={readOnly}
|
|
113
|
+
isRepeated={isRepeated}
|
|
114
|
+
isTabled={isTabled}
|
|
115
|
+
onUploadFile={handleUploadFile}
|
|
116
|
+
onUrlChange={handleUrlChange}
|
|
117
|
+
onFileNameChange={handleFileNameChange}
|
|
118
|
+
/>
|
|
119
|
+
</DndProvider>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export default AttachmentItem;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import React from 'react';
|
|
19
|
+
import type { PropsWithIsTabledAttribute } from '../../../interfaces/renderProps.interface';
|
|
20
|
+
import { StandardTextField } from '../Textfield.styles';
|
|
21
|
+
import Typography from '@mui/material/Typography';
|
|
22
|
+
import Box from '@mui/material/Box';
|
|
23
|
+
import Stack from '@mui/material/Stack';
|
|
24
|
+
import useAttachmentUrlValidation from '../../../hooks/useAttachmentUrlValidation';
|
|
25
|
+
import InputAdornment from '@mui/material/InputAdornment';
|
|
26
|
+
import Tooltip from '@mui/material/Tooltip';
|
|
27
|
+
import CheckIcon from '@mui/icons-material/Check';
|
|
28
|
+
import DangerousIcon from '@mui/icons-material/Dangerous';
|
|
29
|
+
|
|
30
|
+
interface AttachmentUrlFieldProps extends PropsWithIsTabledAttribute {
|
|
31
|
+
linkId: string;
|
|
32
|
+
url: string;
|
|
33
|
+
readOnly: boolean;
|
|
34
|
+
onUrlChange: (url: string) => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function AttachmentUrlField(props: AttachmentUrlFieldProps) {
|
|
38
|
+
const { linkId, url, readOnly, isTabled, onUrlChange } = props;
|
|
39
|
+
|
|
40
|
+
const urlIsValid = useAttachmentUrlValidation(url);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Box>
|
|
44
|
+
<Typography variant="body2">URL</Typography>
|
|
45
|
+
<Stack direction="row" alignItems="center">
|
|
46
|
+
<StandardTextField
|
|
47
|
+
fullWidth
|
|
48
|
+
isTabled={isTabled}
|
|
49
|
+
id={linkId}
|
|
50
|
+
value={url}
|
|
51
|
+
onChange={(event) => onUrlChange(event.target.value)}
|
|
52
|
+
disabled={readOnly}
|
|
53
|
+
size="small"
|
|
54
|
+
data-test="q-item-attachment-field"
|
|
55
|
+
InputProps={{
|
|
56
|
+
endAdornment: (
|
|
57
|
+
<InputAdornment position="end">
|
|
58
|
+
{url != '' ? (
|
|
59
|
+
<Tooltip title={urlIsValid ? 'URL is valid!' : 'Invalid URL'} placement="right">
|
|
60
|
+
<Box mt={0.5}>
|
|
61
|
+
{urlIsValid ? (
|
|
62
|
+
<CheckIcon color="success" fontSize="small" />
|
|
63
|
+
) : (
|
|
64
|
+
<DangerousIcon color="error" fontSize="small" />
|
|
65
|
+
)}
|
|
66
|
+
</Box>
|
|
67
|
+
</Tooltip>
|
|
68
|
+
) : null}
|
|
69
|
+
</InputAdornment>
|
|
70
|
+
)
|
|
71
|
+
}}
|
|
72
|
+
/>
|
|
73
|
+
</Stack>
|
|
74
|
+
</Box>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default AttachmentUrlField;
|