@visns-studio/visns-components 4.10.6 → 4.10.7

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.
package/package.json CHANGED
@@ -75,7 +75,7 @@
75
75
  "react-dom": "^17.0.0 || ^18.0.0"
76
76
  },
77
77
  "name": "@visns-studio/visns-components",
78
- "version": "4.10.6",
78
+ "version": "4.10.7",
79
79
  "description": "Various packages to assist in the development of our Custom Applications.",
80
80
  "main": "src/index.js",
81
81
  "files": [
@@ -149,6 +149,19 @@ const DataGrid = forwardRef(
149
149
  }
150
150
  }, [audioSource]);
151
151
 
152
+ /** JSON Modal States */
153
+ const [modalJsonShow, setModalJsonShow] = useState(false);
154
+ const [jsonData, setJsonData] = useState({});
155
+
156
+ /** JSON Modal Functions */
157
+ const modalJsonOpen = () => {
158
+ setModalJsonShow(true);
159
+ };
160
+
161
+ const modalJsonClose = () => {
162
+ setModalJsonShow(false);
163
+ };
164
+
152
165
  /** Gallery Modal States */
153
166
  const [modalGalleryShow, setModalGalleryShow] = useState(false);
154
167
  const [galleryData, setGalleryData] = useState([]);
@@ -570,6 +583,15 @@ const DataGrid = forwardRef(
570
583
  );
571
584
  }
572
585
  break;
586
+ case 'view':
587
+ modalJsonOpen();
588
+ console.info(d[s.key], s.headers);
589
+ setJsonData((prevState) => ({
590
+ ...prevState,
591
+ data: d[s.key],
592
+ headers: s.headers,
593
+ }));
594
+ break;
573
595
  case 'update':
574
596
  modalOpen('update', d.id);
575
597
  break;
@@ -1127,6 +1149,8 @@ const DataGrid = forwardRef(
1127
1149
  return getIconComponent(Clock);
1128
1150
  case 'update':
1129
1151
  return getIconComponent(Edit);
1152
+ case 'view':
1153
+ return getIconComponent(Search);
1130
1154
  default:
1131
1155
  return null;
1132
1156
  }
@@ -2526,6 +2550,69 @@ const DataGrid = forwardRef(
2526
2550
  }
2527
2551
  };
2528
2552
 
