@awell-health/ui-library 0.1.97 → 0.1.98
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/dist/index.js
CHANGED
|
@@ -41218,6 +41218,40 @@ Check the top-level render call using <` + t + ">.");
|
|
|
41218
41218
|
return { options: options, loading: loading, error: error, onIcdClassificationSearchChange: onIcdClassificationSearchChange };
|
|
41219
41219
|
};
|
|
41220
41220
|
|
|
41221
|
+
var custom_json_parser = function (blob, defaultValue) {
|
|
41222
|
+
if (defaultValue === void 0) {defaultValue = 'invalid JSON';}
|
|
41223
|
+
try {
|
|
41224
|
+
if (typeof blob !== 'string') {
|
|
41225
|
+
throw new Error();
|
|
41226
|
+
}
|
|
41227
|
+
var parsed = JSON.parse(blob);
|
|
41228
|
+
if (typeof parsed === 'string') {
|
|
41229
|
+
return JSON.parse(parsed);
|
|
41230
|
+
}
|
|
41231
|
+
return parsed;
|
|
41232
|
+
}
|
|
41233
|
+
catch (error) {
|
|
41234
|
+
return defaultValue;
|
|
41235
|
+
}
|
|
41236
|
+
};
|
|
41237
|
+
|
|
41238
|
+
var areAttachmentsValid = function (_a) {
|
|
41239
|
+
var attachmentsValue = _a.attachmentsValue,required = _a.required,acceptedFileTypes = _a.acceptedFileTypes;
|
|
41240
|
+
var parseAttachments = function (val) {
|
|
41241
|
+
try {
|
|
41242
|
+
return JSON.parse(val);
|
|
41243
|
+
}
|
|
41244
|
+
catch (error) {
|
|
41245
|
+
return [];
|
|
41246
|
+
}
|
|
41247
|
+
};
|
|
41248
|
+
var attachments = parseAttachments(attachmentsValue);
|
|
41249
|
+
if (required) {
|
|
41250
|
+
return !lodash.exports.isNil(attachments) && attachments.length > 0;
|
|
41251
|
+
}
|
|
41252
|
+
return attachments.every(function (attachment) {var _a;return acceptedFileTypes.includes((_a = attachment.contentType) !== null && _a !== void 0 ? _a : '');});
|
|
41253
|
+
};
|
|
41254
|
+
|
|
41221
41255
|
var Tr={exports:{}},En={};
|
|
41222
41256
|
/**
|
|
41223
41257
|
* @license React
|
|
@@ -48061,187 +48095,138 @@ var Kr=[{
|
|
|
48061
48095
|
|
|
48062
48096
|
var classes$9 = {"file_input_field_container":"awell__FileInputField_file_input_field_container","error_message":"awell__FileInputField_error_message","file_upload_wrapper":"awell__FileInputField_file_upload_wrapper","file_list_wrapper":"awell__FileInputField_file_list_wrapper","btn-square":"awell__FileInputField_btn-square"};
|
|
48063
48097
|
|
|
48064
|
-
var
|
|
48065
|
-
var
|
|
48066
|
-
var
|
|
48067
|
-
|
|
48068
|
-
|
|
48069
|
-
|
|
48070
|
-
|
|
48071
|
-
|
|
48072
|
-
|
|
48073
|
-
|
|
48074
|
-
|
|
48075
|
-
|
|
48076
|
-
|
|
48077
|
-
|
|
48078
|
-
[]),selectedFiles = _d[0],setSelectedFiles = _d[1];
|
|
48079
|
-
React.useEffect(function () {
|
|
48080
|
-
var attachments = selectedFiles.
|
|
48081
|
-
filter(function (file) {return file.url;}).
|
|
48082
|
-
map(function (file) {return {
|
|
48083
|
-
url: file.url,
|
|
48084
|
-
filename: file.name,
|
|
48085
|
-
contentType: file.type,
|
|
48086
|
-
size: file.size };
|
|
48087
|
-
});
|
|
48088
|
-
onChange(attachments);
|
|
48089
|
-
}, [selectedFiles]);
|
|
48098
|
+
var SingleFileInputField = function (_a) {
|
|
48099
|
+
var _b, _c, _d, _e, _f;
|
|
48100
|
+
var id = _a.id,label = _a.label,accept = _a.accept,error = _a.error,onChange = _a.onChange,onError = _a.onError,_g = _a.className,className = _g === void 0 ? '' : _g,dataCy = _a.dataCy,onFileUpload = _a.onFileUpload,configSlug = _a.configSlug,value = _a.value,mandatory = _a.mandatory,disabled = _a.disabled;
|
|
48101
|
+
var _h = React.useState(!lodash.exports.isNil(value) && !lodash.exports.isEmpty(value) ?
|
|
48102
|
+
{
|
|
48103
|
+
id: (_b = value.filename) !== null && _b !== void 0 ? _b : 'untitled',
|
|
48104
|
+
name: (_c = value.filename) !== null && _c !== void 0 ? _c : 'untitled',
|
|
48105
|
+
size: (_d = value.size) !== null && _d !== void 0 ? _d : 0,
|
|
48106
|
+
type: (_e = value.contentType) !== null && _e !== void 0 ? _e : '',
|
|
48107
|
+
url: (_f = value.url) !== null && _f !== void 0 ? _f : '',
|
|
48108
|
+
progress: 100,
|
|
48109
|
+
error: undefined } :
|
|
48110
|
+
|
|
48111
|
+
undefined),selectedFile = _h[0],setSelectedFile = _h[1];
|
|
48090
48112
|
var convertErrorMessage = function (error) {
|
|
48091
48113
|
if (error === 'Failed to fetch') {
|
|
48092
48114
|
return 'File upload failed. Please remove this file and try again.';
|
|
48093
48115
|
}
|
|
48094
48116
|
return error;
|
|
48095
48117
|
};
|
|
48096
|
-
var
|
|
48097
|
-
var
|
|
48098
|
-
return __generator(this, function (
|
|
48099
|
-
switch (
|
|
48118
|
+
var uploadFileToStorage = function (file) {return __awaiter(void 0, void 0, void 0, function () {
|
|
48119
|
+
var uploadingFile, fileUrl, completedFile, finalFile, attachment, error_1, failedFile;
|
|
48120
|
+
return __generator(this, function (_a) {
|
|
48121
|
+
switch (_a.label) {
|
|
48100
48122
|
case 0:
|
|
48101
|
-
|
|
48102
|
-
|
|
48103
|
-
|
|
48104
|
-
|
|
48105
|
-
|
|
48106
|
-
|
|
48107
|
-
|
|
48108
|
-
|
|
48109
|
-
|
|
48110
|
-
|
|
48111
|
-
|
|
48112
|
-
type: file.type,
|
|
48113
|
-
progress: 10,
|
|
48114
|
-
error: undefined };
|
|
48115
|
-
|
|
48116
|
-
setSelectedFiles(function (prev) {return __spreadArray(__spreadArray([], prev.filter(function (f) {return f.id !== file.name;}), true), [
|
|
48117
|
-
uploadingFile_1],
|
|
48118
|
-
false);});
|
|
48119
|
-
return [4, onFileUpload === null || onFileUpload === void 0 ? void 0 : onFileUpload(file, configSlug)];
|
|
48120
|
-
case 1:
|
|
48121
|
-
fileUrl = _c.sent();
|
|
48122
|
-
completedFile_1 = {
|
|
48123
|
-
id: file.name,
|
|
48124
|
-
name: file.name,
|
|
48125
|
-
size: file.size,
|
|
48126
|
-
type: file.type,
|
|
48127
|
-
progress: 99,
|
|
48128
|
-
error: undefined,
|
|
48129
|
-
url: fileUrl };
|
|
48130
|
-
|
|
48131
|
-
setSelectedFiles(function (prev) {return __spreadArray(__spreadArray([], prev.filter(function (f) {return f.id !== file.name;}), true), [
|
|
48132
|
-
completedFile_1],
|
|
48133
|
-
false);});
|
|
48134
|
-
return [4, new Promise(function (resolve) {return setTimeout(resolve, 100);})];
|
|
48135
|
-
case 2:
|
|
48136
|
-
_c.sent();
|
|
48137
|
-
setSelectedFiles(function (prev) {return __spreadArray(__spreadArray([], prev.filter(function (f) {return f.id !== file.name;}), true), [
|
|
48138
|
-
__assign(__assign({}, completedFile_1), { progress: 100 })],
|
|
48139
|
-
false);});
|
|
48140
|
-
fileListWithUrls.push(completedFile_1);
|
|
48141
|
-
return [3, 4];
|
|
48142
|
-
case 3:
|
|
48143
|
-
error_1 = _c.sent();
|
|
48144
|
-
failedFile_1 = {
|
|
48145
|
-
id: file.name,
|
|
48146
|
-
name: file.name,
|
|
48147
|
-
size: file.size,
|
|
48148
|
-
type: file.type,
|
|
48149
|
-
progress: 0,
|
|
48150
|
-
error: error_1 instanceof Error ?
|
|
48151
|
-
convertErrorMessage(error_1.message) :
|
|
48152
|
-
'File upload failed',
|
|
48153
|
-
url: undefined };
|
|
48154
|
-
|
|
48155
|
-
setSelectedFiles(function (prev) {return __spreadArray(__spreadArray([], prev.filter(function (f) {return f.id !== file.name;}), true), [
|
|
48156
|
-
failedFile_1],
|
|
48157
|
-
false);});
|
|
48158
|
-
fileListWithUrls.push(failedFile_1);
|
|
48159
|
-
return [3, 4];
|
|
48160
|
-
case 4:return [2];}
|
|
48161
|
-
|
|
48162
|
-
});
|
|
48163
|
-
};
|
|
48164
|
-
_i = 0, _a = Array.from(files);
|
|
48165
|
-
_b.label = 1;
|
|
48123
|
+
_a.trys.push([0, 3,, 4]);
|
|
48124
|
+
uploadingFile = {
|
|
48125
|
+
id: file.name,
|
|
48126
|
+
name: file.name,
|
|
48127
|
+
size: file.size,
|
|
48128
|
+
type: file.type,
|
|
48129
|
+
progress: 10,
|
|
48130
|
+
error: undefined };
|
|
48131
|
+
|
|
48132
|
+
setSelectedFile(uploadingFile);
|
|
48133
|
+
return [4, onFileUpload === null || onFileUpload === void 0 ? void 0 : onFileUpload(file, configSlug)];
|
|
48166
48134
|
case 1:
|
|
48167
|
-
|
|
48168
|
-
|
|
48169
|
-
|
|
48135
|
+
fileUrl = _a.sent();
|
|
48136
|
+
completedFile = __assign(__assign({}, uploadingFile), { progress: 99, error: undefined, url: fileUrl });
|
|
48137
|
+
setSelectedFile(completedFile);
|
|
48138
|
+
return [4, new Promise(function (resolve) {return setTimeout(resolve, 100);})];
|
|
48170
48139
|
case 2:
|
|
48171
|
-
|
|
48172
|
-
|
|
48140
|
+
_a.sent();
|
|
48141
|
+
finalFile = __assign(__assign({}, completedFile), { progress: 100 });
|
|
48142
|
+
setSelectedFile(finalFile);
|
|
48143
|
+
if (finalFile.url) {
|
|
48144
|
+
attachment = {
|
|
48145
|
+
url: finalFile.url,
|
|
48146
|
+
filename: finalFile.name,
|
|
48147
|
+
contentType: finalFile.type,
|
|
48148
|
+
size: finalFile.size };
|
|
48149
|
+
|
|
48150
|
+
onChange(attachment);
|
|
48151
|
+
}
|
|
48152
|
+
return [2, finalFile];
|
|
48173
48153
|
case 3:
|
|
48174
|
-
|
|
48175
|
-
|
|
48176
|
-
|
|
48154
|
+
error_1 = _a.sent();
|
|
48155
|
+
failedFile = {
|
|
48156
|
+
id: file.name,
|
|
48157
|
+
name: file.name,
|
|
48158
|
+
size: file.size,
|
|
48159
|
+
type: file.type,
|
|
48160
|
+
progress: 0,
|
|
48161
|
+
error: error_1 instanceof Error ?
|
|
48162
|
+
convertErrorMessage(error_1.message) :
|
|
48163
|
+
'File upload failed',
|
|
48164
|
+
url: undefined };
|
|
48165
|
+
|
|
48166
|
+
setSelectedFile(failedFile);
|
|
48167
|
+
return [2, failedFile];
|
|
48168
|
+
case 4:return [2];}
|
|
48177
48169
|
|
|
48178
48170
|
});
|
|
48179
48171
|
});};
|
|
48180
48172
|
var handleFilesChange = function (files) {return __awaiter(void 0, void 0, void 0, function () {
|
|
48181
|
-
var
|
|
48173
|
+
var file, pendingFile;
|
|
48182
48174
|
return __generator(this, function (_a) {
|
|
48183
48175
|
switch (_a.label) {
|
|
48184
48176
|
case 0:
|
|
48185
|
-
|
|
48186
|
-
|
|
48187
|
-
|
|
48188
|
-
|
|
48189
|
-
|
|
48190
|
-
|
|
48191
|
-
|
|
48192
|
-
|
|
48193
|
-
|
|
48194
|
-
|
|
48177
|
+
file = files[0];
|
|
48178
|
+
if (!file) {
|
|
48179
|
+
onChange(undefined);
|
|
48180
|
+
setSelectedFile(undefined);
|
|
48181
|
+
return [2];
|
|
48182
|
+
}
|
|
48183
|
+
pendingFile = {
|
|
48184
|
+
id: file.name,
|
|
48185
|
+
name: file.name,
|
|
48186
|
+
size: file.size,
|
|
48187
|
+
type: file.type,
|
|
48188
|
+
progress: 1,
|
|
48189
|
+
error: undefined };
|
|
48190
|
+
|
|
48191
|
+
setSelectedFile(pendingFile);
|
|
48192
|
+
return [4, uploadFileToStorage(file)];
|
|
48195
48193
|
case 1:
|
|
48196
48194
|
_a.sent();
|
|
48197
48195
|
return [2];}
|
|
48198
48196
|
|
|
48199
48197
|
});
|
|
48200
48198
|
});};
|
|
48201
|
-
var handleRemoveFile = function (
|
|
48202
|
-
|
|
48199
|
+
var handleRemoveFile = function () {
|
|
48200
|
+
setSelectedFile(undefined);
|
|
48201
|
+
onChange(undefined);
|
|
48203
48202
|
};
|
|
48204
|
-
|
|
48205
|
-
|
|
48206
|
-
return acc + ((_a = file.progress) !== null && _a !== void 0 ? _a : 0);
|
|
48207
|
-
}, 0) / selectedFiles.length;
|
|
48208
|
-
var hideGeneralProgress = selectedFiles.length === 0 ||
|
|
48209
|
-
selectedFiles.every(function (file) {return file.progress === 100;}) ||
|
|
48210
|
-
generalProgress === 0;
|
|
48211
|
-
return jsxRuntime.exports.jsxs("div", __assign({ className: "".concat(classes$9.file_input_field_container, " ").concat(className), "data-cy": dataCy }, { children: [label && jsxRuntime.exports.jsx(QuestionLabel, { htmlFor: id, label: label, mandatory: mandatory }), error && jsxRuntime.exports.jsx("div", __assign({ className: classes$9.error_message }, { children: error })), jsxRuntime.exports.jsx("div", __assign({ className: classes$9.file_upload_wrapper }, { children: jsxRuntime.exports.jsx(dg, { onChange: handleFilesChange, onError: onError, isMultiple: multiple, accept: accept, error: error }) })), selectedFiles.length > 0 && jsxRuntime.exports.jsx("div", __assign({ className: "".concat(classes$9.file_list_wrapper, " ").concat(classes$9.custom_file_list_container) }, { children: jsxRuntime.exports.jsx(ug, { files: selectedFiles, onDelete: handleRemoveFile, generalProgress: hideGeneralProgress ? undefined : generalProgress }) }))] }), id);
|
|
48212
|
-
};
|
|
48213
|
-
|
|
48214
|
-
var custom_json_parser = function (blob) {
|
|
48215
|
-
try {
|
|
48216
|
-
if (typeof blob !== 'string') {
|
|
48217
|
-
throw new Error();
|
|
48218
|
-
}
|
|
48219
|
-
var parsed = JSON.parse(blob);
|
|
48220
|
-
if (typeof parsed === 'string') {
|
|
48221
|
-
return JSON.parse(parsed);
|
|
48222
|
-
}
|
|
48223
|
-
return parsed;
|
|
48224
|
-
}
|
|
48225
|
-
catch (error) {
|
|
48226
|
-
return 'invalid JSON';
|
|
48203
|
+
if (value && disabled === true) {
|
|
48204
|
+
return jsxRuntime.exports.jsxs("div", __assign({ className: "".concat(classes$9.file_input_field_container, " ").concat(className), "data-cy": dataCy }, { children: [label && jsxRuntime.exports.jsx(QuestionLabel, { htmlFor: id, label: label, mandatory: mandatory }), !value.url ? jsxRuntime.exports.jsx("div", { children: "No file uploaded" }) : jsxRuntime.exports.jsxs("div", __assign({ className: classes$9.read_only_file }, { children: [value.filename, " (", value.contentType, ")"] }))] }), id);
|
|
48227
48205
|
}
|
|
48206
|
+
return jsxRuntime.exports.jsxs("div", __assign({ className: "".concat(classes$9.file_input_field_container, " ").concat(className), "data-cy": dataCy }, { children: [label && jsxRuntime.exports.jsx(QuestionLabel, { htmlFor: id, label: label, mandatory: mandatory }), error && jsxRuntime.exports.jsx("div", __assign({ className: classes$9.error_message }, { children: error })), jsxRuntime.exports.jsx("div", __assign({ className: classes$9.file_upload_wrapper }, { children: jsxRuntime.exports.jsx(dg, { onChange: handleFilesChange, onError: onError, isMultiple: false, accept: accept, error: error }) })), selectedFile && jsxRuntime.exports.jsx("div", __assign({ className: "".concat(classes$9.file_list_wrapper, " ").concat(classes$9.custom_file_list_container) }, { children: jsxRuntime.exports.jsx(ug, { files: [selectedFile], onDelete: function () {return handleRemoveFile();}, generalProgress: selectedFile.progress !== undefined && selectedFile.progress < 100 ?
|
|
48207
|
+
selectedFile.progress :
|
|
48208
|
+
undefined }) }))] }), id);
|
|
48228
48209
|
};
|
|
48229
48210
|
|
|
48230
|
-
var
|
|
48211
|
+
var isAttachmentValid = function (_a) {
|
|
48231
48212
|
var attachmentsValue = _a.attachmentsValue,required = _a.required,acceptedFileTypes = _a.acceptedFileTypes;
|
|
48232
|
-
var
|
|
48213
|
+
var parseAttachment = function (val) {
|
|
48233
48214
|
try {
|
|
48234
|
-
|
|
48215
|
+
var parsed = JSON.parse(val);
|
|
48216
|
+
return parsed;
|
|
48235
48217
|
}
|
|
48236
48218
|
catch (error) {
|
|
48237
|
-
return
|
|
48219
|
+
return null;
|
|
48238
48220
|
}
|
|
48239
48221
|
};
|
|
48240
|
-
var
|
|
48222
|
+
var attachment = parseAttachment(attachmentsValue);
|
|
48241
48223
|
if (required) {
|
|
48242
|
-
return !lodash.exports.isNil(
|
|
48224
|
+
return !lodash.exports.isNil(attachment) && !lodash.exports.isNil(attachment.url);
|
|
48243
48225
|
}
|
|
48244
|
-
|
|
48226
|
+
if (lodash.exports.isNil(attachment) || lodash.exports.isNil(attachment.contentType)) {
|
|
48227
|
+
return !required;
|
|
48228
|
+
}
|
|
48229
|
+
return acceptedFileTypes.includes(attachment.contentType);
|
|
48245
48230
|
};
|
|
48246
48231
|
|
|
48247
48232
|
var AUTO_PROGRESS_DELAY = 850;
|
|
@@ -48425,7 +48410,7 @@ var Kr=[{
|
|
|
48425
48410
|
required: config === null || config === void 0 ? void 0 : config.mandatory,
|
|
48426
48411
|
validate: function (value) {
|
|
48427
48412
|
var _a, _b, _c;
|
|
48428
|
-
return
|
|
48413
|
+
return isAttachmentValid({
|
|
48429
48414
|
attachmentsValue: value,
|
|
48430
48415
|
acceptedFileTypes: (_b = (_a = config === null || config === void 0 ? void 0 : config.file_storage) === null || _a === void 0 ? void 0 : _a.accepted_file_types) !== null && _b !== void 0 ? _b : [],
|
|
48431
48416
|
required: (_c = config === null || config === void 0 ? void 0 : config.mandatory) !== null && _c !== void 0 ? _c : false });
|
|
@@ -48434,8 +48419,8 @@ var Kr=[{
|
|
|
48434
48419
|
render: function (_a) {
|
|
48435
48420
|
var _b, _c, _d;
|
|
48436
48421
|
var _e = _a.field,onControllerChange = _e.onChange,onBlur = _e.onBlur,value = _e.value;
|
|
48437
|
-
return jsxRuntime.exports.jsx(
|
|
48438
|
-
onControllerChange(JSON.stringify(
|
|
48422
|
+
return jsxRuntime.exports.jsx(SingleFileInputField, { id: question.id, value: custom_json_parser(value, ''), onChange: function (attachment) {
|
|
48423
|
+
onControllerChange(JSON.stringify(attachment));
|
|
48439
48424
|
onAnswerChange();
|
|
48440
48425
|
}, onBlur: onBlur, accept: (_c = (_b = config === null || config === void 0 ? void 0 : config.file_storage) === null || _b === void 0 ? void 0 : _b.accepted_file_types) !== null && _c !== void 0 ? _c : [
|
|
48441
48426
|
'application/pdf'],
|
|
@@ -48455,8 +48440,8 @@ var Kr=[{
|
|
|
48455
48440
|
render: function (_a) {
|
|
48456
48441
|
var _b, _c, _d;
|
|
48457
48442
|
var _e = _a.field,onControllerChange = _e.onChange,onBlur = _e.onBlur,value = _e.value;
|
|
48458
|
-
return jsxRuntime.exports.jsx(
|
|
48459
|
-
onControllerChange(JSON.stringify(
|
|
48443
|
+
return jsxRuntime.exports.jsx(SingleFileInputField, { id: question.id, value: custom_json_parser(value, ''), onChange: function (attachment) {
|
|
48444
|
+
onControllerChange(JSON.stringify(attachment));
|
|
48460
48445
|
onAnswerChange();
|
|
48461
48446
|
}, onBlur: onBlur, accept: (_c = (_b = config === null || config === void 0 ? void 0 : config.file_storage) === null || _b === void 0 ? void 0 : _b.accepted_file_types) !== null && _c !== void 0 ? _c : ['image/*'], configSlug: (_d = config === null || config === void 0 ? void 0 : config.file_storage) === null || _d === void 0 ? void 0 : _d.file_storage_config_slug, onFileUpload: onFileUpload, label: question.title, mandatory: config === null || config === void 0 ? void 0 : config.mandatory });
|
|
48462
48447
|
} });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Attachment } from '../../molecules/question/types';
|
|
3
|
+
import '@awell-health/design-system/style.css';
|
|
4
|
+
interface Props {
|
|
5
|
+
id?: string;
|
|
6
|
+
label?: string;
|
|
7
|
+
accept?: Array<string>;
|
|
8
|
+
error?: string;
|
|
9
|
+
onChange: (attachment: Attachment | undefined) => void;
|
|
10
|
+
onError?: (error: string) => void;
|
|
11
|
+
className?: string;
|
|
12
|
+
onBlur?: () => void;
|
|
13
|
+
dataCy?: string;
|
|
14
|
+
onFileUpload?: (file: File, configSlug?: string) => Promise<string | undefined>;
|
|
15
|
+
configSlug?: string;
|
|
16
|
+
value?: Attachment | null;
|
|
17
|
+
mandatory?: boolean;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare const SingleFileInputField: React.FC<Props>;
|
|
21
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const custom_json_parser: (blob: string) => any;
|
|
1
|
+
export declare const custom_json_parser: (blob: string, defaultValue?: any) => any;
|