@knovator/pagecreator-admin 0.7.0 → 0.7.2
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
CHANGED
|
@@ -2806,7 +2806,7 @@ const usePage = ({
|
|
|
2806
2806
|
}
|
|
2807
2807
|
onError(code, 'error', data === null || data === void 0 ? void 0 : data.message);
|
|
2808
2808
|
}, [onError, onLogout]);
|
|
2809
|
-
const getWidgets = React.useCallback(callback => __awaiter(void 0, void 0, void 0, function* () {
|
|
2809
|
+
const getWidgets = React.useCallback((search, callback) => __awaiter(void 0, void 0, void 0, function* () {
|
|
2810
2810
|
try {
|
|
2811
2811
|
setWidgetsLoading(true);
|
|
2812
2812
|
const api = getApiType({
|
|
@@ -2821,6 +2821,7 @@ const usePage = ({
|
|
|
2821
2821
|
url: api.url,
|
|
2822
2822
|
onError: handleError(CALLBACK_CODES.GET_ALL),
|
|
2823
2823
|
data: {
|
|
2824
|
+
search: search || '',
|
|
2824
2825
|
all: true,
|
|
2825
2826
|
isActive: true
|
|
2826
2827
|
}
|
|
@@ -4063,6 +4064,7 @@ const PageForm = ({
|
|
|
4063
4064
|
canAdd,
|
|
4064
4065
|
canUpdate
|
|
4065
4066
|
} = usePageState();
|
|
4067
|
+
const callerRef = React.useRef(null);
|
|
4066
4068
|
// Form Utility Functions
|
|
4067
4069
|
function handleCapitalize(event) {
|
|
4068
4070
|
event.target.value = capitalizeFirstLetter(event.target.value);
|
|
@@ -4083,10 +4085,13 @@ const PageForm = ({
|
|
|
4083
4085
|
return event;
|
|
4084
4086
|
}
|
|
4085
4087
|
function loadOptions(value, callback) {
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4088
|
+
if (callerRef.current) clearTimeout(callerRef.current);
|
|
4089
|
+
callerRef.current = setTimeout(() => {
|
|
4090
|
+
getWidgets(value, widgetsData => {
|
|
4091
|
+
if (callback) callback(widgetsData);
|
|
4092
|
+
if (formState === 'UPDATE' && data) setSelectedWidgets(data.widgets.map(widgetId => widgetsData.find(widget => widget['value'] === widgetId)).filter(widget => widget));
|
|
4093
|
+
});
|
|
4094
|
+
}, 300);
|
|
4090
4095
|
}
|
|
4091
4096
|
// Widget Form Functions
|
|
4092
4097
|
const onDragEnd = result => {
|
|
@@ -6912,6 +6917,8 @@ const WidgetForm = ({
|
|
|
6912
6917
|
const [selectedCollectionItems, setSelectedCollectionItems] = React.useState([]);
|
|
6913
6918
|
const [tabCollectionItems, setTabCollectionItems] = React.useState([]);
|
|
6914
6919
|
const [selectedCollectionType, setSelectedCollectionType] = React.useState();
|
|
6920
|
+
const [collectionItemsUpdated, setCollectionItemsUpdated] = React.useState(false);
|
|
6921
|
+
const [tabCollectionItemsUpdated, setTabCollectionItemsUpdated] = React.useState([]);
|
|
6915
6922
|
React.useEffect(() => {
|
|
6916
6923
|
if (data && formState === 'UPDATE') {
|
|
6917
6924
|
setSelectedWidgetType(data === null || data === void 0 ? void 0 : data.widgetType);
|
|
@@ -6924,7 +6931,7 @@ const WidgetForm = ({
|
|
|
6924
6931
|
setSelectedCollectionType(itemsTypes.find(item => item.value === (data === null || data === void 0 ? void 0 : data.collectionName)));
|
|
6925
6932
|
}
|
|
6926
6933
|
}
|
|
6927
|
-
}, [data, formState,
|
|
6934
|
+
}, [data, formState, itemsTypes]);
|
|
6928
6935
|
React.useEffect(() => {
|
|
6929
6936
|
if (formState === 'ADD') {
|
|
6930
6937
|
setSelectedCollectionItems([]);
|
|
@@ -6945,7 +6952,10 @@ const WidgetForm = ({
|
|
|
6945
6952
|
collectionItems = data[constants.tabsAccessor][activeTab] ? data[constants.tabsAccessor][activeTab]['collectionItems'] : [];
|
|
6946
6953
|
valueToSet = `${constants.tabsAccessor}.${activeTab}.${constants.tabCollectionItemsAccessor}`;
|
|
6947
6954
|
} else if (Array.isArray(data[constants.collectionItemsAccessor]) && data[constants.collectionItemsAccessor].length > 0) {
|
|
6948
|
-
collectionItems =
|
|
6955
|
+
if (collectionItemsUpdated) collectionItems = selectedCollectionItems.map(
|
|
6956
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6957
|
+
// @ts-ignore
|
|
6958
|
+
collectionItem => collectionItem._id);else collectionItems = data[constants.collectionItemsAccessor];
|
|
6949
6959
|
// valueToSet = constants.collectionItemsAccessor;
|
|
6950
6960
|
}
|
|
6951
6961
|
}
|
|
@@ -6968,9 +6978,16 @@ const WidgetForm = ({
|
|
|
6968
6978
|
})) || [];
|
|
6969
6979
|
selectedOptions = selectedOptions.filter(obj => !!obj.value);
|
|
6970
6980
|
if (valueToSet) {
|
|
6971
|
-
|
|
6981
|
+
// only set tabcollection items, when they are not set
|
|
6982
|
+
if (!tabCollectionItemsUpdated[activeTab]) {
|
|
6983
|
+
const updatedArr = tabCollectionItemsUpdated;
|
|
6984
|
+
updatedArr[activeTab] = true;
|
|
6985
|
+
setTabCollectionItemsUpdated(updatedArr);
|
|
6986
|
+
setValue(valueToSet, selectedOptions);
|
|
6987
|
+
}
|
|
6972
6988
|
} else {
|
|
6973
6989
|
setSelectedCollectionItems(selectedOptions);
|
|
6990
|
+
setCollectionItemsUpdated(true);
|
|
6974
6991
|
}
|
|
6975
6992
|
}
|
|
6976
6993
|
}, collectionItems);
|
package/index.js
CHANGED
|
@@ -2794,7 +2794,7 @@ const usePage = ({
|
|
|
2794
2794
|
}
|
|
2795
2795
|
onError(code, 'error', data === null || data === void 0 ? void 0 : data.message);
|
|
2796
2796
|
}, [onError, onLogout]);
|
|
2797
|
-
const getWidgets = useCallback(callback => __awaiter(void 0, void 0, void 0, function* () {
|
|
2797
|
+
const getWidgets = useCallback((search, callback) => __awaiter(void 0, void 0, void 0, function* () {
|
|
2798
2798
|
try {
|
|
2799
2799
|
setWidgetsLoading(true);
|
|
2800
2800
|
const api = getApiType({
|
|
@@ -2809,6 +2809,7 @@ const usePage = ({
|
|
|
2809
2809
|
url: api.url,
|
|
2810
2810
|
onError: handleError(CALLBACK_CODES.GET_ALL),
|
|
2811
2811
|
data: {
|
|
2812
|
+
search: search || '',
|
|
2812
2813
|
all: true,
|
|
2813
2814
|
isActive: true
|
|
2814
2815
|
}
|
|
@@ -4051,6 +4052,7 @@ const PageForm = ({
|
|
|
4051
4052
|
canAdd,
|
|
4052
4053
|
canUpdate
|
|
4053
4054
|
} = usePageState();
|
|
4055
|
+
const callerRef = useRef(null);
|
|
4054
4056
|
// Form Utility Functions
|
|
4055
4057
|
function handleCapitalize(event) {
|
|
4056
4058
|
event.target.value = capitalizeFirstLetter(event.target.value);
|
|
@@ -4071,10 +4073,13 @@ const PageForm = ({
|
|
|
4071
4073
|
return event;
|
|
4072
4074
|
}
|
|
4073
4075
|
function loadOptions(value, callback) {
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4076
|
+
if (callerRef.current) clearTimeout(callerRef.current);
|
|
4077
|
+
callerRef.current = setTimeout(() => {
|
|
4078
|
+
getWidgets(value, widgetsData => {
|
|
4079
|
+
if (callback) callback(widgetsData);
|
|
4080
|
+
if (formState === 'UPDATE' && data) setSelectedWidgets(data.widgets.map(widgetId => widgetsData.find(widget => widget['value'] === widgetId)).filter(widget => widget));
|
|
4081
|
+
});
|
|
4082
|
+
}, 300);
|
|
4078
4083
|
}
|
|
4079
4084
|
// Widget Form Functions
|
|
4080
4085
|
const onDragEnd = result => {
|
|
@@ -6900,6 +6905,8 @@ const WidgetForm = ({
|
|
|
6900
6905
|
const [selectedCollectionItems, setSelectedCollectionItems] = useState([]);
|
|
6901
6906
|
const [tabCollectionItems, setTabCollectionItems] = useState([]);
|
|
6902
6907
|
const [selectedCollectionType, setSelectedCollectionType] = useState();
|
|
6908
|
+
const [collectionItemsUpdated, setCollectionItemsUpdated] = useState(false);
|
|
6909
|
+
const [tabCollectionItemsUpdated, setTabCollectionItemsUpdated] = useState([]);
|
|
6903
6910
|
useEffect(() => {
|
|
6904
6911
|
if (data && formState === 'UPDATE') {
|
|
6905
6912
|
setSelectedWidgetType(data === null || data === void 0 ? void 0 : data.widgetType);
|
|
@@ -6912,7 +6919,7 @@ const WidgetForm = ({
|
|
|
6912
6919
|
setSelectedCollectionType(itemsTypes.find(item => item.value === (data === null || data === void 0 ? void 0 : data.collectionName)));
|
|
6913
6920
|
}
|
|
6914
6921
|
}
|
|
6915
|
-
}, [data, formState,
|
|
6922
|
+
}, [data, formState, itemsTypes]);
|
|
6916
6923
|
useEffect(() => {
|
|
6917
6924
|
if (formState === 'ADD') {
|
|
6918
6925
|
setSelectedCollectionItems([]);
|
|
@@ -6933,7 +6940,10 @@ const WidgetForm = ({
|
|
|
6933
6940
|
collectionItems = data[constants.tabsAccessor][activeTab] ? data[constants.tabsAccessor][activeTab]['collectionItems'] : [];
|
|
6934
6941
|
valueToSet = `${constants.tabsAccessor}.${activeTab}.${constants.tabCollectionItemsAccessor}`;
|
|
6935
6942
|
} else if (Array.isArray(data[constants.collectionItemsAccessor]) && data[constants.collectionItemsAccessor].length > 0) {
|
|
6936
|
-
collectionItems =
|
|
6943
|
+
if (collectionItemsUpdated) collectionItems = selectedCollectionItems.map(
|
|
6944
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6945
|
+
// @ts-ignore
|
|
6946
|
+
collectionItem => collectionItem._id);else collectionItems = data[constants.collectionItemsAccessor];
|
|
6937
6947
|
// valueToSet = constants.collectionItemsAccessor;
|
|
6938
6948
|
}
|
|
6939
6949
|
}
|
|
@@ -6956,9 +6966,16 @@ const WidgetForm = ({
|
|
|
6956
6966
|
})) || [];
|
|
6957
6967
|
selectedOptions = selectedOptions.filter(obj => !!obj.value);
|
|
6958
6968
|
if (valueToSet) {
|
|
6959
|
-
|
|
6969
|
+
// only set tabcollection items, when they are not set
|
|
6970
|
+
if (!tabCollectionItemsUpdated[activeTab]) {
|
|
6971
|
+
const updatedArr = tabCollectionItemsUpdated;
|
|
6972
|
+
updatedArr[activeTab] = true;
|
|
6973
|
+
setTabCollectionItemsUpdated(updatedArr);
|
|
6974
|
+
setValue(valueToSet, selectedOptions);
|
|
6975
|
+
}
|
|
6960
6976
|
} else {
|
|
6961
6977
|
setSelectedCollectionItems(selectedOptions);
|
|
6978
|
+
setCollectionItemsUpdated(true);
|
|
6962
6979
|
}
|
|
6963
6980
|
}
|
|
6964
6981
|
}, collectionItems);
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { PageProps } from '../../../types';
|
|
3
3
|
declare const Page: {
|
|
4
4
|
({ t, loader, explicitForm, children, permissions, preConfirmDelete, }: PageProps): JSX.Element;
|
|
5
|
-
Table: () => JSX.Element;
|
|
5
|
+
Table: ({ extraActions, extraColumns }: import("../../../types").DerivedTableProps) => JSX.Element;
|
|
6
6
|
Search: () => JSX.Element;
|
|
7
7
|
Form: ({ formRef }: import("../../../types").FormProps) => JSX.Element | null;
|
|
8
8
|
AddButton: () => JSX.Element;
|
|
@@ -3,7 +3,7 @@ import Checkbox from "./Checkbox";
|
|
|
3
3
|
import Select from "./Select";
|
|
4
4
|
import ReactSelect from "./ReactSelect";
|
|
5
5
|
import SrcSet from './SrcSet';
|
|
6
|
-
declare const _default: (({ label, id, placeholder, type, size, required, error, className, disabled, rest, onInput, onBlur, value, onChange, wrapperClassName, }: import("../../../types").InputProps) => JSX.Element) & {
|
|
6
|
+
declare const _default: (({ label, id, placeholder, type, size, required, error, className, disabled, rest, onInput, onBlur, value, info, onChange, wrapperClassName, }: import("../../../types").InputProps) => JSX.Element) & {
|
|
7
7
|
Select: typeof Select;
|
|
8
8
|
ReactSelect: typeof ReactSelect;
|
|
9
9
|
Checkbox: typeof Checkbox;
|
|
@@ -24,7 +24,7 @@ declare const usePage: ({ routes, defaultLimit, canList, preConfirmDelete, }: Us
|
|
|
24
24
|
widgets: ObjectType[];
|
|
25
25
|
itemData: any;
|
|
26
26
|
formState: FormActionTypes | undefined;
|
|
27
|
-
getWidgets: (callback?: ((data: any) => void) | undefined) => Promise<void>;
|
|
27
|
+
getWidgets: (search?: string, callback?: ((data: any) => void) | undefined) => Promise<void>;
|
|
28
28
|
onCloseForm: () => void;
|
|
29
29
|
widgetsLoading: boolean;
|
|
30
30
|
selectedWidgets: {
|
|
@@ -70,7 +70,7 @@ export interface PageContextType {
|
|
|
70
70
|
list: any[];
|
|
71
71
|
searchText: string;
|
|
72
72
|
changeSearch: (val: string) => void;
|
|
73
|
-
getWidgets: (callback?: (data: any) => void) => void;
|
|
73
|
+
getWidgets: (search?: string, callback?: (data: any) => void) => void;
|
|
74
74
|
formState: FormActionTypes | undefined;
|
|
75
75
|
closeForm: () => void;
|
|
76
76
|
onPageFormSubmit: (data: any) => void;
|