-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement standalone KYC Case summarization (#103)
Signed-off-by: Sean Sundberg <[email protected]>
- Loading branch information
Showing
22 changed files
with
324 additions
and
12 deletions.
There are no files selected for viewing
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,4 @@ | ||
import {atom} from "jotai"; | ||
import {DocumentStatusModel} from "../models"; | ||
|
||
export const documentStatusAtom = atom<DocumentStatusModel[]>([]); |
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,16 @@ | ||
import {atom} from "jotai"; | ||
import {loadable} from "jotai/utils"; | ||
|
||
import {kycCaseSummaryApi} from "../services/kyc-case-summary"; | ||
import {KycCaseSummaryModel} from "../models"; | ||
|
||
const baseAtom = atom<Promise<KycCaseSummaryModel | undefined>>(Promise.resolve(undefined)); | ||
|
||
export const kycCaseSummaryAtom = atom( | ||
get => get(baseAtom), | ||
async (_get, set, name: string) => { | ||
set(baseAtom, kycCaseSummaryApi().summarize(name).then(summary => ({summary}))) | ||
} | ||
) | ||
|
||
export const kycCaseSummaryAtomLoadable = loadable(kycCaseSummaryAtom) |
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,65 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import React, {useEffect} from 'react'; | ||
import {useAtom} from "jotai"; | ||
import {timer} from "rxjs"; | ||
|
||
import {documentStatusAtom} from "../../atoms/document-status.atom"; | ||
import {DocumentModel, DocumentStatusModel} from "../../models"; | ||
import {fileUploadApi, FileUploadContext, ListFileRequest} from "../../services"; | ||
import {first} from "../../utils"; | ||
|
||
export interface DocumentStatusProps { | ||
context: FileUploadContext; | ||
statuses?: string[]; | ||
documents: DocumentModel[]; | ||
} | ||
|
||
const buildRequest = ({context, statuses}: {context: FileUploadContext, statuses?: string[]}): ListFileRequest => { | ||
const request: ListFileRequest = {context} | ||
|
||
if (statuses) { | ||
request.statuses = statuses; | ||
} | ||
|
||
return request; | ||
} | ||
|
||
const getFilename = (id: string, docs: DocumentModel[]): string => { | ||
return first(docs.filter(doc => doc.id === id).map(doc => doc.name)).orElse(undefined) | ||
} | ||
|
||
export const DocumentStatus: React.FunctionComponent<DocumentStatusProps> = (props: DocumentStatusProps) => { | ||
const [documentStatus, setDocumentStatus] = useAtom(documentStatusAtom) | ||
useEffect(() => { | ||
const handle = timer(500, 30000).subscribe({ | ||
next: async () => { | ||
if (props.documents.length === 0 && documentStatus.length === 0) { | ||
return | ||
} | ||
|
||
const result: DocumentStatusModel[] = await fileUploadApi().listFiles(buildRequest(props)) | ||
|
||
setDocumentStatus(result | ||
.map(doc => Object.assign(doc, {name: getFilename(doc.id, props.documents)})) | ||
.filter(doc => !!doc.name) | ||
) | ||
} | ||
}) | ||
|
||
return () => handle.unsubscribe(); | ||
}) | ||
|
||
if (documentStatus.length === 0) { | ||
return (<></>) | ||
} | ||
|
||
return ( | ||
<div style={{justifyContent: 'flex-start'}}> | ||
<div className="cds--file--label" style={{textAlign: 'left'}}>Document status</div> | ||
<ul> | ||
{documentStatus.map(val => (<li key={val.id} style={{textAlign: 'left'}}>{val.name || val.id} - {val.status}</li>))} | ||
</ul> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './DocumentStatus' |
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
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 |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import {DocumentModel} from "../../models"; | ||
import {DocumentModel, DocumentStatusModel} from "../../models"; | ||
|
||
export type FileUploadContext = 'data-extraction' | 'kyc-case'; | ||
|
||
export const isFileUploadContext = (value: unknown): value is FileUploadContext => { | ||
return value === 'data-extraction' || value === 'kyc-case'; | ||
} | ||
|
||
export interface ListFileRequest { | ||
context?: FileUploadContext, | ||
statuses?: string[], | ||
} | ||
|
||
export abstract class FileUploadApi { | ||
abstract uploadFile(caseId: string, name: string, file: File, context?: FileUploadContext): Promise<DocumentModel>; | ||
abstract uploadFile(caseId: string, name: string, file: File, context?: FileUploadContext, standalone?: boolean): Promise<DocumentModel>; | ||
abstract listFiles(request?: ListFileRequest): Promise<DocumentStatusModel[]>; | ||
} |
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,13 @@ | ||
import {KycCaseSummaryApi} from "./kyc-case-summary.api"; | ||
import {KycCaseSummaryGraphql} from "./kyc-case-summary.graphql"; | ||
|
||
export * from './kyc-case-summary.api'; | ||
|
||
let _instance: KycCaseSummaryApi; | ||
export const kycCaseSummaryApi = (): KycCaseSummaryApi => { | ||
if (_instance) { | ||
return _instance; | ||
} | ||
|
||
return _instance = new KycCaseSummaryGraphql(); | ||
} |
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,4 @@ | ||
|
||
export abstract class KycCaseSummaryApi { | ||
abstract summarize(name: string): Promise<string>; | ||
} |
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,33 @@ | ||
import {ApolloClient, gql} from "@apollo/client"; | ||
|
||
import {KycCaseSummaryApi} from "./kyc-case-summary.api.ts"; | ||
import {getApolloClient} from "../../backends"; | ||
|
||
const SUMMARIZE = gql` | ||
query Summarize($name:String!) { | ||
summarize(name:$name) { | ||
result | ||
} | ||
} | ||
` | ||
|
||
export class KycCaseSummaryGraphql implements KycCaseSummaryApi { | ||
client: ApolloClient<unknown>; | ||
|
||
constructor() { | ||
this.client = getApolloClient(); | ||
} | ||
|
||
summarize(name: string): Promise<string> { | ||
return this.client | ||
.query<{summarize: {result: string}}>({ | ||
query: SUMMARIZE, | ||
variables: {name}, | ||
}) | ||
.then(result => result.data.summarize.result) | ||
.catch(() => { | ||
return '[Error]' | ||
}) as Promise<string> | ||
} | ||
|
||
} |
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,7 @@ | ||
import {KycCaseSummaryApi} from "./kyc-case-summary.api.ts"; | ||
|
||
export class KycCaseSummaryMock implements KycCaseSummaryApi { | ||
async summarize(name: string): Promise<string> { | ||
return name; | ||
} | ||
} |
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
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
Oops, something went wrong.