datastake-daf 0.6.778 → 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.
Files changed (25) hide show
  1. package/dist/components/index.js +403 -355
  2. package/dist/pages/index.js +2120 -235
  3. package/dist/utils/index.js +13 -0
  4. package/package.json +1 -1
  5. package/src/@daf/core/components/Dashboard/Map/ChainIcon/Markers/StakeholderMarker.js +9 -76
  6. package/src/@daf/core/components/Dashboard/Map/ChainIcon/index.js +116 -8
  7. package/src/@daf/core/components/Dashboard/Map/ChainIcon/utils.js +73 -17
  8. package/src/@daf/core/components/Dashboard/Map/helper.js +1 -0
  9. package/src/@daf/core/components/Dashboard/Map/hook.js +64 -29
  10. package/src/@daf/core/components/Dashboard/Map/style.js +20 -5
  11. package/src/@daf/pages/Summary/Activities/PlantingCycle/components/AssociatedInformation/config.js +4 -2
  12. package/src/@daf/pages/Summary/Activities/PlantingCycle/components/AssociatedInformation/index.jsx +1 -0
  13. package/src/@daf/pages/Summary/Activities/PlantingCycle/components/PlantingLocations/index.jsx +60 -4
  14. package/src/@daf/pages/View/hooks/useCallToGetData.js +73 -0
  15. package/src/@daf/pages/View/hooks/usePrepareForm.js +86 -0
  16. package/src/@daf/pages/View/hooks/useSubmitSubject.js +40 -0
  17. package/src/@daf/pages/View/hooks/useViewActions.js +83 -0
  18. package/src/@daf/pages/View/hooks/useViewPermissions.js +75 -0
  19. package/src/@daf/pages/View/hooks/useViewUrlParams.js +93 -0
  20. package/src/@daf/pages/View/index.jsx +286 -0
  21. package/src/@daf/utils/object.js +3 -1
  22. package/src/pages.js +4 -1
  23. package/src/utils.js +1 -1
  24. package/dist/style/datastake/mapbox-gl.css +0 -330
  25. package/src/@daf/hooks/useViewFormUrlParams.js +0 -84
@@ -5295,6 +5295,12 @@ const createNumberArray = i => {
5295
5295
  return numbers;
5296
5296
  };
5297
5297
  const tooltipInputs = ["text", "phoneNumber", "textarea", "percentage", "number", "select", "ajaxSelect", "switch", "multiselect", "radioGroup", "date", "year"];
5298
+ const formPaths = {
5299
+ edit: (mod, getRedirectLink) => typeof getRedirectLink === "function" ? getRedirectLink(`/app/edit/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`) : `/app/${mod}/edit/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`,
5300
+ view: (mod, getRedirectLink) => typeof getRedirectLink === "function" ? getRedirectLink(`/app/view/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`) : `/app/${mod}/view/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`,
5301
+ viewDD: mod => `/app/${mod}/viewdd/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`,
5302
+ editDD: mod => `/app/${mod}/editdd/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`
5303
+ };
5298
5304
  const CREATE_DRAWER_WIDTH = 480;
5299
5305
  const MAX_COMMENTS_LENGTH = 1200;
5300
5306
  const MAX_TEXT_AREA_LENGTH = 1200;
@@ -7570,6 +7576,8 @@ const Style$f = styled__default["default"].div`
7570
7576
  width: 100%;
7571
7577
  height: 472px;
7572
7578
 
7579
+
7580
+
7573
7581
  .filter-cont {
7574
7582
  position: absolute;
7575
7583
  top: 24px;
@@ -7672,11 +7680,24 @@ const Style$f = styled__default["default"].div`
7672
7680
  align-items: center;
7673
7681
  }
7674
7682
 
7675
- .marker-chain {
7676
- display: flex;
7677
- align-items: center;
7678
- justify-content: center;
7679
- }
7683
+ .marker-chain {
7684
+ display: flex;
7685
+ align-items: center;
7686
+ justify-content: center;
7687
+ }
7688
+
7689
+ .animated-polyline {
7690
+ stroke-dasharray: 10 10;
7691
+ animation: dash-flow 1.5s linear infinite;
7692
+ stroke-linecap: round;
7693
+ }
7694
+
7695
+ @keyframes dash-flow {
7696
+ to {
7697
+ stroke-dashoffset: -20;
7698
+ }
7699
+ }
7700
+
7680
7701
 
7681
7702
  }
7682
7703
 
@@ -8200,18 +8221,15 @@ const VILLAGE = "village";
8200
8221
  const EXPORTER = "exporter";
8201
8222
  const PROCESSOR = "mineralProcessor";
8202
8223
  const DEPOT = "depot";
8224
+ const OPERATOR = "miningOperator";
8203
8225
  const MAX_EXTRA_SMALL_ZOOM_THRESHOLD = 2;
8204
8226
  const MAX_SMALL_ZOOM_THRESHOLD = 3;
8205
8227
  const MAX_MEDIUM_ZOOM_THRESHOLD = 6;
8206
8228
  const LOCATION_TYPES = [MINE_SITE, VILLAGE];
8207
- const STAKEHOLDER_TYPES = [EXPORTER, PROCESSOR, DEPOT];
8229
+ const STAKEHOLDER_TYPES = [EXPORTER, PROCESSOR, DEPOT, OPERATOR];
8208
8230
  const RADIUS_SMALL = 15;
8209
8231
  const RADIUS_MEDIUM = 35;
8210
8232
  const RADIUS_LARGE = 60;
8211
- const RADIUS_CURVE_SMALL = 10;
8212
- const RADIUS_CURVE_MEDIUM = 15;
8213
- const RADIUS_CURVE_LARGE = 20;
8214
- const TENSION = 0.2;
8215
8233
  function isLocation(type) {
8216
8234
  return LOCATION_TYPES.includes(type);
8217
8235
  }
