@visns-studio/visns-components 1.7.6 → 1.8.1

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.
@@ -327,35 +327,33 @@ const DataGrid = forwardRef(
327
327
  ).indexOf(cellElement);
328
328
 
329
329
  if (columnIndex === rowProps.columns.length - 1) {
330
+ // Handle last column click
330
331
  } else {
331
- if (
332
- rowProps.columns[columnIndex].link &&
333
- rowProps.columns[columnIndex].link.url
334
- ) {
335
- if (rowProps.columns[columnIndex].link.folder) {
336
- window.location.href =
337
- rowProps.columns[columnIndex].link.url +
338
- rowProps.data[
339
- rowProps.columns[columnIndex].link.key
340
- ] +
341
- "/" +
332
+ const column = rowProps.columns[columnIndex];
333
+
334
+ if (column.link && column.link.url) {
335
+ const fileRelationArray = column.id.split(".");
336
+ const linkUrl = column.link.url;
337
+ const linkKey = rowProps.columns[columnIndex].link.key;
338
+ const rowData = rowProps.data[linkKey];
339
+
340
+ if (column.link.folder) {
341
+ const linkFolder =
342
342
  rowProps.columns[columnIndex].link.folder;
343
+
344
+ if (rowProps.data[fileRelationArray[0]]) {
345
+ window.location.href = `${linkUrl}${rowData}/${linkFolder}`;
346
+ }
343
347
  } else {
344
- navigate(
345
- `${rowProps.columns[columnIndex].link.url}${
346
- rowProps.data[
347
- rowProps.columns[columnIndex].link.key
348
- ]
349
- }`
350
- );
348
+ navigate(`${linkUrl}${rowData}`);
351
349
  }
352
- } else if (rowProps.columns[columnIndex].link.popup) {
350
+ } else if (column.link && column.link.popup) {
351
+ const linkPopup = column.link.popup;
352
+ const linkKey = rowProps.columns[columnIndex].link.key;
353
+ const rowData = rowProps.data[linkKey];
354
+
353
355
  window.open(
354
- `${rowProps.columns[columnIndex].link.popup}/${
355
- rowProps.data[
356
- rowProps.columns[columnIndex].link.key
357
- ]
358
- }`,
356
+ `${linkPopup}/${rowData}`,
359
357
  "",
360
358
  "width=1440,height=1024,menubar=1,resizable=1,status=1,titlebar=1,toolbar=1"
361
359
  );
@@ -4,77 +4,85 @@ import { trackPromise } from "react-promise-tracker";
4
4
  import { toast } from "react-toastify";
5
5
  import parse from "html-react-parser";
6
6
 
7
- const CustomFetch = async (
8
- url,
9
- method,
10
- formData,
11
- successCallback = null,
12
- errorCallback = null
7
+ const CustomFetch = (
8
+ url,
9
+ method,
10
+ formData,
11
+ successCallback = null,
12
+ errorCallback = null
13
13
  ) => {
14
- const baseUrl = "";
15
- const headers = {
16
- "Content-Type": "application/json",
17
- };
14
+ const baseUrl = "";
15
+ const headers = {
16
+ "Content-Type": "application/json",
17
+ };
18
18
 
19
- if (method.toUpperCase() === "PUT" || method.toUpperCase() === "PATCH") {
20
- formData = {
21
- ...formData,
22
- _method: method,
23
- };
24
- }
19
+ if (method.toUpperCase() === "PUT" || method.toUpperCase() === "PATCH") {
20
+ formData = {
21
+ ...formData,
22
+ _method: method,
23
+ };
24
+ }
25
25
 
26
- const options = {
27
- method: method,
28
- data: formData,
29
- headers: headers,
30
- url: baseUrl + url,
31
- };
26
+ const options = {
27
+ method: method,
28
+ data: formData,
29
+ headers: headers,
30
+ url: baseUrl + url,
31
+ };
32
32
 
33
- try {
34
- const response = await trackPromise(axios(options));
33
+ return trackPromise(
34
+ new Promise((resolve, reject) => {
35
+ axios(options)
36
+ .then((response) => {
37
+ if (successCallback) {
38
+ successCallback(response.data);
39
+ } else {
40
+ const error = response.data.error;
35
41
 
36
- if (successCallback) {
37
- successCallback(response.data);
38
- } else {
39
- const error =
40
- response.data.error || "Data has been updated successfully.";
41
- toast.error(<div>{parse(error)}</div>);
42
- }
43
- } catch (error) {
44
- let errorMessage = "";
42
+ if (error && error !== "") {
43
+ toast.error(<div>{parse(error)}</div>);
44
+ }
45
+ }
46
+ resolve(response);
47
+ })
48
+ .catch((error) => {
49
+ let errorMessage = "";
45
50
 
46
- if (
47
- error.response &&
48
- error.response.data &&
49
- error.response.data.message
50
- ) {
51
- const { data } = error.response;
51
+ if (
52
+ error.response &&
53
+ error.response.data &&
54
+ error.response.data.message
55
+ ) {
56
+ const { data } = error.response;
52
57
 
53
- if (data.errors) {
54
- const { errors } = data;
58
+ if (data.errors) {
59
+ const { errors } = data;
55
60
 
56
- Object.values(errors).forEach((errorArray) => {
57
- errorArray.forEach((errorMsg) => {
58
- errorMessage += `${errorMsg}<br />`;
59
- });
60
- });
61
- } else {
62
- if (data.message === "CSRF token mismatch.") {
63
- window.location.replace("/login");
64
- } else {
65
- errorMessage = data.message;
66
- }
67
- }
68
- } else {
69
- errorMessage = error.message;
70
- }
61
+ Object.values(errors).forEach((errorArray) => {
62
+ errorArray.forEach((errorMsg) => {
63
+ errorMessage += `${errorMsg}<br />`;
64
+ });
65
+ });
66
+ } else {
67
+ if (data.message === "CSRF token mismatch.") {
68
+ window.location.replace("/login");
69
+ } else {
70
+ errorMessage = data.message;
71
+ }
72
+ }
73
+ } else {
74
+ errorMessage = error.message;
75
+ }
71
76
 
72
- if (errorCallback) {
73
- errorCallback(errorMessage);
74
- } else {
75
- toast.error(<div>{parse(errorMessage)}</div>);
76
- }
77
- }
77
+ if (errorCallback) {
78
+ errorCallback(errorMessage);
79
+ } else {
80
+ toast.error(<div>{parse(errorMessage)}</div>);
81
+ }
82
+ reject(error);
83
+ });
84
+ })
85
+ );
78
86
  };
79
87
 
80
88
  export default CustomFetch;