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