Skip to content

Commit

Permalink
fix(*): re-introduced file type into the system - missing type broke …
Browse files Browse the repository at this point in the history
…the backoffice
  • Loading branch information
Omri-Levy committed Nov 28, 2023
1 parent 85d2498 commit ea423a2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-lies-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ballerine/common': patch
---

updated validation to allow file type on document page
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { HTTPError } from 'ky';
import get from 'lodash/get';
import set from 'lodash/set';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { getDocumentFileTypePath } from '@/components/organisms/UIRenderer/elements/JSONForm/components/DocumentField/helpers/getDocumentFileTypePath';

interface DocumentFieldParams {
documentData: Partial<Document>;
Expand Down Expand Up @@ -94,13 +95,15 @@ export const DocumentField = (
}

const fileIdPath = getDocumentFileIdPath(definition);
const fileTypePath = getDocumentFileTypePath(definition);

try {
const uploadResult = await uploadFile({ file });

// @ts-ignore
set(document, fileIdPath, uploadResult.id);
// set(document, fileTypePath, file.type);
// @ts-ignore
set(document, fileTypePath, file.type);
set(document, 'decision', {});

stateApi.setContext(context);
Expand Down
25 changes: 24 additions & 1 deletion packages/common/src/schemas/documents/default-context-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,28 @@ export const defaultContextSchema = Type.Object({
version: Type.Optional(Type.Number()),
pages: Type.Array(
Type.Union([
Type.Object({ ballerineFileId: Type.String() }, { additionalProperties: false }),
Type.Object(
{
ballerineFileId: Type.String(),
type: Type.Optional(
Type.String({
enum: [
'text/csv',
'application/csv',
'application/pdf',
'image/png',
'image/jpg',
'image/jpeg',
// Backwards compatibility
'pdf',
'png',
'jpg',
],
}),
),
},
{ additionalProperties: false },
),
Type.Object(
{
ballerineFileId: Type.Optional(Type.String()),
Expand All @@ -108,6 +129,8 @@ export const defaultContextSchema = Type.Object({
type: Type.Optional(
Type.String({
enum: [
'text/csv',
'application/csv',
'application/pdf',
'image/png',
'image/jpg',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const FileInputAdapter: RJSFInputAdapter<File> = ({
placeholder={uiSchema?.['ui:placeholder']}
//@ts-ignore
onChange={handleChange}
accept="image/jpeg, image/png, application/pdf, .docx, .csv"
accept="image/jpeg, image/png, application/pdf, .docx"
className="line-1 flex items-center"
disabled={disabled}
onBlur={handleBlur}
Expand Down

0 comments on commit ea423a2

Please sign in to comment.