datastake-daf 0.6.824 → 0.6.826

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.
@@ -42258,7 +42258,7 @@ const getFilterOptions$a = (options, t) => {
42258
42258
  const formConfig$8 = {
42259
42259
  namespace: 'armed-groups',
42260
42260
  view: ['scoping', 'new'],
42261
- scope: 'global',
42261
+ scope: 'createArmedGroup',
42262
42262
  formType: 'armed-group'
42263
42263
  };
42264
42264
  const viewConfig$8 = {
@@ -44012,7 +44012,7 @@ const getFilterOptions$6 = (options, t) => {
44012
44012
  const formConfig$4 = {
44013
44013
  namespace: 'testimonials',
44014
44014
  view: 'testimonials',
44015
- scope: 'create',
44015
+ scope: 'createTestimonial',
44016
44016
  formType: 'testimonial'
44017
44017
  };
44018
44018
  const viewConfig$4 = {
@@ -44979,7 +44979,7 @@ const getFilterOptions$3 = (options, t) => {
44979
44979
  const formConfig$1 = {
44980
44980
  namespace: 'conflict-areas',
44981
44981
  view: ['scoping', 'new'],
44982
- scope: 'conflictAreaCreate',
44982
+ scope: 'createConflictArea',
44983
44983
  formType: 'conflict-area'
44984
44984
  };
44985
44985
  const viewConfig$1 = {
@@ -52898,9 +52898,8 @@ class AdminService extends BaseService {
52898
52898
  subject,
52899
52899
  id
52900
52900
  }) {
52901
- const type = subject === 'location' ? 'location' : 'stakeholder';
52902
52901
  return this.apiDelete({
52903
- url: `/management/subject/${type}/${id}`
52902
+ url: `/management/subject/${subject}/${id}`
52904
52903
  });
52905
52904
  }
52906
52905
  async getUserGrowth(activeFilter) {
@@ -61316,6 +61315,22 @@ const usePrepareForm$1 = ({
61316
61315
  };
61317
61316
  };
61318
61317
 
61318
+ const evaluateRule = (rule, data) => {
61319
+ if (typeof rule === "boolean") return rule;
61320
+ if (typeof rule === "function") return rule();
61321
+ if (typeof rule === "string") {
61322
+ const parts = rule.split(" ");
61323
+
61324
+ // Expecting: "<field> <is|not> <value>"
61325
+ if (parts.length === 3) {
61326
+ const [field, condition, value] = parts;
61327
+ if (condition === "is") return data?.[field] === value;
61328
+ if (condition === "not") return data?.[field] !== value;
61329
+ }
61330
+ }
61331
+ console.warn("Invalid rule:", rule);
61332
+ return false;
61333
+ };
61319
61334
  const useViewPermissions = ({
61320
61335
  data,
61321
61336
  id,
@@ -61333,9 +61348,6 @@ const useViewPermissions = ({
61333
61348
  viewConfig
61334
61349
  }) => {
61335
61350
  const baseNamespaceKeys = Object.keys(namespaceConfig || {});
61336
- console.log({
61337
- namespaceConfig
61338
- });
61339
61351
  const baseSupportedNamespaces = baseNamespaceKeys?.reduce((acc, key) => {
61340
61352
  acc[key] = () => true;
61341
61353
  return acc;
@@ -61357,7 +61369,8 @@ const useViewPermissions = ({
61357
61369
  ...baseCanEditAction,
61358
61370
  ...namespaceOverrides.canEdit
61359
61371
  };
61360
- return canEditAction[namespace] ? canEditAction[namespace]() : false;
61372
+ const rule = canEditAction[namespace] ? canEditAction[namespace]() : false;
61373
+ return evaluateRule(rule, data);
61361
61374
  }, [namespace, data, user]);
61362
61375
  const canDelete = React.useMemo(() => {
61363
61376
  baseNamespaceKeys.reduce((acc, key) => {
@@ -61367,7 +61380,8 @@ const useViewPermissions = ({
61367
61380
  const canDeleteAction = {
61368
61381
  ...namespaceOverrides.canDelete
61369
61382
  };
61370
- return canDeleteAction[namespace] ? canDeleteAction[namespace]() : false;
61383
+ const rule = canDeleteAction[namespace] ? canDeleteAction[namespace]() : false;
61384
+ return evaluateRule(rule, data);
61371
61385
  }, [namespace, data, user, namespaceOverrides]);
61372
61386
  React.useEffect(() => {
61373
61387
  if (data) {
@@ -61621,7 +61635,12 @@ const namespaceMap = {
61621
61635
  "production-sites": "location",
61622
61636
  operators: "stakeholder",
61623
61637
  workers: "stakeholder",
61624
- activities: "event"
61638
+ activities: "event",
61639
+ "conflict-areas": "location",
61640
+ "armed-groups": "stakeholder",
61641
+ scl: "location",
61642
+ testimonials: 'event',
61643
+ 'corrective-actions': 'event'
61625
61644
  };
61626
61645
 
61627
61646
  const getColumns = ({
@@ -62008,15 +62027,9 @@ const View = ({
62008
62027
  options,
62009
62028
  getSubjectsDetails,
62010
62029
  namespaceOverrides
62011
- // ADD CALLBACK TO GET THE CURRENT NAMESPACE CONFIG
62012
62030
  }) => {
62013
62031
  const getNamespaceConfig = namespace => namespaceConfiguration?.[namespace] || {};
62014
62032
  const [openRecordsModal, setOpenRecordsModal] = React.useState(false);
62015
- console.log({
62016
- partners
62017
- });
62018
-
62019
- // HANDLES THE URL PARAMS FOR THE VIEW PAGE
62020
62033
  const {
62021
62034
  namespace,
62022
62035
  id,
@@ -62041,8 +62054,6 @@ const View = ({
62041
62054
  getRedirectLink
62042
62055
  });
62043
62056
  const namespaceConfig = React.useMemo(() => getNamespaceConfig(namespace), [namespace]);
62044
-
62045
- // PREPARES THE FORM FOR THE VIEW PAGE
62046
62057
  const {
62047
62058
  form,
62048
62059
  data,
@@ -62099,7 +62110,9 @@ const View = ({
62099
62110
  });
62100
62111
  const subjects = {
62101
62112
  "management-location": "location",
62102
- "management-stakeholder": "stakeholder"
62113
+ "management-stakeholder": "stakeholder",
62114
+ "management-event": "event",
62115
+ "management-incident": "incident"
62103
62116
  };
62104
62117
  const handleDeleteSubject = React.useCallback(async () => {
62105
62118
  try {
@@ -62108,7 +62121,7 @@ const View = ({
62108
62121
  id: id
62109
62122
  });
62110
62123
  antd.message.success(t("Subject deleted successfully"));
62111
- push(getRedirectLink(`/app/management/subject/${subjects[namespace]}`));
62124
+ // push(getRedirectLink(`/app/management/subject/${subjects[namespace]}`));
62112
62125
  } catch (error) {
62113
62126
  handleError(error);
62114
62127
  antd.message.error(t("Failed to delete subject"));
@@ -1016,9 +1016,8 @@ class AdminService extends BaseService {
1016
1016
  subject,
1017
1017
  id
1018
1018
  }) {
1019
- const type = subject === 'location' ? 'location' : 'stakeholder';
1020
1019
  return this.apiDelete({
1021
- url: `/management/subject/${type}/${id}`
1020
+ url: `/management/subject/${subject}/${id}`
1022
1021
  });
1023
1022
  }
1024
1023
  async getUserGrowth(activeFilter) {
@@ -11601,7 +11601,7 @@ const sp = {
11601
11601
  "unlinkData": "¿Está seguro de que desea eliminar este enlace?",
11602
11602
  "Link": "Enlace",
11603
11603
  "riskMitigationMeasures": "Medidas de mitigación del riesgo",
11604
- "other": "Otros",
11604
+ "other": "Otro",
11605
11605
  "Reset": "Restablecer",
11606
11606
  "Lir Details": "Detalles LIR",
11607
11607
  "Locations": "Ubicaciones",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datastake-daf",
3
- "version": "0.6.824",
3
+ "version": "0.6.826",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.2.5",
6
6
  "@antv/g2": "^5.1.1",
@@ -37,12 +37,6 @@ export default function DocumentsTable({
37
37
  const [selectedDocuments, setSelectedDocuments] = useState([]);
38
38
  const { token } = useToken();
39
39
 
40
- const transformedParams = useGetParams({location});
41
-
42
- const getDataWithStringPagination = async () => {
43
- return getData({ params: transformedParams });
44
- };
45
-
46
40
  const {
47
41
  filter,
48
42
  activeTab,
@@ -62,17 +56,13 @@ export default function DocumentsTable({
62
56
  defaultPageSize,
63
57
  filtersConfig,
64
58
  getRedirectLink,
65
- getData: getDataWithStringPagination,
59
+ getData: getData,
66
60
  refetchTrigger,
67
61
  });
68
62
 
69
63
  const selectOptions = useMemo(() => {
70
- return {
71
- category: config.options?.category,
72
- country: config.options?.countries,
73
- sources: [],
74
- };
75
- }, [config.options]);
64
+ return options;
65
+ }, [options]);
76
66
 
77
67
  const columns = useMemo(() => {
78
68
  return getColumns({
@@ -57,7 +57,7 @@ export const getColumns = ({
57
57
  label: typeof item.label === 'object' ? Object.values(item.label)[1] : item.label,
58
58
  }))
59
59
 
60
- const type = findOptions(value, options?.eventsType || []) || "-";
60
+ const type = (value === 'other' ? t(value) : findOptions(value, options?.eventsType || [])) || "-";
61
61
 
62
62
  return <Tooltip title={type}>{type}</Tooltip>;
63
63
  },
@@ -37,12 +37,6 @@ export default function EventsTable({
37
37
  const [selectedEvents, setSelectedEvents] = useState([]);
38
38
  const { token } = useToken();
39
39
 
40
- const transformedParams = useGetParams({location});
41
-
42
- const getDataWithStringPagination = async () => {
43
- return getData({ params: transformedParams });
44
- };
45
-
46
40
  const {
47
41
  filter,
48
42
  activeTab,
@@ -62,7 +56,7 @@ export default function EventsTable({
62
56
  defaultPageSize,
63
57
  filtersConfig,
64
58
  getRedirectLink,
65
- getData: getDataWithStringPagination,
59
+ getData: getData,
66
60
  refetchTrigger,
67
61
  });
68
62
 
@@ -42,12 +42,6 @@ export default function LocationTable({
42
42
  const { token } = useToken();
43
43
  const [isCombineModalOpen, setIsModalOpen] = useState(false);
44
44
 
45
- const transformedParams = useGetParams({location});
46
-
47
- const getDataWithStringPagination = async () => {
48
- return getData({ params: transformedParams });
49
- };
50
-
51
45
  const {
52
46
  filter,
53
47
  activeTab,
@@ -67,7 +61,7 @@ export default function LocationTable({
67
61
  defaultPageSize,
68
62
  filtersConfig,
69
63
  getRedirectLink,
70
- getData: getDataWithStringPagination,
64
+ getData: getData,
71
65
  refetchTrigger,
72
66
  });
73
67
 
@@ -39,12 +39,6 @@ export default function SubjectsTable({
39
39
  const [selectedSubjects, setSelectedSubjects] = useState([]);
40
40
  const { token } = useToken();
41
41
  const [isCombineModalOpen, setIsModalOpen] = useState(false);
42
- const transformedParams = useGetParams({location});
43
-
44
- const getDataWithStringPagination = async () => {
45
- return getData({ params: transformedParams });
46
- };
47
-
48
42
 
49
43
  const {
50
44
  filter,
@@ -65,7 +59,7 @@ export default function SubjectsTable({
65
59
  defaultPageSize,
66
60
  filtersConfig,
67
61
  getRedirectLink,
68
- getData: getDataWithStringPagination,
62
+ getData: getData,
69
63
  refetchTrigger,
70
64
  });
71
65
 
@@ -105,13 +105,21 @@ export const useGetParams = ({location}) => {
105
105
  Object.entries(searchParams).filter(([_, value]) => value != null && value !== '')
106
106
  );
107
107
 
108
- const hasPagination = paginationQuery.skip != null || paginationQuery.take != null;
108
+ const hasPagination = paginationQuery?.skip != null || paginationQuery?.take != null;
109
109
 
110
110
  const { activeTab, ...rest } = otherParams;
111
111
 
112
+ console.log({hasPagination})
113
+
112
114
  const params = useMemo(() => {
113
115
  if (!hasPagination) {
114
- return undefined;
116
+ return {
117
+ pagination: {
118
+ skip: 1,
119
+ take: 20,
120
+ },
121
+ tab: 'active'
122
+ };
115
123
  }
116
124
 
117
125
  return {
@@ -120,7 +128,7 @@ export const useGetParams = ({location}) => {
120
128
  ...(Object.keys(cleanSearchParams)?.length > 0 && { search: cleanSearchParams }),
121
129
  tab: activeTab,
122
130
  }
123
- }, [location.search, hasPagination, paginationQuery, rest, cleanSearchParams, activeTab]);
131
+ }, [location.search]);
124
132
 
125
133
  return params;
126
134
  }
@@ -141,7 +149,8 @@ export function useSubjectsAdminTable({
141
149
  const [initFetchDone, setInitFetchDone] = useState(false);
142
150
  const [loading, setLoading] = useState(false);
143
151
  const [data, setData] = useState([]);
144
-
152
+ const params = useGetParams({location});
153
+
145
154
  const filter = useFilters({
146
155
  goTo,
147
156
  location,
@@ -163,7 +172,7 @@ export function useSubjectsAdminTable({
163
172
  const fetchData = useCallback(async () => {
164
173
  try {
165
174
  setLoading(true);
166
- const { data } = await getData();
175
+ const { data } = await getData({ params });
167
176
  setData(data.data || data || []);
168
177
  filter.setPagination((prev) => ({ ...prev, total: data?.meta?.total || data?.length || 0 }));
169
178
  if (!initFetchDone) {
@@ -173,11 +182,11 @@ export function useSubjectsAdminTable({
173
182
  } catch (err) {
174
183
  console.log(err);
175
184
  }
176
- }, [filter.activeFilters, refetchTrigger, location.search]);
185
+ }, [params]);
177
186
 
178
187
  useEffect(() => {
179
188
  fetchData();
180
- }, [fetchData, refetchTrigger]);
189
+ }, [params, refetchTrigger]);
181
190
 
182
191
  return {
183
192
  filter,
@@ -165,7 +165,7 @@ export const getFilterOptions = (options, t) => {
165
165
  export const formConfig = {
166
166
  namespace: 'testimonials',
167
167
  view: 'testimonials',
168
- scope: 'create',
168
+ scope: 'createTestimonial',
169
169
  formType: 'testimonial',
170
170
  }
171
171
 
@@ -31,7 +31,7 @@ export const getFilterOptions = (options, t) => {
31
31
  export const formConfig = {
32
32
  namespace: 'conflict-areas',
33
33
  view: ['scoping', 'new'],
34
- scope: 'conflictAreaCreate',
34
+ scope: 'createConflictArea',
35
35
  formType: 'conflict-area',
36
36
  }
37
37
 
@@ -60,7 +60,7 @@ export const getFilterOptions = (options, t) => {
60
60
  export const formConfig = {
61
61
  namespace: 'armed-groups',
62
62
  view: ['scoping', 'new'],
63
- scope: 'global',
63
+ scope: 'createArmedGroup',
64
64
  formType: 'armed-group',
65
65
  }
66
66
 
@@ -85,4 +85,9 @@ export const namespaceMap = {
85
85
  operators: "stakeholder",
86
86
  workers: "stakeholder",
87
87
  activities: "event",
88
+ "conflict-areas": "location",
89
+ "armed-groups": "stakeholder",
90
+ scl: "location",
91
+ testimonials: 'event',
92
+ 'corrective-actions': 'event',
88
93
  }
@@ -1,5 +1,26 @@
1
1
  import { useMemo, useEffect } from "react";
2
2
 
3
+ const evaluateRule = (rule, data) => {
4
+ if (typeof rule === "boolean") return rule;
5
+ if (typeof rule === "function") return rule();
6
+
7
+ if (typeof rule === "string") {
8
+ const parts = rule.split(" ");
9
+
10
+ // Expecting: "<field> <is|not> <value>"
11
+ if (parts.length === 3) {
12
+ const [field, condition, value] = parts;
13
+
14
+ if (condition === "is") return data?.[field] === value;
15
+ if (condition === "not") return data?.[field] !== value;
16
+ }
17
+ }
18
+
19
+ console.warn("Invalid rule:", rule);
20
+ return false;
21
+ };
22
+
23
+
3
24
  export const useViewPermissions = ({
4
25
  data,
5
26
  id,
@@ -17,7 +38,6 @@ export const useViewPermissions = ({
17
38
  viewConfig,
18
39
  }) => {
19
40
  const baseNamespaceKeys = Object.keys(namespaceConfig || {});
20
- console.log({namespaceConfig})
21
41
 
22
42
  const baseSupportedNamespaces = baseNamespaceKeys?.reduce((acc, key) => {
23
43
  acc[key] = () => true;
@@ -54,7 +74,8 @@ export const useViewPermissions = ({
54
74
  ...namespaceOverrides.canEdit,
55
75
  };
56
76
 
57
- return canEditAction[namespace] ? canEditAction[namespace]() : false;
77
+ const rule = canEditAction[namespace] ? canEditAction[namespace]() : false;
78
+ return evaluateRule(rule, data);
58
79
  }, [namespace, data, user]);
59
80
 
60
81
  const canDelete = useMemo(() => {
@@ -67,7 +88,8 @@ export const useViewPermissions = ({
67
88
  ...namespaceOverrides.canDelete,
68
89
  };
69
90
 
70
- return canDeleteAction[namespace] ? canDeleteAction[namespace]() : false;
91
+ const rule = canDeleteAction[namespace] ? canDeleteAction[namespace]() : false;
92
+ return evaluateRule(rule, data);
71
93
  }, [namespace, data, user, namespaceOverrides])
72
94
 
73
95
  useEffect(() => {
@@ -51,14 +51,10 @@ const View = ({
51
51
  options,
52
52
  getSubjectsDetails,
53
53
  namespaceOverrides,
54
- // ADD CALLBACK TO GET THE CURRENT NAMESPACE CONFIG
55
54
  }) => {
56
55
  const getNamespaceConfig = (namespace) => namespaceConfiguration?.[namespace] || {};
57
56
  const [openRecordsModal, setOpenRecordsModal] = useState(false);
58
-
59
- console.log({partners})
60
57
 
61
- // HANDLES THE URL PARAMS FOR THE VIEW PAGE
62
58
  const {
63
59
  namespace,
64
60
  id,
@@ -85,7 +81,6 @@ const View = ({
85
81
 
86
82
  const namespaceConfig = useMemo(() => getNamespaceConfig(namespace), [namespace]);
87
83
 
88
- // PREPARES THE FORM FOR THE VIEW PAGE
89
84
  const {
90
85
  form,
91
86
  data,
@@ -139,6 +134,8 @@ const View = ({
139
134
  const subjects = {
140
135
  "management-location": "location",
141
136
  "management-stakeholder": "stakeholder",
137
+ "management-event": "event",
138
+ "management-incident": "incident",
142
139
  }
143
140
 
144
141
 
@@ -149,7 +146,7 @@ const View = ({
149
146
  id: id,
150
147
  });
151
148
  message.success(t("Subject deleted successfully"));
152
- push(getRedirectLink(`/app/management/subject/${subjects[namespace]}`));
149
+ // push(getRedirectLink(`/app/management/subject/${subjects[namespace]}`));
153
150
  } catch (error) {
154
151
  handleError(error);
155
152
  message.error(t("Failed to delete subject"));
@@ -234,9 +234,8 @@ class AdminService extends BaseService {
234
234
  }
235
235
 
236
236
  deleteSubject({ subject, id }) {
237
- const type = subject === 'location' ? 'location' : 'stakeholder';
238
237
  return this.apiDelete({
239
- url: `/management/subject/${type}/${id}`,
238
+ url: `/management/subject/${subject}/${id}`,
240
239
  });
241
240
  }
242
241
 
@@ -467,7 +467,7 @@ const sp = {
467
467
  "unlinkData": "¿Está seguro de que desea eliminar este enlace?",
468
468
  "Link": "Enlace",
469
469
  "riskMitigationMeasures": "Medidas de mitigación del riesgo",
470
- "other": "Otros",
470
+ "other": "Otro",
471
471
  "Reset": "Restablecer",
472
472
  "Lir Details": "Detalles LIR",
473
473
  "Locations": "Ubicaciones",