2553
+ const snakeCaseToTitle = (text) => {
2554
+ return text
2555
+ .replace(/_/g, ' ')
2556
+ .replace(/\b\w/g, (char) => char.toUpperCase()); // Capitalize first letter of each word
2557
+ };
2558
+
2559
+ // Recursive function to handle nested objects
2560
+ const renderField = (key, value) => {
2561
+ // If the value is an object, recursively render its fields
2562
+ if (typeof value === 'object' && value !== null) {
2563
+ return (
2564
+ <div key={key} style={{ marginBottom: '1rem' }}>
2565
+ <h4
2566
+ style={{
2567
+ fontSize: '1.2rem',
2568
+ marginBottom: '0.5rem',
2569
+ color: '#333',
2570
+ borderBottom: '1px solid #ccc',
2571
+ }}
2572
+ >
2573
+ {snakeCaseToTitle(key)}
2574
+ </h4>
2575
+ <div style={{ paddingLeft: '1.5rem' }}>
2576
+ {Object.keys(value).map((childKey) =>
2577
+ renderField(childKey, value[childKey])
2578
+ )}
2579
+ </div>
2580
+ </div>
2581
+ );
2582
+ }
2583
+ // Otherwise, render the key and value as a label and paragraph
2584
+ return (
2585
+ <div key={key} style={{ marginBottom: '1rem' }}>
2586
+ <span
2587
+ style={{
2588
+ fontWeight: 'bold',
2589
+ marginBottom: '0.2rem',
2590
+ display: 'block',
2591
+ color: '#444',
2592
+ }}
2593
+ >
2594
+ {snakeCaseToTitle(key)}
2595
+ </span>
2596
+ <p
2597
+ style={{
2598
+ margin: 0,
2599
+ color: '#666',
2600
+ backgroundColor: '#f9f9f9',
2601
+ padding: '0.5rem',
2602
+ borderRadius: '5px',
2603
+ }}
2604
+ >
2605
+ {value !== null ? value : 'N/A'}
2606
+ </p>
2607
+ </div>
2608
+ );
2609
+ };
2610
+
2611
+ const getHeaderLabel = (headers, parentKey) => {
2612
+ const headerObj = headers.find((header) => header.id === parentKey);
2613
+ return headerObj ? headerObj.label : snakeCaseToTitle(parentKey);
2614
+ };
2615
+
2529
2616
  useEffect(() => {
2530
2617
  columns.forEach((column) => {
2531
2618
  if (column.filter && column.filter.url) {
@@ -2578,10 +2665,15 @@ const DataGrid = forwardRef(
2578
2665
  : 400,
2579
2666
  boxShadow: 'none',
2580
2667
  });
2668
+
2581
2669
  const headerProps = {
2582
2670
  style: style ? style : {},
2583
2671
  };
2584
2672
 
2673
+ useEffect(() => {
2674
+ console.info(jsonData);
2675
+ }, [jsonData]);
2676
+
2585
2677
  useEffect(() => {
2586
2678
  const getMinimumHeight = () => {
2587
2679
  if (gridHeight > 0) return gridHeight;
@@ -2722,6 +2814,100 @@ const DataGrid = forwardRef(
2722
2814
  </div>
2723
2815
  </div>
2724
2816
  </Popup>
2817
+ <Popup
2818
+ open={modalJsonShow}
2819
+ onClose={modalJsonClose}
2820
+ closeOnDocumentClick={false}
2821
+ >
2822
+ <div
2823
+ className={`${styles.modalwrap} ${styles['top--modal']}`}
2824
+ >
2825
+ <div className={styles.modal}>
2826
+ <div className={styles.modal__header}>
2827
+ <h1>View Data</h1>
2828
+ <button
2829
+ className={styles.modal__close}
2830
+ onClick={modalJsonClose}
2831
+ >
2832
+ <CircleX strokeWidth={1} size={24} />
2833
+ </button>
2834
+ </div>
2835
+ <div className={styles.modal__content}>
2836
+ <div className={styles.formcontainer}>
2837
+ <div
2838
+ style={{
2839
+ lineHeight: '1.5',
2840
+ }}
2841
+ >
2842
+ {jsonData.headers &&
2843
+ jsonData.headers.map((header) => {
2844
+ const parentKey = header.id;
2845
+
2846
+ // Skip rendering if the parentKey is "id" or doesn't exist in jsonData
2847
+ if (
2848
+ parentKey === 'id' ||
2849
+ !(
2850
+ parentKey in
2851
+ jsonData.data
2852
+ )
2853
+ )
2854
+ return null;
2855
+
2856
+ return (
2857
+ <div
2858
+ key={parentKey}
2859
+ style={{
2860
+ marginBottom:
2861
+ '2rem',
2862
+ }}
2863
+ >
2864
+ {/* Section Header */}
2865
+ <h3
2866
+ style={{
2867
+ fontSize:
2868
+ '1.4rem',
2869
+ marginBottom:
2870
+ '1rem',
2871
+ color: '#222',
2872
+ borderBottom:
2873
+ '2px solid #ddd',
2874
+ }}
2875
+ >
2876
+ {getHeaderLabel(
2877
+ jsonData.headers,
2878
+ parentKey
2879
+ )}
2880
+ </h3>
2881
+ <div
2882
+ style={{
2883
+ paddingLeft:
2884
+ '1rem',
2885
+ }}
2886
+ >
2887
+ {/* Render fields for each section */}
2888
+ {Object.keys(
2889
+ jsonData.data[
2890
+ parentKey
2891
+ ]
2892
+ ).map((childKey) =>
2893
+ renderField(
2894
+ childKey,
2895
+ jsonData
2896
+ .data[
2897
+ parentKey
2898
+ ][childKey]
2899
+ )
2900
+ )}
2901
+ </div>
2902
+ </div>
2903
+ );
2904
+ })}
2905
+ </div>
2906
+ </div>
2907
+ </div>
2908
+ </div>
2909
+ </div>
2910
+ </Popup>
2725
2911
  </>
2726
2912
  );
2727
2913
  }