Open History to see the last commit
1import { createMemo, createSignal, onCleanup } from 'solid-js'
2import { getFieldDebugDetails } from './suspicionViews'
3import type { Accessor } from 'solid-js'
4import type { EvaluatedDebugDetails } from '../debug/types'
5import type { FieldDebugReport, FieldDebugSuspicion } from '@/eventClientTypes'
6import type { FieldId, FormId } from '@/types/branded'
7import { requestFieldDebugReport } from '@/debugReports'
8import { DebugInfoCard } from '@/components/fields/fieldDetails/debug/DebugInfoCard'
9
10const fieldDebugCopy = {
11 loading: 'Investigating this field…',
12 empty:
13 "We couldn't find anything unusual that would help explain why this field has no errors. This screen can only provide guidance when a field matches a known suspicious pattern.",
14 dismissed:
15 "The only patterns related to this field are no longer considered relevant, so there's nothing else for this screen to investigate.",
16 suggestion: 'Think this issue should be recognized in the future?',
17}
18
19interface FieldDebugInfoProps {
20 formInstanceId: FormId
21 fieldId: FieldId
22 dismissedDebugCases: Accessor<ReadonlySet<FieldDebugSuspicion['kind']>>
23 onDismissDebugCase: (kind: FieldDebugSuspicion['kind']) => void
24}
25
26export function FieldDebugInfo(props: FieldDebugInfoProps) {
27 const [report, setReport] = createSignal<FieldDebugReport>()
28 const cancelRequest = requestFieldDebugReport(
29 {
30 formInstanceId: props.formInstanceId,
31 fieldId: props.fieldId,
32 },
33 setReport,
34 )
35 onCleanup(cancelRequest)
36
37 const remainingSuspicions = createMemo(() =>
38 (report()?.suspicions ?? []).filter(
39 (suspicion) => !props.dismissedDebugCases().has(suspicion.kind),
40 ),
41 )
42 const currentDebug = createMemo<
43 EvaluatedDebugDetails<FieldDebugSuspicion['kind']> | undefined
44 >(() => {
45 const suspicion = remainingSuspicions()[0]
46 if (!suspicion) return undefined
47
48 return {
49 ...getFieldDebugDetails(suspicion),
50 kind: suspicion.kind,
51 }
52 })
53
54 return (
55 <DebugInfoCard
56 currentDebug={currentDebug}
57 isLoading={() => report() === undefined}
58 hasDismissedDebugCases={() => props.dismissedDebugCases().size > 0}
59 copy={fieldDebugCopy}
60 onDismissDebugCase={props.onDismissDebugCase}
61 />
62 )
63}