@@ -8268,7 +8286,6 @@ function getStakeholderPosition({
8268
8286
  const isLarge = isLargeMarker(zoom);
8269
8287
  let radius;
8270
8288
  let center = {
8271
- // NOT BEING USED FOR NOW AND MAYBE NEVER
8272
8289
  left: 0,
8273
8290
  top: 0
8274
8291
  };
@@ -8292,6 +8309,25 @@ function getStakeholderPosition({
8292
8309
  angleDeg
8293
8310
  };
8294
8311
  }
8312
+ function applyAnimationDirect(el, isShortLink) {
8313
+ if (!(el instanceof SVGElement) || isShortLink) return;
8314
+ el.style.strokeDasharray = "10, 10";
8315
+ el.style.strokeDashoffset = "0";
8316
+ el.style.animation = "dash-flow 1.2s linear infinite";
8317
+ el.classList.add('animated-polyline');
8318
+ }
8319
+ function removeAnimationFromElement(element) {
8320
+ if (!element) return;
8321
+ element.classList.remove('animated-polyline');
8322
+ element.style.animation = '';
8323
+ element.style.strokeDasharray = '';
8324
+ }
8325
+ function applyAnimationToPolyline(polyline, isShortLink) {
8326
+ const element = polyline.getElement();
8327
+ if (element) {
8328
+ applyAnimationDirect(element, isShortLink);
8329
+ }
8330
+ }
8295
8331
  function createPolyline({
8296
8332
  L,
8297
8333
  startLatLng,
@@ -8301,109 +8337,47 @@ function createPolyline({
8301
8337
  zoom,
8302
8338
  listOfPolylines = [],
8303
8339
  isFromStakeholder = false,
8304
- isForceOpen = false
8340
+ isForceOpen = false,
8341
+ stakeholderType = null,
8342
+ animated = false,
8343
+ mapRef
8305
8344
  }) {
8306
- const width = isFromStakeholder && isExtraSmallMarker(zoom) && !isForceOpen ? 0 : 1.2;
8307
- const coordinates = [[startLatLng.lat, startLatLng.lng], [endLatLng.lat, endLatLng.lng]];
8308
- const style = {
8345
+ const lineWidth = isFromStakeholder && isExtraSmallMarker(zoom) && !isForceOpen ? 0 : 1.2;
8346
+ const isShortLink = stakeholderType === OPERATOR || isFromStakeholder;
8347
+ const shouldAnimate = animated;
8348
+ const lineCoordinates = [[startLatLng.lat, startLatLng.lng], [endLatLng.lat, endLatLng.lng]];
8349
+ const polylineStyle = {
8309
8350
  color: "var(--base-gray-70)",
8310
- weight: width,
8311
- opacity: 0.5,
8312
- smoothFactor: 1,
8351
+ weight: lineWidth,
8352
+ opacity: isSelected ? 1 : 0.5,
8353
+ smoothFactor: 0,
8313
8354
  id,
8314
- dashArray: !isSelected ? "5, 5" : "0, 0"
8355
+ dashArray: isShortLink ? "0, 0" : shouldAnimate ? "10, 10" : !isSelected ? "5, 5" : "10, 10",
8356
+ renderer: L.svg()
8315
8357
  };
8316
- const newPolyline = L.polyline(coordinates, style);
8317
- if (listOfPolylines.find(p => p.options.id === id)) {
8318
- const polylineToUpdateCoordinates = listOfPolylines.find(p => p.options.id === id);
8319
- polylineToUpdateCoordinates.setLatLngs(coordinates);
8320
- polylineToUpdateCoordinates.setStyle(style);
8321
- } else {
8322
- listOfPolylines.push(newPolyline);
8358
+ const existingPolyline = listOfPolylines.find(p => p.options.id === id);
8359
+ if (existingPolyline) {
8360
+ removeAnimationFromElement(existingPolyline.getElement());
8361
+ existingPolyline.setLatLngs(lineCoordinates);
8362
+ existingPolyline.setStyle(polylineStyle);
8363
+ if (shouldAnimate && isSelected) {
8364
+ existingPolyline.once('add', () => {
8365
+ applyAnimationToPolyline(existingPolyline, isShortLink);
8366
+ });
8367
+ applyAnimationToPolyline(existingPolyline, isShortLink);
8368
+ }
8369
+ return existingPolyline;
8323
8370
  }
8324
- return newPolyline;
8325
- }
8326
- function createCurvePath({
8327
- zoom,
8328
- totalMarkers,
8329
- markerIndex
8330
- }) {
8331
- const radius = getCurvePointRadius(zoom);
8332
- const {
8333
- x,
8334
- y,
8335
- angleDeg
8336
- } = getAngleDeg(totalMarkers, markerIndex, radius);
8337
- return {
8338
- x,
8339
- y,
8340
- angleDeg
8341
- };
8342
- }
8343
- function getCurvePointRadius(zoom) {
8344
- const isSmall = isSmallMarker(zoom) || isExtraSmallMarker(zoom);
8345
- const isMedium = isMediumMarker(zoom);
8346
- if (isSmall) {
8347
- return RADIUS_SMALL + RADIUS_CURVE_SMALL;
8348
- } else if (isMedium) {
8349
- return RADIUS_MEDIUM + RADIUS_CURVE_MEDIUM;
8350
- } else {
8351
- return RADIUS_LARGE + RADIUS_CURVE_LARGE;
8371
+ const newPolyline = L.polyline(lineCoordinates, polylineStyle);
8372
+ newPolyline.addTo(mapRef);
8373
+ listOfPolylines.push(newPolyline);
8374
+ if (shouldAnimate && isSelected) {
8375
+ newPolyline.once('add', () => {
8376
+ applyAnimationToPolyline(newPolyline, isShortLink);
8377
+ });
8378
+ applyAnimationToPolyline(newPolyline, isShortLink);
8352
8379
  }
8353
- }
8354
- function buildSmoothCurve(layerPoints, mapRef) {
8355
- const path = [];
8356
- for (let i = 0; i < layerPoints.length - 1; i++) {
8357
- const p0 = layerPoints[i];
8358
- const p1 = layerPoints[i + 1];
8359
- const pPrev = layerPoints[i - 1] || p0;
8360
- const pNext = layerPoints[i + 2] || p1;
8361
- const cp1 = L__namespace.point(p0.x + (p1.x - pPrev.x) * TENSION, p0.y + (p1.y - pPrev.y) * TENSION);
8362
- const cp2 = L__namespace.point(p1.x - (pNext.x - p0.x) * TENSION, p1.y - (pNext.y - p0.y) * TENSION);
8363
- if (i === 0) {
8364
- path.push("M", [mapRef.layerPointToLatLng(p0).lat, mapRef.layerPointToLatLng(p0).lng]);
8365
- }
8366
- 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]);
8367
- }
8368
- return path;
8369
- }
8370
- function getSiblingCurveStrength(zoom) {
8371
- if (isExtraSmallMarker(zoom)) return RADIUS_CURVE_SMALL / 2;
8372
- if (isSmallMarker(zoom)) return RADIUS_CURVE_MEDIUM;
8373
- if (isMediumMarker(zoom)) return RADIUS_CURVE_LARGE;
8374
- return RADIUS_CURVE_LARGE;
8375
- }
8376
- function buildCurveWIthTwoSiblings({
8377
- mapRef,
8378
- startLatLng,
8379
- endLatLng,
8380
- zoom,
8381
- isSelected,
8382
- id
8383
- }) {
8384
- const fromPoint = mapRef.latLngToLayerPoint(startLatLng);
8385
- const toPoint = mapRef.latLngToLayerPoint(endLatLng);
8386
- const midX = (fromPoint.x + toPoint.x) / 2;
8387
- const midY = (fromPoint.y + toPoint.y) / 2 + (isSmallMarker(zoom) ? RADIUS_CURVE_SMALL / 2 : 0);
8388
- const dx = toPoint.x - fromPoint.x;
8389
- const dy = toPoint.y - fromPoint.y;
8390
- const normal = L__namespace.point(-dy, dx);
8391
- const length = Math.sqrt(normal.x ** 2 + normal.y ** 2) || 1;
8392
- const normalized = normal.multiplyBy(1 / length);
8393
- const curveStrength = getSiblingCurveStrength(zoom);
8394
- const controlPoint = L__namespace.point(midX, midY).add(normalized.multiplyBy(curveStrength));
8395
- const latlngs = [startLatLng, mapRef.layerPointToLatLng(controlPoint), endLatLng];
8396
- const layerPoints = latlngs.map(latlng => mapRef.latLngToLayerPoint(latlng));
8397
- const path = buildSmoothCurve(layerPoints, mapRef);
8398
- const curve = L__namespace.curve(path, {
8399
- color: "var(--base-gray-70)",
8400
- weight: isExtraSmallMarker(zoom) ? 0 : 1.2,
8401
- opacity: 0.5,
8402
- smoothFactor: 1,
8403
- id,
8404
- dashArray: !isSelected ? "5, 5" : "0, 0"
8405
- });
8406
- mapRef.addLayer(curve);
8380
+ return newPolyline;
8407
8381
  }
8408
8382
 
8409
8383
  const StakeholderMarker = styled__default["default"].div`
@@ -8705,6 +8679,9 @@ function StakeholderIcon$1({
8705
8679
  return null;
8706
8680
  }, [parentId, allData]);
8707
8681
  React.useEffect(() => {
8682
+ if (selectedMarkersId.length === 0 || !isSelected) {
8683
+ return;
8684
+ }
8708
8685
  linkNodesData.map(node => {
8709
8686
  const isConnectingToStakeholder = node.isStakeholder;
8710
8687
  const id = `${data.datastakeId}-${node.stakeholderId || node.datastakeId}`;
@@ -8716,8 +8693,6 @@ function StakeholderIcon$1({
8716
8693
  const stakeholderPoint = centerPoint.add(L__namespace.point(x, y));
8717
8694
  const stakeholderLatLng = mapRef.layerPointToLatLng(stakeholderPoint);
8718
8695
  let endLatLng = L__namespace.latLng(node.gps.latitude, node.gps.longitude);
8719
- const areNextToEachOther = targetMarkerIndex === index + 1 || targetMarkerIndex === index - 1 || index === 0 && targetMarkerIndex === node.totalStakeholders - 1 || targetMarkerIndex === 0 && index === node.totalStakeholders - 1;
8720
- const areOnlyTwoSiblings = node.totalStakeholders === 2;
8721
8696
  if (isExtraSmallMarker(zoom) && !isForceOpen) {
8722
8697
  createPolyline({
8723
8698
  L: L__namespace,
@@ -8727,7 +8702,8 @@ function StakeholderIcon$1({
8727
8702
  zoom,
8728
8703
  isSelected,
8729
8704
  id,
8730
- listOfPolylines: polylinesRef.current
8705
+ listOfPolylines: polylinesRef.current,
8706
+ animated: true
8731
8707
  });
8732
8708
  return;
8733
8709
  }
@@ -8745,61 +8721,8 @@ function StakeholderIcon$1({
8745
8721
  const nodePoint = mapRef.latLngToLayerPoint(nodeLatLng);
8746
8722
  const endPoint = L__namespace.point(x + nodePoint.x + center.left, y + nodePoint.y + center.top);
8747
8723
  endLatLng = mapRef.layerPointToLatLng(endPoint);
8748
- if (isSibling && (!areNextToEachOther || areOnlyTwoSiblings)) {
8749
- if (areOnlyTwoSiblings) {
8750
- buildCurveWIthTwoSiblings({
8751
- mapRef,
8752
- startLatLng: stakeholderLatLng,
8753
- endLatLng,
8754
- zoom,
8755
- isSelected,
8756
- id
8757
- });
8758
- return;
8759
- }
8760
- const total = node.totalStakeholders;
8761
- let from = index;
8762
- let to = targetMarkerIndex;
8763
- let flip = false;
8764
- const forwardDistance = (to - from + total) % total;
8765
- const backwardDistance = (from - to + total) % total;
8766
- if (backwardDistance < forwardDistance) {
8767
- [from, to] = [to, from];
8768
- flip = true;
8769
- }
8770
- const intermediateIndices = [];
8771
- for (let i = 1; i < (to - from + total) % total; i++) {
8772
- intermediateIndices.push((from + i) % total);
8773
- }
8774
- const indices = [from, ...intermediateIndices, to];
8775
- const intermediatePoints = [];
8776
- for (const i of indices) {
8777
- const {
8778
- x,
8779
- y
8780
- } = createCurvePath({
8781
- zoom,
8782
- totalMarkers: node.totalStakeholders,
8783
- markerIndex: i
8784
- });
8785
- const point = centerPoint.add(L__namespace.point(x, y));
8786
- const latlng = mapRef.layerPointToLatLng(point);
8787
- intermediatePoints.push(latlng);
8788
- }
8789
- const latlngs = flip ? [endLatLng, ...intermediatePoints, stakeholderLatLng] : [stakeholderLatLng, ...intermediatePoints, endLatLng];
8790
- const layerPoints = latlngs.map(latlng => mapRef.latLngToLayerPoint(latlng));
8791
- const path = buildSmoothCurve(layerPoints, mapRef);
8792
- const curve = L__namespace?.curve?.(path, {
8793
- color: "var(--base-gray-70)",
8794
- weight: isExtraSmallMarker(zoom) ? 0 : 1,
8795
- opacity: isSelected ? 1 : 0.5,
8796
- smoothFactor: 1,
8797
- id
8798
- });
8799
- mapRef.addLayer(curve);
8800
- return;
8801
- }
8802
8724
  }
8725
+ // Always use straight lines
8803
8726
  createPolyline({
8804
8727
  L: L__namespace,
8805
8728
  mapRef,
@@ -8809,10 +8732,11 @@ function StakeholderIcon$1({
8809
8732
  isFromStakeholder: false,
8810
8733
  isSelected,
8811
8734
  id,
8812
- listOfPolylines: polylinesRef.current
8735
+ listOfPolylines: polylinesRef.current,
8736
+ animated: true
8813
8737
  });
8814
8738
  });
8815
- }, [mapRef, x, y, parentData, linkNodesData, isSelected, zoom, isForceOpen]);
8739
+ }, [mapRef, x, y, parentData, linkNodesData, isSelected, zoom, isForceOpen, selectedMarkersId]);
8816
8740
  return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
8817
8741
  children: /*#__PURE__*/jsxRuntime.jsx(antd.Popover, {
8818
8742
  content: renderTooltipJsx({
@@ -8824,7 +8748,8 @@ function StakeholderIcon$1({
8824
8748
  link,
8825
8749
  onClickLink: () => {
8826
8750
  onClickLink(data);
8827
- }
8751
+ },
8752
+ isNewTab: true
8828
8753
  }),
8829
8754
  getPopupContainer: triggerNode => {
8830
8755
  const mapElement = document.getElementById("map");
@@ -8879,6 +8804,8 @@ function LocationIcon({
8879
8804
  const linkedNodesData = React.useMemo(() => {
8880
8805
  const nodes = [];
8881
8806
  const links = data.links || [];
8807
+
8808
+ // Add links from the location itself
8882
8809
  links.forEach(link => {
8883
8810
  allData.forEach(d => {
8884
8811
  if (d.datastakeId === link) {
@@ -8898,8 +8825,45 @@ function LocationIcon({
8898
8825
  }
8899
8826
  });
8900
8827
  });
8828
+
8829
+ // ADD: Also include links from this location's stakeholders
8830
+ const stakeholders = data.stakeholders || [];
8831
+ stakeholders.forEach(stakeholder => {
8832
+ const stakeholderLinks = stakeholder.links || [];
8833
+ stakeholderLinks.forEach(link => {
8834
+ allData.forEach(d => {
8835
+ // Check if it's a direct location link
8836
+ if (d.datastakeId === link) {
8837
+ // Avoid duplicates
8838
+ if (!nodes.find(n => n.datastakeId === link && !n.isStakeholder)) {
8839
+ nodes.push({
8840
+ ...d,
8841
+ fromStakeholderId: stakeholder.datastakeId
8842
+ });
8843
+ }
8844
+ }
8845
+ // Check if it's a stakeholder link
8846
+ if (d.stakeholders && d.stakeholders.length > 0) {
8847
+ d.stakeholders.forEach(targetStakeholder => {
8848
+ if (targetStakeholder.datastakeId === link) {
8849
+ // Avoid duplicates
8850
+ if (!nodes.find(n => n.isStakeholder && n.datastakeId === d.datastakeId && n.stakeholdersIndex === d.stakeholders.indexOf(targetStakeholder))) {
8851
+ nodes.push({
8852
+ ...d,
8853
+ isStakeholder: true,
8854
+ totalStakeholders: d.stakeholders.length,
8855
+ stakeholdersIndex: d.stakeholders.indexOf(targetStakeholder),
8856
+ fromStakeholderId: stakeholder.datastakeId
8857
+ });
8858
+ }
8859
+ }
8860
+ });
8861
+ }
8862
+ });
8863
+ });
8864
+ });
8901
8865
  return nodes;
8902
- }, [JSON.stringify(allData), JSON.stringify(data.links), zoom]);
8866
+ }, [JSON.stringify(allData), JSON.stringify(data.links), JSON.stringify(data.stakeholders), zoom]);
8903
8867
  const stakeholdersOfLocation = React.useMemo(() => {
8904
8868
  return data?.stakeholders || [];
8905
8869
  }, [data.stakeholders, zoom]);
@@ -8917,7 +8881,13 @@ function LocationIcon({
8917
8881
  currentRoots.clear();
8918
8882
  markersRef.current = [];
8919
8883
 
8920
- // Create new markers
8884
+ // Only create stakeholder markers if this location or any of its stakeholders are selected
8885
+ const shouldShowStakeholders = isSelected || stakeholdersOfLocation.some(stk => selectedMarkersId.includes(stk.datastakeId));
8886
+ if (!shouldShowStakeholders || selectedMarkersId.length === 0) {
8887
+ return;
8888
+ }
8889
+
8890
+ // Create new markers only when selected
8921
8891
  stakeholdersOfLocation.forEach((stakeholder, index) => {
8922
8892
  const markerId = `${stakeholder.datastakeId}`;
8923
8893
  const {
@@ -9003,7 +8973,9 @@ function LocationIcon({
9003
8973
  zoom,
9004
8974
  isFromStakeholder: true,
9005
8975
  isForceOpen,
9006
- listOfPolylines: polylinesRef.current
8976
+ listOfPolylines: polylinesRef.current,
8977
+ stakeholderType: stakeholder.type,
8978
+ animated: true
9007
8979
  });
9008
8980
  });
9009
8981
  return () => {
@@ -9018,38 +8990,88 @@ function LocationIcon({
9018
8990
  rootsMapRef.current.clear();
9019
8991
  markersRef.current = [];
9020
8992
  };
9021
- }, [stakeholdersOfLocation, selectedMarkersId, activeMarker]);
9022
- linkedNodesData.map(node => {
9023
- const id = `${data.datastakeId}-${node.datastakeId}`;
9024
- const isConnectingToStakeholder = node.isStakeholder;
9025
- const centerLatLng = L__namespace.latLng(data.gps.latitude, data.gps.longitude);
9026
- let endLatLng = L__namespace.latLng(node.gps.latitude, node.gps.longitude);
9027
- const isConnectingToStakeholderSelected = selectedMarkersId.includes(node.datastakeId);
9028
- if (isConnectingToStakeholder && !isExtraSmallMarker(zoom)) {
9029
- const {
9030
- x,
9031
- y
9032
- } = getStakeholderPosition({
8993
+ }, [stakeholdersOfLocation, selectedMarkersId, activeMarker, zoom]);
8994
+
8995
+ // Only create polylines for linked nodes when something is selected
8996
+ React.useEffect(() => {
8997
+ if (selectedMarkersId.length === 0) {
8998
+ return;
8999
+ }
9000
+
9001
+ // IMPORTANT: Only draw links if this location is actually selected
9002
+ // Not just highlighted as part of the chain
9003
+ if (!isSelected) {
9004
+ return;
9005
+ }
9006
+
9007
+ // Filter linkedNodesData to only include nodes that are in the selected chain
9008
+ const relevantLinks = linkedNodesData.filter(node => {
9009
+ // Check if the target node (location) is in the selected markers
9010
+ const targetLocationInSelection = selectedMarkersId.includes(node.datastakeId);
9011
+
9012
+ // If connecting to a stakeholder, check if that stakeholder is selected
9013
+ if (node.isStakeholder) {
9014
+ const stakeholderInSelection = node.stakeholdersIndex !== undefined && selectedMarkersId.includes(node.datastakeId);
9015
+ return stakeholderInSelection;
9016
+ }
9017
+ return targetLocationInSelection;
9018
+ });
9019
+ relevantLinks.forEach(node => {
9020
+ const id = node.fromStakeholderId ? `${node.fromStakeholderId}-${node.datastakeId}` : `${data.datastakeId}-${node.datastakeId}`;
9021
+ const isConnectingToStakeholder = node.isStakeholder;
9022
+
9023
+ // If the link is from a stakeholder, start from the stakeholder position
9024
+ let startLatLng;
9025
+ if (node.fromStakeholderId) {
9026
+ // Find the stakeholder index in this location's stakeholders
9027
+ const stakeholderIndex = stakeholdersOfLocation.findIndex(s => s.datastakeId === node.fromStakeholderId);
9028
+ if (stakeholderIndex !== -1) {
9029
+ const {
9030
+ x,
9031
+ y
9032
+ } = getStakeholderPosition({
9033
+ zoom,
9034
+ totalMarkers: stakeholdersOfLocation.length,
9035
+ markerIndex: stakeholderIndex
9036
+ });
9037
+ const centerLatLng = L__namespace.latLng(data.gps.latitude, data.gps.longitude);
9038
+ const centerPoint = mapRef.latLngToLayerPoint(centerLatLng);
9039
+ const stakeholderPoint = centerPoint.add(L__namespace.point(x, y));
9040
+ startLatLng = mapRef.layerPointToLatLng(stakeholderPoint);
9041
+ } else {
9042
+ startLatLng = L__namespace.latLng(data.gps.latitude, data.gps.longitude);
9043
+ }
9044
+ } else {
9045
+ startLatLng = L__namespace.latLng(data.gps.latitude, data.gps.longitude);
9046
+ }
9047
+ let endLatLng = L__namespace.latLng(node.gps.latitude, node.gps.longitude);
9048
+ const isConnectingToStakeholderSelected = selectedMarkersId.includes(node.datastakeId);
9049
+ if (isConnectingToStakeholder && !isExtraSmallMarker(zoom)) {
9050
+ const {
9051
+ x,
9052
+ y
9053
+ } = getStakeholderPosition({
9054
+ zoom,
9055
+ totalMarkers: node.totalStakeholders,
9056
+ markerIndex: node.stakeholdersIndex
9057
+ });
9058
+ const nodeLatLng = L__namespace.latLng(node.gps.latitude, node.gps.longitude);
9059
+ const nodePoint = mapRef.latLngToLayerPoint(nodeLatLng);
9060
+ const endPoint = L__namespace.point(x + nodePoint.x, y + nodePoint.y);
9061
+ endLatLng = mapRef.layerPointToLatLng(endPoint);
9062
+ }
9063
+ createPolyline({
9064
+ L: L__namespace,
9065
+ mapRef,
9066
+ startLatLng,
9067
+ endLatLng,
9068
+ isSelected: isConnectingToStakeholderSelected,
9069
+ id,
9033
9070
  zoom,
9034
- totalMarkers: node.totalStakeholders,
9035
- markerIndex: node.stakeholdersIndex
9036
- });
9037
- const nodeLatLng = L__namespace.latLng(node.gps.latitude, node.gps.longitude);
9038
- const nodePoint = mapRef.latLngToLayerPoint(nodeLatLng);
9039
- const endPoint = L__namespace.point(x + nodePoint.x, y + nodePoint.y);
9040
- endLatLng = mapRef.layerPointToLatLng(endPoint);
9041
- }
9042
- createPolyline({
9043
- L: L__namespace,
9044
- mapRef,
9045
- startLatLng: centerLatLng,
9046
- endLatLng,
9047
- isSelected: isConnectingToStakeholderSelected,
9048
- id,
9049
- zoom,
9050
- listOfPolylines: polylinesRef.current
9071
+ listOfPolylines: polylinesRef.current
9072
+ });
9051
9073
  });
9052
- });
9074
+ }, [linkedNodesData, selectedMarkersId, zoom, stakeholdersOfLocation, isSelected]);
9053
9075
  return /*#__PURE__*/jsxRuntime.jsx(antd.Popover, {
9054
9076
  content: renderTooltipJsx({
9055
9077
  title: data.name,
@@ -9565,7 +9587,8 @@ function useMapHelper$1({
9565
9587
  link: link,
9566
9588
  onClickLink: onClickLink,
9567
9589
  activeStakeholder: activeStakeholder,
9568
- setActiveStakeholder: setActiveStakeholder
9590
+ setActiveStakeholder: setActiveStakeholder,
9591
+ mapRef: mapRef
9569
9592
  }));
9570
9593
  roots.current.push(root);
9571
9594
  } else if (type === "location") {
@@ -9770,7 +9793,8 @@ const useMap = ({
9770
9793
  MAP_TOKEN
9771
9794
  } = useMapConfig({
9772
9795
  app,
9773
- isSatellite
9796
+ isSatellite,
9797
+ mapRef: container
9774
9798
  });
9775
9799
  const [initialMarkerSetIsDone, setInitialMarkerSetIsDone] = React.useState(false);
9776
9800
  const [mapCenter, setMapCenter] = React.useState([0, 0]);
@@ -9787,6 +9811,8 @@ const useMap = ({
9787
9811
  const graph = new Map();
9788
9812
  const stakeToLoc = new Map();
9789
9813
  const nodeTypes = new Map();
9814
+
9815
+ // Build the graph
9790
9816
  for (const loc of data) {
9791
9817
  const locId = loc.datastakeId;
9792
9818
  nodeTypes.set(locId, loc.type);
@@ -9811,26 +9837,45 @@ const useMap = ({
9811
9837
  }
9812
9838
  }
9813
9839
  const highlightTable = {};
9840
+
9841
+ // Perform BFS/DFS to find all connected nodes in the entire chain
9814
9842
  for (const [node] of graph) {
9815
9843
  const highlighted = new Set();
9816
- highlighted.add(node);
9817
- const nodeIsStakeholder = !isLocation(nodeTypes.get(node));
9818
- if (nodeIsStakeholder && stakeToLoc.has(node)) {
9819
- const parentLoc = stakeToLoc.get(node);
9820
- highlighted.add(parentLoc);
9821
- }
9822
- for (const neighbor of graph.get(node) || []) {
9823
- const neighborIsStakeholder = !isLocation(nodeTypes.get(neighbor));
9824
- if (neighborIsStakeholder && stakeToLoc.has(neighbor)) {
9825
- const neighborParent = stakeToLoc.get(neighbor);
9826
- if (isLocation(nodeTypes.get(node)) && neighborParent === node || nodeIsStakeholder && stakeToLoc.get(node) === neighborParent) {
9827
- highlighted.add(neighbor);
9828
- } else {
9844
+ const queue = [node];
9845
+ const visited = new Set([node]);
9846
+ while (queue.length > 0) {
9847
+ const current = queue.shift();
9848
+ highlighted.add(current);
9849
+
9850
+ // Add parent location if current is stakeholder
9851
+ const currentIsStakeholder = !isLocation(nodeTypes.get(current));
9852
+ if (currentIsStakeholder && stakeToLoc.has(current)) {
9853
+ const parentLoc = stakeToLoc.get(current);
9854
+ if (!visited.has(parentLoc)) {
9855
+ highlighted.add(parentLoc);
9856
+ visited.add(parentLoc);
9857
+ queue.push(parentLoc);
9858
+ }
9859
+ }
9860
+
9861
+ // Traverse all neighbors
9862
+ for (const neighbor of graph.get(current) || []) {
9863
+ if (!visited.has(neighbor)) {
9864
+ visited.add(neighbor);
9865
+ queue.push(neighbor);
9829
9866
  highlighted.add(neighbor);
9830
- highlighted.add(neighborParent);
9867
+
9868
+ // If neighbor is stakeholder, add its parent location
9869
+ const neighborIsStakeholder = !isLocation(nodeTypes.get(neighbor));
9870
+ if (neighborIsStakeholder && stakeToLoc.has(neighbor)) {
9871
+ const neighborParent = stakeToLoc.get(neighbor);
9872
+ if (!visited.has(neighborParent)) {
9873
+ highlighted.add(neighborParent);
9874
+ visited.add(neighborParent);
9875
+ queue.push(neighborParent);
9876
+ }
9877
+ }
9831
9878
  }
9832
- } else {
9833
- highlighted.add(neighbor);
9834
9879
  }
9835
9880
  }
9836
9881
  highlightTable[node] = [...highlighted];
@@ -9868,10 +9913,20 @@ const useMap = ({
9868
9913
  function handleSelectMarker(clickedMarker) {
9869
9914
  setSelectedMarkersId(prev => {
9870
9915
  if (prev.includes(clickedMarker.datastakeId)) {
9916
+ // Deselecting - clear polylines
9871
9917
  openPopupIdRef.current = null;
9872
9918
  setMarkerWithPopup(null);
9873
9919
  return [];
9874
9920
  } else {
9921
+ // CLEAR OLD POLYLINES BEFORE SELECTING NEW MARKER
9922
+ if (polylinesRef.current.length > 0) {
9923
+ polylinesRef.current.forEach(polyline => {
9924
+ if (mapRef.hasLayer(polyline)) {
9925
+ mapRef.removeLayer(polyline);
9926
+ }
9927
+ });
9928
+ polylinesRef.current = [];
9929
+ }
9875
9930
  setMarkerWithPopup(isStakeholder(clickedMarker.type) ? clickedMarker : null);
9876
9931
  const newSelectedMarkersId = highlightTable[clickedMarker.datastakeId];
9877
9932
  openPopupIdRef.current = clickedMarker.datastakeId;
@@ -9895,19 +9950,29 @@ const useMap = ({
9895
9950
  });
9896
9951
  }
9897
9952
  }
9953
+ if (type === "chain" && selectedMarkersId.length === 0) {
9954
+ if (polylinesRef.current.length) {
9955
+ polylinesRef.current.forEach(polyline => {
9956
+ if (mapRef.hasLayer(polyline)) {
9957
+ mapRef.removeLayer(polyline);
9958
+ }
9959
+ });
9960
+ polylinesRef.current = [];
9961
+ }
9962
+ }
9898
9963
  clearMapMarkers();
9899
9964
  if (data) {
9900
- // Filters out locations that are not connected to any stakeholders
9901
- const excludedType = ['village', 'town', 'area', 'territory'];
9902
- 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)))));
9965
+ 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))));
9903
9966
  const maxTotal = Math.max(...(data || []).map(d => d.total));
9904
9967
  const dataToRender = type === "chain" ? filteredData : data;
9905
9968
  dataToRender.forEach((d, i) => {
9906
9969
  addIconToMapInitialy([d?.marker?.lat, d?.marker?.lng], "location", d.category || "mineSite", d, maxTotal, i);
9907
9970
  });
9908
- polylinesRef.current.forEach(polyline => {
9909
- mapRef.addLayer(polyline);
9910
- });
9971
+ if (selectedMarkersId.length > 0) {
9972
+ polylinesRef.current.forEach(polyline => {
9973
+ mapRef.addLayer(polyline);
9974
+ });
9975
+ }
9911
9976
  mapRef.invalidateSize();
9912
9977
  mapRef.fire("moveend");
9913
9978
  }
@@ -17087,6 +17152,9 @@ function showHideForm(form, formsValue) {
17087
17152
  }
17088
17153
  return true;
17089
17154
  }
17155
+ const filterForm = (f, d) => {
17156
+ return f && (f.showFormIf ? showHideForm(f, d) : true);
17157
+ };
17090
17158
  const getSgbEvaluationIcons = (width, height) => ({
17091
17159
  0: /*#__PURE__*/jsxRuntime.jsxs("svg", {
17092
17160
  width: width,
@@ -17424,8 +17492,28 @@ function AjaxModal$1({
17424
17492
  const types = {
17425
17493
  MODAL: 'modal'
17426
17494
  };
17495
+ const isGroupInput = (group, repeatable = false, data) => {
17496
+ let resp = group.inputs && Object.keys(group.inputs).length && group.repeatable === repeatable && group.type !== 'groupInputs' && group.type !== 'group' && group.type !== 'dataLinkGroup' && group.display !== 'group' && !group.viewGroup && !group.component;
17497
+ if (group.showIf || group?.meta?.excludeFromView) {
17498
+ resp = resp && showHideInput$3(group, data);
17499
+ }
17500
+ return resp;
17501
+ };
17427
17502
  const repeatObjects = (obj, fn = () => {}, filter = null, sort = null) => filter ? Object.keys(obj).filter(key => filter(obj[key])).map(fn) : sort ? Object.keys(obj).sort(sort).map(fn) : Object.keys(obj).map(fn);
17428
17503
  const conditions = new RegExp(/( is | and | not | notEmpty | includes )/gm);
17504
+ const getLastRow = (arr, cols) => {
17505
+ let currentInd = -1;
17506
+ const newArr = [];
17507
+ arr.forEach(nr => {
17508
+ if (nr % cols === 0) {
17509
+ newArr[currentInd + 1] = [nr];
17510
+ currentInd++;
17511
+ } else {
17512
+ newArr[currentInd].push(nr);
17513
+ }
17514
+ });
17515
+ return newArr[newArr.length - 1];
17516
+ };
17429
17517
  const _verifyCondition = (condition, data, allData) => {
17430
17518
  let [path, match, needed] = condition.split(conditions);
17431
17519
  const isRepeatable = path.split('./').length > 1;
@@ -17498,6 +17586,49 @@ const showHideInput$3 = (input, formsValue, repeatValues) => {
17498
17586
  }
17499
17587
  return true;
17500
17588
  };
17589
+ const getNkey = namespace => {
17590
+ if (['location', 'scl', 'village', 'event', 'incidents', 'corrective-actions', 'testimonials', 'initiatives', 'victims', 'pictures', 'documents', 'lir', 'sp', 'im', 'sci', 'bpe', 'gm'].includes(namespace)) {
17591
+ return 'scoping';
17592
+ }
17593
+ return namespace;
17594
+ };
17595
+ const groupSubsections = (form, onlyConf = false) => {
17596
+ return Object.keys(form).reduce((f, fKey) => {
17597
+ if (form[fKey].subSection) {
17598
+ let subName = form[fKey].subSection;
17599
+ if (typeof form[fKey].subSection === "object") {
17600
+ subName = form[fKey].subSection.name;
17601
+ }
17602
+ if (!f[subName]) {
17603
+ f[subName] = {
17604
+ label: '',
17605
+ icon: '',
17606
+ position: 0
17607
+ };
17608
+ if (typeof form[fKey].subSection === "object") {
17609
+ const {
17610
+ label = '',
17611
+ icon = '',
17612
+ position = 0,
17613
+ showFormIf = ''
17614
+ } = form[fKey].subSection;
17615
+ f[subName] = {
17616
+ label,
17617
+ icon,
17618
+ position,
17619
+ showFormIf
17620
+ };
17621
+ }
17622
+ }
17623
+ if (!onlyConf) {
17624
+ Object.assign(f[subName], {
17625
+ [fKey]: form[fKey]
17626
+ });
17627
+ }
17628
+ }
17629
+ return f;
17630
+ }, {});
17631
+ };
17501
17632
  const renderPlaceholder = ({
17502
17633
  data,
17503
17634
  config,
@@ -24479,6 +24610,19 @@ const Input = ({
24479
24610
  return getComponent();
24480
24611
  };
24481
24612
 
24613
+ const getDisabled = ({
24614
+ disabled,
24615
+ groupCheckboxDisableKey,
24616
+ data
24617
+ }) => {
24618
+ if (disabled) {
24619
+ return true;
24620
+ }
24621
+ if (typeof groupCheckboxDisableKey === 'string') {
24622
+ return !Object.values(data?.[groupCheckboxDisableKey] || {}).find(c => typeof c === 'number');
24623
+ }
24624
+ return false;
24625
+ };
24482
24626
  ({
24483
24627
  t: PropTypes__default["default"].func,
24484
24628
  data: PropTypes__default["default"].any,
@@ -24541,6 +24685,7 @@ function convertUndefinedToNull(obj) {
24541
24685
  }
24542
24686
  return obj;
24543
24687
  }
24688
+ const hasKeyInObject = (obj, key) => Object.keys(obj || {}).includes(key);
24544
24689
 
24545
24690
  const packageApps = ["kota", "sbg", "nashiriki", "straatos", "wazi", "hatua"]; //PACKAGE_CHANGE_LATER (add sbg)
24546
24691
 
@@ -39900,6 +40045,710 @@ const StatCard = ({
39900
40045
  });
39901
40046
  };
39902
40047
 
40048
+ const RepeatableGroup = ({
40049
+ name = null,
40050
+ config = {},
40051
+ allData = {},
40052
+ linkingData = {},
40053
+ ajaxOptions,
40054
+ t,
40055
+ ajaxForms,
40056
+ changeAjaxForms,
40057
+ getApiBaseUrl,
40058
+ getAppHeader,
40059
+ user,
40060
+ getToken,
40061
+ app
40062
+ }) => {
40063
+ const {
40064
+ automaticallyLink,
40065
+ dataLink,
40066
+ call
40067
+ } = React.useMemo(() => config, [config]);
40068
+ const entity = React.useMemo(() => automaticallyLink?.entity || config?.meta?.dataLinkEntity, [automaticallyLink, config]);
40069
+ const isAjaxModal = React.useMemo(() => automaticallyLink && dataLink && call, [automaticallyLink, dataLink, call]);
40070
+ const [modalRow, setModalRow] = React.useState(null);
40071
+ const dataSource = React.useMemo(() => allData[name] || [], [allData, name]);
40072
+ const notAvailable = (allData?.meta?.inputs || {})[name]?.notAvailable;
40073
+ const notApplicable = (allData?.meta?.inputs || {})[name]?.notApplicable;
40074
+ const noBody = notApplicable || notAvailable;
40075
+ const _data = React.useMemo(() => dataSource.length ? dataSource.map((f, i) => {
40076
+ if (isAjaxModal && typeof f === 'string' && linkingData && linkingData[entity] && linkingData[entity][f]) {
40077
+ const value = linkingData[entity][f];
40078
+ return {
40079
+ ...value,
40080
+ key: i
40081
+ };
40082
+ }
40083
+ if (config?.meta?.ajaxOptionsKey) {
40084
+ if (linkingData && linkingData[entity] && linkingData[entity][f[config?.meta?.ajaxOptionsKey]]) {
40085
+ const value = linkingData[entity][f[config?.meta?.ajaxOptionsKey]];
40086
+ return {
40087
+ ...value,
40088
+ key: i
40089
+ };
40090
+ }
40091
+ const options = ajaxOptions[config?.meta?.ajaxOptionsKey];
40092
+ if (Array.isArray(options)) {
40093
+ const value = options.find(v => v.value === f[config?.meta?.ajaxOptionsKey]);
40094
+ if (value) {
40095
+ return {
40096
+ ...f,
40097
+ ...value,
40098
+ key: i
40099
+ };
40100
+ }
40101
+ }
40102
+ }
40103
+ return {
40104
+ ...f,
40105
+ key: i
40106
+ };
40107
+ }) : [{
40108
+ key: 1,
40109
+ isEmpty: true
40110
+ }, {
40111
+ key: 2,
40112
+ isEmpty: true
40113
+ }], [isAjaxModal, dataSource, entity, config, ajaxOptions, linkingData]);
40114
+ const mapKey = key => ({
40115
+ title: config?.inputs[key]?.label,
40116
+ key: key,
40117
+ dataIndex: key,
40118
+ ellipsis: true,
40119
+ render: (v, all) => {
40120
+ if (all.isEmpty) {
40121
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
40122
+ className: "daf-default-cell md"
40123
+ });
40124
+ }
40125
+ if (v) {
40126
+ return /*#__PURE__*/jsxRuntime.jsx(BasicInput, {
40127
+ t: t,
40128
+ app: app,
40129
+ ajaxForms: ajaxForms,
40130
+ changeAjaxForms: changeAjaxForms,
40131
+ getApiBaseUrl: getApiBaseUrl,
40132
+ getAppHeader: getAppHeader,
40133
+ user: user,
40134
+ getToken: getToken,
40135
+ name: key,
40136
+ config: config.inputs[key],
40137
+ valueOnlyString: true,
40138
+ data: all
40139
+ }, key);
40140
+ }
40141
+ return '--';
40142
+ }
40143
+ });
40144
+ const columns = [...(Array.isArray(config?.meta?.tableKeys) ? config.meta.tableKeys.map(mapKey) : Object.keys(config?.inputs).map(mapKey)), {
40145
+ key: 'actions',
40146
+ dataIndex: 'actions',
40147
+ label: '',
40148
+ width: 50,
40149
+ render: (_, all) => {
40150
+ if (all.isEmpty) {
40151
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
40152
+ className: "daf-default-cell md"
40153
+ });
40154
+ }
40155
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
40156
+ onClick: () => setModalRow(all),
40157
+ className: "cursor-pointer flex justify-content-center",
40158
+ children: /*#__PURE__*/jsxRuntime.jsx(Icons.EyeOutlined, {})
40159
+ });
40160
+ }
40161
+ }];
40162
+ const _subTitle = config.viewSubTitle || config.subTitle;
40163
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
40164
+ className: formatClassname(["group repeatable", noBody && 'no-body']),
40165
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
40166
+ className: "daf-title with-subtitle",
40167
+ children: [/*#__PURE__*/jsxRuntime.jsx("h1", {
40168
+ children: ReactHtmlParser__default["default"](config?.label)
40169
+ }), _subTitle && typeof _subTitle === 'string' ? /*#__PURE__*/jsxRuntime.jsx("p", {
40170
+ children: ReactHtmlParser__default["default"](_subTitle)
40171
+ }) : null]
40172
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
40173
+ className: "flex",
40174
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
40175
+ className: "daf-table-wrapper no-padding repeatable-form-table input no-pagination",
40176
+ children: /*#__PURE__*/jsxRuntime.jsx(antd.ConfigProvider, {
40177
+ renderEmpty: () => notApplicable ? t('Not applicable') : t('No information available'),
40178
+ children: /*#__PURE__*/jsxRuntime.jsx(antd.Table, {
40179
+ locale: getLocales(t),
40180
+ pagination: false,
40181
+ columns: columns,
40182
+ rowKey: "key",
40183
+ dataSource: noBody ? [] : _data
40184
+ })
40185
+ })
40186
+ }), !noActionsInputs.includes(config?.type) ? /*#__PURE__*/jsxRuntime.jsxs("div", {
40187
+ className: "ml-4 input-actions flex",
40188
+ children: [/*#__PURE__*/jsxRuntime.jsx(Review, {
40189
+ t: t,
40190
+ config: config,
40191
+ inputMeta: (allData?.meta?.inputs || {})[name] || {},
40192
+ name: name
40193
+ }), /*#__PURE__*/jsxRuntime.jsx(Versions, {
40194
+ t: t,
40195
+ versionsDatapoints: [],
40196
+ config: config,
40197
+ allData: allData,
40198
+ name: name,
40199
+ getValue: () => null
40200
+ }), /*#__PURE__*/jsxRuntime.jsx(antd.Tooltip, {
40201
+ title: t("Sources"),
40202
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40203
+ children: /*#__PURE__*/jsxRuntime.jsx(antd.Button, {
40204
+ className: "default p-0 flex flex-column justify-content-center",
40205
+ type: "link",
40206
+ disabled: true,
40207
+ children: /*#__PURE__*/jsxRuntime.jsx(CustomIcon, {
40208
+ name: "Sources",
40209
+ width: 16,
40210
+ height: 16
40211
+ })
40212
+ })
40213
+ })
40214
+ }), /*#__PURE__*/jsxRuntime.jsx(antd.Tooltip, {
40215
+ title: t("Comments"),
40216
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40217
+ children: /*#__PURE__*/jsxRuntime.jsx(Comments, {
40218
+ t: t,
40219
+ config: config,
40220
+ allData: allData,
40221
+ name: name
40222
+ })
40223
+ })
40224
+ })]
40225
+ }) : null]
40226
+ }), /*#__PURE__*/jsxRuntime.jsx(antd.Modal, {
40227
+ open: !!modalRow,
40228
+ title: /*#__PURE__*/jsxRuntime.jsx(ModalHeader, {
40229
+ title: config?.label
40230
+ }),
40231
+ footer: null,
40232
+ width: 650,
40233
+ className: "max-h-50",
40234
+ onCancel: () => setModalRow(null),
40235
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40236
+ className: "daf-view-form",
40237
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40238
+ className: "view-content",
40239
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40240
+ className: "content no-padding",
40241
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40242
+ className: "wrapper",
40243
+ style: {
40244
+ maxWidth: 600 // FUTURE ILVI
40245
+ },
40246
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40247
+ className: "group",
40248
+ children: /*#__PURE__*/jsxRuntime.jsx(Input, {
40249
+ app: app,
40250
+ t: t,
40251
+ ajaxForms: ajaxForms,
40252
+ changeAjaxForms: changeAjaxForms,
40253
+ getApiBaseUrl: getApiBaseUrl,
40254
+ getAppHeader: getAppHeader,
40255
+ user: user,
40256
+ getToken: getToken,
40257
+ config: Object.keys(config.inputs || {}).filter(k => {
40258
+ return !(config?.meta?.excludedKeysView || []).includes(k);
40259
+ }).reduce((all, key) => {
40260
+ all[key] = config.inputs[key];
40261
+ return all;
40262
+ }, {}),
40263
+ data: {
40264
+ ...modalRow
40265
+ }
40266
+ })
40267
+ })
40268
+ })
40269
+ })
40270
+ })
40271
+ })
40272
+ })]
40273
+ });
40274
+ };
40275
+
40276
+ /* eslint-disable no-case-declarations */
40277
+ const RepeatableModals = ({
40278
+ name = null,
40279
+ config = {},
40280
+ data = {},
40281
+ linkingData = {},
40282
+ linkingForms = {},
40283
+ ajaxOptions = [],
40284
+ t,
40285
+ ajaxForms,
40286
+ changeAjaxForms,
40287
+ getApiBaseUrl,
40288
+ getAppHeader,
40289
+ user,
40290
+ getToken,
40291
+ app
40292
+ }) => {
40293
+ const label = (prop = null) => {
40294
+ function getLabel(label) {
40295
+ switch (typeof label) {
40296
+ case 'string':
40297
+ return label;
40298
+ case 'object':
40299
+ const labelKey = Object.keys(label).find(cond => verifyConditional(cond, data));
40300
+ return label[labelKey];
40301
+ default:
40302
+ return label;
40303
+ }
40304
+ }
40305
+ if (config[prop]) {
40306
+ return getLabel(config[prop]);
40307
+ }
40308
+ if (config.sectionLabel) {
40309
+ return getLabel(config.sectionLabel);
40310
+ }
40311
+ if (config.outputLabel) {
40312
+ return getLabel(config.outputLabel);
40313
+ }
40314
+ return getLabel(config.label);
40315
+ };
40316
+ return verifyConditional(config.showIf ? config.showIf : null, data) ? /*#__PURE__*/jsxRuntime.jsxs("div", {
40317
+ className: "group",
40318
+ children: [label('outputLabel') ? /*#__PURE__*/jsxRuntime.jsx("div", {
40319
+ className: "title",
40320
+ children: /*#__PURE__*/jsxRuntime.jsx("h1", {
40321
+ children: label('outputLabel')
40322
+ })
40323
+ }) : null, data[name] && data[name].length ? data[name].map((item, index) => /*#__PURE__*/jsxRuntime.jsxs("div", {
40324
+ className: "group display",
40325
+ style: {
40326
+ border: '1px dotted var(--mmt-primary-70)'
40327
+ },
40328
+ children: [label() ? /*#__PURE__*/jsxRuntime.jsx("div", {
40329
+ className: "title",
40330
+ children: /*#__PURE__*/jsxRuntime.jsxs("h1", {
40331
+ children: [label(), " #", index + 1]
40332
+ })
40333
+ }) : null, repeatObjects(config.inputs, key => {
40334
+ const modalData = {
40335
+ [name]: {
40336
+ [key]: data[name][index][key] || null
40337
+ }
40338
+ };
40339
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
40340
+ className: "group",
40341
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
40342
+ className: "title",
40343
+ children: /*#__PURE__*/jsxRuntime.jsx("h1", {
40344
+ children: config.inputs[key].outputLabel || getInputLabel$2(config.inputs[key], item)
40345
+ })
40346
+ }), /*#__PURE__*/jsxRuntime.jsx(Input, {
40347
+ app: app,
40348
+ ajaxForms: ajaxForms,
40349
+ changeAjaxForms: changeAjaxForms,
40350
+ getApiBaseUrl: getApiBaseUrl,
40351
+ getAppHeader: getAppHeader,
40352
+ user: user,
40353
+ getToken: getToken,
40354
+ t: t,
40355
+ parent: name,
40356
+ name: config.inputs[key].dataId || key,
40357
+ config: config.inputs[key],
40358
+ data: modalData,
40359
+ linkingData: linkingData,
40360
+ linkingForms: linkingForms,
40361
+ ajaxOptions: ajaxOptions,
40362
+ cols: 2
40363
+ }, key)]
40364
+ }, key);
40365
+ })]
40366
+ }, index)) : /*#__PURE__*/jsxRuntime.jsx("span", {
40367
+ className: "text-muted",
40368
+ children: t('Not answered')
40369
+ })]
40370
+ }) : null;
40371
+ };
40372
+
40373
+ /* eslint-disable no-unused-vars */
40374
+ const Content = ({
40375
+ style = {},
40376
+ form = {},
40377
+ data = {},
40378
+ groupConfig = {},
40379
+ versionsDatapoints,
40380
+ linkingData = {},
40381
+ linkingForms = {},
40382
+ ajaxOptions = [],
40383
+ // ADDED
40384
+ t,
40385
+ app,
40386
+ ajaxForms,
40387
+ language,
40388
+ changeAjaxForms,
40389
+ getApiBaseUrl,
40390
+ getAppHeader,
40391
+ user,
40392
+ evaluationConfig = [],
40393
+ fullWidth = false
40394
+ }) => {
40395
+ const groupSingle = grps => {
40396
+ const form = Object.keys(grps).reduce((f, gKey) => {
40397
+ if (grps[gKey].type !== "modal" && !isGroupInput(grps[gKey], false, data) && !isGroupInput(grps[gKey], true, data) && grps[gKey].display !== "group" && !grps[gKey].viewGroup && !grps[gKey].component) {
40398
+ if (grps[gKey].group && !f[grps[gKey].group]) {
40399
+ f[grps[gKey].group] = {};
40400
+ Object.assign(f[grps[gKey].group], {
40401
+ [gKey]: grps[gKey]
40402
+ });
40403
+ } else if (grps[gKey].group && f[grps[gKey].group]) {
40404
+ Object.assign(f[grps[gKey].group], {
40405
+ [gKey]: grps[gKey]
40406
+ });
40407
+ }
40408
+ if (grps[gKey]?.meta?.group && !f[grps[gKey]?.meta?.group]) {
40409
+ f[grps[gKey]?.meta?.group] = {};
40410
+ Object.assign(f[grps[gKey].meta.group], {
40411
+ [gKey]: grps[gKey]
40412
+ });
40413
+ } else if (grps[gKey]?.meta?.group && f[grps[gKey]?.meta?.group]) {
40414
+ Object.assign(f[grps[gKey].meta.group], {
40415
+ [gKey]: grps[gKey]
40416
+ });
40417
+ }
40418
+ if (grps[gKey].section && !f[grps[gKey].section]) {
40419
+ f[grps[gKey].section] = {};
40420
+ Object.assign(f[grps[gKey].section], {
40421
+ [gKey]: grps[gKey]
40422
+ });
40423
+ } else if (grps[gKey].section && f[grps[gKey].section]) {
40424
+ Object.assign(f[grps[gKey].section], {
40425
+ [gKey]: grps[gKey]
40426
+ });
40427
+ }
40428
+ }
40429
+ return f;
40430
+ }, {});
40431
+ return form;
40432
+ };
40433
+ const getDisplayGroupConfig = (groups, key) => {
40434
+ return Object.keys(groups).reduce((items, gKey) => {
40435
+ if (groups[gKey].viewGroup === key) {
40436
+ // eslint-disable-next-line no-unused-vars
40437
+ const {
40438
+ viewGroup,
40439
+ ...gCfg
40440
+ } = groups[gKey];
40441
+ items[gKey] = gCfg;
40442
+ }
40443
+ return items;
40444
+ }, {});
40445
+ };
40446
+ const getComponent = (component, key, config) => {
40447
+ switch (component) {
40448
+ case "repeatableModals":
40449
+ return /*#__PURE__*/jsxRuntime.jsx(RepeatableModals, {
40450
+ app: app,
40451
+ t: t,
40452
+ ajaxForms: ajaxForms,
40453
+ changeAjaxForms: changeAjaxForms,
40454
+ getApiBaseUrl: getApiBaseUrl,
40455
+ getAppHeader: getAppHeader,
40456
+ user: user,
40457
+ getToken: getToken,
40458
+ name: key,
40459
+ data: data,
40460
+ config: config,
40461
+ linkingData: linkingData,
40462
+ linkingForms: linkingForms,
40463
+ ajaxOptions: ajaxOptions
40464
+ }, key);
40465
+ default:
40466
+ return /*#__PURE__*/jsxRuntime.jsx("p", {
40467
+ children: "Component"
40468
+ });
40469
+ }
40470
+ };
40471
+ const isDisplayGroup = input => input.display && input.display === "group";
40472
+ const isSingleModal = input => input.type && input.type === "modal";
40473
+ const hasComponent = input => input.component && typeof input.component === "string";
40474
+ const typeRender = (groups, singleGroupsKeys, addedContent) => {
40475
+ const _length = Object.keys(groups || {}).length;
40476
+ const isEven = _length % 2 === 0;
40477
+ const groupped = Object.keys(groups).reduce((all, key) => {
40478
+ const _val = groups[key];
40479
+ const group = _val.group || _val?.meta?.group || _val.section;
40480
+ if (all[group]) {
40481
+ all[group][key] = _val;
40482
+ } else {
40483
+ all[group] = {
40484
+ [key]: _val
40485
+ };
40486
+ }
40487
+ return all;
40488
+ }, {});
40489
+ return Object.keys(groupped).map(key => {
40490
+ const groups = groupped[key];
40491
+ return /*#__PURE__*/jsxRuntime.jsx(React__default["default"].Fragment, {
40492
+ children: repeatObjects(groups, (key, ind) => {
40493
+ // normal group
40494
+ return hasComponent(groups[key]) ? getComponent(groups[key].component, key, groups[key]) : isGroupInput(groups[key], false, data) ? /*#__PURE__*/jsxRuntime.jsx(Group, {
40495
+ t: t,
40496
+ name: key,
40497
+ linkingData: linkingData,
40498
+ config: groups[key],
40499
+ data: data,
40500
+ allData: data,
40501
+ linkingForms: linkingForms,
40502
+ cols: 2,
40503
+ ajaxForms: ajaxForms,
40504
+ changeAjaxForms: changeAjaxForms,
40505
+ getApiBaseUrl: getApiBaseUrl,
40506
+ getAppHeader: getAppHeader,
40507
+ user: user,
40508
+ getToken: getToken,
40509
+ evaluationConfig: evaluationConfig,
40510
+ ajaxOptions: ajaxOptions
40511
+ }, key) :
40512
+ // repeatable group
40513
+ isGroupInput(groups[key], true, data) ? /*#__PURE__*/jsxRuntime.jsx(RepeatableGroup, {
40514
+ app: app,
40515
+ t: t,
40516
+ ajaxForms: ajaxForms,
40517
+ changeAjaxForms: changeAjaxForms,
40518
+ getApiBaseUrl: getApiBaseUrl,
40519
+ getAppHeader: getAppHeader,
40520
+ user: user,
40521
+ getToken: getToken,
40522
+ name: key,
40523
+ config: groups[key],
40524
+ data: data,
40525
+ allData: data,
40526
+ linkingData: linkingData,
40527
+ linkingForms: linkingForms,
40528
+ ajaxOptions: ajaxOptions
40529
+ }, key) :
40530
+ // single inputs grouped
40531
+ singleGroupsKeys.includes(key) ? (() => {
40532
+ if (!addedContent.includes(key)) {
40533
+ const currentGroup = Object.keys(groupSingle(groups)).find(k => Object.keys(groupSingle(groups)[k]).includes(key));
40534
+ addedContent.push(...Object.keys(groupSingle(groups)[currentGroup]));
40535
+ const config = groupSingle(groups)[currentGroup];
40536
+ if (groups[key].viewShowIf || groups[key]?.meta?.excludeFromView) {
40537
+ if (!showHideInput$3(groups[key], data)) {
40538
+ return null;
40539
+ }
40540
+ }
40541
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
40542
+ className: "group",
40543
+ id: currentGroup,
40544
+ children: [groupConfig[currentGroup] ? /*#__PURE__*/jsxRuntime.jsx("div", {
40545
+ className: "title",
40546
+ children: /*#__PURE__*/jsxRuntime.jsx("h1", {
40547
+ children: groupConfig[currentGroup][language]
40548
+ })
40549
+ }) : null, /*#__PURE__*/jsxRuntime.jsx(Input, {
40550
+ app: app,
40551
+ t: t,
40552
+ ajaxForms: ajaxForms,
40553
+ changeAjaxForms: changeAjaxForms,
40554
+ getApiBaseUrl: getApiBaseUrl,
40555
+ getAppHeader: getAppHeader,
40556
+ user: user,
40557
+ getToken: getToken,
40558
+ versionsDatapoints: versionsDatapoints,
40559
+ name: config.dataId || key,
40560
+ config: config,
40561
+ data: data,
40562
+ allData: data,
40563
+ linkingData: linkingData,
40564
+ className: isEven ? ind === _length - 1 || ind === _length - 2 ? "last" : undefined : ind === _length - 1 ? "last" : undefined,
40565
+ linkingForms: linkingForms,
40566
+ ajaxOptions: ajaxOptions,
40567
+ evaluationConfig: evaluationConfig,
40568
+ cols: 2
40569
+ }, key)]
40570
+ }, `${currentGroup}-${Date.now()}`);
40571
+ }
40572
+ })() :
40573
+ // display group
40574
+ isDisplayGroup(groups[key]) ? /*#__PURE__*/jsxRuntime.jsxs("div", {
40575
+ className: "group display",
40576
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
40577
+ className: "title",
40578
+ children: /*#__PURE__*/jsxRuntime.jsx("h1", {
40579
+ children: groups[key].label
40580
+ })
40581
+ }), typeRender(getDisplayGroupConfig(groups, key), singleGroupsKeys, addedContent)]
40582
+ }, key) :
40583
+ // single modal
40584
+ isSingleModal(groups[key]) ? /*#__PURE__*/jsxRuntime.jsxs("div", {
40585
+ className: "group",
40586
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
40587
+ className: "title",
40588
+ children: /*#__PURE__*/jsxRuntime.jsx("h1", {
40589
+ children: groups[key].outputLabel || getInputLabel$2(groups[key], data)
40590
+ })
40591
+ }), /*#__PURE__*/jsxRuntime.jsx(Input, {
40592
+ app: app,
40593
+ t: t,
40594
+ ajaxForms: ajaxForms,
40595
+ changeAjaxForms: changeAjaxForms,
40596
+ getApiBaseUrl: getApiBaseUrl,
40597
+ getAppHeader: getAppHeader,
40598
+ user: user,
40599
+ getToken: getToken,
40600
+ versionsDatapoints: versionsDatapoints,
40601
+ parent: key,
40602
+ name: groups[key].dataId || key,
40603
+ config: groups[key],
40604
+ className: "last",
40605
+ data: data,
40606
+ allData: data,
40607
+ linkingData: linkingData,
40608
+ linkingForms: linkingForms,
40609
+ ajaxOptions: ajaxOptions,
40610
+ evaluationConfig: evaluationConfig,
40611
+ cols: 2
40612
+ }, key)]
40613
+ }, key) : null;
40614
+ })
40615
+ }, key);
40616
+ });
40617
+ };
40618
+ React.useEffect(() => {
40619
+ setTimeout(() => {
40620
+ const groups = Array.from(document.getElementsByClassName("group"));
40621
+ const rows = Array.from(document.querySelectorAll(".repetable-row-extra"));
40622
+ rows.forEach(row => {
40623
+ const inputs = Array.from(row.querySelectorAll(".input"));
40624
+ const lasts = getLastRow(inputs.map((i, ind) => ind), 4);
40625
+ if (lasts) {
40626
+ lasts.forEach(index => inputs[index].classList.add("last"));
40627
+ }
40628
+ });
40629
+ groups.forEach(group => {
40630
+ // const isRepeatable = Array.from(group.classList).includes('repeatable');
40631
+ const inputs = Array.from(group.querySelectorAll(".input"));
40632
+ // if (inputs.length && !isRepeatable) {
40633
+ // if (inputs.length % 2 === 0) {
40634
+ // inputs[inputs.length - 1].classList.add('last');
40635
+ // inputs[inputs.length - 2].classList.add('last');
40636
+ // } else {
40637
+ // inputs[inputs.length - 1].classList.add('last');
40638
+ // }
40639
+ // }
40640
+ // remove groups without inputs
40641
+ if (!inputs.length) {
40642
+ group.remove();
40643
+ }
40644
+ });
40645
+ }, 200);
40646
+ }, [form, data]);
40647
+ React.useState({});
40648
+ React.useState({});
40649
+ React.useState({});
40650
+ const renderContent = (f, showTitle = true) => {
40651
+ if (f) {
40652
+ const alertType = ["error", "warning", "info", "success"];
40653
+ if (f.alertConf && f.alertConf.type === "warning") {
40654
+ return /*#__PURE__*/jsxRuntime.jsx(antd.Alert, {
40655
+ message: f.alertConf.text,
40656
+ type: f.alertConf.type,
40657
+ showIcon: true
40658
+ });
40659
+ }
40660
+ let {
40661
+ label,
40662
+ icon,
40663
+ position,
40664
+ ...groups
40665
+ } = f;
40666
+ groups = Object.keys(groups).reduce((items, key) => {
40667
+ if (!groups[key]?.meta?.excludeFromView) {
40668
+ items[key] = groups[key];
40669
+ }
40670
+ return items;
40671
+ }, {});
40672
+ const addedContent = [];
40673
+ const singleGroupsKeys = [].concat(...Object.keys(groupSingle(groups)).map(key => Object.keys(groupSingle(groups)[key])));
40674
+ return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
40675
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
40676
+ className: "wrapper",
40677
+ style: {
40678
+ width: fullWidth ? "100%" : 700
40679
+ },
40680
+ children: [f.alertConf ? /*#__PURE__*/jsxRuntime.jsx(antd.Alert, {
40681
+ className: "w-100",
40682
+ style: {
40683
+ marginBottom: "20px"
40684
+ },
40685
+ message: f.alertConf.text,
40686
+ type: alertType.includes(f.alertConf.type) ? f.alertConf.type : "info",
40687
+ showIcon: true
40688
+ }) : null, typeRender(groups, singleGroupsKeys, addedContent)]
40689
+ }, Date.now())
40690
+ });
40691
+ }
40692
+ };
40693
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
40694
+ className: "content",
40695
+ style: style,
40696
+ children: renderContent(form)
40697
+ });
40698
+ };
40699
+
40700
+ function Modal({
40701
+ t = text => text,
40702
+ open,
40703
+ title,
40704
+ children,
40705
+ onClose,
40706
+ onSuccess,
40707
+ cancelBtnText = "Cancel",
40708
+ saveBtnText = "Save",
40709
+ className,
40710
+ loading = false,
40711
+ disabled = false,
40712
+ withModalFormWrapper = true,
40713
+ ...props
40714
+ }) {
40715
+ return /*#__PURE__*/jsxRuntime.jsxs(antd.Modal, {
40716
+ width: 650,
40717
+ footer: null,
40718
+ open: open,
40719
+ onCancel: onClose,
40720
+ title: /*#__PURE__*/jsxRuntime.jsx(ModalHeader, {
40721
+ title: t(title)
40722
+ }),
40723
+ className: `${className}`,
40724
+ ...props,
40725
+ children: [withModalFormWrapper ? /*#__PURE__*/jsxRuntime.jsx("div", {
40726
+ className: "repeatable-modal-form",
40727
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40728
+ className: "daf-dynamic-form-form",
40729
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40730
+ className: "form",
40731
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40732
+ className: "daf-dynamic-form dynamic-form",
40733
+ children: children
40734
+ })
40735
+ })
40736
+ })
40737
+ }) : children, onSuccess && onClose ? /*#__PURE__*/jsxRuntime.jsxs("div", {
40738
+ className: "daf-form-bottom",
40739
+ children: [onClose && /*#__PURE__*/jsxRuntime.jsx(antd.Button, {
40740
+ onClick: onClose,
40741
+ children: t(cancelBtnText)
40742
+ }), onSuccess && /*#__PURE__*/jsxRuntime.jsx(antd.Button, {
40743
+ type: "primary",
40744
+ onClick: onSuccess,
40745
+ disabled: loading || disabled,
40746
+ children: t(saveBtnText)
40747
+ })]
40748
+ }) : null]
40749
+ });
40750
+ }
40751
+
39903
40752
  class SourceService extends BaseService {
39904
40753
  get(tab, filters) {
39905
40754
  const {
@@ -39937,7 +40786,7 @@ class SourceService extends BaseService {
39937
40786
  });
39938
40787
  }
39939
40788
  }
39940
- createLazyService(SourceService);
40789
+ var SourceService$1 = createLazyService(SourceService);
39941
40790
 
39942
40791
  class VersionService extends BaseService {
39943
40792
  getSources({
@@ -39951,7 +40800,344 @@ class VersionService extends BaseService {
39951
40800
  });
39952
40801
  }
39953
40802
  }
39954
- createLazyService(VersionService);
40803
+ var VersionService$1 = createLazyService(VersionService);
40804
+
40805
+ const getSourcesType = subject => {
40806
+ const typeMapping = {
40807
+ locations: "location",
40808
+ location: "location",
40809
+ "production-sites": "location",
40810
+ stakeholders: "stakeholder",
40811
+ stakeholder: "stakeholder",
40812
+ workers: "stakeholder",
40813
+ operators: "stakeholder",
40814
+ documents: "document",
40815
+ document: "document",
40816
+ events: "event",
40817
+ event: "event",
40818
+ activities: "event",
40819
+ incidents: "event"
40820
+ };
40821
+ return typeMapping[subject] ?? null;
40822
+ };
40823
+
40824
+ const Records = ({
40825
+ onSubmit,
40826
+ modalTitle = "Records",
40827
+ t = () => {},
40828
+ onClose = () => {},
40829
+ open = false,
40830
+ subject = "",
40831
+ id = ""
40832
+ }) => {
40833
+ const [form] = antd.Form.useForm();
40834
+ const [sources, setSources] = React.useState([]);
40835
+ const [versions, setVersions] = React.useState([]);
40836
+ const [selectedSource, setSelectedSource] = React.useState(null);
40837
+ const handleCancel = () => {
40838
+ onClose();
40839
+ form.resetFields();
40840
+ };
40841
+ const type = React.useMemo(() => getSourcesType(subject), [subject]);
40842
+ const getSources = async () => {
40843
+ try {
40844
+ const {
40845
+ data
40846
+ } = await SourceService$1.getSources({
40847
+ type,
40848
+ id
40849
+ });
40850
+ setSources(data);
40851
+ } catch (error) {
40852
+ console.error('Error fetching sources:', error);
40853
+ }
40854
+ };
40855
+ const getVersions = async () => {
40856
+ try {
40857
+ const {
40858
+ data
40859
+ } = await VersionService$1.getSources({
40860
+ type,
40861
+ id,
40862
+ params: {
40863
+ source: selectedSource
40864
+ }
40865
+ });
40866
+ console.log({
40867
+ data
40868
+ });
40869
+ setVersions(data);
40870
+ } catch (error) {
40871
+ console.error('Error fetching versions:', error);
40872
+ }
40873
+ };
40874
+ const sourceOptions = React.useMemo(() => {
40875
+ return sources.map(source => ({
40876
+ label: source?.name,
40877
+ value: source?.id
40878
+ }));
40879
+ }, [sources]);
40880
+ React.useEffect(() => {
40881
+ if (type && id) {
40882
+ getSources();
40883
+ }
40884
+ }, [type, id]);
40885
+ React.useEffect(() => {
40886
+ if (selectedSource) {
40887
+ getVersions();
40888
+ }
40889
+ }, [selectedSource]);
40890
+ const versionOptions = React.useMemo(() => {
40891
+ if (!versions?.numberOfVersions) return [];
40892
+ return Array.from({
40893
+ length: versions.numberOfVersions
40894
+ }, (_, index) => ({
40895
+ label: `Version ${index + 1}`,
40896
+ value: index + 1
40897
+ }));
40898
+ }, [versions]);
40899
+ const handleOk = async () => {
40900
+ try {
40901
+ const values = await form.validateFields();
40902
+ if (onSubmit) {
40903
+ onSubmit(values);
40904
+ }
40905
+ onClose();
40906
+ form.resetFields();
40907
+ } catch (error) {
40908
+ console.error('Validation failed:', error);
40909
+ }
40910
+ };
40911
+ return /*#__PURE__*/jsxRuntime.jsxs(Modal, {
40912
+ open: open,
40913
+ t: t,
40914
+ title: t(modalTitle),
40915
+ onSuccess: handleOk,
40916
+ onClose: handleCancel,
40917
+ withModalFormWrapper: false,
40918
+ children: [/*#__PURE__*/jsxRuntime.jsxs(antd.Form, {
40919
+ form: form,
40920
+ layout: "vertical",
40921
+ name: "recordsForm",
40922
+ children: [/*#__PURE__*/jsxRuntime.jsx(antd.Form.Item, {
40923
+ name: "source",
40924
+ label: t("Source"),
40925
+ rules: [{
40926
+ required: true,
40927
+ message: t('Please select an option')
40928
+ }],
40929
+ children: /*#__PURE__*/jsxRuntime.jsx(antd.Select, {
40930
+ placeholder: t("Select"),
40931
+ showSearch: true,
40932
+ optionFilterProp: "children",
40933
+ onChange: value => {
40934
+ console.log('Selected source ID:', value);
40935
+ setSelectedSource(value);
40936
+ },
40937
+ children: sourceOptions.map(option => /*#__PURE__*/jsxRuntime.jsx(antd.Select.Option, {
40938
+ value: option.value,
40939
+ children: option.label
40940
+ }, option.value))
40941
+ })
40942
+ }), /*#__PURE__*/jsxRuntime.jsx(antd.Form.Item, {
40943
+ name: "version",
40944
+ label: t("Version"),
40945
+ rules: [{
40946
+ required: true,
40947
+ message: t('Please select an option')
40948
+ }],
40949
+ children: /*#__PURE__*/jsxRuntime.jsx(antd.Select, {
40950
+ placeholder: t("Select"),
40951
+ showSearch: true,
40952
+ optionFilterProp: "children",
40953
+ children: versionOptions.map(option => /*#__PURE__*/jsxRuntime.jsx(antd.Select.Option, {
40954
+ value: option.value,
40955
+ children: option.label
40956
+ }, option.value))
40957
+ })
40958
+ })]
40959
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
40960
+ style: {
40961
+ height: 60
40962
+ }
40963
+ })]
40964
+ });
40965
+ };
40966
+
40967
+ const Navigation = ({
40968
+ form = {},
40969
+ data = {},
40970
+ group = null,
40971
+ subsection = null,
40972
+ search = null,
40973
+ onGroupChange = () => {},
40974
+ mod,
40975
+ // TODO: ADD this
40976
+ goTo,
40977
+ params,
40978
+ generatePath,
40979
+ getRedirectLink
40980
+ }) => {
40981
+ const [selectedGroup, setSelectedGroup] = React.useState(null);
40982
+ const [formGroups, setFormGroups] = React.useState([]);
40983
+ const [openKeys, setOpenKeys] = React.useState([]);
40984
+ const hasSubSections = f => Object.keys(f).map(key => propHasValue$1(f[key].subSection)).includes(true);
40985
+ const mapFormGroup = f => Object.keys(f).map(key => {
40986
+ const {
40987
+ label,
40988
+ showFormIf,
40989
+ position
40990
+ } = f[key];
40991
+ const disabled = getDisabled({
40992
+ disabled: f[key]?.title?.meta?.disabled || false,
40993
+ groupCheckboxDisableKey: f[key]?.title?.meta?.groupCheckboxDisableKey,
40994
+ data
40995
+ });
40996
+ const fConf = {
40997
+ key,
40998
+ label,
40999
+ showFormIf,
41000
+ show: filterForm(f[key], data),
41001
+ items: [],
41002
+ disabled: disabled || false,
41003
+ position
41004
+ };
41005
+ if (hasSubSections(f[key])) {
41006
+ fConf.items = {};
41007
+ const items = groupSubsections(f[key], true);
41008
+ Object.keys(items).forEach(i => {
41009
+ items[i].show = filterForm(items[i], data);
41010
+ fConf.items[i] = items[i];
41011
+ });
41012
+ }
41013
+ return fConf;
41014
+ });
41015
+ React.useEffect(() => {
41016
+ const formG = mapFormGroup(form).sort((a, b) => (a.position || 0) - (b.position || 0));
41017
+ const keys = [];
41018
+ formG.forEach(f => {
41019
+ if (!keys.includes(f.key)) {
41020
+ keys.push(f.key);
41021
+ }
41022
+ if (f.items) {
41023
+ Object.keys(f.items).forEach(item => {
41024
+ if (!keys.includes(`${f.key}/${item}`)) {
41025
+ keys.push(`${f.key}/${item}`);
41026
+ }
41027
+ });
41028
+ }
41029
+ });
41030
+ let sGroup = group;
41031
+ if (!group && formG.length) {
41032
+ sGroup = formG[0].key;
41033
+ }
41034
+ if (subsection && keys.includes(`${sGroup}/${subsection}`)) {
41035
+ sGroup = `${sGroup}/${subsection}`;
41036
+ }
41037
+ if (sGroup === selectedGroup) {
41038
+ groupChanged();
41039
+ }
41040
+ setFormGroups(formG);
41041
+ if (!keys.includes(sGroup)) {
41042
+ sGroup = keys[0];
41043
+ }
41044
+ setSelectedGroup(sGroup);
41045
+ }, [form, group, subsection]);
41046
+ React.useEffect(() => {
41047
+ groupChanged();
41048
+ }, [selectedGroup]);
41049
+
41050
+ // useEffect(() => {
41051
+ // if (!selectedGroup && !formGroups.map(f => f.key).includes(selectedGroup)) {
41052
+ // setSelectedGroup(formGroups.map(f => f.key)[0]);
41053
+ // }
41054
+ // }, [formGroups])
41055
+
41056
+ const groupChanged = () => {
41057
+ if (selectedGroup) {
41058
+ onGroupChange(selectedGroup);
41059
+ if (selectedGroup !== group) {
41060
+ // const path = formPaths.view(mod, getRedirectLink);
41061
+ const [section, subSection, subgroup] = selectedGroup.split('/');
41062
+ let url;
41063
+ if (params.formId) {
41064
+ // Dynamic context (within a project : monitoring, restoration, engagement, etc.)
41065
+ url = `/app/${params.namespace}/${params.id}/${params.subsection}/view/general/${params.formId}/${section}`;
41066
+ } else {
41067
+ // Default: organisation context
41068
+ const path = formPaths.view(mod, getRedirectLink);
41069
+ url = `${generatePath(path, {
41070
+ ...params,
41071
+ group: section,
41072
+ subsection: subSection,
41073
+ subgroup: subgroup || undefined
41074
+ })}${search || ''}`;
41075
+ }
41076
+ goTo(url);
41077
+ }
41078
+ }
41079
+ setTimeout(() => {
41080
+ const groups = Array.from(document.getElementsByClassName('group'));
41081
+ const rows = Array.from(document.querySelectorAll('.repetable-row-extra'));
41082
+ rows.forEach(row => {
41083
+ const inputs = Array.from(row.querySelectorAll('.input'));
41084
+ const lasts = getLastRow(inputs.map((i, ind) => ind), 4);
41085
+ if (lasts) {
41086
+ lasts.forEach(index => inputs[index].classList.add('last'));
41087
+ }
41088
+ });
41089
+ groups.forEach(group => {
41090
+ // const isRepeatable = Array.from(group.classList).includes('repeatable');
41091
+ const inputs = Array.from(group.querySelectorAll('.input'));
41092
+ // if (inputs.length && !isRepeatable) {
41093
+ // if (inputs.length % 2 === 0) {
41094
+ // inputs[inputs.length - 1].classList.add('last');
41095
+ // inputs[inputs.length - 2].classList.add('last');
41096
+ // } else {
41097
+ // inputs[inputs.length - 1].classList.add('last');
41098
+ // }
41099
+ // }
41100
+ // remove groups without inputs
41101
+ if (!inputs.length) {
41102
+ group.remove();
41103
+ }
41104
+ });
41105
+ }, 200);
41106
+ };
41107
+ return selectedGroup ? /*#__PURE__*/jsxRuntime.jsx(antd.Menu, {
41108
+ mode: "inline",
41109
+ defaultSelectedKeys: [selectedGroup],
41110
+ selectedKeys: [selectedGroup],
41111
+ defaultOpenKeys: selectedGroup ? [selectedGroup.split('/')[0]] : [],
41112
+ openKeys: openKeys,
41113
+ onOpenChange: oKeys => {
41114
+ setOpenKeys(oKeys);
41115
+ },
41116
+ style: {
41117
+ overflowY: 'auto',
41118
+ overflowX: 'hidden'
41119
+ },
41120
+ onSelect: g => {
41121
+ setSelectedGroup(g.key);
41122
+ },
41123
+ children: formGroups.filter(key => key.show).map(key => key.items && typeof key.items === 'object' && Object.keys(key.items).length > 0 ? /*#__PURE__*/jsxRuntime.jsx(antd.Menu.SubMenu, {
41124
+ title: getInputLabel$2(key, data),
41125
+ children: Object.keys(key.items).filter(item => key.items[item].show).map(item => /*#__PURE__*/jsxRuntime.jsx(antd.Menu.Item, {
41126
+ level: 2,
41127
+ children: getInputLabel$2(key.items[item], data)
41128
+ }, `${key.key}/${item}`))
41129
+ }, key.key) : /*#__PURE__*/jsxRuntime.jsx(antd.Menu.Item, {
41130
+ disabled: key.disabled,
41131
+ onClick: props => {
41132
+ if (params.subgroup && params.group === props.key) {
41133
+ const path = formPaths.view(mod, getRedirectLink);
41134
+ goTo(`${generatePath(path, params)}${search || ''}`);
41135
+ }
41136
+ },
41137
+ children: getInputLabel$2(key, data)
41138
+ }, key.key))
41139
+ }) : null;
41140
+ };
39955
41141
 
39956
41142
  styled__default["default"](antd.Select)`
39957
41143
  width: 100%;
@@ -42770,6 +43956,7 @@ const PlantingLocations = ({
42770
43956
  longitude: locationCheckArrival.longitude
42771
43957
  };
42772
43958
  const color = "#15FFFFB2";
43959
+ const locationName = matchingLocation?.name || locationCheckArrival.name || 'Planting Location';
42773
43960
  return {
42774
43961
  _id: locationCheckArrival._id || event._id || {},
42775
43962
  area: area,
@@ -42777,13 +43964,16 @@ const PlantingLocations = ({
42777
43964
  datastakeId: `LOC-${String(index + 1).padStart(9, '0')}`,
42778
43965
  gps: gps,
42779
43966
  id: matchingLocation?.id || locationCheckArrival._id || `event-${index}`,
42780
- name: locationCheckArrival.name || matchingLocation?.name || `Event ${index + 1}`,
43967
+ name: event.name || t("Activity Start"),
43968
+ date: event.date,
42781
43969
  sources: 1,
42782
- subTitle: locationCheckArrival.name || matchingLocation?.name || 'Planting Location',
43970
+ subTitle: event.date ? renderDateFormatted(event.date, "DD MMM YY") : locationName,
43971
+ plotName: locationName,
43972
+ territoryTitle: locationName,
42783
43973
  type: 'Planting Location'
42784
43974
  };
42785
43975
  });
42786
- }, [plantingLocationsData]);
43976
+ }, [plantingLocationsData, t]);
42787
43977
  return /*#__PURE__*/jsxRuntime.jsx("section", {
42788
43978
  children: /*#__PURE__*/jsxRuntime.jsx(Widget, {
42789
43979
  title: t("Planting Locations"),
@@ -42805,7 +43995,66 @@ const PlantingLocations = ({
42805
43995
  onClickLink: () => {},
42806
43996
  onFilterChange: () => {},
42807
43997
  primaryLink: true,
42808
- renderTooltip: () => {},
43998
+ renderTooltipForLocation: data => {
43999
+ const coordinates = data.gps?.latitude && data.gps?.longitude ? convertDMS(data.gps.latitude, data.gps.longitude) : null;
44000
+ if (!coordinates) {
44001
+ return [];
44002
+ }
44003
+ const iconColor = "#016C6E"; // Activity Start color
44004
+
44005
+ return [{
44006
+ label: t("Coordinates"),
44007
+ value: /*#__PURE__*/jsxRuntime.jsxs("div", {
44008
+ style: {
44009
+ display: 'flex',
44010
+ alignItems: 'center',
44011
+ gap: '6px',
44012
+ flexWrap: 'nowrap'
44013
+ },
44014
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
44015
+ style: {
44016
+ display: 'flex',
44017
+ alignItems: 'center'
44018
+ },
44019
+ children: [/*#__PURE__*/jsxRuntime.jsx(CustomIcon, {
44020
+ name: "SpacingHeight",
44021
+ width: 14,
44022
+ height: 14,
44023
+ color: iconColor
44024
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
44025
+ style: {
44026
+ fontWeight: 600,
44027
+ marginLeft: '4px'
44028
+ },
44029
+ children: coordinates[0]
44030
+ })]
44031
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
44032
+ style: {
44033
+ display: 'flex',
44034
+ alignItems: 'center'
44035
+ },
44036
+ children: [/*#__PURE__*/jsxRuntime.jsx(CustomIcon, {
44037
+ name: "SpacingWidth",
44038
+ width: 14,
44039
+ height: 14,
44040
+ color: iconColor
44041
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
44042
+ style: {
44043
+ fontWeight: 600,
44044
+ marginLeft: '4px'
44045
+ },
44046
+ children: coordinates[1]
44047
+ })]
44048
+ })]
44049
+ })
44050
+ }];
44051
+ },
44052
+ renderTooltipForTerritory: data => {
44053
+ return [{
44054
+ label: t("Plot Name"),
44055
+ value: data.plotName || data.name || "--"
44056
+ }];
44057
+ },
42809
44058
  renderTooltipTags: () => {},
42810
44059
  type: "location-territory"
42811
44060
  })
@@ -44839,9 +46088,10 @@ const getColumns = ({
44839
46088
  className: "daf-default-cell"
44840
46089
  });
44841
46090
  }
46091
+ const title = findOptions(value, selectOptions?.implPartnersCategory || []) || '-';
44842
46092
  return /*#__PURE__*/jsxRuntime.jsx(antd.Tooltip, {
44843
- title: value,
44844
- children: value || '-'
46093
+ title: title,
46094
+ children: title
44845
46095
  });
44846
46096
  }
44847
46097
  }, {
@@ -44855,9 +46105,10 @@ const getColumns = ({
44855
46105
  className: "daf-default-cell"
44856
46106
  });
44857
46107
  }
