@visns-studio/visns-components 5.10.10 → 5.11.1

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.
@@ -686,8 +686,73 @@ function GenericDetail({
686
686
 
687
687
  const renderExist = () => (truncatedValue ? 'Yes' : 'No');
688
688
 
689
- const renderJson = () =>
690
- value ? <pre>{JSON.stringify(value, null, 4)}</pre> : null;
689
+ const renderJson = () => {
690
+ if (!value) return null;
691
+
692
+ try {
693
+ const jsonData = typeof value === 'string' ? JSON.parse(value) : value;
694
+
695
+ // Check if this looks like a question/answer format
696
+ const isQuestionAnswerFormat = Object.values(jsonData).every(item =>
697
+ item && typeof item === 'object' &&
698
+ (item.hasOwnProperty('question') || item.hasOwnProperty('answer'))
699
+ );
700
+
701
+ if (isQuestionAnswerFormat) {
702
+ return (
703
+ <div className={styles.jsonQuestionAnswer}>
704
+ {Object.entries(jsonData).map(([key, item]) => {
705
+ if (!item || typeof item !== 'object') return null;
706
+
707
+ const question = item.question || key.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase());
708
+ const answer = item.answer !== undefined ?
709
+ (typeof item.answer === 'boolean' ? (item.answer ? 'Yes' : 'No') : String(item.answer)) :
710
+ 'N/A';
711
+
712
+ return (
713
+ <div key={key} className={styles.questionAnswerPair}>
714
+ <div className={styles.question}>
715
+ <strong>{question}</strong>
716
+ </div>
717
+ <div className={styles.answer}>
718
+ {answer}
719
+ </div>
720
+ </div>
721
+ );
722
+ })}
723
+ </div>
724
+ );
725
+ }
726
+
727
+ // Check if this is a simple key-value object
728
+ const isSimpleKeyValue = Object.values(jsonData).every(val =>
729
+ typeof val !== 'object' || val === null
730
+ );
731
+
732
+ if (isSimpleKeyValue) {
733
+ return (
734
+ <div className={styles.jsonKeyValue}>
735
+ {Object.entries(jsonData).map(([key, val]) => (
736
+ <div key={key} className={styles.keyValuePair}>
737
+ <strong>{key.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase())}:</strong> {
738
+ val !== null && val !== undefined ?
739
+ (typeof val === 'boolean' ? (val ? 'Yes' : 'No') : String(val)) :
740
+ 'N/A'
741
+ }
742
+ </div>
743
+ ))}
744
+ </div>
745
+ );
746
+ }
747
+
748
+ // For complex nested objects, fall back to formatted JSON
749
+ return <pre className={styles.jsonRaw}>{JSON.stringify(jsonData, null, 2)}</pre>;
750
+
751
+ } catch (error) {
752
+ // If parsing fails, show raw value
753
+ return <pre className={styles.jsonRaw}>{JSON.stringify(value, null, 2)}</pre>;
754
+ }
755
+ };
691
756
 
692
757
  const renderLatestNotes = () => formatNoteValue();
693
758