datastake-daf 0.6.814 → 0.6.815

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.
@@ -0,0 +1,175 @@
1
+ import { getStatusOptions } from '../../../utils/filters';
2
+
3
+ export const getFiltersConfig = ({t}) => {
4
+ return {
5
+ timeframe: {
6
+ type: "timeframe",
7
+ label: "Timeframe",
8
+ style: { flex: 1 },
9
+ t: t,
10
+ },
11
+ country: {
12
+ type: 'select',
13
+ label: 'Country',
14
+ placeholder: () => `${t('Filter by')} ${t('Country').toLowerCase()}`,
15
+ style: { flex: 1 },
16
+ labelStyle: { flex: 1 },
17
+ getLabel: (option) => option.label,
18
+ getValue: (option) => option.value,
19
+ },
20
+ administrativeLevel1: {
21
+ type: 'ajaxSelect',
22
+ label: ({ t = (s) => s, options = {}, filters = {}, language = 'en' }) => {
23
+ const { administrativeLevel1 } = options;
24
+
25
+ if (administrativeLevel1) {
26
+ if (options.country) {
27
+ const _item = administrativeLevel1[filters.country];
28
+ if (_item) {
29
+ if (_item[language]) {
30
+ return _item[language]
31
+ }
32
+ }
33
+ }
34
+ }
35
+
36
+ return t('Province');
37
+ },
38
+ placeholder: () => `${t('Filter by')} ${t('Province').toLowerCase()}`,
39
+ filters: (data) => ({
40
+ country: data.country,
41
+ level: 'level_1',
42
+ }),
43
+ show: (data) => !data.country,
44
+ disabled: (data) => !data.country,
45
+ mapper: { label: "name", value: "id" },
46
+ method: 'getOptions',
47
+ entity: 'AdministrativeLevel',
48
+ style: { flex: 1 },
49
+ labelStyle: { flex: 1 },
50
+ },
51
+ administrativeLevel2: {
52
+ type: 'ajaxSelect',
53
+ label: ({ t = (s) => s, options = {}, filters = {}, language = 'en' }) => {
54
+ const { administrativeLevel2 } = options;
55
+
56
+ if (administrativeLevel2) {
57
+ if (options.country) {
58
+ const _item = administrativeLevel2[filters.country];
59
+ if (_item) {
60
+ if (_item[language]) {
61
+ return _item[language]
62
+ }
63
+ }
64
+ }
65
+ }
66
+
67
+ return t('Province');
68
+ },
69
+ show: (data) => !(data.country && data.administrativeLevel1),
70
+ placeholder: () => `${t('Filter by')} ${t('Territory').toLowerCase()}`,
71
+ filters: (data) => ({
72
+ country: data.country,
73
+ level: 'level_2',
74
+ administrativeLevel1: data.administrativeLevel1,
75
+ }),
76
+ disabled: (data) => !(data.country && data.administrativeLevel1),
77
+ mapper: { label: "name", value: "id" },
78
+ method: 'getOptions',
79
+ entity: 'AdministrativeLevel',
80
+ style: { flex: 1 },
81
+ labelStyle: { flex: 1 },
82
+ },
83
+ eventCategory: {
84
+ type: 'select',
85
+ label: 'Category',
86
+ placeholder: () => `${t('Filter by')} ${t('Category').toLowerCase()}`,
87
+ style: { flex: 1 },
88
+ labelStyle: { flex: 1 },
89
+ getLabel: (option) => option.label,
90
+ getValue: (option) => option.value,
91
+ filterOptions: (val) => {
92
+ if (val) {
93
+ const { option, filters } = val
94
+ if (filters && option) {
95
+ const { filters: optionFilters } = option;
96
+ if (Array.isArray(optionFilters) && optionFilters.length) {
97
+ const { value, condition } = optionFilters[0];
98
+ if (condition === 'includes') {
99
+ return value.includes('corporation');
100
+ }
101
+ }
102
+ }
103
+ }
104
+ return true;
105
+ },
106
+ },
107
+ // positionInTheMineralSupplyChain: {
108
+ // type: 'select',
109
+ // label: 'Position',
110
+ // placeholder: () => `${t('Filter by')} ${t('Position').toLowerCase()}`,
111
+ // style: { flex: 1 },
112
+ // labelStyle: { flex: 1 },
113
+ // getLabel: (option) => option.label,
114
+ // getValue: (option) => option.value,
115
+ // },
116
+ status: {
117
+ type: "select",
118
+ label: "Status",
119
+ placeholder: () => `${t("Filter by")} ${t("Status").toLowerCase()}`,
120
+ style: { flex: 1 },
121
+ labelStyle: { fley: 1 },
122
+ getLabel: (option) => option.label,
123
+ getValue: (option) => option.value,
124
+ },
125
+ }
126
+ }
127
+
128
+ export const getFilterOptions = (options, t) => {
129
+ const {
130
+ timeframe = [],
131
+ statusOptions,
132
+ categoryOptions,
133
+ countries,
134
+ subCategory,
135
+ category,
136
+ stakeholderCategoryOptions,
137
+ stakeholderSubCategoriesOptions,
138
+ administrativeLevel1,
139
+ administrativeLevel2,
140
+ positionInMineralSupplyChainOptions,
141
+ subCategoriesOptions,
142
+ eventCategoryOptions,
143
+ } = options || {};
144
+
145
+ const _categoryOptions = (eventCategoryOptions || categoryOptions || [])?.map((item) => ({
146
+ value: item.value,
147
+ label: typeof item.label === 'object' ? Object.values(item.label)[1] : item.label,
148
+ }))
149
+
150
+ const _default = {
151
+ timeframe: timeframe,
152
+ status: getStatusOptions(t) || [],
153
+ eventCategory: _categoryOptions || [],
154
+ country: countries || [],
155
+ subCategory: subCategoriesOptions || [],
156
+ // category: category,
157
+ administrativeLevel1,
158
+ administrativeLevel2,
159
+ // positionInTheMineralSupplyChain: positionInMineralSupplyChainOptions || [],
160
+ }
161
+
162
+ return _default;
163
+ }
164
+
165
+ export const formConfig = {
166
+ namespace: 'testimonials',
167
+ view: 'testimonials',
168
+ scope: 'create',
169
+ formType: 'testimonial',
170
+ }
171
+
172
+ export const viewConfig = {
173
+ title: "Testimonials",
174
+ createTitle: "New Testimonial",
175
+ }
@@ -147,13 +147,17 @@ export const getColumns = ({ t, goTo, user, options, activeTab, getRedirectLink,
147
147
  key: "sources",
148
148
  show: activeTab !== "own",
149
149
  render: (val, all) => {
150
- if (all.empty) {
151
- return <div className="daf-default-cell" />;
150
+ if (all.empty) {
151
+ return <div className="daf-default-cell" />;
152
+ }
153
+
154
+ if (!val || val?.length === 0) {
155
+ return "-";
152
156
  }
153
157
 
154
158
  const sources = sourceAvatarConfig(val, user, applications);
155
159
 
156
- return <AvatarGroup items={sources}></AvatarGroup>;
160
+ return <AvatarGroup items={sources} />;
157
161
  },
158
162
  },
159
163
  {
@@ -145,20 +145,25 @@ export const getColumns = ({t, goTo, user, options, activeTab, getRedirectLink,
145
145
  return renderStatusTag({ value: _val, t });
146
146
  },
147
147
  },
148
-
149
- {
150
- title: t("Sources"),
151
- dataIndex: 'sources',
152
- ellipsis: true,
153
- show: activeTab !== "own",
154
- render: (v, all) => {
148
+ {
149
+ title: t("Sources"),
150
+ dataIndex: "sources",
151
+ key: "sources",
152
+ show: activeTab !== "own",
153
+ render: (val, all) => {
155
154
  if (all.empty) {
156
- return <div className="daf-default-cell" />
155
+ return <div className="daf-default-cell" />;
157
156
  }
158
- const sources = sourceAvatarConfig(v, user, applications);
159
- return <AvatarGroup items={sources}></AvatarGroup>;
160
- },
157
+
158
+ if (!val || val?.length === 0) {
159
+ return "-";
160
+ }
161
+
162
+ const sources = sourceAvatarConfig(val, user, applications);
163
+
164
+ return <AvatarGroup items={sources} />;
161
165
  },
166
+ },
162
167
  {
163
168
  id: 'actions',
164
169
  title: "",
@@ -105,11 +105,15 @@ export const getColumns = ({t, goTo, user, options, activeTab, getRedirectLink,
105
105
  return <div className="daf-default-cell" />;
106
106
  }
107
107
 
108
- const sources = sourceAvatarConfig(val, user, applications);
108
+ if (!val || val?.length === 0) {
109
+ return "-";
110
+ }
111
+
112
+ const sources = sourceAvatarConfig(val, user, applications);
109
113
 
110
- return <AvatarGroup items={sources}></AvatarGroup>;
114
+ return <AvatarGroup items={sources} />;
111
115
  },
112
- },
116
+ },
113
117
  {
114
118
  title: t("Last Update"),
115
119
  dataIndex: "updatedAt",
@@ -116,21 +116,25 @@ export const getColumns = ({t, goTo, user, options, activeTab, getRedirectLink,
116
116
  },
117
117
  ellipsis: true,
118
118
  },
119
- {
120
- title: t("Sources"),
121
- dataIndex: "sources",
122
- key: "sources",
123
- show: activeTab !== "own",
124
- render: (val, all) => {
125
- if (all.empty) {
126
- return <div className="daf-default-cell" />;
127
- }
119
+ {
120
+ title: t("Sources"),
121
+ dataIndex: "sources",
122
+ key: "sources",
123
+ show: activeTab !== "own",
124
+ render: (val, all) => {
125
+ if (all.empty) {
126
+ return <div className="daf-default-cell" />;
127
+ }
128
128
 
129
- const sources = sourceAvatarConfig(val, user, applications);
129
+ if (!val || val?.length === 0) {
130
+ return "-";
131
+ }
130
132
 
131
- return <AvatarGroup items={sources}></AvatarGroup>;
132
- },
133
+ const sources = sourceAvatarConfig(val, user, applications);
134
+
135
+ return <AvatarGroup items={sources} />;
133
136
  },
137
+ },
134
138
  {
135
139
  title: t("Status"),
136
140
  dataIndex: 'status',
@@ -101,20 +101,24 @@ export const getColumns = ({t, goTo, user, options, activeTab, getRedirectLink,
101
101
  ellipsis: true,
102
102
  },
103
103
  {
104
- title: t("Sources"),
105
- dataIndex: "sources",
106
- key: "sources",
107
- show: activeTab !== "own",
108
- render: (val, all) => {
109
- if (all.empty) {
110
- return <div className="daf-default-cell" />;
111
- }
104
+ title: t("Sources"),
105
+ dataIndex: "sources",
106
+ key: "sources",
107
+ show: activeTab !== "own",
108
+ render: (val, all) => {
109
+ if (all.empty) {
110
+ return <div className="daf-default-cell" />;
111
+ }
112
112
 
113
- const sources = sourceAvatarConfig(val, user, applications);
113
+ if (!val || val?.length === 0) {
114
+ return "-";
115
+ }
114
116
 
115
- return <AvatarGroup items={sources}></AvatarGroup>;
116
- },
117
- },
117
+ const sources = sourceAvatarConfig(val, user, applications);
118
+
119
+ return <AvatarGroup items={sources} />;
120
+ },
121
+ },
118
122
  {
119
123
  title: t("Status"),
120
124
  dataIndex: "status",
@@ -43,7 +43,9 @@ export const getColumns = ({t, goTo, user, options, activeTab, getRedirectLink,
43
43
  return <div className="daf-default-cell" />
44
44
  }
45
45
 
46
- const category = findOptions(v, options?.categoriesOptions);
46
+ const categoriesOptions = [...(options?.categoriesOptions || []), ...(options?.category || [])]
47
+
48
+ const category = findOptions(v, categoriesOptions);
47
49
 
48
50
  return category ? <Tooltip title={category}>{category}</Tooltip> : '-';
49
51
  },
@@ -58,7 +60,9 @@ export const getColumns = ({t, goTo, user, options, activeTab, getRedirectLink,
58
60
  return <div className="daf-default-cell" />
59
61
  }
60
62
 
61
- const subCategory = findOptions(v, options?.subCategoriesOptions);
63
+ const subCategoriesOptions = [...(options?.subCategoriesOptions || []), ...(options?.subCategory || [])];
64
+
65
+ const subCategory = findOptions(v, subCategoriesOptions);
62
66
 
63
67
  return subCategory ? <Tooltip title={subCategory}>{subCategory}</Tooltip> : '-';
64
68
  },
@@ -89,12 +93,12 @@ export const getColumns = ({t, goTo, user, options, activeTab, getRedirectLink,
89
93
  return <div className="daf-default-cell" />;
90
94
  }
91
95
  if (!val || val?.length === 0) {
92
- return "--";
96
+ return "-";
93
97
  }
94
98
 
95
99
  const sources = sourceAvatarConfig(val, user, applications);
96
100
 
97
- return <AvatarGroup items={sources}></AvatarGroup>;
101
+ return <AvatarGroup items={sources} />;
98
102
  },
99
103
  },
100
104
  {
@@ -45,6 +45,14 @@ import {
45
45
  viewConfig as viewConfigIncidents
46
46
  } from '../Events/Incidents/config.js';
47
47
  import { getColumns as getColumnsIncidents } from "../Events/Incidents/columns.js";
48
+
49
+ import {
50
+ getFiltersConfig as getFiltersConfigTestimonials,
51
+ getFilterOptions as getFilterOptionsTestimonials,
52
+ formConfig as formConfigTestimonials,
53
+ viewConfig as viewConfigTestimonials
54
+ } from '../Events/Testimonials/config.js';
55
+ import { getColumns as getColumnsTestimonials } from "../Events/Testimonials/columns.js";
48
56
 
49
57
  import {
50
58
  getFiltersConfig as getFiltersConfigLocations,
@@ -123,6 +131,13 @@ export const FILTER_REGISTRY = {
123
131
  viewConfig: viewConfigIncidents,
124
132
  columns: getColumnsIncidents,
125
133
  },
134
+ testimonials: {
135
+ config: getFiltersConfigTestimonials,
136
+ options: getFilterOptionsTestimonials,
137
+ formConfig: formConfigTestimonials,
138
+ viewConfig: viewConfigTestimonials,
139
+ columns: getColumnsTestimonials,
140
+ },
126
141
  locations: {
127
142
  config: getFiltersConfigLocations,
128
143
  options: getFilterOptionsLocations,
@@ -1,67 +1,135 @@
1
1
  import { message } from 'antd';
2
2
 
3
+ /**
4
+ * Check if a successful response contains embedded error data
5
+ */
6
+ export const isErrorResponse = (data) => {
7
+ if (!data) return false;
8
+
9
+ return (
10
+ // Check for Exception names
11
+ (data.name && data.name.includes('Exception')) ||
12
+ // Check for nested response with error status
13
+ (data.response?.statusCode && data.response.statusCode >= 400) ||
14
+ // Check for top-level error status
15
+ (data.statusCode && data.statusCode >= 400) ||
16
+ // Check for explicit error flag
17
+ data.error === true ||
18
+ // Check for nested error property
19
+ (data.response?.error && data.response.error !== null)
20
+ );
21
+ };
22
+
23
+ /**
24
+ * Extract error message from various error response formats
25
+ */
26
+ export const getErrorMessage = (data) => {
27
+ return (
28
+ data?.message ||
29
+ data?.response?.message ||
30
+ data?.response?.error ||
31
+ 'An error occurred'
32
+ );
33
+ };
34
+
3
35
  /**
4
36
  * Generic error handler factory for axios requests
5
37
  * Highly configurable to adapt to different project needs
6
38
  */
7
39
  export const createErrorHandler = (config = {}) => {
8
- const {
9
- onUnauthorized,
10
- handleError,
11
- getStorageManager,
12
- checkTokenValidity = true,
13
- unauthorizedRedirect = '/',
14
- tokenStorageKey = 'token',
15
- handleNetworkError = true,
16
- } = config;
17
-
18
- return (error, customOnUnauthorized) => {
19
- // Handle cases where error.response doesn't exist (network errors)
20
- if (!error.response) {
21
- if (handleNetworkError && handleError) {
22
- handleError({
23
- status: 0,
24
- statusText: "Network Error",
25
- data: ["Please check your internet connection."],
26
- });
27
- }
28
- return Promise.reject(error);
40
+ const {
41
+ onUnauthorized,
42
+ handleError,
43
+ getStorageManager,
44
+ checkTokenValidity = true,
45
+ unauthorizedRedirect = '/',
46
+ tokenStorageKey = 'token',
47
+ handleNetworkError = true,
48
+ } = config;
49
+
50
+ return (error, customOnUnauthorized) => {
51
+ // Handle cases where error.response doesn't exist (network errors)
52
+ if (!error.response) {
53
+ if (handleNetworkError && handleError) {
54
+ handleError({
55
+ status: 0,
56
+ statusText: "Network Error",
57
+ data: ["Please check your internet connection."],
58
+ });
29
59
  }
30
-
31
- const { status, statusText, data: { errors, message } = {} } = error.response || { data: {} };
32
-
33
- // Handle 401 Unauthorized
34
- if (status === 401) {
35
- if (checkTokenValidity && getStorageManager) {
36
- const token = getStorageManager().get(tokenStorageKey);
37
- if (token) {
38
- if (typeof customOnUnauthorized === 'function') {
39
- customOnUnauthorized();
40
- } else if (typeof onUnauthorized === 'function') {
41
- onUnauthorized();
42
- } else {
43
- getStorageManager().clearOne(tokenStorageKey);
44
- if (typeof window !== 'undefined') {
45
- window.location.href = unauthorizedRedirect;
46
- }
60
+ return Promise.reject(error);
61
+ }
62
+
63
+ const { status, statusText, data: { errors, message } = {} } = error.response || { data: {} };
64
+
65
+ // Handle 401 Unauthorized
66
+ if (status === 401) {
67
+ if (checkTokenValidity && getStorageManager) {
68
+ const token = getStorageManager().get(tokenStorageKey);
69
+ if (token) {
70
+ if (typeof customOnUnauthorized === 'function') {
71
+ customOnUnauthorized();
72
+ } else if (typeof onUnauthorized === 'function') {
73
+ onUnauthorized();
74
+ } else {
75
+ getStorageManager().clearOne(tokenStorageKey);
76
+ if (typeof window !== 'undefined') {
77
+ window.location.href = unauthorizedRedirect;
47
78
  }
48
79
  }
49
80
  }
50
81
  }
51
-
52
- // Handle 4xx and 5xx errors
53
- if (status >= 400 && status <= 500) {
54
- if (handleError) {
55
- handleError({
56
- status,
57
- statusText: message || statusText,
58
- data: errors || []
59
- });
82
+ }
83
+
84
+ // Handle 4xx and 5xx errors
85
+ if (status >= 400 && status <= 500) {
86
+ if (handleError) {
87
+ handleError({
88
+ status,
89
+ statusText: message || statusText,
90
+ data: errors || []
91
+ });
92
+ }
93
+ }
94
+
95
+ return Promise.reject(error);
96
+ };
97
+ };
98
+
99
+ /**
100
+ * Create axios response interceptor to catch embedded errors in successful responses
101
+ */
102
+ export const createResponseInterceptor = (config = {}) => {
103
+ const { showNotification = true } = config;
104
+
105
+ return {
106
+ onSuccess: (response) => {
107
+ // Check if the response data contains an error
108
+ if (isErrorResponse(response.data)) {
109
+ const errorMessage = getErrorMessage(response.data);
110
+
111
+ if (showNotification) {
112
+ message.error(errorMessage);
60
113
  }
114
+
115
+ // Convert to a rejected promise so catch blocks handle it
116
+ const error = new Error(errorMessage);
117
+ error.response = {
118
+ data: response.data,
119
+ status: response.data.statusCode || response.data.response?.statusCode || 200,
120
+ statusText: errorMessage,
121
+ };
122
+ error.isEmbeddedError = true; // Flag to identify these special errors
123
+
124
+ return Promise.reject(error);
61
125
  }
62
126
 
127
+ return response;
128
+ },
129
+ onError: (error) => {
63
130
  return Promise.reject(error);
64
- };
131
+ }
132
+ };
65
133
  };
66
134
 
67
135
  /**
@@ -69,29 +137,29 @@ export const createErrorHandler = (config = {}) => {
69
137
  * Useful for quick error notifications
70
138
  */
71
139
  export const handleError = (err) => {
72
- const errorMessage = err?.response?.data?.message ||
73
- err?.message ||
74
- 'An error occurred';
75
- message.error(errorMessage);
76
- };
77
-
78
- /**
79
- * Success message handler
80
- */
81
- export const handleSuccess = (msg) => {
82
- message.success(msg || 'Operation successful');
83
- };
84
-
85
- /**
86
- * Warning message handler
87
- */
88
- export const handleWarning = (msg) => {
89
- message.warning(msg || 'Warning');
90
- };
91
-
92
- /**
93
- * Info message handler
94
- */
95
- export const handleInfo = (msg) => {
96
- message.info(msg);
97
- };
140
+ const errorMessage = err?.response?.data?.message ||
141
+ err?.message ||
142
+ 'An error occurred';
143
+ message.error(errorMessage);
144
+ };
145
+
146
+ /**
147
+ * Success message handler
148
+ */
149
+ export const handleSuccess = (msg) => {
150
+ message.success(msg || 'Operation successful');
151
+ };
152
+
153
+ /**
154
+ * Warning message handler
155
+ */
156
+ export const handleWarning = (msg) => {
157
+ message.warning(msg || 'Warning');
158
+ };
159
+
160
+ /**
161
+ * Info message handler
162
+ */
163
+ export const handleInfo = (msg) => {
164
+ message.info(msg);
165
+ };
package/src/utils.js CHANGED
@@ -46,7 +46,7 @@ export { StorageManager } from './helpers/StorageManager.js';
46
46
 
47
47
  export { assignParamsToUrl, buildQueryString } from './helpers/urlHelpers.js';
48
48
 
49
- export { createErrorHandler, handleError, handleSuccess, handleWarning, handleInfo } from './helpers/errorHandling.js';
49
+ export { createErrorHandler, handleError, handleSuccess, handleWarning, handleInfo, isErrorResponse, getErrorMessage } from './helpers/errorHandling.js';
50
50
 
51
51
  export { createTheme, createAdminTheme } from './helpers/theme.js';
52
52