@knovator/pagecreator-admin 0.5.4 → 0.5.6
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/index.cjs +87 -79
- package/index.js +87 -79
- package/package.json +2 -2
- package/src/index.d.ts +5 -0
- package/src/lib/api/index.d.ts +10 -0
- package/src/lib/api/list.d.ts +48 -0
- package/src/lib/components/Page/AddButton/AddButton.d.ts +3 -0
- package/src/lib/components/Page/AddButton/index.d.ts +2 -0
- package/src/lib/components/Page/Form/PageForm.d.ts +4 -0
- package/src/lib/components/Page/Form/index.d.ts +2 -0
- package/src/lib/components/Page/Page/Page.d.ts +13 -0
- package/src/lib/components/Page/Page/index.d.ts +2 -0
- package/src/lib/components/Page/PageFormActions/PageFormActions.d.ts +4 -0
- package/src/lib/components/Page/PageFormActions/index.d.ts +2 -0
- package/src/lib/components/Page/PageFormWrapper/PageFormWrapper.d.ts +4 -0
- package/src/lib/components/Page/PageFormWrapper/index.d.ts +2 -0
- package/src/lib/components/Page/Pagination/PagePagination.d.ts +3 -0
- package/src/lib/components/Page/Pagination/index.d.ts +2 -0
- package/src/lib/components/Page/Search/PageSearch.d.ts +3 -0
- package/src/lib/components/Page/Search/index.d.ts +2 -0
- package/src/lib/components/Page/Table/PageTable.d.ts +3 -0
- package/src/lib/components/Page/Table/index.d.ts +2 -0
- package/src/lib/components/Page/index.d.ts +2 -0
- package/src/lib/components/Widget/AddButton/AddButton.d.ts +3 -0
- package/src/lib/components/Widget/AddButton/index.d.ts +2 -0
- package/src/lib/components/Widget/Form/ItemsAccordian.d.ts +4 -0
- package/src/lib/components/Widget/Form/Tabs/TabItem.d.ts +4 -0
- package/src/lib/components/Widget/Form/Tabs/Tabs.d.ts +4 -0
- package/src/lib/components/Widget/Form/Tabs/index.d.ts +2 -0
- package/src/lib/components/Widget/Form/WidgetForm.d.ts +4 -0
- package/src/lib/components/Widget/Form/index.d.ts +2 -0
- package/src/lib/components/Widget/Pagination/WidgetPagination.d.ts +3 -0
- package/src/lib/components/Widget/Pagination/index.d.ts +2 -0
- package/src/lib/components/Widget/Search/WidgetSearch.d.ts +3 -0
- package/src/lib/components/Widget/Search/index.d.ts +2 -0
- package/src/lib/components/Widget/Table/WidgetTable.d.ts +3 -0
- package/src/lib/components/Widget/Table/index.d.ts +2 -0
- package/src/lib/components/Widget/Widget/Widget.d.ts +13 -0
- package/src/lib/components/Widget/Widget/index.d.ts +2 -0
- package/src/lib/components/Widget/WidgetFormActions/WidgetFormActions.d.ts +4 -0
- package/src/lib/components/Widget/WidgetFormActions/index.d.ts +2 -0
- package/src/lib/components/Widget/WidgetFormWrapper/WidgetFormWrapper.d.ts +4 -0
- package/src/lib/components/Widget/WidgetFormWrapper/index.d.ts +2 -0
- package/src/lib/components/Widget/index.d.ts +2 -0
- package/src/lib/components/common/Accordian/Accordian.d.ts +13 -0
- package/src/lib/components/common/Accordian/index.d.ts +2 -0
- package/src/lib/components/common/Button/Button.d.ts +4 -0
- package/src/lib/components/common/Button/index.d.ts +2 -0
- package/src/lib/components/common/ConfirmPopover/ConfirmPopover.d.ts +4 -0
- package/src/lib/components/common/ConfirmPopover/index.d.ts +2 -0
- package/src/lib/components/common/DNDItemsList/DNDItemsList.d.ts +4 -0
- package/src/lib/components/common/DNDItemsList/index.d.ts +2 -0
- package/src/lib/components/common/DeleteModal/DeleteModal.d.ts +4 -0
- package/src/lib/components/common/DeleteModal/index.d.ts +2 -0
- package/src/lib/components/common/Drawer/Drawer.d.ts +9 -0
- package/src/lib/components/common/Drawer/index.d.ts +2 -0
- package/src/lib/components/common/Form/Form.d.ts +15 -0
- package/src/lib/components/common/Form/SimpleForm.d.ts +17 -0
- package/src/lib/components/common/Form/index.d.ts +4 -0
- package/src/lib/components/common/FormActions/FormActions.d.ts +10 -0
- package/src/lib/components/common/FormActions/index.d.ts +2 -0
- package/src/lib/components/common/ImageUpload/ImageUpload.d.ts +4 -0
- package/src/lib/components/common/ImageUpload/index.d.ts +2 -0
- package/src/lib/components/common/Input/Checkbox.d.ts +4 -0
- package/src/lib/components/common/Input/Input.d.ts +4 -0
- package/src/lib/components/common/Input/ReactSelect.d.ts +4 -0
- package/src/lib/components/common/Input/Select.d.ts +4 -0
- package/src/lib/components/common/Input/SrcSet.d.ts +4 -0
- package/src/lib/components/common/Input/index.d.ts +12 -0
- package/src/lib/components/common/Modal/Modal.d.ts +8 -0
- package/src/lib/components/common/Modal/index.d.ts +2 -0
- package/src/lib/components/common/Pagination/Pagination.d.ts +4 -0
- package/src/lib/components/common/Pagination/index.d.ts +2 -0
- package/src/lib/components/common/Table/Table.d.ts +4 -0
- package/src/lib/components/common/Table/index.d.ts +2 -0
- package/src/lib/components/common/Toggle/Toggle.d.ts +4 -0
- package/src/lib/components/common/Toggle/index.d.ts +2 -0
- package/src/lib/constants/common.d.ts +113 -0
- package/src/lib/context/PageContext.d.ts +7 -0
- package/src/lib/context/ProviderContext.d.ts +5 -0
- package/src/lib/context/WidgetContext.d.ts +7 -0
- package/src/lib/helper/utils.d.ts +11 -0
- package/src/lib/hooks/usePage.d.ts +41 -0
- package/src/lib/hooks/usePagination.d.ts +27 -0
- package/src/lib/hooks/useWidget.d.ts +50 -0
- package/src/lib/icons/chevronDown.d.ts +4 -0
- package/src/lib/icons/chevronLeft.d.ts +4 -0
- package/src/lib/icons/chevronRight.d.ts +4 -0
- package/src/lib/icons/chevronUp.d.ts +4 -0
- package/src/lib/icons/close.d.ts +4 -0
- package/src/lib/icons/pencil.d.ts +4 -0
- package/src/lib/icons/plus.d.ts +4 -0
- package/src/lib/icons/trash.d.ts +4 -0
- package/src/lib/types/api.d.ts +34 -0
- package/src/lib/types/common.d.ts +25 -0
- package/src/lib/types/components.d.ts +307 -0
- package/src/lib/types/context.d.ts +98 -0
- package/src/lib/types/index.d.ts +4 -0
package/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var fetchUrl = require('@knovator/api');
|
|
7
7
|
var classNames = require('classnames');
|
|
8
|
-
var ReactSelect = require('react-select');
|
|
8
|
+
var ReactSelect = require('react-select/async');
|
|
9
9
|
var reactHookForm = require('react-hook-form');
|
|
10
10
|
var reactBeautifulDnd = require('react-beautiful-dnd');
|
|
11
11
|
var CSSTransition = require('react-transition-group/CSSTransition');
|
|
@@ -2819,7 +2819,7 @@ const usePage = ({
|
|
|
2819
2819
|
}
|
|
2820
2820
|
onError(code, 'error', data === null || data === void 0 ? void 0 : data.message);
|
|
2821
2821
|
}, [onError, onLogout]);
|
|
2822
|
-
const getWidgets = React.useCallback(
|
|
2822
|
+
const getWidgets = React.useCallback(callback => __awaiter(void 0, void 0, void 0, function* () {
|
|
2823
2823
|
try {
|
|
2824
2824
|
setWidgetsLoading(true);
|
|
2825
2825
|
const api = getApiType({
|
|
@@ -2846,6 +2846,7 @@ const usePage = ({
|
|
|
2846
2846
|
value: item['_id'] || item['id']
|
|
2847
2847
|
};
|
|
2848
2848
|
});
|
|
2849
|
+
if (typeof callback === 'function') callback(widgetsData);
|
|
2849
2850
|
return setWidgets(widgetsData);
|
|
2850
2851
|
}
|
|
2851
2852
|
setWidgetsLoading(false);
|
|
@@ -2970,10 +2971,7 @@ const usePage = ({
|
|
|
2970
2971
|
const onChangeFormState = (state, data) => {
|
|
2971
2972
|
setItemData(data || null);
|
|
2972
2973
|
setFormState(state);
|
|
2973
|
-
if (state === 'UPDATE' && (data === null || data === void 0 ? void 0 : data.widgets)) {
|
|
2974
|
-
setSelectedWidgets(data.widgets.map(widgetId => widgets.find(widget => widget['value'] === widgetId)).filter(widget => widget));
|
|
2975
|
-
// setSelectedWidgets(widgets.filter((widget) => data.widgets.includes(widget.value)));
|
|
2976
|
-
} else {
|
|
2974
|
+
if (state === 'UPDATE' && (data === null || data === void 0 ? void 0 : data.widgets)) ; else {
|
|
2977
2975
|
setSelectedWidgets([]);
|
|
2978
2976
|
}
|
|
2979
2977
|
};
|
|
@@ -2987,7 +2985,6 @@ const usePage = ({
|
|
|
2987
2985
|
};
|
|
2988
2986
|
React.useEffect(() => {
|
|
2989
2987
|
if (_canList) getPages();
|
|
2990
|
-
getWidgets();
|
|
2991
2988
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2992
2989
|
}, [pageSize, currentPage, _canList]);
|
|
2993
2990
|
return {
|
|
@@ -3006,6 +3003,7 @@ const usePage = ({
|
|
|
3006
3003
|
widgets,
|
|
3007
3004
|
itemData,
|
|
3008
3005
|
formState,
|
|
3006
|
+
getWidgets,
|
|
3009
3007
|
onCloseForm,
|
|
3010
3008
|
widgetsLoading,
|
|
3011
3009
|
selectedWidgets,
|
|
@@ -3027,6 +3025,7 @@ const PageContextProvider = ({
|
|
|
3027
3025
|
closeForm: _closeForm = () => {},
|
|
3028
3026
|
getPages: _getPages = () => {},
|
|
3029
3027
|
loading: _loading = false,
|
|
3028
|
+
getWidgets: _getWidgets = () => {},
|
|
3030
3029
|
onChangeFormState: _onChangeFormState = () => {},
|
|
3031
3030
|
onPageFormSubmit: _onPageFormSubmit = () => {},
|
|
3032
3031
|
canAdd: _canAdd = false,
|
|
@@ -3060,6 +3059,7 @@ const PageContextProvider = ({
|
|
|
3060
3059
|
closeForm: _closeForm,
|
|
3061
3060
|
formState: _formState,
|
|
3062
3061
|
loading: _loading,
|
|
3062
|
+
getWidgets: _getWidgets,
|
|
3063
3063
|
onChangeFormState: _onChangeFormState,
|
|
3064
3064
|
canAdd: _canAdd,
|
|
3065
3065
|
canUpdate: _canUpdate,
|
|
@@ -3323,19 +3323,19 @@ const CustomReactSelect = ({
|
|
|
3323
3323
|
onChange,
|
|
3324
3324
|
label,
|
|
3325
3325
|
error,
|
|
3326
|
-
options: _options = [],
|
|
3327
3326
|
className,
|
|
3328
3327
|
isMulti,
|
|
3329
3328
|
selectedOptions: _selectedOptions = [],
|
|
3330
3329
|
required,
|
|
3331
3330
|
isLoading,
|
|
3332
3331
|
isSearchable,
|
|
3333
|
-
|
|
3332
|
+
loadOptions,
|
|
3334
3333
|
placeholder,
|
|
3335
3334
|
wrapperClassName,
|
|
3336
3335
|
formatOptionLabel,
|
|
3337
3336
|
listCode,
|
|
3338
|
-
customStyles
|
|
3337
|
+
customStyles,
|
|
3338
|
+
selectKey
|
|
3339
3339
|
}) => {
|
|
3340
3340
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3341
3341
|
className: wrapperClassName
|
|
@@ -3344,6 +3344,7 @@ const CustomReactSelect = ({
|
|
|
3344
3344
|
}, label, required ? /*#__PURE__*/React__default["default"].createElement("span", {
|
|
3345
3345
|
className: "khb_input-label-required"
|
|
3346
3346
|
}, "*") : null), /*#__PURE__*/React__default["default"].createElement(ReactSelect__default["default"], {
|
|
3347
|
+
key: selectKey,
|
|
3347
3348
|
"data-testid": `input-select-${label}`,
|
|
3348
3349
|
value: _selectedOptions,
|
|
3349
3350
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -3351,10 +3352,10 @@ const CustomReactSelect = ({
|
|
|
3351
3352
|
onChange: onChange,
|
|
3352
3353
|
className: classNames__default["default"](className),
|
|
3353
3354
|
isMulti: isMulti,
|
|
3354
|
-
|
|
3355
|
+
defaultOptions: true,
|
|
3355
3356
|
isSearchable: isSearchable,
|
|
3356
3357
|
isLoading: isLoading,
|
|
3357
|
-
|
|
3358
|
+
loadOptions: loadOptions,
|
|
3358
3359
|
placeholder: placeholder,
|
|
3359
3360
|
formatOptionLabel: formatOptionLabel ? option => formatOptionLabel(listCode, option) : undefined,
|
|
3360
3361
|
styles: customStyles
|
|
@@ -3723,7 +3724,6 @@ const Form = /*#__PURE__*/React.forwardRef(({
|
|
|
3723
3724
|
switch (schema.type) {
|
|
3724
3725
|
case 'ReactSelect':
|
|
3725
3726
|
input = /*#__PURE__*/React__default["default"].createElement(CustomReactSelect, {
|
|
3726
|
-
options: schema.options,
|
|
3727
3727
|
disabled: !_enable,
|
|
3728
3728
|
label: schema.label,
|
|
3729
3729
|
error: (_b = (_a = errors[schema.accessor]) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.toString(),
|
|
@@ -3737,11 +3737,12 @@ const Form = /*#__PURE__*/React.forwardRef(({
|
|
|
3737
3737
|
required: schema.required,
|
|
3738
3738
|
isMulti: schema.isMulti,
|
|
3739
3739
|
isSearchable: schema.isSearchable,
|
|
3740
|
-
onSearch: schema.onSearch,
|
|
3741
3740
|
isLoading: schema.isLoading,
|
|
3742
3741
|
placeholder: schema.placeholder,
|
|
3743
3742
|
wrapperClassName: schema.wrapperClassName,
|
|
3744
|
-
formatOptionLabel: schema.formatOptionLabel
|
|
3743
|
+
formatOptionLabel: schema.formatOptionLabel,
|
|
3744
|
+
selectKey: schema.selectKey,
|
|
3745
|
+
loadOptions: schema.loadOptions
|
|
3745
3746
|
});
|
|
3746
3747
|
break;
|
|
3747
3748
|
case 'checkbox':
|
|
@@ -3876,7 +3877,6 @@ const SimpleForm = /*#__PURE__*/React.forwardRef(({
|
|
|
3876
3877
|
switch (schema.type) {
|
|
3877
3878
|
case 'ReactSelect':
|
|
3878
3879
|
input = /*#__PURE__*/React__default["default"].createElement(CustomReactSelect, {
|
|
3879
|
-
options: schema.options,
|
|
3880
3880
|
disabled: !_enable,
|
|
3881
3881
|
label: schema.label,
|
|
3882
3882
|
error: (_b = (_a = errors[schema.accessor]) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.toString(),
|
|
@@ -3890,13 +3890,14 @@ const SimpleForm = /*#__PURE__*/React.forwardRef(({
|
|
|
3890
3890
|
required: schema.required,
|
|
3891
3891
|
isMulti: schema.isMulti,
|
|
3892
3892
|
isSearchable: schema.isSearchable,
|
|
3893
|
-
onSearch: schema.onSearch,
|
|
3894
3893
|
isLoading: schema.isLoading,
|
|
3895
3894
|
placeholder: schema.placeholder,
|
|
3896
3895
|
wrapperClassName: schema.wrapperClassName,
|
|
3897
3896
|
formatOptionLabel: schema.formatOptionLabel,
|
|
3898
3897
|
listCode: schema.listCode,
|
|
3899
|
-
customStyles: schema.customStyles
|
|
3898
|
+
customStyles: schema.customStyles,
|
|
3899
|
+
loadOptions: schema.loadOptions,
|
|
3900
|
+
selectKey: schema.selectKey
|
|
3900
3901
|
});
|
|
3901
3902
|
break;
|
|
3902
3903
|
case 'checkbox':
|
|
@@ -4041,6 +4042,7 @@ const PageForm = ({
|
|
|
4041
4042
|
selectedWidgets,
|
|
4042
4043
|
setSelectedWidgets,
|
|
4043
4044
|
widgets,
|
|
4045
|
+
getWidgets,
|
|
4044
4046
|
onChangeWidgetSequence,
|
|
4045
4047
|
canAdd,
|
|
4046
4048
|
canUpdate
|
|
@@ -4054,6 +4056,12 @@ const PageForm = ({
|
|
|
4054
4056
|
event.target.value = changeToCode(event.target.value);
|
|
4055
4057
|
return event;
|
|
4056
4058
|
}
|
|
4059
|
+
function loadOptions(value, callback) {
|
|
4060
|
+
getWidgets(widgetsData => {
|
|
4061
|
+
if (callback) callback(widgetsData);
|
|
4062
|
+
if (formState === 'UPDATE' && data) setSelectedWidgets(data.widgets.map(widgetId => widgetsData.find(widget => widget['value'] === widgetId)).filter(widget => widget));
|
|
4063
|
+
});
|
|
4064
|
+
}
|
|
4057
4065
|
// Widget Form Functions
|
|
4058
4066
|
const onDragEnd = result => {
|
|
4059
4067
|
const {
|
|
@@ -4091,6 +4099,7 @@ const PageForm = ({
|
|
|
4091
4099
|
options: widgets,
|
|
4092
4100
|
selectedOptions: selectedWidgets,
|
|
4093
4101
|
isMulti: true,
|
|
4102
|
+
loadOptions: loadOptions,
|
|
4094
4103
|
onChange: widgets => setSelectedWidgets(widgets)
|
|
4095
4104
|
}];
|
|
4096
4105
|
if (!canAdd && !canUpdate) return null;
|
|
@@ -4511,6 +4520,7 @@ const Page = ({
|
|
|
4511
4520
|
itemData,
|
|
4512
4521
|
setCurrentPage,
|
|
4513
4522
|
formState,
|
|
4523
|
+
getWidgets,
|
|
4514
4524
|
onChangeFormState,
|
|
4515
4525
|
onPageFormSubmit,
|
|
4516
4526
|
onCloseForm,
|
|
@@ -4536,6 +4546,7 @@ const Page = ({
|
|
|
4536
4546
|
currentPage: currentPage,
|
|
4537
4547
|
onChangeFormState: onChangeFormState,
|
|
4538
4548
|
pageSize: pageSize,
|
|
4549
|
+
getWidgets: getWidgets,
|
|
4539
4550
|
setCurrentPage: setCurrentPage,
|
|
4540
4551
|
onPageFormSubmit: onPageFormSubmit,
|
|
4541
4552
|
selectedWidgets: selectedWidgets,
|
|
@@ -4837,7 +4848,7 @@ const useWidget = ({
|
|
|
4837
4848
|
}
|
|
4838
4849
|
setLoading(false);
|
|
4839
4850
|
});
|
|
4840
|
-
const getCollectionData = (collectionName, search, callback) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4851
|
+
const getCollectionData = (collectionName, search, callback, collectionItems) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4841
4852
|
setCollectionDataLoading(true);
|
|
4842
4853
|
const api = getApiType({
|
|
4843
4854
|
routes,
|
|
@@ -4853,7 +4864,8 @@ const useWidget = ({
|
|
|
4853
4864
|
onError: handleError(CALLBACK_CODES.GET_ALL),
|
|
4854
4865
|
data: {
|
|
4855
4866
|
search: search || '',
|
|
4856
|
-
collectionName
|
|
4867
|
+
collectionName,
|
|
4868
|
+
collectionItems: collectionItems || []
|
|
4857
4869
|
}
|
|
4858
4870
|
});
|
|
4859
4871
|
if ((response === null || response === void 0 ? void 0 : response.code) === 'SUCCESS') {
|
|
@@ -4897,35 +4909,6 @@ const useWidget = ({
|
|
|
4897
4909
|
setFormState(undefined);
|
|
4898
4910
|
setItemData(null);
|
|
4899
4911
|
};
|
|
4900
|
-
const updateCollectionDataReferences = itemData => collectionData => {
|
|
4901
|
-
const itemDataUpdated = Object.assign({}, itemData);
|
|
4902
|
-
if (itemDataUpdated['tabs'] && itemDataUpdated['tabs'].length > 0 && collectionData && collectionData.length > 0) {
|
|
4903
|
-
itemDataUpdated['tabs'] = itemDataUpdated['tabs'].map(item => {
|
|
4904
|
-
var _a;
|
|
4905
|
-
return {
|
|
4906
|
-
name: item.name,
|
|
4907
|
-
collectionItems: ((_a = item === null || item === void 0 ? void 0 : item.collectionItems) === null || _a === void 0 ? void 0 : _a.map(itemId => {
|
|
4908
|
-
item = collectionData.find(item => item._id === itemId || item.id === itemId);
|
|
4909
|
-
return item ? Object.assign({
|
|
4910
|
-
label: item.name,
|
|
4911
|
-
value: item._id || item.id
|
|
4912
|
-
}, item) : {};
|
|
4913
|
-
})) || []
|
|
4914
|
-
};
|
|
4915
|
-
});
|
|
4916
|
-
}
|
|
4917
|
-
if (itemDataUpdated['collectionItems'] && itemDataUpdated['collectionItems'].length > 0 && collectionData && collectionData.length > 0) {
|
|
4918
|
-
let item;
|
|
4919
|
-
itemDataUpdated['collectionItems'] = itemDataUpdated['collectionItems'].map(itemId => {
|
|
4920
|
-
item = collectionData.find(item => item._id === itemId || item.id === itemId);
|
|
4921
|
-
return item ? Object.assign({
|
|
4922
|
-
label: item.name,
|
|
4923
|
-
value: item._id || item.id
|
|
4924
|
-
}, item) : {};
|
|
4925
|
-
});
|
|
4926
|
-
}
|
|
4927
|
-
setItemData(itemDataUpdated);
|
|
4928
|
-
};
|
|
4929
4912
|
const onChangeFormState = (state, data) => {
|
|
4930
4913
|
setFormState(state);
|
|
4931
4914
|
// fetch ItemsTypes & WidgetTypes if needed
|
|
@@ -4935,10 +4918,10 @@ const useWidget = ({
|
|
|
4935
4918
|
}
|
|
4936
4919
|
// get Item data if widget is updating
|
|
4937
4920
|
if (state === 'UPDATE' && data) {
|
|
4938
|
-
if (data['itemsType']
|
|
4921
|
+
if (data['itemsType'] === 'Image') {
|
|
4939
4922
|
getItems(data['_id']);
|
|
4940
|
-
setItemData(data);
|
|
4941
4923
|
}
|
|
4924
|
+
setItemData(data);
|
|
4942
4925
|
} else if (state === 'ADD') {
|
|
4943
4926
|
// reset Item data if widget is adding
|
|
4944
4927
|
setItemsList({
|
|
@@ -6734,23 +6717,24 @@ const TabItem = ({
|
|
|
6734
6717
|
};
|
|
6735
6718
|
|
|
6736
6719
|
const Tabs = ({
|
|
6720
|
+
activeTab,
|
|
6721
|
+
setActiveTab,
|
|
6737
6722
|
options,
|
|
6738
6723
|
control,
|
|
6739
6724
|
register,
|
|
6740
6725
|
listCode,
|
|
6741
6726
|
formatItem,
|
|
6742
6727
|
deleteTitle,
|
|
6728
|
+
loadOptions,
|
|
6743
6729
|
customStyles,
|
|
6744
6730
|
noButtonText,
|
|
6745
6731
|
yesButtonText,
|
|
6746
|
-
onItemsSearch,
|
|
6747
6732
|
isItemsLoading,
|
|
6748
6733
|
itemsPlaceholder,
|
|
6749
6734
|
formatOptionLabel,
|
|
6750
6735
|
tabCollectionItems,
|
|
6751
6736
|
onCollectionItemsIndexChange
|
|
6752
6737
|
}) => {
|
|
6753
|
-
const [activeTab, setActiveTab] = React.useState(0);
|
|
6754
6738
|
const {
|
|
6755
6739
|
fields: tabFields,
|
|
6756
6740
|
append: appendField,
|
|
@@ -6808,16 +6792,17 @@ const Tabs = ({
|
|
|
6808
6792
|
onChange
|
|
6809
6793
|
}
|
|
6810
6794
|
}) => /*#__PURE__*/React__default["default"].createElement(CustomReactSelect, {
|
|
6811
|
-
options: options,
|
|
6795
|
+
options: options || [],
|
|
6812
6796
|
onChange: value => {
|
|
6813
6797
|
if (value) {
|
|
6814
6798
|
if (Array.isArray(value)) onChange(value);else onChange([value]);
|
|
6815
6799
|
}
|
|
6816
6800
|
},
|
|
6801
|
+
selectKey: `tabs.${index}.collectionItems.${listCode}`,
|
|
6817
6802
|
selectedOptions: value,
|
|
6818
6803
|
isMulti: true,
|
|
6819
6804
|
isSearchable: true,
|
|
6820
|
-
|
|
6805
|
+
loadOptions: loadOptions,
|
|
6821
6806
|
isLoading: isItemsLoading,
|
|
6822
6807
|
placeholder: itemsPlaceholder,
|
|
6823
6808
|
listCode: listCode,
|
|
@@ -6837,6 +6822,7 @@ const constants = {
|
|
|
6837
6822
|
widgetTypeAccessor: 'widgetType',
|
|
6838
6823
|
itemTypeAccessor: 'itemsType',
|
|
6839
6824
|
collectionNameAccessor: 'collectionName',
|
|
6825
|
+
collectionItemsAccessor: 'collectionItems',
|
|
6840
6826
|
tabsWidgetTypeValue: 'Tabs',
|
|
6841
6827
|
fixedCardWidgetTypeValue: 'FixedCard',
|
|
6842
6828
|
carouselWidgetTypeValue: 'Carousel',
|
|
@@ -6889,6 +6875,7 @@ const WidgetForm = ({
|
|
|
6889
6875
|
reactSelectStyles
|
|
6890
6876
|
} = useWidgetState();
|
|
6891
6877
|
const callerRef = React.useRef(null);
|
|
6878
|
+
const [activeTab, setActiveTab] = React.useState(0);
|
|
6892
6879
|
const [webItemsVisible, setWebItemsVisible] = React.useState(false);
|
|
6893
6880
|
const [mobileItemsVisible, setMobileItemsVisible] = React.useState(false);
|
|
6894
6881
|
const [selectedWidgetType, setSelectedWidgetType] = React.useState();
|
|
@@ -6904,11 +6891,6 @@ const WidgetForm = ({
|
|
|
6904
6891
|
} else {
|
|
6905
6892
|
setItemsEnabled(false);
|
|
6906
6893
|
}
|
|
6907
|
-
if ((data === null || data === void 0 ? void 0 : data.collectionItems) && (data === null || data === void 0 ? void 0 : data.collectionItems.length) > 0 && collectionData && collectionData.length > 0) {
|
|
6908
|
-
setSelectedCollectionItems((data === null || data === void 0 ? void 0 : data.collectionItems) || []);
|
|
6909
|
-
} else {
|
|
6910
|
-
setSelectedCollectionItems([]);
|
|
6911
|
-
}
|
|
6912
6894
|
if ((data === null || data === void 0 ? void 0 : data.collectionName) !== 'Image' && itemsTypes && itemsTypes.length > 0) {
|
|
6913
6895
|
setSelectedCollectionType(itemsTypes.find(item => item.value === (data === null || data === void 0 ? void 0 : data.collectionName)));
|
|
6914
6896
|
}
|
|
@@ -6926,10 +6908,42 @@ const WidgetForm = ({
|
|
|
6926
6908
|
reset(data);
|
|
6927
6909
|
}
|
|
6928
6910
|
}, [data, reset]);
|
|
6929
|
-
const onChangeSearch = str => {
|
|
6911
|
+
const onChangeSearch = (str, callback) => {
|
|
6912
|
+
let collectionItems = [];
|
|
6913
|
+
let valueToSet = '';
|
|
6914
|
+
if (formState === 'UPDATE') {
|
|
6915
|
+
if (data[constants.widgetTypeAccessor] === constants.tabsWidgetTypeValue) {
|
|
6916
|
+
collectionItems = data[constants.tabsAccessor][activeTab]['collectionItems'];
|
|
6917
|
+
valueToSet = `${constants.tabsAccessor}.${activeTab}.${constants.tabCollectionItemsAccessor}`;
|
|
6918
|
+
} else if (Array.isArray(data[constants.collectionItemsAccessor]) && data[constants.collectionItemsAccessor].length > 0) {
|
|
6919
|
+
collectionItems = data[constants.collectionItemsAccessor];
|
|
6920
|
+
// valueToSet = constants.collectionItemsAccessor;
|
|
6921
|
+
}
|
|
6922
|
+
}
|
|
6923
|
+
|
|
6930
6924
|
if (callerRef.current) clearTimeout(callerRef.current);
|
|
6925
|
+
let item;
|
|
6931
6926
|
callerRef.current = setTimeout(() => {
|
|
6932
|
-
if (selectedCollectionType) getCollectionData(selectedCollectionType.value, str
|
|
6927
|
+
if (selectedCollectionType) getCollectionData(selectedCollectionType.value, str, options => {
|
|
6928
|
+
if (typeof callback === 'function') callback(options.map(item => Object.assign({
|
|
6929
|
+
value: item['_id'] || item['id'],
|
|
6930
|
+
label: item['name']
|
|
6931
|
+
}, item)));
|
|
6932
|
+
if (formState === 'UPDATE') {
|
|
6933
|
+
const selectedOptions = (collectionItems === null || collectionItems === void 0 ? void 0 : collectionItems.map(itemId => {
|
|
6934
|
+
item = options.find(item => item._id === itemId || item.id === itemId);
|
|
6935
|
+
return item ? Object.assign({
|
|
6936
|
+
label: item.name,
|
|
6937
|
+
value: item._id || item.id
|
|
6938
|
+
}, item) : {};
|
|
6939
|
+
})) || [];
|
|
6940
|
+
if (valueToSet) {
|
|
6941
|
+
setValue(valueToSet, selectedOptions);
|
|
6942
|
+
} else {
|
|
6943
|
+
setSelectedCollectionItems(selectedOptions);
|
|
6944
|
+
}
|
|
6945
|
+
}
|
|
6946
|
+
}, collectionItems);
|
|
6933
6947
|
}, 300);
|
|
6934
6948
|
};
|
|
6935
6949
|
// Form Utility Functions
|
|
@@ -6955,7 +6969,6 @@ const WidgetForm = ({
|
|
|
6955
6969
|
if (value[name] === 'Tabs') {
|
|
6956
6970
|
const firstItemType = getFirstItemTypeValue(value[name]);
|
|
6957
6971
|
if (firstItemType) {
|
|
6958
|
-
getCollectionData(firstItemType.value);
|
|
6959
6972
|
setSelectedCollectionType(firstItemType);
|
|
6960
6973
|
}
|
|
6961
6974
|
}
|
|
@@ -6966,13 +6979,12 @@ const WidgetForm = ({
|
|
|
6966
6979
|
} else {
|
|
6967
6980
|
const selectedWType = itemsTypes.find(wType => wType.value === value[constants.itemTypeAccessor]);
|
|
6968
6981
|
setSelectedCollectionType(selectedWType);
|
|
6969
|
-
getCollectionData(value[constants.itemTypeAccessor]);
|
|
6970
6982
|
setItemsEnabled(false);
|
|
6971
6983
|
}
|
|
6972
|
-
} else if (name === null || name === void 0 ? void 0 : name.includes(constants.tabsAccessor)) {
|
|
6984
|
+
} else if ((name === null || name === void 0 ? void 0 : name.includes(constants.tabsAccessor)) && Array.isArray(value[constants.tabsAccessor])) {
|
|
6973
6985
|
setTabCollectionItems(value[constants.tabsAccessor].map(tabItem => tabItem[constants.tabCollectionItemsAccessor]));
|
|
6974
6986
|
}
|
|
6975
|
-
}, [
|
|
6987
|
+
}, [getFirstItemTypeValue, itemsTypes]);
|
|
6976
6988
|
const onFormSubmit = data => {
|
|
6977
6989
|
var _a, _b;
|
|
6978
6990
|
const formData = Object.assign({}, data);
|
|
@@ -6985,7 +6997,7 @@ const WidgetForm = ({
|
|
|
6985
6997
|
if (Array.isArray(tabsData) && (formData[constants.widgetTypeAccessor] === constants.tabsWidgetTypeValue || formState === 'UPDATE')) {
|
|
6986
6998
|
formData[constants.tabsAccessor] = tabsData.map(tabItem => ({
|
|
6987
6999
|
name: tabItem.name,
|
|
6988
|
-
collectionItems: tabItem.collectionItems.map(item => item.value)
|
|
7000
|
+
collectionItems: tabItem.collectionItems.map(item => typeof item == 'string' ? item : item.value)
|
|
6989
7001
|
}));
|
|
6990
7002
|
} else formData[constants.tabsAccessor] = [];
|
|
6991
7003
|
// setting items type if undefined
|
|
@@ -7137,20 +7149,18 @@ const WidgetForm = ({
|
|
|
7137
7149
|
required: true,
|
|
7138
7150
|
accessor: 'collectionItems',
|
|
7139
7151
|
type: 'ReactSelect',
|
|
7140
|
-
options: collectionData
|
|
7141
|
-
value: item['_id'] || item['id'],
|
|
7142
|
-
label: item['name']
|
|
7143
|
-
}, item)),
|
|
7152
|
+
options: collectionData,
|
|
7144
7153
|
selectedOptions: selectedCollectionItems,
|
|
7145
7154
|
isMulti: true,
|
|
7146
7155
|
isSearchable: true,
|
|
7147
7156
|
onChange: setSelectedCollectionItems,
|
|
7148
|
-
|
|
7157
|
+
loadOptions: onChangeSearch,
|
|
7149
7158
|
isLoading: collectionDataLoading,
|
|
7150
7159
|
show: !itemsEnabled && selectedWidgetType !== 'Tabs',
|
|
7151
7160
|
formatOptionLabel: formatOptionLabel,
|
|
7152
7161
|
listCode: selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value,
|
|
7153
|
-
customStyles: reactSelectStyles || {}
|
|
7162
|
+
customStyles: reactSelectStyles || {},
|
|
7163
|
+
selectKey: selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value
|
|
7154
7164
|
}];
|
|
7155
7165
|
const itemFormSchema = [{
|
|
7156
7166
|
label: `${t('item.title')}`,
|
|
@@ -7231,19 +7241,17 @@ const WidgetForm = ({
|
|
|
7231
7241
|
deleteTitle: t('widget.tabDeleteTitle'),
|
|
7232
7242
|
yesButtonText: t('yesButtonText'),
|
|
7233
7243
|
noButtonText: t('cancelButtonText'),
|
|
7234
|
-
options: collectionData.map(item => Object.assign({
|
|
7235
|
-
value: item['_id'] || item['id'],
|
|
7236
|
-
label: item['name']
|
|
7237
|
-
}, item)),
|
|
7238
7244
|
itemsPlaceholder: `Select ${selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.label}...`,
|
|
7239
|
-
|
|
7245
|
+
loadOptions: onChangeSearch,
|
|
7240
7246
|
isItemsLoading: collectionDataLoading,
|
|
7241
7247
|
formatOptionLabel: formatOptionLabel,
|
|
7242
7248
|
listCode: (selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value) || '',
|
|
7243
7249
|
onCollectionItemsIndexChange: onTabItemsIndexChange,
|
|
7244
7250
|
tabCollectionItems: tabCollectionItems,
|
|
7245
7251
|
formatItem: formatListItem,
|
|
7246
|
-
customStyles: reactSelectStyles || {}
|
|
7252
|
+
customStyles: reactSelectStyles || {},
|
|
7253
|
+
activeTab: activeTab,
|
|
7254
|
+
setActiveTab: setActiveTab
|
|
7247
7255
|
}) : null, !itemsEnabled && selectedWidgetType !== 'Tabs' && /*#__PURE__*/React__default["default"].createElement(DNDItemsList, {
|
|
7248
7256
|
items: selectedCollectionItems,
|
|
7249
7257
|
onDragEnd: onCollectionIndexChange,
|