datastake-daf 0.6.779 → 0.6.780

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.
@@ -9546,29 +9546,24 @@ const processConditionalTableKeys = (tableKeys, item) => {
9546
9546
  });
9547
9547
  return processedKeys;
9548
9548
  };
9549
- const renderFieldData = function (type, value, user, config) {
9550
- let getApiBaseUrl = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : () => {};
9551
- let getAppHeader = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : () => {};
9552
- let app = arguments.length > 6 ? arguments[6] : undefined;
9553
- let allValues = arguments.length > 7 ? arguments[7] : undefined;
9554
- let formValues = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : {};
9549
+ const renderFieldData = (type, value, user, config, getApiBaseUrl = () => {}, getAppHeader = () => {}, app, allValues, formValues = {}) => {
9555
9550
  switch (type) {
9556
9551
  case 'year':
9557
9552
  return value !== '-' ? renderDateFormatted(value, 'YYYY', 'en') : '-';
9558
9553
  case 'date':
9559
9554
  {
9560
- const language = user !== null && user !== void 0 && user.language && (user === null || user === void 0 ? void 0 : user.language) === 'sp' ? 'es' : user === null || user === void 0 ? void 0 : user.language;
9555
+ const language = user?.language && user?.language === 'sp' ? 'es' : user?.language;
9561
9556
  return value !== '-' ? renderDateFormatted(value, 'DD MMM YYYY', language || 'en') : '-';
9562
9557
  }
9563
9558
  case 'select':
9564
9559
  {
9565
- const options = (config === null || config === void 0 ? void 0 : config.options) || [];
9560
+ const options = config?.options || [];
9566
9561
  const option = findOptions(value, options);
9567
9562
  return option;
9568
9563
  }
9569
9564
  case 'multiselect':
9570
9565
  {
9571
- const options = (config === null || config === void 0 ? void 0 : config.options) || [];
9566
+ const options = config?.options || [];
9572
9567
  const _val = typeof value === 'string' ? value.split(',').map(v => v.trim()) : value;
9573
9568
  const option = findOptions(_val, options);
9574
9569
  return option.join(', ');
@@ -9583,7 +9578,7 @@ const renderFieldData = function (type, value, user, config) {
9583
9578
  formValues: formValues
9584
9579
  });
9585
9580
  case 'percentage':
9586
- return value === '-' || value === null || value === undefined ? '-' : "".concat(value, " %");
9581
+ return value === '-' || value === null || value === undefined ? '-' : `${value} %`;
9587
9582
  case 'geolocation':
9588
9583
  {
9589
9584
  const val = JSON.parse(value) || {};
@@ -9597,7 +9592,7 @@ const renderFieldData = function (type, value, user, config) {
9597
9592
  case 'upload':
9598
9593
  case 'videoUpload':
9599
9594
  {
9600
- const documentName = allValues === null || allValues === void 0 ? void 0 : allValues.map(item => item === null || item === void 0 ? void 0 : item.name).join(', ');
9595
+ const documentName = allValues?.map(item => item?.name).join(', ');
9601
9596
  return documentName;
9602
9597
  }
9603
9598
  default:
@@ -9721,18 +9716,19 @@ const resolveDynamicLabel = (labelConfig, item, defaultLabel) => {
9721
9716
  return labelConfig || defaultLabel;
9722
9717
  };
9723
9718
 
9724
- const handleSectionChildren = ({
9725
- config,
9726
- allData,
9727
- level,
9728
- t,
9729
- rootForm,
9730
- user,
9731
- getApiBaseUrl = () => {},
9732
- getAppHeader = () => {},
9733
- app,
9734
- TreeNodeComponent
9735
- }) => {
9719
+ const handleSectionChildren = _ref => {
9720
+ let {
9721
+ config,
9722
+ allData,
9723
+ level,
9724
+ t,
9725
+ rootForm,
9726
+ user,
9727
+ getApiBaseUrl = () => {},
9728
+ getAppHeader = () => {},
9729
+ app,
9730
+ TreeNodeComponent
9731
+ } = _ref;
9736
9732
  if (!(level === 0 && config && typeof config === 'object')) {
9737
9733
  return null;
9738
9734
  }
@@ -9746,14 +9742,14 @@ const handleSectionChildren = ({
9746
9742
  let fieldValue;
9747
9743
 
9748
9744
  // Determine field value based on type
9749
- if (fieldConfig.type === 'dataLinkGroup' && Array.isArray(allData?.[fieldKey])) {
9745
+ if (fieldConfig.type === 'dataLinkGroup' && Array.isArray(allData === null || allData === void 0 ? void 0 : allData[fieldKey])) {
9750
9746
  fieldValue = allData[fieldKey];
9751
- } else if (fieldConfig.type === 'dataLinkGroup' && allData?.[fieldKey]) {
9747
+ } else if (fieldConfig.type === 'dataLinkGroup' && allData !== null && allData !== void 0 && allData[fieldKey]) {
9752
9748
  fieldValue = allData[fieldKey];
9753
9749
  } else if (fieldConfig.type === 'group') {
9754
9750
  fieldValue = {};
9755
9751
  } else {
9756
- fieldValue = allData?.[fieldKey];
9752
+ fieldValue = allData === null || allData === void 0 ? void 0 : allData[fieldKey];
9757
9753
  }
9758
9754
  return /*#__PURE__*/jsxRuntime.jsx(TreeNodeComponent, {
9759
9755
  nodeKey: fieldKey,
@@ -12463,6 +12459,8 @@ const Style$M = styled__default["default"].div`
12463
12459
  width: 100%;
12464
12460
  height: 472px;
12465
12461
 
12462
+
12463
+
12466
12464
  .filter-cont {
12467
12465
  position: absolute;
12468
12466
  top: 24px;
@@ -12565,11 +12563,24 @@ const Style$M = styled__default["default"].div`
12565
12563
  align-items: center;
12566
12564
  }
12567
12565
 
12568
- .marker-chain {
12569
- display: flex;
12570
- align-items: center;
12571
- justify-content: center;
12572
- }
12566
+ .marker-chain {
12567
+ display: flex;
12568
+ align-items: center;
12569
+ justify-content: center;
12570
+ }
12571
+
12572
+ .animated-polyline {
12573
+ stroke-dasharray: 10 10;
12574
+ animation: dash-flow 1.5s linear infinite;
12575
+ stroke-linecap: round;
12576
+ }
12577
+
12578
+ @keyframes dash-flow {
12579
+ to {
12580
+ stroke-dashoffset: -20;
12581
+ }
12582
+ }
12583
+
12573
12584
 
12574
12585
  }
12575
12586
 
@@ -13015,18 +13026,15 @@ const VILLAGE = "village";
13015
13026
  const EXPORTER = "exporter";
13016
13027
  const PROCESSOR = "mineralProcessor";
13017
13028
  const DEPOT = "depot";
13029
+ const OPERATOR = "miningOperator";
13018
13030
  const MAX_EXTRA_SMALL_ZOOM_THRESHOLD = 2;
13019
13031
  const MAX_SMALL_ZOOM_THRESHOLD = 3;
13020
13032
  const MAX_MEDIUM_ZOOM_THRESHOLD = 6;
13021
13033
  const LOCATION_TYPES = [MINE_SITE, VILLAGE];
13022
- const STAKEHOLDER_TYPES = [EXPORTER, PROCESSOR, DEPOT];
13034
+ const STAKEHOLDER_TYPES = [EXPORTER, PROCESSOR, DEPOT, OPERATOR];
13023
13035
  const RADIUS_SMALL = 15;
13024
13036
  const RADIUS_MEDIUM = 35;
13025
13037
  const RADIUS_LARGE = 60;
13026
- const RADIUS_CURVE_SMALL = 10;
13027
- const RADIUS_CURVE_MEDIUM = 15;
13028
- const RADIUS_CURVE_LARGE = 20;
13029
- const TENSION = 0.2;
13030
13038
  function isLocation(type) {
13031
13039
  return LOCATION_TYPES.includes(type);
13032
13040
  }
@@ -13083,7 +13091,6 @@ function getStakeholderPosition({
13083
13091
  const isLarge = isLargeMarker(zoom);
13084
13092
  let radius;
13085
13093
  let center = {
13086
- // NOT BEING USED FOR NOW AND MAYBE NEVER
13087
13094
  left: 0,
13088
13095
  top: 0
13089
13096
  };
@@ -13107,6 +13114,25 @@ function getStakeholderPosition({
13107
13114
  angleDeg
13108
13115
  };
13109
13116
  }
13117
+ function applyAnimationDirect(el, isShortLink) {
13118
+ if (!(el instanceof SVGElement) || isShortLink) return;
13119
+ el.style.strokeDasharray = "10, 10";
13120
+ el.style.strokeDashoffset = "0";
13121
+ el.style.animation = "dash-flow 1.2s linear infinite";
13122
+ el.classList.add('animated-polyline');
13123
+ }
13124
+ function removeAnimationFromElement(element) {
13125
+ if (!element) return;
13126
+ element.classList.remove('animated-polyline');
13127
+ element.style.animation = '';
13128
+ element.style.strokeDasharray = '';
13129
+ }
13130
+ function applyAnimationToPolyline(polyline, isShortLink) {
13131
+ const element = polyline.getElement();
13132
+ if (element) {
13133
+ applyAnimationDirect(element, isShortLink);
13134
+ }
13135
+ }
13110
13136
  function createPolyline({
13111
13137
  L,
13112
13138
  startLatLng,
@@ -13116,109 +13142,47 @@ function createPolyline({
13116
13142
  zoom,
13117
13143
  listOfPolylines = [],
13118
13144
  isFromStakeholder = false,
13119
- isForceOpen = false
13145
+ isForceOpen = false,
13146
+ stakeholderType = null,
13147
+ animated = false,
13148
+ mapRef
13120
13149
  }) {
13121
- const width = isFromStakeholder && isExtraSmallMarker(zoom) && !isForceOpen ? 0 : 1.2;
13122
- const coordinates = [[startLatLng.lat, startLatLng.lng], [endLatLng.lat, endLatLng.lng]];
13123
- const style = {
13150
+ const lineWidth = isFromStakeholder && isExtraSmallMarker(zoom) && !isForceOpen ? 0 : 1.2;
13151
+ const isShortLink = stakeholderType === OPERATOR || isFromStakeholder;
13152
+ const shouldAnimate = animated;
13153
+ const lineCoordinates = [[startLatLng.lat, startLatLng.lng], [endLatLng.lat, endLatLng.lng]];
13154
+ const polylineStyle = {
13124
13155
  color: "var(--base-gray-70)",
13125
- weight: width,
13126
- opacity: 0.5,
13127
- smoothFactor: 1,
13156
+ weight: lineWidth,
13157
+ opacity: isSelected ? 1 : 0.5,
13158
+ smoothFactor: 0,
13128
13159
  id,
13129
- dashArray: !isSelected ? "5, 5" : "0, 0"
13160
+ dashArray: isShortLink ? "0, 0" : shouldAnimate ? "10, 10" : !isSelected ? "5, 5" : "10, 10",
13161
+ renderer: L.svg()
13130
13162
  };
13131
- const newPolyline = L.polyline(coordinates, style);
13132
- if (listOfPolylines.find(p => p.options.id === id)) {
13133
- const polylineToUpdateCoordinates = listOfPolylines.find(p => p.options.id === id);
13134
- polylineToUpdateCoordinates.setLatLngs(coordinates);
13135
- polylineToUpdateCoordinates.setStyle(style);
13136
- } else {
13137
- listOfPolylines.push(newPolyline);
13138
- }
13139
- return newPolyline;
13140
- }
13141
- function createCurvePath({
13142
- zoom,
13143
- totalMarkers,
13144
- markerIndex
13145
- }) {
13146
- const radius = getCurvePointRadius(zoom);
13147
- const {
13148
- x,
13149
- y,
13150
- angleDeg
13151
- } = getAngleDeg(totalMarkers, markerIndex, radius);
13152
- return {
13153
- x,
13154
- y,
13155
- angleDeg
13156
- };
13157
- }
13158
- function getCurvePointRadius(zoom) {
13159
- const isSmall = isSmallMarker(zoom) || isExtraSmallMarker(zoom);
13160
- const isMedium = isMediumMarker(zoom);
13161
- if (isSmall) {
13162
- return RADIUS_SMALL + RADIUS_CURVE_SMALL;
13163
- } else if (isMedium) {
13164
- return RADIUS_MEDIUM + RADIUS_CURVE_MEDIUM;
13165
- } else {
13166
- return RADIUS_LARGE + RADIUS_CURVE_LARGE;
13167
- }
13168
- }
13169
- function buildSmoothCurve(layerPoints, mapRef) {
13170
- const path = [];
13171
- for (let i = 0; i < layerPoints.length - 1; i++) {
13172
- const p0 = layerPoints[i];
13173
- const p1 = layerPoints[i + 1];
13174
- const pPrev = layerPoints[i - 1] || p0;
13175
- const pNext = layerPoints[i + 2] || p1;
13176
- const cp1 = L__namespace.point(p0.x + (p1.x - pPrev.x) * TENSION, p0.y + (p1.y - pPrev.y) * TENSION);
13177
- const cp2 = L__namespace.point(p1.x - (pNext.x - p0.x) * TENSION, p1.y - (pNext.y - p0.y) * TENSION);
13178
- if (i === 0) {
13179
- path.push("M", [mapRef.layerPointToLatLng(p0).lat, mapRef.layerPointToLatLng(p0).lng]);
13163
+ const existingPolyline = listOfPolylines.find(p => p.options.id === id);
13164
+ if (existingPolyline) {
13165
+ removeAnimationFromElement(existingPolyline.getElement());
13166
+ existingPolyline.setLatLngs(lineCoordinates);
13167
+ existingPolyline.setStyle(polylineStyle);
13168
+ if (shouldAnimate && isSelected) {
13169
+ existingPolyline.once('add', () => {
13170
+ applyAnimationToPolyline(existingPolyline, isShortLink);
13171
+ });
13172
+ applyAnimationToPolyline(existingPolyline, isShortLink);
13180
13173
  }
13181
- path.push("C", [mapRef.layerPointToLatLng(cp1).lat, mapRef.layerPointToLatLng(cp1).lng], [mapRef.layerPointToLatLng(cp2).lat, mapRef.layerPointToLatLng(cp2).lng], [mapRef.layerPointToLatLng(p1).lat, mapRef.layerPointToLatLng(p1).lng]);
13174
+ return existingPolyline;
13182
13175
  }
13183
- return path;
13184
- }
13185
- function getSiblingCurveStrength(zoom) {
13186
- if (isExtraSmallMarker(zoom)) return RADIUS_CURVE_SMALL / 2;
13187
- if (isSmallMarker(zoom)) return RADIUS_CURVE_MEDIUM;
13188
- if (isMediumMarker(zoom)) return RADIUS_CURVE_LARGE;
13189
- return RADIUS_CURVE_LARGE;
13190
- }
13191
- function buildCurveWIthTwoSiblings({
13192
- mapRef,
13193
- startLatLng,
13194
- endLatLng,
13195
- zoom,
13196
- isSelected,
13197
- id
13198
- }) {
13199
- const fromPoint = mapRef.latLngToLayerPoint(startLatLng);
13200
- const toPoint = mapRef.latLngToLayerPoint(endLatLng);
13201
- const midX = (fromPoint.x + toPoint.x) / 2;
13202
- const midY = (fromPoint.y + toPoint.y) / 2 + (isSmallMarker(zoom) ? RADIUS_CURVE_SMALL / 2 : 0);
13203
- const dx = toPoint.x - fromPoint.x;
13204
- const dy = toPoint.y - fromPoint.y;
13205
- const normal = L__namespace.point(-dy, dx);
13206
- const length = Math.sqrt(normal.x ** 2 + normal.y ** 2) || 1;
13207
- const normalized = normal.multiplyBy(1 / length);
13208
- const curveStrength = getSiblingCurveStrength(zoom);
13209
- const controlPoint = L__namespace.point(midX, midY).add(normalized.multiplyBy(curveStrength));
13210
- const latlngs = [startLatLng, mapRef.layerPointToLatLng(controlPoint), endLatLng];
13211
- const layerPoints = latlngs.map(latlng => mapRef.latLngToLayerPoint(latlng));
13212
- const path = buildSmoothCurve(layerPoints, mapRef);
13213
- const curve = L__namespace.curve(path, {
13214
- color: "var(--base-gray-70)",
13215
- weight: isExtraSmallMarker(zoom) ? 0 : 1.2,
13216
- opacity: 0.5,
13217
- smoothFactor: 1,
13218
- id,
13219
- dashArray: !isSelected ? "5, 5" : "0, 0"
13220
- });
13221
- mapRef.addLayer(curve);
13176
+ const newPolyline = L.polyline(lineCoordinates, polylineStyle);
13177
+ newPolyline.addTo(mapRef);
13178
+ listOfPolylines.push(newPolyline);
13179
+ if (shouldAnimate && isSelected) {
13180
+ newPolyline.once('add', () => {
13181
+ applyAnimationToPolyline(newPolyline, isShortLink);
13182
+ });
13183
+ applyAnimationToPolyline(newPolyline, isShortLink);
13184
+ }
13185
+ return newPolyline;
13222
13186
  }
13223
13187
 
13224
13188
  const StakeholderMarker = styled__default["default"].div`
@@ -13520,6 +13484,9 @@ function StakeholderIcon$1({
13520
13484
  return null;
13521
13485
  }, [parentId, allData]);
13522
13486
  React.useEffect(() => {
13487
+ if (selectedMarkersId.length === 0 || !isSelected) {
13488
+ return;
13489
+ }
13523
13490
  linkNodesData.map(node => {
13524
13491
  const isConnectingToStakeholder = node.isStakeholder;
13525
13492
  const id = `${data.datastakeId}-${node.stakeholderId || node.datastakeId}`;
@@ -13531,8 +13498,6 @@ function StakeholderIcon$1({
13531
13498
  const stakeholderPoint = centerPoint.add(L__namespace.point(x, y));
13532
13499
  const stakeholderLatLng = mapRef.layerPointToLatLng(stakeholderPoint);
13533
13500
  let endLatLng = L__namespace.latLng(node.gps.latitude, node.gps.longitude);
13534
- const areNextToEachOther = targetMarkerIndex === index + 1 || targetMarkerIndex === index - 1 || index === 0 && targetMarkerIndex === node.totalStakeholders - 1 || targetMarkerIndex === 0 && index === node.totalStakeholders - 1;
13535
- const areOnlyTwoSiblings = node.totalStakeholders === 2;
13536
13501
  if (isExtraSmallMarker(zoom) && !isForceOpen) {
13537
13502
  createPolyline({
13538
13503
  L: L__namespace,
@@ -13542,7 +13507,8 @@ function StakeholderIcon$1({
13542
13507
  zoom,
13543
13508
  isSelected,
13544
13509
  id,
13545
- listOfPolylines: polylinesRef.current
13510
+ listOfPolylines: polylinesRef.current,
13511
+ animated: true
13546
13512
  });
13547
13513
  return;
13548
13514
  }
@@ -13560,61 +13526,8 @@ function StakeholderIcon$1({
13560
13526
  const nodePoint = mapRef.latLngToLayerPoint(nodeLatLng);
13561
13527
  const endPoint = L__namespace.point(x + nodePoint.x + center.left, y + nodePoint.y + center.top);
13562
13528
  endLatLng = mapRef.layerPointToLatLng(endPoint);
13563
- if (isSibling && (!areNextToEachOther || areOnlyTwoSiblings)) {
13564
- if (areOnlyTwoSiblings) {
13565
- buildCurveWIthTwoSiblings({
13566
- mapRef,
13567
- startLatLng: stakeholderLatLng,
13568
- endLatLng,
13569
- zoom,
13570
- isSelected,
13571
- id
13572
- });
13573
- return;
13574
- }
13575
- const total = node.totalStakeholders;
13576
- let from = index;
13577
- let to = targetMarkerIndex;
13578
- let flip = false;
13579
- const forwardDistance = (to - from + total) % total;
13580
- const backwardDistance = (from - to + total) % total;
13581
- if (backwardDistance < forwardDistance) {
13582
- [from, to] = [to, from];
13583
- flip = true;
13584
- }
13585
- const intermediateIndices = [];
13586
- for (let i = 1; i < (to - from + total) % total; i++) {
13587
- intermediateIndices.push((from + i) % total);
13588
- }
13589
- const indices = [from, ...intermediateIndices, to];
13590
- const intermediatePoints = [];
13591
- for (const i of indices) {
13592
- const {
13593
- x,
13594
- y
13595
- } = createCurvePath({
13596
- zoom,
13597
- totalMarkers: node.totalStakeholders,
13598
- markerIndex: i
13599
- });
13600
- const point = centerPoint.add(L__namespace.point(x, y));
13601
- const latlng = mapRef.layerPointToLatLng(point);
13602
- intermediatePoints.push(latlng);
13603
- }
13604
- const latlngs = flip ? [endLatLng, ...intermediatePoints, stakeholderLatLng] : [stakeholderLatLng, ...intermediatePoints, endLatLng];
13605
- const layerPoints = latlngs.map(latlng => mapRef.latLngToLayerPoint(latlng));
13606
- const path = buildSmoothCurve(layerPoints, mapRef);
13607
- const curve = L__namespace?.curve?.(path, {
13608
- color: "var(--base-gray-70)",
13609
- weight: isExtraSmallMarker(zoom) ? 0 : 1,
13610
- opacity: isSelected ? 1 : 0.5,
13611
- smoothFactor: 1,
13612
- id
13613
- });
13614
- mapRef.addLayer(curve);
13615
- return;
13616
- }
13617
13529
  }
13530
+ // Always use straight lines
13618
13531
  createPolyline({
13619
13532
  L: L__namespace,
13620
13533
  mapRef,
@@ -13624,10 +13537,11 @@ function StakeholderIcon$1({
13624
13537
  isFromStakeholder: false,
13625
13538
  isSelected,
13626
13539
  id,
13627
- listOfPolylines: polylinesRef.current
13540
+ listOfPolylines: polylinesRef.current,
13541
+ animated: true
13628
13542
  });
13629
13543
  });
13630
- }, [mapRef, x, y, parentData, linkNodesData, isSelected, zoom, isForceOpen]);
13544
+ }, [mapRef, x, y, parentData, linkNodesData, isSelected, zoom, isForceOpen, selectedMarkersId]);
13631
13545
  return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
13632
13546
  children: /*#__PURE__*/jsxRuntime.jsx(antd.Popover, {
13633
13547
  content: renderTooltipJsx({
@@ -13639,7 +13553,8 @@ function StakeholderIcon$1({
13639
13553
  link,
13640
13554
  onClickLink: () => {
13641
13555
  onClickLink(data);
13642
- }
13556
+ },
13557
+ isNewTab: true
13643
13558
  }),
13644
13559
  getPopupContainer: triggerNode => {
13645
13560
  const mapElement = document.getElementById("map");
@@ -13694,6 +13609,8 @@ function LocationIcon({
13694
13609
  const linkedNodesData = React.useMemo(() => {
13695
13610
  const nodes = [];
13696
13611
  const links = data.links || [];
13612
+
13613
+ // Add links from the location itself
13697
13614
  links.forEach(link => {
13698
13615
  allData.forEach(d => {
13699
13616
  if (d.datastakeId === link) {
@@ -13713,8 +13630,45 @@ function LocationIcon({
13713
13630
  }
13714
13631
  });
13715
13632
  });
13633
+
13634
+ // ADD: Also include links from this location's stakeholders
13635
+ const stakeholders = data.stakeholders || [];
13636
+ stakeholders.forEach(stakeholder => {
13637
+ const stakeholderLinks = stakeholder.links || [];
13638
+ stakeholderLinks.forEach(link => {
13639
+ allData.forEach(d => {
13640
+ // Check if it's a direct location link
13641
+ if (d.datastakeId === link) {
13642
+ // Avoid duplicates
13643
+ if (!nodes.find(n => n.datastakeId === link && !n.isStakeholder)) {
13644
+ nodes.push({
13645
+ ...d,
13646
+ fromStakeholderId: stakeholder.datastakeId
13647
+ });
13648
+ }
13649
+ }
13650
+ // Check if it's a stakeholder link
13651
+ if (d.stakeholders && d.stakeholders.length > 0) {
13652
+ d.stakeholders.forEach(targetStakeholder => {
13653
+ if (targetStakeholder.datastakeId === link) {
13654
+ // Avoid duplicates
13655
+ if (!nodes.find(n => n.isStakeholder && n.datastakeId === d.datastakeId && n.stakeholdersIndex === d.stakeholders.indexOf(targetStakeholder))) {
13656
+ nodes.push({
13657
+ ...d,
13658
+ isStakeholder: true,
13659
+ totalStakeholders: d.stakeholders.length,
13660
+ stakeholdersIndex: d.stakeholders.indexOf(targetStakeholder),
13661
+ fromStakeholderId: stakeholder.datastakeId
13662
+ });
13663
+ }
13664
+ }
13665
+ });
13666
+ }
13667
+ });
13668
+ });
13669
+ });
13716
13670
  return nodes;
13717
- }, [JSON.stringify(allData), JSON.stringify(data.links), zoom]);
13671
+ }, [JSON.stringify(allData), JSON.stringify(data.links), JSON.stringify(data.stakeholders), zoom]);
13718
13672
  const stakeholdersOfLocation = React.useMemo(() => {
13719
13673
  return data?.stakeholders || [];
13720
13674
  }, [data.stakeholders, zoom]);
@@ -13732,7 +13686,13 @@ function LocationIcon({
13732
13686
  currentRoots.clear();
13733
13687
  markersRef.current = [];
13734
13688
 
13735
- // Create new markers
13689
+ // Only create stakeholder markers if this location or any of its stakeholders are selected
13690
+ const shouldShowStakeholders = isSelected || stakeholdersOfLocation.some(stk => selectedMarkersId.includes(stk.datastakeId));
13691
+ if (!shouldShowStakeholders || selectedMarkersId.length === 0) {
13692
+ return;
13693
+ }
13694
+
13695
+ // Create new markers only when selected
13736
13696
  stakeholdersOfLocation.forEach((stakeholder, index) => {
13737
13697
  const markerId = `${stakeholder.datastakeId}`;
13738
13698
  const {
@@ -13818,7 +13778,9 @@ function LocationIcon({
13818
13778
  zoom,
13819
13779
  isFromStakeholder: true,
13820
13780
  isForceOpen,
13821
- listOfPolylines: polylinesRef.current
13781
+ listOfPolylines: polylinesRef.current,
13782
+ stakeholderType: stakeholder.type,
13783
+ animated: true
13822
13784
  });
13823
13785
  });
13824
13786
  return () => {
@@ -13833,38 +13795,88 @@ function LocationIcon({
13833
13795
  rootsMapRef.current.clear();
13834
13796
  markersRef.current = [];
13835
13797
  };
13836
- }, [stakeholdersOfLocation, selectedMarkersId, activeMarker]);
13837
- linkedNodesData.map(node => {
13838
- const id = `${data.datastakeId}-${node.datastakeId}`;
13839
- const isConnectingToStakeholder = node.isStakeholder;
13840
- const centerLatLng = L__namespace.latLng(data.gps.latitude, data.gps.longitude);
13841
- let endLatLng = L__namespace.latLng(node.gps.latitude, node.gps.longitude);
13842
- const isConnectingToStakeholderSelected = selectedMarkersId.includes(node.datastakeId);
13843
- if (isConnectingToStakeholder && !isExtraSmallMarker(zoom)) {
13844
- const {
13845
- x,
13846
- y
13847
- } = getStakeholderPosition({
13798
+ }, [stakeholdersOfLocation, selectedMarkersId, activeMarker, zoom]);
13799
+
13800
+ // Only create polylines for linked nodes when something is selected
13801
+ React.useEffect(() => {
13802
+ if (selectedMarkersId.length === 0) {
13803
+ return;
13804
+ }
13805
+
13806
+ // IMPORTANT: Only draw links if this location is actually selected
13807
+ // Not just highlighted as part of the chain
13808
+ if (!isSelected) {
13809
+ return;
13810
+ }
13811
+
13812
+ // Filter linkedNodesData to only include nodes that are in the selected chain
13813
+ const relevantLinks = linkedNodesData.filter(node => {
13814
+ // Check if the target node (location) is in the selected markers
13815
+ const targetLocationInSelection = selectedMarkersId.includes(node.datastakeId);
13816
+
13817
+ // If connecting to a stakeholder, check if that stakeholder is selected
13818
+ if (node.isStakeholder) {
13819
+ const stakeholderInSelection = node.stakeholdersIndex !== undefined && selectedMarkersId.includes(node.datastakeId);
13820
+ return stakeholderInSelection;
13821
+ }
13822
+ return targetLocationInSelection;
13823
+ });
13824
+ relevantLinks.forEach(node => {
13825
+ const id = node.fromStakeholderId ? `${node.fromStakeholderId}-${node.datastakeId}` : `${data.datastakeId}-${node.datastakeId}`;
13826
+ const isConnectingToStakeholder = node.isStakeholder;
13827
+
13828
+ // If the link is from a stakeholder, start from the stakeholder position
13829
+ let startLatLng;
13830
+ if (node.fromStakeholderId) {
13831
+ // Find the stakeholder index in this location's stakeholders
13832
+ const stakeholderIndex = stakeholdersOfLocation.findIndex(s => s.datastakeId === node.fromStakeholderId);
13833
+ if (stakeholderIndex !== -1) {
13834
+ const {
13835
+ x,
13836
+ y
13837
+ } = getStakeholderPosition({
13838
+ zoom,
13839
+ totalMarkers: stakeholdersOfLocation.length,
13840
+ markerIndex: stakeholderIndex
13841
+ });
13842
+ const centerLatLng = L__namespace.latLng(data.gps.latitude, data.gps.longitude);
13843
+ const centerPoint = mapRef.latLngToLayerPoint(centerLatLng);
13844
+ const stakeholderPoint = centerPoint.add(L__namespace.point(x, y));
13845
+ startLatLng = mapRef.layerPointToLatLng(stakeholderPoint);
13846
+ } else {
13847
+ startLatLng = L__namespace.latLng(data.gps.latitude, data.gps.longitude);
13848
+ }
13849
+ } else {
13850
+ startLatLng = L__namespace.latLng(data.gps.latitude, data.gps.longitude);
13851
+ }
13852
+ let endLatLng = L__namespace.latLng(node.gps.latitude, node.gps.longitude);
13853
+ const isConnectingToStakeholderSelected = selectedMarkersId.includes(node.datastakeId);
13854
+ if (isConnectingToStakeholder && !isExtraSmallMarker(zoom)) {
13855
+ const {
13856
+ x,
13857
+ y
13858
+ } = getStakeholderPosition({
13859
+ zoom,
13860
+ totalMarkers: node.totalStakeholders,
13861
+ markerIndex: node.stakeholdersIndex
13862
+ });
13863
+ const nodeLatLng = L__namespace.latLng(node.gps.latitude, node.gps.longitude);
13864
+ const nodePoint = mapRef.latLngToLayerPoint(nodeLatLng);
13865
+ const endPoint = L__namespace.point(x + nodePoint.x, y + nodePoint.y);
13866
+ endLatLng = mapRef.layerPointToLatLng(endPoint);
13867
+ }
13868
+ createPolyline({
13869
+ L: L__namespace,
13870
+ mapRef,
13871
+ startLatLng,
13872
+ endLatLng,
13873
+ isSelected: isConnectingToStakeholderSelected,
13874
+ id,
13848
13875
  zoom,
13849
- totalMarkers: node.totalStakeholders,
13850
- markerIndex: node.stakeholdersIndex
13851
- });
13852
- const nodeLatLng = L__namespace.latLng(node.gps.latitude, node.gps.longitude);
13853
- const nodePoint = mapRef.latLngToLayerPoint(nodeLatLng);
13854
- const endPoint = L__namespace.point(x + nodePoint.x, y + nodePoint.y);
13855
- endLatLng = mapRef.layerPointToLatLng(endPoint);
13856
- }
13857
- createPolyline({
13858
- L: L__namespace,
13859
- mapRef,
13860
- startLatLng: centerLatLng,
13861
- endLatLng,
13862
- isSelected: isConnectingToStakeholderSelected,
13863
- id,
13864
- zoom,
13865
- listOfPolylines: polylinesRef.current
13876
+ listOfPolylines: polylinesRef.current
13877
+ });
13866
13878
  });
13867
- });
13879
+ }, [linkedNodesData, selectedMarkersId, zoom, stakeholdersOfLocation, isSelected]);
13868
13880
  return /*#__PURE__*/jsxRuntime.jsx(antd.Popover, {
13869
13881
  content: renderTooltipJsx({
13870
13882
  title: data.name,
@@ -14380,7 +14392,8 @@ function useMapHelper$1({
14380
14392
  link: link,
14381
14393
  onClickLink: onClickLink,
14382
14394
  activeStakeholder: activeStakeholder,
14383
- setActiveStakeholder: setActiveStakeholder
14395
+ setActiveStakeholder: setActiveStakeholder,
14396
+ mapRef: mapRef
14384
14397
  }));
14385
14398
  roots.current.push(root);
14386
14399
  } else if (type === "location") {
@@ -14585,7 +14598,8 @@ const useMap$1 = ({
14585
14598
  MAP_TOKEN
14586
14599
  } = useMapConfig({
14587
14600
  app,
14588
- isSatellite
14601
+ isSatellite,
14602
+ mapRef: container
14589
14603
  });
14590
14604
  const [initialMarkerSetIsDone, setInitialMarkerSetIsDone] = React.useState(false);
14591
14605
  const [mapCenter, setMapCenter] = React.useState([0, 0]);
@@ -14602,6 +14616,8 @@ const useMap$1 = ({
14602
14616
  const graph = new Map();
14603
14617
  const stakeToLoc = new Map();
14604
14618
  const nodeTypes = new Map();
14619
+
14620
+ // Build the graph
14605
14621
  for (const loc of data) {
14606
14622
  const locId = loc.datastakeId;
14607
14623
  nodeTypes.set(locId, loc.type);
@@ -14626,26 +14642,45 @@ const useMap$1 = ({
14626
14642
  }
14627
14643
  }
14628
14644
  const highlightTable = {};
14645
+
14646
+ // Perform BFS/DFS to find all connected nodes in the entire chain
14629
14647
  for (const [node] of graph) {
14630
14648
  const highlighted = new Set();
14631
- highlighted.add(node);
14632
- const nodeIsStakeholder = !isLocation(nodeTypes.get(node));
14633
- if (nodeIsStakeholder && stakeToLoc.has(node)) {
14634
- const parentLoc = stakeToLoc.get(node);
14635
- highlighted.add(parentLoc);
14636
- }
14637
- for (const neighbor of graph.get(node) || []) {
14638
- const neighborIsStakeholder = !isLocation(nodeTypes.get(neighbor));
14639
- if (neighborIsStakeholder && stakeToLoc.has(neighbor)) {
14640
- const neighborParent = stakeToLoc.get(neighbor);
14641
- if (isLocation(nodeTypes.get(node)) && neighborParent === node || nodeIsStakeholder && stakeToLoc.get(node) === neighborParent) {
14649
+ const queue = [node];
14650
+ const visited = new Set([node]);
14651
+ while (queue.length > 0) {
14652
+ const current = queue.shift();
14653
+ highlighted.add(current);
14654
+
14655
+ // Add parent location if current is stakeholder
14656
+ const currentIsStakeholder = !isLocation(nodeTypes.get(current));
14657
+ if (currentIsStakeholder && stakeToLoc.has(current)) {
14658
+ const parentLoc = stakeToLoc.get(current);
14659
+ if (!visited.has(parentLoc)) {
14660
+ highlighted.add(parentLoc);
14661
+ visited.add(parentLoc);
14662
+ queue.push(parentLoc);
14663
+ }
14664
+ }
14665
+
14666
+ // Traverse all neighbors
14667
+ for (const neighbor of graph.get(current) || []) {
14668
+ if (!visited.has(neighbor)) {
14669
+ visited.add(neighbor);
14670
+ queue.push(neighbor);
14642
14671
  highlighted.add(neighbor);
14643
- } else {
14644
- highlighted.add(neighbor);
14645
- highlighted.add(neighborParent);
14672
+
14673
+ // If neighbor is stakeholder, add its parent location
14674
+ const neighborIsStakeholder = !isLocation(nodeTypes.get(neighbor));
14675
+ if (neighborIsStakeholder && stakeToLoc.has(neighbor)) {
14676
+ const neighborParent = stakeToLoc.get(neighbor);
14677
+ if (!visited.has(neighborParent)) {
14678
+ highlighted.add(neighborParent);
14679
+ visited.add(neighborParent);
14680
+ queue.push(neighborParent);
14681
+ }
14682
+ }
14646
14683
  }
14647
- } else {
14648
- highlighted.add(neighbor);
14649
14684
  }
14650
14685
  }
14651
14686
  highlightTable[node] = [...highlighted];
@@ -14683,10 +14718,20 @@ const useMap$1 = ({
14683
14718
  function handleSelectMarker(clickedMarker) {
14684
14719
  setSelectedMarkersId(prev => {
14685
14720
  if (prev.includes(clickedMarker.datastakeId)) {
14721
+ // Deselecting - clear polylines
14686
14722
  openPopupIdRef.current = null;
14687
14723
  setMarkerWithPopup(null);
14688
14724
  return [];
14689
14725
  } else {
14726
+ // CLEAR OLD POLYLINES BEFORE SELECTING NEW MARKER
14727
+ if (polylinesRef.current.length > 0) {
14728
+ polylinesRef.current.forEach(polyline => {
14729
+ if (mapRef.hasLayer(polyline)) {
14730
+ mapRef.removeLayer(polyline);
14731
+ }
14732
+ });
14733
+ polylinesRef.current = [];
14734
+ }
14690
14735
  setMarkerWithPopup(isStakeholder(clickedMarker.type) ? clickedMarker : null);
14691
14736
  const newSelectedMarkersId = highlightTable[clickedMarker.datastakeId];
14692
14737
  openPopupIdRef.current = clickedMarker.datastakeId;
@@ -14710,19 +14755,29 @@ const useMap$1 = ({
14710
14755
  });
14711
14756
  }
14712
14757
  }
14758
+ if (type === "chain" && selectedMarkersId.length === 0) {
14759
+ if (polylinesRef.current.length) {
14760
+ polylinesRef.current.forEach(polyline => {
14761
+ if (mapRef.hasLayer(polyline)) {
14762
+ mapRef.removeLayer(polyline);
14763
+ }
14764
+ });
14765
+ polylinesRef.current = [];
14766
+ }
14767
+ }
14713
14768
  clearMapMarkers();
14714
14769
  if (data) {
14715
- // Filters out locations that are not connected to any stakeholders
14716
- const excludedType = ['village', 'town', 'area', 'territory'];
14717
- const filteredData = data?.filter(obj => !excludedType.includes(obj?.type) && (obj?.stakeholders?.length > 0 || data.some(other => other.datastakeId !== obj.datastakeId && (other.stakeholders || []).some(stk => (stk.links || []).includes(obj.datastakeId)))));
14770
+ const filteredData = data?.filter(obj => obj.type === 'mineSite' || obj?.stakeholders?.length > 0 || data.some(other => other.datastakeId !== obj.datastakeId && (other.stakeholders || []).some(stk => (stk.links || []).includes(obj.datastakeId))));
14718
14771
  const maxTotal = Math.max(...(data || []).map(d => d.total));
14719
14772
  const dataToRender = type === "chain" ? filteredData : data;
14720
14773
  dataToRender.forEach((d, i) => {
14721
14774
  addIconToMapInitialy([d?.marker?.lat, d?.marker?.lng], "location", d.category || "mineSite", d, maxTotal, i);
14722
14775
  });
14723
- polylinesRef.current.forEach(polyline => {
14724
- mapRef.addLayer(polyline);
14725
- });
14776
+ if (selectedMarkersId.length > 0) {
14777
+ polylinesRef.current.forEach(polyline => {
14778
+ mapRef.addLayer(polyline);
14779
+ });
14780
+ }
14726
14781
  mapRef.invalidateSize();
14727
14782
  mapRef.fire("moveend");
14728
14783
  }