// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 import { FormMetadata, FormReviewWorkflowTag, StatusTransition } from '@aws/api-typescript'; import { Badge, Button, Inline, Link } from 'aws-northstar'; import Table from 'aws-northstar/components/Table'; import { Column as TableColumn } from 'aws-northstar/components/Table/types'; import Grid from 'aws-northstar/layouts/Grid'; import React, { useState, useEffect } from 'react'; import { API } from '../../../api/client'; import { listAllPages } from '../../../api/utils'; import { tagIdsToTags } from '../../../utils/review-tags-helper'; import { updateStatus } from '../../../utils/status-update-helper'; import { DurationBetween } from '../../status/durationBetween'; import { ExtractionExecutionStatusIndicator } from '../../status/extractionExecutionStatusIndicator'; export interface FormsTableProps { readonly dataLoaded?: boolean; readonly forms: FormMetadata[]; readonly reloadAction?: any; } export const FormsTable: React.FC = ({ dataLoaded, forms, reloadAction }) => { const [availableReviewTags, setAvailableReviewTags] = useState(); const formListColumns: TableColumn[] = [ { id: 'formId', width: 220, Header: 'Form', accessor: 'formId', Cell: ({ value, row }) => { const link = `/view/${row.original.documentId}/${value}`; return {row.original.documentName} {value}; }, }, { id: 'schema', width: 120, Header: 'Schema', accessor: 'schemaId', }, { id: 'updatedTimestamp', width: 150, Header: 'Last Updated', accessor: 'updatedTimestamp', Cell: ({ value }) => <>{new Date(value).toLocaleString()}, }, { id: 'status', width: 200, Header: 'Status', // backlog/in review/reviewed accessor: 'extractionExecution.status', Cell: ({ value, row }) => ( updateStatus(documentId, formId, 'REVIEWING')} statusReason={row.original.extractionExecution.statusReason} /> ), }, { id: 'tags', width: 250, Header: 'Tags', accessor: 'tags', // @ts-ignore Cell: ({ value, row }) => ( <> { tagIdsToTags(row.original.tags, availableReviewTags)?.map((tag: any) => ) } ), }, { id: 'reviewer', width: 100, Header: 'Reviewer', accessor: 'statusTransitionLog', Cell: ({ value }: { value: StatusTransition[] }) => ( <> { value.find(({ status }) => status === 'REVIEWED')?.actingUser || value.find(({ status }) => status === 'REVIEWING')?.actingUser || 'N/A' } ), }, { id: 'extractionTime', width: 100, Header: 'Data Extraction Time', accessor: 'statusTransitionLog', Cell: ({ value }) => ( ), }, { id: 'waitTime', width: 100, Header: 'Time in Queue', accessor: 'statusTransitionLog', Cell: ({ value }) => ( ), }, { id: 'reviewTime', width: 100, Header: 'Time in Review', accessor: 'statusTransitionLog', Cell: ({ value }) => ( ), }, ]; useEffect(() => { void (async () => { const tags = await listAllPages(API.listFormReviewWorkflowTags.bind(API), 'tags'); setAvailableReviewTags(tags); })(); }, []); const actionGroup = ( {reloadAction ?