Severian commited on
Commit
dce71c7
·
verified ·
1 Parent(s): 7b642ea

Update components/ResultsTable.tsx

Browse files
Files changed (1) hide show
  1. components/ResultsTable.tsx +91 -125
components/ResultsTable.tsx CHANGED
@@ -273,10 +273,6 @@ const QAReportModal: React.FC<{ report: DetailedQaReport; onClose: () => void }>
273
  </div>
274
  <div className="space-y-2">
275
  <OverallSection data={report.overall} />
276
- <Section title="Title" data={report.title} />
277
- <Section title="Meta Description" data={report.meta} />
278
- <Section title="H1" data={report.h1} />
279
- <Section title="Copy" data={report.copy} />
280
  <AdditionalSections sections={report.additionalSections} />
281
 
282
  {/* Complete Raw Report */}
@@ -332,50 +328,18 @@ const ResultsTable: React.FC<ResultsTableProps> = ({ results }) => {
332
  'Generated H1': row.generatedH1,
333
  'Generated Meta': row.generatedMeta,
334
  'Generated Copy': row.generatedCopy,
335
- 'Overall Pass': row.overallPass,
336
- 'Overall Grade': row.overallGrade,
337
  'Overall Primary Issue': report?.overall.primaryIssue,
338
  'Overall Detailed Assessment': report?.overall.detailedAssessment,
339
  'Overall Key Strengths': report?.overall.keyStrengths?.join('; '),
340
  'Overall Recommendations': report?.overall.recommendations?.join('; '),
341
  'Overall Explanations': report?.overall.explanations,
342
- 'Title Pass': report?.title.pass,
343
- 'Title Grade': report?.title.grade,
344
- 'Title Errors': report?.title.errors.join('; '),
345
- 'Title Detailed Assessment': report?.title.detailedAssessment,
346
- 'Title Key Strengths': report?.title.keyStrengths?.join('; '),
347
- 'Title Recommendations': report?.title.recommendations?.join('; '),
348
- 'Title Explanations': report?.title.explanations,
349
- 'Title Corrected': report?.title.corrected,
350
- 'Meta Pass': report?.meta.pass,
351
- 'Meta Grade': report?.meta.grade,
352
- 'Meta Errors': report?.meta.errors.join('; '),
353
- 'Meta Detailed Assessment': report?.meta.detailedAssessment,
354
- 'Meta Key Strengths': report?.meta.keyStrengths?.join('; '),
355
- 'Meta Recommendations': report?.meta.recommendations?.join('; '),
356
- 'Meta Explanations': report?.meta.explanations,
357
- 'Meta Corrected': report?.meta.corrected,
358
- 'H1 Pass': report?.h1.pass,
359
- 'H1 Grade': report?.h1.grade,
360
- 'H1 Errors': report?.h1.errors.join('; '),
361
- 'H1 Detailed Assessment': report?.h1.detailedAssessment,
362
- 'H1 Key Strengths': report?.h1.keyStrengths?.join('; '),
363
- 'H1 Recommendations': report?.h1.recommendations?.join('; '),
364
- 'H1 Explanations': report?.h1.explanations,
365
- 'H1 Corrected': report?.h1.corrected,
366
- 'Copy Pass': report?.copy.pass,
367
- 'Copy Grade': report?.copy.grade,
368
- 'Copy Errors': report?.copy.errors.join('; '),
369
- 'Copy Detailed Assessment': report?.copy.detailedAssessment,
370
- 'Copy Key Strengths': report?.copy.keyStrengths?.join('; '),
371
- 'Copy Recommendations': report?.copy.recommendations?.join('; '),
372
- 'Copy Explanations': report?.copy.explanations,
373
- 'Copy Corrected': report?.copy.corrected,
374
  'Additional QA Sections': report?.additionalSections ?
375
  Object.entries(report.additionalSections)
376
- .map(([name, data]) => `${name}: ${data.content}`)
377
  .join(' | ') : '',
378
- 'Complete Raw QA Report': report?.completeRawReport || row.qaReport,
379
  };
380
  });
381
 
