datastake-daf 0.6.782 → 0.6.783

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.
@@ -4794,6 +4794,7 @@ function Loading({
4794
4794
  }
4795
4795
 
4796
4796
  const capitalize = string => string && string.charAt(0).toUpperCase() + string.slice(1);
4797
+ const capitalizeAll = string => string && string.split(" ").map(word => word.length > 1 ? capitalize(word) : word).join(" ");
4797
4798
  const camelCaseToTitle = string => string && typeof string === 'string' ? string.split(/(?=[A-Z])/).map(word => capitalize(word)).join(' ') : string;
4798
4799
  const findOptions = (value, options) => {
4799
4800
  if (value instanceof Array) {
@@ -5295,6 +5296,12 @@ const createNumberArray = i => {
5295
5296
  return numbers;
5296
5297
  };
5297
5298
  const tooltipInputs = ["text", "phoneNumber", "textarea", "percentage", "number", "select", "ajaxSelect", "switch", "multiselect", "radioGroup", "date", "year"];
5299
+ const formPaths = {
5300
+ edit: (mod, getRedirectLink) => typeof getRedirectLink === "function" ? getRedirectLink(`/app/edit/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`) : `/app/${mod}/edit/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`,
5301
+ view: (mod, getRedirectLink) => typeof getRedirectLink === "function" ? getRedirectLink(`/app/view/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`) : `/app/${mod}/view/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`,
5302
+ viewDD: mod => `/app/${mod}/viewdd/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`,
5303
+ editDD: mod => `/app/${mod}/editdd/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`
5304
+ };
5298
5305
  const CREATE_DRAWER_WIDTH = 480;
5299
5306
  const MAX_COMMENTS_LENGTH = 1200;
5300
5307
  const MAX_TEXT_AREA_LENGTH = 1200;
@@ -5401,6 +5408,44 @@ const getImageUploadEditValue = value => {
5401
5408
  return (Array.isArray(value) ? value : value && typeof value === "object" && value.fileList && Array.isArray(value.fileList) ? value.fileList.map(f => f.response).filter(f => f) : []) || [];
5402
5409
  };
5403
5410
  const noActionsInputs = ["groupExpandable", "groupCheckbox", "smartHelp"];
5411
+ const isObjectEmpty = obj => {
5412
+ if (obj === null || typeof obj !== "object") {
5413
+ return false;
5414
+ }
5415
+ if (Object.keys(obj).length === 0) {
5416
+ return true;
5417
+ }
5418
+ return Object.values(obj).every(value => isObjectEmpty(value));
5419
+ };
5420
+
5421
+ /**
5422
+ * Filters and processes the input data by extracting specific properties.
5423
+ * It checks if the 'meta' property is empty and sets it to undefined if so,
5424
+ * then returns the rest of the data merged with the processed 'meta'. Used to clear data
5425
+ * when they are sent to backend.
5426
+ *
5427
+ * @param {Object} data - The input data object containing various properties.
5428
+ * @returns {Object} - The processed data object with filtered properties.
5429
+ */
5430
+
5431
+ const filterCreateData = data => {
5432
+ // eslint-disable-next-line no-unused-vars
5433
+ const {
5434
+ view,
5435
+ module,
5436
+ scope,
5437
+ form,
5438
+ meta,
5439
+ createdAt,
5440
+ updatedAt,
5441
+ ...rest
5442
+ } = data;
5443
+ const _meta = isObjectEmpty(meta) ? undefined : meta;
5444
+ return {
5445
+ ...rest,
5446
+ meta: _meta
5447
+ };
5448
+ };
5404
5449
 
5405
5450
  /**
5406
5451
  * Formats a date string into a specified format. This function should
@@ -7570,6 +7615,8 @@ const Style$f = styled__default["default"].div`
7570
7615
  width: 100%;
7571
7616
  height: 472px;
7572
7617
 
7618
+
7619
+
7573
7620
  .filter-cont {
7574
7621
  position: absolute;
7575
7622
  top: 24px;
@@ -7672,11 +7719,24 @@ const Style$f = styled__default["default"].div`
7672
7719
  align-items: center;
7673
7720
  }
7674
7721
 
7675
- .marker-chain {
7676
- display: flex;
7677
- align-items: center;
7678
- justify-content: center;
7679
- }
7722
+ .marker-chain {
7723
+ display: flex;
7724
+ align-items: center;
7725
+ justify-content: center;
7726
+ }
7727
+
7728
+ .animated-polyline {
7729
+ stroke-dasharray: 10 10;
7730
+ animation: dash-flow 1.5s linear infinite;
7731
+ stroke-linecap: round;
7732
+ }
7733
+
7734
+ @keyframes dash-flow {
7735
+ to {
7736
+ stroke-dashoffset: -20;
7737
+ }
7738
+ }
7739
+
7680
7740
 
7681
7741
  }
7682
7742
 
@@ -8200,18 +8260,15 @@ const VILLAGE = "village";
8200
8260
  const EXPORTER = "exporter";
8201
8261
  const PROCESSOR = "mineralProcessor";
8202
8262
  const DEPOT = "depot";
8263
+ const OPERATOR = "miningOperator";
8203
8264
  const MAX_EXTRA_SMALL_ZOOM_THRESHOLD = 2;
8204
8265
  const MAX_SMALL_ZOOM_THRESHOLD = 3;
8205
8266
  const MAX_MEDIUM_ZOOM_THRESHOLD = 6;
8206
8267
  const LOCATION_TYPES = [MINE_SITE, VILLAGE];
8207
- const STAKEHOLDER_TYPES = [EXPORTER, PROCESSOR, DEPOT];
8268
+ const STAKEHOLDER_TYPES = [EXPORTER, PROCESSOR, DEPOT, OPERATOR];
8208
8269
  const RADIUS_SMALL = 15;
8209
8270
  const RADIUS_MEDIUM = 35;
8210
8271
  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
8272
  function isLocation(type) {
8216
8273
  return LOCATION_TYPES.includes(type);
8217
8274
  }
@@ -8268,7 +8325,6 @@ function getStakeholderPosition({
8268
8325
  const isLarge = isLargeMarker(zoom);
8269
8326
  let radius;
8270
8327
  let center = {
8271
- // NOT BEING USED FOR NOW AND MAYBE NEVER
8272
8328
  left: 0,
8273
8329
  top: 0
8274
8330
  };
@@ -8292,6 +8348,25 @@ function getStakeholderPosition({
8292
8348
  angleDeg
8293
8349
  };
8294
8350
  }
8351
+ function applyAnimationDirect(el, isShortLink) {
8352
+ if (!(el instanceof SVGElement) || isShortLink) return;
8353
+ el.style.strokeDasharray = "10, 10";
8354
+ el.style.strokeDashoffset = "0";
8355
+ el.style.animation = "dash-flow 1.2s linear infinite";
8356
+ el.classList.add('animated-polyline');
8357
+ }
8358
+ function removeAnimationFromElement(element) {
8359
+ if (!element) return;
8360
+ element.classList.remove('animated-polyline');
8361
+ element.style.animation = '';
8362
+ element.style.strokeDasharray = '';
8363
+ }
8364
+ function applyAnimationToPolyline(polyline, isShortLink) {
8365
+ const element = polyline.getElement();
8366
+ if (element) {
8367
+ applyAnimationDirect(element, isShortLink);
8368
+ }
8369
+ }
8295
8370
  function createPolyline({
8296
8371
  L,
8297
8372
  startLatLng,
@@ -8301,109 +8376,47 @@ function createPolyline({
8301
8376
  zoom,
8302
8377
  listOfPolylines = [],
8303
8378
  isFromStakeholder = false,
8304
- isForceOpen = false
8379
+ isForceOpen = false,
8380
+ stakeholderType = null,
8381
+ animated = false,
8382
+ mapRef
8305
8383
  }) {
8306
- const width = isFromStakeholder && isExtraSmallMarker(zoom) && !isForceOpen ? 0 : 1.2;
8307
- const coordinates = [[startLatLng.lat, startLatLng.lng], [endLatLng.lat, endLatLng.lng]];
8308
- const style = {
8384
+ const lineWidth = isFromStakeholder && isExtraSmallMarker(zoom) && !isForceOpen ? 0 : 1.2;
8385
+ const isShortLink = stakeholderType === OPERATOR || isFromStakeholder;
8386
+ const shouldAnimate = animated;
8387
+ const lineCoordinates = [[startLatLng.lat, startLatLng.lng], [endLatLng.lat, endLatLng.lng]];
8388
+ const polylineStyle = {
8309
8389
  color: "var(--base-gray-70)",
8310
- weight: width,
8311
- opacity: 0.5,
8312
- smoothFactor: 1,
8390
+ weight: lineWidth,
8391
+ opacity: isSelected ? 1 : 0.5,
8392
+ smoothFactor: 0,
8313
8393
  id,
8314
- dashArray: !isSelected ? "5, 5" : "0, 0"
8394
+ dashArray: isShortLink ? "0, 0" : shouldAnimate ? "10, 10" : !isSelected ? "5, 5" : "10, 10",
8395
+ renderer: L.svg()
8315
8396
  };
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);
8397
+ const existingPolyline = listOfPolylines.find(p => p.options.id === id);
8398
+ if (existingPolyline) {
8399
+ removeAnimationFromElement(existingPolyline.getElement());
8400
+ existingPolyline.setLatLngs(lineCoordinates);
8401
+ existingPolyline.setStyle(polylineStyle);
8402
+ if (shouldAnimate && isSelected) {
8403
+ existingPolyline.once('add', () => {
8404
+ applyAnimationToPolyline(existingPolyline, isShortLink);
8405
+ });
8406
+ applyAnimationToPolyline(existingPolyline, isShortLink);
8407
+ }
8408
+ return existingPolyline;
8323
8409
  }
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;
8410
+ const newPolyline = L.polyline(lineCoordinates, polylineStyle);
8411
+ newPolyline.addTo(mapRef);
8412
+ listOfPolylines.push(newPolyline);
8413
+ if (shouldAnimate && isSelected) {
8414
+ newPolyline.once('add', () => {
8415
+ applyAnimationToPolyline(newPolyline, isShortLink);
8416
+ });
8417
+ applyAnimationToPolyline(newPolyline, isShortLink);
8352
8418
  }
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);
8419
+ return newPolyline;
8407
8420
  }
8408
8421
 
8409
8422
  const StakeholderMarker = styled__default["default"].div`
@@ -8705,6 +8718,9 @@ function StakeholderIcon$1({
8705
8718
  return null;
8706
8719
  }, [parentId, allData]);
8707
8720
  React.useEffect(() => {
8721
+ if (selectedMarkersId.length === 0 || !isSelected) {
8722
+ return;
8723
+ }
8708
8724
  linkNodesData.map(node => {
8709
8725
  const isConnectingToStakeholder = node.isStakeholder;
8710
8726
  const id = `${data.datastakeId}-${node.stakeholderId || node.datastakeId}`;
@@ -8716,8 +8732,6 @@ function StakeholderIcon$1({
8716
8732
  const stakeholderPoint = centerPoint.add(L__namespace.point(x, y));
8717
8733
  const stakeholderLatLng = mapRef.layerPointToLatLng(stakeholderPoint);
8718
8734
  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
8735
  if (isExtraSmallMarker(zoom) && !isForceOpen) {
8722
8736
  createPolyline({
8723
8737
  L: L__namespace,
@@ -8727,7 +8741,8 @@ function StakeholderIcon$1({
8727
8741
  zoom,
8728
8742
  isSelected,
8729
8743
  id,
8730
- listOfPolylines: polylinesRef.current
8744
+ listOfPolylines: polylinesRef.current,
8745
+ animated: true
8731
8746
  });
8732
8747
  return;
8733
8748
  }
@@ -8745,61 +8760,8 @@ function StakeholderIcon$1({
8745
8760
  const nodePoint = mapRef.latLngToLayerPoint(nodeLatLng);
8746
8761
  const endPoint = L__namespace.point(x + nodePoint.x + center.left, y + nodePoint.y + center.top);
8747
8762
  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
8763
  }
8764
+ // Always use straight lines
8803
8765
  createPolyline({
8804
8766
  L: L__namespace,
8805
8767
  mapRef,
@@ -8809,10 +8771,11 @@ function StakeholderIcon$1({
8809
8771
  isFromStakeholder: false,
8810
8772
  isSelected,
8811
8773
  id,
8812
- listOfPolylines: polylinesRef.current
8774
+ listOfPolylines: polylinesRef.current,
8775
+ animated: true
8813
8776
  });
8814
8777
  });
8815
- }, [mapRef, x, y, parentData, linkNodesData, isSelected, zoom, isForceOpen]);
8778
+ }, [mapRef, x, y, parentData, linkNodesData, isSelected, zoom, isForceOpen, selectedMarkersId]);
8816
8779
  return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
8817
8780
  children: /*#__PURE__*/jsxRuntime.jsx(antd.Popover, {
8818
8781
  content: renderTooltipJsx({
@@ -8824,7 +8787,8 @@ function StakeholderIcon$1({
8824
8787
  link,
8825
8788
  onClickLink: () => {
8826
8789
  onClickLink(data);
8827
- }
8790
+ },
8791
+ isNewTab: true
8828
8792
  }),
8829
8793
  getPopupContainer: triggerNode => {
8830
8794
  const mapElement = document.getElementById("map");
@@ -8879,6 +8843,8 @@ function LocationIcon({
8879
8843
  const linkedNodesData = React.useMemo(() => {
8880
8844
  const nodes = [];
8881
8845
  const links = data.links || [];
8846
+
8847
+ // Add links from the location itself
8882
8848
  links.forEach(link => {
8883
8849
  allData.forEach(d => {
8884
8850
  if (d.datastakeId === link) {
@@ -8898,8 +8864,45 @@ function LocationIcon({
8898
8864
  }
8899
8865
  });
8900
8866
  });
8867
+
8868
+ // ADD: Also include links from this location's stakeholders
8869
+ const stakeholders = data.stakeholders || [];
8870
+ stakeholders.forEach(stakeholder => {
8871
+ const stakeholderLinks = stakeholder.links || [];
8872
+ stakeholderLinks.forEach(link => {
8873
+ allData.forEach(d => {
8874
+ // Check if it's a direct location link
8875
+ if (d.datastakeId === link) {
8876
+ // Avoid duplicates
8877
+ if (!nodes.find(n => n.datastakeId === link && !n.isStakeholder)) {
8878
+ nodes.push({
8879
+ ...d,
8880
+ fromStakeholderId: stakeholder.datastakeId
8881
+ });
8882
+ }
8883
+ }
8884
+ // Check if it's a stakeholder link
8885
+ if (d.stakeholders && d.stakeholders.length > 0) {
8886
+ d.stakeholders.forEach(targetStakeholder => {
8887
+ if (targetStakeholder.datastakeId === link) {
8888
+ // Avoid duplicates
8889
+ if (!nodes.find(n => n.isStakeholder && n.datastakeId === d.datastakeId && n.stakeholdersIndex === d.stakeholders.indexOf(targetStakeholder))) {
8890
+ nodes.push({
8891
+ ...d,
8892
+ isStakeholder: true,
8893
+ totalStakeholders: d.stakeholders.length,
8894
+ stakeholdersIndex: d.stakeholders.indexOf(targetStakeholder),
8895
+ fromStakeholderId: stakeholder.datastakeId
8896
+ });
8897
+ }
8898
+ }
8899
+ });
8900
+ }
8901
+ });
8902
+ });
8903
+ });
8901
8904
  return nodes;
8902
- }, [JSON.stringify(allData), JSON.stringify(data.links), zoom]);
8905
+ }, [JSON.stringify(allData), JSON.stringify(data.links), JSON.stringify(data.stakeholders), zoom]);
8903
8906
  const stakeholdersOfLocation = React.useMemo(() => {
8904
8907
  return data?.stakeholders || [];
8905
8908
  }, [data.stakeholders, zoom]);
@@ -8917,7 +8920,13 @@ function LocationIcon({
8917
8920
  currentRoots.clear();
8918
8921
  markersRef.current = [];
8919
8922
 
8920
- // Create new markers
8923
+ // Only create stakeholder markers if this location or any of its stakeholders are selected
8924
+ const shouldShowStakeholders = isSelected || stakeholdersOfLocation.some(stk => selectedMarkersId.includes(stk.datastakeId));
8925
+ if (!shouldShowStakeholders || selectedMarkersId.length === 0) {
8926
+ return;
8927
+ }
8928
+
8929
+ // Create new markers only when selected
8921
8930
  stakeholdersOfLocation.forEach((stakeholder, index) => {
8922
8931
  const markerId = `${stakeholder.datastakeId}`;
8923
8932
  const {
@@ -9003,7 +9012,9 @@ function LocationIcon({
9003
9012
  zoom,
9004
9013
  isFromStakeholder: true,
9005
9014
  isForceOpen,
9006
- listOfPolylines: polylinesRef.current
9015
+ listOfPolylines: polylinesRef.current,
9016
+ stakeholderType: stakeholder.type,
9017
+ animated: true
9007
9018
  });
9008
9019
  });
9009
9020
  return () => {
@@ -9018,38 +9029,88 @@ function LocationIcon({
9018
9029
  rootsMapRef.current.clear();
9019
9030
  markersRef.current = [];
9020
9031
  };
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({
9032
+ }, [stakeholdersOfLocation, selectedMarkersId, activeMarker, zoom]);
9033
+
9034
+ // Only create polylines for linked nodes when something is selected
9035
+ React.useEffect(() => {
9036
+ if (selectedMarkersId.length === 0) {
9037
+ return;
9038
+ }
9039
+
9040
+ // IMPORTANT: Only draw links if this location is actually selected
9041
+ // Not just highlighted as part of the chain
9042
+ if (!isSelected) {
9043
+ return;
9044
+ }
9045
+
9046
+ // Filter linkedNodesData to only include nodes that are in the selected chain
9047
+ const relevantLinks = linkedNodesData.filter(node => {
9048
+ // Check if the target node (location) is in the selected markers
9049
+ const targetLocationInSelection = selectedMarkersId.includes(node.datastakeId);
9050
+
9051
+ // If connecting to a stakeholder, check if that stakeholder is selected
9052
+ if (node.isStakeholder) {
9053
+ const stakeholderInSelection = node.stakeholdersIndex !== undefined && selectedMarkersId.includes(node.datastakeId);
9054
+ return stakeholderInSelection;
9055
+ }
9056
+ return targetLocationInSelection;
9057
+ });
9058
+ relevantLinks.forEach(node => {
9059
+ const id = node.fromStakeholderId ? `${node.fromStakeholderId}-${node.datastakeId}` : `${data.datastakeId}-${node.datastakeId}`;
9060
+ const isConnectingToStakeholder = node.isStakeholder;
9061
+
9062
+ // If the link is from a stakeholder, start from the stakeholder position
9063
+ let startLatLng;
9064
+ if (node.fromStakeholderId) {
9065
+ // Find the stakeholder index in this location's stakeholders
9066
+ const stakeholderIndex = stakeholdersOfLocation.findIndex(s => s.datastakeId === node.fromStakeholderId);
9067
+ if (stakeholderIndex !== -1) {
9068
+ const {
9069
+ x,
9070
+ y
9071
+ } = getStakeholderPosition({
9072
+ zoom,
9073
+ totalMarkers: stakeholdersOfLocation.length,
9074
+ markerIndex: stakeholderIndex
9075
+ });
9076
+ const centerLatLng = L__namespace.latLng(data.gps.latitude, data.gps.longitude);
9077
+ const centerPoint = mapRef.latLngToLayerPoint(centerLatLng);
9078
+ const stakeholderPoint = centerPoint.add(L__namespace.point(x, y));
9079
+ startLatLng = mapRef.layerPointToLatLng(stakeholderPoint);
9080
+ } else {
9081
+ startLatLng = L__namespace.latLng(data.gps.latitude, data.gps.longitude);
9082
+ }
9083
+ } else {
9084
+ startLatLng = L__namespace.latLng(data.gps.latitude, data.gps.longitude);
9085
+ }
9086
+ let endLatLng = L__namespace.latLng(node.gps.latitude, node.gps.longitude);
9087
+ const isConnectingToStakeholderSelected = selectedMarkersId.includes(node.datastakeId);
9088
+ if (isConnectingToStakeholder && !isExtraSmallMarker(zoom)) {
9089
+ const {
9090
+ x,
9091
+ y
9092
+ } = getStakeholderPosition({
9093
+ zoom,
9094
+ totalMarkers: node.totalStakeholders,
9095
+ markerIndex: node.stakeholdersIndex
9096
+ });
9097
+ const nodeLatLng = L__namespace.latLng(node.gps.latitude, node.gps.longitude);
9098
+ const nodePoint = mapRef.latLngToLayerPoint(nodeLatLng);
9099
+ const endPoint = L__namespace.point(x + nodePoint.x, y + nodePoint.y);
9100
+ endLatLng = mapRef.layerPointToLatLng(endPoint);
9101
+ }
9102
+ createPolyline({
9103
+ L: L__namespace,
9104
+ mapRef,
9105
+ startLatLng,
9106
+ endLatLng,
9107
+ isSelected: isConnectingToStakeholderSelected,
9108
+ id,
9033
9109
  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
9110
+ listOfPolylines: polylinesRef.current
9111
+ });
9051
9112
  });
9052
- });
9113
+ }, [linkedNodesData, selectedMarkersId, zoom, stakeholdersOfLocation, isSelected]);
9053
9114
  return /*#__PURE__*/jsxRuntime.jsx(antd.Popover, {
9054
9115
  content: renderTooltipJsx({
9055
9116
  title: data.name,
@@ -9565,7 +9626,8 @@ function useMapHelper$1({
9565
9626
  link: link,
9566
9627
  onClickLink: onClickLink,
9567
9628
  activeStakeholder: activeStakeholder,
9568
- setActiveStakeholder: setActiveStakeholder
9629
+ setActiveStakeholder: setActiveStakeholder,
9630
+ mapRef: mapRef
9569
9631
  }));
9570
9632
  roots.current.push(root);
9571
9633
  } else if (type === "location") {
@@ -9770,7 +9832,8 @@ const useMap = ({
9770
9832
  MAP_TOKEN
9771
9833
  } = useMapConfig({
9772
9834
  app,
9773
- isSatellite
9835
+ isSatellite,
9836
+ mapRef: container
9774
9837
  });
9775
9838
  const [initialMarkerSetIsDone, setInitialMarkerSetIsDone] = React.useState(false);
9776
9839
  const [mapCenter, setMapCenter] = React.useState([0, 0]);
@@ -9787,6 +9850,8 @@ const useMap = ({
9787
9850
  const graph = new Map();
9788
9851
  const stakeToLoc = new Map();
9789
9852
  const nodeTypes = new Map();
9853
+
9854
+ // Build the graph
9790
9855
  for (const loc of data) {
9791
9856
  const locId = loc.datastakeId;
9792
9857
  nodeTypes.set(locId, loc.type);
@@ -9811,26 +9876,45 @@ const useMap = ({
9811
9876
  }
9812
9877
  }
9813
9878
  const highlightTable = {};
9879
+
9880
+ // Perform BFS/DFS to find all connected nodes in the entire chain
9814
9881
  for (const [node] of graph) {
9815
9882
  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 {
9883
+ const queue = [node];
9884
+ const visited = new Set([node]);
9885
+ while (queue.length > 0) {
9886
+ const current = queue.shift();
9887
+ highlighted.add(current);
9888
+
9889
+ // Add parent location if current is stakeholder
9890
+ const currentIsStakeholder = !isLocation(nodeTypes.get(current));
9891
+ if (currentIsStakeholder && stakeToLoc.has(current)) {
9892
+ const parentLoc = stakeToLoc.get(current);
9893
+ if (!visited.has(parentLoc)) {
9894
+ highlighted.add(parentLoc);
9895
+ visited.add(parentLoc);
9896
+ queue.push(parentLoc);
9897
+ }
9898
+ }
9899
+
9900
+ // Traverse all neighbors
9901
+ for (const neighbor of graph.get(current) || []) {
9902
+ if (!visited.has(neighbor)) {
9903
+ visited.add(neighbor);
9904
+ queue.push(neighbor);
9829
9905
  highlighted.add(neighbor);
9830
- highlighted.add(neighborParent);
9906
+
9907
+ // If neighbor is stakeholder, add its parent location
9908
+ const neighborIsStakeholder = !isLocation(nodeTypes.get(neighbor));
9909
+ if (neighborIsStakeholder && stakeToLoc.has(neighbor)) {
9910
+ const neighborParent = stakeToLoc.get(neighbor);
9911
+ if (!visited.has(neighborParent)) {
9912
+ highlighted.add(neighborParent);
9913
+ visited.add(neighborParent);
9914
+ queue.push(neighborParent);
9915
+ }
9916
+ }
9831
9917
  }
9832
- } else {
9833
- highlighted.add(neighbor);
9834
9918
  }
9835
9919
  }
9836
9920
  highlightTable[node] = [...highlighted];
@@ -9868,10 +9952,20 @@ const useMap = ({
9868
9952
  function handleSelectMarker(clickedMarker) {
9869
9953
  setSelectedMarkersId(prev => {
9870
9954
  if (prev.includes(clickedMarker.datastakeId)) {
9955
+ // Deselecting - clear polylines
9871
9956
  openPopupIdRef.current = null;
9872
9957
  setMarkerWithPopup(null);
9873
9958
  return [];
9874
9959
  } else {
9960
+ // CLEAR OLD POLYLINES BEFORE SELECTING NEW MARKER
9961
+ if (polylinesRef.current.length > 0) {
9962
+ polylinesRef.current.forEach(polyline => {
9963
+ if (mapRef.hasLayer(polyline)) {
9964
+ mapRef.removeLayer(polyline);
9965
+ }
9966
+ });
9967
+ polylinesRef.current = [];
9968
+ }
9875
9969
  setMarkerWithPopup(isStakeholder(clickedMarker.type) ? clickedMarker : null);
9876
9970
  const newSelectedMarkersId = highlightTable[clickedMarker.datastakeId];
9877
9971
  openPopupIdRef.current = clickedMarker.datastakeId;
@@ -9895,19 +9989,29 @@ const useMap = ({
9895
9989
  });
9896
9990
  }
9897
9991
  }
9992
+ if (type === "chain" && selectedMarkersId.length === 0) {
9993
+ if (polylinesRef.current.length) {
9994
+ polylinesRef.current.forEach(polyline => {
9995
+ if (mapRef.hasLayer(polyline)) {
9996
+ mapRef.removeLayer(polyline);
9997
+ }
9998
+ });
9999
+ polylinesRef.current = [];
10000
+ }
10001
+ }
9898
10002
  clearMapMarkers();
9899
10003
  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)))));
10004
+ 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
10005
  const maxTotal = Math.max(...(data || []).map(d => d.total));
9904
10006
  const dataToRender = type === "chain" ? filteredData : data;
9905
10007
  dataToRender.forEach((d, i) => {
9906
10008
  addIconToMapInitialy([d?.marker?.lat, d?.marker?.lng], "location", d.category || "mineSite", d, maxTotal, i);
9907
10009
  });
9908
- polylinesRef.current.forEach(polyline => {
9909
- mapRef.addLayer(polyline);
9910
- });
10010
+ if (selectedMarkersId.length > 0) {
10011
+ polylinesRef.current.forEach(polyline => {
10012
+ mapRef.addLayer(polyline);
10013
+ });
10014
+ }
9911
10015
  mapRef.invalidateSize();
9912
10016
  mapRef.fire("moveend");
9913
10017
  }
@@ -15176,7 +15280,7 @@ const renderStatusTag = ({
15176
15280
  }
15177
15281
  };
15178
15282
 
15179
- const getColumns$c = ({
15283
+ const getColumns$d = ({
15180
15284
  t,
15181
15285
  goTo,
15182
15286
  user,
@@ -17087,6 +17191,9 @@ function showHideForm(form, formsValue) {
17087
17191
  }
17088
17192
  return true;
17089
17193
  }
17194
+ const filterForm = (f, d) => {
17195
+ return f && (f.showFormIf ? showHideForm(f, d) : true);
17196
+ };
17090
17197
  const getSgbEvaluationIcons = (width, height) => ({
17091
17198
  0: /*#__PURE__*/jsxRuntime.jsxs("svg", {
17092
17199
  width: width,
@@ -17424,8 +17531,28 @@ function AjaxModal$1({
17424
17531
  const types = {
17425
17532
  MODAL: 'modal'
17426
17533
  };
17534
+ const isGroupInput = (group, repeatable = false, data) => {
17535
+ 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;
17536
+ if (group.showIf || group?.meta?.excludeFromView) {
17537
+ resp = resp && showHideInput$3(group, data);
17538
+ }
17539
+ return resp;
17540
+ };
17427
17541
  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
17542
  const conditions = new RegExp(/( is | and | not | notEmpty | includes )/gm);
17543
+ const getLastRow = (arr, cols) => {
17544
+ let currentInd = -1;
17545
+ const newArr = [];
17546
+ arr.forEach(nr => {
17547
+ if (nr % cols === 0) {
17548
+ newArr[currentInd + 1] = [nr];
17549
+ currentInd++;
17550
+ } else {
17551
+ newArr[currentInd].push(nr);
17552
+ }
17553
+ });
17554
+ return newArr[newArr.length - 1];
17555
+ };
17429
17556
  const _verifyCondition = (condition, data, allData) => {
17430
17557
  let [path, match, needed] = condition.split(conditions);
17431
17558
  const isRepeatable = path.split('./').length > 1;
@@ -17498,6 +17625,49 @@ const showHideInput$3 = (input, formsValue, repeatValues) => {
17498
17625
  }
17499
17626
  return true;
17500
17627
  };
17628
+ const getNkey = namespace => {
17629
+ if (['location', 'scl', 'village', 'event', 'incidents', 'corrective-actions', 'testimonials', 'initiatives', 'victims', 'pictures', 'documents', 'lir', 'sp', 'im', 'sci', 'bpe', 'gm'].includes(namespace)) {
17630
+ return 'scoping';
17631
+ }
17632
+ return namespace;
17633
+ };
17634
+ const groupSubsections = (form, onlyConf = false) => {
17635
+ return Object.keys(form).reduce((f, fKey) => {
17636
+ if (form[fKey].subSection) {
17637
+ let subName = form[fKey].subSection;
17638
+ if (typeof form[fKey].subSection === "object") {
17639
+ subName = form[fKey].subSection.name;
17640
+ }
17641
+ if (!f[subName]) {
17642
+ f[subName] = {
17643
+ label: '',
17644
+ icon: '',
17645
+ position: 0
17646
+ };
17647
+ if (typeof form[fKey].subSection === "object") {
17648
+ const {
17649
+ label = '',
17650
+ icon = '',
17651
+ position = 0,
17652
+ showFormIf = ''
17653
+ } = form[fKey].subSection;
17654
+ f[subName] = {
17655
+ label,
17656
+ icon,
17657
+ position,
17658
+ showFormIf
17659
+ };
17660
+ }
17661
+ }
17662
+ if (!onlyConf) {
17663
+ Object.assign(f[subName], {
17664
+ [fKey]: form[fKey]
17665
+ });
17666
+ }
17667
+ }
17668
+ return f;
17669
+ }, {});
17670
+ };
17501
17671
  const renderPlaceholder = ({
17502
17672
  data,
17503
17673
  config,
@@ -24479,6 +24649,19 @@ const Input = ({
24479
24649
  return getComponent();
24480
24650
  };
24481
24651
 
24652
+ const getDisabled = ({
24653
+ disabled,
24654
+ groupCheckboxDisableKey,
24655
+ data
24656
+ }) => {
24657
+ if (disabled) {
24658
+ return true;
24659
+ }
24660
+ if (typeof groupCheckboxDisableKey === 'string') {
24661
+ return !Object.values(data?.[groupCheckboxDisableKey] || {}).find(c => typeof c === 'number');
24662
+ }
24663
+ return false;
24664
+ };
24482
24665
  ({
24483
24666
  t: PropTypes__default["default"].func,
24484
24667
  data: PropTypes__default["default"].any,
@@ -24541,6 +24724,17 @@ function convertUndefinedToNull(obj) {
24541
24724
  }
24542
24725
  return obj;
24543
24726
  }
24727
+ const removeKeysFromObject = (obj = {}, keys = []) => {
24728
+ if (typeof obj !== 'object' || obj === null) return obj;
24729
+ const result = {};
24730
+ for (const key of Object.keys(obj)) {
24731
+ if (!keys.includes(key)) {
24732
+ result[key] = obj[key];
24733
+ }
24734
+ }
24735
+ return result;
24736
+ };
24737
+ const hasKeyInObject = (obj, key) => Object.keys(obj || {}).includes(key);
24544
24738
 
24545
24739
  const packageApps = ["kota", "sbg", "nashiriki", "straatos", "wazi", "hatua"]; //PACKAGE_CHANGE_LATER (add sbg)
24546
24740
 
@@ -30056,7 +30250,7 @@ const NavigationAction = ({
30056
30250
  });
30057
30251
  };
30058
30252
 
30059
- const getColumns$b = ({
30253
+ const getColumns$c = ({
30060
30254
  t,
30061
30255
  goTo,
30062
30256
  user,
@@ -30628,7 +30822,7 @@ const viewConfig$6 = {
30628
30822
  createTitle: "Create Worker"
30629
30823
  };
30630
30824
 
30631
- const getColumns$a = ({
30825
+ const getColumns$b = ({
30632
30826
  t,
30633
30827
  goTo,
30634
30828
  user,
@@ -31130,7 +31324,7 @@ MoreTags.propTypes = {
31130
31324
  limit: PropTypes__default["default"].number
31131
31325
  };
31132
31326
 
31133
- const getColumns$9 = ({
31327
+ const getColumns$a = ({
31134
31328
  t,
31135
31329
  goTo,
31136
31330
  user,
@@ -31585,7 +31779,7 @@ const getEventCategoryBySubject = (eventCategoryObject, subject, isSingular = fa
31585
31779
  return eventCategoryObject[key] || null;
31586
31780
  };
31587
31781
 
31588
- const getColumns$8 = ({
31782
+ const getColumns$9 = ({
31589
31783
  t,
31590
31784
  goTo,
31591
31785
  user,
@@ -32010,7 +32204,7 @@ const viewConfig$3 = {
32010
32204
  createTitle: "Create Incident"
32011
32205
  };
32012
32206
 
32013
- const getColumns$7 = ({
32207
+ const getColumns$8 = ({
32014
32208
  t,
32015
32209
  goTo,
32016
32210
  user,
@@ -32268,7 +32462,7 @@ const viewConfig$2 = {
32268
32462
  createTitle: "Create Location"
32269
32463
  };
32270
32464
 
32271
- const getColumns$6 = ({
32465
+ const getColumns$7 = ({
32272
32466
  t,
32273
32467
  goTo,
32274
32468
  user,
@@ -32682,7 +32876,7 @@ MoreOptions.propTypes = {
32682
32876
  limit: PropTypes__default["default"].number
32683
32877
  };
32684
32878
 
32685
- const getColumns$5 = ({
32879
+ const getColumns$6 = ({
32686
32880
  t,
32687
32881
  goTo,
32688
32882
  user,
@@ -32918,7 +33112,7 @@ const viewConfig = {
32918
33112
  createTitle: "Create Document"
32919
33113
  };
32920
33114
 
32921
- const getColumns$4 = ({
33115
+ const getColumns$5 = ({
32922
33116
  t,
32923
33117
  goTo,
32924
33118
  user,
@@ -33043,63 +33237,63 @@ const FILTER_REGISTRY = {
33043
33237
  options: getFilterOptions$a,
33044
33238
  formConfig: formConfig$8,
33045
33239
  viewConfig: viewConfig$8,
33046
- columns: getColumns$b
33240
+ columns: getColumns$c
33047
33241
  },
33048
33242
  workers: {
33049
33243
  config: getFiltersConfig$8,
33050
33244
  options: getFilterOptions$8,
33051
33245
  formConfig: formConfig$6,
33052
33246
  viewConfig: viewConfig$6,
33053
- columns: getColumns$a
33247
+ columns: getColumns$b
33054
33248
  },
33055
33249
  operators: {
33056
33250
  config: getFiltersConfig$9,
33057
33251
  options: getFilterOptions$9,
33058
33252
  formConfig: formConfig$7,
33059
33253
  viewConfig: viewConfig$7,
33060
- columns: getColumns$c
33254
+ columns: getColumns$d
33061
33255
  },
33062
33256
  events: {
33063
33257
  config: getFiltersConfig$7,
33064
33258
  options: getFilterOptions$7,
33065
33259
  formConfig: formConfig$5,
33066
33260
  viewConfig: viewConfig$5,
33067
- columns: getColumns$9
33261
+ columns: getColumns$a
33068
33262
  },
33069
33263
  activities: {
33070
33264
  config: getFiltersConfig$6,
33071
33265
  options: getFilterOptions$6,
33072
33266
  formConfig: formConfig$4,
33073
33267
  viewConfig: viewConfig$4,
33074
- columns: getColumns$8
33268
+ columns: getColumns$9
33075
33269
  },
33076
33270
  incidents: {
33077
33271
  config: getFiltersConfig$5,
33078
33272
  options: getFilterOptions$5,
33079
33273
  formConfig: formConfig$3,
33080
33274
  viewConfig: viewConfig$3,
33081
- columns: getColumns$7
33275
+ columns: getColumns$8
33082
33276
  },
33083
33277
  locations: {
33084
33278
  config: getFiltersConfig$4,
33085
33279
  options: getFilterOptions$4,
33086
33280
  formConfig: formConfig$2,
33087
33281
  viewConfig: viewConfig$2,
33088
- columns: getColumns$6
33282
+ columns: getColumns$7
33089
33283
  },
33090
33284
  'production-sites': {
33091
33285
  config: getFiltersConfig$3,
33092
33286
  options: getFilterOptions$3,
33093
33287
  formConfig: formConfig$1,
33094
33288
  viewConfig: viewConfig$1,
33095
- columns: getColumns$5
33289
+ columns: getColumns$6
33096
33290
  },
33097
33291
  documents: {
33098
33292
  config: getFiltersConfig$2,
33099
33293
  options: getFilterOptions$2,
33100
33294
  formConfig: formConfig,
33101
33295
  viewConfig: viewConfig,
33102
- columns: getColumns$4
33296
+ columns: getColumns$5
33103
33297
  }
33104
33298
  };
33105
33299
  const DEFAULT_SUBJECT = 'stakeholders';
@@ -33150,7 +33344,7 @@ const getViewConfig = ({
33150
33344
  return registry?.viewConfig;
33151
33345
  };
33152
33346
 
33153
- const getColumns$3 = ({
33347
+ const getColumns$4 = ({
33154
33348
  t,
33155
33349
  goTo,
33156
33350
  user,
@@ -33237,7 +33431,7 @@ const useTablePage = ({
33237
33431
  extendingFilters: extendingFilters,
33238
33432
  subject
33239
33433
  });
33240
- const columns = React.useMemo(() => getColumns$3({
33434
+ const columns = React.useMemo(() => getColumns$4({
33241
33435
  t,
33242
33436
  goTo,
33243
33437
  user,
@@ -33248,7 +33442,7 @@ const useTablePage = ({
33248
33442
  subject,
33249
33443
  data,
33250
33444
  applications
33251
- }), [t, goTo, user, options, activeTab, getRedirectLink, theme, data, applications, subject, getColumns$3]);
33445
+ }), [t, goTo, user, options, activeTab, getRedirectLink, theme, data, applications, subject, getColumns$4]);
33252
33446
  const selectFiltersConfig = React.useMemo(() => getFiltersConfig$1({
33253
33447
  t,
33254
33448
  subject
@@ -33813,7 +34007,7 @@ const WorkersTable = ({
33813
34007
  getData: getData,
33814
34008
  getApiBaseUrl: getApiBaseUrl,
33815
34009
  getAppHeader: getAppHeader,
33816
- getColumns: getColumns$a,
34010
+ getColumns: getColumns$b,
33817
34011
  breadcrumbs: breadcrumbs,
33818
34012
  extendingFilters: extendingFilters,
33819
34013
  formConfig: {
@@ -34038,7 +34232,7 @@ const ProductionSitesTable = ({
34038
34232
  });
34039
34233
  };
34040
34234
 
34041
- const getColumns$2 = ({
34235
+ const getColumns$3 = ({
34042
34236
  t,
34043
34237
  goTo,
34044
34238
  user,
@@ -34516,7 +34710,7 @@ const UsersTable = ({
34516
34710
  const params = new URLSearchParams(location?.search);
34517
34711
  const [openCreateModal, setOpenCreateModal] = React.useState(params.has("create"));
34518
34712
  const [userToEdit, setUserToEdit] = React.useState(null);
34519
- const columns = React.useMemo(() => getColumns$2({
34713
+ const columns = React.useMemo(() => getColumns$3({
34520
34714
  t,
34521
34715
  goTo,
34522
34716
  user,
@@ -34907,7 +35101,7 @@ const partnershipTypes = [{
34907
35101
  value: "exchange"
34908
35102
  }];
34909
35103
 
34910
- const getColumns$1 = ({
35104
+ const getColumns$2 = ({
34911
35105
  t,
34912
35106
  accept,
34913
35107
  decline,
@@ -35652,7 +35846,7 @@ const PartnersTable = ({
35652
35846
  setTotalRequests,
35653
35847
  t
35654
35848
  });
35655
- const columns = React.useMemo(() => getColumns$1({
35849
+ const columns = React.useMemo(() => getColumns$2({
35656
35850
  t,
35657
35851
  accept,
35658
35852
  decline,
@@ -39900,6 +40094,710 @@ const StatCard = ({
39900
40094
  });
39901
40095
  };
39902
40096
 
40097
+ const RepeatableGroup = ({
40098
+ name = null,
40099
+ config = {},
40100
+ allData = {},
40101
+ linkingData = {},
40102
+ ajaxOptions,
40103
+ t,
40104
+ ajaxForms,
40105
+ changeAjaxForms,
40106
+ getApiBaseUrl,
40107
+ getAppHeader,
40108
+ user,
40109
+ getToken,
40110
+ app
40111
+ }) => {
40112
+ const {
40113
+ automaticallyLink,
40114
+ dataLink,
40115
+ call
40116
+ } = React.useMemo(() => config, [config]);
40117
+ const entity = React.useMemo(() => automaticallyLink?.entity || config?.meta?.dataLinkEntity, [automaticallyLink, config]);
40118
+ const isAjaxModal = React.useMemo(() => automaticallyLink && dataLink && call, [automaticallyLink, dataLink, call]);
40119
+ const [modalRow, setModalRow] = React.useState(null);
40120
+ const dataSource = React.useMemo(() => allData[name] || [], [allData, name]);
40121
+ const notAvailable = (allData?.meta?.inputs || {})[name]?.notAvailable;
40122
+ const notApplicable = (allData?.meta?.inputs || {})[name]?.notApplicable;
40123
+ const noBody = notApplicable || notAvailable;
40124
+ const _data = React.useMemo(() => dataSource.length ? dataSource.map((f, i) => {
40125
+ if (isAjaxModal && typeof f === 'string' && linkingData && linkingData[entity] && linkingData[entity][f]) {
40126
+ const value = linkingData[entity][f];
40127
+ return {
40128
+ ...value,
40129
+ key: i
40130
+ };
40131
+ }
40132
+ if (config?.meta?.ajaxOptionsKey) {
40133
+ if (linkingData && linkingData[entity] && linkingData[entity][f[config?.meta?.ajaxOptionsKey]]) {
40134
+ const value = linkingData[entity][f[config?.meta?.ajaxOptionsKey]];
40135
+ return {
40136
+ ...value,
40137
+ key: i
40138
+ };
40139
+ }
40140
+ const options = ajaxOptions[config?.meta?.ajaxOptionsKey];
40141
+ if (Array.isArray(options)) {
40142
+ const value = options.find(v => v.value === f[config?.meta?.ajaxOptionsKey]);
40143
+ if (value) {
40144
+ return {
40145
+ ...f,
40146
+ ...value,
40147
+ key: i
40148
+ };
40149
+ }
40150
+ }
40151
+ }
40152
+ return {
40153
+ ...f,
40154
+ key: i
40155
+ };
40156
+ }) : [{
40157
+ key: 1,
40158
+ isEmpty: true
40159
+ }, {
40160
+ key: 2,
40161
+ isEmpty: true
40162
+ }], [isAjaxModal, dataSource, entity, config, ajaxOptions, linkingData]);
40163
+ const mapKey = key => ({
40164
+ title: config?.inputs[key]?.label,
40165
+ key: key,
40166
+ dataIndex: key,
40167
+ ellipsis: true,
40168
+ render: (v, all) => {
40169
+ if (all.isEmpty) {
40170
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
40171
+ className: "daf-default-cell md"
40172
+ });
40173
+ }
40174
+ if (v) {
40175
+ return /*#__PURE__*/jsxRuntime.jsx(BasicInput, {
40176
+ t: t,
40177
+ app: app,
40178
+ ajaxForms: ajaxForms,
40179
+ changeAjaxForms: changeAjaxForms,
40180
+ getApiBaseUrl: getApiBaseUrl,
40181
+ getAppHeader: getAppHeader,
40182
+ user: user,
40183
+ getToken: getToken,
40184
+ name: key,
40185
+ config: config.inputs[key],
40186
+ valueOnlyString: true,
40187
+ data: all
40188
+ }, key);
40189
+ }
40190
+ return '--';
40191
+ }
40192
+ });
40193
+ const columns = [...(Array.isArray(config?.meta?.tableKeys) ? config.meta.tableKeys.map(mapKey) : Object.keys(config?.inputs).map(mapKey)), {
40194
+ key: 'actions',
40195
+ dataIndex: 'actions',
40196
+ label: '',
40197
+ width: 50,
40198
+ render: (_, all) => {
40199
+ if (all.isEmpty) {
40200
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
40201
+ className: "daf-default-cell md"
40202
+ });
40203
+ }
40204
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
40205
+ onClick: () => setModalRow(all),
40206
+ className: "cursor-pointer flex justify-content-center",
40207
+ children: /*#__PURE__*/jsxRuntime.jsx(Icons.EyeOutlined, {})
40208
+ });
40209
+ }
40210
+ }];
40211
+ const _subTitle = config.viewSubTitle || config.subTitle;
40212
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
40213
+ className: formatClassname(["group repeatable", noBody && 'no-body']),
40214
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
40215
+ className: "daf-title with-subtitle",
40216
+ children: [/*#__PURE__*/jsxRuntime.jsx("h1", {
40217
+ children: ReactHtmlParser__default["default"](config?.label)
40218
+ }), _subTitle && typeof _subTitle === 'string' ? /*#__PURE__*/jsxRuntime.jsx("p", {
40219
+ children: ReactHtmlParser__default["default"](_subTitle)
40220
+ }) : null]
40221
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
40222
+ className: "flex",
40223
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
40224
+ className: "daf-table-wrapper no-padding repeatable-form-table input no-pagination",
40225
+ children: /*#__PURE__*/jsxRuntime.jsx(antd.ConfigProvider, {
40226
+ renderEmpty: () => notApplicable ? t('Not applicable') : t('No information available'),
40227
+ children: /*#__PURE__*/jsxRuntime.jsx(antd.Table, {
40228
+ locale: getLocales(t),
40229
+ pagination: false,
40230
+ columns: columns,
40231
+ rowKey: "key",
40232
+ dataSource: noBody ? [] : _data
40233
+ })
40234
+ })
40235
+ }), !noActionsInputs.includes(config?.type) ? /*#__PURE__*/jsxRuntime.jsxs("div", {
40236
+ className: "ml-4 input-actions flex",
40237
+ children: [/*#__PURE__*/jsxRuntime.jsx(Review, {
40238
+ t: t,
40239
+ config: config,
40240
+ inputMeta: (allData?.meta?.inputs || {})[name] || {},
40241
+ name: name
40242
+ }), /*#__PURE__*/jsxRuntime.jsx(Versions, {
40243
+ t: t,
40244
+ versionsDatapoints: [],
40245
+ config: config,
40246
+ allData: allData,
40247
+ name: name,
40248
+ getValue: () => null
40249
+ }), /*#__PURE__*/jsxRuntime.jsx(antd.Tooltip, {
40250
+ title: t("Sources"),
40251
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40252
+ children: /*#__PURE__*/jsxRuntime.jsx(antd.Button, {
40253
+ className: "default p-0 flex flex-column justify-content-center",
40254
+ type: "link",
40255
+ disabled: true,
40256
+ children: /*#__PURE__*/jsxRuntime.jsx(CustomIcon, {
40257
+ name: "Sources",
40258
+ width: 16,
40259
+ height: 16
40260
+ })
40261
+ })
40262
+ })
40263
+ }), /*#__PURE__*/jsxRuntime.jsx(antd.Tooltip, {
40264
+ title: t("Comments"),
40265
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40266
+ children: /*#__PURE__*/jsxRuntime.jsx(Comments, {
40267
+ t: t,
40268
+ config: config,
40269
+ allData: allData,
40270
+ name: name
40271
+ })
40272
+ })
40273
+ })]
40274
+ }) : null]
40275
+ }), /*#__PURE__*/jsxRuntime.jsx(antd.Modal, {
40276
+ open: !!modalRow,
40277
+ title: /*#__PURE__*/jsxRuntime.jsx(ModalHeader, {
40278
+ title: config?.label
40279
+ }),
40280
+ footer: null,
40281
+ width: 650,
40282
+ className: "max-h-50",
40283
+ onCancel: () => setModalRow(null),
40284
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40285
+ className: "daf-view-form",
40286
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40287
+ className: "view-content",
40288
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40289
+ className: "content no-padding",
40290
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40291
+ className: "wrapper",
40292
+ style: {
40293
+ maxWidth: 600 // FUTURE ILVI
40294
+ },
40295
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40296
+ className: "group",
40297
+ children: /*#__PURE__*/jsxRuntime.jsx(Input, {
40298
+ app: app,
40299
+ t: t,
40300
+ ajaxForms: ajaxForms,
40301
+ changeAjaxForms: changeAjaxForms,
40302
+ getApiBaseUrl: getApiBaseUrl,
40303
+ getAppHeader: getAppHeader,
40304
+ user: user,
40305
+ getToken: getToken,
40306
+ config: Object.keys(config.inputs || {}).filter(k => {
40307
+ return !(config?.meta?.excludedKeysView || []).includes(k);
40308
+ }).reduce((all, key) => {
40309
+ all[key] = config.inputs[key];
40310
+ return all;
40311
+ }, {}),
40312
+ data: {
40313
+ ...modalRow
40314
+ }
40315
+ })
40316
+ })
40317
+ })
40318
+ })
40319
+ })
40320
+ })
40321
+ })]
40322
+ });
40323
+ };
40324
+
40325
+ /* eslint-disable no-case-declarations */
40326
+ const RepeatableModals = ({
40327
+ name = null,
40328
+ config = {},
40329
+ data = {},
40330
+ linkingData = {},
40331
+ linkingForms = {},
40332
+ ajaxOptions = [],
40333
+ t,
40334
+ ajaxForms,
40335
+ changeAjaxForms,
40336
+ getApiBaseUrl,
40337
+ getAppHeader,
40338
+ user,
40339
+ getToken,
40340
+ app
40341
+ }) => {
40342
+ const label = (prop = null) => {
40343
+ function getLabel(label) {
40344
+ switch (typeof label) {
40345
+ case 'string':
40346
+ return label;
40347
+ case 'object':
40348
+ const labelKey = Object.keys(label).find(cond => verifyConditional(cond, data));
40349
+ return label[labelKey];
40350
+ default:
40351
+ return label;
40352
+ }
40353
+ }
40354
+ if (config[prop]) {
40355
+ return getLabel(config[prop]);
40356
+ }
40357
+ if (config.sectionLabel) {
40358
+ return getLabel(config.sectionLabel);
40359
+ }
40360
+ if (config.outputLabel) {
40361
+ return getLabel(config.outputLabel);
40362
+ }
40363
+ return getLabel(config.label);
40364
+ };
40365
+ return verifyConditional(config.showIf ? config.showIf : null, data) ? /*#__PURE__*/jsxRuntime.jsxs("div", {
40366
+ className: "group",
40367
+ children: [label('outputLabel') ? /*#__PURE__*/jsxRuntime.jsx("div", {
40368
+ className: "title",
40369
+ children: /*#__PURE__*/jsxRuntime.jsx("h1", {
40370
+ children: label('outputLabel')
40371
+ })
40372
+ }) : null, data[name] && data[name].length ? data[name].map((item, index) => /*#__PURE__*/jsxRuntime.jsxs("div", {
40373
+ className: "group display",
40374
+ style: {
40375
+ border: '1px dotted var(--mmt-primary-70)'
40376
+ },
40377
+ children: [label() ? /*#__PURE__*/jsxRuntime.jsx("div", {
40378
+ className: "title",
40379
+ children: /*#__PURE__*/jsxRuntime.jsxs("h1", {
40380
+ children: [label(), " #", index + 1]
40381
+ })
40382
+ }) : null, repeatObjects(config.inputs, key => {
40383
+ const modalData = {
40384
+ [name]: {
40385
+ [key]: data[name][index][key] || null
40386
+ }
40387
+ };
40388
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
40389
+ className: "group",
40390
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
40391
+ className: "title",
40392
+ children: /*#__PURE__*/jsxRuntime.jsx("h1", {
40393
+ children: config.inputs[key].outputLabel || getInputLabel$2(config.inputs[key], item)
40394
+ })
40395
+ }), /*#__PURE__*/jsxRuntime.jsx(Input, {
40396
+ app: app,
40397
+ ajaxForms: ajaxForms,
40398
+ changeAjaxForms: changeAjaxForms,
40399
+ getApiBaseUrl: getApiBaseUrl,
40400
+ getAppHeader: getAppHeader,
40401
+ user: user,
40402
+ getToken: getToken,
40403
+ t: t,
40404
+ parent: name,
40405
+ name: config.inputs[key].dataId || key,
40406
+ config: config.inputs[key],
40407
+ data: modalData,
40408
+ linkingData: linkingData,
40409
+ linkingForms: linkingForms,
40410
+ ajaxOptions: ajaxOptions,
40411
+ cols: 2
40412
+ }, key)]
40413
+ }, key);
40414
+ })]
40415
+ }, index)) : /*#__PURE__*/jsxRuntime.jsx("span", {
40416
+ className: "text-muted",
40417
+ children: t('Not answered')
40418
+ })]
40419
+ }) : null;
40420
+ };
40421
+
40422
+ /* eslint-disable no-unused-vars */
40423
+ const Content = ({
40424
+ style = {},
40425
+ form = {},
40426
+ data = {},
40427
+ groupConfig = {},
40428
+ versionsDatapoints,
40429
+ linkingData = {},
40430
+ linkingForms = {},
40431
+ ajaxOptions = [],
40432
+ // ADDED
40433
+ t,
40434
+ app,
40435
+ ajaxForms,
40436
+ language,
40437
+ changeAjaxForms,
40438
+ getApiBaseUrl,
40439
+ getAppHeader,
40440
+ user,
40441
+ evaluationConfig = [],
40442
+ fullWidth = false
40443
+ }) => {
40444
+ const groupSingle = grps => {
40445
+ const form = Object.keys(grps).reduce((f, gKey) => {
40446
+ 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) {
40447
+ if (grps[gKey].group && !f[grps[gKey].group]) {
40448
+ f[grps[gKey].group] = {};
40449
+ Object.assign(f[grps[gKey].group], {
40450
+ [gKey]: grps[gKey]
40451
+ });
40452
+ } else if (grps[gKey].group && f[grps[gKey].group]) {
40453
+ Object.assign(f[grps[gKey].group], {
40454
+ [gKey]: grps[gKey]
40455
+ });
40456
+ }
40457
+ if (grps[gKey]?.meta?.group && !f[grps[gKey]?.meta?.group]) {
40458
+ f[grps[gKey]?.meta?.group] = {};
40459
+ Object.assign(f[grps[gKey].meta.group], {
40460
+ [gKey]: grps[gKey]
40461
+ });
40462
+ } else if (grps[gKey]?.meta?.group && f[grps[gKey]?.meta?.group]) {
40463
+ Object.assign(f[grps[gKey].meta.group], {
40464
+ [gKey]: grps[gKey]
40465
+ });
40466
+ }
40467
+ if (grps[gKey].section && !f[grps[gKey].section]) {
40468
+ f[grps[gKey].section] = {};
40469
+ Object.assign(f[grps[gKey].section], {
40470
+ [gKey]: grps[gKey]
40471
+ });
40472
+ } else if (grps[gKey].section && f[grps[gKey].section]) {
40473
+ Object.assign(f[grps[gKey].section], {
40474
+ [gKey]: grps[gKey]
40475
+ });
40476
+ }
40477
+ }
40478
+ return f;
40479
+ }, {});
40480
+ return form;
40481
+ };
40482
+ const getDisplayGroupConfig = (groups, key) => {
40483
+ return Object.keys(groups).reduce((items, gKey) => {
40484
+ if (groups[gKey].viewGroup === key) {
40485
+ // eslint-disable-next-line no-unused-vars
40486
+ const {
40487
+ viewGroup,
40488
+ ...gCfg
40489
+ } = groups[gKey];
40490
+ items[gKey] = gCfg;
40491
+ }
40492
+ return items;
40493
+ }, {});
40494
+ };
40495
+ const getComponent = (component, key, config) => {
40496
+ switch (component) {
40497
+ case "repeatableModals":
40498
+ return /*#__PURE__*/jsxRuntime.jsx(RepeatableModals, {
40499
+ app: app,
40500
+ t: t,
40501
+ ajaxForms: ajaxForms,
40502
+ changeAjaxForms: changeAjaxForms,
40503
+ getApiBaseUrl: getApiBaseUrl,
40504
+ getAppHeader: getAppHeader,
40505
+ user: user,
40506
+ getToken: getToken,
40507
+ name: key,
40508
+ data: data,
40509
+ config: config,
40510
+ linkingData: linkingData,
40511
+ linkingForms: linkingForms,
40512
+ ajaxOptions: ajaxOptions
40513
+ }, key);
40514
+ default:
40515
+ return /*#__PURE__*/jsxRuntime.jsx("p", {
40516
+ children: "Component"
40517
+ });
40518
+ }
40519
+ };
40520
+ const isDisplayGroup = input => input.display && input.display === "group";
40521
+ const isSingleModal = input => input.type && input.type === "modal";
40522
+ const hasComponent = input => input.component && typeof input.component === "string";
40523
+ const typeRender = (groups, singleGroupsKeys, addedContent) => {
40524
+ const _length = Object.keys(groups || {}).length;
40525
+ const isEven = _length % 2 === 0;
40526
+ const groupped = Object.keys(groups).reduce((all, key) => {
40527
+ const _val = groups[key];
40528
+ const group = _val.group || _val?.meta?.group || _val.section;
40529
+ if (all[group]) {
40530
+ all[group][key] = _val;
40531
+ } else {
40532
+ all[group] = {
40533
+ [key]: _val
40534
+ };
40535
+ }
40536
+ return all;
40537
+ }, {});
40538
+ return Object.keys(groupped).map(key => {
40539
+ const groups = groupped[key];
40540
+ return /*#__PURE__*/jsxRuntime.jsx(React__default["default"].Fragment, {
40541
+ children: repeatObjects(groups, (key, ind) => {
40542
+ // normal group
40543
+ return hasComponent(groups[key]) ? getComponent(groups[key].component, key, groups[key]) : isGroupInput(groups[key], false, data) ? /*#__PURE__*/jsxRuntime.jsx(Group, {
40544
+ t: t,
40545
+ name: key,
40546
+ linkingData: linkingData,
40547
+ config: groups[key],
40548
+ data: data,
40549
+ allData: data,
40550
+ linkingForms: linkingForms,
40551
+ cols: 2,
40552
+ ajaxForms: ajaxForms,
40553
+ changeAjaxForms: changeAjaxForms,
40554
+ getApiBaseUrl: getApiBaseUrl,
40555
+ getAppHeader: getAppHeader,
40556
+ user: user,
40557
+ getToken: getToken,
40558
+ evaluationConfig: evaluationConfig,
40559
+ ajaxOptions: ajaxOptions
40560
+ }, key) :
40561
+ // repeatable group
40562
+ isGroupInput(groups[key], true, data) ? /*#__PURE__*/jsxRuntime.jsx(RepeatableGroup, {
40563
+ app: app,
40564
+ t: t,
40565
+ ajaxForms: ajaxForms,
40566
+ changeAjaxForms: changeAjaxForms,
40567
+ getApiBaseUrl: getApiBaseUrl,
40568
+ getAppHeader: getAppHeader,
40569
+ user: user,
40570
+ getToken: getToken,
40571
+ name: key,
40572
+ config: groups[key],
40573
+ data: data,
40574
+ allData: data,
40575
+ linkingData: linkingData,
40576
+ linkingForms: linkingForms,
40577
+ ajaxOptions: ajaxOptions
40578
+ }, key) :
40579
+ // single inputs grouped
40580
+ singleGroupsKeys.includes(key) ? (() => {
40581
+ if (!addedContent.includes(key)) {
40582
+ const currentGroup = Object.keys(groupSingle(groups)).find(k => Object.keys(groupSingle(groups)[k]).includes(key));
40583
+ addedContent.push(...Object.keys(groupSingle(groups)[currentGroup]));
40584
+ const config = groupSingle(groups)[currentGroup];
40585
+ if (groups[key].viewShowIf || groups[key]?.meta?.excludeFromView) {
40586
+ if (!showHideInput$3(groups[key], data)) {
40587
+ return null;
40588
+ }
40589
+ }
40590
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
40591
+ className: "group",
40592
+ id: currentGroup,
40593
+ children: [groupConfig[currentGroup] ? /*#__PURE__*/jsxRuntime.jsx("div", {
40594
+ className: "title",
40595
+ children: /*#__PURE__*/jsxRuntime.jsx("h1", {
40596
+ children: groupConfig[currentGroup][language]
40597
+ })
40598
+ }) : null, /*#__PURE__*/jsxRuntime.jsx(Input, {
40599
+ app: app,
40600
+ t: t,
40601
+ ajaxForms: ajaxForms,
40602
+ changeAjaxForms: changeAjaxForms,
40603
+ getApiBaseUrl: getApiBaseUrl,
40604
+ getAppHeader: getAppHeader,
40605
+ user: user,
40606
+ getToken: getToken,
40607
+ versionsDatapoints: versionsDatapoints,
40608
+ name: config.dataId || key,
40609
+ config: config,
40610
+ data: data,
40611
+ allData: data,
40612
+ linkingData: linkingData,
40613
+ className: isEven ? ind === _length - 1 || ind === _length - 2 ? "last" : undefined : ind === _length - 1 ? "last" : undefined,
40614
+ linkingForms: linkingForms,
40615
+ ajaxOptions: ajaxOptions,
40616
+ evaluationConfig: evaluationConfig,
40617
+ cols: 2
40618
+ }, key)]
40619
+ }, `${currentGroup}-${Date.now()}`);
40620
+ }
40621
+ })() :
40622
+ // display group
40623
+ isDisplayGroup(groups[key]) ? /*#__PURE__*/jsxRuntime.jsxs("div", {
40624
+ className: "group display",
40625
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
40626
+ className: "title",
40627
+ children: /*#__PURE__*/jsxRuntime.jsx("h1", {
40628
+ children: groups[key].label
40629
+ })
40630
+ }), typeRender(getDisplayGroupConfig(groups, key), singleGroupsKeys, addedContent)]
40631
+ }, key) :
40632
+ // single modal
40633
+ isSingleModal(groups[key]) ? /*#__PURE__*/jsxRuntime.jsxs("div", {
40634
+ className: "group",
40635
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
40636
+ className: "title",
40637
+ children: /*#__PURE__*/jsxRuntime.jsx("h1", {
40638
+ children: groups[key].outputLabel || getInputLabel$2(groups[key], data)
40639
+ })
40640
+ }), /*#__PURE__*/jsxRuntime.jsx(Input, {
40641
+ app: app,
40642
+ t: t,
40643
+ ajaxForms: ajaxForms,
40644
+ changeAjaxForms: changeAjaxForms,
40645
+ getApiBaseUrl: getApiBaseUrl,
40646
+ getAppHeader: getAppHeader,
40647
+ user: user,
40648
+ getToken: getToken,
40649
+ versionsDatapoints: versionsDatapoints,
40650
+ parent: key,
40651
+ name: groups[key].dataId || key,
40652
+ config: groups[key],
40653
+ className: "last",
40654
+ data: data,
40655
+ allData: data,
40656
+ linkingData: linkingData,
40657
+ linkingForms: linkingForms,
40658
+ ajaxOptions: ajaxOptions,
40659
+ evaluationConfig: evaluationConfig,
40660
+ cols: 2
40661
+ }, key)]
40662
+ }, key) : null;
40663
+ })
40664
+ }, key);
40665
+ });
40666
+ };
40667
+ React.useEffect(() => {
40668
+ setTimeout(() => {
40669
+ const groups = Array.from(document.getElementsByClassName("group"));
40670
+ const rows = Array.from(document.querySelectorAll(".repetable-row-extra"));
40671
+ rows.forEach(row => {
40672
+ const inputs = Array.from(row.querySelectorAll(".input"));
40673
+ const lasts = getLastRow(inputs.map((i, ind) => ind), 4);
40674
+ if (lasts) {
40675
+ lasts.forEach(index => inputs[index].classList.add("last"));
40676
+ }
40677
+ });
40678
+ groups.forEach(group => {
40679
+ // const isRepeatable = Array.from(group.classList).includes('repeatable');
40680
+ const inputs = Array.from(group.querySelectorAll(".input"));
40681
+ // if (inputs.length && !isRepeatable) {
40682
+ // if (inputs.length % 2 === 0) {
40683
+ // inputs[inputs.length - 1].classList.add('last');
40684
+ // inputs[inputs.length - 2].classList.add('last');
40685
+ // } else {
40686
+ // inputs[inputs.length - 1].classList.add('last');
40687
+ // }
40688
+ // }
40689
+ // remove groups without inputs
40690
+ if (!inputs.length) {
40691
+ group.remove();
40692
+ }
40693
+ });
40694
+ }, 200);
40695
+ }, [form, data]);
40696
+ React.useState({});
40697
+ React.useState({});
40698
+ React.useState({});
40699
+ const renderContent = (f, showTitle = true) => {
40700
+ if (f) {
40701
+ const alertType = ["error", "warning", "info", "success"];
40702
+ if (f.alertConf && f.alertConf.type === "warning") {
40703
+ return /*#__PURE__*/jsxRuntime.jsx(antd.Alert, {
40704
+ message: f.alertConf.text,
40705
+ type: f.alertConf.type,
40706
+ showIcon: true
40707
+ });
40708
+ }
40709
+ let {
40710
+ label,
40711
+ icon,
40712
+ position,
40713
+ ...groups
40714
+ } = f;
40715
+ groups = Object.keys(groups).reduce((items, key) => {
40716
+ if (!groups[key]?.meta?.excludeFromView) {
40717
+ items[key] = groups[key];
40718
+ }
40719
+ return items;
40720
+ }, {});
40721
+ const addedContent = [];
40722
+ const singleGroupsKeys = [].concat(...Object.keys(groupSingle(groups)).map(key => Object.keys(groupSingle(groups)[key])));
40723
+ return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
40724
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
40725
+ className: "wrapper",
40726
+ style: {
40727
+ width: fullWidth ? "100%" : 700
40728
+ },
40729
+ children: [f.alertConf ? /*#__PURE__*/jsxRuntime.jsx(antd.Alert, {
40730
+ className: "w-100",
40731
+ style: {
40732
+ marginBottom: "20px"
40733
+ },
40734
+ message: f.alertConf.text,
40735
+ type: alertType.includes(f.alertConf.type) ? f.alertConf.type : "info",
40736
+ showIcon: true
40737
+ }) : null, typeRender(groups, singleGroupsKeys, addedContent)]
40738
+ }, Date.now())
40739
+ });
40740
+ }
40741
+ };
40742
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
40743
+ className: "content",
40744
+ style: style,
40745
+ children: renderContent(form)
40746
+ });
40747
+ };
40748
+
40749
+ function Modal({
40750
+ t = text => text,
40751
+ open,
40752
+ title,
40753
+ children,
40754
+ onClose,
40755
+ onSuccess,
40756
+ cancelBtnText = "Cancel",
40757
+ saveBtnText = "Save",
40758
+ className,
40759
+ loading = false,
40760
+ disabled = false,
40761
+ withModalFormWrapper = true,
40762
+ ...props
40763
+ }) {
40764
+ return /*#__PURE__*/jsxRuntime.jsxs(antd.Modal, {
40765
+ width: 650,
40766
+ footer: null,
40767
+ open: open,
40768
+ onCancel: onClose,
40769
+ title: /*#__PURE__*/jsxRuntime.jsx(ModalHeader, {
40770
+ title: t(title)
40771
+ }),
40772
+ className: `${className}`,
40773
+ ...props,
40774
+ children: [withModalFormWrapper ? /*#__PURE__*/jsxRuntime.jsx("div", {
40775
+ className: "repeatable-modal-form",
40776
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40777
+ className: "daf-dynamic-form-form",
40778
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40779
+ className: "form",
40780
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
40781
+ className: "daf-dynamic-form dynamic-form",
40782
+ children: children
40783
+ })
40784
+ })
40785
+ })
40786
+ }) : children, onSuccess && onClose ? /*#__PURE__*/jsxRuntime.jsxs("div", {
40787
+ className: "daf-form-bottom",
40788
+ children: [onClose && /*#__PURE__*/jsxRuntime.jsx(antd.Button, {
40789
+ onClick: onClose,
40790
+ children: t(cancelBtnText)
40791
+ }), onSuccess && /*#__PURE__*/jsxRuntime.jsx(antd.Button, {
40792
+ type: "primary",
40793
+ onClick: onSuccess,
40794
+ disabled: loading || disabled,
40795
+ children: t(saveBtnText)
40796
+ })]
40797
+ }) : null]
40798
+ });
40799
+ }
40800
+
39903
40801
  class SourceService extends BaseService {
39904
40802
  get(tab, filters) {
39905
40803
  const {
@@ -39937,7 +40835,7 @@ class SourceService extends BaseService {
39937
40835
  });
39938
40836
  }
39939
40837
  }
39940
- createLazyService(SourceService);
40838
+ var SourceService$1 = createLazyService(SourceService);
39941
40839
 
39942
40840
  class VersionService extends BaseService {
39943
40841
  getSources({
@@ -39951,7 +40849,344 @@ class VersionService extends BaseService {
39951
40849
  });
39952
40850
  }
39953
40851
  }
39954
- createLazyService(VersionService);
40852
+ var VersionService$1 = createLazyService(VersionService);
40853
+
40854
+ const getSourcesType = subject => {
40855
+ const typeMapping = {
40856
+ locations: "location",
40857
+ location: "location",
40858
+ "production-sites": "location",
40859
+ stakeholders: "stakeholder",
40860
+ stakeholder: "stakeholder",
40861
+ workers: "stakeholder",
40862
+ operators: "stakeholder",
40863
+ documents: "document",
40864
+ document: "document",
40865
+ events: "event",
40866
+ event: "event",
40867
+ activities: "event",
40868
+ incidents: "event"
40869
+ };
40870
+ return typeMapping[subject] ?? null;
40871
+ };
40872
+
40873
+ const Records = ({
40874
+ onSubmit,
40875
+ modalTitle = "Records",
40876
+ t = () => {},
40877
+ onClose = () => {},
40878
+ open = false,
40879
+ subject = "",
40880
+ id = ""
40881
+ }) => {
40882
+ const [form] = antd.Form.useForm();
40883
+ const [sources, setSources] = React.useState([]);
40884
+ const [versions, setVersions] = React.useState([]);
40885
+ const [selectedSource, setSelectedSource] = React.useState(null);
40886
+ const handleCancel = () => {
40887
+ onClose();
40888
+ form.resetFields();
40889
+ };
40890
+ const type = React.useMemo(() => getSourcesType(subject), [subject]);
40891
+ const getSources = async () => {
40892
+ try {
40893
+ const {
40894
+ data
40895
+ } = await SourceService$1.getSources({
40896
+ type,
40897
+ id
40898
+ });
40899
+ setSources(data);
40900
+ } catch (error) {
40901
+ console.error('Error fetching sources:', error);
40902
+ }
40903
+ };
40904
+ const getVersions = async () => {
40905
+ try {
40906
+ const {
40907
+ data
40908
+ } = await VersionService$1.getSources({
40909
+ type,
40910
+ id,
40911
+ params: {
40912
+ source: selectedSource
40913
+ }
40914
+ });
40915
+ console.log({
40916
+ data
40917
+ });
40918
+ setVersions(data);
40919
+ } catch (error) {
40920
+ console.error('Error fetching versions:', error);
40921
+ }
40922
+ };
40923
+ const sourceOptions = React.useMemo(() => {
40924
+ return sources.map(source => ({
40925
+ label: source?.name,
40926
+ value: source?.id
40927
+ }));
40928
+ }, [sources]);
40929
+ React.useEffect(() => {
40930
+ if (type && id) {
40931
+ getSources();
40932
+ }
40933
+ }, [type, id]);
40934
+ React.useEffect(() => {
40935
+ if (selectedSource) {
40936
+ getVersions();
40937
+ }
40938
+ }, [selectedSource]);
40939
+ const versionOptions = React.useMemo(() => {
40940
+ if (!versions?.numberOfVersions) return [];
40941
+ return Array.from({
40942
+ length: versions.numberOfVersions
40943
+ }, (_, index) => ({
40944
+ label: `Version ${index + 1}`,
40945
+ value: index + 1
40946
+ }));
40947
+ }, [versions]);
40948
+ const handleOk = async () => {
40949
+ try {
40950
+ const values = await form.validateFields();
40951
+ if (onSubmit) {
40952
+ onSubmit(values);
40953
+ }
40954
+ onClose();
40955
+ form.resetFields();
40956
+ } catch (error) {
40957
+ console.error('Validation failed:', error);
40958
+ }
40959
+ };
40960
+ return /*#__PURE__*/jsxRuntime.jsxs(Modal, {
40961
+ open: open,
40962
+ t: t,
40963
+ title: t(modalTitle),
40964
+ onSuccess: handleOk,
40965
+ onClose: handleCancel,
40966
+ withModalFormWrapper: false,
40967
+ children: [/*#__PURE__*/jsxRuntime.jsxs(antd.Form, {
40968
+ form: form,
40969
+ layout: "vertical",
40970
+ name: "recordsForm",
40971
+ children: [/*#__PURE__*/jsxRuntime.jsx(antd.Form.Item, {
40972
+ name: "source",
40973
+ label: t("Source"),
40974
+ rules: [{
40975
+ required: true,
40976
+ message: t('Please select an option')
40977
+ }],
40978
+ children: /*#__PURE__*/jsxRuntime.jsx(antd.Select, {
40979
+ placeholder: t("Select"),
40980
+ showSearch: true,
40981
+ optionFilterProp: "children",
40982
+ onChange: value => {
40983
+ console.log('Selected source ID:', value);
40984
+ setSelectedSource(value);
40985
+ },
40986
+ children: sourceOptions.map(option => /*#__PURE__*/jsxRuntime.jsx(antd.Select.Option, {
40987
+ value: option.value,
40988
+ children: option.label
40989
+ }, option.value))
40990
+ })
40991
+ }), /*#__PURE__*/jsxRuntime.jsx(antd.Form.Item, {
40992
+ name: "version",
40993
+ label: t("Version"),
40994
+ rules: [{
40995
+ required: true,
40996
+ message: t('Please select an option')
40997
+ }],
40998
+ children: /*#__PURE__*/jsxRuntime.jsx(antd.Select, {
40999
+ placeholder: t("Select"),
41000
+ showSearch: true,
41001
+ optionFilterProp: "children",
41002
+ children: versionOptions.map(option => /*#__PURE__*/jsxRuntime.jsx(antd.Select.Option, {
41003
+ value: option.value,
41004
+ children: option.label
41005
+ }, option.value))
41006
+ })
41007
+ })]
41008
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
41009
+ style: {
41010
+ height: 60
41011
+ }
41012
+ })]
41013
+ });
41014
+ };
41015
+
41016
+ const Navigation = ({
41017
+ form = {},
41018
+ data = {},
41019
+ group = null,
41020
+ subsection = null,
41021
+ search = null,
41022
+ onGroupChange = () => {},
41023
+ mod,
41024
+ // TODO: ADD this
41025
+ goTo,
41026
+ params,
41027
+ generatePath,
41028
+ getRedirectLink
41029
+ }) => {
41030
+ const [selectedGroup, setSelectedGroup] = React.useState(null);
41031
+ const [formGroups, setFormGroups] = React.useState([]);
41032
+ const [openKeys, setOpenKeys] = React.useState([]);
41033
+ const hasSubSections = f => Object.keys(f).map(key => propHasValue$1(f[key].subSection)).includes(true);
41034
+ const mapFormGroup = f => Object.keys(f).map(key => {
41035
+ const {
41036
+ label,
41037
+ showFormIf,
41038
+ position
41039
+ } = f[key];
41040
+ const disabled = getDisabled({
41041
+ disabled: f[key]?.title?.meta?.disabled || false,
41042
+ groupCheckboxDisableKey: f[key]?.title?.meta?.groupCheckboxDisableKey,
41043
+ data
41044
+ });
41045
+ const fConf = {
41046
+ key,
41047
+ label,
41048
+ showFormIf,
41049
+ show: filterForm(f[key], data),
41050
+ items: [],
41051
+ disabled: disabled || false,
41052
+ position
41053
+ };
41054
+ if (hasSubSections(f[key])) {
41055
+ fConf.items = {};
41056
+ const items = groupSubsections(f[key], true);
41057
+ Object.keys(items).forEach(i => {
41058
+ items[i].show = filterForm(items[i], data);
41059
+ fConf.items[i] = items[i];
41060
+ });
41061
+ }
41062
+ return fConf;
41063
+ });
41064
+ React.useEffect(() => {
41065
+ const formG = mapFormGroup(form).sort((a, b) => (a.position || 0) - (b.position || 0));
41066
+ const keys = [];
41067
+ formG.forEach(f => {
41068
+ if (!keys.includes(f.key)) {
41069
+ keys.push(f.key);
41070
+ }
41071
+ if (f.items) {
41072
+ Object.keys(f.items).forEach(item => {
41073
+ if (!keys.includes(`${f.key}/${item}`)) {
41074
+ keys.push(`${f.key}/${item}`);
41075
+ }
41076
+ });
41077
+ }
41078
+ });
41079
+ let sGroup = group;
41080
+ if (!group && formG.length) {
41081
+ sGroup = formG[0].key;
41082
+ }
41083
+ if (subsection && keys.includes(`${sGroup}/${subsection}`)) {
41084
+ sGroup = `${sGroup}/${subsection}`;
41085
+ }
41086
+ if (sGroup === selectedGroup) {
41087
+ groupChanged();
41088
+ }
41089
+ setFormGroups(formG);
41090
+ if (!keys.includes(sGroup)) {
41091
+ sGroup = keys[0];
41092
+ }
41093
+ setSelectedGroup(sGroup);
41094
+ }, [form, group, subsection]);
41095
+ React.useEffect(() => {
41096
+ groupChanged();
41097
+ }, [selectedGroup]);
41098
+
41099
+ // useEffect(() => {
41100
+ // if (!selectedGroup && !formGroups.map(f => f.key).includes(selectedGroup)) {
41101
+ // setSelectedGroup(formGroups.map(f => f.key)[0]);
41102
+ // }
41103
+ // }, [formGroups])
41104
+
41105
+ const groupChanged = () => {
41106
+ if (selectedGroup) {
41107
+ onGroupChange(selectedGroup);
41108
+ if (selectedGroup !== group) {
41109
+ // const path = formPaths.view(mod, getRedirectLink);
41110
+ const [section, subSection, subgroup] = selectedGroup.split('/');
41111
+ let url;
41112
+ if (params.formId) {
41113
+ // Dynamic context (within a project : monitoring, restoration, engagement, etc.)
41114
+ url = `/app/${params.namespace}/${params.id}/${params.subsection}/view/general/${params.formId}/${section}`;
41115
+ } else {
41116
+ // Default: organisation context
41117
+ const path = formPaths.view(mod, getRedirectLink);
41118
+ url = `${generatePath(path, {
41119
+ ...params,
41120
+ group: section,
41121
+ subsection: subSection,
41122
+ subgroup: subgroup || undefined
41123
+ })}${search || ''}`;
41124
+ }
41125
+ goTo(url);
41126
+ }
41127
+ }
41128
+ setTimeout(() => {
41129
+ const groups = Array.from(document.getElementsByClassName('group'));
41130
+ const rows = Array.from(document.querySelectorAll('.repetable-row-extra'));
41131
+ rows.forEach(row => {
41132
+ const inputs = Array.from(row.querySelectorAll('.input'));
41133
+ const lasts = getLastRow(inputs.map((i, ind) => ind), 4);
41134
+ if (lasts) {
41135
+ lasts.forEach(index => inputs[index].classList.add('last'));
41136
+ }
41137
+ });
41138
+ groups.forEach(group => {
41139
+ // const isRepeatable = Array.from(group.classList).includes('repeatable');
41140
+ const inputs = Array.from(group.querySelectorAll('.input'));
41141
+ // if (inputs.length && !isRepeatable) {
41142
+ // if (inputs.length % 2 === 0) {
41143
+ // inputs[inputs.length - 1].classList.add('last');
41144
+ // inputs[inputs.length - 2].classList.add('last');
41145
+ // } else {
41146
+ // inputs[inputs.length - 1].classList.add('last');
41147
+ // }
41148
+ // }
41149
+ // remove groups without inputs
41150
+ if (!inputs.length) {
41151
+ group.remove();
41152
+ }
41153
+ });
41154
+ }, 200);
41155
+ };
41156
+ return selectedGroup ? /*#__PURE__*/jsxRuntime.jsx(antd.Menu, {
41157
+ mode: "inline",
41158
+ defaultSelectedKeys: [selectedGroup],
41159
+ selectedKeys: [selectedGroup],
41160
+ defaultOpenKeys: selectedGroup ? [selectedGroup.split('/')[0]] : [],
41161
+ openKeys: openKeys,
41162
+ onOpenChange: oKeys => {
41163
+ setOpenKeys(oKeys);
41164
+ },
41165
+ style: {
41166
+ overflowY: 'auto',
41167
+ overflowX: 'hidden'
41168
+ },
41169
+ onSelect: g => {
41170
+ setSelectedGroup(g.key);
41171
+ },
41172
+ 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, {
41173
+ title: getInputLabel$2(key, data),
41174
+ children: Object.keys(key.items).filter(item => key.items[item].show).map(item => /*#__PURE__*/jsxRuntime.jsx(antd.Menu.Item, {
41175
+ level: 2,
41176
+ children: getInputLabel$2(key.items[item], data)
41177
+ }, `${key.key}/${item}`))
41178
+ }, key.key) : /*#__PURE__*/jsxRuntime.jsx(antd.Menu.Item, {
41179
+ disabled: key.disabled,
41180
+ onClick: props => {
41181
+ if (params.subgroup && params.group === props.key) {
41182
+ const path = formPaths.view(mod, getRedirectLink);
41183
+ goTo(`${generatePath(path, params)}${search || ''}`);
41184
+ }
41185
+ },
41186
+ children: getInputLabel$2(key, data)
41187
+ }, key.key))
41188
+ }) : null;
41189
+ };
39955
41190
 
39956
41191
  styled__default["default"](antd.Select)`
39957
41192
  width: 100%;
@@ -44564,7 +45799,7 @@ const CommunityParticipation = ({
44564
45799
  const ACTIVITIES_TAB$1 = 'activities';
44565
45800
  const PARTNERS_TAB$1 = 'partners';
44566
45801
  const INCIDENTS_TAB$1 = 'incidents';
44567
- const getColumns = ({
45802
+ const getColumns$1 = ({
44568
45803
  projectId,
44569
45804
  t,
44570
45805
  show = 'show',
@@ -45245,7 +46480,7 @@ const AssociatedInformation = ({
45245
46480
  const handleTabChange = React.useCallback(value => {
45246
46481
  setActiveTab(value);
45247
46482
  }, []);
45248
- const columns = React.useMemo(() => getColumns({
46483
+ const columns = React.useMemo(() => getColumns$1({
45249
46484
  t,
45250
46485
  activeTab,
45251
46486
  view: activeTab,
@@ -45915,6 +47150,1089 @@ const MineSummary = ({
45915
47150
  });
45916
47151
  };
45917
47152
 
47153
+ const useViewUrlParams = ({
47154
+ params,
47155
+ push,
47156
+ pathname,
47157
+ search,
47158
+ searchParams,
47159
+ setSearchParams
47160
+ }) => {
47161
+ const [namespace, setNamespace] = React.useState(params?.namespace);
47162
+ const [id, setId] = React.useState(params?.id);
47163
+ const [group, setGroup] = React.useState(params?.group);
47164
+ const [subsection, setSubSection] = React.useState(params?.subsection);
47165
+ const sourceUrl = searchParams.get("source");
47166
+ const versionUrl = searchParams.get("version");
47167
+ const [source, setSource] = React.useState(sourceUrl || null);
47168
+ const [version, setVersion] = React.useState(versionUrl || null);
47169
+ React.useEffect(() => {
47170
+ if (id && params.id !== id || namespace && namespace !== params.namespace) {
47171
+ setGroup(undefined);
47172
+ setSubSection(undefined);
47173
+ // setSubGroup(undefined);
47174
+ } else {
47175
+ setGroup(params.group);
47176
+ setSubSection(params.subsection);
47177
+ // setSubGroup(params.subgroup);
47178
+ }
47179
+ setNamespace(params.namespace);
47180
+ setId(params.id);
47181
+ }, [params]);
47182
+ React.useEffect(() => {
47183
+ if (source && version) {
47184
+ const newParams = new URLSearchParams(searchParams);
47185
+ newParams.set("source", source);
47186
+ newParams.set("version", version);
47187
+ setSearchParams(newParams);
47188
+ }
47189
+ }, [source, version]);
47190
+ const goBackFromSource = React.useCallback(() => {
47191
+ const params = new URLSearchParams(searchParams);
47192
+ params.delete("source");
47193
+ params.delete("version");
47194
+ setSearchParams(params);
47195
+ setVersion(null);
47196
+ setSource(null);
47197
+ }, [searchParams, setSearchParams]);
47198
+ const getEditLink = React.useCallback(srcId => {
47199
+ const r = new RegExp(`\/view\/`);
47200
+ const [previous, extra] = pathname.split(r);
47201
+ if (srcId) {
47202
+ push(`${previous}/edit/${extra}?sourceId=${srcId}`);
47203
+ return;
47204
+ }
47205
+ if (search) {
47206
+ push(`${previous}/edit/${extra}${search}`);
47207
+ } else {
47208
+ push(`${previous}/edit/${extra}`);
47209
+ }
47210
+ }, [pathname, search, push]);
47211
+ const match = React.useMemo(() => ({
47212
+ params,
47213
+ path: pathname
47214
+ }), [params, pathname]);
47215
+ return {
47216
+ namespace,
47217
+ id,
47218
+ group,
47219
+ subsection,
47220
+ params,
47221
+ source,
47222
+ setSource,
47223
+ sourceUrl,
47224
+ version,
47225
+ setVersion,
47226
+ versionUrl,
47227
+ goBackFromSource,
47228
+ getEditLink,
47229
+ match,
47230
+ search
47231
+ };
47232
+ };
47233
+
47234
+ const usePrepareForm = ({
47235
+ namespaceConfig,
47236
+ allData,
47237
+ id,
47238
+ namespace,
47239
+ t,
47240
+ mode,
47241
+ APP,
47242
+ viewConfig
47243
+ }) => {
47244
+ const [form, setForm] = React.useState({});
47245
+ const [data, setData] = React.useState({});
47246
+ const [groups, setGroups] = React.useState({});
47247
+ const [linkingForms, setLinkingForms] = React.useState({});
47248
+ const [loading, setLoading] = React.useState(true);
47249
+ const [notFound, setNotFound] = React.useState(false);
47250
+ const prepareForm = currentView => {
47251
+ const dKey = namespaceConfig?.dataKey;
47252
+ const nKey = `${APP}-${currentView}`;
47253
+ if (hasKeyInObject(allData, dKey) && hasKeyInObject(allData[dKey], nKey)) {
47254
+ const {
47255
+ form = {},
47256
+ data = {},
47257
+ config = {},
47258
+ linkingForms = {}
47259
+ } = JSON.parse(JSON.stringify(allData[dKey][nKey] || {}));
47260
+ if (data.datastakeId === id || id === "user") {
47261
+ if (viewConfig.linkingSubjects.includes(namespace)) {
47262
+ setForm({
47263
+ ...form,
47264
+ linking: {
47265
+ position: 100,
47266
+ excludeFromEdit: true,
47267
+ label: t("Linked Subjects"),
47268
+ template: "linkingSubjects"
47269
+ }
47270
+ });
47271
+ } else {
47272
+ setForm(form);
47273
+ }
47274
+ setData(data);
47275
+ setGroups(config.groups || {});
47276
+ setLinkingForms(linkingForms);
47277
+ setLoading(false);
47278
+ setNotFound(false);
47279
+ } else if (!data.id) {
47280
+ if (mode === "proxy") {
47281
+ window.location.reload();
47282
+ } else {
47283
+ setLoading(false);
47284
+ setNotFound(true);
47285
+ }
47286
+ }
47287
+ }
47288
+ };
47289
+ const getCertainData = allData?.[namespaceConfig?.dataKey];
47290
+ React.useEffect(() => {
47291
+ if (namespace && namespaceConfig) {
47292
+ prepareForm(namespaceConfig?.view);
47293
+ }
47294
+ }, [getCertainData, namespaceConfig]);
47295
+ return {
47296
+ form,
47297
+ setForm,
47298
+ data,
47299
+ setData,
47300
+ groups,
47301
+ setGroups,
47302
+ linkingForms,
47303
+ setLinkingForms,
47304
+ loading,
47305
+ setLoading,
47306
+ notFound,
47307
+ setNotFound,
47308
+ prepareForm
47309
+ };
47310
+ };
47311
+
47312
+ const useViewPermissions = ({
47313
+ data,
47314
+ id,
47315
+ namespaceOverrides = {
47316
+ supportedNamespaces: {},
47317
+ canEdit: {}
47318
+ },
47319
+ namespace,
47320
+ user,
47321
+ push,
47322
+ getRedirectLink,
47323
+ namespaceConfig,
47324
+ APP,
47325
+ viewConfig
47326
+ }) => {
47327
+ const baseNamespaceKeys = Object.keys(namespaceConfig || {});
47328
+ const baseSupportedNamespaces = baseNamespaceKeys?.reduce((acc, key) => {
47329
+ acc[key] = () => true;
47330
+ return acc;
47331
+ }, {});
47332
+ const isSupportedNamespaces = React.useMemo(() => ({
47333
+ ...baseSupportedNamespaces,
47334
+ ...namespaceOverrides?.supportedNamespaces
47335
+ }), [data, id]);
47336
+ const isSupported = typeof isSupportedNamespaces[namespace] === "function" ? isSupportedNamespaces[namespace]() && viewConfig?.supportedNamespaces[APP] && viewConfig?.supportedNamespaces[APP]?.includes(namespace) : viewConfig?.supportedNamespaces[APP] && viewConfig?.supportedNamespaces[APP].includes(namespace);
47337
+ const isUserData = () => {
47338
+ return data && data.authorId && user?.company?.id === data.authorId;
47339
+ };
47340
+ const canEdit = React.useMemo(() => {
47341
+ const baseCanEditAction = baseNamespaceKeys.reduce((acc, key) => {
47342
+ acc[key] = () => isUserData();
47343
+ return acc;
47344
+ }, {});
47345
+ const canEditAction = {
47346
+ ...baseCanEditAction,
47347
+ ...namespaceOverrides.canEdit
47348
+ };
47349
+ return canEditAction[namespace] ? canEditAction[namespace]() : false;
47350
+ }, [namespace, data, user]);
47351
+ React.useEffect(() => {
47352
+ if (data) {
47353
+ if (typeof isSupportedNamespaces[namespace] === "function") {
47354
+ if (!isSupportedNamespaces[namespace]()) {
47355
+ push(getRedirectLink(`/app`));
47356
+ }
47357
+ }
47358
+ }
47359
+ }, [data, namespace]);
47360
+ return {
47361
+ isSupportedNamespaces,
47362
+ canEdit,
47363
+ isSupported
47364
+ };
47365
+ };
47366
+
47367
+ const submitSubjectData = async (namespace, data, serviceMap) => {
47368
+ const service = serviceMap[namespace];
47369
+ if (!service) {
47370
+ throw new Error(`No service found for namespace: ${namespace}`);
47371
+ }
47372
+ const response = await service.submitStep(data, data.datastakeId || data.id);
47373
+ return response.data;
47374
+ };
47375
+ const useSubmitSubject = ({
47376
+ namespace,
47377
+ data,
47378
+ serviceMap
47379
+ }) => {
47380
+ const [isDisabled, setIsDisabled] = React.useState(false);
47381
+ const [loading, setLoading] = React.useState(false);
47382
+ const [isPublished, setIsPublished] = React.useState(false);
47383
+ const submitSubject = React.useCallback(async () => {
47384
+ try {
47385
+ setLoading(true);
47386
+ const response = await submitSubjectData(namespace, data, serviceMap);
47387
+ setIsDisabled(response.published);
47388
+ setIsPublished(response.published);
47389
+ } catch (error) {
47390
+ console.error("Submit error:", error);
47391
+ } finally {
47392
+ setLoading(false);
47393
+ }
47394
+ }, [namespace, data]);
47395
+ return {
47396
+ submitSubject,
47397
+ isDisabled,
47398
+ submitLoading: loading,
47399
+ isPublished
47400
+ };
47401
+ };
47402
+
47403
+ const useCallToGetData = ({
47404
+ namespaceConfig,
47405
+ namespace,
47406
+ allData,
47407
+ id,
47408
+ isSupported,
47409
+ namespaceGet,
47410
+ source,
47411
+ version,
47412
+ user,
47413
+ setLoading,
47414
+ APP
47415
+ }) => {
47416
+ const isFirstRender = React.useRef(true);
47417
+ const callToGetData = (_doCall = false) => {
47418
+ const dKey = namespaceConfig?.dataKey;
47419
+ const nKey = `${APP}-${getNkey(namespace || "")}`;
47420
+ const doCall = _doCall ? true : hasKeyInObject(allData, dKey) && hasKeyInObject(allData[dKey], nKey) ? allData[dKey][nKey]?.data?.datastakeId !== id : true;
47421
+ if (doCall) {
47422
+ if (isSupported) {
47423
+ namespaceGet[namespace]();
47424
+ }
47425
+ }
47426
+ };
47427
+ React.useEffect(() => {
47428
+ if (isFirstRender.current) {
47429
+ isFirstRender.current = false;
47430
+ return;
47431
+ }
47432
+ callToGetData(true);
47433
+ }, [source, version]);
47434
+ React.useEffect(() => {
47435
+ callToGetData(true);
47436
+ }, [id, namespace, user.language]);
47437
+ const onStorageUpdate = e => {
47438
+ const {
47439
+ key,
47440
+ newValue
47441
+ } = e;
47442
+ if (key === `${id}-loading` && newValue) {
47443
+ setLoading(newValue);
47444
+ }
47445
+ if (key === `${id}-updated` && newValue) {
47446
+ setLoading(true);
47447
+ callToGetData();
47448
+ }
47449
+ };
47450
+ React.useEffect(() => {
47451
+ window.addEventListener("storage", onStorageUpdate);
47452
+ return () => {
47453
+ window.removeEventListener("storage", onStorageUpdate);
47454
+ };
47455
+ }, []);
47456
+
47457
+ // useEffect(() => {
47458
+ // setLoading(true);
47459
+ // }, [namespace]);
47460
+
47461
+ return {
47462
+ callToGetData
47463
+ };
47464
+ };
47465
+
47466
+ const useViewActions = ({
47467
+ namespace,
47468
+ data,
47469
+ isSupported,
47470
+ canEdit,
47471
+ versionUrl,
47472
+ sourceUrl,
47473
+ getEditLink,
47474
+ submitSubject,
47475
+ isDisabled,
47476
+ setOpenRecordsModal,
47477
+ goBackFromSource,
47478
+ push,
47479
+ getRedirectLink,
47480
+ t,
47481
+ viewConfig,
47482
+ buttonActions
47483
+ }) => {
47484
+ const [pageActions, setPageActions] = React.useState([]);
47485
+ const [extraPageActions, setExtraPageActions] = React.useState([]);
47486
+ React.useEffect(() => {
47487
+ const actions = [];
47488
+ const extraActions = [];
47489
+ if (!isSupported) {
47490
+ setPageActions([]);
47491
+ setExtraPageActions([]);
47492
+ return;
47493
+ }
47494
+ if (canEdit) {
47495
+ if (viewConfig.namespacesWithoutActionButtons.includes(namespace)) {
47496
+ if (viewConfig.editOnlyButton.includes(namespace)) {
47497
+ if (versionUrl && sourceUrl) {
47498
+ actions.push(buttonActions.createBackButton(t, goBackFromSource));
47499
+ } else {
47500
+ actions.push(buttonActions.createEditButton(t, getEditLink));
47501
+ }
47502
+ }
47503
+ } else {
47504
+ if (versionUrl && sourceUrl) {
47505
+ actions.push(buttonActions.createBackButton(t, goBackFromSource));
47506
+ } else {
47507
+ actions.push(buttonActions.createSubmitButton(t, submitSubject, isDisabled, data));
47508
+ actions.push(buttonActions.createEditButton(t, getEditLink));
47509
+ // actions.push(createRecordsButton(t, setOpenRecordsModal));
47510
+ }
47511
+ }
47512
+ }
47513
+ if (viewConfig.summaryNamespaces.includes(namespace)) {
47514
+ extraActions.push(buttonActions.createSummaryButton(t, namespace, data, push, getRedirectLink));
47515
+ extraActions.push(buttonActions.createRecordsButton(t, setOpenRecordsModal));
47516
+ }
47517
+ setPageActions(actions);
47518
+ setExtraPageActions(extraActions);
47519
+ }, [namespace, data, isSupported, canEdit, versionUrl, sourceUrl, isDisabled, t, getEditLink, submitSubject, goBackFromSource, setOpenRecordsModal, push, getRedirectLink]);
47520
+ return {
47521
+ pageActions,
47522
+ extraPageActions
47523
+ };
47524
+ };
47525
+
47526
+ const decapitalize = string => string && string.charAt(0).toLowerCase() + string.slice(1);
47527
+ const formatRedirectString = stringItem => {
47528
+ let string;
47529
+ if (stringItem.includes("nashiriki")) {
47530
+ string = decapitalize(stringItem?.replaceAll("nashiriki", ""));
47531
+ } else {
47532
+ string = stringItem;
47533
+ }
47534
+ return string;
47535
+ };
47536
+ const redirect = ({
47537
+ id,
47538
+ item
47539
+ }) => {
47540
+ const viewMode = "view";
47541
+ let type = "testimonials";
47542
+ if (item.category === "mineSite") {
47543
+ type = "scl";
47544
+ }
47545
+ if (item.stakeholderType === "operator") {
47546
+ type = "operators";
47547
+ }
47548
+ if (item.stakeholderType === "worker") {
47549
+ type = "workers";
47550
+ }
47551
+ if (item.form) {
47552
+ type = `${formatRedirectString(item.form)}s`;
47553
+ }
47554
+ let url = `/${viewMode}/${type}/${id}`;
47555
+ return `/app${url}`;
47556
+ };
47557
+ const renderType = ({
47558
+ item = {},
47559
+ t = s => s
47560
+ }) => {
47561
+ if (item.empty) {
47562
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
47563
+ className: "daf-default-cell"
47564
+ });
47565
+ }
47566
+ if (item.category === "mineSite") {
47567
+ return t("Mine Site");
47568
+ }
47569
+ if (item.stakeholderType === "operator") {
47570
+ return t("Operator");
47571
+ }
47572
+ if (item.stakeholderType === "worker") {
47573
+ return t("Worker");
47574
+ }
47575
+ if (item.form) {
47576
+ return t(capitalizeAll(item.form));
47577
+ }
47578
+ return "--";
47579
+ };
47580
+
47581
+ const getColumns = ({
47582
+ t,
47583
+ redirect = () => "",
47584
+ mod,
47585
+ mode = "app",
47586
+ options
47587
+ }) => [{
47588
+ title: "ID",
47589
+ dataIndex: "datastakeId",
47590
+ key: "datastakeId"
47591
+ }, {
47592
+ title: t("Type"),
47593
+ dataIndex: "type",
47594
+ key: "type",
47595
+ render: (type, all) => renderType({
47596
+ item: all,
47597
+ t,
47598
+ type
47599
+ })
47600
+ }, {
47601
+ title: t("Name"),
47602
+ dataIndex: "name",
47603
+ key: "name",
47604
+ render: (name, all) => {
47605
+ if (all.empty) {
47606
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
47607
+ className: "daf-default-cell"
47608
+ });
47609
+ }
47610
+ if (all?.form === "products") {
47611
+ const {
47612
+ minerals
47613
+ } = options;
47614
+ const mineral = minerals.find(mineral => mineral.value === all?.typeOfProduct)?.label;
47615
+ return mineral || "--";
47616
+ }
47617
+ return name || "--";
47618
+ }
47619
+ }, {
47620
+ title: t("Last Update"),
47621
+ dataIndex: "updatedAt",
47622
+ key: "updateAt",
47623
+ render: (updatedAt, all) => {
47624
+ if (all.empty) {
47625
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
47626
+ className: "daf-default-cell"
47627
+ });
47628
+ }
47629
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
47630
+ className: "daf-default-cell",
47631
+ children: renderDateFormatted(updatedAt, "DD MMM YYYY")
47632
+ });
47633
+ }
47634
+ }, {
47635
+ title: "",
47636
+ dataIndex: "actions",
47637
+ width: 50,
47638
+ key: "actions",
47639
+ render: (_, all) => {
47640
+ if (all.empty) {
47641
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
47642
+ className: "daf-default-cell"
47643
+ });
47644
+ }
47645
+ return mode === "proxy" ? /*#__PURE__*/jsxRuntime.jsx("a", {
47646
+ onClick: () => redirect({
47647
+ id: all.datastakeId,
47648
+ type: all.type,
47649
+ mod,
47650
+ mode,
47651
+ item: all
47652
+ }),
47653
+ href: "#",
47654
+ children: /*#__PURE__*/jsxRuntime.jsx(CustomIcon, {
47655
+ name: "LinkNewTab",
47656
+ width: 14,
47657
+ height: 14,
47658
+ color: "#6C737F"
47659
+ })
47660
+ }) : /*#__PURE__*/jsxRuntime.jsx("a", {
47661
+ href: redirect({
47662
+ id: all.datastakeId,
47663
+ type: all.type,
47664
+ mod,
47665
+ mode,
47666
+ item: all
47667
+ }),
47668
+ target: "_blank",
47669
+ rel: "noreferrer",
47670
+ children: /*#__PURE__*/jsxRuntime.jsx(CustomIcon, {
47671
+ name: "LinkNewTab",
47672
+ width: 14,
47673
+ height: 14,
47674
+ color: "#6C737F"
47675
+ })
47676
+ });
47677
+ }
47678
+ }];
47679
+
47680
+ const getNamespace = namespace => {
47681
+ let _namespace = namespace;
47682
+ switch (namespace) {
47683
+ case "locations":
47684
+ _namespace = "location";
47685
+ break;
47686
+ case "stakeholders":
47687
+ _namespace = "stakeholder";
47688
+ break;
47689
+ case "documents":
47690
+ _namespace = "document";
47691
+ break;
47692
+ case "nashirikiEvent":
47693
+ case "events":
47694
+ _namespace = "event";
47695
+ break;
47696
+ }
47697
+ return _namespace;
47698
+ };
47699
+ class LinkedSubjectsService extends BaseService {
47700
+ getForm({
47701
+ namespace
47702
+ }, language = "en", scope) {
47703
+ return this.apiGet({
47704
+ url: `forms/${namespace === "documents" ? namespace : getNamespace(namespace)}`,
47705
+ isApp: true,
47706
+ params: {
47707
+ scope: scope || "create",
47708
+ language
47709
+ }
47710
+ });
47711
+ }
47712
+ getWithModule({
47713
+ query,
47714
+ signal,
47715
+ namespace
47716
+ }) {
47717
+ const _namespace = getNamespace(namespace);
47718
+ return this.apiGet({
47719
+ url: `/${_namespace}`,
47720
+ isApp: true,
47721
+ params: query,
47722
+ signal
47723
+ });
47724
+ }
47725
+ getOne({
47726
+ id,
47727
+ signal,
47728
+ namespace,
47729
+ sourceId,
47730
+ source,
47731
+ version
47732
+ }) {
47733
+ return this.apiGet({
47734
+ url: `/${namespace === "nashirikiEvent" ? "event" : namespace}/${id}`,
47735
+ isApp: true,
47736
+ signal,
47737
+ params: {
47738
+ authorId: sourceId,
47739
+ source,
47740
+ version
47741
+ }
47742
+ });
47743
+ }
47744
+ getData(query, namespace) {
47745
+ return this.apiGet({
47746
+ url: `/${namespace}/data`,
47747
+ isApp: true,
47748
+ params: query
47749
+ });
47750
+ }
47751
+ save(payload, namespace) {
47752
+ if (payload.datastakeId) {
47753
+ let _namespace = getNamespace(namespace);
47754
+ const keysToRemove = ['associatedSubjects', 'authorId', 'channels', 'form', 'createdAt', 'meta', 'module', 'updatedAt', 'published', 'version', 'sbgi'];
47755
+ const filteredData = removeKeysFromObject(payload, keysToRemove);
47756
+ return this.apiPut({
47757
+ url: `/${_namespace}/${filteredData.id}`,
47758
+ isApp: true,
47759
+ data: filterCreateData(filteredData)
47760
+ });
47761
+ }
47762
+ return this.apiPost({
47763
+ url: `/${getNamespace(namespace)}`,
47764
+ isApp: true,
47765
+ data: payload
47766
+ });
47767
+ }
47768
+ remove(id, data, namespace, mod) {
47769
+ if (mod) {
47770
+ return this.apiDelete({
47771
+ url: `/${namespace}/${id}`,
47772
+ isApp: true,
47773
+ data: data
47774
+ });
47775
+ }
47776
+ return this.apiDelete({
47777
+ url: `/${namespace}/${id}/remove`,
47778
+ data: data
47779
+ });
47780
+ }
47781
+ getLinkedSubjects({
47782
+ namespace,
47783
+ id
47784
+ }) {
47785
+ const _namespace = getNamespace(namespace);
47786
+ return this.apiGet({
47787
+ url: `/${namespace === "events" ? "event" : _namespace}/${id}/linkedSubjects`,
47788
+ isApp: true
47789
+ });
47790
+ }
47791
+ getOptions() {
47792
+ return this.apiGet({
47793
+ url: `/forms/options`,
47794
+ isApp: true,
47795
+ params: {
47796
+ id: "categoryOptions,eventsType,locationCategories,countries,category,subCategory,optionPositionSupplyChain"
47797
+ }
47798
+ });
47799
+ }
47800
+ }
47801
+ var LinkedSubjectsService$1 = createLazyService(LinkedSubjectsService);
47802
+
47803
+ const emptyObject = {};
47804
+ const LinkingTemplate = ({
47805
+ conf,
47806
+ namespace
47807
+ }) => {
47808
+ const view = React.useMemo(() => conf?.location?.pathname?.split(`/app/${conf.mod}/`)[1], [conf]);
47809
+ const {
47810
+ pagination,
47811
+ onTableChange,
47812
+ totalPages,
47813
+ canGoNext,
47814
+ canGoPrev,
47815
+ setPagination,
47816
+ goPrev,
47817
+ goNext
47818
+ } = useFilters({
47819
+ module: conf.mod,
47820
+ view,
47821
+ selectFiltersConfig: emptyObject,
47822
+ filtersConfig: emptyObject
47823
+ });
47824
+ const columns = React.useMemo(() => getColumns({
47825
+ t: conf.t,
47826
+ redirect,
47827
+ mod: conf.mod,
47828
+ language: conf.user?.language,
47829
+ mode: conf.mode,
47830
+ options: conf.options
47831
+ }), [conf]);
47832
+ const id = conf.allData.id;
47833
+ const dataSource = conf?.linkingTemplateContextData?.[id];
47834
+ const changeData = async () => {
47835
+ try {
47836
+ const _data = await LinkedSubjectsService$1.getLinkedSubjects({
47837
+ namespace,
47838
+ id,
47839
+ mod: conf.mod
47840
+ });
47841
+ const data = (_data?.data || []).map((d, i) => ({
47842
+ ...d,
47843
+ key: `${d.id}-${i}`
47844
+ }));
47845
+ conf?.addData(id, data);
47846
+ setPagination(prev => ({
47847
+ ...prev,
47848
+ current: 1,
47849
+ total: data.length ? data.length : 1
47850
+ }));
47851
+ } catch (err) {
47852
+ console.log(err);
47853
+ }
47854
+ };
47855
+ const _dataSource = React.useMemo(() => {
47856
+ const startIndex = pagination.pageSize * (pagination.current - 1);
47857
+ const endIndex = Math.min(startIndex + pagination.pageSize, dataSource?.length || 0);
47858
+ return [...(dataSource || [])].slice(startIndex, endIndex);
47859
+ }, [pagination, dataSource]);
47860
+ React.useEffect(() => {
47861
+ if (!dataSource) {
47862
+ changeData();
47863
+ } else {
47864
+ setPagination(prev => ({
47865
+ ...prev,
47866
+ current: 1,
47867
+ total: dataSource.length ? dataSource.length : 1
47868
+ }));
47869
+ }
47870
+ }, []);
47871
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
47872
+ className: formatClassname(["content", "documents-layout"]),
47873
+ style: {},
47874
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
47875
+ className: "view-header",
47876
+ style: {
47877
+ flexDirection: "column",
47878
+ paddingTop: 0
47879
+ },
47880
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
47881
+ className: "daf-table-wrapper pagination-no-padding",
47882
+ children: [/*#__PURE__*/jsxRuntime.jsx(DAFTable, {
47883
+ className: "mt-0 p-0",
47884
+ columns: columns,
47885
+ hideOnLoading: false,
47886
+ data: _dataSource,
47887
+ doEmptyRows: true,
47888
+ loading: !dataSource,
47889
+ rowKey: "key",
47890
+ pagination: pagination,
47891
+ size: "small"
47892
+ }), /*#__PURE__*/jsxRuntime.jsx(Pagination, {
47893
+ t: conf?.t,
47894
+ isMobile: conf?.isMobile,
47895
+ page: pagination.current,
47896
+ totalPages: totalPages,
47897
+ goPrev: goPrev,
47898
+ goNext: goNext,
47899
+ canGoNext: canGoNext,
47900
+ canGoPrev: canGoPrev,
47901
+ totalItems: pagination.total,
47902
+ doTotalItems: true,
47903
+ onChangePagination: val => {
47904
+ onTableChange({
47905
+ ...pagination,
47906
+ current: 1,
47907
+ pageSize: val
47908
+ });
47909
+ },
47910
+ perPage: pagination.pageSize,
47911
+ arrowIcons: true
47912
+ })]
47913
+ })
47914
+ })
47915
+ });
47916
+ };
47917
+
47918
+ /* eslint-disable react/prop-types */
47919
+ function Template({
47920
+ conf,
47921
+ namespace
47922
+ }) {
47923
+ switch (namespace) {
47924
+ case 'locations':
47925
+ case 'documents':
47926
+ case 'stakeholders':
47927
+ case 'events':
47928
+ return /*#__PURE__*/jsxRuntime.jsx(LinkingTemplate, {
47929
+ conf: conf,
47930
+ namespace: namespace
47931
+ });
47932
+ default:
47933
+ return null;
47934
+ }
47935
+ }
47936
+
47937
+ const View = ({
47938
+ push,
47939
+ getRedirectLink,
47940
+ allData,
47941
+ ajaxForms,
47942
+ changeAjaxForms,
47943
+ t,
47944
+ namespaceConfiguration,
47945
+ params,
47946
+ pathname,
47947
+ search,
47948
+ searchParams,
47949
+ setSearchParams,
47950
+ mode = "app",
47951
+ APP,
47952
+ viewConfig,
47953
+ partners,
47954
+ setSelectedPartners,
47955
+ user,
47956
+ serviceMap,
47957
+ actionMap,
47958
+ goBack,
47959
+ breadcrumbs,
47960
+ theme,
47961
+ buttonActions,
47962
+ generatePath,
47963
+ getApiBaseUrl,
47964
+ getAppHeader,
47965
+ location,
47966
+ isMobile,
47967
+ linkingTemplateContextData,
47968
+ addData,
47969
+ options,
47970
+ getSubjectsDetails
47971
+ // ADD CALLBACK TO GET THE CURRENT NAMESPACE CONFIG
47972
+ }) => {
47973
+ const getNamespaceConfig = namespace => namespaceConfiguration?.[namespace] || {};
47974
+ const [openRecordsModal, setOpenRecordsModal] = React.useState(false);
47975
+
47976
+ // HANDLES THE URL PARAMS FOR THE VIEW PAGE
47977
+ const {
47978
+ namespace,
47979
+ id,
47980
+ group,
47981
+ subsection,
47982
+ source,
47983
+ setSource,
47984
+ sourceUrl,
47985
+ version,
47986
+ setVersion,
47987
+ versionUrl,
47988
+ goBackFromSource,
47989
+ getEditLink,
47990
+ match
47991
+ } = useViewUrlParams({
47992
+ params,
47993
+ push,
47994
+ pathname,
47995
+ search,
47996
+ searchParams,
47997
+ setSearchParams
47998
+ });
47999
+ const namespaceConfig = React.useMemo(() => getNamespaceConfig(namespace), [namespace]);
48000
+
48001
+ // PREPARES THE FORM FOR THE VIEW PAGE
48002
+ const {
48003
+ form,
48004
+ data,
48005
+ groups,
48006
+ linkingForms,
48007
+ loading,
48008
+ setLoading,
48009
+ notFound
48010
+ } = usePrepareForm({
48011
+ namespaceConfig,
48012
+ allData,
48013
+ id,
48014
+ namespace,
48015
+ t,
48016
+ mode,
48017
+ APP,
48018
+ viewConfig
48019
+ });
48020
+ const {
48021
+ canEdit,
48022
+ isSupported
48023
+ } = useViewPermissions({
48024
+ data,
48025
+ id,
48026
+ namespace,
48027
+ user,
48028
+ push,
48029
+ getRedirectLink,
48030
+ namespaceConfig: namespaceConfiguration,
48031
+ APP,
48032
+ viewConfig
48033
+ });
48034
+ const groupForm = React.useMemo(() => {
48035
+ const gF = form[group] || {};
48036
+ if (subsection) {
48037
+ const sectionForms = groupSubsections(gF);
48038
+ if (sectionForms[subsection]) {
48039
+ return sectionForms[subsection];
48040
+ }
48041
+ }
48042
+ return gF;
48043
+ }, [form, group, subsection]);
48044
+ const {
48045
+ submitSubject,
48046
+ isDisabled,
48047
+ submitLoading,
48048
+ isPublished
48049
+ } = useSubmitSubject({
48050
+ namespace,
48051
+ data,
48052
+ serviceMap
48053
+ });
48054
+ const {
48055
+ pageActions,
48056
+ extraPageActions
48057
+ } = useViewActions({
48058
+ namespace,
48059
+ data,
48060
+ isSupported,
48061
+ canEdit,
48062
+ versionUrl,
48063
+ sourceUrl,
48064
+ getEditLink,
48065
+ submitSubject,
48066
+ isDisabled,
48067
+ setOpenRecordsModal,
48068
+ goBackFromSource,
48069
+ push,
48070
+ getRedirectLink,
48071
+ t,
48072
+ viewConfig,
48073
+ buttonActions
48074
+ });
48075
+ React.useEffect(() => {
48076
+ if (namespace && id && namespaceConfig && typeof getSubjectsDetails === 'function') {
48077
+ getSubjectsDetails({
48078
+ namespace,
48079
+ id,
48080
+ namespaceConfig
48081
+ });
48082
+ }
48083
+ }, [namespace, id, namespaceConfig]);
48084
+ const action = React.useMemo(() => actionMap?.[namespaceConfig?.action], [namespaceConfig?.action, actionMap]);
48085
+ const namespaceGet = {
48086
+ [namespace]: () => {
48087
+ return action?.({
48088
+ namespace: namespaceConfig?.namespace,
48089
+ module: APP,
48090
+ view: namespaceConfig?.view,
48091
+ ...(namespaceConfig?.scope && {
48092
+ scope: namespaceConfig.scope
48093
+ }),
48094
+ datastakeId: id,
48095
+ version,
48096
+ source
48097
+ });
48098
+ }
48099
+ };
48100
+ useCallToGetData({
48101
+ namespaceConfig,
48102
+ namespace,
48103
+ allData,
48104
+ id,
48105
+ isSupported,
48106
+ namespaceGet,
48107
+ source,
48108
+ version,
48109
+ user,
48110
+ setLoading,
48111
+ APP
48112
+ });
48113
+ const extraLinking = React.useMemo(() => {
48114
+ return null;
48115
+ }, [namespace, match, data]);
48116
+ const sourceOptions = React.useMemo(() => {
48117
+ return partners.map(partner => {
48118
+ const isOwnData = partner.id === user?.company?.id;
48119
+ return {
48120
+ label: partner.nickName,
48121
+ value: partner.id,
48122
+ avatar: isOwnData ? /*#__PURE__*/jsxRuntime.jsx("span", {
48123
+ children: "OWN"
48124
+ }) : undefined,
48125
+ background: isOwnData ? theme.colorPrimary7 : undefined,
48126
+ color: isOwnData ? "white" : undefined
48127
+ };
48128
+ });
48129
+ }, [partners, user]);
48130
+ const actionButtons = React.useMemo(() => {
48131
+ return groupForm?.template === "linkingSubjects" ? pageActions.filter(v => v.key !== "edit") : pageActions;
48132
+ }, [groupForm, pageActions]);
48133
+ if (!isSupported || notFound) {
48134
+ return /*#__PURE__*/jsxRuntime.jsx(Loading, {});
48135
+ }
48136
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
48137
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
48138
+ className: "daf-view-form",
48139
+ children: [/*#__PURE__*/jsxRuntime.jsx(DAFHeader, {
48140
+ title: data?.name || "",
48141
+ breadcrumbs: breadcrumbs,
48142
+ goBackTo: goBack,
48143
+ actionButtons: actionButtons,
48144
+ extraButtons: extraPageActions,
48145
+ addedHeaderFirst: true,
48146
+ addedHeader: /*#__PURE__*/jsxRuntime.jsx("div", {
48147
+ className: "flex flex-row gap-4",
48148
+ style: {
48149
+ marginRight: 8
48150
+ },
48151
+ children: /*#__PURE__*/jsxRuntime.jsx(Multiselect, {
48152
+ options: [...sourceOptions],
48153
+ isAvatarGroup: true,
48154
+ selectionType: "checkbox",
48155
+ canUnselectLast: false,
48156
+ onChange: selected => {
48157
+ setSelectedPartners(prev => ({
48158
+ ...prev,
48159
+ partners: selected,
48160
+ loading: false
48161
+ }));
48162
+ },
48163
+ dropDownWidth: 200,
48164
+ defaultSelected: (partners || []).map(p => p.id) || []
48165
+ }, partners?.length)
48166
+ })
48167
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
48168
+ className: "view-content",
48169
+ children: [/*#__PURE__*/jsxRuntime.jsx(Navigation, {
48170
+ mod: APP,
48171
+ data: data,
48172
+ match: match,
48173
+ form: form,
48174
+ group: group,
48175
+ subsection: subsection,
48176
+ search: search,
48177
+ goTo: push,
48178
+ getRedirectLink: getRedirectLink,
48179
+ generatePath: generatePath,
48180
+ params: params
48181
+ }), groupForm.template ? /*#__PURE__*/jsxRuntime.jsx(Template, {
48182
+ namespace: namespace,
48183
+ conf: {
48184
+ mod: APP,
48185
+ group: group,
48186
+ form: groupForm,
48187
+ data: data[group] ? data[group] : data || {},
48188
+ allData: data,
48189
+ linkingForms: linkingForms || {},
48190
+ linkingData: data.linking || {},
48191
+ match,
48192
+ canEdit: isSupported && canEdit,
48193
+ mode,
48194
+ user: user,
48195
+ t: t,
48196
+ location: location,
48197
+ isMobile: isMobile,
48198
+ linkingTemplateContextData: linkingTemplateContextData,
48199
+ addData: addData,
48200
+ options: options
48201
+ }
48202
+ }) : /*#__PURE__*/jsxRuntime.jsx(Content, {
48203
+ form: groupForm,
48204
+ data: data || {},
48205
+ groupConfig: groups || {},
48206
+ linkingData: (data || {}).linking || {},
48207
+ linkingForms: linkingForms || {},
48208
+ ajaxOptions: [],
48209
+ extraLinking: extraLinking,
48210
+ t: t,
48211
+ app: APP,
48212
+ ajaxForms: ajaxForms,
48213
+ language: user?.language,
48214
+ changeAjaxForms: changeAjaxForms,
48215
+ getApiBaseUrl: getApiBaseUrl,
48216
+ getAppHeader: getAppHeader,
48217
+ user: user
48218
+ })]
48219
+ })]
48220
+ }), openRecordsModal && /*#__PURE__*/jsxRuntime.jsx(Records, {
48221
+ open: openRecordsModal,
48222
+ onClose: () => setOpenRecordsModal(false),
48223
+ t: t,
48224
+ sourceOptions: [],
48225
+ versionOptions: [],
48226
+ id: params?.id,
48227
+ subject: namespace,
48228
+ onSubmit: values => {
48229
+ setSource(values?.source);
48230
+ setVersion(values?.version);
48231
+ }
48232
+ })]
48233
+ });
48234
+ };
48235
+
45918
48236
  exports.ActivitiesTable = ActivitiesTable;
45919
48237
  exports.DocumentsTable = DocumentsTable;
45920
48238
  exports.EventsTable = EventsTable;
@@ -45932,4 +48250,5 @@ exports.SupplyChainDashboard = SupplyChain;
45932
48250
  exports.TablePage = TablePage;
45933
48251
  exports.UserDashboard = UserDashboard;
45934
48252
  exports.UsersTable = UsersTable;
48253
+ exports.View = View;
45935
48254
  exports.WorkersTable = WorkersTable;