@guillotinaweb/react-gmi 0.28.3 → 0.28.4

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.
@@ -1963,6 +1963,167 @@
1963
1963
  });
1964
1964
  Select.displayName = 'Select';
1965
1965
 
1966
+ var formatDate = function formatDate(str) {
1967
+ var d = new Date(str);
1968
+ var minutes = d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes();
1969
+ return d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear() + " " + d.getHours() + ":" + minutes;
1970
+ };
1971
+ var get$1 = function get(obj, path, defValue) {
1972
+ var _pathArray$reduce;
1973
+
1974
+ if (!path) return undefined;
1975
+ var pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g);
1976
+ return (_pathArray$reduce = pathArray.reduce(function (prevObj, key) {
1977
+ return prevObj && prevObj[key];
1978
+ }, obj)) != null ? _pathArray$reduce : defValue;
1979
+ };
1980
+ function getNewId(id) {
1981
+ if (id === void 0) {
1982
+ id = '';
1983
+ }
1984
+
1985
+ var suffix = '-copy-';
1986
+ var rgx = new RegExp("($|" + suffix + "\\d*)");
1987
+ return stringToSlug(id).replace(rgx, function (r) {
1988
+ var num = parseInt(r.replace(suffix, '') || '0');
1989
+ return "" + suffix + (num + 1);
1990
+ });
1991
+ }
1992
+
1993
+ function _catch$1(body, recover) {
1994
+ try {
1995
+ var result = body();
1996
+ } catch (e) {
1997
+ return recover(e);
1998
+ }
1999
+
2000
+ if (result && result.then) {
2001
+ return result.then(void 0, recover);
2002
+ }
2003
+
2004
+ return result;
2005
+ }
2006
+
2007
+ function useVocabulary(vocabularyName, path) {
2008
+ if (path === void 0) {
2009
+ path = null;
2010
+ }
2011
+
2012
+ var traversal = useTraversal();
2013
+
2014
+ var _useSetState = useSetState({
2015
+ data: undefined,
2016
+ loading: false,
2017
+ error: undefined
2018
+ }),
2019
+ vocabulary = _useSetState[0],
2020
+ setVocabulary = _useSetState[1];
2021
+
2022
+ var getPath = function getPath() {
2023
+ if (path) return path;
2024
+ return traversal.path + "@vocabularies/" + vocabularyName;
2025
+ };
2026
+
2027
+ React.useEffect(function () {
2028
+ var getVocabulary = function getVocabulary() {
2029
+ try {
2030
+ var _temp3 = function () {
2031
+ if (vocabularyName && vocabulary.data === undefined && !vocabulary.loading) {
2032
+ var _temp4 = _catch$1(function () {
2033
+ setVocabulary({
2034
+ loading: true
2035
+ });
2036
+ return Promise.resolve(traversal.client.get(getPath())).then(function (data) {
2037
+ return Promise.resolve(data.json()).then(function (dataJson) {
2038
+ setVocabulary({
2039
+ loading: false,
2040
+ data: dataJson
2041
+ });
2042
+ });
2043
+ });
2044
+ }, function (err) {
2045
+ setVocabulary({
2046
+ loading: false,
2047
+ error: err,
2048
+ data: undefined
2049
+ });
2050
+ });
2051
+
2052
+ if (_temp4 && _temp4.then) return _temp4.then(function () {});
2053
+ }
2054
+ }();
2055
+
2056
+ return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(function () {}) : void 0);
2057
+ } catch (e) {
2058
+ return Promise.reject(e);
2059
+ }
2060
+ };
2061
+
2062
+ getVocabulary();
2063
+ }, [vocabularyName, vocabulary, path]);
2064
+ return vocabulary;
2065
+ }
2066
+
2067
+ var SelectVocabulary = React.forwardRef(function (_ref, ref) {
2068
+ var vocabularyName = _ref.vocabularyName,
2069
+ className = _ref.className,
2070
+ classWrap = _ref.classWrap,
2071
+ val = _ref.val,
2072
+ dataTest = _ref.dataTest,
2073
+ multiple = _ref.multiple,
2074
+ onChange = _ref.onChange,
2075
+ id = _ref.id,
2076
+ placeholder = _ref.placeholder;
2077
+ var vocabulary = useVocabulary(vocabularyName);
2078
+
2079
+ var getOptions = function getOptions() {
2080
+ if (get$1(vocabulary, 'data.items', null)) {
2081
+ var vocData = vocabulary.data.items.map(function (item) {
2082
+ return {
2083
+ text: item.title,
2084
+ value: item.token
2085
+ };
2086
+ });
2087
+ return vocData;
2088
+ }
2089
+
2090
+ return [];
2091
+ };
2092
+
2093
+ var getProps = function getProps() {
2094
+ if (multiple) {
2095
+ var currentValue = val || [];
2096
+ return {
2097
+ multiple: true,
2098
+ size: 5,
2099
+ value: currentValue,
2100
+ options: getOptions()
2101
+ };
2102
+ }
2103
+
2104
+ return {
2105
+ value: val != null ? val : '',
2106
+ appendDefault: true,
2107
+ options: getOptions()
2108
+ };
2109
+ };
2110
+
2111
+ if (vocabulary.data === undefined || vocabulary.loading) {
2112
+ return jsxRuntime.jsx("div", {});
2113
+ }
2114
+
2115
+ return jsxRuntime.jsx(Select, _extends({}, getProps(), {
2116
+ className: className,
2117
+ classWrap: classWrap || 'is-fullwidth',
2118
+ dataTest: dataTest,
2119
+ ref: ref,
2120
+ onChange: onChange,
2121
+ id: id,
2122
+ placeholder: placeholder
2123
+ }));
2124
+ });
2125
+ SelectVocabulary.displayName = 'SelectVocabulary';
2126
+
1966
2127
  var setURLParams = function setURLParams(p) {
1967
2128
  return window.history.pushState(0, '0', '' + '?' + p.toString().replace(/%2F/g, '/'));
1968
2129
  };
@@ -3083,33 +3244,6 @@
3083
3244
  }, [events, ref]);
3084
3245
  }
3085
3246
 
3086
- var formatDate = function formatDate(str) {
3087
- var d = new Date(str);
3088
- var minutes = d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes();
3089
- return d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear() + " " + d.getHours() + ":" + minutes;
3090
- };
3091
- var get$1 = function get(obj, path, defValue) {
3092
- var _pathArray$reduce;
3093
-
3094
- if (!path) return undefined;
3095
- var pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g);
3096
- return (_pathArray$reduce = pathArray.reduce(function (prevObj, key) {
3097
- return prevObj && prevObj[key];
3098
- }, obj)) != null ? _pathArray$reduce : defValue;
3099
- };
3100
- function getNewId(id) {
3101
- if (id === void 0) {
3102
- id = '';
3103
- }
3104
-
3105
- var suffix = '-copy-';
3106
- var rgx = new RegExp("($|" + suffix + "\\d*)");
3107
- return stringToSlug(id).replace(rgx, function (r) {
3108
- var num = parseInt(r.replace(suffix, '') || '0');
3109
- return "" + suffix + (num + 1);
3110
- });
3111
- }
3112
-
3113
3247
  function debounce(func, wait) {
3114
3248
  var timeout;
3115
3249
  return function () {
@@ -3439,1136 +3573,1002 @@
3439
3573
  });
3440
3574
  };
3441
3575
 
