datastake-daf 0.6.767 → 0.6.768

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.
Files changed (43) hide show
  1. package/dist/components/index.js +257 -196
  2. package/dist/pages/index.js +17468 -18460
  3. package/package.json +1 -1
  4. package/src/@daf/core/components/Dashboard/Map/ChainIcon/Markers/StakeholderMarker.js +5 -2
  5. package/src/@daf/core/components/Dashboard/Map/ChainIcon/index.js +67 -27
  6. package/src/@daf/core/components/Dashboard/Map/hook.js +26 -32
  7. package/src/@daf/core/components/Screens/BaseScreen/index.jsx +1 -1
  8. package/src/@daf/core/components/Screens/TableScreen/TablePageWithTabs/index.jsx +1 -1
  9. package/src/@daf/core/components/UI/MissingTagButton/index.jsx +36 -0
  10. package/src/@daf/pages/Dashboards/SupplyChain/components/SupplyChainMap/index.js +0 -2
  11. package/src/@daf/pages/Documents/config.js +0 -10
  12. package/src/@daf/pages/Documents/index.jsx +51 -108
  13. package/src/@daf/pages/Events/Activities/config.js +1 -11
  14. package/src/@daf/pages/Events/Activities/index.jsx +47 -105
  15. package/src/@daf/pages/Events/Incidents/config.js +1 -11
  16. package/src/@daf/pages/Events/Incidents/index.jsx +47 -105
  17. package/src/@daf/pages/Events/config.js +18 -34
  18. package/src/@daf/pages/Events/index.jsx +49 -111
  19. package/src/@daf/pages/Locations/MineSite/config.js +0 -10
  20. package/src/@daf/pages/Locations/MineSite/index.jsx +47 -105
  21. package/src/@daf/pages/Locations/config.js +4 -16
  22. package/src/@daf/pages/Locations/index.jsx +53 -110
  23. package/src/@daf/pages/Stakeholders/Operators/config.js +0 -10
  24. package/src/@daf/pages/Stakeholders/Operators/index.jsx +47 -105
  25. package/src/@daf/pages/Stakeholders/Workers/config.js +0 -10
  26. package/src/@daf/pages/Stakeholders/Workers/index.jsx +47 -105
  27. package/src/@daf/pages/Stakeholders/config.js +3 -15
  28. package/src/@daf/pages/Stakeholders/index.jsx +53 -109
  29. package/src/@daf/pages/TablePage/config.js +78 -0
  30. package/src/@daf/{core/components/Screens/TableScreen/TableWithTabsAndCreate → pages/TablePage}/create.jsx +6 -5
  31. package/src/@daf/pages/TablePage/hook.js +123 -0
  32. package/src/@daf/pages/TablePage/index.jsx +142 -0
  33. package/src/index.js +1 -0
  34. package/src/@daf/core/components/Screens/TableScreen/TableWithTabsAndCreate/index.jsx +0 -115
  35. package/src/@daf/pages/Documents/create.jsx +0 -105
  36. package/src/@daf/pages/Events/Activities/create.jsx +0 -104
  37. package/src/@daf/pages/Events/Incidents/create.jsx +0 -104
  38. package/src/@daf/pages/Events/create.jsx +0 -104
  39. package/src/@daf/pages/Locations/MineSite/create.jsx +0 -104
  40. package/src/@daf/pages/Locations/create.jsx +0 -104
  41. package/src/@daf/pages/Stakeholders/Operators/create.jsx +0 -104
  42. package/src/@daf/pages/Stakeholders/Workers/create.jsx +0 -104
  43. package/src/@daf/pages/Stakeholders/create.jsx +0 -105
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datastake-daf",
3
- "version": "0.6.767",
3
+ "version": "0.6.768",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.2.5",
6
6
  "@antv/g2": "^5.1.1",
