aefis-core-ui 2.3.0-rc4 → 2.3.0-rc6

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.
@@ -84,6 +84,7 @@ import FilePondPluginImageExifOrientation from 'filepond-plugin-image-exif-orien
84
84
  import FilePondPluginImagePreview from 'filepond-plugin-image-preview';
85
85
  import { registerPlugin, FilePond } from 'react-filepond';
86
86
  import FilePondPluginGetFile from 'filepond-plugin-get-file';
87
+ import FilePondPluginFileValidateSize from 'filepond-plugin-file-validate-size';
87
88
  import MaskedInput from 'react-text-mask';
88
89
  import StylesProvider from '@mui/styles/StylesProvider';
89
90
 
@@ -3296,12 +3297,12 @@ const outcomeConfiguration = {
3296
3297
  // about solution: https://stackoverflow.com/questions/22820162/mustache-js-escaping
3297
3298
  mustache.escape = _ => _;
3298
3299
  function compile() {}
3299
- function render$2(template, data, defaultValue) {
3300
+ function render$1(template, data, defaultValue) {
3300
3301
  return template ? mustache.render(template, data) : defaultValue;
3301
3302
  }
3302
3303
  var template = {
3303
3304
  compile,
3304
- render: render$2
3305
+ render: render$1
3305
3306
  };
3306
3307
 
3307
3308
  // Copyright (c) 2020 AEFIS, all rights reserved.
@@ -7659,69 +7660,6 @@ TextSearch.propTypes = {
7659
7660
  bottomGutter: PropTypes.number
7660
7661
  };
7661
7662
 
7662
- const {
7663
- render: render$1
7664
- } = template;
7665
-
7666
- /**
7667
- * This function returns unique field inside filter item using render.
7668
- *
7669
- * @param {object} item
7670
- * @param {object} filter
7671
- * @returns {string}
7672
- */
7673
- const getFilterItemId = (item, configItem = {}) => {
7674
- var _item$data;
7675
- if (item.id) {
7676
- return item.id;
7677
- }
7678
- const template = configItem.idTemplate || configItem.template || configItem.optionTemplate;
7679
- if (template) {
7680
- return render$1(template, item.data || item);
7681
- }
7682
- if ((_item$data = item.data) != null && _item$data.id) {
7683
- return item.data.id;
7684
- }
7685
- };
7686
-
7687
- /**
7688
- * This function checks filter items; if index and id fields are missing then
7689
- * try to sets them with possible ways.
7690
- *
7691
- * @param {array} filters
7692
- * @param {array} configuration
7693
- * @returns {array}
7694
- */
7695
- const formatFilters = (filters = [], configuration = []) => filters.map(filter => {
7696
- var _ref, _filter$index, _filter$id, _configuration$index, _configuration$index2, _configuration$index3, _configuration$index4, _configuration$index5;
7697
- // TODO: index should be defined on filters. There should not be need of
7698
- // search of index value throught type or map values.
7699
- const index = (_ref = (_filter$index = filter == null ? void 0 : filter.index) != null ? _filter$index : findIndexByType(filter, configuration)) != null ? _ref : findIndexByMap(filter, configuration);
7700
- const id = (_filter$id = filter == null ? void 0 : filter.id) != null ? _filter$id : getFilterItemId(filter, configuration[index]);
7701
-
7702
- // TODO: These properties should ONLY be defined either in configuration
7703
- // or filters; currently data can be defined from both sources. Filter
7704
- // data prioritised over configuratuon.
7705
- const {
7706
- map = (_configuration$index = configuration[index]) == null ? void 0 : _configuration$index.map,
7707
- type = (_configuration$index2 = configuration[index]) == null ? void 0 : _configuration$index2.type,
7708
- template = (_configuration$index3 = configuration[index]) == null ? void 0 : _configuration$index3.template,
7709
- idTemplate = (_configuration$index4 = configuration[index]) == null ? void 0 : _configuration$index4.idTemplate,
7710
- optionTemplate = (_configuration$index5 = configuration[index]) == null ? void 0 : _configuration$index5.optionTemplate
7711
- } = filter;
7712
- return _extends({}, filter, {
7713
- template,
7714
- idTemplate,
7715
- optionTemplate,
7716
- type,
7717
- map,
7718
- index,
7719
- id
7720
- });
7721
- });
7722
- const findIndexByType = (filter, configuration) => filter.type !== undefined ? configuration.findIndex(config => config.type === filter.type) : undefined;
7723
- const findIndexByMap = (filter, configuration) => filter.map !== undefined ? configuration.findIndex(config => config.map === filter.map) : undefined;
7724
-
7725
7663
  const mapFilters = newFilters => {
7726
7664
  const mappedFilters = {};
7727
7665
  newFilters.map(filter => {
@@ -8096,7 +8034,8 @@ const FilterChips = ({
8096
8034
  const Filters = useMemo(() => {
8097
8035
  return /*#__PURE__*/jsx(Box$1, {
8098
8036
  sx: {
8099
- display: "flex"
8037
+ display: "flex",
8038
+ flexFlow: "wrap"
8100
8039
  },
8101
8040
  children: _filters.map(filter => /*#__PURE__*/jsx(Grow, {
8102
8041
  in: true,
@@ -8111,7 +8050,7 @@ const FilterChips = ({
8111
8050
  displayOptions: {
8112
8051
  hasIcon: filter.type !== "keyword"
8113
8052
  },
8114
- type: "businessObject",
8053
+ type: filter.type || "businessObject",
8115
8054
  template: filter.template,
8116
8055
  data: filter.data,
8117
8056
  onDelete: () => {
@@ -8122,7 +8061,11 @@ const FilterChips = ({
8122
8061
  }, `filterPanelFilter-${filter.index}-${filter.id}`))
8123
8062
  });
8124
8063
  }, [_filters]);
8125
- const SortItems = useMemo(() => /*#__PURE__*/jsx(Fragment, {
8064
+ const SortItems = useMemo(() => /*#__PURE__*/jsx(Box$1, {
8065
+ sx: {
8066
+ display: "flex",
8067
+ flexFlow: "wrap"
8068
+ },
8126
8069
  children: _sort.map(sortItem => /*#__PURE__*/jsx(Grow, {
8127
8070
  in: true,
8128
8071
  children: /*#__PURE__*/jsx("div", {
@@ -8360,6 +8303,36 @@ PanelDisplay.propTypes = {
8360
8303
  renderFilterSelection: PropTypes.bool
8361
8304
  };
8362
8305
 
8306
+ const usePrevState = (callback, current) => {
8307
+ const [prev, setPrev] = useState(current);
8308
+ if (prev !== current) {
8309
+ callback(prev, current);
8310
+ setPrev(current);
8311
+ }
8312
+ };
8313
+
8314
+ const useFilterState = filtersProp => {
8315
+ const [filters, _setFilters] = useState(filtersProp);
8316
+ const setFilters = useCallback((filters = []) => {
8317
+ const sorted = filters.sort((a, b) => a.index - b.index);
8318
+ _setFilters(sorted);
8319
+ }, []);
8320
+ usePrevState(() => {
8321
+ setFilters(filtersProp);
8322
+ }, filtersProp);
8323
+ return [filters, setFilters];
8324
+ };
8325
+
8326
+ const getItemId = (item, filter) => item.id || template.render(filter.idTemplate || filter.optionTemplate, item);
8327
+ const formatFilterItem = (index, filter, data) => ({
8328
+ index: index,
8329
+ id: getItemId(data, filter),
8330
+ type: filter.type,
8331
+ template: filter.optionTemplate,
8332
+ idTemplate: filter.idTemplate,
8333
+ map: filter.map,
8334
+ data
8335
+ });
8363
8336
  const mapSort = value => value.map(i => i.map);
8364
8337
  const getSearchFilter = newFilters => (newFilters == null ? void 0 : newFilters.filter(filter => (filter == null ? void 0 : filter.type) === "keyword").map(item => item.data.id)) || [];
8365
8338
 
@@ -8378,7 +8351,7 @@ const FilterPanel = props => {
8378
8351
  searchTooltip,
8379
8352
  searchPlaceHolderText,
8380
8353
  configuration,
8381
- filters: filtersProp,
8354
+ filters: filtersProp = [],
8382
8355
  displayType,
8383
8356
  limitTags,
8384
8357
  bottomGutter,
@@ -8388,14 +8361,10 @@ const FilterPanel = props => {
8388
8361
  sort: sortProp
8389
8362
  } = props;
8390
8363
  const [menuPosition, setMenuPosition] = useState(null);
8391
- const [filters, setFilters] = useState([]);
8364
+ const [filters, setFilters] = useFilterState(filtersProp);
8392
8365
  const [sort, setSort] = useState(sortProp || []);
8393
8366
  const [panelSearch, setPanelSearch] = useState([]);
8394
8367
  const [pickerFilters, setPickerFilters] = useState([]);
8395
- useEffect(() => {
8396
- const formattedFilters = formatFilters(filtersProp, configuration);
8397
- setFilters(formattedFilters);
8398
- }, [filtersProp]);
8399
8368
 
8400
8369
  // TODO: replace it with useMemo
8401
8370
  useEffect(() => {
@@ -8421,9 +8390,8 @@ const FilterPanel = props => {
8421
8390
  onDataChange(filteredData, filterParameters, filters);
8422
8391
  }
8423
8392
  }, [filters, sort]);
8424
- const removeFilter = filter => {
8425
- console.log("remove filter ", filter);
8426
- const newFilterArray = filters == null ? void 0 : filters.filter(i => i.index !== filter.index || filter.id !== i.id);
8393
+ const removeFilter = (filter = []) => {
8394
+ const newFilterArray = filters.filter(i => i.index !== filter.index || filter.id !== i.id);
8427
8395
  setFilters(newFilterArray);
8428
8396
  if (!onApplyFilters) {
8429
8397
  if ((filter == null ? void 0 : filter.type) === "keyword" && onSearchChange) {
@@ -8460,69 +8428,14 @@ const FilterPanel = props => {
8460
8428
  onChange(mapFilters(newFilterArray), newFilterArray);
8461
8429
  }
8462
8430
  };
8463
- /** Had to revert this function as filters were not working properly
8464
- const handleSetFilterType = (inputIndex, configItem, data = []) => {
8465
- const newFiltersByUpdatedIndex = data.map((filterItem) => {
8466
- return {
8467
- index: inputIndex,
8468
- id: filterItem.id || getFilterItemId(configItem, filterItem),
8469
- type: configItem.type,
8470
- template: configItem.optionTemplate,
8471
- idTemplate: configItem.idTemplate,
8472
- map: configItem.map,
8473
- data: filterItem
8474
- };
8475
- });
8476
- const filtersByUnupdatedIndex = filters.filter((i) => i.index !== inputIndex);
8477
- const newFilters = [...filtersByUnupdatedIndex, ...newFiltersByUpdatedIndex];
8478
- setFilters(newFilters);
8479
- if (onChange) {
8480
- // TO-CHECK: what does mapFilters do?
8481
- onChange(mapFilters(newFilters), newFilters);
8482
- }
8483
- }; */
8484
-
8485
8431
  const handleSetFilterType = (index, filter, data) => {
8486
- const getItemId = item => item.id || template.render(filter.idTemplate || filter.optionTemplate, item);
8487
- if (!Array.isArray(data)) {
8488
- const _newFilterArray = filters.filter(i => index !== i.index);
8489
- if (data) {
8490
- const newItemId = getItemId(data);
8491
- _newFilterArray.push({
8492
- index: index,
8493
- id: newItemId,
8494
- type: filter.type,
8495
- template: filter.optionTemplate,
8496
- idTemplate: filter.idTemplate,
8497
- map: filter.map,
8498
- data: data
8499
- });
8500
- }
8501
- setFilters(_newFilterArray);
8502
- if (onChange && !onApplyFilters) {
8503
- onChange(mapFilters(_newFilterArray), _newFilterArray);
8504
- }
8505
- return;
8506
- }
8507
- data.map(item => {
8508
- const newItemId = getItemId(item);
8509
- if (!filters.find(i => i.index === index && i.id === newItemId)) {
8510
- filters.push({
8511
- index: index,
8512
- id: newItemId,
8513
- type: filter.type,
8514
- template: filter.optionTemplate,
8515
- idTemplate: filter.idTemplate,
8516
- map: filter.map,
8517
- data: item
8518
- });
8519
- }
8520
- });
8521
- const newFilterArray = filters.filter(i => index !== i.index || index === i.index && data.find(d => i.data.id === d.id));
8522
- setFilters(newFilterArray);
8523
- if (onChange && !onApplyFilters) {
8524
- onChange(mapFilters(newFilterArray), newFilterArray);
8525
- }
8432
+ let _data = data;
8433
+ if (!Array.isArray(data)) _data = data ? [data] : [];
8434
+ const filtersWithoutUpdatedField = filters.filter(filter => index !== filter.index);
8435
+ const newUpdatedFilters = _data.map(d => formatFilterItem(index, filter, d));
8436
+ const newFilters = filtersWithoutUpdatedField.concat(newUpdatedFilters);
8437
+ setFilters(newFilters);
8438
+ if (!onApplyFilters) onChange == null ? void 0 : onChange(mapFilters(newFilters), newFilters);
8526
8439
  };
8527
8440
  const handleSortChange = value => {
8528
8441
  setSort(value);
@@ -16654,14 +16567,6 @@ const render = (value, formState) => {
16654
16567
  }
16655
16568
  return mustache.render(value, formState);
16656
16569
  };
16657
- const renderUrl = (value, formState) => {
16658
- if (value === undefined || value === null) {
16659
- return value;
16660
- }
16661
- return decodeHtml$2(mustache.render(value, formState));
16662
- };
16663
- const useRenderUrl = template => useSelectFormState(state => renderUrl(template, state));
16664
- const useRender = template => useSelectFormState(state => render(template, state));
16665
16570
 
16666
16571
  const useQueryTemplateParam = queryTemplate => {
16667
16572
  const selector = useCallback(state => {
@@ -17157,49 +17062,6 @@ const DisableWrapper = ({
17157
17062
  }));
17158
17063
  };
17159
17064
 
17160
- const ImageUploadReadOnly = ({
17161
- formData,
17162
- schema,
17163
- uiSchema: _uiSchema = {
17164
- "ui:options": {}
17165
- }
17166
- }) => {
17167
- const {
17168
- downloadUrl: downloadUrlTemplate,
17169
- extension: extensionTemplate
17170
- } = _uiSchema["ui:options"];
17171
- const downloadUrl = useRenderUrl(downloadUrlTemplate);
17172
- const extension = useRender(extensionTemplate);
17173
- return /*#__PURE__*/jsxs(Fragment, {
17174
- children: [/*#__PURE__*/jsx(Typography, {
17175
- gutterBottom: true,
17176
- variant: "subtitle2",
17177
- children: schema.title
17178
- }), /*#__PURE__*/jsx(Paper, {
17179
- sx: {
17180
- height: 185,
17181
- justifyContent: "center",
17182
- display: "flex",
17183
- padding: 2,
17184
- overflow: "hidden"
17185
- },
17186
- variant: "outlined",
17187
- children: /*#__PURE__*/jsx(Image, {
17188
- src: downloadUrl,
17189
- style: {
17190
- height: "100%",
17191
- width: "auto"
17192
- },
17193
- extension: extension
17194
- })
17195
- })]
17196
- });
17197
- };
17198
- ImageUploadReadOnly.propTypes = {
17199
- schema: PropTypes.any,
17200
- renderedValues: PropTypes.any
17201
- };
17202
-
17203
17065
  const FieldContainer = props => {
17204
17066
  return /*#__PURE__*/jsx(Box$2, _extends({}, props, {
17205
17067
  sx: _extends({}, props.sx, {
@@ -17211,7 +17073,30 @@ const FieldContainer = props => {
17211
17073
  };
17212
17074
  FieldContainer.propTypes = Box$2.propTypes;
17213
17075
 
17214
- registerPlugin(FilePondPluginFileValidateType, FilePondPluginImageExifOrientation, FilePondPluginImagePreview, FilePondPluginGetFile);
17076
+ registerPlugin(FilePondPluginFileValidateType, FilePondPluginFileValidateSize, FilePondPluginImageExifOrientation, FilePondPluginImagePreview, FilePondPluginGetFile);
17077
+
17078
+ // Check enums below
17079
+ // source:https://github.com/pqina/filepond-docs/blob/master/content/patterns/API/filepond-object.md#filepond-status
17080
+ const FILE_STATUS = {
17081
+ INIT: 1,
17082
+ IDLE: 2,
17083
+ PROCESSING_QUEUED: 9,
17084
+ PROCESSING: 3,
17085
+ PROCESSING_COMPLETE: 5,
17086
+ // upload complete
17087
+ PROCESSING_ERROR: 6,
17088
+ PROCESSING_REVERT_ERROR: 10,
17089
+ LOADING: 7,
17090
+ LOAD_ERROR: 8
17091
+ };
17092
+ const FILE_ORIGIN = {
17093
+ INPUT: 1,
17094
+ // add by user
17095
+ LIMBO: 2,
17096
+ // temp file
17097
+ LOCAL: 3 // pre-loaded files
17098
+ };
17099
+
17215
17100
  const Upload = props => {
17216
17101
  const {
17217
17102
  schema,
@@ -17220,67 +17105,108 @@ const Upload = props => {
17220
17105
  "ui:options": {}
17221
17106
  },
17222
17107
  onChange,
17223
- disabled,
17224
- required
17108
+ disabled
17225
17109
  } = props;
17110
+ const emptyValue = uiSchema["ui:emptyValue"] || null;
17226
17111
  const isReadOnly = useReadOnly();
17227
17112
  const {
17228
- documentName: documentNameTemplate,
17229
- downloadUrl: downloadUrlTemplate,
17230
- extension: extensionTemplate,
17231
17113
  uploadDataSource,
17232
- mapUploadResponse,
17233
17114
  acceptedFileTypes,
17234
17115
  message,
17235
- isImage
17236
- } = uiSchema["ui:options"];
17237
- const inputProps = uiSchema == null ? void 0 : uiSchema["ui:props"];
17238
- const documentName = useRender(documentNameTemplate);
17239
- const downloadUrl = useRenderUrl(downloadUrlTemplate);
17240
- useRender(extensionTemplate);
17241
- const [files, setFiles] = useState([]);
17242
- const uploadUrl = useMemo(() => getDataSourceUrl(uploadDataSource), [uploadDataSource]);
17116
+ // TODO: can be handled generic way with HOC
17117
+ isImage = true,
17118
+ // multiple = true, // change to false
17243
17119
 
17244
- // INFO: this state is needed to prevent re-load of file during submit
17245
- const [currentFileId, setCurrentFileId] = useState();
17120
+ isPreviewHidden = false,
17121
+ idTemplate,
17122
+ downloadUrlTemplate,
17123
+ nameTemplate,
17124
+ mapUploadResponseToIdTemplate,
17125
+ maxFiles = 1,
17126
+ maxFileSize = null,
17127
+ maxTotalFileSize = null
17128
+ } = uiSchema["ui:options"];
17246
17129
 
17247
- // TODO: change this to useMemo with help of useLastestDeps
17248
- useEffect(() => {
17249
- if (formData === currentFileId) return;
17250
- const files = [{
17251
- source: documentName || "File",
17252
- options: {
17253
- type: "local",
17254
- metadata: {
17255
- url: downloadUrl
17130
+ // TODO: implement single vs multipe mode, currently only multiple is active
17131
+ // let _formData = formData; if (multiple && (formData === null ||
17132
+ // formData === undefined)) { _formData = [];
17133
+ // }
17134
+ const _formData = formData || [];
17135
+ const initialFiles = useMemo(() => {
17136
+ return _formData.map(({
17137
+ data
17138
+ }) => {
17139
+ const id = mustache.render(idTemplate, data);
17140
+ const downloadUrl = downloadUrlTemplate ? decodeHtml$2(mustache.render(downloadUrlTemplate, data)) : downloadUrlTemplate;
17141
+ const name = mustache.render(nameTemplate, data);
17142
+ return {
17143
+ // INFO: source appears in preview but also needed to identify
17144
+ // the download URL. Check issue:
17145
+ // https://github.com/pqina/filepond/issues/284
17146
+ source: `${name} id:${id}`,
17147
+ options: {
17148
+ type: "local",
17149
+ origin: downloadUrl,
17150
+ // INFO: id is used in getFileIds function
17151
+ metadata: {
17152
+ url: downloadUrl,
17153
+ id
17154
+ }
17256
17155
  }
17257
- }
17258
- }];
17259
- if (formData != undefined) setFiles(files);
17260
- }, [formData]);
17261
- const handleLoad = (source, load, error) => {
17262
- fetch(downloadUrl).then(res => res.blob()).then(res => {
17156
+ };
17157
+ });
17158
+ }, []);
17159
+ const inputProps = uiSchema == null ? void 0 : uiSchema["ui:props"];
17160
+ const filePondRef = useRef();
17161
+ const getFileIds = () => {
17162
+ var _filePondRef$current;
17163
+ return ((_filePondRef$current = filePondRef.current) == null ? void 0 : _filePondRef$current.getFiles().filter(file => {
17164
+ const {
17165
+ origin,
17166
+ status
17167
+ } = file;
17168
+ if (origin === FILE_ORIGIN.LOCAL) return true;
17169
+ if (origin === FILE_ORIGIN.INPUT && status === FILE_STATUS.PROCESSING_COMPLETE) return true;
17170
+ }).map(file => {
17171
+ if (file.origin === FILE_ORIGIN.LOCAL) return file.getMetadata().id;
17172
+ return file.serverId;
17173
+ }).map(i => i.toString())) || [];
17174
+ };
17175
+ const uploadUrl = useMemo(() => getDataSourceUrl(uploadDataSource), [uploadDataSource]);
17176
+ const handleLoad = (source, load, error, progress, abort, headers) => {
17177
+ // INFO: source appears in preview but also needed to identify
17178
+ // the download URL. Check issue:
17179
+ // https://github.com/pqina/filepond/issues/284
17180
+ const file = initialFiles.find(item => item.source === source);
17181
+ const loadUrl = file.options.origin;
17182
+ fetch(loadUrl).then(res => res.blob()).then(res => {
17263
17183
  const file = res.type === "jpeg/jfif" || !res.type ? new Blob([res], {
17264
17184
  type: "image/jpeg"
17265
17185
  }) : res;
17266
- load(file);
17186
+ const preview = isPreviewHidden ? res : file;
17187
+ load(preview);
17267
17188
  }).catch(error);
17189
+
17190
+ // Should expose an abort method so the request can be cancelled
17191
+ return {
17192
+ abort: () => abort()
17193
+ };
17268
17194
  };
17269
17195
  const handleUploadResponse = res => {
17270
17196
  try {
17271
17197
  const jsonRes = JSON.parse(res);
17272
- const fileUuid = mapUploadResponse ? mustache.render(mapUploadResponse.fileUuid, jsonRes) : jsonRes.DATA.fileUuid;
17273
- setCurrentFileId(fileUuid);
17274
- onChange(fileUuid);
17198
+ const id = mustache.render(mapUploadResponseToIdTemplate, jsonRes);
17199
+ return id;
17275
17200
  } catch (err) {
17276
- console.log(err);
17201
+ var _window$logger;
17202
+ (_window$logger = window.logger) == null ? void 0 : _window$logger.sendLog({
17203
+ name: `Upload response could not be parsed. ${err}`,
17204
+ data: res
17205
+ });
17277
17206
  }
17278
17207
  };
17279
- const handleDelete = () => {
17280
- setCurrentFileId();
17281
- setFiles([]);
17282
- onChange();
17283
- };
17208
+
17209
+ // TODO: move to message HOC
17284
17210
  const messageProps = {
17285
17211
  title: (message == null ? void 0 : message.title) || undefined,
17286
17212
  description: (message == null ? void 0 : message.description) || undefined,
@@ -17290,48 +17216,91 @@ const Upload = props => {
17290
17216
  const {
17291
17217
  error
17292
17218
  } = useNotify();
17293
- const filePondProps = {
17294
- acceptedFileTypes: acceptedFileTypes ? acceptedFileTypes : isImage ? ["image/*"] : null,
17295
- files,
17296
- allowMultiple: false,
17297
- server: {
17298
- url: uploadUrl,
17299
- process: {
17300
- method: "POST",
17301
- headers: {
17302
- Methods: "POST"
17303
- },
17304
- onload: handleUploadResponse,
17305
- onerror: e => {
17306
- var _window$logger;
17307
- const message = `The image could not be uploaded.`;
17308
- error(message);
17309
- (_window$logger = window.logger) == null ? void 0 : _window$logger.sendLog({
17310
- name: message,
17311
- data: e
17312
- });
17313
- }
17219
+ const handleFileChange = () => {
17220
+ const ids = getFileIds();
17221
+
17222
+ // TODO: fill the data
17223
+ const value = ids.map(id => ({
17224
+ value: id,
17225
+ data: {}
17226
+ }));
17227
+ if (value.length === 0) onChange(emptyValue);else onChange(value);
17228
+ };
17229
+
17230
+ // TODO: move to memo component
17231
+ const FileUpload = useMemo(() => {
17232
+ const styles = isReadOnly ? {
17233
+ // INFO: hide drop panel and drop panel
17234
+ "div>div>div.filepond--drop-label": {
17235
+ display: "none"
17314
17236
  },
17315
- load: handleLoad,
17316
- revert: handleDelete
17317
- },
17318
- onupdatefiles: files => {
17319
- if (files.length === 0) {
17320
- onChange(undefined);
17237
+ "button.filepond--action-remove-item": {
17238
+ display: "none"
17321
17239
  }
17322
- setFiles(files);
17323
- },
17324
- allowProcess: false,
17325
- disabled: isReadOnly,
17326
- allowDownloadByUrl: true
17327
- };
17328
- const overrideProps = typeof inputProps === "function" ? inputProps(filePondProps) : inputProps;
17240
+ } : null;
17241
+ const getAcceptedFileTypes = () => {
17242
+ if (acceptedFileTypes) return acceptedFileTypes;
17243
+ if (isImage) return ["image/*"];
17244
+ return null;
17245
+ };
17246
+ const filePondProps = {
17247
+ acceptedFileTypes: getAcceptedFileTypes(),
17248
+ files: initialFiles,
17249
+ // files: undefined,
17250
+ allowMultiple: true,
17251
+ server: {
17252
+ url: uploadUrl,
17253
+ process: {
17254
+ method: "POST",
17255
+ headers: {
17256
+ Methods: "POST"
17257
+ },
17258
+ onload: handleUploadResponse,
17259
+ onerror: e => {
17260
+ var _window$logger2;
17261
+ const message = `The image could not be uploaded.`;
17262
+ error(message);
17263
+ (_window$logger2 = window.logger) == null ? void 0 : _window$logger2.sendLog({
17264
+ name: message,
17265
+ data: e
17266
+ });
17267
+ }
17268
+ },
17269
+ load: handleLoad
17270
+ },
17271
+ onprocessfile: () => handleFileChange(),
17272
+ onremovefile: () => handleFileChange(),
17273
+ maxParallelUploads: 3,
17274
+ allowProcess: false,
17275
+ disabled: isReadOnly,
17276
+ allowDownloadByUrl: true,
17277
+ maxFiles: maxFiles,
17278
+ maxFileSize,
17279
+ maxTotalFileSize,
17280
+ // INFO: allowDrop create problem on file type validation //
17281
+ // (check badge form), for preview image allowDrop: false, //
17282
+ // labelIdle: "Click Here to Browse File(s)" //
17283
+ allowFileTypeValidation: false
17284
+ };
17285
+ const overrideProps = typeof inputProps === "function" ? inputProps(filePondProps) : inputProps;
17286
+ return /*#__PURE__*/jsx(Box$1, {
17287
+ sx: styles,
17288
+ children: /*#__PURE__*/jsx(FilePond, _extends({
17289
+ ref: filePondRef
17290
+ }, filePondProps, overrideProps))
17291
+ });
17292
+ }, []);
17293
+
17294
+ // TODO: better implementation
17329
17295
  if (isReadOnly) {
17330
17296
  if (formData == undefined) return /*#__PURE__*/jsx(ReadOnlyView, {
17331
17297
  label: schema.title,
17332
17298
  emptyViewText: "No file uploaded"
17333
17299
  });
17334
- if (isImage) return /*#__PURE__*/jsx(ImageUploadReadOnly, _extends({}, props));
17300
+ return /*#__PURE__*/jsx(ReadOnlyView, {
17301
+ label: schema.title,
17302
+ renderValue: () => FileUpload
17303
+ });
17335
17304
  }
17336
17305
  return /*#__PURE__*/jsxs(FieldContainer, {
17337
17306
  children: [/*#__PURE__*/jsxs(DisableWrapper, {
@@ -17348,7 +17317,7 @@ const Upload = props => {
17348
17317
  sx: {
17349
17318
  marginTop: 1
17350
17319
  },
17351
- children: /*#__PURE__*/jsx(FilePond, _extends({}, filePondProps, overrideProps))
17320
+ children: FileUpload
17352
17321
  })]
17353
17322
  }), message && /*#__PURE__*/jsx(Alert, _extends({}, messageProps))]
17354
17323
  });