3442
- var InputList = React.forwardRef(function (_ref, ref) {
3443
- var value = _ref.value,
3444
- onChange = _ref.onChange,
3445
- dataTest = _ref.dataTest,
3446
- id = _ref.id;
3447
- var intl = reactIntl.useIntl();
3576
+ function debounce$1(func, wait) {
3577
+ var timeout;
3578
+ return function () {
3579
+ var context = this;
3580
+ var args = arguments;
3448
3581
 
3449
- var _useState = React.useState(''),
3450
- inputValue = _useState[0],
3451
- setInputValue = _useState[1];
3582
+ var later = function later() {
3583
+ timeout = null;
3584
+ func.apply(context, args);
3585
+ };
3452
3586
 
3453
- var addTags = function addTags(event) {
3454
- if (event.key === 'Enter' && event.target.value !== '') {
3455
- onChange([].concat(value, [event.target.value]));
3456
- setInputValue('');
3457
- }
3587
+ clearTimeout(timeout);
3588
+ timeout = setTimeout(later, wait);
3458
3589
  };
3590
+ }
3459
3591
 
3460
- return jsxRuntime.jsxs("div", {
3461
- className: "control",
3462
- children: [(value != null ? value : []).length > 0 && jsxRuntime.jsx("div", {
3463
- className: "tags",
3464
- children: value.map(function (tag, index) {
3465
- return jsxRuntime.jsxs("div", {
3466
- className: "tag is-info is-medium",
3467
- children: [tag, jsxRuntime.jsx("button", {
3468
- className: "delete is-small",
3469
- type: "button",
3470
- onClick: function onClick() {
3471
- return onChange([].concat(value.filter(function (tag) {
3472
- return value.indexOf(tag) !== index;
3473
- })));
3474
- }
3475
- })]
3476
- }, "input_list_" + tag + "_" + index);
3477
- })
3478
- }), jsxRuntime.jsx(Input, {
3479
- type: "text",
3480
- id: id,
3481
- placeholder: intl.formatMessage({
3482
- id: "press_enter_to_add_value",
3483
- defaultMessage: [{
3484
- "type": 0,
3485
- "value": "Press enter to add value"
3486
- }]
3487
- }),
3488
- onKeyUp: function onKeyUp(event) {
3489
- return addTags(event);
3490
- },
3491
- value: inputValue,
3492
- ref: ref,
3493
- dataTest: dataTest,
3494
- onChange: function onChange(value) {
3495
- setInputValue(value);
3496
- }
3497
- })]
3498
- });
3499
- });
3500
- InputList.displayName = 'InputList';
3501
-
3502
- function Dropdown(_ref) {
3503
- var children = _ref.children,
3504
- disabled = _ref.disabled,
3505
- id = _ref.id,
3506
- isRight = _ref.isRight,
3507
- onChange = _ref.onChange,
3508
- optionDisabledWhen = _ref.optionDisabledWhen,
3509
- options = _ref.options;
3510
- var ref = React.useRef(null);
3592
+ var initialState$1 = {
3593
+ page: 0,
3594
+ items: undefined,
3595
+ loading: false,
3596
+ items_total: 0
3597
+ };
3598
+ var SearchInputList = function SearchInputList(_ref) {
3599
+ var onChange = _ref.onChange,
3600
+ error = _ref.error,
3601
+ errorZoneClassName = _ref.errorZoneClassName,
3602
+ _ref$traversal = _ref.traversal,
3603
+ traversal = _ref$traversal === void 0 ? null : _ref$traversal,
3604
+ _ref$path = _ref.path,
3605
+ path = _ref$path === void 0 ? null : _ref$path,
3606
+ _ref$qs = _ref.qs,
3607
+ qs = _ref$qs === void 0 ? [] : _ref$qs,
3608
+ _ref$queryCondition = _ref.queryCondition,
3609
+ queryCondition = _ref$queryCondition === void 0 ? 'id__in' : _ref$queryCondition,
3610
+ value = _ref.value,
3611
+ _ref$btnClass = _ref.btnClass,
3612
+ btnClass = _ref$btnClass === void 0 ? '' : _ref$btnClass,
3613
+ _ref$dataTestWrapper = _ref.dataTestWrapper,
3614
+ dataTestWrapper = _ref$dataTestWrapper === void 0 ? 'wrapperSearchInputTest' : _ref$dataTestWrapper,
3615
+ _ref$dataTestSearchIn = _ref.dataTestSearchInput,
3616
+ dataTestSearchInput = _ref$dataTestSearchIn === void 0 ? 'searchInputTest' : _ref$dataTestSearchIn,
3617
+ _ref$dataTestItem = _ref.dataTestItem,
3618
+ dataTestItem = _ref$dataTestItem === void 0 ? 'searchInputItemTest' : _ref$dataTestItem,
3619
+ _ref$renderTextItemOp = _ref.renderTextItemOption,
3620
+ renderTextItemOption = _ref$renderTextItemOp === void 0 ? null : _ref$renderTextItemOp,
3621
+ _ref$typeNameQuery = _ref.typeNameQuery,
3622
+ typeNameQuery = _ref$typeNameQuery === void 0 ? null : _ref$typeNameQuery,
3623
+ _ref$labelProperty = _ref.labelProperty,
3624
+ labelProperty = _ref$labelProperty === void 0 ? 'id' : _ref$labelProperty;
3625
+ var intl = reactIntl.useIntl();
3511
3626
 
3512
- var _useState = React.useState(false),
3513
- isActive = _useState[0],
3514
- setIsActive = _useState[1];
3627
+ var _useSetState = useSetState(initialState$1),
3628
+ options = _useSetState[0],
3629
+ setOptions = _useSetState[1];
3515
3630
 
3516
- var position = isRight ? 'is-right' : '';
3517
- var status = isActive ? "dropdown " + position + " is-active" : "dropdown " + position;
3518
- useClickAway(ref, function () {
3519
- setIsActive(false);
3520
- });
3521
- return jsxRuntime.jsxs("div", {
3522
- ref: ref,
3523
- className: status,
3524
- children: [jsxRuntime.jsx("div", {
3525
- className: "dropdown-trigger",
3526
- children: jsxRuntime.jsx("button", {
3527
- className: "button is-size-7",
3528
- onClick: function onClick() {
3529
- return setIsActive(!isActive);
3530
- },
3531
- "aria-haspopup": "true",
3532
- disabled: disabled,
3533
- "aria-controls": id,
3534
- children: children
3535
- })
3536
- }), jsxRuntime.jsx("div", {
3537
- className: "dropdown-menu",
3538
- id: id,
3539
- role: "menu",
3540
- children: jsxRuntime.jsx("div", {
3541
- className: "dropdown-content",
3542
- children: options.map(function (option) {
3543
- var disabled = typeof optionDisabledWhen === 'function' ? optionDisabledWhen(option) : false;
3544
- return jsxRuntime.jsx("a", {
3545
- className: disabled ? 'dropdown-item is-active' : 'dropdown-item',
3546
- "data-test": "dropdownItemTest-" + option.value.toLowerCase(),
3547
- onClick: disabled ? undefined : function () {
3548
- return onChange(option.value);
3549
- },
3550
- style: disabled ? {
3551
- cursor: 'not-allowed',
3552
- color: 'black',
3553
- opacity: 0.5,
3554
- backgroundColor: '#eeeeee'
3555
- } : {},
3556
- children: option.text
3557
- }, option.text);
3558
- })
3559
- })
3560
- })]
3631
+ var _useState = React.useState(undefined),
3632
+ valuesLabel = _useState[0],
3633
+ setValuesLabels = _useState[1];
3634
+
3635
+ var _useState2 = React.useState(false),
3636
+ isOpen = _useState2[0],
3637
+ setIsOpen = _useState2[1];
3638
+
3639
+ var _useState3 = React.useState(''),
3640
+ searchTerm = _useState3[0],
3641
+ setSearchTerm = _useState3[1];
3642
+
3643
+ var inputRef = React.useRef(null);
3644
+ var wrapperRef = React.useRef(null);
3645
+
3646
+ var _useConfig = useConfig(),
3647
+ PageSize = _useConfig.PageSize,
3648
+ SearchEngine = _useConfig.SearchEngine;
3649
+
3650
+ var _useState4 = React.useState(false),
3651
+ isLoadingData = _useState4[0],
3652
+ setIsLoadingData = _useState4[1];
3653
+
3654
+ var _useState5 = React.useState(generateUID('search_input')),
3655
+ uid = _useState5[0];
3656
+
3657
+ useClickAway(wrapperRef, function () {
3658
+ setIsOpen(false);
3561
3659
  });
3562
- }
3563
3660
 
3564
- function EditableField(_ref) {
3565
- var field = _ref.field,
3566
- value = _ref.value,
3567
- ns = _ref.ns,
3568
- _ref$schema = _ref.schema,
3569
- schema = _ref$schema === void 0 ? undefined : _ref$schema,
3570
- modifyContent = _ref.modifyContent,
3571
- required = _ref.required;
3572
- var intl = reactIntl.useIntl();
3573
- var ref = React.useRef();
3661
+ var getHeight = function getHeight() {
3662
+ if (wrapperRef && wrapperRef.current) {
3663
+ return {
3664
+ maxHeight: window.innerHeight - wrapperRef.current.getBoundingClientRect().top - 100 + "px"
3665
+ };
3666
+ }
3574
3667
 
3575
- var _useState = React.useState(false),
3576
- isEdit = _useState[0],
3577
- setEdit = _useState[1];
3668
+ return {
3669
+ maxHeight: 'auto'
3670
+ };
3671
+ };
3578
3672
 
3579
- var _useState2 = React.useState(value),
3580
- val = _useState2[0],
3581
- setValue = _useState2[1];
3673
+ var delayedQuery = React.useCallback(debounce$1(function (value) {
3674
+ return handleSearch(0, false, value);
3675
+ }, 500), []);
3582
3676
 
3583
- var _useCrudContext = useCrudContext(),
3584
- patch = _useCrudContext.patch,
3585
- loading = _useCrudContext.loading,
3586
- Ctx = _useCrudContext.Ctx;
3677
+ var handleSearch = function handleSearch(page, concat, value) {
3678
+ if (page === void 0) {
3679
+ page = 0;
3680
+ }
3587
3681
 
3588
- var _useConfig = useConfig(),
3589
- fieldHaveDeleteButton = _useConfig.fieldHaveDeleteButton;
3682
+ if (concat === void 0) {
3683
+ concat = false;
3684
+ }
3590
3685
 
3591
- var EditComponent = Ctx.registry.get('components', 'EditComponent');
3592
- var RenderFieldComponent = Ctx.registry.get('components', 'RenderFieldComponent');
3593
- React.useEffect(function () {
3594
- if (isEdit && ref.current) {
3595
- ref.current.focus();
3686
+ if (value === void 0) {
3687
+ value = '';
3596
3688
  }
3597
- });
3598
- var canModified = modifyContent && !get$1(schema, 'readonly', false);
3599
3689
 
3600
- var saveField = function saveField(ev) {
3601
3690
  try {
3602
- function _temp3() {
3603
- setEdit(false);
3604
- Ctx.refresh();
3605
- }
3606
-
3607
- if (ev) ev.preventDefault();
3691
+ setOptions({
3692
+ loading: true
3693
+ });
3694
+ var searchTermQs = '';
3695
+ var searchTermParsed = [];
3608
3696
 
3609
- if (!field) {
3610
- Ctx.flash(intl.formatMessage(genericMessages.error_provide_key_name), 'danger');
3611
- return Promise.resolve();
3697
+ if (value !== '') {
3698
+ searchTermParsed = parser(queryCondition + "=" + value);
3612
3699
  }
3613
3700
 
3614
- if (!val && required) {
3615
- Ctx.flash(intl.formatMessage(genericMessages.mandatory_field, {
3616
- field: field
3617
- }), 'danger');
3618
- return Promise.resolve();
3619
- }
3701
+ var _get = traversal.registry.get;
3620
3702
 
3621
- var _temp4 = function () {
3622
- if ((schema == null ? void 0 : schema.widget) === 'file') {
3623
- var _value = val;
3703
+ var fnName = _get('searchEngineQueryParamsFunction', SearchEngine);
3624
3704
 
3625
- if (_value) {
3626
- _value['filename'] = unescape(encodeURIComponent(_value['filename']));
3627
- }
3705
+ var qsParsed = traversal.client[fnName]({
3706
+ path: traversal.path,
3707
+ start: page * PageSize,
3708
+ pageSize: PageSize,
3709
+ withDepth: false
3710
+ });
3711
+ var sortParsed = parser("_sort_des=" + labelProperty);
3712
+ var typeNameParsed = [];
3628
3713
 
3629
- var endpoint = Ctx.path + "@upload/" + field;
3630
- return Promise.resolve(Ctx.client.upload(endpoint, _value)).then(function (req) {
3631
- if (req.status !== 200) {
3632
- Ctx.flash(intl.formatMessage(genericFileMessages.error_upload_file), 'danger');
3633
- } else {
3634
- Ctx.flash(intl.formatMessage(genericFileMessages.file_uploaded), 'success');
3635
- }
3636
- });
3637
- } else {
3638
- var _ns, _ref2, _ref3;
3714
+ if (typeNameQuery) {
3715
+ typeNameParsed = parser("type_name__in=" + typeNameQuery);
3716
+ }
3639
3717
 
3640
- var data = ns ? (_ref2 = {}, _ref2[ns] = (_ns = {}, _ns[field] = val, _ns), _ref2) : (_ref3 = {}, _ref3[field] = val, _ref3);
3641
- return Promise.resolve(patch(data)).then(function (dataPatch) {
3642
- if (dataPatch.isError) {
3643
- Ctx.flash(intl.formatMessage(genericMessages.error_in_field, {
3644
- field: field
3645
- }), 'danger');
3646
- } else {
3647
- Ctx.flash(intl.formatMessage(genericMessages.field_updated, {
3648
- field: field
3649
- }), 'success');
3650
- }
3651
- });
3652
- }
3653
- }();
3718
+ if (qs.length > 0 || searchTermParsed.length > 0 || qsParsed.length > 0 || typeNameParsed.length > 0) {
3719
+ searchTermQs = buildQs([].concat(qs, searchTermParsed, qsParsed, typeNameParsed, sortParsed));
3720
+ }
3654
3721
 
3655
- return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp3) : _temp3(_temp4));
3722
+ return Promise.resolve(traversal.client.search(path ? path : traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false)).then(function (data) {
3723
+ var _data$items_total;
3724
+
3725
+ var newItems = options.items && concat ? [].concat(options.items, data.items) : data.items;
3726
+ setOptions({
3727
+ items: newItems != null ? newItems : [],
3728
+ loading: false,
3729
+ items_total: (_data$items_total = data.items_total) != null ? _data$items_total : 0,
3730
+ page: page
3731
+ });
3732
+ });
3656
3733
  } catch (e) {
3657
3734
  return Promise.reject(e);
3658
3735
  }
3659
3736
  };
3660
3737
 
3661
- var deleteField = function deleteField(ev) {
3738
+ var inicializeLabels = function inicializeLabels() {
3662
3739
  try {
3663
- if (ev) ev.preventDefault();
3664
- return Promise.resolve(function () {
3665
- if ((schema == null ? void 0 : schema.widget) === 'file') {
3666
- var _ns2, _ref4, _ref5;
3740
+ var _temp2 = function () {
3741
+ if (labelProperty !== 'id' && value.length > 0) {
3742
+ setIsLoadingData(true);
3743
+ var searchTermQs = '';
3744
+ var searchTermParsed = ['__or', "id=" + value.join('%26id=')];
3745
+ var getSearch = traversal.registry.get;
3746
+ var fnName = getSearch('searchEngineQueryParamsFunction', SearchEngine);
3747
+ var qsParsed = traversal.client[fnName]({
3748
+ path: traversal.path,
3749
+ start: 0,
3750
+ pageSize: 100,
3751
+ withDepth: false
3752
+ });
3753
+ var typeNameParsed = [];
3667
3754
 
3668
- if (!field || !val && required) {
3669
- Ctx.flash(intl.formatMessage(genericMessages.can_not_delete_field, {
3670
- field: field
3671
- }), 'danger');
3672
- return;
3755
+ if (typeNameQuery) {
3756
+ typeNameParsed = parser("type_name__in=" + typeNameQuery);
3673
3757
  }
3674
3758
 
3675
- var data = ns ? (_ref4 = {}, _ref4[ns] = (_ns2 = {}, _ns2[field] = null, _ns2), _ref4) : (_ref5 = {}, _ref5[field] = null, _ref5);
3676
- return Promise.resolve(patch(data)).then(function (dataPatch) {
3677
- if (dataPatch.isError) {
3678
- Ctx.flash(intl.formatMessage(genericMessages.error_in_field, {
3679
- field: field
3680
- }), 'danger');
3681
- } else {
3682
- Ctx.flash(intl.formatMessage(genericMessages.field_deleted, {
3683
- field: field
3684
- }), 'success');
3685
- }
3759
+ if (qs.length > 0 || searchTermParsed.length > 0 || qsParsed.length > 0 || typeNameParsed.length > 0) {
3760
+ searchTermQs = buildQs([].concat(qs, [searchTermParsed], qsParsed, typeNameParsed));
3761
+ }
3686
3762
 
3687
- setEdit(false);
3688
- Ctx.refresh();
3763
+ return Promise.resolve(traversal.client.search(path ? path : traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false, 0, 100)).then(function (data) {
3764
+ var newValuesLabel = data.items.reduce(function (result, item) {
3765
+ result[item.id] = get$1(item, labelProperty, item.id);
3766
+ return result;
3767
+ }, {});
3768
+ setValuesLabels(newValuesLabel);
3769
+ setIsLoadingData(false);
3689
3770
  });
3690
- } else if ((schema == null ? void 0 : schema.type) === 'string' && schema != null && schema.enum) {
3691
- setValue(null);
3692
- } else if ((schema == null ? void 0 : schema.type) === 'array' && (schema == null ? void 0 : schema.items.type) === 'string') {
3693
- setValue([]);
3694
3771
  }
3695
- }());
3772
+ }();
3773
+
3774
+ return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
3696
3775
  } catch (e) {
3697
3776
  return Promise.reject(e);
3698
3777
  }
3699
3778
  };
3700
3779
 
3701
- return jsxRuntime.jsxs(jsxRuntime.Fragment, {
3702
- children: [!isEdit && jsxRuntime.jsxs("div", {
3703
- className: canModified ? 'editable' : '',
3704
- onClick: function onClick() {
3705
- setEdit(!!canModified);
3706
- },
3707
- "data-test": "editableFieldTest-" + field,
3708
- children: [jsxRuntime.jsx(RenderFieldComponent, {
3709
- schema: schema,
3710
- field: field,
3711
- val: val,
3712
- modifyContent: modifyContent
3713
- }), canModified && jsxRuntime.jsx(Icon, {
3714
- icon: "fas fa-edit"
3715
- })]
3716
- }), isEdit && jsxRuntime.jsxs("div", {
3717
- className: "field",
3718
- "data-test": "editableFieldTest-" + field,
3719
- children: [jsxRuntime.jsx("div", {
3720
- className: "control",
3721
- children: jsxRuntime.jsx(EditComponent, {
3722
- ref: ref,
3723
- schema: schema,
3724
- val: val,
3725
- setValue: setValue,
3726
- dataTest: "editableFieldEditTest"
3727
- })
3728
- }), jsxRuntime.jsxs("div", {
3729
- className: "field is-grouped",
3730
- children: [jsxRuntime.jsx("div", {
3731
- className: "control",
3732
- children: jsxRuntime.jsx(Button, {
3733
- className: "is-small is-primary",
3734
- loading: loading,
3735
- onClick: saveField,
3736
- dataTest: "editableFieldBtnSaveTest",
3737
- children: intl.formatMessage(genericMessages.save)
3738
- })
3739
- }), jsxRuntime.jsx("div", {
3740
- className: "control",
3741
- children: jsxRuntime.jsx(Button, {
3742
- className: "is-small",
3743
- onClick: function onClick() {
3744
- return setEdit(false);
3745
- },
3746
- dataTest: "editableFieldBtnCancelTest",
3747
- children: intl.formatMessage(genericMessages.cancel)
3748
- })
3749
- }), !required && fieldHaveDeleteButton(schema) && jsxRuntime.jsx("div", {
3750
- className: "control",
3751
- children: jsxRuntime.jsx(Button, {
3752
- className: "is-small is-danger",
3753
- onClick: deleteField,
3754
- dataTest: "editableFieldBtnDeleteTest",
3755
- children: intl.formatMessage(genericMessages.delete)
3756
- })
3757
- })]
3758
- })]
3759
- })]
3760
- });
3761
- }
3762
-
3763
- var DownloadField = function DownloadField(_ref) {
3764
- var value = _ref.value;
3765
- var intl = reactIntl.useIntl();
3766
- var Ctx = useTraversal();
3767
- var data = value.data,
3768
- field = value.field;
3769
-
3770
- var getField = function getField(downloadFile) {
3771
- try {
3772
- var endpoint = Ctx.path + "@download/" + field;
3773
- return Promise.resolve(Ctx.client.download(endpoint)).then(function (res) {
3774
- return Promise.resolve(res.blob()).then(function (text) {
3775
- var blob = new Blob([text], {
3776
- type: data.content_type
3777
- });
3778
- var url = window.URL.createObjectURL(blob);
3779
- var link = document.createElement('a');
3780
- link.href = url;
3781
-
3782
- if (downloadFile) {
3783
- link.setAttribute('download', "" + data.filename);
3784
- } else {
3785
- link.setAttribute('target', "_blank");
3786
- }
3780
+ var renderTextItemOptionFn = function renderTextItemOptionFn(item) {
3781
+ if (renderTextItemOption) {
3782
+ return renderTextItemOption(item);
3783
+ }
3787
3784
 
3788
- document.body.appendChild(link);
3789
- link.click();
3790
- setTimeout(function () {
3791
- var _link$parentNode;
3785
+ return get$1(item, labelProperty, item.title) || item['@name'];
3786
+ };
3792
3787
 
3793
- window.URL.revokeObjectURL(url);
3794
- (_link$parentNode = link.parentNode) == null ? void 0 : _link$parentNode.removeChild(link);
3795
- }, 100);
3796
- });
3797
- });
3798
- } catch (e) {
3799
- return Promise.reject(e);
3788
+ React.useEffect(function () {
3789
+ if (!options.loading && !options.items && value.length > 0) {
3790
+ inicializeLabels();
3791
+ } else if (value.length === 0) {
3792
+ setValuesLabels({});
3800
3793
  }
3801
- };
3794
+ }, [path, options.loading, options.items]);
3802
3795
 
3803
- return jsxRuntime.jsxs("div", {
3804
- className: "field",
3796
+ if (isLoadingData || valuesLabel === undefined) {
3797
+ return jsxRuntime.jsx("div", {
3798
+ className: "spinner"
3799
+ });
3800
+ }
3801
+
3802
+ return jsxRuntime.jsxs(jsxRuntime.Fragment, {
3805
3803
  children: [jsxRuntime.jsx("div", {
3806
- className: "label",
3807
- children: data.filename
3804
+ className: "tags mb-2",
3805
+ children: value.map(function (tag, index) {
3806
+ return jsxRuntime.jsxs("div", {
3807
+ className: "tag is-info is-medium",
3808
+ children: [get$1(valuesLabel, tag, tag), jsxRuntime.jsx("button", {
3809
+ className: "delete is-small",
3810
+ onClick: function onClick(ev) {
3811
+ ev.stopPropagation();
3812
+ ev.preventDefault();
3813
+ onChange([].concat(value.filter(function (tag) {
3814
+ return value.indexOf(tag) !== index;
3815
+ })));
3816
+ }
3817
+ })]
3818
+ }, "input_list_" + tag + "_" + index);
3819
+ })
3808
3820
  }), jsxRuntime.jsxs("div", {
3809
- className: "columns",
3821
+ "data-test": dataTestWrapper,
3822
+ ref: wrapperRef,
3823
+ className: "dropdown mb-2 " + (isOpen ? 'is-active' : ''),
3824
+ onBlur: function onBlur(ev) {
3825
+ if (!ev.currentTarget.contains(ev.relatedTarget)) {
3826
+ if (searchTerm !== '') {
3827
+ setSearchTerm('');
3828
+ setOptions(initialState$1);
3829
+ }
3830
+
3831
+ setIsOpen(false);
3832
+ }
3833
+ },
3810
3834
  children: [jsxRuntime.jsx("div", {
3811
- className: "column",
3812
- children: jsxRuntime.jsx("button", {
3813
- className: "button is-small is-primary level-left",
3814
- onClick: function (event) {
3815
- try {
3816
- event.preventDefault();
3817
- event.stopPropagation();
3818
- getField(false);
3819
- return Promise.resolve();
3820
- } catch (e) {
3821
- return Promise.reject(e);
3835
+ className: "dropdown-trigger",
3836
+ children: jsxRuntime.jsxs("button", {
3837
+ className: "button " + btnClass,
3838
+ onClick: function onClick(ev) {
3839
+ ev.preventDefault();
3840
+ setIsOpen(!isOpen);
3841
+
3842
+ if (!options.loading && !options.items) {
3843
+ handleSearch(options.page);
3822
3844
  }
3823
3845
  },
3824
- children: intl.formatMessage(genericMessages.open)
3846
+ "aria-haspopup": "true",
3847
+ "aria-controls": "dropdown-menu",
3848
+ children: [jsxRuntime.jsx("span", {
3849
+ children: intl.formatMessage(genericMessages.choose)
3850
+ }), jsxRuntime.jsx("span", {
3851
+ className: "icon",
3852
+ children: jsxRuntime.jsx("i", {
3853
+ className: "fas fa-angle-down",
3854
+ "aria-hidden": "true"
3855
+ })
3856
+ })]
3825
3857
  })
3826
3858
  }), jsxRuntime.jsx("div", {
3827
- className: "column",
3828
- children: jsxRuntime.jsx("button", {
3829
- className: "button is-small is-primary level-right",
3830
- onClick: function (event) {
3831
- try {
3832
- event.preventDefault();
3833
- event.stopPropagation();
3834
- getField(true);
3835
- return Promise.resolve();
3836
- } catch (e) {
3837
- return Promise.reject(e);
3838
- }
3839
- },
3840
- children: intl.formatMessage(genericMessages.download)
3841
- })
3842
- })]
3859
+ className: "dropdown-menu",
3860
+ id: "dropdown-menu",
3861
+ role: "menu",
3862
+ style: getHeight(),
3863
+ children: jsxRuntime.jsxs("div", {
3864
+ className: "dropdown-content",
3865
+ children: [jsxRuntime.jsx("div", {
3866
+ className: "dropdown-item",
3867
+ children: jsxRuntime.jsx("input", {
3868
+ ref: inputRef,
3869
+ "data-test": dataTestSearchInput,
3870
+ className: "input",
3871
+ type: "text",
3872
+ placeholder: intl.formatMessage(genericMessages.search),
3873
+ value: searchTerm,
3874
+ onChange: function onChange(ev) {
3875
+ delayedQuery(ev.target.value);
3876
+ setSearchTerm(ev.target.value);
3877
+ }
3878
+ })
3879
+ }), jsxRuntime.jsx("hr", {
3880
+ className: "dropdown-divider"
3881
+ }), options.loading && jsxRuntime.jsx(Loading, {}), options.items && options.items.map(function (item) {
3882
+ return jsxRuntime.jsx("div", {
3883
+ className: "dropdown-item editable " + (value.includes(item.id) ? 'is-active' : ''),
3884
+ "data-test": dataTestItem + "-" + item.id,
3885
+ onMouseDown: function onMouseDown(ev) {
3886
+ ev.stopPropagation();
3887
+ ev.preventDefault();
3888
+
3889
+ if (onChange && !value.includes(item.id)) {
3890
+ var _extends2;
3891
+
3892
+ setValuesLabels(_extends({}, valuesLabel, (_extends2 = {}, _extends2[item.id] = get$1(item, labelProperty, item.id), _extends2)));
3893
+ onChange([].concat(value, [item.id]));
3894
+ }
3895
+ },
3896
+ children: renderTextItemOptionFn(item)
3897
+ }, item.path);
3898
+ }), options.items && options.items.length === 0 && jsxRuntime.jsx("div", {
3899
+ className: "dropdown-item",
3900
+ children: intl.formatMessage(genericMessages.no_results)
3901
+ }), options.items && options.items_total > options.items.length && jsxRuntime.jsxs(jsxRuntime.Fragment, {
3902
+ children: [jsxRuntime.jsx("hr", {
3903
+ className: "dropdown-divider"
3904
+ }), jsxRuntime.jsx("div", {
3905
+ className: "dropdown-item editable",
3906
+ onMouseDown: function onMouseDown(ev) {
3907
+ ev.stopPropagation();
3908
+ ev.preventDefault();
3909
+ handleSearch(options.page + 1, true);
3910
+ },
3911
+ children: intl.formatMessage(genericMessages.load_more)
3912
+ })]
3913
+ })]
3914
+ })
3915
+ })]
3916
+ }), error && jsxRuntime.jsx(ErrorZone, {
3917
+ className: errorZoneClassName,
3918
+ id: uid,
3919
+ children: error ? error : ''
3843
3920
  })]
3844
3921
  });
3845
3922
  };
3846
3923
 
3847
- function _catch$1(body, recover) {
3848
- try {
3849
- var result = body();
3850
- } catch (e) {
3851
- return recover(e);
3852
- }
3853
-
3854
- if (result && result.then) {
3855
- return result.then(void 0, recover);
3856
- }
3857
-
3858
- return result;
3859
- }
3860
-
3861
- function useVocabulary(vocabularyName, path) {
3862
- if (path === void 0) {
3863
- path = null;
3864
- }
3865
-
3866
- var traversal = useTraversal();
3924
+ var InputList = React.forwardRef(function (_ref, ref) {
3925
+ var value = _ref.value,
3926
+ onChange = _ref.onChange,
3927
+ dataTest = _ref.dataTest,
3928
+ id = _ref.id;
3929
+ var intl = reactIntl.useIntl();
3867
3930
 
3868
- var _useSetState = useSetState({
3869
- data: undefined,
3870
- loading: false,
3871
- error: undefined
3872
- }),
3873
- vocabulary = _useSetState[0],
3874
- setVocabulary = _useSetState[1];
3931
+ var _useState = React.useState(''),
3932
+ inputValue = _useState[0],
3933
+ setInputValue = _useState[1];
3875
3934
 
3876
- var getPath = function getPath() {
3877
- if (path) return path;
3878
- return traversal.path + "@vocabularies/" + vocabularyName;
3935
+ var addTags = function addTags(event) {
3936
+ if (event.key === 'Enter' && event.target.value !== '') {
3937
+ onChange([].concat(value, [event.target.value]));
3938
+ setInputValue('');
3939
+ }
3879
3940
  };
3880
3941
 
3881
- React.useEffect(function () {
3882
- var getVocabulary = function getVocabulary() {
3883
- try {
3884
- var _temp3 = function () {
3885
- if (vocabularyName && vocabulary.data === undefined && !vocabulary.loading) {
3886
- var _temp4 = _catch$1(function () {
3887
- setVocabulary({
3888
- loading: true
3889
- });
3890
- return Promise.resolve(traversal.client.get(getPath())).then(function (data) {
3891
- return Promise.resolve(data.json()).then(function (dataJson) {
3892
- setVocabulary({
3893
- loading: false,
3894
- data: dataJson
3895
- });
3896
- });
3897
- });
3898
- }, function (err) {
3899
- setVocabulary({
3900
- loading: false,
3901
- error: err,
3902
- data: undefined
3903
- });
3904
- });
3905
-
3906
- if (_temp4 && _temp4.then) return _temp4.then(function () {});
3907
- }
3908
- }();
3909
-
3910
- return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(function () {}) : void 0);
3911
- } catch (e) {
3912
- return Promise.reject(e);
3942
+ return jsxRuntime.jsxs("div", {
3943
+ className: "control",
3944
+ children: [(value != null ? value : []).length > 0 && jsxRuntime.jsx("div", {
3945
+ className: "tags",
3946
+ children: value.map(function (tag, index) {
3947
+ return jsxRuntime.jsxs("div", {
3948
+ className: "tag is-info is-medium",
3949
+ children: [tag, jsxRuntime.jsx("button", {
3950
+ className: "delete is-small",
3951
+ type: "button",
3952
+ onClick: function onClick() {
3953
+ return onChange([].concat(value.filter(function (tag) {
3954
+ return value.indexOf(tag) !== index;
3955
+ })));
3956
+ }
3957
+ })]
3958
+ }, "input_list_" + tag + "_" + index);
3959
+ })
3960
+ }), jsxRuntime.jsx(Input, {
3961
+ type: "text",
3962
+ id: id,
3963
+ placeholder: intl.formatMessage({
3964
+ id: "press_enter_to_add_value",
3965
+ defaultMessage: [{
3966
+ "type": 0,
3967
+ "value": "Press enter to add value"
3968
+ }]
3969
+ }),
3970
+ onKeyUp: function onKeyUp(event) {
3971
+ return addTags(event);
3972
+ },
3973
+ value: inputValue,
3974
+ ref: ref,
3975
+ dataTest: dataTest,
3976
+ onChange: function onChange(value) {
3977
+ setInputValue(value);
3913
3978
  }
3914
- };
3915
-
3916
- getVocabulary();
3917
- }, [vocabularyName, vocabulary, path]);
3918
- return vocabulary;
3919
- }
3920
-
3921
- var plain = ['string', 'number', 'boolean'];
3922
- function RenderField(_ref) {
3923
- var value = _ref.value,
3924
- Widget = _ref.Widget,
3925
- schema = _ref.schema;
3926
- if (value === null || value === undefined) return '';
3927
-
3928
- if (Widget) {
3929
- return jsxRuntime.jsx(Widget, {
3930
- value: value,
3931
- schema: schema
3932
- });
3933
- }
3934
-
3935
- var type = typeof value;
3936
-
3937
- if (plain.includes(type)) {
3938
- return value;
3939
- }
3979
+ })]
3980
+ });
3981
+ });
3982
+ InputList.displayName = 'InputList';
3940
3983
 
3941
- if (type === 'object') {
3942
- if (Array.isArray(value)) {
3943
- return value.map(function (item) {
3944
- return jsxRuntime.jsx("div", {
3945
- children: jsxRuntime.jsx(RenderField, {
3946
- value: item
3947
- })
3948
- }, item);
3949
- });
3950
- }
3984
+ function Dropdown(_ref) {
3985
+ var children = _ref.children,
3986
+ disabled = _ref.disabled,
3987
+ id = _ref.id,
3988
+ isRight = _ref.isRight,
3989
+ onChange = _ref.onChange,
3990
+ optionDisabledWhen = _ref.optionDisabledWhen,
3991
+ options = _ref.options;
3992
+ var ref = React.useRef(null);
3951
3993
 
3952
- return Object.keys(value).map(function (key) {
3953
- return jsxRuntime.jsx(FieldValue, {
3954
- field: get$1(schema, "properties." + key + ".title", key),
3955
- schema: get$1(schema, "properties." + key, {}),
3956
- value: value[key]
3957
- }, key);
3958
- });
3959
- }
3994
+ var _useState = React.useState(false),
3995
+ isActive = _useState[0],
3996
+ setIsActive = _useState[1];
3960
3997
 
3961
- return jsxRuntime.jsxs("p", {
3962
- children: ["No render for ", JSON.stringify(value)]
3998
+ var position = isRight ? 'is-right' : '';
3999
+ var status = isActive ? "dropdown " + position + " is-active" : "dropdown " + position;
4000
+ useClickAway(ref, function () {
4001
+ setIsActive(false);
3963
4002
  });
3964
- }
3965
-
3966
- var FieldValue = function FieldValue(_ref2) {
3967
- var field = _ref2.field,
3968
- value = _ref2.value,
3969
- schema = _ref2.schema;
3970
4003
  return jsxRuntime.jsxs("div", {
3971
- className: "field",
4004
+ ref: ref,
4005
+ className: status,
3972
4006
  children: [jsxRuntime.jsx("div", {
3973
- className: "label",
3974
- children: field
4007
+ className: "dropdown-trigger",
4008
+ children: jsxRuntime.jsx("button", {
4009
+ className: "button is-size-7",
4010
+ onClick: function onClick() {
4011
+ return setIsActive(!isActive);
4012
+ },
4013
+ "aria-haspopup": "true",
4014
+ disabled: disabled,
4015
+ "aria-controls": id,
4016
+ children: children
4017
+ })
3975
4018
  }), jsxRuntime.jsx("div", {
3976
- className: "value",
3977
- children: jsxRuntime.jsx(RenderFieldComponent, {
3978
- val: value,
3979
- schema: schema,
3980
- field: field
4019
+ className: "dropdown-menu",
4020
+ id: id,
4021
+ role: "menu",
4022
+ children: jsxRuntime.jsx("div", {
4023
+ className: "dropdown-content",
4024
+ children: options.map(function (option) {
4025
+ var disabled = typeof optionDisabledWhen === 'function' ? optionDisabledWhen(option) : false;
4026
+ return jsxRuntime.jsx("a", {
4027
+ className: disabled ? 'dropdown-item is-active' : 'dropdown-item',
4028
+ "data-test": "dropdownItemTest-" + option.value.toLowerCase(),
4029
+ onClick: disabled ? undefined : function () {
4030
+ return onChange(option.value);
4031
+ },
4032
+ style: disabled ? {
4033
+ cursor: 'not-allowed',
4034
+ color: 'black',
4035
+ opacity: 0.5,
4036
+ backgroundColor: '#eeeeee'
4037
+ } : {},
4038
+ children: option.text
4039
+ }, option.text);
4040
+ })
3981
4041
  })
3982
4042
  })]
3983
4043
  });
3984
- };
3985
-
3986
- var DEFAULT_VALUE_NO_EDITABLE_FIELD = ' -- ';
3987
-
3988
- var getDefaultValueEditableField = function getDefaultValueEditableField(intl) {
3989
- return intl.formatMessage({
3990
- id: "default_value_editable_field",
3991
- defaultMessage: [{
3992
- "type": 0,
3993
- "value": "Click to edit"
3994
- }]
3995
- });
3996
- };
4044
+ }
3997
4045
 
3998
- var SearchRenderField = function SearchRenderField(_ref3) {
3999
- var schema = _ref3.schema,
4000
- value = _ref3.value,
4001
- modifyContent = _ref3.modifyContent;
4046
+ function EditableField(_ref) {
4047
+ var field = _ref.field,
4048
+ value = _ref.value,
4049
+ ns = _ref.ns,
4050
+ _ref$schema = _ref.schema,
4051
+ schema = _ref$schema === void 0 ? undefined : _ref$schema,
4052
+ modifyContent = _ref.modifyContent,
4053
+ required = _ref.required;
4002
4054
  var intl = reactIntl.useIntl();
4055
+ var ref = React.useRef();
4003
4056
 
4004
- var _useState = React.useState([]),
4005
- valuesLabels = _useState[0],
4006
- setValuesLabels = _useState[1];
4057
+ var _useState = React.useState(false),
4058
+ isEdit = _useState[0],
4059
+ setEdit = _useState[1];
4007
4060
 
4008
- var _useState2 = React.useState(false),
4009
- isLoadingData = _useState2[0],
4010
- setIsLoadingData = _useState2[1];
4061
+ var _useState2 = React.useState(value),
4062
+ val = _useState2[0],
4063
+ setValue = _useState2[1];
4011
4064
 
4012
- var traversal = useTraversal();
4065
+ var _useCrudContext = useCrudContext(),
4066
+ patch = _useCrudContext.patch,
4067
+ loading = _useCrudContext.loading,
4068
+ Ctx = _useCrudContext.Ctx;
4013
4069
 
4014
4070
  var _useConfig = useConfig(),
4015
- SearchEngine = _useConfig.SearchEngine;
4071
+ fieldHaveDeleteButton = _useConfig.fieldHaveDeleteButton;
4016
4072
 
4017
- var DEFAULT_VALUE_EDITABLE_FIELD = getDefaultValueEditableField(intl);
4073
+ var EditComponent = Ctx.registry.get('components', 'EditComponent');
4074
+ var RenderFieldComponent = Ctx.registry.get('components', 'RenderFieldComponent');
4018
4075
  React.useEffect(function () {
4019
- var fetchData = function fetchData(valuesToSearch) {
4020
- try {
4021
- setIsLoadingData(true);
4022
- var searchTermQs = '';
4023
- var searchTermParsed = ['__or', "id=" + valuesToSearch.join('%26id=')];
4024
- var getSearch = traversal.registry.get;
4025
- var fnName = getSearch('searchEngineQueryParamsFunction', SearchEngine);
4026
- var qsParsed = traversal.client[fnName]({
4027
- path: traversal.path,
4028
- start: 0,
4029
- pageSize: 100,
4030
- withDepth: false
4031
- });
4032
-
4033
- if (searchTermParsed.length > 0 || qsParsed.length > 0) {
4034
- searchTermQs = buildQs([searchTermParsed].concat(qsParsed));
4035
- }
4036
-
4037
- return Promise.resolve(traversal.client.search(traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false, 0, 100)).then(function (data) {
4038
- var newValuesLabel = data.items.map(function (item) {
4039
- var _schema$labelProperty;
4040
-
4041
- return get$1(item, (_schema$labelProperty = schema == null ? void 0 : schema.labelProperty) != null ? _schema$labelProperty : 'title', item.id);
4042
- });
4043
- setValuesLabels(newValuesLabel);
4044
- setIsLoadingData(false);
4045
- });
4046
- } catch (e) {
4047
- return Promise.reject(e);
4048
- }
4049
- };
4050
-
4051
- var valuesToSearch = value;
4052
-
4053
- if (typeof valuesToSearch === 'string') {
4054
- valuesToSearch = [valuesToSearch];
4055
- }
4056
-
4057
- if (valuesToSearch !== undefined && valuesToSearch.length > 0) {
4058
- fetchData(valuesToSearch);
4059
- } else {
4060
- setValuesLabels([]);
4076
+ if (isEdit && ref.current) {
4077
+ ref.current.focus();
4061
4078
  }
4062
- }, [value]);
4079
+ });
4080
+ var canModified = modifyContent && !get$1(schema, 'readonly', false);
4063
4081
 
4064
- var getRenderValue = function getRenderValue() {
4065
- if (value === undefined) {
4066
- if (modifyContent) {
4067
- return DEFAULT_VALUE_EDITABLE_FIELD;
4082
+ var saveField = function saveField(ev) {
4083
+ try {
4084
+ function _temp3() {
4085
+ setEdit(false);
4086
+ Ctx.refresh();
4068
4087
  }
4069
4088
 
4070
- return DEFAULT_VALUE_NO_EDITABLE_FIELD;
4071
- }
4072
-
4073
- if (isLoadingData) {
4074
- return 'Loading...';
4075
- }
4076
-
4077
- return valuesLabels;
4078
- };
4089
+ if (ev) ev.preventDefault();
4079
4090
 
4080
- return jsxRuntime.jsx(RenderField, {
4081
- value: getRenderValue()
4082
- });
4083
- };
4084
- var VocabularyRenderField = function VocabularyRenderField(_ref4) {
4085
- var _schema$items;
4091
+ if (!field) {
4092
+ Ctx.flash(intl.formatMessage(genericMessages.error_provide_key_name), 'danger');
4093
+ return Promise.resolve();
4094
+ }
4086
4095
 
4087
- var schema = _ref4.schema,
4088
- value = _ref4.value,
4089
- modifyContent = _ref4.modifyContent;
4090
- var intl = reactIntl.useIntl();
4091
- var DEFAULT_VALUE_EDITABLE_FIELD = getDefaultValueEditableField(intl);
4092
- var vocabularyName = (schema == null ? void 0 : (_schema$items = schema.items) == null ? void 0 : _schema$items.vocabularyName) || (schema == null ? void 0 : schema.vocabularyName);
4093
- var vocabulary = useVocabulary(vocabularyName);
4096
+ if (!val && required) {
4097
+ Ctx.flash(intl.formatMessage(genericMessages.mandatory_field, {
4098
+ field: field
4099
+ }), 'danger');
4100
+ return Promise.resolve();
4101
+ }
4094
4102
 
4095
- var getRenderProps = function getRenderProps() {
4096
- var renderProps = {
4097
- value: value != null ? value : modifyContent ? DEFAULT_VALUE_EDITABLE_FIELD : DEFAULT_VALUE_NO_EDITABLE_FIELD
4098
- };
4103
+ var _temp4 = function () {
4104
+ if ((schema == null ? void 0 : schema.widget) === 'file') {
4105
+ var _value = val;
4099
4106
 
4100
- if (schema != null && schema.vocabularyName) {
4101
- var _vocabularyValue$titl;
4107
+ if (_value) {
4108
+ _value['filename'] = unescape(encodeURIComponent(_value['filename']));
4109
+ }
4102
4110
 
4103
- var vocabularyValue = get$1(vocabulary, 'data.items', []).find(function (item) {
4104
- return item.token === value;
4105
- });
4106
- renderProps['value'] = (_vocabularyValue$titl = vocabularyValue == null ? void 0 : vocabularyValue.title) != null ? _vocabularyValue$titl : '';
4107
- } else {
4108
- var _renderProps$value;
4111
+ var endpoint = Ctx.path + "@upload/" + field;
4112
+ return Promise.resolve(Ctx.client.upload(endpoint, _value)).then(function (req) {
4113
+ if (req.status !== 200) {
4114
+ Ctx.flash(intl.formatMessage(genericFileMessages.error_upload_file), 'danger');
4115
+ } else {
4116
+ Ctx.flash(intl.formatMessage(genericFileMessages.file_uploaded), 'success');
4117
+ }
4118
+ });
4119
+ } else {
4120
+ var _ns, _ref2, _ref3;
4109
4121
 
4110
- renderProps['value'] = ((_renderProps$value = renderProps['value']) != null ? _renderProps$value : []).map(function (value) {
4111
- var _get$find$title, _get$find;
4122
+ var data = ns ? (_ref2 = {}, _ref2[ns] = (_ns = {}, _ns[field] = val, _ns), _ref2) : (_ref3 = {}, _ref3[field] = val, _ref3);
4123
+ return Promise.resolve(patch(data)).then(function (dataPatch) {
4124
+ if (dataPatch.isError) {
4125
+ Ctx.flash(intl.formatMessage(genericMessages.error_in_field, {
4126
+ field: field
4127
+ }), 'danger');
4128
+ } else {
4129
+ Ctx.flash(intl.formatMessage(genericMessages.field_updated, {
4130
+ field: field
4131
+ }), 'success');
4132
+ }
4133
+ });
4134
+ }
4135
+ }();
4112
4136
 
4113
- return (_get$find$title = (_get$find = get$1(vocabulary, 'data.items', []).find(function (item) {
4114
- return item.token === value;
4115
- })) == null ? void 0 : _get$find.title) != null ? _get$find$title : '';
4116
- });
4137
+ return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp3) : _temp3(_temp4));
4138
+ } catch (e) {
4139
+ return Promise.reject(e);
4117
4140
  }
4118
-
4119
- return renderProps;
4120
4141
  };
4121
4142
 
4122
- return jsxRuntime.jsx(RenderField, _extends({}, getRenderProps()));
4123
- };
4124
- function RenderFieldComponent(_ref5) {
4125
- var schema = _ref5.schema,
4126
- field = _ref5.field,
4127
- val = _ref5.val,
4128
- modifyContent = _ref5.modifyContent;
4129
- var intl = reactIntl.useIntl();
4130
- var DEFAULT_VALUE_EDITABLE_FIELD = getDefaultValueEditableField(intl);
4131
-
4132
- var getRenderProps = function getRenderProps() {
4133
- var _schema$items2;
4143
+ var deleteField = function deleteField(ev) {
4144
+ try {
4145
+ if (ev) ev.preventDefault();
4146
+ return Promise.resolve(function () {
4147
+ if ((schema == null ? void 0 : schema.widget) === 'file') {
4148
+ var _ns2, _ref4, _ref5;
4134
4149
 
4135
- var renderProps = {
4136
- value: val != null ? val : modifyContent ? DEFAULT_VALUE_EDITABLE_FIELD : DEFAULT_VALUE_NO_EDITABLE_FIELD,
4137
- schema: schema
4138
- };
4150
+ if (!field || !val && required) {
4151
+ Ctx.flash(intl.formatMessage(genericMessages.can_not_delete_field, {
4152
+ field: field
4153
+ }), 'danger');
4154
+ return;
4155
+ }
4139
4156
 
4140
- if (val && (schema == null ? void 0 : schema.widget) === 'file') {
4141
- renderProps['value'] = {
4142
- data: val,
4143
- field: field
4144
- };
4145
- renderProps['Widget'] = DownloadField;
4146
- } else if ((schema == null ? void 0 : schema.type) === 'boolean') {
4147
- var _val$toString;
4157
+ var data = ns ? (_ref4 = {}, _ref4[ns] = (_ns2 = {}, _ns2[field] = null, _ns2), _ref4) : (_ref5 = {}, _ref5[field] = null, _ref5);
4158
+ return Promise.resolve(patch(data)).then(function (dataPatch) {
4159
+ if (dataPatch.isError) {
4160
+ Ctx.flash(intl.formatMessage(genericMessages.error_in_field, {
4161
+ field: field
4162
+ }), 'danger');
4163
+ } else {
4164
+ Ctx.flash(intl.formatMessage(genericMessages.field_deleted, {
4165
+ field: field
4166
+ }), 'success');
4167
+ }
4148
4168
 
4149
- renderProps['value'] = (_val$toString = val == null ? void 0 : val.toString()) != null ? _val$toString : renderProps['value'];
4150
- } else if (val && (schema == null ? void 0 : schema.type) === 'datetime') {
4151
- renderProps['value'] = new Date(val).toLocaleString();
4152
- } else if (schema != null && (_schema$items2 = schema.items) != null && _schema$items2.vocabularyName || schema != null && schema.vocabularyName) {
4153
- renderProps['Widget'] = VocabularyRenderField;
4154
- } else if ((schema == null ? void 0 : schema.widget) === 'search' || (schema == null ? void 0 : schema.widget) === 'search_list') {
4155
- renderProps['Widget'] = SearchRenderField;
4156
- renderProps['value'] = val;
4169
+ setEdit(false);
4170
+ Ctx.refresh();
4171
+ });
4172
+ } else if ((schema == null ? void 0 : schema.type) === 'string' && schema != null && schema.enum) {
4173
+ setValue(null);
4174
+ } else if ((schema == null ? void 0 : schema.type) === 'array' && (schema == null ? void 0 : schema.items.type) === 'string') {
4175
+ setValue([]);
4176
+ }
4177
+ }());
4178
+ } catch (e) {
4179
+ return Promise.reject(e);
4157
4180
  }
4158
-
4159
- return renderProps;
4160
4181
  };
4161
4182
 
4162
- return jsxRuntime.jsx(RenderField, _extends({}, getRenderProps()));
4183
+ return jsxRuntime.jsxs(jsxRuntime.Fragment, {
4184
+ children: [!isEdit && jsxRuntime.jsxs("div", {
4185
+ className: canModified ? 'editable' : '',
4186
+ onClick: function onClick() {
4187
+ setEdit(!!canModified);
4188
+ },
4189
+ "data-test": "editableFieldTest-" + field,
4190
+ children: [jsxRuntime.jsx(RenderFieldComponent, {
4191
+ schema: schema,
4192
+ field: field,
4193
+ val: val,
4194
+ modifyContent: modifyContent
4195
+ }), canModified && jsxRuntime.jsx(Icon, {
4196
+ icon: "fas fa-edit"
4197
+ })]
4198
+ }), isEdit && jsxRuntime.jsxs("div", {
4199
+ className: "field",
4200
+ "data-test": "editableFieldTest-" + field,
4201
+ children: [jsxRuntime.jsx("div", {
4202
+ className: "control",
4203
+ children: jsxRuntime.jsx(EditComponent, {
4204
+ ref: ref,
4205
+ schema: schema,
4206
+ val: val,
4207
+ setValue: setValue,
4208
+ dataTest: "editableFieldEditTest"
4209
+ })
4210
+ }), jsxRuntime.jsxs("div", {
4211
+ className: "field is-grouped",
4212
+ children: [jsxRuntime.jsx("div", {
4213
+ className: "control",
4214
+ children: jsxRuntime.jsx(Button, {
4215
+ className: "is-small is-primary",
4216
+ loading: loading,
4217
+ onClick: saveField,
4218
+ dataTest: "editableFieldBtnSaveTest",
4219
+ children: intl.formatMessage(genericMessages.save)
4220
+ })
4221
+ }), jsxRuntime.jsx("div", {
4222
+ className: "control",
4223
+ children: jsxRuntime.jsx(Button, {
4224
+ className: "is-small",
4225
+ onClick: function onClick() {
4226
+ return setEdit(false);
4227
+ },
4228
+ dataTest: "editableFieldBtnCancelTest",
4229
+ children: intl.formatMessage(genericMessages.cancel)
4230
+ })
4231
+ }), !required && fieldHaveDeleteButton(schema) && jsxRuntime.jsx("div", {
4232
+ className: "control",
4233
+ children: jsxRuntime.jsx(Button, {
4234
+ className: "is-small is-danger",
4235
+ onClick: deleteField,
4236
+ dataTest: "editableFieldBtnDeleteTest",
4237
+ children: intl.formatMessage(genericMessages.delete)
4238
+ })
4239
+ })]
4240
+ })]
4241
+ })]
4242
+ });
4163
4243
  }
4164
4244
 
4165
- var SelectVocabulary = React.forwardRef(function (_ref, ref) {
4166
- var vocabularyName = _ref.vocabularyName,
4167
- className = _ref.className,
4168
- classWrap = _ref.classWrap,
4169
- val = _ref.val,
4170
- dataTest = _ref.dataTest,
4171
- multiple = _ref.multiple,
4172
- onChange = _ref.onChange,
4173
- id = _ref.id,
4174
- placeholder = _ref.placeholder;
4175
- var vocabulary = useVocabulary(vocabularyName);
4245
+ var DownloadField = function DownloadField(_ref) {
4246
+ var value = _ref.value;
4247
+ var intl = reactIntl.useIntl();
4248
+ var Ctx = useTraversal();
4249
+ var data = value.data,
4250
+ field = value.field;
4176
4251
 
4177
- var getOptions = function getOptions() {
4178
- if (get$1(vocabulary, 'data.items', null)) {
4179
- var vocData = vocabulary.data.items.map(function (item) {
4180
- return {
4181
- text: item.title,
4182
- value: item.token
4183
- };
4184
- });
4185
- return vocData;
4186
- }
4252
+ var getField = function getField(downloadFile) {
4253
+ try {
4254
+ var endpoint = Ctx.path + "@download/" + field;
4255
+ return Promise.resolve(Ctx.client.download(endpoint)).then(function (res) {
4256
+ return Promise.resolve(res.blob()).then(function (text) {
4257
+ var blob = new Blob([text], {
4258
+ type: data.content_type
4259
+ });
4260
+ var url = window.URL.createObjectURL(blob);
4261
+ var link = document.createElement('a');
4262
+ link.href = url;
4187
4263
 
4188
- return [];
4189
- };
4264
+ if (downloadFile) {
4265
+ link.setAttribute('download', "" + data.filename);
4266
+ } else {
4267
+ link.setAttribute('target', "_blank");
4268
+ }
4190
4269
 
4191
- var getProps = function getProps() {
4192
- if (multiple) {
4193
- var currentValue = val || [];
4194
- return {
4195
- multiple: true,
4196
- size: 5,
4197
- value: currentValue,
4198
- options: getOptions()
4199
- };
4200
- }
4270
+ document.body.appendChild(link);
4271
+ link.click();
4272
+ setTimeout(function () {
4273
+ var _link$parentNode;
4201
4274
 
4202
- return {
4203
- value: val != null ? val : '',
4204
- appendDefault: true,
4205
- options: getOptions()
4206
- };
4275
+ window.URL.revokeObjectURL(url);
4276
+ (_link$parentNode = link.parentNode) == null ? void 0 : _link$parentNode.removeChild(link);
4277
+ }, 100);
4278
+ });
4279
+ });
4280
+ } catch (e) {
4281
+ return Promise.reject(e);
4282
+ }
4207
4283
  };
4208
4284
 
4209
- if (vocabulary.data === undefined || vocabulary.loading) {
4210
- return jsxRuntime.jsx("div", {});
4285
+ return jsxRuntime.jsxs("div", {
4286
+ className: "field",
4287
+ children: [jsxRuntime.jsx("div", {
4288
+ className: "label",
4289
+ children: data.filename
4290
+ }), jsxRuntime.jsxs("div", {
4291
+ className: "columns",
4292
+ children: [jsxRuntime.jsx("div", {
4293
+ className: "column",
4294
+ children: jsxRuntime.jsx("button", {
4295
+ className: "button is-small is-primary level-left",
4296
+ onClick: function (event) {
4297
+ try {
4298
+ event.preventDefault();
4299
+ event.stopPropagation();
4300
+ getField(false);
4301
+ return Promise.resolve();
4302
+ } catch (e) {
4303
+ return Promise.reject(e);
4304
+ }
4305
+ },
4306
+ children: intl.formatMessage(genericMessages.open)
4307
+ })
4308
+ }), jsxRuntime.jsx("div", {
4309
+ className: "column",
4310
+ children: jsxRuntime.jsx("button", {
4311
+ className: "button is-small is-primary level-right",
4312
+ onClick: function (event) {
4313
+ try {
4314
+ event.preventDefault();
4315
+ event.stopPropagation();
4316
+ getField(true);
4317
+ return Promise.resolve();
4318
+ } catch (e) {
4319
+ return Promise.reject(e);
4320
+ }
4321
+ },
4322
+ children: intl.formatMessage(genericMessages.download)
4323
+ })
4324
+ })]
4325
+ })]
4326
+ });
4327
+ };
4328
+
4329
+ var plain = ['string', 'number', 'boolean'];
4330
+ function RenderField(_ref) {
4331
+ var value = _ref.value,
4332
+ Widget = _ref.Widget,
4333
+ schema = _ref.schema;
4334
+ if (value === null || value === undefined) return '';
4335
+
4336
+ if (Widget) {
4337
+ return jsxRuntime.jsx(Widget, {
4338
+ value: value,
4339
+ schema: schema
4340
+ });
4211
4341
  }
4212
4342
 
4213
- return jsxRuntime.jsx(Select, _extends({}, getProps(), {
4214
- className: className,
4215
- classWrap: classWrap || 'is-fullwidth',
4216
- dataTest: dataTest,
4217
- ref: ref,
4218
- onChange: onChange,
4219
- id: id,
4220
- placeholder: placeholder
4221
- }));
4222
- });
4223
- SelectVocabulary.displayName = 'SelectVocabulary';
4343
+ var type = typeof value;
4224
4344
 
4225
- function debounce$1(func, wait) {
4226
- var timeout;
4227
- return function () {
4228
- var context = this;
4229
- var args = arguments;
4345
+ if (plain.includes(type)) {
4346
+ return value;
4347
+ }
4230
4348
 
4231
- var later = function later() {
4232
- timeout = null;
4233
- func.apply(context, args);
4234
- };
4349
+ if (type === 'object') {
4350
+ if (Array.isArray(value)) {
4351
+ return value.map(function (item) {
4352
+ return jsxRuntime.jsx("div", {
4353
+ children: jsxRuntime.jsx(RenderField, {
4354
+ value: item
4355
+ })
4356
+ }, item);
4357
+ });
4358
+ }
4235
4359
 
4236
- clearTimeout(timeout);
4237
- timeout = setTimeout(later, wait);
4238
- };
4360
+ return Object.keys(value).map(function (key) {
4361
+ return jsxRuntime.jsx(FieldValue, {
4362
+ field: get$1(schema, "properties." + key + ".title", key),
4363
+ schema: get$1(schema, "properties." + key, {}),
4364
+ value: value[key]
4365
+ }, key);
4366
+ });
4367
+ }
4368
+
4369
+ return jsxRuntime.jsxs("p", {
4370
+ children: ["No render for ", JSON.stringify(value)]
4371
+ });
4239
4372
  }
4240
4373
 
4241
- var initialState$1 = {
4242
- page: 0,
4243
- items: undefined,
4244
- loading: false,
4245
- items_total: 0
4374
+ var FieldValue = function FieldValue(_ref2) {
4375
+ var field = _ref2.field,
4376
+ value = _ref2.value,
4377
+ schema = _ref2.schema;
4378
+ return jsxRuntime.jsxs("div", {
4379
+ className: "field",
4380
+ children: [jsxRuntime.jsx("div", {
4381
+ className: "label",
4382
+ children: field
4383
+ }), jsxRuntime.jsx("div", {
4384
+ className: "value",
4385
+ children: jsxRuntime.jsx(RenderFieldComponent, {
4386
+ val: value,
4387
+ schema: schema,
4388
+ field: field
4389
+ })
4390
+ })]
4391
+ });
4246
4392
  };
4247
- var SearchInputList = function SearchInputList(_ref) {
4248
- var onChange = _ref.onChange,
4249
- error = _ref.error,
4250
- errorZoneClassName = _ref.errorZoneClassName,
4251
- _ref$traversal = _ref.traversal,
4252
- traversal = _ref$traversal === void 0 ? null : _ref$traversal,
4253
- _ref$path = _ref.path,
4254
- path = _ref$path === void 0 ? null : _ref$path,
4255
- _ref$qs = _ref.qs,
4256
- qs = _ref$qs === void 0 ? [] : _ref$qs,
4257
- _ref$queryCondition = _ref.queryCondition,
4258
- queryCondition = _ref$queryCondition === void 0 ? 'id__in' : _ref$queryCondition,
4259
- value = _ref.value,
4260
- _ref$btnClass = _ref.btnClass,
4261
- btnClass = _ref$btnClass === void 0 ? '' : _ref$btnClass,
4262
- _ref$dataTestWrapper = _ref.dataTestWrapper,
4263
- dataTestWrapper = _ref$dataTestWrapper === void 0 ? 'wrapperSearchInputTest' : _ref$dataTestWrapper,
4264
- _ref$dataTestSearchIn = _ref.dataTestSearchInput,
4265
- dataTestSearchInput = _ref$dataTestSearchIn === void 0 ? 'searchInputTest' : _ref$dataTestSearchIn,
4266
- _ref$dataTestItem = _ref.dataTestItem,
4267
- dataTestItem = _ref$dataTestItem === void 0 ? 'searchInputItemTest' : _ref$dataTestItem,
4268
- _ref$renderTextItemOp = _ref.renderTextItemOption,
4269
- renderTextItemOption = _ref$renderTextItemOp === void 0 ? null : _ref$renderTextItemOp,
4270
- _ref$typeNameQuery = _ref.typeNameQuery,
4271
- typeNameQuery = _ref$typeNameQuery === void 0 ? null : _ref$typeNameQuery,
4272
- _ref$labelProperty = _ref.labelProperty,
4273
- labelProperty = _ref$labelProperty === void 0 ? 'id' : _ref$labelProperty;
4274
- var intl = reactIntl.useIntl();
4275
4393
 
4276
- var _useSetState = useSetState(initialState$1),
4277
- options = _useSetState[0],
4278
- setOptions = _useSetState[1];
4394
+ var DEFAULT_VALUE_NO_EDITABLE_FIELD = ' -- ';
4279
4395
 
4280
- var _useState = React.useState(undefined),
4281
- valuesLabel = _useState[0],
4396
+ var getDefaultValueEditableField = function getDefaultValueEditableField(intl) {
4397
+ return intl.formatMessage({
4398
+ id: "default_value_editable_field",
4399
+ defaultMessage: [{
4400
+ "type": 0,
4401
+ "value": "Click to edit"
4402
+ }]
4403
+ });
4404
+ };
4405
+
4406
+ var SearchRenderField = function SearchRenderField(_ref3) {
4407
+ var schema = _ref3.schema,
4408
+ value = _ref3.value,
4409
+ modifyContent = _ref3.modifyContent;
4410
+ var intl = reactIntl.useIntl();
4411
+
4412
+ var _useState = React.useState([]),
4413
+ valuesLabels = _useState[0],
4282
4414
  setValuesLabels = _useState[1];
4283
4415
 
4284
4416
  var _useState2 = React.useState(false),
4285
- isOpen = _useState2[0],
4286
- setIsOpen = _useState2[1];
4287
-
4288
- var _useState3 = React.useState(''),
4289
- searchTerm = _useState3[0],
4290
- setSearchTerm = _useState3[1];
4417
+ isLoadingData = _useState2[0],
4418
+ setIsLoadingData = _useState2[1];
4291
4419
 
4292
- var inputRef = React.useRef(null);
4293
- var wrapperRef = React.useRef(null);
4420
+ var traversal = useTraversal();
4294
4421
 
4295
4422
  var _useConfig = useConfig(),
4296
- PageSize = _useConfig.PageSize,
4297
4423
  SearchEngine = _useConfig.SearchEngine;
4298
4424
 
4299
- var _useState4 = React.useState(false),
4300
- isLoadingData = _useState4[0],
4301
- setIsLoadingData = _useState4[1];
4302
-
4303
- var _useState5 = React.useState(generateUID('search_input')),
4304
- uid = _useState5[0];
4425
+ var DEFAULT_VALUE_EDITABLE_FIELD = getDefaultValueEditableField(intl);
4426
+ React.useEffect(function () {
4427
+ var fetchData = function fetchData(valuesToSearch) {
4428
+ try {
4429
+ setIsLoadingData(true);
4430
+ var searchTermQs = '';
4431
+ var searchTermParsed = ['__or', "id=" + valuesToSearch.join('%26id=')];
4432
+ var getSearch = traversal.registry.get;
4433
+ var fnName = getSearch('searchEngineQueryParamsFunction', SearchEngine);
4434
+ var qsParsed = traversal.client[fnName]({
4435
+ path: traversal.path,
4436
+ start: 0,
4437
+ pageSize: 100,
4438
+ withDepth: false
4439
+ });
4305
4440
 
4306
- useClickAway(wrapperRef, function () {
4307
- setIsOpen(false);
4308
- });
4441
+ if (searchTermParsed.length > 0 || qsParsed.length > 0) {
4442
+ searchTermQs = buildQs([searchTermParsed].concat(qsParsed));
4443
+ }
4309
4444
 
4310
- var getHeight = function getHeight() {
4311
- if (wrapperRef && wrapperRef.current) {
4312
- return {
4313
- maxHeight: window.innerHeight - wrapperRef.current.getBoundingClientRect().top - 100 + "px"
4314
- };
4315
- }
4445
+ return Promise.resolve(traversal.client.search(traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false, 0, 100)).then(function (data) {
4446
+ var newValuesLabel = data.items.map(function (item) {
4447
+ var _schema$labelProperty;
4316
4448
 
4317
- return {
4318
- maxHeight: 'auto'
4449
+ return get$1(item, (_schema$labelProperty = schema == null ? void 0 : schema.labelProperty) != null ? _schema$labelProperty : 'title', item.id);
4450
+ });
4451
+ setValuesLabels(newValuesLabel);
4452
+ setIsLoadingData(false);
4453
+ });
4454
+ } catch (e) {
4455
+ return Promise.reject(e);
4456
+ }
4319
4457
  };
4320
- };
4321
-
4322
- var delayedQuery = React.useCallback(debounce$1(function (value) {
4323
- return handleSearch(0, false, value);
4324
- }, 500), []);
4325
4458
 
4326
- var handleSearch = function handleSearch(page, concat, value) {
4327
- if (page === void 0) {
4328
- page = 0;
4329
- }
4459
+ var valuesToSearch = value;
4330
4460
 
4331
- if (concat === void 0) {
4332
- concat = false;
4461
+ if (typeof valuesToSearch === 'string') {
4462
+ valuesToSearch = [valuesToSearch];
4333
4463
  }
4334
4464
 
4335
- if (value === void 0) {
4336
- value = '';
4465
+ if (valuesToSearch !== undefined && valuesToSearch.length > 0) {
4466
+ fetchData(valuesToSearch);
4467
+ } else {
4468
+ setValuesLabels([]);
4337
4469
  }
4470
+ }, [value]);
4338
4471
 
4339
- try {
4340
- setOptions({
4341
- loading: true
4342
- });
4343
- var searchTermQs = '';
4344
- var searchTermParsed = [];
4345
-
4346
- if (value !== '') {
4347
- searchTermParsed = parser(queryCondition + "=" + value);
4348
- }
4349
-
4350
- var _get = traversal.registry.get;
4351
-
4352
- var fnName = _get('searchEngineQueryParamsFunction', SearchEngine);
4353
-
4354
- var qsParsed = traversal.client[fnName]({
4355
- path: traversal.path,
4356
- start: page * PageSize,
4357
- pageSize: PageSize,
4358
- withDepth: false
4359
- });
4360
- var sortParsed = parser("_sort_des=" + labelProperty);
4361
- var typeNameParsed = [];
4362
-
4363
- if (typeNameQuery) {
4364
- typeNameParsed = parser("type_name__in=" + typeNameQuery);
4365
- }
4366
-
4367
- if (qs.length > 0 || searchTermParsed.length > 0 || qsParsed.length > 0 || typeNameParsed.length > 0) {
4368
- searchTermQs = buildQs([].concat(qs, searchTermParsed, qsParsed, typeNameParsed, sortParsed));
4472
+ var getRenderValue = function getRenderValue() {
4473
+ if (value === undefined) {
4474
+ if (modifyContent) {
4475
+ return DEFAULT_VALUE_EDITABLE_FIELD;
4369
4476
  }
4370
4477
 
4371
- return Promise.resolve(traversal.client.search(path ? path : traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false)).then(function (data) {
4372
- var _data$items_total;
4373
-
4374
- var newItems = options.items && concat ? [].concat(options.items, data.items) : data.items;
4375
- setOptions({
4376
- items: newItems != null ? newItems : [],
4377
- loading: false,
4378
- items_total: (_data$items_total = data.items_total) != null ? _data$items_total : 0,
4379
- page: page
4380
- });
4381
- });
4382
- } catch (e) {
4383
- return Promise.reject(e);
4478
+ return DEFAULT_VALUE_NO_EDITABLE_FIELD;
4479
+ }
4480
+
4481
+ if (isLoadingData) {
4482
+ return 'Loading...';
4384
4483
  }
4484
+
4485
+ return valuesLabels;
4385
4486
  };
4386
4487
 
4387
- var inicializeLabels = function inicializeLabels() {
4388
- try {
4389
- var _temp2 = function () {
4390
- if (labelProperty !== 'id' && value.length > 0) {
4391
- setIsLoadingData(true);
4392
- var searchTermQs = '';
4393
- var searchTermParsed = ['__or', "id=" + value.join('%26id=')];
4394
- var getSearch = traversal.registry.get;
4395
- var fnName = getSearch('searchEngineQueryParamsFunction', SearchEngine);
4396
- var qsParsed = traversal.client[fnName]({
4397
- path: traversal.path,
4398
- start: 0,
4399
- pageSize: 100,
4400
- withDepth: false
4401
- });
4402
- var typeNameParsed = [];
4488
+ return jsxRuntime.jsx(RenderField, {
4489
+ value: getRenderValue()
4490
+ });
4491
+ };
4492
+ var VocabularyRenderField = function VocabularyRenderField(_ref4) {
4493
+ var _schema$items;
4403
4494
 
4404
- if (typeNameQuery) {
4405
- typeNameParsed = parser("type_name__in=" + typeNameQuery);
4406
- }
4495
+ var schema = _ref4.schema,
4496
+ value = _ref4.value,
4497
+ modifyContent = _ref4.modifyContent;
4498
+ var intl = reactIntl.useIntl();
4499
+ var DEFAULT_VALUE_EDITABLE_FIELD = getDefaultValueEditableField(intl);
4500
+ var vocabularyName = (schema == null ? void 0 : (_schema$items = schema.items) == null ? void 0 : _schema$items.vocabularyName) || (schema == null ? void 0 : schema.vocabularyName);
4501
+ var vocabulary = useVocabulary(vocabularyName);
4407
4502
 
4408
- if (qs.length > 0 || searchTermParsed.length > 0 || qsParsed.length > 0 || typeNameParsed.length > 0) {
4409
- searchTermQs = buildQs([].concat(qs, [searchTermParsed], qsParsed, typeNameParsed));
4410
- }
4503
+ var getRenderProps = function getRenderProps() {
4504
+ var renderProps = {
4505
+ value: value != null ? value : modifyContent ? DEFAULT_VALUE_EDITABLE_FIELD : DEFAULT_VALUE_NO_EDITABLE_FIELD
4506
+ };
4411
4507
 
4412
- return Promise.resolve(traversal.client.search(path ? path : traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false, 0, 100)).then(function (data) {
4413
- var newValuesLabel = data.items.reduce(function (result, item) {
4414
- result[item.id] = get$1(item, labelProperty, item.id);
4415
- return result;
4416
- }, {});
4417
- setValuesLabels(newValuesLabel);
4418
- setIsLoadingData(false);
4419
- });
4420
- }
4421
- }();
4508
+ if (schema != null && schema.vocabularyName) {
4509
+ var _vocabularyValue$titl;
4422
4510
 
4423
- return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
4424
- } catch (e) {
4425
- return Promise.reject(e);
4426
- }
4427
- };
4511
+ var vocabularyValue = get$1(vocabulary, 'data.items', []).find(function (item) {
4512
+ return item.token === value;
4513
+ });
4514
+ renderProps['value'] = (_vocabularyValue$titl = vocabularyValue == null ? void 0 : vocabularyValue.title) != null ? _vocabularyValue$titl : '';
4515
+ } else {
4516
+ var _renderProps$value;
4428
4517
 
4429
- var renderTextItemOptionFn = function renderTextItemOptionFn(item) {
4430
- if (renderTextItemOption) {
4431
- return renderTextItemOption(item);
4518
+ renderProps['value'] = ((_renderProps$value = renderProps['value']) != null ? _renderProps$value : []).map(function (value) {
4519
+ var _get$find$title, _get$find;
4520
+
4521
+ return (_get$find$title = (_get$find = get$1(vocabulary, 'data.items', []).find(function (item) {
4522
+ return item.token === value;
4523
+ })) == null ? void 0 : _get$find.title) != null ? _get$find$title : '';
4524
+ });
4432
4525
  }
4433
4526
 
4434
- return get$1(item, labelProperty, item.title) || item['@name'];
4527
+ return renderProps;
4435
4528
  };
4436
4529
 
4437
- React.useEffect(function () {
4438
- if (!options.loading && !options.items && value.length > 0) {
4439
- inicializeLabels();
4440
- } else if (value.length === 0) {
4441
- setValuesLabels({});
4442
- }
4443
- }, [path, options.loading, options.items]);
4530
+ return jsxRuntime.jsx(RenderField, _extends({}, getRenderProps()));
4531
+ };
4532
+ function RenderFieldComponent(_ref5) {
4533
+ var schema = _ref5.schema,
4534
+ field = _ref5.field,
4535
+ val = _ref5.val,
4536
+ modifyContent = _ref5.modifyContent;
4537
+ var intl = reactIntl.useIntl();
4538
+ var DEFAULT_VALUE_EDITABLE_FIELD = getDefaultValueEditableField(intl);
4444
4539
 
4445
- if (isLoadingData || valuesLabel === undefined) {
4446
- return jsxRuntime.jsx("div", {
4447
- className: "spinner"
4448
- });
4449
- }
4540
+ var getRenderProps = function getRenderProps() {
4541
+ var _schema$items2;
4450
4542
 
4451
- return jsxRuntime.jsxs(jsxRuntime.Fragment, {
4452
- children: [jsxRuntime.jsx("div", {
4453
- className: "tags mb-2",
4454
- children: value.map(function (tag, index) {
4455
- return jsxRuntime.jsxs("div", {
4456
- className: "tag is-info is-medium",
4457
- children: [get$1(valuesLabel, tag, tag), jsxRuntime.jsx("button", {
4458
- className: "delete is-small",
4459
- onClick: function onClick(ev) {
4460
- ev.stopPropagation();
4461
- ev.preventDefault();
4462
- onChange([].concat(value.filter(function (tag) {
4463
- return value.indexOf(tag) !== index;
4464
- })));
4465
- }
4466
- })]
4467
- }, "input_list_" + tag + "_" + index);
4468
- })
4469
- }), jsxRuntime.jsxs("div", {
4470
- "data-test": dataTestWrapper,
4471
- ref: wrapperRef,
4472
- className: "dropdown mb-2 " + (isOpen ? 'is-active' : ''),
4473
- onBlur: function onBlur(ev) {
4474
- if (!ev.currentTarget.contains(ev.relatedTarget)) {
4475
- if (searchTerm !== '') {
4476
- setSearchTerm('');
4477
- setOptions(initialState$1);
4478
- }
4543
+ var renderProps = {
4544
+ value: val != null ? val : modifyContent ? DEFAULT_VALUE_EDITABLE_FIELD : DEFAULT_VALUE_NO_EDITABLE_FIELD,
4545
+ schema: schema
4546
+ };
4479
4547
 
4480
- setIsOpen(false);
4481
- }
4482
- },
4483
- children: [jsxRuntime.jsx("div", {
4484
- className: "dropdown-trigger",
4485
- children: jsxRuntime.jsxs("button", {
4486
- className: "button " + btnClass,
4487
- onClick: function onClick(ev) {
4488
- ev.preventDefault();
4489
- setIsOpen(!isOpen);
4548
+ if (val && (schema == null ? void 0 : schema.widget) === 'file') {
4549
+ renderProps['value'] = {
4550
+ data: val,
4551
+ field: field
4552
+ };
4553
+ renderProps['Widget'] = DownloadField;
4554
+ } else if ((schema == null ? void 0 : schema.type) === 'boolean') {
4555
+ var _val$toString;
4490
4556
 
4491
- if (!options.loading && !options.items) {
4492
- handleSearch(options.page);
4493
- }
4494
- },
4495
- "aria-haspopup": "true",
4496
- "aria-controls": "dropdown-menu",
4497
- children: [jsxRuntime.jsx("span", {
4498
- children: intl.formatMessage(genericMessages.choose)
4499
- }), jsxRuntime.jsx("span", {
4500
- className: "icon",
4501
- children: jsxRuntime.jsx("i", {
4502
- className: "fas fa-angle-down",
4503
- "aria-hidden": "true"
4504
- })
4505
- })]
4506
- })
4507
- }), jsxRuntime.jsx("div", {
4508
- className: "dropdown-menu",
4509
- id: "dropdown-menu",
4510
- role: "menu",
4511
- style: getHeight(),
4512
- children: jsxRuntime.jsxs("div", {
4513
- className: "dropdown-content",
4514
- children: [jsxRuntime.jsx("div", {
4515
- className: "dropdown-item",
4516
- children: jsxRuntime.jsx("input", {
4517
- ref: inputRef,
4518
- "data-test": dataTestSearchInput,
4519
- className: "input",
4520
- type: "text",
4521
- placeholder: intl.formatMessage(genericMessages.search),
4522
- value: searchTerm,
4523
- onChange: function onChange(ev) {
4524
- delayedQuery(ev.target.value);
4525
- setSearchTerm(ev.target.value);
4526
- }
4527
- })
4528
- }), jsxRuntime.jsx("hr", {
4529
- className: "dropdown-divider"
4530
- }), options.loading && jsxRuntime.jsx(Loading, {}), options.items && options.items.map(function (item) {
4531
- return jsxRuntime.jsx("div", {
4532
- className: "dropdown-item editable " + (value.includes(item.id) ? 'is-active' : ''),
4533
- "data-test": dataTestItem + "-" + item.id,
4534
- onMouseDown: function onMouseDown(ev) {
4535
- ev.stopPropagation();
4536
- ev.preventDefault();
4557
+ renderProps['value'] = (_val$toString = val == null ? void 0 : val.toString()) != null ? _val$toString : renderProps['value'];
4558
+ } else if (val && (schema == null ? void 0 : schema.type) === 'datetime') {
4559
+ renderProps['value'] = new Date(val).toLocaleString();
4560
+ } else if (schema != null && (_schema$items2 = schema.items) != null && _schema$items2.vocabularyName || schema != null && schema.vocabularyName) {
4561
+ renderProps['Widget'] = VocabularyRenderField;
4562
+ } else if ((schema == null ? void 0 : schema.widget) === 'search' || (schema == null ? void 0 : schema.widget) === 'search_list') {
4563
+ renderProps['Widget'] = SearchRenderField;
4564
+ renderProps['value'] = val;
4565
+ }
4537
4566
 
4538
- if (onChange && !value.includes(item.id)) {
4539
- var _extends2;
4567
+ return renderProps;
4568
+ };
4540
4569
 
4541
- setValuesLabels(_extends({}, valuesLabel, (_extends2 = {}, _extends2[item.id] = get$1(item, labelProperty, item.id), _extends2)));
4542
- onChange([].concat(value, [item.id]));
4543
- }
4544
- },
4545
- children: renderTextItemOptionFn(item)
4546
- }, item.path);
4547
- }), options.items && options.items.length === 0 && jsxRuntime.jsx("div", {
4548
- className: "dropdown-item",
4549
- children: intl.formatMessage(genericMessages.no_results)
4550
- }), options.items && options.items_total > options.items.length && jsxRuntime.jsxs(jsxRuntime.Fragment, {
4551
- children: [jsxRuntime.jsx("hr", {
4552
- className: "dropdown-divider"
4553
- }), jsxRuntime.jsx("div", {
4554
- className: "dropdown-item editable",
4555
- onMouseDown: function onMouseDown(ev) {
4556
- ev.stopPropagation();
4557
- ev.preventDefault();
4558
- handleSearch(options.page + 1, true);
4559
- },
4560
- children: intl.formatMessage(genericMessages.load_more)
4561
- })]
4562
- })]
4563
- })
4564
- })]
4565
- }), error && jsxRuntime.jsx(ErrorZone, {
4566
- className: errorZoneClassName,
4567
- id: uid,
4568
- children: error ? error : ''
4569
- })]
4570
- });
4571
- };
4570
+ return jsxRuntime.jsx(RenderField, _extends({}, getRenderProps()));
4571
+ }
4572
4572
 
4573
4573
  var EditComponent = React.forwardRef(function (_ref, ref) {
4574
4574
  var schema = _ref.schema,
@@ -14387,11 +14387,13 @@
14387
14387
  exports.RequiredFieldsForm = RequiredFieldsForm;
14388
14388
  exports.RestClient = RestClient;
14389
14389
  exports.SearchInput = SearchInput;
14390
+ exports.SearchInputList = SearchInputList;
14390
14391
  exports.SearchLabels = SearchLabels;
14391
14392
  exports.SearchOptionsLabels = SearchOptionsLabels;
14392
14393
  exports.SearchRenderField = SearchRenderField;
14393
14394
  exports.SearchVocabularyLabels = SearchVocabularyLabels;
14394
14395
  exports.Select = Select;
14396
+ exports.SelectVocabulary = SelectVocabulary;
14395
14397
  exports.Sharing = Sharing;
14396
14398
  exports.Table = Table;
14397
14399
  exports.TabsPanel = TabsPanel;