@@ -90,7 +90,7 @@ export default function StakeholderIcon({
90
90
  useEffect(() => {
91
91
  linkNodesData.map((node) => {
92
92
  const isConnectingToStakeholder = node.isStakeholder;
93
- const id = `${data.datastakeId}-${node.stakeholderId}`;
93
+ const id = `${data.datastakeId}-${node.stakeholderId || node.datastakeId}`;
94
94
  const targetsParentId = node.parentId;
95
95
  const targetMarkerIndex = node.stakeholdersIndex;
96
96
  const isSibling = targetsParentId === parentId;
@@ -234,7 +234,10 @@ export default function StakeholderIcon({
234
234
  onClickLink(data);
235
235
  },
236
236
  })}
237
- getPopupContainer={() => document.getElementById("map")}
237
+ getPopupContainer={(triggerNode) => {
238
+ const mapElement = document.getElementById("map");
239
+ return mapElement || triggerNode.parentElement || document.body;
240
+ }}
238
241
  >
239
242
  <StakeholderMarker
240
243
  className={`${data.type} ${
@@ -32,7 +32,8 @@ export default function LocationIcon({
32
32
  activeMarker,
33
33
  setActiveMarker,
34
34
  }) {
35
- const root = useRef(null);
35
+ const rootsMapRef = useRef(new Map());
36
+ const markersRef = useRef([])
36
37
  const isSelected = selectedMarkersId.includes(data.datastakeId);
37
38
  const Marker = useMemo(() => {
38
39
  if (isMineSite(data.type)) {
@@ -75,7 +76,22 @@ export default function LocationIcon({
75
76
  }, [data.stakeholders, zoom]);
76
77
 
77
78
  useEffect(() => {
78
- stakeholdersOfLocation.map((stakeholder, index) => {
79
+ const currentRoots = rootsMapRef.current;
80
+ const currentMarkers = markersRef.current;
81
+
82
+ currentMarkers.forEach(marker => {
83
+ if (mapRef.hasLayer(marker)) {
84
+ mapRef.removeLayer(marker);
85
+ }
86
+ });
87
+ currentRoots.forEach(root => {
88
+ root.unmount();
89
+ });
90
+ currentRoots.clear();
91
+ markersRef.current = [];
92
+
93
+ // Create new markers
94
+ stakeholdersOfLocation.forEach((stakeholder, index) => {
79
95
  const markerId = `${stakeholder.datastakeId}`;
80
96
  const { x, y, radius, center } = getStakeholderPosition({
81
97
  zoom,
@@ -94,6 +110,7 @@ export default function LocationIcon({
94
110
  const pathLocLatLng = mapRef.layerPointToLatLng(pathLocPoint);
95
111
  const isForceOpen = activeMarker?.datastakeId === data.datastakeId;
96
112
  const iconSize = isSmallMarker(zoom) || isExtraSmallMarker(zoom) ? [11, 11] : [25, 25];
113
+
97
114
  const marker = L.marker(stakeholderLatLng, {
98
115
  icon: L.divIcon({
99
116
  html: `<div id="${markerId}"></div>`,
@@ -102,31 +119,38 @@ export default function LocationIcon({
102
119
  }),
103
120
  }).addTo(mapRef);
104
121
 
105
- const div = document.getElementById(markerId);
106
- root.current = createRoot(div);
122
+ markersRef.current.push(marker);
107
123
 
108
- root.current.render(
109
- <StakeholderIcon
110
- data={stakeholder}
111
- zoom={zoom}
112
- allData={allData}
113
- link={link}
114
- parentId={data.datastakeId}
115
- renderTooltip={renderTooltip}
116
- onClickLink={onClickLink}
117
- selectedMarkersId={selectedMarkersId}
118
- handleSelectMarker={handleSelectMarker}
119
- mapRef={mapRef}
120
- radius={radius}
121
- index={index}
122
- x={x}
123
- y={y}
124
- openPopupIdRef={openPopupIdRef}
125
- polylinesRef={polylinesRef}
126
- isForceOpen={isForceOpen}
127
- activeMarker={activeMarker}
128
- />,
129
- );
124
+ setTimeout(() => {
125
+ const div = document.getElementById(markerId);
126
+ if (div && !rootsMapRef.current.has(markerId)) {
127
+ const root = createRoot(div);
128
+ rootsMapRef.current.set(markerId, root);
129
+
130
+ root.render(
131
+ <StakeholderIcon
132
+ data={stakeholder}
133
+ zoom={zoom}
134
+ allData={allData}
135
+ link={link}
136
+ parentId={data.datastakeId}
137
+ renderTooltip={renderTooltip}
138
+ onClickLink={onClickLink}
139
+ selectedMarkersId={selectedMarkersId}
140
+ handleSelectMarker={handleSelectMarker}
141
+ mapRef={mapRef}
142
+ radius={radius}
143
+ index={index}
144
+ x={x}
145
+ y={y}
146
+ openPopupIdRef={openPopupIdRef}
147
+ polylinesRef={polylinesRef}
148
+ isForceOpen={isForceOpen}
149
+ activeMarker={activeMarker}
150
+ />,
151
+ );
152
+ }
153
+ }, 0);
130
154
 
131
155
  setMapMarkers((prev) => {
132
156
  const array = [
@@ -162,6 +186,19 @@ export default function LocationIcon({
162
186
  listOfPolylines: polylinesRef.current,
163
187
  });
164
188
  });
189
+
190
+ return () => {
191
+ markersRef.current.forEach(marker => {
192
+ if (mapRef.hasLayer(marker)) {
193
+ mapRef.removeLayer(marker);
194
+ }
195
+ });
196
+ rootsMapRef.current.forEach(root => {
197
+ root.unmount();
198
+ });
199
+ rootsMapRef.current.clear();
200
+ markersRef.current = [];
201
+ };
165
202
  }, [stakeholdersOfLocation, selectedMarkersId, activeMarker]);
166
203
 
167
204
  linkedNodesData.map((node) => {
@@ -213,7 +250,10 @@ export default function LocationIcon({
213
250
  // (!openPopupIdRef.current || openPopupIdRef.current === data.datastakeId) &&
214
251
  // isHovering
215
252
  // }
216
- getPopupContainer={() => document.getElementById("map")}
253
+ getPopupContainer={(triggerNode) => {
254
+ const mapElement = document.getElementById("map");
255
+ return mapElement || triggerNode.parentElement || document.body;
256
+ }}
217
257
  >
218
258
  <div style={{ position: "relative", display: "inline-block" }}>
219
259
  {(isSelected || selectedMarkersId.length === 0) && (
@@ -82,43 +82,37 @@ export const useMap = ({
82
82
  const highlightTable = {};
83
83
 
84
84
  for (const [node] of graph) {
85
- const visited = new Set();
86
- const queue = [node];
87
-
88
- while (queue.length) {
89
- const current = queue.shift();
90
- if (visited.has(current)) continue;
91
-
92
- const currentType = nodeTypes.get(current);
93
-
94
- if (current !== node && isLocation(currentType)) continue;
95
-
96
- visited.add(current);
97
-
98
- for (const neighbor of graph.get(current)) {
99
- if (!visited.has(neighbor)) queue.push(neighbor);
100
- }
85
+ const highlighted = new Set();
86
+
87
+ highlighted.add(node);
88
+
89
+ const nodeIsStakeholder = !isLocation(nodeTypes.get(node));
90
+ if (nodeIsStakeholder && stakeToLoc.has(node)) {
91
+ const parentLoc = stakeToLoc.get(node);
92
+ highlighted.add(parentLoc);
101
93
  }
102
-
103
- if (!isLocation(nodeTypes.get(node)) && stakeToLoc.has(node)) {
104
- visited.add(stakeToLoc.get(node));
105
- }
106
-
107
- visited.add(node);
108
-
109
- const extraLocs = new Set();
110
- for (const n of visited) {
111
- for (const neighbor of graph.get(n) || []) {
112
- if (isLocation(nodeTypes.get(neighbor))) {
113
- extraLocs.add(neighbor);
94
+
95
+ for (const neighbor of graph.get(node) || []) {
96
+ const neighborIsStakeholder = !isLocation(nodeTypes.get(neighbor));
97
+
98
+ if (neighborIsStakeholder && stakeToLoc.has(neighbor)) {
99
+ const neighborParent = stakeToLoc.get(neighbor);
100
+
101
+ if (
102
+ (isLocation(nodeTypes.get(node)) && neighborParent === node) ||
103
+ (nodeIsStakeholder && stakeToLoc.get(node) === neighborParent)
104
+ ) {
105
+ highlighted.add(neighbor);
106
+ } else {
107
+ highlighted.add(neighbor);
108
+ highlighted.add(neighborParent);
114
109
  }
110
+ } else {
111
+ highlighted.add(neighbor);
115
112
  }
116
113
  }
117
- for (const loc of extraLocs) {
118
- visited.add(loc);
119
- }
120
114
 
121
- highlightTable[node] = [...visited];
115
+ highlightTable[node] = [...highlighted];
122
116
  }
123
117
 
124
118
  return highlightTable;
@@ -134,7 +134,7 @@ const BaseScreen = ({
134
134
  <div className="daf-table-wrapper pagination-w-padding">
135
135
  <DAFTable
136
136
  columns={columns}
137
- data={data?.data}
137
+ data={Array.isArray(data?.data) ? data?.data : data?.data?.data}
138
138
  loading={loading}
139
139
  hideOnLoading={false}
140
140
  pagination={pagination}
@@ -90,7 +90,7 @@ const TablePageWithTabs = ({
90
90
  checkboxConfig={checkboxConfig}
91
91
  defaultTableFilters={{}}
92
92
  columns={columns}
93
- data={data}
93
+ data={data?.data}
94
94
  loading={loading}
95
95
  location={location}
96
96
  goTo={goTo}
@@ -0,0 +1,36 @@
1
+ import React from 'react'
2
+ import { Tag, Tooltip } from 'antd'
3
+ import { formatClassname } from '../../../../../helpers/ClassesHelper.js'
4
+
5
+ function MissingTagButton({
6
+ hasMissing,
7
+ setHighlightMandatory,
8
+ highlightMandatory,
9
+ t,
10
+ }) {
11
+ return (
12
+ <>
13
+ {hasMissing ? (
14
+ <Tag
15
+ onClick={() => setHighlightMandatory(!highlightMandatory)}
16
+ className={formatClassname(['ml-2 highlight-tag', highlightMandatory && 'highlighted'])}
17
+ style={{textAlign: "center"}}
18
+ >
19
+ {t('missing-inputs')}
20
+ </Tag>
21
+ ) : (
22
+ <Tooltip title={t('all-inputs-fullfilled')}>
23
+ <Tag
24
+ onClick={() => setHighlightMandatory(!highlightMandatory)}
25
+ className={formatClassname(['ml-2 highlight-tag disabled'])}
26
+ style={{textAlign: "center"}}
27
+ >
28
+ {t('missing-inputs')}
29
+ </Tag>
30
+ </Tooltip>
31
+ )}
32
+ </>
33
+ )
34
+ }
35
+
36
+ export default MissingTagButton;
@@ -24,8 +24,6 @@ function SupplyChainMap({selectedSources = {}, t = () => {}, goTo = () => {}, op
24
24
 
25
25
  const { loading, data } = useWidgetFetch({config: defaultConfig});
26
26
 
27
- console.log('data', data);
28
-
29
27
  return (
30
28
  <Widget
31
29
  title={t("Supply Chain Map")}
@@ -1,8 +1,3 @@
1
- export const checkboxConfig = {
2
- name: 'Name',
3
- datastakeId: 'ID'
4
- }
5
-
6
1
  export const getFiltersConfig = ({t}) => {
7
2
  return {
8
3
  timeframe: {
@@ -13,11 +8,6 @@ export const getFiltersConfig = ({t}) => {
13
8
  }
14
9
  }
15
10
 
16
- export const filtersConfig = {
17
- name: '',
18
- datastakeId: '',
19
- };
20
-
21
11
  export const getFilterOptions = (options, t) => {
22
12
  const { timeframe = [] } = options || {};
23
13
  const _default = {
@@ -1,11 +1,6 @@
1
- import React, { useMemo, useState, useEffect, useCallback } from 'react'
2
- import TablePageWithTabs from '../../core/components/Screens/TableScreen/TablePageWithTabs/index.jsx'
1
+ import React from 'react'
3
2
  import { getColumns } from './columns.js';
4
- import { checkboxConfig, getFiltersConfig, filtersConfig, getFilterOptions } from './config.js';
5
- import { useGetQueryParams } from '../../hooks/useGetQueryParams.js';
6
- import StakeholdersCreate from './create.jsx';
7
- import { displayMessage } from '../../../helpers/messages.js';
8
- import { useFetchData } from '../hook.js';
3
+ import TablePage from '../TablePage/index.jsx';
9
4
 
10
5
  const DocumentsTable = ({
11
6
  t = () => {},
@@ -37,109 +32,57 @@ const DocumentsTable = ({
37
32
  subjectClear = () => {},
38
33
  breadcrumbs = [],
39
34
  extendingFilters = {},
35
+ createDefaultValues = {},
40
36
  }) => {
41
- const [selectOptions, setSelectOptions] = useState();
42
- const [activeTab, setActiveTab] = useState("own");
43
- const columns = useMemo(() => getColumns({
44
- t,
45
- goTo,
46
- user,
47
- options,
48
- activeTab,
49
- getRedirectLink,
50
- theme,
51
- subject: 'documents',
52
- applications,
53
- }), [t, goTo, user, options, activeTab, getRedirectLink, theme, applications]);
54
-
55
- useFetchData({
56
- location,
57
- getData,
58
- activeTab,
59
- extendingFilters,
60
- subject: 'documents',
61
- })
62
-
63
- const selectFiltersConfig = useMemo(() => {
64
- return getFiltersConfig({t});
65
- }, [t]);
66
-
67
- useEffect(() => {
68
- setSelectOptions((prev) => ({
69
- ...prev,
70
- ...getFilterOptions(options, t),
71
- }))
72
- }, [options, t])
73
-
74
- const handleActiveTabChange = useCallback((value) => {
75
- setActiveTab(value);
76
- }, []);
77
-
78
- useEffect(
79
- () => () => {
80
- subjectClear();
81
- },
82
- [],
83
- );
84
-
85
37
  return (
86
- <TablePageWithTabs
87
- t={t}
88
- title={t("Documents")}
89
- breadCrumbs={breadcrumbs}
90
- location={location}
91
- loading={loading}
92
- goTo={goTo}
93
- defaultActiveTab={"own"}
94
- columns={columns}
95
- data={data}
96
- checkboxConfig={checkboxConfig}
97
- APP={APP}
98
- getApiBaseUrl={getApiBaseUrl}
99
- selectOptions={selectOptions}
100
- selectFiltersConfig={selectFiltersConfig}
101
- getRedirectLink={getRedirectLink}
102
- filtersConfig={filtersConfig}
103
- isMobile={isMobile}
104
- view="documents"
105
- getActiveTab={handleActiveTabChange}
106
- onDownload={() => {
107
- console.log("download");
108
- }}
109
- drawerTitle={t("Create Document")}
110
- >
111
- {({onDrawerClose}) => (
112
- <StakeholdersCreate
113
- t={t}
114
- goTo={goTo}
115
- user={user}
116
- APP={APP}
117
- getApiBaseUrl={getApiBaseUrl}
118
- getAppHeader={getAppHeader}
119
- getData={getFormData}
120
- saveData={saveFormData}
121
- loading={formLoading}
122
- onSubmitted={(type, m, data) => {
123
- if (data.datastakeId) {
124
- displayMessage(
125
- type,
126
- t("affirmations::subject-created-successfully") || m,
127
- );
128
- goTo(`/app/edit/documents/${data.datastakeId}`);
129
- }
130
- }}
131
- onCancel={onDrawerClose}
132
- query={query}
133
- ajaxForms={ajaxForms}
134
- changeAjaxForms={changeAjaxForms}
135
- ajaxOptions={ajaxOptions}
136
- changeAjaxOptions={changeAjaxOptions}
137
- formData={formData}
138
- formValue={formValue}
139
- form={form}
140
- />
141
- )}
142
- </TablePageWithTabs>
38
+ <TablePage
39
+ t={t}
40
+ goTo={goTo}
41
+ user={user}
42
+ options={options}
43
+ getRedirectLink={getRedirectLink}
44
+ theme={theme}
45
+ loading={loading}
46
+ data={data}
47
+ isMobile={isMobile}
48
+ APP={APP}
49
+ location={location}
50
+ applications={applications}
51
+
52
+ subject="documents"
53
+ getData={getData}
54
+ getApiBaseUrl={getApiBaseUrl}
55
+ getAppHeader={getAppHeader}
56
+ subjectClear={subjectClear}
57
+ getColumns={getColumns}
58
+
59
+ viewConfig={{
60
+ title: "Documents",
61
+ breadcrumbs: breadcrumbs,
62
+ createTitle: "Create Document",
63
+ }}
64
+
65
+ formConfig={{
66
+ getFormData,
67
+ saveFormData,
68
+ formLoading,
69
+ query,
70
+ ajaxForms,
71
+ changeAjaxForms,
72
+ ajaxOptions,
73
+ changeAjaxOptions,
74
+ formData,
75
+ formValue,
76
+ form,
77
+ namespace: 'document',
78
+ view: 'scoping',
79
+ scope: 'create',
80
+ formType: 'document',
81
+ defaultValues: createDefaultValues,
82
+ }}
83
+
84
+ onDownload={() => console.log("download")}
85
+ />
143
86
  )
144
87
  }
145
88
 
@@ -1,8 +1,3 @@
1
- export const checkboxConfig = {
2
- name: 'Name',
3
- datastakeId: 'ID'
4
- }
5
-
6
1
  export const getFiltersConfig = ({t}) => {
7
2
  return {
8
3
 
@@ -129,11 +124,6 @@ timeframe: {
129
124
  }
130
125
  }
131
126
 
132
- export const filtersConfig = {
133
- name: '',
134
- datastakeId: '',
135
- };
136
-
137
127
  export const getFilterOptions = (options, t) => {
138
128
  const {
139
129
  timeframe = [],
@@ -166,7 +156,7 @@ export const getFilterOptions = (options, t) => {
166
156
  category: stakeholderCategoryOptions || categoryOptions,
167
157
  country: countries,
168
158
  subCategory: subCategoriesOptions,
169
- category: category,
159
+ // category: category,
170
160
  administrativeLevel1,
171
161
  administrativeLevel2,
172
162
  positionInTheMineralSupplyChain: positionInMineralSupplyChainOptions,