Avijit Ghosh commited on
Commit
f7c8d87
·
1 Parent(s): 18e0e98
Files changed (1) hide show
  1. app/evaluation/[id]/page.client.tsx +39 -30
app/evaluation/[id]/page.client.tsx CHANGED
@@ -89,13 +89,8 @@ export default function EvaluationDetailsPage() {
89
  const catEval = evaluation?.categoryEvaluations?.[categoryId]
90
  if (!catEval) return undefined
91
 
92
- // Priority: additionalAspects containing 'not applicable'
93
- if (typeof catEval.additionalAspects === "string" && /not applicable/i.test(catEval.additionalAspects)) {
94
- return catEval.additionalAspects
95
- }
96
-
97
- // Check processSources and benchmarkSources for explicit scope/description notes
98
- const checkSources = (sourcesObj: any) => {
99
  if (!sourcesObj) return undefined
100
  for (const entries of Object.values(sourcesObj)) {
101
  if (Array.isArray(entries)) {
@@ -109,35 +104,49 @@ export default function EvaluationDetailsPage() {
109
  return undefined
110
  }
111
 
112
- const fromProcess = checkSources(catEval.processSources)
113
- if (fromProcess) return fromProcess
114
- const fromBench = checkSources(catEval.benchmarkSources)
115
- if (fromBench) return fromBench
116
-
117
- // If all answers in both sections are explicitly 'N/A' or empty, treat as not applicable
118
- const allNA = (obj: any, canonicalKeys: string[]) => {
119
- if (!obj) return true
120
- for (const k of canonicalKeys) {
121
- const ans = obj[k]
122
- if (Array.isArray(ans)) {
123
- if (!ans.every((a) => String(a).toLowerCase() === "n/a" || /not applicable/i.test(String(a)))) return false
124
- } else if (ans === undefined || ans === null) {
125
- // treat missing as NA
126
- continue
127
- } else if (String(ans).toLowerCase() === "n/a" || /not applicable/i.test(String(ans))) {
128
- continue
129
- } else {
130
- return false
131
- }
132
  }
133
- return true
 
134
  }
135
 
136
  const benchmarkQs = BENCHMARK_QUESTIONS.map((q) => q.id)
137
  const processQs = PROCESS_QUESTIONS.map((q) => q.id)
138
 
139
- if (allNA(catEval.benchmarkAnswers, benchmarkQs) && allNA(catEval.processAnswers, processQs)) {
140
- return "Not applicable"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  }
142
 
143
  return undefined
 
89
  const catEval = evaluation?.categoryEvaluations?.[categoryId]
90
  if (!catEval) return undefined
91
 
92
+ // Helper to check sources for explicit NA notes
93
+ const checkSourcesForNA = (sourcesObj: any) => {
 
 
 
 
 
94
  if (!sourcesObj) return undefined
95
  for (const entries of Object.values(sourcesObj)) {
96
  if (Array.isArray(entries)) {
 
104
  return undefined
105
  }
106
 
107
+ // If there are any non-NA answers (yes/no or any non 'n/a' text), the category is applicable
108
+ const isNonNAAnswer = (ans: any) => {
109
+ if (ans === undefined || ans === null) return false
110
+ if (Array.isArray(ans)) {
111
+ return ans.some((a) => {
112
+ const s = String(a || "").trim().toLowerCase()
113
+ return s !== "n/a" && !/not applicable/i.test(s) && s.length > 0
114
+ })
 
 
 
 
 
 
 
 
 
 
 
 
115
  }
116
+ const s = String(ans).trim().toLowerCase()
117
+ return s !== "n/a" && !/not applicable/i.test(s) && s.length > 0
118
  }
119
 
120
  const benchmarkQs = BENCHMARK_QUESTIONS.map((q) => q.id)
121
  const processQs = PROCESS_QUESTIONS.map((q) => q.id)
122
 
123
+ // Check answers for any non-NA content
124
+ let anyNonNA = false
125
+ if (catEval.benchmarkAnswers) {
126
+ for (const k of benchmarkQs) {
127
+ if (isNonNAAnswer(catEval.benchmarkAnswers[k])) {
128
+ anyNonNA = true
129
+ break
130
+ }
131
+ }
132
+ }
133
+ if (!anyNonNA && catEval.processAnswers) {
134
+ for (const k of processQs) {
135
+ if (isNonNAAnswer(catEval.processAnswers[k])) {
136
+ anyNonNA = true
137
+ break
138
+ }
139
+ }
140
+ }
141
+
142
+ if (anyNonNA) return undefined
143
+
144
+ // Only treat category as fully N/A when the category-level field `additionalAspects`
145
+ // explicitly marks it as not applicable (page 2 of the form). Question-level markers
146
+ // (process/benchmark source descriptions or scopes) should NOT make the entire category
147
+ // non-selectable — they will still be shown as per-question NA in the details view.
148
+ if (typeof catEval.additionalAspects === "string" && /not applicable/i.test(catEval.additionalAspects)) {
149
+ return catEval.additionalAspects
150
  }
151
 
152
  return undefined