From f78c09cfd88463de67b1cf71800bc4cbf8b59b6f Mon Sep 17 00:00:00 2001 From: Remi Guan Date: Mon, 30 Dec 2024 20:33:40 +0800 Subject: [PATCH] refactor: Format with prettier --- .github/pull_request_template.md | 9 +- README.md | 4 +- app/actions/runSyncExtractKeyValue.ts | 2 +- .../ExtractKeyValuePairContainer.tsx | 56 +++++----- app/components/playground/KeyValueInputs.tsx | 105 ++++++++---------- .../tutorials/ExtractKeyValuePairTutorial.tsx | 40 +++---- app/globals.css | 19 +--- test-results.json | 11 +- tests/README.md | 19 +++- tests/coreTests.ts | 20 ++-- tsconfig.json | 10 +- 11 files changed, 145 insertions(+), 150 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 405c7dcd..4b8dcc7d 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,10 +1,13 @@ ## Description + ## Related Issue + ## Type of Change + - [ ] Bug fix (non-breaking change which fixes an issue) @@ -15,12 +18,15 @@ - [ ] Performance improvement ## How Has This Been Tested? + ## Screenshots (if applicable) + ## Checklist + - [ ] My code follows the project's style guidelines @@ -32,4 +38,5 @@ - [ ] New and existing unit tests pass locally with my changes ## Additional Notes - + + diff --git a/README.md b/README.md index b96cdb1e..7ff0d613 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ # Cambio Website Source + For Dev setup, please refer to this [Notion Page](https://www.notion.so/goldpiggy/TS-JS-Dev-Setup-ada0f7cdf74c424c8767ed692150cc88?pvs=4). You may need to request access, and you will only receive access if appropriate. ## Quick setup + - checkout a dev branch - copy .env from 1password - `npm install` for dependency - `npm run dev` for local development and testing - open `http://localhost:3000` in your browser -- \ No newline at end of file +- diff --git a/app/actions/runSyncExtractKeyValue.ts b/app/actions/runSyncExtractKeyValue.ts index 5f0183e7..aa8918a6 100644 --- a/app/actions/runSyncExtractKeyValue.ts +++ b/app/actions/runSyncExtractKeyValue.ts @@ -20,7 +20,7 @@ export const runSyncExtractKeyValue = async ({ file_type: 'pdf', extract_args: { extract_instruction: extractInstruction, - } + }, }; const config = { diff --git a/app/components/playground/ExtractKeyValuePairContainer.tsx b/app/components/playground/ExtractKeyValuePairContainer.tsx index 6dda3a1b..7841644d 100644 --- a/app/components/playground/ExtractKeyValuePairContainer.tsx +++ b/app/components/playground/ExtractKeyValuePairContainer.tsx @@ -16,7 +16,7 @@ import ExtractKeyValuePairTutorial from '../tutorials/ExtractKeyValuePairTutoria const downloadExtractedData = (formattedData: string, file?: PlaygroundFile['file']) => { if (!formattedData) return; - + const fileName = file instanceof File ? file.name : 'extracted_data'; const blob = new Blob([formattedData], { type: 'application/json' }); const url = URL.createObjectURL(blob); @@ -33,7 +33,8 @@ const downloadExtractedData = (formattedData: string, file?: PlaygroundFile['fil const ExtractKeyValuePairContainer = () => { const [hideResult, setHideResult] = useState(false); const { apiURL, isProduction } = useProductionContext(); - const { selectedFileIndex, files, updateFileAtIndex, token, userId, clientId, addFilesFormData } = usePlaygroundStore(); + const { selectedFileIndex, files, updateFileAtIndex, token, userId, clientId, addFilesFormData } = + usePlaygroundStore(); const selectedFile = useMemo(() => { if (selectedFileIndex !== null && files.length > 0) { @@ -44,7 +45,10 @@ const ExtractKeyValuePairContainer = () => { useEffect(() => { if (!selectedFile) return; - if (selectedFile.extractKeyValueState === ExtractState.EXTRACTING || selectedFile.extractKeyValueState === ExtractState.UPLOADING) { + if ( + selectedFile.extractKeyValueState === ExtractState.EXTRACTING || + selectedFile.extractKeyValueState === ExtractState.UPLOADING + ) { toast.loading('Extracting data...', { id: 'key-value-extracting-toast' }); } else { toast.dismiss('key-value-extracting-toast'); @@ -53,7 +57,9 @@ const ExtractKeyValuePairContainer = () => { const handleSuccess = async (response: any) => { if (!response.data) { - toast.error(`${selectedFile?.file instanceof File ? selectedFile.file.name : 'File'}: Received undefined result. Please try again.`); + toast.error( + `${selectedFile?.file instanceof File ? selectedFile.file.name : 'File'}: Received undefined result. Please try again.` + ); updateFileAtIndex(selectedFileIndex, 'extractKeyValueState', ExtractState.READY); return; } @@ -104,8 +110,8 @@ const ExtractKeyValuePairContainer = () => { const jobParams: JobParams = { vqaProcessorArgs: { - vqaExtractInstruction: extractInstruction - } + vqaExtractInstruction: extractInstruction, + }, }; // Upload file and get presigned url and metadata @@ -116,7 +122,7 @@ const ExtractKeyValuePairContainer = () => { file: file as File, process_type: ProcessType.EXTRACT_KEY_VALUE, extractArgs: { - extractInstruction + extractInstruction, }, addFilesFormData, }); @@ -153,7 +159,6 @@ const ExtractKeyValuePairContainer = () => { // Run the async job based on environment const runJob = isProduction ? runAsyncRequestJob : runPreprodAsyncRequestJob; await runJob(jobConfig); - } catch (error) { toast.error('Extraction failed. Please try again.'); console.error(error); @@ -173,38 +178,26 @@ const ExtractKeyValuePairContainer = () => { {fileUrl && (hideResult || !selectedFile?.extractKeyValueResult) && (
- {selectedFile?.extractKeyValueResult && (
-
)}
)} {!hideResult && selectedFile?.extractKeyValueResult && (
- +
-
@@ -213,9 +206,12 @@ const ExtractKeyValuePairContainer = () => {
-
diff --git a/app/components/playground/KeyValueInputs.tsx b/app/components/playground/KeyValueInputs.tsx index da970864..688d2f2c 100644 --- a/app/components/playground/KeyValueInputs.tsx +++ b/app/components/playground/KeyValueInputs.tsx @@ -24,11 +24,7 @@ interface KeyValueInputsProps { const AddButton = ({ onClick }: { onClick?: () => void }) => { return ( - ); @@ -36,37 +32,21 @@ const AddButton = ({ onClick }: { onClick?: () => void }) => { const RemoveButton = ({ onClick }: { onClick?: () => void }) => { return ( - ); }; -const ExpandButton = ({ active, onClick }: { active: boolean, onClick: () => void }) => { +const ExpandButton = ({ active, onClick }: { active: boolean; onClick: () => void }) => { return ( - ); }; -const Input = ({ - id, - errors, - register, - onAdd, - onRemove, - canRemove = true, - onInputChange, -}: InputProps) => { +const Input = ({ id, errors, register, onAdd, onRemove, canRemove = true, onInputChange }: InputProps) => { const [descriptionExpanded, setDescriptionExpanded] = useState(false); return (
@@ -75,7 +55,12 @@ const Input = ({ {canRemove && }
- {setDescriptionExpanded(!descriptionExpanded)}} active={descriptionExpanded} /> + { + setDescriptionExpanded(!descriptionExpanded); + }} + active={descriptionExpanded} + />
@@ -83,7 +68,7 @@ const Input = ({ id={`${id}-key`} {...register(`${id}-key`, { required: true, - onChange: () => setTimeout(onInputChange, 0) + onChange: () => setTimeout(onInputChange, 0), })} placeholder="Key Name" type="text" @@ -106,11 +91,13 @@ const Input = ({ {errors[`${id}-key`]?.message?.toString() || 'Key name is required'} )} -
+