@knovator/pagecreator-admin 0.7.6 → 0.8.0

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
@@ -1758,6 +1758,8 @@ const TRANSLATION_PAIRS_WIDGET = {
1758
1758
  'widget.widgetTitleInfo': 'HTML is supported',
1759
1759
  'widget.minPerRow': 'Value must be greater than zero',
1760
1760
  'widget.actionsLabel': 'Actions',
1761
+ 'widget.category': 'Category',
1762
+ 'widget.categoryPlaceholder': 'Select Category',
1761
1763
  'widget.tabNameRequired': 'Tab Name is required'
1762
1764
  };
1763
1765
  const TRANSLATION_PAIRS_ITEM = {
@@ -2692,6 +2694,12 @@ const apiList = {
2692
2694
  url: `${prefix}/collection-data`,
2693
2695
  method: 'POST'
2694
2696
  }),
2697
+ CATEGORIES: ({
2698
+ prefix
2699
+ }) => ({
2700
+ url: `${prefix}/categories`,
2701
+ method: 'GET'
2702
+ }),
2695
2703
  // Image Upload API
2696
2704
  IMAGE_UPLOAD: ({
2697
2705
  prefix
@@ -4510,6 +4518,7 @@ const useWidget = ({
4510
4518
  const [formState, setFormState] = React.useState();
4511
4519
  const [itemsTypes, setItemsTypes] = React.useState([]);
4512
4520
  const [widgetTypes, setWidgetTypes] = React.useState([]);
4521
+ const [categories, setCategories] = React.useState([]);
4513
4522
  const [collectionDataLoading, setCollectionDataLoading] = React.useState(false);
4514
4523
  const [collectionData, setCollectionData] = React.useState([]);
4515
4524
  const {
@@ -4688,6 +4697,27 @@ const useWidget = ({
4688
4697
  }
4689
4698
  setLoading(false);
4690
4699
  });
4700
+ const getCategories = () => __awaiter(void 0, void 0, void 0, function* () {
4701
+ if ((categories === null || categories === void 0 ? void 0 : categories.length) > 0) return;
4702
+ setLoading(true);
4703
+ const api = getApiType({
4704
+ routes,
4705
+ action: 'CATEGORIES',
4706
+ prefix: widgetRoutesPrefix
4707
+ });
4708
+ const response = yield commonApi({
4709
+ baseUrl,
4710
+ token,
4711
+ method: api.method,
4712
+ url: api.url,
4713
+ onError: handleError(CALLBACK_CODES.GET_ALL)
4714
+ });
4715
+ if ((response === null || response === void 0 ? void 0 : response.code) === 'SUCCESS') {
4716
+ setLoading(false);
4717
+ return setCategories(dataGatter(response));
4718
+ }
4719
+ setLoading(false);
4720
+ });
4691
4721
  const getCollectionData = (collectionName, search, callback, collectionItems) => __awaiter(void 0, void 0, void 0, function* () {
4692
4722
  setCollectionDataLoading(true);
4693
4723
  const api = getApiType({
@@ -4790,6 +4820,7 @@ const useWidget = ({
4790
4820
  if (state === 'ADD' || state === 'UPDATE') {
4791
4821
  getWidgetsTypes();
4792
4822
  getWidgetTypes();
4823
+ getCategories();
4793
4824
  }
4794
4825
  // get Item data if widget is updating
4795
4826
  if (state === 'UPDATE' && data) {
@@ -4884,6 +4915,7 @@ const useWidget = ({
4884
4915
  // Form
4885
4916
  formState,
4886
4917
  itemData,
4918
+ categories,
4887
4919
  onChangeFormState,
4888
4920
  onCloseForm,
4889
4921
  onWidgetFormSubmit,
@@ -5993,6 +6025,7 @@ const WidgetContextProvider = ({
5993
6025
  onImageRemove: _onImageRemove = id => __awaiter(void 0, void 0, void 0, function* () {}),
5994
6026
  itemsTypes: _itemsTypes = [],
5995
6027
  widgetTypes: _widgetTypes = [],
6028
+ categories: _categories = [],
5996
6029
  getCollectionData: _getCollectionData = () => Promise.resolve(),
5997
6030
  collectionDataLoading: _collectionDataLoading = false,
5998
6031
  collectionData: _collectionData = [],
@@ -6040,6 +6073,7 @@ const WidgetContextProvider = ({
6040
6073
  onImageRemove: _onImageRemove,
6041
6074
  onPartialUpdateWidget: _onPartialUpdateWidget,
6042
6075
  itemsTypes: _itemsTypes,
6076
+ categories: _categories,
6043
6077
  widgetTypes: _widgetTypes,
6044
6078
  getCollectionData: _getCollectionData,
6045
6079
  collectionDataLoading: _collectionDataLoading,
@@ -6722,6 +6756,7 @@ const Tabs = ({
6722
6756
  };
6723
6757
 
6724
6758
  const constants = {
6759
+ categoryTypeAccessor: 'category',
6725
6760
  widgetTypeAccessor: 'widgetType',
6726
6761
  itemTypeAccessor: 'itemsType',
6727
6762
  collectionNameAccessor: 'collectionName',
@@ -6765,6 +6800,7 @@ const WidgetForm = ({
6765
6800
  canUpdate,
6766
6801
  formState,
6767
6802
  itemsTypes,
6803
+ categories,
6768
6804
  widgetTypes,
6769
6805
  loading,
6770
6806
  onWidgetFormSubmit,
@@ -6876,6 +6912,9 @@ const WidgetForm = ({
6876
6912
  const getFirstWidgetTypeValue = React.useCallback(() => {
6877
6913
  return widgetTypes[0].value;
6878
6914
  }, [widgetTypes]);
6915
+ const getFirstCategoryValue = React.useCallback(() => {
6916
+ return categories[0].value;
6917
+ }, [categories]);
6879
6918
  // Widget Form Functions
6880
6919
  const onWidgetFormInputChange = React.useCallback((value, name) => {
6881
6920
  if (name === 'widgetType') {
@@ -6902,6 +6941,9 @@ const WidgetForm = ({
6902
6941
  const onFormSubmit = data => {
6903
6942
  var _a, _b;
6904
6943
  const formData = Object.assign({}, data);
6944
+ if (!formData[constants.categoryTypeAccessor] && categories && categories.length > 0) {
6945
+ formData[constants.categoryTypeAccessor] = getFirstCategoryValue();
6946
+ }
6905
6947
  // setting widget type if undefined
6906
6948
  if (!formData[constants.widgetTypeAccessor] && formState === 'ADD') {
6907
6949
  formData[constants.widgetTypeAccessor] = getFirstWidgetTypeValue();
@@ -7019,6 +7061,13 @@ const WidgetForm = ({
7019
7061
  required: t('widget.widgetTypeRequired')
7020
7062
  },
7021
7063
  options: widgetTypes
7064
+ }, {
7065
+ label: `${t('widget.category')}`,
7066
+ placeholder: t('widget.categoryPlaceholder'),
7067
+ accessor: 'category',
7068
+ type: 'select',
7069
+ show: categories && categories.length > 0,
7070
+ options: categories
7022
7071
  }, {
7023
7072
  label: t('widget.autoPlay'),
7024
7073
  accessor: 'autoPlay',
@@ -7318,6 +7367,7 @@ const Widget = ({
7318
7367
  onImageUpload,
7319
7368
  onPartialUpdateWidget,
7320
7369
  itemsTypes,
7370
+ categories,
7321
7371
  widgetTypes,
7322
7372
  getCollectionData,
7323
7373
  collectionData,
@@ -7350,6 +7400,7 @@ const Widget = ({
7350
7400
  onImageRemove: onImageRemove,
7351
7401
  onImageUpload: onImageUpload,
7352
7402
  onPartialUpdateWidget: onPartialUpdateWidget,
7403
+ categories: categories,
7353
7404
  itemsTypes: itemsTypes,
7354
7405
  widgetTypes: widgetTypes,
7355
7406
  getCollectionData: getCollectionData,
package/index.js CHANGED
@@ -1746,6 +1746,8 @@ const TRANSLATION_PAIRS_WIDGET = {
1746
1746
  'widget.widgetTitleInfo': 'HTML is supported',
1747
1747
  'widget.minPerRow': 'Value must be greater than zero',
1748
1748
  'widget.actionsLabel': 'Actions',
1749
+ 'widget.category': 'Category',
1750
+ 'widget.categoryPlaceholder': 'Select Category',
1749
1751
  'widget.tabNameRequired': 'Tab Name is required'
1750
1752
  };
1751
1753
  const TRANSLATION_PAIRS_ITEM = {
@@ -2680,6 +2682,12 @@ const apiList = {
2680
2682
  url: `${prefix}/collection-data`,
2681
2683
  method: 'POST'
2682
2684
  }),
2685
+ CATEGORIES: ({
2686
+ prefix
2687
+ }) => ({
2688
+ url: `${prefix}/categories`,
2689
+ method: 'GET'
2690
+ }),
2683
2691
  // Image Upload API
2684
2692
  IMAGE_UPLOAD: ({
2685
2693
  prefix
@@ -4498,6 +4506,7 @@ const useWidget = ({
4498
4506
  const [formState, setFormState] = useState();
4499
4507
  const [itemsTypes, setItemsTypes] = useState([]);
4500
4508
  const [widgetTypes, setWidgetTypes] = useState([]);
4509
+ const [categories, setCategories] = useState([]);
4501
4510
  const [collectionDataLoading, setCollectionDataLoading] = useState(false);
4502
4511
  const [collectionData, setCollectionData] = useState([]);
4503
4512
  const {
@@ -4676,6 +4685,27 @@ const useWidget = ({
4676
4685
  }
4677
4686
  setLoading(false);
4678
4687
  });
4688
+ const getCategories = () => __awaiter(void 0, void 0, void 0, function* () {
4689
+ if ((categories === null || categories === void 0 ? void 0 : categories.length) > 0) return;
4690
+ setLoading(true);
4691
+ const api = getApiType({
4692
+ routes,
4693
+ action: 'CATEGORIES',
4694
+ prefix: widgetRoutesPrefix
4695
+ });
4696
+ const response = yield commonApi({
4697
+ baseUrl,
4698
+ token,
4699
+ method: api.method,
4700
+ url: api.url,
4701
+ onError: handleError(CALLBACK_CODES.GET_ALL)
4702
+ });
4703
+ if ((response === null || response === void 0 ? void 0 : response.code) === 'SUCCESS') {
4704
+ setLoading(false);
4705
+ return setCategories(dataGatter(response));
4706
+ }
4707
+ setLoading(false);
4708
+ });
4679
4709
  const getCollectionData = (collectionName, search, callback, collectionItems) => __awaiter(void 0, void 0, void 0, function* () {
4680
4710
  setCollectionDataLoading(true);
4681
4711
  const api = getApiType({
@@ -4778,6 +4808,7 @@ const useWidget = ({
4778
4808
  if (state === 'ADD' || state === 'UPDATE') {
4779
4809
  getWidgetsTypes();
4780
4810
  getWidgetTypes();
4811
+ getCategories();
4781
4812
  }
4782
4813
  // get Item data if widget is updating
4783
4814
  if (state === 'UPDATE' && data) {
@@ -4872,6 +4903,7 @@ const useWidget = ({
4872
4903
  // Form
4873
4904
  formState,
4874
4905
  itemData,
4906
+ categories,
4875
4907
  onChangeFormState,
4876
4908
  onCloseForm,
4877
4909
  onWidgetFormSubmit,
@@ -5981,6 +6013,7 @@ const WidgetContextProvider = ({
5981
6013
  onImageRemove: _onImageRemove = id => __awaiter(void 0, void 0, void 0, function* () {}),
5982
6014
  itemsTypes: _itemsTypes = [],
5983
6015
  widgetTypes: _widgetTypes = [],
6016
+ categories: _categories = [],
5984
6017
  getCollectionData: _getCollectionData = () => Promise.resolve(),
5985
6018
  collectionDataLoading: _collectionDataLoading = false,
5986
6019
  collectionData: _collectionData = [],
@@ -6028,6 +6061,7 @@ const WidgetContextProvider = ({
6028
6061
  onImageRemove: _onImageRemove,
6029
6062
  onPartialUpdateWidget: _onPartialUpdateWidget,
6030
6063
  itemsTypes: _itemsTypes,
6064
+ categories: _categories,
6031
6065
  widgetTypes: _widgetTypes,
6032
6066
  getCollectionData: _getCollectionData,
6033
6067
  collectionDataLoading: _collectionDataLoading,
@@ -6710,6 +6744,7 @@ const Tabs = ({
6710
6744
  };
6711
6745
 
6712
6746
  const constants = {
6747
+ categoryTypeAccessor: 'category',
6713
6748
  widgetTypeAccessor: 'widgetType',
6714
6749
  itemTypeAccessor: 'itemsType',
6715
6750
  collectionNameAccessor: 'collectionName',
@@ -6753,6 +6788,7 @@ const WidgetForm = ({
6753
6788
  canUpdate,
6754
6789
  formState,
6755
6790
  itemsTypes,
6791
+ categories,
6756
6792
  widgetTypes,
6757
6793
  loading,
6758
6794
  onWidgetFormSubmit,
@@ -6864,6 +6900,9 @@ const WidgetForm = ({
6864
6900
  const getFirstWidgetTypeValue = useCallback(() => {
6865
6901
  return widgetTypes[0].value;
6866
6902
  }, [widgetTypes]);
6903
+ const getFirstCategoryValue = useCallback(() => {
6904
+ return categories[0].value;
6905
+ }, [categories]);
6867
6906
  // Widget Form Functions
6868
6907
  const onWidgetFormInputChange = useCallback((value, name) => {
6869
6908
  if (name === 'widgetType') {
@@ -6890,6 +6929,9 @@ const WidgetForm = ({
6890
6929
  const onFormSubmit = data => {
6891
6930
  var _a, _b;
6892
6931
  const formData = Object.assign({}, data);
6932
+ if (!formData[constants.categoryTypeAccessor] && categories && categories.length > 0) {
6933
+ formData[constants.categoryTypeAccessor] = getFirstCategoryValue();
6934
+ }
6893
6935
  // setting widget type if undefined
6894
6936
  if (!formData[constants.widgetTypeAccessor] && formState === 'ADD') {
6895
6937
  formData[constants.widgetTypeAccessor] = getFirstWidgetTypeValue();
@@ -7007,6 +7049,13 @@ const WidgetForm = ({
7007
7049
  required: t('widget.widgetTypeRequired')
7008
7050
  },
7009
7051
  options: widgetTypes
7052
+ }, {
7053
+ label: `${t('widget.category')}`,
7054
+ placeholder: t('widget.categoryPlaceholder'),
7055
+ accessor: 'category',
7056
+ type: 'select',
7057
+ show: categories && categories.length > 0,
7058
+ options: categories
7010
7059
  }, {
7011
7060
  label: t('widget.autoPlay'),
7012
7061
  accessor: 'autoPlay',
@@ -7306,6 +7355,7 @@ const Widget = ({
7306
7355
  onImageUpload,
7307
7356
  onPartialUpdateWidget,
7308
7357
  itemsTypes,
7358
+ categories,
7309
7359
  widgetTypes,
7310
7360
  getCollectionData,
7311
7361
  collectionData,
@@ -7338,6 +7388,7 @@ const Widget = ({
7338
7388
  onImageRemove: onImageRemove,
7339
7389
  onImageUpload: onImageUpload,
7340
7390
  onPartialUpdateWidget: onPartialUpdateWidget,
7391
+ categories: categories,
7341
7392
  itemsTypes: itemsTypes,
7342
7393
  widgetTypes: widgetTypes,
7343
7394
  getCollectionData: getCollectionData,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knovator/pagecreator-admin",
3
- "version": "0.7.6",
3
+ "version": "0.8.0",
4
4
  "dependencies": {
5
5
  "classnames": "^2.3.1",
6
6
  "react-beautiful-dnd": "^13.1.0",
@@ -40,6 +40,10 @@ declare const apiList: {
40
40
  url: string;
41
41
  method: string;
42
42
  };
43
+ CATEGORIES: ({ prefix }: API_INPUT_TYPE) => {
44
+ url: string;
45
+ method: string;
46
+ };
43
47
  IMAGE_UPLOAD: ({ prefix }: API_INPUT_TYPE) => {
44
48
  url: string;
45
49
  method: string;
@@ -87,6 +87,8 @@ declare const TRANSLATION_PAIRS_WIDGET: {
87
87
  'widget.widgetTitleInfo': string;
88
88
  'widget.minPerRow': string;
89
89
  'widget.actionsLabel': string;
90
+ 'widget.category': string;
91
+ 'widget.categoryPlaceholder': string;
90
92
  'widget.tabNameRequired': string;
91
93
  };
92
94
  declare const TRANSLATION_PAIRS_ITEM: {
@@ -2,6 +2,6 @@ import React from 'react';
2
2
  import { WidgetContextType } from '../types';
3
3
  interface WidgetContextProviderProps extends React.PropsWithChildren, Partial<WidgetContextType> {
4
4
  }
5
- declare const WidgetContextProvider: ({ t, list, imageBaseUrl, searchText, changeSearch, formState, closeForm, loading, onChangeFormState, onWidgetFormSubmit, updateData, canAdd, canUpdate, onDeleteItem, getWidgets, onImageUpload, onImageRemove, itemsTypes, widgetTypes, getCollectionData, collectionDataLoading, collectionData, formatListItem, formatOptionLabel, currentPage, limits, pageSize, setCurrentPage, setPageSize, totalPages, totalRecords, canList, canPartialUpdate, columns, data, canDelete, loader, onPartialUpdateWidget, reactSelectStyles, children, }: WidgetContextProviderProps) => JSX.Element;
5
+ declare const WidgetContextProvider: ({ t, list, imageBaseUrl, searchText, changeSearch, formState, closeForm, loading, onChangeFormState, onWidgetFormSubmit, updateData, canAdd, canUpdate, onDeleteItem, getWidgets, onImageUpload, onImageRemove, itemsTypes, widgetTypes, categories, getCollectionData, collectionDataLoading, collectionData, formatListItem, formatOptionLabel, currentPage, limits, pageSize, setCurrentPage, setPageSize, totalPages, totalRecords, canList, canPartialUpdate, columns, data, canDelete, loader, onPartialUpdateWidget, reactSelectStyles, children, }: WidgetContextProviderProps) => JSX.Element;
6
6
  export declare function useWidgetState(): WidgetContextType;
7
7
  export default WidgetContextProvider;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { Routes_Input, WidgetType, ItemsType } from '../types';
2
+ import { Routes_Input, WidgetType, ItemsType, Category } from '../types';
3
3
  import { FormActionTypes, ObjectType } from '../types/common';
4
4
  interface UseWidgetProps {
5
5
  canList?: boolean;
@@ -10,7 +10,7 @@ interface UseWidgetProps {
10
10
  }) => Promise<boolean>;
11
11
  imageBaseUrl?: string;
12
12
  }
13
- declare const useWidget: ({ canList, defaultLimit, routes, preConfirmDelete, imageBaseUrl }: UseWidgetProps) => {
13
+ declare const useWidget: ({ canList, defaultLimit, routes, preConfirmDelete, imageBaseUrl, }: UseWidgetProps) => {
14
14
  list: ObjectType[];
15
15
  getWidgets: (search?: string) => Promise<void>;
16
16
  loading: boolean;
@@ -24,6 +24,7 @@ declare const useWidget: ({ canList, defaultLimit, routes, preConfirmDelete, ima
24
24
  setPageSize: (value: number) => void;
25
25
  formState: FormActionTypes | undefined;
26
26
  itemData: ObjectType | null;
27
+ categories: Category[];
27
28
  onChangeFormState: (state: FormActionTypes, data?: ObjectType) => Promise<void>;
28
29
  onCloseForm: () => void;
29
30
  onWidgetFormSubmit: (data: ObjectType) => Promise<void>;
@@ -1,4 +1,4 @@
1
- export type ACTION_TYPES = 'IMAGE_UPLOAD' | 'IMAGE_REMOVE' | 'CREATE' | 'LIST' | 'DELETE' | 'UPDATE' | 'ITEM' | 'PARTIAL_UPDATE' | 'WIDGET_TYPES' | 'SELECTION_TYPES' | 'COLLECTION_DATA' | 'GET_ONE';
1
+ export type ACTION_TYPES = 'IMAGE_UPLOAD' | 'IMAGE_REMOVE' | 'CREATE' | 'LIST' | 'DELETE' | 'UPDATE' | 'ITEM' | 'PARTIAL_UPDATE' | 'WIDGET_TYPES' | 'SELECTION_TYPES' | 'COLLECTION_DATA' | 'GET_ONE' | 'CATEGORIES';
2
2
  export type API_TYPE = {
3
3
  url: string;
4
4
  method: string;
@@ -18,6 +18,10 @@ export type WidgetType = {
18
18
  value: string;
19
19
  label: string;
20
20
  };
21
+ export type Category = {
22
+ value: string;
23
+ label: string;
24
+ };
21
25
  export interface BaseAPIProps {
22
26
  config?: any;
23
27
  baseUrl: string;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { WidgetType, ItemsType } from './api';
2
+ import { WidgetType, ItemsType, Category } from './api';
3
3
  import { FormActionTypes, OptionType } from './common';
4
4
  export interface ProviderContextType {
5
5
  baseUrl: string;
@@ -43,6 +43,7 @@ export interface WidgetContextType {
43
43
  onImageRemove: (id: string) => Promise<void>;
44
44
  itemsTypes: ItemsType[];
45
45
  widgetTypes: WidgetType[];
46
+ categories: Category[];
46
47
  getCollectionData: (collectionName: string, search?: string, callback?: (options: OptionType[]) => void, collectionItems?: string[]) => Promise<void>;
47
48
  collectionDataLoading: boolean;
48
49
  collectionData: any[];