@knovator/pagecreator-admin 1.6.7 → 1.6.9

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
@@ -7138,7 +7138,8 @@ const constants = {
7138
7138
  };
7139
7139
  const WidgetForm = ({
7140
7140
  formRef,
7141
- customInputs
7141
+ customInputs,
7142
+ onPrimaryButtonClick
7142
7143
  }) => {
7143
7144
  const {
7144
7145
  register,
@@ -7199,6 +7200,7 @@ const WidgetForm = ({
7199
7200
  const [blogLimit, setBlogLimit] = React.useState(10);
7200
7201
  const [blogCategories, setBlogCategories] = React.useState([]);
7201
7202
  const [blogCategoriesLoading, setBlogCategoriesLoading] = React.useState(false);
7203
+ const pagesLoadedRef = React.useRef(false);
7202
7204
  React.useEffect(() => {
7203
7205
  if (data && formState === 'UPDATE') {
7204
7206
  const widgetType = widgetTypes.find(type => type.value === (data === null || data === void 0 ? void 0 : data.widgetType));
@@ -7277,56 +7279,16 @@ const WidgetForm = ({
7277
7279
  }
7278
7280
  }
7279
7281
  }, [formState, data, currentItemsType, blogCategories, blogCategory, blogLimit]);
7280
- // Auto-fetch blogs when category or limit changes
7282
+ // Clear collectionItems when using blog category/limit (server will handle fetching latest blogs)
7281
7283
  React.useEffect(() => {
7282
7284
  if (currentItemsType === 'blog') {
7283
- if (blogCategory && blogLimit > 0) {
7284
- // Fetch blogs when category is selected
7285
- const fetchBlogsByCategory = () => __awaiter(void 0, void 0, void 0, function* () {
7286
- var _a;
7287
- try {
7288
- setCollectionItemsUpdated(false);
7289
- const response = yield commonApi({
7290
- baseUrl,
7291
- token,
7292
- method: 'POST',
7293
- url: `${widgetRoutesPrefix}/collection-data`,
7294
- data: {
7295
- search: '',
7296
- collectionName: 'blog',
7297
- collectionItems: []
7298
- },
7299
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7300
- onError: error => console.error('Error fetching blogs:', error)
7301
- });
7302
- if ((response === null || response === void 0 ? void 0 : response.code) === 'SUCCESS' && Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.docs)) {
7303
- // Filter blogs by selected category
7304
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7305
- const filteredBlogs = response.data.docs
7306
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7307
- .filter(blog => Array.isArray(blog.category) &&
7308
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7309
- blog.category.some(cat => cat.id === blogCategory.value)).slice(0, blogLimit)
7310
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7311
- .map(blog => Object.assign(Object.assign({}, blog), {
7312
- value: blog._id,
7313
- label: blog.name || blog.title
7314
- }));
7315
- setSelectedCollectionItems(filteredBlogs);
7316
- setCollectionItemsUpdated(true);
7317
- }
7318
- } catch (error) {
7319
- console.error('Error fetching blogs:', error);
7320
- }
7321
- });
7322
- fetchBlogsByCategory();
7323
- } else if (!blogCategory) {
7324
- // Clear selected blogs when category is cleared
7285
+ if (blogCategory || blogLimit > 0) {
7286
+ // Clear selected collection items since server will fetch latest blogs based on category/limit
7325
7287
  setSelectedCollectionItems([]);
7326
7288
  setCollectionItemsUpdated(true);
7327
7289
  }
7328
7290
  }
7329
- }, [blogCategory, blogLimit, currentItemsType, baseUrl, token, widgetRoutesPrefix]);
7291
+ }, [blogCategory, blogLimit, currentItemsType]);
7330
7292
  // Reset blog category and limit when itemsType changes away from 'blogs'
7331
7293
  React.useEffect(() => {
7332
7294
  if (currentItemsType !== 'blog') {
@@ -7343,6 +7305,18 @@ const WidgetForm = ({
7343
7305
  setBlogLimit(limit);
7344
7306
  }
7345
7307
  }, [watchedBlogLimit, currentItemsType]);
7308
+ // Load pages data when Links widget type is selected
7309
+ React.useEffect(() => {
7310
+ if ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.linksWidgetTypeValue && (selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value) === constants.pagesItemsTypeValue && !pagesLoadedRef.current) {
7311
+ // Trigger initial load of pages
7312
+ pagesLoadedRef.current = true;
7313
+ getCollectionData(constants.pagesItemsTypeValue, '');
7314
+ }
7315
+ // Reset ref when widget type changes away from Links
7316
+ if ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) !== constants.linksWidgetTypeValue) {
7317
+ pagesLoadedRef.current = false;
7318
+ }
7319
+ }, [selectedWidgetType, selectedCollectionType, getCollectionData]);
7346
7320
  const onChangeSearch = (str, callback, collectionName) => {
7347
7321
  let collectionItems = [];
7348
7322
  let valueToSet = '';
@@ -7532,9 +7506,15 @@ const WidgetForm = ({
7532
7506
  }
7533
7507
  return item;
7534
7508
  });
7535
- onWidgetFormSubmit(Object.assign(Object.assign({}, formData), {
7509
+ const submitPayload = Object.assign(Object.assign(Object.assign(Object.assign({}, formData), {
7536
7510
  items
7537
- }));
7511
+ }), blogCategory && {
7512
+ blogCategory: blogCategory.value
7513
+ }), blogLimit && {
7514
+ blogLimit
7515
+ });
7516
+ onPrimaryButtonClick === null || onPrimaryButtonClick === void 0 ? void 0 : onPrimaryButtonClick(undefined, submitPayload);
7517
+ onWidgetFormSubmit(submitPayload);
7538
7518
  };
7539
7519
  const onCollectionIndexChange = result => {
7540
7520
  const {
@@ -7777,7 +7757,7 @@ const WidgetForm = ({
7777
7757
  loadOptions: onChangeSearch,
7778
7758
  isLoading: collectionDataLoading,
7779
7759
  disabled: currentItemsType === 'blog' && !!blogCategory,
7780
- show: !itemsEnabled && ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.carouselWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.fixedCardWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.linksWidgetTypeValue || !selectedWidgetType) && !!(selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value),
7760
+ show: !itemsEnabled && currentItemsType !== 'blog' && ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.carouselWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.fixedCardWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.linksWidgetTypeValue || !selectedWidgetType) && !!(selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value),
7781
7761
  formatOptionLabel: formatOptionLabel,
7782
7762
  listCode: selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value,
7783
7763
  customStyles: reactSelectStyles || {},
@@ -7932,7 +7912,8 @@ const WidgetSearch = () => {
7932
7912
  };
7933
7913
 
7934
7914
  const WidgetFormActions = ({
7935
- formRef
7915
+ formRef,
7916
+ onPrimaryButtonClick
7936
7917
  }) => {
7937
7918
  const {
7938
7919
  onError,
@@ -7947,6 +7928,7 @@ const WidgetFormActions = ({
7947
7928
  } = useWidgetState();
7948
7929
  const onSubmitClick = e => {
7949
7930
  var _a;
7931
+ onPrimaryButtonClick === null || onPrimaryButtonClick === void 0 ? void 0 : onPrimaryButtonClick(e);
7950
7932
  if (!formRef) {
7951
7933
  return onError(CALLBACK_CODES.INTERNAL, 'error', `formRef is required to submit the form!`);
7952
7934
  } else if (!formRef.current) {
@@ -7996,7 +7978,8 @@ const Widget = ({
7996
7978
  formatOptionLabel,
7997
7979
  imageMaxSize,
7998
7980
  translations,
7999
- children
7981
+ children,
7982
+ onPrimaryButtonClick
8000
7983
  }) => {
8001
7984
  const {
8002
7985
  commonTranslations
@@ -8083,10 +8066,12 @@ const Widget = ({
8083
8066
  onClose: onCloseForm,
8084
8067
  title: formState === 'ADD' ? derivedT.addWidgetTitle : formState === 'UPDATE' ? derivedT.updateWidgetTitle : '',
8085
8068
  footerContent: /*#__PURE__*/React__default["default"].createElement(WidgetFormActions, {
8086
- formRef: widgetFormRef
8069
+ formRef: widgetFormRef,
8070
+ onPrimaryButtonClick: onPrimaryButtonClick
8087
8071
  })
8088
8072
  }, /*#__PURE__*/React__default["default"].createElement(WidgetForm, {
8089
- formRef: widgetFormRef
8073
+ formRef: widgetFormRef,
8074
+ onPrimaryButtonClick: onPrimaryButtonClick
8090
8075
  }))), itemData && (/*#__PURE__*/React__default["default"].createElement(DeleteModal, {
8091
8076
  formState: formState,
8092
8077
  itemData: itemData,
package/index.js CHANGED
@@ -7126,7 +7126,8 @@ const constants = {
7126
7126
  };
7127
7127
  const WidgetForm = ({
7128
7128
  formRef,
7129
- customInputs
7129
+ customInputs,
7130
+ onPrimaryButtonClick
7130
7131
  }) => {
7131
7132
  const {
7132
7133
  register,
@@ -7187,6 +7188,7 @@ const WidgetForm = ({
7187
7188
  const [blogLimit, setBlogLimit] = useState(10);
7188
7189
  const [blogCategories, setBlogCategories] = useState([]);
7189
7190
  const [blogCategoriesLoading, setBlogCategoriesLoading] = useState(false);
7191
+ const pagesLoadedRef = useRef(false);
7190
7192
  useEffect(() => {
7191
7193
  if (data && formState === 'UPDATE') {
7192
7194
  const widgetType = widgetTypes.find(type => type.value === (data === null || data === void 0 ? void 0 : data.widgetType));
@@ -7265,56 +7267,16 @@ const WidgetForm = ({
7265
7267
  }
7266
7268
  }
7267
7269
  }, [formState, data, currentItemsType, blogCategories, blogCategory, blogLimit]);
7268
- // Auto-fetch blogs when category or limit changes
7270
+ // Clear collectionItems when using blog category/limit (server will handle fetching latest blogs)
7269
7271
  useEffect(() => {
7270
7272
  if (currentItemsType === 'blog') {
7271
- if (blogCategory && blogLimit > 0) {
7272
- // Fetch blogs when category is selected
7273
- const fetchBlogsByCategory = () => __awaiter(void 0, void 0, void 0, function* () {
7274
- var _a;
7275
- try {
7276
- setCollectionItemsUpdated(false);
7277
- const response = yield commonApi({
7278
- baseUrl,
7279
- token,
7280
- method: 'POST',
7281
- url: `${widgetRoutesPrefix}/collection-data`,
7282
- data: {
7283
- search: '',
7284
- collectionName: 'blog',
7285
- collectionItems: []
7286
- },
7287
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7288
- onError: error => console.error('Error fetching blogs:', error)
7289
- });
7290
- if ((response === null || response === void 0 ? void 0 : response.code) === 'SUCCESS' && Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.docs)) {
7291
- // Filter blogs by selected category
7292
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7293
- const filteredBlogs = response.data.docs
7294
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7295
- .filter(blog => Array.isArray(blog.category) &&
7296
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7297
- blog.category.some(cat => cat.id === blogCategory.value)).slice(0, blogLimit)
7298
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7299
- .map(blog => Object.assign(Object.assign({}, blog), {
7300
- value: blog._id,
7301
- label: blog.name || blog.title
7302
- }));
7303
- setSelectedCollectionItems(filteredBlogs);
7304
- setCollectionItemsUpdated(true);
7305
- }
7306
- } catch (error) {
7307
- console.error('Error fetching blogs:', error);
7308
- }
7309
- });
7310
- fetchBlogsByCategory();
7311
- } else if (!blogCategory) {
7312
- // Clear selected blogs when category is cleared
7273
+ if (blogCategory || blogLimit > 0) {
7274
+ // Clear selected collection items since server will fetch latest blogs based on category/limit
7313
7275
  setSelectedCollectionItems([]);
7314
7276
  setCollectionItemsUpdated(true);
7315
7277
  }
7316
7278
  }
7317
- }, [blogCategory, blogLimit, currentItemsType, baseUrl, token, widgetRoutesPrefix]);
7279
+ }, [blogCategory, blogLimit, currentItemsType]);
7318
7280
  // Reset blog category and limit when itemsType changes away from 'blogs'
7319
7281
  useEffect(() => {
7320
7282
  if (currentItemsType !== 'blog') {
@@ -7331,6 +7293,18 @@ const WidgetForm = ({
7331
7293
  setBlogLimit(limit);
7332
7294
  }
7333
7295
  }, [watchedBlogLimit, currentItemsType]);
7296
+ // Load pages data when Links widget type is selected
7297
+ useEffect(() => {
7298
+ if ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.linksWidgetTypeValue && (selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value) === constants.pagesItemsTypeValue && !pagesLoadedRef.current) {
7299
+ // Trigger initial load of pages
7300
+ pagesLoadedRef.current = true;
7301
+ getCollectionData(constants.pagesItemsTypeValue, '');
7302
+ }
7303
+ // Reset ref when widget type changes away from Links
7304
+ if ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) !== constants.linksWidgetTypeValue) {
7305
+ pagesLoadedRef.current = false;
7306
+ }
7307
+ }, [selectedWidgetType, selectedCollectionType, getCollectionData]);
7334
7308
  const onChangeSearch = (str, callback, collectionName) => {
7335
7309
  let collectionItems = [];
7336
7310
  let valueToSet = '';
@@ -7520,9 +7494,15 @@ const WidgetForm = ({
7520
7494
  }
7521
7495
  return item;
7522
7496
  });
7523
- onWidgetFormSubmit(Object.assign(Object.assign({}, formData), {
7497
+ const submitPayload = Object.assign(Object.assign(Object.assign(Object.assign({}, formData), {
7524
7498
  items
7525
- }));
7499
+ }), blogCategory && {
7500
+ blogCategory: blogCategory.value
7501
+ }), blogLimit && {
7502
+ blogLimit
7503
+ });
7504
+ onPrimaryButtonClick === null || onPrimaryButtonClick === void 0 ? void 0 : onPrimaryButtonClick(undefined, submitPayload);
7505
+ onWidgetFormSubmit(submitPayload);
7526
7506
  };
7527
7507
  const onCollectionIndexChange = result => {
7528
7508
  const {
@@ -7765,7 +7745,7 @@ const WidgetForm = ({
7765
7745
  loadOptions: onChangeSearch,
7766
7746
  isLoading: collectionDataLoading,
7767
7747
  disabled: currentItemsType === 'blog' && !!blogCategory,
7768
- show: !itemsEnabled && ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.carouselWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.fixedCardWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.linksWidgetTypeValue || !selectedWidgetType) && !!(selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value),
7748
+ show: !itemsEnabled && currentItemsType !== 'blog' && ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.carouselWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.fixedCardWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.linksWidgetTypeValue || !selectedWidgetType) && !!(selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value),
7769
7749
  formatOptionLabel: formatOptionLabel,
7770
7750
  listCode: selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value,
7771
7751
  customStyles: reactSelectStyles || {},
@@ -7920,7 +7900,8 @@ const WidgetSearch = () => {
7920
7900
  };
7921
7901
 
7922
7902
  const WidgetFormActions = ({
7923
- formRef
7903
+ formRef,
7904
+ onPrimaryButtonClick
7924
7905
  }) => {
7925
7906
  const {
7926
7907
  onError,
@@ -7935,6 +7916,7 @@ const WidgetFormActions = ({
7935
7916
  } = useWidgetState();
7936
7917
  const onSubmitClick = e => {
7937
7918
  var _a;
7919
+ onPrimaryButtonClick === null || onPrimaryButtonClick === void 0 ? void 0 : onPrimaryButtonClick(e);
7938
7920
  if (!formRef) {
7939
7921
  return onError(CALLBACK_CODES.INTERNAL, 'error', `formRef is required to submit the form!`);
7940
7922
  } else if (!formRef.current) {
@@ -7984,7 +7966,8 @@ const Widget = ({
7984
7966
  formatOptionLabel,
7985
7967
  imageMaxSize,
7986
7968
  translations,
7987
- children
7969
+ children,
7970
+ onPrimaryButtonClick
7988
7971
  }) => {
7989
7972
  const {
7990
7973
  commonTranslations
@@ -8071,10 +8054,12 @@ const Widget = ({
8071
8054
  onClose: onCloseForm,
8072
8055
  title: formState === 'ADD' ? derivedT.addWidgetTitle : formState === 'UPDATE' ? derivedT.updateWidgetTitle : '',
8073
8056
  footerContent: /*#__PURE__*/React.createElement(WidgetFormActions, {
8074
- formRef: widgetFormRef
8057
+ formRef: widgetFormRef,
8058
+ onPrimaryButtonClick: onPrimaryButtonClick
8075
8059
  })
8076
8060
  }, /*#__PURE__*/React.createElement(WidgetForm, {
8077
- formRef: widgetFormRef
8061
+ formRef: widgetFormRef,
8062
+ onPrimaryButtonClick: onPrimaryButtonClick
8078
8063
  }))), itemData && (/*#__PURE__*/React.createElement(DeleteModal, {
8079
8064
  formState: formState,
8080
8065
  itemData: itemData,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knovator/pagecreator-admin",
3
- "version": "1.6.7",
3
+ "version": "1.6.9",
4
4
  "dependencies": {
5
5
  "classnames": "^2.3.1",
6
6
  "react-beautiful-dnd": "^13.1.0",
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { FormProps } from '../../../types';
3
- declare const WidgetForm: ({ formRef, customInputs }: FormProps) => JSX.Element | null;
3
+ declare const WidgetForm: ({ formRef, customInputs, onPrimaryButtonClick }: FormProps) => JSX.Element | null;
4
4
  export default WidgetForm;
@@ -1,13 +1,13 @@
1
1
  /// <reference types="react" />
2
2
  import { WidgetProps } from '../../../types';
3
3
  declare const Widget: {
4
- ({ routes, loader, explicitForm, imageBaseUrl, permissions, preConfirmDelete, formatListItem, formatOptionLabel, imageMaxSize, translations, children, }: WidgetProps): JSX.Element;
4
+ ({ routes, loader, explicitForm, imageBaseUrl, permissions, preConfirmDelete, formatListItem, formatOptionLabel, imageMaxSize, translations, children, onPrimaryButtonClick, }: WidgetProps): JSX.Element;
5
5
  Table: ({ extraActions, extraColumns }: import("../../../types").DerivedTableProps) => JSX.Element;
6
- Form: ({ formRef, customInputs }: import("../../../types").FormProps) => JSX.Element | null;
6
+ Form: ({ formRef, customInputs, onPrimaryButtonClick }: import("../../../types").FormProps) => JSX.Element | null;
7
7
  AddButton: () => JSX.Element;
8
8
  Search: () => JSX.Element;
9
9
  Pagination: () => JSX.Element;
10
10
  FormWrapper: ({ children }: import("../../../types").FormWrapperProps) => JSX.Element | null;
11
- FormActions: ({ formRef }: import("../../../types").FormActionWrapperProps) => JSX.Element | null;
11
+ FormActions: ({ formRef, onPrimaryButtonClick }: import("../../../types").FormActionWrapperProps) => JSX.Element | null;
12
12
  };
13
13
  export default Widget;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { FormActionWrapperProps } from '../../../types';
3
- declare const WidgetFormActions: ({ formRef }: FormActionWrapperProps) => JSX.Element | null;
3
+ declare const WidgetFormActions: ({ formRef, onPrimaryButtonClick }: FormActionWrapperProps) => JSX.Element | null;
4
4
  export default WidgetFormActions;
@@ -214,6 +214,7 @@ export interface WidgetProps {
214
214
  imageBaseUrl?: string;
215
215
  imageMaxSize?: number;
216
216
  translations?: WidgetTranslationPairs;
217
+ onPrimaryButtonClick?: (e?: React.MouseEvent<HTMLButtonElement, MouseEvent>, data?: any) => void;
217
218
  }
218
219
  export interface DerivedTableProps {
219
220
  extraActions?: (item: any) => JSX.Element;