46108
+ const title = findOptions(value, selectOptions?.implPartnersSubcategory || []) || '-';
44858
46109
  return /*#__PURE__*/jsxRuntime.jsx(antd.Tooltip, {
44859
- title: value,
44860
- children: value || '-'
46110
+ title: title,
46111
+ children: title
44861
46112
  });
44862
46113
  }
44863
46114
  }, {
@@ -45847,6 +47098,639 @@ const MineSummary = ({
45847
47098
  });
45848
47099
  };
45849
47100
 
47101
+ const useViewUrlParams = ({
47102
+ params,
47103
+ push,
47104
+ pathname,
47105
+ search,
47106
+ searchParams,
47107
+ setSearchParams
47108
+ }) => {
47109
+ const [namespace, setNamespace] = React.useState(params?.namespace);
47110
+ const [id, setId] = React.useState(params?.id);
47111
+ const [group, setGroup] = React.useState(params?.group);
47112
+ const [subsection, setSubSection] = React.useState(params?.subsection);
47113
+ const sourceUrl = searchParams.get("source");
47114
+ const versionUrl = searchParams.get("version");
47115
+ const [source, setSource] = React.useState(sourceUrl || null);
47116
+ const [version, setVersion] = React.useState(versionUrl || null);
47117
+ React.useEffect(() => {
47118
+ if (id && params.id !== id || namespace && namespace !== params.namespace) {
47119
+ setGroup(undefined);
47120
+ setSubSection(undefined);
47121
+ // setSubGroup(undefined);
47122
+ } else {
47123
+ setGroup(params.group);
47124
+ setSubSection(params.subsection);
47125
+ // setSubGroup(params.subgroup);
47126
+ }
47127
+ setNamespace(params.namespace);
47128
+ setId(params.id);
47129
+ }, [params]);
47130
+ React.useEffect(() => {
47131
+ if (source && version) {
47132
+ const newParams = new URLSearchParams(searchParams);
47133
+ newParams.set("source", source);
47134
+ newParams.set("version", version);
47135
+ setSearchParams(newParams);
47136
+ }
47137
+ }, [source, version]);
47138
+ const goBackFromSource = React.useCallback(() => {
47139
+ const params = new URLSearchParams(searchParams);
47140
+ params.delete("source");
47141
+ params.delete("version");
47142
+ setSearchParams(params);
47143
+ setVersion(null);
47144
+ setSource(null);
47145
+ }, [searchParams, setSearchParams]);
47146
+ const getEditLink = React.useCallback(srcId => {
47147
+ const r = new RegExp(`\/view\/`);
47148
+ const [previous, extra] = pathname.split(r);
47149
+ if (srcId) {
47150
+ push(`${previous}/edit/${extra}?sourceId=${srcId}`);
47151
+ return;
47152
+ }
47153
+ if (search) {
47154
+ push(`${previous}/edit/${extra}${search}`);
47155
+ } else {
47156
+ push(`${previous}/edit/${extra}`);
47157
+ }
47158
+ }, [pathname, search, push]);
47159
+ const match = React.useMemo(() => ({
47160
+ params,
47161
+ path: pathname
47162
+ }), [params, pathname]);
47163
+ return {
47164
+ namespace,
47165
+ id,
47166
+ group,
47167
+ subsection,
47168
+ params,
47169
+ source,
47170
+ setSource,
47171
+ sourceUrl,
47172
+ version,
47173
+ setVersion,
47174
+ versionUrl,
47175
+ goBackFromSource,
47176
+ getEditLink,
47177
+ match,
47178
+ search
47179
+ };
47180
+ };
47181
+
47182
+ const usePrepareForm = ({
47183
+ namespaceConfig,
47184
+ allData,
47185
+ id,
47186
+ namespace,
47187
+ t,
47188
+ mode,
47189
+ APP,
47190
+ viewConfig
47191
+ }) => {
47192
+ const [form, setForm] = React.useState({});
47193
+ const [data, setData] = React.useState({});
47194
+ const [groups, setGroups] = React.useState({});
47195
+ const [linkingForms, setLinkingForms] = React.useState({});
47196
+ const [loading, setLoading] = React.useState(true);
47197
+ const [notFound, setNotFound] = React.useState(false);
47198
+ const prepareForm = currentView => {
47199
+ const dKey = namespaceConfig.dataKey;
47200
+ const nKey = `${APP}-${currentView}`;
47201
+ if (hasKeyInObject(allData, dKey) && hasKeyInObject(allData[dKey], nKey)) {
47202
+ const {
47203
+ form = {},
47204
+ data = {},
47205
+ config = {},
47206
+ linkingForms = {}
47207
+ } = JSON.parse(JSON.stringify(allData[dKey][nKey] || {}));
47208
+ if (data.datastakeId === id || id === "user") {
47209
+ if (viewConfig.linkingSubjects.includes(namespace)) {
47210
+ setForm({
47211
+ ...form,
47212
+ linking: {
47213
+ position: 100,
47214
+ excludeFromEdit: true,
47215
+ label: t("Linked Subjects"),
47216
+ template: "linkingSubjects"
47217
+ }
47218
+ });
47219
+ } else {
47220
+ setForm(form);
47221
+ }
47222
+ setData(data);
47223
+ setGroups(config.groups || {});
47224
+ setLinkingForms(linkingForms);
47225
+ setLoading(false);
47226
+ setNotFound(false);
47227
+ } else if (!data.id) {
47228
+ if (mode === "proxy") {
47229
+ window.location.reload();
47230
+ } else {
47231
+ setLoading(false);
47232
+ setNotFound(true);
47233
+ }
47234
+ }
47235
+ }
47236
+ };
47237
+ const getCertainData = allData[namespaceConfig.dataKey];
47238
+ React.useEffect(() => {
47239
+ if (namespace && namespaceConfig) {
47240
+ prepareForm(namespaceConfig.view);
47241
+ }
47242
+ }, [getCertainData, namespaceConfig]);
47243
+ return {
47244
+ form,
47245
+ setForm,
47246
+ data,
47247
+ setData,
47248
+ groups,
47249
+ setGroups,
47250
+ linkingForms,
47251
+ setLinkingForms,
47252
+ loading,
47253
+ setLoading,
47254
+ notFound,
47255
+ setNotFound,
47256
+ prepareForm
47257
+ };
47258
+ };
47259
+
47260
+ const useViewPermissions = ({
47261
+ data,
47262
+ id,
47263
+ namespaceOverrides = {
47264
+ supportedNamespaces: {},
47265
+ canEdit: {}
47266
+ },
47267
+ namespace,
47268
+ user,
47269
+ push,
47270
+ getRedirectLink,
47271
+ namespaceConfig,
47272
+ APP,
47273
+ viewConfig
47274
+ }) => {
47275
+ const baseNamespaceKeys = Object.keys(namespaceConfig);
47276
+ const baseSupportedNamespaces = baseNamespaceKeys.reduce((acc, key) => {
47277
+ acc[key] = () => true;
47278
+ return acc;
47279
+ }, {});
47280
+ const isSupportedNamespaces = React.useMemo(() => ({
47281
+ ...baseSupportedNamespaces,
47282
+ ...namespaceOverrides.supportedNamespaces
47283
+ }), [data, id]);
47284
+ const isSupported = typeof isSupportedNamespaces[namespace] === "function" ? isSupportedNamespaces[namespace]() && viewConfig.supportedNamespaces[APP] && namespaceConfig.supportedNamespaces[APP].includes(namespace) : namespaceConfig.supportedNamespaces[APP] && namespaceConfig.supportedNamespaces[APP].includes(namespace);
47285
+ const isUserData = () => {
47286
+ return data && data.authorId && user?.company?.id === data.authorId;
47287
+ };
47288
+ const canEdit = React.useMemo(() => {
47289
+ const baseCanEditAction = baseNamespaceKeys.reduce((acc, key) => {
47290
+ acc[key] = () => isUserData();
47291
+ return acc;
47292
+ }, {});
47293
+ const canEditAction = {
47294
+ ...baseCanEditAction,
47295
+ ...namespaceOverrides.canEdit
47296
+ };
47297
+ return canEditAction[namespace] ? canEditAction[namespace]() : false;
47298
+ }, [namespace, data, user]);
47299
+ React.useEffect(() => {
47300
+ if (data) {
47301
+ if (typeof isSupportedNamespaces[namespace] === "function") {
47302
+ if (!isSupportedNamespaces[namespace]()) {
47303
+ push(getRedirectLink(`/app`));
47304
+ }
47305
+ }
47306
+ }
47307
+ }, [data, namespace]);
47308
+ return {
47309
+ isSupportedNamespaces,
47310
+ canEdit,
47311
+ isSupported
47312
+ };
47313
+ };
47314
+
47315
+ const submitSubjectData = async (namespace, data, serviceMap) => {
47316
+ const service = serviceMap[namespace];
47317
+ if (!service) {
47318
+ throw new Error(`No service found for namespace: ${namespace}`);
47319
+ }
47320
+ const response = await service.submitStep(data, data.datastakeId || data.id);
47321
+ return response.data;
47322
+ };
47323
+ const useSubmitSubject = ({
47324
+ namespace,
47325
+ data,
47326
+ serviceMap
47327
+ }) => {
47328
+ const [isDisabled, setIsDisabled] = React.useState(false);
47329
+ const [loading, setLoading] = React.useState(false);
47330
+ const [isPublished, setIsPublished] = React.useState(false);
47331
+ const submitSubject = React.useCallback(async () => {
47332
+ try {
47333
+ setLoading(true);
47334
+ const response = await submitSubjectData(namespace, data, serviceMap);
47335
+ setIsDisabled(response.published);
47336
+ setIsPublished(response.published);
47337
+ } catch (error) {
47338
+ console.error("Submit error:", error);
47339
+ } finally {
47340
+ setLoading(false);
47341
+ }
47342
+ }, [namespace, data]);
47343
+ return {
47344
+ submitSubject,
47345
+ isDisabled,
47346
+ submitLoading: loading,
47347
+ isPublished
47348
+ };
47349
+ };
47350
+
47351
+ const useCallToGetData = ({
47352
+ namespaceConfig,
47353
+ namespace,
47354
+ allData,
47355
+ id,
47356
+ isSupported,
47357
+ namespaceGet,
47358
+ source,
47359
+ version,
47360
+ user,
47361
+ setLoading,
47362
+ APP
47363
+ }) => {
47364
+ const isFirstRender = React.useRef(true);
47365
+ const callToGetData = (_doCall = false) => {
47366
+ const dKey = namespaceConfig.dataKey;
47367
+ const nKey = `${APP}-${getNkey(namespace)}`;
47368
+ const doCall = _doCall ? true : hasKeyInObject(allData, dKey) && hasKeyInObject(allData[dKey], nKey) ? allData[dKey][nKey]?.data?.datastakeId !== id : true;
47369
+ if (doCall) {
47370
+ if (isSupported) {
47371
+ namespaceGet[namespace]();
47372
+ }
47373
+ }
47374
+ };
47375
+ React.useEffect(() => {
47376
+ if (isFirstRender.current) {
47377
+ isFirstRender.current = false;
47378
+ return;
47379
+ }
47380
+ callToGetData(true);
47381
+ }, [source, version]);
47382
+ React.useEffect(() => {
47383
+ callToGetData(true);
47384
+ }, [id, namespace, user.language]);
47385
+ const onStorageUpdate = e => {
47386
+ const {
47387
+ key,
47388
+ newValue
47389
+ } = e;
47390
+ if (key === `${id}-loading` && newValue) {
47391
+ setLoading(newValue);
47392
+ }
47393
+ if (key === `${id}-updated` && newValue) {
47394
+ setLoading(true);
47395
+ callToGetData();
47396
+ }
47397
+ };
47398
+ React.useEffect(() => {
47399
+ window.addEventListener("storage", onStorageUpdate);
47400
+ return () => {
47401
+ window.removeEventListener("storage", onStorageUpdate);
47402
+ };
47403
+ }, []);
47404
+ React.useEffect(() => {
47405
+ setLoading(true);
47406
+ }, [namespace]);
47407
+ return {
47408
+ callToGetData
47409
+ };
47410
+ };
47411
+
47412
+ const useViewActions = ({
47413
+ namespace,
47414
+ data,
47415
+ isSupported,
47416
+ canEdit,
47417
+ versionUrl,
47418
+ sourceUrl,
47419
+ getEditLink,
47420
+ submitSubject,
47421
+ isDisabled,
47422
+ setOpenRecordsModal,
47423
+ goBackFromSource,
47424
+ push,
47425
+ getRedirectLink,
47426
+ t,
47427
+ viewConfig,
47428
+ buttonActions
47429
+ }) => {
47430
+ const [pageActions, setPageActions] = React.useState([]);
47431
+ const [extraPageActions, setExtraPageActions] = React.useState([]);
47432
+ React.useEffect(() => {
47433
+ const actions = [];
47434
+ const extraActions = [];
47435
+ if (!isSupported) {
47436
+ setPageActions([]);
47437
+ setExtraPageActions([]);
47438
+ return;
47439
+ }
47440
+ if (canEdit) {
47441
+ if (viewConfig.namespacesWithoutActionButtons.includes(namespace)) {
47442
+ if (viewConfig.editOnlyButton.includes(namespace)) {
47443
+ if (versionUrl && sourceUrl) {
47444
+ actions.push(buttonActions.createBackButton(t, goBackFromSource));
47445
+ } else {
47446
+ actions.push(buttonActions.createEditButton(t, getEditLink));
47447
+ }
47448
+ }
47449
+ } else {
47450
+ if (versionUrl && sourceUrl) {
47451
+ actions.push(buttonActions.createBackButton(t, goBackFromSource));
47452
+ } else {
47453
+ actions.push(buttonActions.createSubmitButton(t, submitSubject, isDisabled, data));
47454
+ actions.push(buttonActions.createEditButton(t, getEditLink));
47455
+ // actions.push(createRecordsButton(t, setOpenRecordsModal));
47456
+ }
47457
+ }
47458
+ }
47459
+ if (viewConfig.summaryNamespaces.includes(namespace)) {
47460
+ extraActions.push(buttonActions.createSummaryButton(t, namespace, data, push, getRedirectLink));
47461
+ extraActions.push(buttonActions.createRecordsButton(t, setOpenRecordsModal));
47462
+ }
47463
+ setPageActions(actions);
47464
+ setExtraPageActions(extraActions);
47465
+ }, [namespace, data, isSupported, canEdit, versionUrl, sourceUrl, isDisabled, t, getEditLink, submitSubject, goBackFromSource, setOpenRecordsModal, push, getRedirectLink]);
47466
+ return {
47467
+ pageActions,
47468
+ extraPageActions
47469
+ };
47470
+ };
47471
+
47472
+ const View = ({
47473
+ push,
47474
+ getRedirectLink,
47475
+ allData,
47476
+ ajaxForms,
47477
+ changeAjaxForms,
47478
+ t,
47479
+ namespaceConfiguaration,
47480
+ params,
47481
+ pathname,
47482
+ search,
47483
+ searchParams,
47484
+ setSearchParams,
47485
+ mode = "app",
47486
+ APP,
47487
+ viewConfig,
47488
+ partners,
47489
+ setSelectedPartners,
47490
+ user,
47491
+ serviceMap,
47492
+ actionMap,
47493
+ goBack,
47494
+ breadcrumbs,
47495
+ theme,
47496
+ buttonActions,
47497
+ generatePath,
47498
+ getApiBaseUrl,
47499
+ getAppHeader
47500
+ // ADD CALLBACK TO GET THE CURRENT NAMESPACE CONFIG
47501
+ }) => {
47502
+ const getNamespaceConfig = namespace => namespaceConfiguaration[namespace];
47503
+ const [openRecordsModal, setOpenRecordsModal] = React.useState(false);
47504
+
47505
+ // HANDLES THE URL PARAMS FOR THE VIEW PAGE
47506
+ const {
47507
+ namespace,
47508
+ id,
47509
+ group,
47510
+ subsection,
47511
+ source,
47512
+ setSource,
47513
+ sourceUrl,
47514
+ version,
47515
+ setVersion,
47516
+ versionUrl,
47517
+ goBackFromSource,
47518
+ getEditLink,
47519
+ match
47520
+ } = useViewUrlParams({
47521
+ params,
47522
+ push,
47523
+ pathname,
47524
+ search,
47525
+ searchParams,
47526
+ setSearchParams
47527
+ });
47528
+ const namespaceConfig = React.useMemo(() => getNamespaceConfig(namespace), [namespace]);
47529
+
47530
+ // PREPARES THE FORM FOR THE VIEW PAGE
47531
+ const {
47532
+ form,
47533
+ data,
47534
+ groups,
47535
+ linkingForms,
47536
+ loading,
47537
+ setLoading,
47538
+ notFound
47539
+ } = usePrepareForm({
47540
+ namespaceConfig,
47541
+ allData,
47542
+ id,
47543
+ namespace,
47544
+ t,
47545
+ mode,
47546
+ APP,
47547
+ viewConfig
47548
+ });
47549
+ const {
47550
+ canEdit,
47551
+ isSupported
47552
+ } = useViewPermissions({
47553
+ data,
47554
+ id,
47555
+ namespace,
47556
+ user,
47557
+ push,
47558
+ getRedirectLink,
47559
+ namespaceConfig: namespaceConfiguaration,
47560
+ APP,
47561
+ viewConfig
47562
+ });
47563
+ const groupForm = React.useMemo(() => {
47564
+ const gF = form[group] || {};
47565
+ if (subsection) {
47566
+ const sectionForms = groupSubsections(gF);
47567
+ if (sectionForms[subsection]) {
47568
+ return sectionForms[subsection];
47569
+ }
47570
+ }
47571
+ return gF;
47572
+ }, [form, group, subsection]);
47573
+ const {
47574
+ submitSubject,
47575
+ isDisabled,
47576
+ submitLoading,
47577
+ isPublished
47578
+ } = useSubmitSubject({
47579
+ namespace,
47580
+ data,
47581
+ serviceMap
47582
+ });
47583
+ const {
47584
+ pageActions,
47585
+ extraPageActions
47586
+ } = useViewActions({
47587
+ namespace,
47588
+ data,
47589
+ isSupported,
47590
+ canEdit,
47591
+ versionUrl,
47592
+ sourceUrl,
47593
+ getEditLink,
47594
+ submitSubject,
47595
+ isDisabled,
47596
+ setOpenRecordsModal,
47597
+ goBackFromSource,
47598
+ push,
47599
+ getRedirectLink,
47600
+ t,
47601
+ viewConfig,
47602
+ buttonActions
47603
+ });
47604
+ const action = React.useMemo(() => actionMap[namespaceConfig?.action], [namespaceConfig?.action]);
47605
+ const namespaceGet = {
47606
+ [namespace]: () => {
47607
+ return action({
47608
+ namespace: namespaceConfig.namespace,
47609
+ module: APP,
47610
+ view: namespaceConfig.view,
47611
+ ...(namespaceConfig.scope && {
47612
+ scope: namespaceConfig.scope
47613
+ }),
47614
+ datastakeId: id,
47615
+ version,
47616
+ source
47617
+ });
47618
+ }
47619
+ };
47620
+ useCallToGetData({
47621
+ namespaceConfig,
47622
+ namespace,
47623
+ allData,
47624
+ id,
47625
+ isSupported,
47626
+ namespaceGet,
47627
+ source,
47628
+ version,
47629
+ user,
47630
+ setLoading
47631
+ });
47632
+ const extraLinking = React.useMemo(() => {
47633
+ return null;
47634
+ }, [namespace, match, data]);
47635
+ const sourceOptions = React.useMemo(() => {
47636
+ return partners.map(partner => {
47637
+ const isOwnData = partner.id === user?.company?.id;
47638
+ return {
47639
+ label: partner.nickName,
47640
+ value: partner.id,
47641
+ avatar: isOwnData ? /*#__PURE__*/jsxRuntime.jsx("span", {
47642
+ children: "OWN"
47643
+ }) : undefined,
47644
+ background: isOwnData ? theme.colorPrimary7 : undefined,
47645
+ color: isOwnData ? "white" : undefined
47646
+ };
47647
+ });
47648
+ }, [partners, user]);
47649
+ const actionButtons = React.useMemo(() => {
47650
+ return groupForm?.template === "linkingSubjects" ? pageActions.filter(v => v.key !== "edit") : pageActions;
47651
+ }, [groupForm, pageActions]);
47652
+ if (!isSupported || notFound || loading) {
47653
+ return /*#__PURE__*/jsxRuntime.jsx(Loading, {});
47654
+ }
47655
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
47656
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
47657
+ className: "daf-view-form",
47658
+ children: [/*#__PURE__*/jsxRuntime.jsx(DAFHeader, {
47659
+ title: data?.name || "",
47660
+ breadcrumbs: breadcrumbs,
47661
+ goBackTo: goBack,
47662
+ actionButtons: actionButtons,
47663
+ extraButtons: extraPageActions,
47664
+ addedHeaderFirst: true,
47665
+ addedHeader: /*#__PURE__*/jsxRuntime.jsx("div", {
47666
+ className: "flex flex-row gap-4",
47667
+ style: {
47668
+ marginRight: 8
47669
+ },
47670
+ children: /*#__PURE__*/jsxRuntime.jsx(Multiselect, {
47671
+ options: [...sourceOptions],
47672
+ isAvatarGroup: true,
47673
+ selectionType: "checkbox",
47674
+ canUnselectLast: false,
47675
+ onChange: selected => {
47676
+ setSelectedPartners(prev => ({
47677
+ ...prev,
47678
+ partners: selected,
47679
+ loading: false
47680
+ }));
47681
+ },
47682
+ dropDownWidth: 200,
47683
+ defaultSelected: (partners || []).map(p => p.id) || []
47684
+ }, partners?.length)
47685
+ })
47686
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
47687
+ className: "view-content",
47688
+ children: [/*#__PURE__*/jsxRuntime.jsx(Navigation, {
47689
+ mod: APP,
47690
+ data: data,
47691
+ match: match,
47692
+ form: form,
47693
+ group: group,
47694
+ subsection: subsection,
47695
+ search: search,
47696
+ goTo: push,
47697
+ getRedirectLink: getRedirectLink,
47698
+ generatePath: generatePath,
47699
+ params: params
47700
+ }), groupForm.template ? /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {}) : /*#__PURE__*/jsxRuntime.jsx(Content, {
47701
+ form: groupForm,
47702
+ data: data || {},
47703
+ groupConfig: groups || {},
47704
+ linkingData: (data || {}).linking || {},
47705
+ linkingForms: linkingForms || {},
47706
+ ajaxOptions: [],
47707
+ extraLinking: extraLinking,
47708
+ t: t,
47709
+ app: APP,
47710
+ ajaxForms: ajaxForms,
47711
+ language: user?.language,
47712
+ changeAjaxForms: changeAjaxForms,
47713
+ getApiBaseUrl: getApiBaseUrl,
47714
+ getAppHeader: getAppHeader,
47715
+ user: user
47716
+ })]
47717
+ })]
47718
+ }), openRecordsModal && /*#__PURE__*/jsxRuntime.jsx(Records, {
47719
+ open: openRecordsModal,
47720
+ onClose: () => setOpenRecordsModal(false),
47721
+ t: t,
47722
+ sourceOptions: [],
47723
+ versionOptions: [],
47724
+ id: params?.id,
47725
+ subject: namespace,
47726
+ onSubmit: values => {
47727
+ setSource(values?.source);
47728
+ setVersion(values?.version);
47729
+ }
47730
+ })]
47731
+ });
47732
+ };
47733
+
45850
47734
  exports.ActivitiesTable = ActivitiesTable;
45851
47735
  exports.DocumentsTable = DocumentsTable;
45852
47736
  exports.EventsTable = EventsTable;
@@ -45864,4 +47748,5 @@ exports.SupplyChainDashboard = SupplyChain;
45864
47748
  exports.TablePage = TablePage;
45865
47749
  exports.UserDashboard = UserDashboard;
45866
47750
  exports.UsersTable = UsersTable;
47751
+ exports.View = View;
45867
47752
  exports.WorkersTable = WorkersTable;