From c7f9aeac863ee489d7aa4d14b98fa45eeda1f773 Mon Sep 17 00:00:00 2001 From: Jim Moffet Date: Wed, 22 May 2024 14:10:42 -0700 Subject: [PATCH] Jim/bring form summary back (#137) * form summary from v1 api * default vals * split into two PRs * split into two PRs * base url * defaults --- packages/forms/src/documents/document.ts | 2 +- .../forms/src/documents/pdf/parsing-api.ts | 21 +++++++++++++++++-- packages/forms/src/patterns/index.ts | 2 ++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/forms/src/documents/document.ts b/packages/forms/src/documents/document.ts index 8a2d8500..4ccc89c4 100644 --- a/packages/forms/src/documents/document.ts +++ b/packages/forms/src/documents/document.ts @@ -27,7 +27,7 @@ export const addDocument = async ( if (parsedPdf) { form = updateFormSummary(form, { title: parsedPdf.title, - description: '', + description: parsedPdf.description, }); form = addPatternMap(form, parsedPdf.patterns, parsedPdf.root); const updatedForm = addFormOutput(form, { diff --git a/packages/forms/src/documents/pdf/parsing-api.ts b/packages/forms/src/documents/pdf/parsing-api.ts index f4978517..9bfea0c6 100644 --- a/packages/forms/src/documents/pdf/parsing-api.ts +++ b/packages/forms/src/documents/pdf/parsing-api.ts @@ -8,6 +8,7 @@ import { type ParagraphPattern } from '../../patterns/paragraph'; import { type SequencePattern } from '../../patterns/sequence'; import { type CheckboxPattern } from '../../patterns/checkbox'; import { type RadioGroupPattern } from '../../patterns/radio-group'; +import { type FormSummary } from '../../patterns/form-summary'; import { uint8ArrayToBase64 } from '../util'; import { type DocumentFieldMap } from '../types'; @@ -126,6 +127,7 @@ export type ParsedPdf = { outputs: DocumentFieldMap; // to populate FormOutput root: PatternId; title: string; + description: string; }; export const callExternalParser = async ( @@ -151,14 +153,29 @@ export const callExternalParser = async ( const json = await response.json(); const extracted: ExtractedObject = ExtractedObject.parse(json.parsed_pdf); + const rootSequence: PatternId[] = []; + const parsedPdf: ParsedPdf = { patterns: {}, outputs: {}, root: 'root', - title: extracted.form_summary.title, + title: extracted.form_summary.title || 'Default Form Title', + description: + extracted.form_summary.description || 'Default Form Description', }; - const rootSequence: PatternId[] = []; + const formSummaryId = generatePatternId(); + + parsedPdf.patterns[formSummaryId] = { + type: 'form-summary', + id: formSummaryId, + data: { + title: extracted.form_summary.title || 'Default Form Title', + description: + extracted.form_summary.description || 'Default Form Description', + }, + } satisfies FormSummary; + rootSequence.push(formSummaryId); for (const element of extracted.elements) { const randomId = generatePatternId(); diff --git a/packages/forms/src/patterns/index.ts b/packages/forms/src/patterns/index.ts index be642c4b..384ceb4f 100644 --- a/packages/forms/src/patterns/index.ts +++ b/packages/forms/src/patterns/index.ts @@ -3,6 +3,7 @@ import { type FormConfig } from '../pattern'; import { addressConfig } from './address'; import { checkboxConfig } from './checkbox'; import { fieldsetConfig } from './fieldset'; +import { formSummaryConfig } from './form-summary'; import { inputConfig } from './input'; import { paragraphConfig } from './paragraph'; import { radioGroupConfig } from './radio-group'; @@ -13,6 +14,7 @@ import { sequenceConfig } from './sequence'; // understand the usage scenarios better. export const defaultFormConfig: FormConfig = { patterns: { + 'form-summary': formSummaryConfig, address: addressConfig, checkbox: checkboxConfig, fieldset: fieldsetConfig,