@visns-studio/visns-components 2.9.7 → 2.9.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.
@@ -295,6 +295,18 @@ const DataGrid = forwardRef(
295
295
  const handleSettingClick = (s, d) => {
296
296
  switch (s.id) {
297
297
  case 'delete':
298
+ const getDataId = () => {
299
+ for (const item of ajaxSetting.where) {
300
+ if (
301
+ item.hasOwnProperty('urlParam') &&
302
+ item.urlParam === 'dataId'
303
+ ) {
304
+ return item.value;
305
+ }
306
+ }
307
+ return 0;
308
+ };
309
+
298
310
  confirmAlert({
299
311
  title: 'Delete Item',
300
312
  message:
@@ -310,11 +322,33 @@ const DataGrid = forwardRef(
310
322
  buttons: [
311
323
  {
312
324
  label: 'Yes',
313
- onClick: () =>
325
+ onClick: () => {
326
+ let deleteForm = {
327
+ url: '',
328
+ method: 'DELETE',
329
+ payload: {},
330
+ };
331
+
332
+ if (
333
+ form.hasOwnProperty('json') &&
334
+ form.json === true
335
+ ) {
336
+ deleteForm.url = `${form.url}/jsonDelete`;
337
+ deleteForm.method = 'POST';
338
+ deleteForm.payload = {
339
+ id: d[form.primaryKey],
340
+ dataId: getDataId(),
341
+ };
342
+ } else {
343
+ deleteForm.url = `${form.url}/${
344
+ d[form.primaryKey]
345
+ }`;
346
+ }
347
+
314
348
  CustomFetch(
315
- form.url + '/' + d[form.primaryKey],
316
- 'DELETE',
317
- {},
349
+ deleteForm.url,
350
+ deleteForm.method,
351
+ deleteForm.payload,
318
352
  (result) => {
319
353
  if (result.error === '') {
320
354
  const min = 0;
@@ -338,7 +372,8 @@ const DataGrid = forwardRef(
338
372
  );
339
373
  }
340
374
  }
341
- ),
375
+ );
376
+ },
342
377
  },
343
378
  {
344
379
  label: 'No',
@@ -2030,6 +2065,7 @@ const DataGrid = forwardRef(
2030
2065
  closeOnDocumentClick={false}
2031
2066
  >
2032
2067
  <Form
2068
+ ajaxSetting={ajaxSetting}
2033
2069
  closeModal={modalClose}
2034
2070
  columnId={formId}
2035
2071
  fetchTable={handleReload}
@@ -12,6 +12,7 @@ import Field from './Field';
12
12
  import Table from './DataGrid';
13
13
 
14
14
  function Form({
15
+ ajaxSetting,
15
16
  closeModal,
16
17
  columnId,
17
18
  formType,
@@ -441,11 +442,30 @@ function Form({
441
442
  } else {
442
443
  switch (formType) {
443
444
  case 'create':
444
- // URL and method are already set to default values
445
+ if (
446
+ formSettings.hasOwnProperty('json') &&
447
+ formSettings.json === true
448
+ ) {
449
+ url += '/jsonStore';
450
+ }
445
451
  break;
446
452
  case 'update':
447
453
  case 'delete':
448
- url += `/${formData[formSettings.primaryKey]}`;
454
+ if (
455
+ formSettings.hasOwnProperty('json') &&
456
+ formSettings.json === true
457
+ ) {
458
+ if (formType === 'update') {
459
+ url += `/jsonUpdate`;
460
+ } else {
461
+ url += `/jsonDelete/${
462
+ formData[formSettings.primaryKey]
463
+ }`;
464
+ }
465
+ } else {
466
+ url += `/${formData[formSettings.primaryKey]}`;
467
+ }
468
+
449
469
  method = formType === 'update' ? 'PUT' : 'DELETE';
450
470
  break;
451
471
  }
@@ -578,11 +598,40 @@ function Form({
578
598
 
579
599
  if (formType !== 'create' && columnId > 0) {
580
600
  try {
581
- const result = await CustomFetch(
582
- `${formSettings.url}/${columnId}`,
583
- 'GET',
584
- {}
585
- );
601
+ let urlSuffix,
602
+ method,
603
+ payload = {};
604
+
605
+ // Function to extract dataId from ajaxSetting
606
+ const getDataId = () => {
607
+ for (const item of ajaxSetting.where) {
608
+ if (
609
+ item.hasOwnProperty('urlParam') &&
610
+ item.urlParam === 'dataId'
611
+ ) {
612
+ return item.value;
613
+ }
614
+ }
615
+ return 0;
616
+ };
617
+
618
+ if (
619
+ formSettings.hasOwnProperty('json') &&
620
+ formSettings.json === true
621
+ ) {
622
+ let dataId = getDataId();
623
+
624
+ urlSuffix = '/jsonGet';
625
+ method = 'POST';
626
+ payload = { id: columnId, dataId };
627
+ } else {
628
+ urlSuffix = `/${columnId}`;
629
+ method = 'GET';
630
+ }
631
+
632
+ const url = `${formSettings.url}${urlSuffix}`;
633
+ const result = await CustomFetch(url, method, payload);
634
+
586
635
  const data = result.hasOwnProperty('data')
587
636
  ? result.data
588
637
  : result;
@@ -808,7 +857,7 @@ function Form({
808
857
 
809
858
  useEffect(() => {
810
859
  fetchData();
811
- }, [formSettings]);
860
+ }, []);
812
861
 
813
862
  useEffect(() => {
814
863
  formSettings.fields.forEach((field) => {
@@ -713,8 +713,7 @@ function GenericDetail({ setting, urlParam, userProfile }) {
713
713
  case 'table':
714
714
  if (
715
715
  activeTabConfig.ajaxSetting &&
716
- activeTabConfig.ajaxSetting.where &&
717
- activeTabConfig.ajaxSetting.where.length > 0
716
+ activeTabConfig.ajaxSetting.where
718
717
  ) {
719
718
  const updatedAjaxSetting = {
720
719
  ...activeTabConfig.ajaxSetting,
package/package.json CHANGED
@@ -6,8 +6,8 @@
6
6
  "array-move": "^4.0.0",
7
7
  "awesome-debounce-promise": "^2.1.0",
8
8
  "axios": "^1.6.2",
9
- "framer-motion": "^10.16.12",
10
- "html-react-parser": "^5.0.6",
9
+ "framer-motion": "^10.16.16",
10
+ "html-react-parser": "^5.0.7",
11
11
  "lodash": "^4.17.21",
12
12
  "moment": "^2.29.4",
13
13
  "motion": "^10.16.4",
@@ -29,7 +29,7 @@
29
29
  "react-to-print": "^2.14.15",
30
30
  "react-toastify": "^9.1.3",
31
31
  "react-toggle": "^4.1.3",
32
- "react-tooltip": "^5.24.0",
32
+ "react-tooltip": "^5.25.0",
33
33
  "react-window": "^1.8.10",
34
34
  "reactjs-popup": "^2.0.6",
35
35
  "truncate": "^3.0.0",
@@ -45,7 +45,7 @@
45
45
  "react-dom": "^17.0.1"
46
46
  },
47
47
  "name": "@visns-studio/visns-components",
48
- "version": "2.9.7",
48
+ "version": "2.9.9",
49
49
  "description": "Various packages to assist in the development of our Custom Applications.",
50
50
  "main": "index.js",
51
51
  "scripts": {