@@ -514,6 +478,7 @@ const ResultsTable: React.FC<ResultsTableProps> = ({ results }) => {
514
 
515
  // Add QA Details if available
516
  if (row.detailedQaReport) {
 
517
  currentY = ensureMinSpace(60); // Ensure space for QA header + at least one section
518
  currentY += 5;
519
  pdf.setFontSize(12);
@@ -521,7 +486,9 @@ const ResultsTable: React.FC<ResultsTableProps> = ({ results }) => {
521
  currentY = addWrappedText('QA Report Details:', margin + 5, currentY, maxLineWidth - 5, 12);
522
  currentY += 2;
523
 
524
- const addQaSection = (title: string, section: QaSectionResult) => {
 
 
525
  currentY = ensureMinSpace(30);
526
  pdf.setFontSize(10);
527
  pdf.setFont('helvetica', 'bold');
@@ -535,9 +502,15 @@ const ResultsTable: React.FC<ResultsTableProps> = ({ results }) => {
535
  pdf.setTextColor(0, 0, 0); // Reset color
536
 
537
  pdf.setFont('helvetica', 'normal');
538
- currentY = addWrappedText(`Errors: ${section.errors.join(', ')}`, margin + 10, currentY, maxLineWidth - 10, 8);
539
 
540
- // Enhanced QA content display
 
 
 
 
 
 
 
541
  if (section.detailedAssessment) {
542
  currentY = ensureMinSpace(20);
543
  pdf.setFont('helvetica', 'bold');
@@ -574,78 +547,26 @@ const ResultsTable: React.FC<ResultsTableProps> = ({ results }) => {
574
  currentY = addWrappedText(section.explanations, margin + 15, currentY, maxLineWidth - 15, 7);
575
  }
576
 
577
- if (section.corrected) {
578
  currentY = ensureMinSpace(20);
579
  pdf.setFont('helvetica', 'italic');
580
  currentY = addWrappedText(`Correction/Analysis: ${section.corrected}`, margin + 10, currentY, maxLineWidth - 10, 8);
 
581
  }
582
  currentY += 4;
583
  };
584
 
585
- // Add Overall Assessment first
586
- const overall = row.detailedQaReport.overall;
587
- currentY = ensureMinSpace(40);
588
- pdf.setFontSize(11);
589
- pdf.setFont('helvetica', 'bold');
590
- currentY = addWrappedText('Overall Assessment:', margin + 5, currentY, maxLineWidth - 5, 11);
591
- currentY += 2;
592
-
593
- pdf.setFontSize(9);
594
- pdf.setFont('helvetica', 'normal');
595
- currentY = addWrappedText(`Primary Issue: ${overall.primaryIssue}`, margin + 10, currentY, maxLineWidth - 10, 9);
596
-
597
- if (overall.detailedAssessment) {
598
- currentY = ensureMinSpace(20);
599
- pdf.setFont('helvetica', 'bold');
600
- currentY = addWrappedText('Detailed Assessment:', margin + 10, currentY, maxLineWidth - 10, 8);
601
- pdf.setFont('helvetica', 'normal');
602
- currentY = addWrappedText(overall.detailedAssessment, margin + 15, currentY, maxLineWidth - 15, 7);
603
- }
604
-
605
- if (overall.keyStrengths && overall.keyStrengths.length > 0) {
606
- currentY = ensureMinSpace(20);
607
- pdf.setFont('helvetica', 'bold');
608
- currentY = addWrappedText('Key Strengths:', margin + 10, currentY, maxLineWidth - 10, 8);
609
- pdf.setFont('helvetica', 'normal');
610
- overall.keyStrengths.forEach(strength => {
611
- currentY = addWrappedText(`• ${strength}`, margin + 15, currentY, maxLineWidth - 15, 7);
612
- });
613
- }
614
-
615
- if (overall.recommendations && overall.recommendations.length > 0) {
616
- currentY = ensureMinSpace(20);
617
- pdf.setFont('helvetica', 'bold');
618
- currentY = addWrappedText('Recommendations:', margin + 10, currentY, maxLineWidth - 10, 8);
619
- pdf.setFont('helvetica', 'normal');
620
- overall.recommendations.forEach(rec => {
621
- currentY = addWrappedText(`• ${rec}`, margin + 15, currentY, maxLineWidth - 15, 7);
622
- });
623
- }
624
-
625
- if (overall.explanations) {
626
- currentY = ensureMinSpace(20);
627
- pdf.setFont('helvetica', 'bold');
628
- currentY = addWrappedText('Explanations:', margin + 10, currentY, maxLineWidth - 10, 8);
629
- pdf.setFont('helvetica', 'normal');
630
- currentY = addWrappedText(overall.explanations, margin + 15, currentY, maxLineWidth - 15, 7);
631
- }
632
-
633
- currentY += 5;
634
-
635
- addQaSection('Title', row.detailedQaReport.title);
636
- addQaSection('Meta', row.detailedQaReport.meta);
637
- addQaSection('H1', row.detailedQaReport.h1);
638
- addQaSection('Copy', row.detailedQaReport.copy);
639
 
640
  // Add Additional Sections if available
641
- if (row.detailedQaReport.additionalSections) {
642
  currentY = ensureMinSpace(30);
643
  pdf.setFontSize(10);
644
  pdf.setFont('helvetica', 'bold');
645
  currentY = addWrappedText('Additional QA Sections:', margin + 5, currentY, maxLineWidth - 5, 10);
646
  currentY += 2;
647
 
648
- Object.entries(row.detailedQaReport.additionalSections).forEach(([sectionName, sectionData]) => {
649
  currentY = ensureMinSpace(25);
650
  pdf.setFontSize(9);
651
  pdf.setFont('helvetica', 'bold');
@@ -655,6 +576,20 @@ const ResultsTable: React.FC<ResultsTableProps> = ({ results }) => {
655
  currentY += 2;
656
  });
657
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
658
  }
659
 
660
  currentY += sectionSpacing * 2; // Extra spacing between entries
@@ -870,6 +805,7 @@ const ResultsTable: React.FC<ResultsTableProps> = ({ results }) => {
870
 
871
  // QA Details if available
872
  if (row.detailedQaReport) {
 
873
  children.push(
874
  new Paragraph({
875
  text: "QA Report Details:",
@@ -878,7 +814,9 @@ const ResultsTable: React.FC<ResultsTableProps> = ({ results }) => {
878
  })
879
  );
880
 
881
- const addQaSection = (title: string, section: QaSectionResult) => {
 
 
882
  children.push(
883
  new Paragraph({
884
  children: [
@@ -890,36 +828,64 @@ const ResultsTable: React.FC<ResultsTableProps> = ({ results }) => {
890
  ],
891
  heading: HeadingLevel.HEADING_4,
892
  spacing: { before: 300, after: 100 }
893
- }),
894
- new Paragraph({
895
- text: `Errors: ${section.errors.join(', ')}`,
896
- spacing: { after: 100 }
897
  })
898
  );
899
 
900
- // Handle correction/analysis with proper formatting
901
- if (section.corrected && section.corrected.trim()) {
902
- const correctedText = cleanText(section.corrected);
903
- if (correctedText && correctedText !== 'Content analysis not available.') {
904
- children.push(
905
- new Paragraph({
906
- children: [
907
- new TextRun({
908
- text: `Correction/Analysis: ${correctedText}`,
909
- italics: true
910
- })
911
- ],
912
- spacing: { after: 200 }
913
- })
914
- );
915
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
916
  }
917
  };
918
 
919
- addQaSection('Title', row.detailedQaReport.title);
920
- addQaSection('Meta', row.detailedQaReport.meta);
921
- addQaSection('H1', row.detailedQaReport.h1);
922
- addQaSection('Copy', row.detailedQaReport.copy);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
923
  }
924
 
925
  // Add spacing between entries
 
273
  </div>
274
  <div className="space-y-2">
275
  <OverallSection data={report.overall} />
 
 
 
 
276
  <AdditionalSections sections={report.additionalSections} />
277
 
278
  {/* Complete Raw Report */}
 
328
  'Generated H1': row.generatedH1,
329
  'Generated Meta': row.generatedMeta,
330
  'Generated Copy': row.generatedCopy,
331
+ 'Overall Pass': report?.overall.pass,
332
+ 'Overall Grade': report?.overall.grade,
333
  'Overall Primary Issue': report?.overall.primaryIssue,
334
  'Overall Detailed Assessment': report?.overall.detailedAssessment,
335
  'Overall Key Strengths': report?.overall.keyStrengths?.join('; '),
336
  'Overall Recommendations': report?.overall.recommendations?.join('; '),
337
  'Overall Explanations': report?.overall.explanations,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338
  'Additional QA Sections': report?.additionalSections ?
339
  Object.entries(report.additionalSections)
340
+ .map(([name, data]) => `${name}: ${data.content.replace(/\r?\n|\r/g, ' ')}`) // Sanitize newlines
341
  .join(' | ') : '',
342
+ 'Complete Raw QA Report': report?.completeRawReport?.replace(/\r?\n|\r/g, ' ') || row.qaReport.replace(/\r?\n|\r/g, ' '), // Sanitize newlines
343
  };
344
  });
345
 
 
478
 
479
  // Add QA Details if available
480
  if (row.detailedQaReport) {
481
+ const report = row.detailedQaReport;
482
  currentY = ensureMinSpace(60); // Ensure space for QA header + at least one section
483
  currentY += 5;
484
  pdf.setFontSize(12);
 
486
  currentY = addWrappedText('QA Report Details:', margin + 5, currentY, maxLineWidth - 5, 12);
487
  currentY += 2;
488
 
489
+ const addDetailedSection = (title: string, section: QaSectionResult | DetailedQaReport['overall']) => {
490
+ const isOverall = 'primaryIssue' in section;
491
+
492
  currentY = ensureMinSpace(30);
493
  pdf.setFontSize(10);
494
  pdf.setFont('helvetica', 'bold');
 
502
  pdf.setTextColor(0, 0, 0); // Reset color
503
 
504
  pdf.setFont('helvetica', 'normal');
 
505
 
506
+ if (isOverall && section.primaryIssue) {
507
+ currentY = addWrappedText(`Primary Issue: ${section.primaryIssue}`, margin + 10, currentY, maxLineWidth - 10, 8);
508
+ }
509
+
510
+ if (!isOverall && section.errors.length > 0) {
511
+ currentY = addWrappedText(`Errors: ${section.errors.join(', ')}`, margin + 10, currentY, maxLineWidth - 10, 8);
512
+ }
513
+
514
  if (section.detailedAssessment) {
515
  currentY = ensureMinSpace(20);
516
  pdf.setFont('helvetica', 'bold');
 
547
  currentY = addWrappedText(section.explanations, margin + 15, currentY, maxLineWidth - 15, 7);
548
  }
549
 
550
+ if (!isOverall && section.corrected) {
551
  currentY = ensureMinSpace(20);
552
  pdf.setFont('helvetica', 'italic');
553
  currentY = addWrappedText(`Correction/Analysis: ${section.corrected}`, margin + 10, currentY, maxLineWidth - 10, 8);
554
+ pdf.setFont('helvetica', 'normal');
555
  }
556
  currentY += 4;
557
  };
558
 
559
+ addDetailedSection('Overall Assessment', report.overall);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
560
 
561
  // Add Additional Sections if available
562
+ if (report.additionalSections) {
563
  currentY = ensureMinSpace(30);
564
  pdf.setFontSize(10);
565
  pdf.setFont('helvetica', 'bold');
566
  currentY = addWrappedText('Additional QA Sections:', margin + 5, currentY, maxLineWidth - 5, 10);
567
  currentY += 2;
568
 
569
+ Object.entries(report.additionalSections).forEach(([sectionName, sectionData]) => {
570
  currentY = ensureMinSpace(25);
571
  pdf.setFontSize(9);
572
  pdf.setFont('helvetica', 'bold');
 
576
  currentY += 2;
577
  });
578
  }
579
+
580
+ // Add Complete Raw Report
581
+ if (report.completeRawReport) {
582
+ currentY = ensureMinSpace(30);
583
+ pdf.setFontSize(10);
584
+ pdf.setFont('helvetica', 'bold');
585
+ currentY = addWrappedText('Complete Raw QA Report:', margin + 5, currentY, maxLineWidth - 5, 10);
586
+ currentY += 2;
587
+ pdf.setFontSize(7);
588
+ pdf.setFont('helvetica', 'normal');
589
+ pdf.setTextColor(100, 100, 100); // Lighter text for raw content
590
+ currentY = addWrappedText(report.completeRawReport, margin + 10, currentY, maxLineWidth - 10, 7);
591
+ pdf.setTextColor(0, 0, 0); // Reset color
592
+ }
593
  }
594
 
595
  currentY += sectionSpacing * 2; // Extra spacing between entries
 
805
 
806
  // QA Details if available
807
  if (row.detailedQaReport) {
808
+ const report = row.detailedQaReport;
809
  children.push(
810
  new Paragraph({
811
  text: "QA Report Details:",
 
814
  })
815
  );
816
 
817
+ const addDetailedSection = (title: string, section: QaSectionResult | DetailedQaReport['overall']) => {
818
+ const isOverall = 'primaryIssue' in section;
819
+
820
  children.push(
821
  new Paragraph({
822
  children: [
 
828
  ],
829
  heading: HeadingLevel.HEADING_4,
830
  spacing: { before: 300, after: 100 }
 
 
 
 
831
  })
832
  );
833
 
834
+ if (isOverall && section.primaryIssue) {
835
+ children.push(new Paragraph({ text: `Primary Issue: ${cleanText(section.primaryIssue)}`, spacing: { after: 100 } }));
836
+ }
837
+
838
+ if (!isOverall && section.errors && section.errors.length > 0) {
839
+ children.push(new Paragraph({ text: `Errors: ${section.errors.join(', ')}`, spacing: { after: 100 } }));
840
+ }
841
+
842
+ if (section.detailedAssessment) {
843
+ children.push(new Paragraph({ children: [new TextRun({ text: "Detailed Assessment:", bold: true })], spacing: { after: 50 } }));
844
+ splitIntoParagraphs(section.detailedAssessment).forEach(p => children.push(new Paragraph({ text: p, spacing: { after: 100 } })));
845
+ }
846
+
847
+ if (section.keyStrengths && section.keyStrengths.length > 0) {
848
+ children.push(new Paragraph({ children: [new TextRun({ text: "Key Strengths:", bold: true })], spacing: { after: 50 } }));
849
+ section.keyStrengths.forEach(s => children.push(new Paragraph({ text: `• ${cleanText(s)}`, spacing: { after: 50 }, indent: { left: 400 } })));
850
+ }
851
+
852
+ if (section.recommendations && section.recommendations.length > 0) {
853
+ children.push(new Paragraph({ children: [new TextRun({ text: "Recommendations:", bold: true })], spacing: { after: 50 } }));
854
+ section.recommendations.forEach(r => children.push(new Paragraph({ text: `• ${cleanText(r)}`, spacing: { after: 50 }, indent: { left: 400 } })));
855
+ }
856
+
857
+ if (section.explanations) {
858
+ children.push(new Paragraph({ children: [new TextRun({ text: "Explanations:", bold: true })], spacing: { after: 50 } }));
859
+ splitIntoParagraphs(section.explanations).forEach(p => children.push(new Paragraph({ text: p, spacing: { after: 100 } })));
860
+ }
861
+
862
+ if (!isOverall && section.corrected) {
863
+ children.push(new Paragraph({ children: [new TextRun({ text: "Corrected Content:", bold: true })], spacing: { after: 50 } }));
864
+ splitIntoParagraphs(section.corrected).forEach(p => children.push(new Paragraph({ text: p, spacing: { after: 100 } })));
865
  }
866
  };
867
 
868
+ addDetailedSection('Overall Assessment', report.overall);
869
+
870
+ // Add Additional Sections
871
+ if (report.additionalSections && Object.keys(report.additionalSections).length > 0) {
872
+ children.push(new Paragraph({ text: "Additional QA Sections", heading: HeadingLevel.HEADING_4, spacing: { before: 300, after: 100 } }));
873
+ Object.entries(report.additionalSections).forEach(([name, data]) => {
874
+ children.push(new Paragraph({ children: [new TextRun({ text: `${name}:`, bold: true })], spacing: { after: 50 } }));
875
+ splitIntoParagraphs(data.content).forEach(p => children.push(new Paragraph({ text: p, spacing: { after: 100 }, indent: { left: 400 } })));
876
+ });
877
+ }
878
+
879
+ // Add Complete Raw Report
880
+ if (report.completeRawReport) {
881
+ children.push(new Paragraph({ text: "Complete Raw QA Report", heading: HeadingLevel.HEADING_4, spacing: { before: 300, after: 100 } }));
882
+ splitIntoParagraphs(report.completeRawReport).forEach(p => {
883
+ children.push(new Paragraph({
884
+ children: [ new TextRun({ text: p, size: 16 }) ], // smaller font
885
+ spacing: { after: 100 }
886
+ }));
887
+ });
888
+ }
889
  }
890
 
891
  // Add spacing between entries