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