-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial form building workflow (#17)
* Put field details in a grid * Reorganize React components * Split form fields into separate module. * Move capitalization into a function that we can pipeline with other similar transformations. * To make it or more clear what customizations are required for different document formats and/or alternate PDF implementations, split PDF-specific into separate directory in the documents package. * Comment out broken test in to-be-deleted interviews package. * Test simple in-browser PDF preview. * Initial work for form list/edit/add functionality. * Basic client-side form storage * Add a really simple client-side router for managing form/interview state in concert with localstorage. This is a temporary thing, to avoid spinning up a database and webserver ATM. * Update form context constructor to take a form instead of question list. * Add temporary function to append sample questions to a form, just to test the display of form fields. Will add in edit UI next, to remove the need for this. * Wire in "prompt" and "prompt parts"; use react-hook form in React components. * Link document importer from edit form page. * Wire PDF field extraction to "import PDF" function. * Add documents prop to Form type, to store mapping of form field ID to document ID. * Rename "form-service" app to "rest-api" in lieu of a "form-service" package. * Wire document downloads up to form submission. This involved some clean-up of the structure of the document importer and other refactoring. Additionally, there are inconsistencies on the imported fields that is preventing the PDFs from being properly filled, so that will be be follow-up work. * addDocumentAndData function added * Move addDocumentAndData to documents package. * Rename "addDocument" to "addOutput", and "addDocumentAndData" to "addDocument" * Fix issue with form field mapping in addDocument - this was the bug preventing PDF filling from working as expected. TODO: use unique form field IDs for imported fields. * Add factories for test and browser form services, and create basic initial form service test of the submitForm use case. * Wire browser form service up to all the existing CRUD operations. * Move all service functions into "operations" directory; update service calls to return Result objects in all scenarios. * Fix document parsing tests.
- Loading branch information
1 parent
5dc3bd9
commit 7229c23
Showing
85 changed files
with
2,485 additions
and
645 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../packages/documents/samples |
32 changes: 0 additions & 32 deletions
32
apps/spotlight/src/components/react/document-assembler.tsx
This file was deleted.
Oops, something went wrong.
185 changes: 0 additions & 185 deletions
185
apps/spotlight/src/components/react/document-importer.tsx
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
apps/spotlight/src/components/react/experiments/document-assembler.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { useState } from 'react'; | ||
import { generateDummyPDF } from '@atj/documents'; | ||
|
||
export const downloadPdfBytes = (bytes: Uint8Array) => { | ||
const base64 = btoa(String.fromCharCode(...bytes)); | ||
var element = document.createElement('a'); | ||
element.setAttribute( | ||
'href', | ||
'data:application/pdf;base64,' + encodeURIComponent(base64) | ||
); | ||
element.setAttribute('download', 'sample-document.pdf'); | ||
element.style.display = 'none'; | ||
document.body.appendChild(element); | ||
element.click(); | ||
document.body.removeChild(element); | ||
}; | ||
|
||
const generatePDF = async () => { | ||
const timestamp = new Date().toISOString(); | ||
const pdfBytes = await generateDummyPDF({ timestamp }); | ||
downloadPdfBytes(pdfBytes); | ||
}; | ||
|
||
const previewPDF = async setPreviewPdfUrl => { | ||
const timestamp = new Date().toISOString(); | ||
const pdfBytes = await generateDummyPDF({ timestamp }); | ||
const pdfBlob = new Blob([pdfBytes], { type: 'application/pdf' }); | ||
setPreviewPdfUrl(URL.createObjectURL(pdfBlob)); | ||
}; | ||
|
||
export const DocumentAssembler = () => { | ||
const [previewPdfUrl, setPreviewPdfUrl] = useState<URL>(); | ||
return ( | ||
<div> | ||
<button className="usa-button" onClick={generatePDF}> | ||
Generate PDF | ||
</button> | ||
<button | ||
className="usa-button" | ||
onClick={() => previewPDF(setPreviewPdfUrl)} | ||
> | ||
Preview PDF | ||
</button> | ||
<div> | ||
{previewPdfUrl ? ( | ||
<embed src={previewPdfUrl.toString()} width={500} height={600} /> | ||
) : null} | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.