Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Resolve Errors] [Review Warnings] Exceed error warning limit alert & counts read off the response body #699

Merged
merged 5 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/api/requests/downloadValidationReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ export const downloadValidationReport = async ({
baseURL: FILING_URL,
headers: {
Authorization: `Bearer ${auth.user?.access_token}`,
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
Expires: '0',
},
url: `/v1/filing/institutions/${lei}/filings/${filingPeriod}/submissions/${submissionId}/report`,
method: 'GET',
Expand Down
25 changes: 23 additions & 2 deletions src/pages/Filing/FilingApp/FieldEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { Link } from 'components/Link';
import { Heading, Pagination, Table } from 'design-system-react';
import { useState } from 'react';
import Markdown from 'react-markdown';
import type { Detail, Field } from 'types/filingTypes';
import type { Detail, Field, FilingPeriodType } from 'types/filingTypes';
import { ITEMS_PER_PAGE, One } from 'utils/constants';
import useIsOverflowing from 'utils/useIsOverflowing';
import FilingErrorsWarningsLimit from './FilingErrors/FilingErrorsWarningsLimit';

// NOTE: To be removed after table styling finalized
// const maxUidTestRows = [...Array.from({ length: Hundred }).keys()].map(
Expand All @@ -27,13 +28,24 @@ import useIsOverflowing from 'utils/useIsOverflowing';

interface FieldEntryProperties {
fieldObject: Detail;
lei: string;
submissionId: number;
filingPeriod: FilingPeriodType;
isWarning?: boolean;
}

function FieldEntry({ fieldObject }: FieldEntryProperties): JSX.Element {
function FieldEntry({
fieldObject,
lei,
submissionId,
filingPeriod,
isWarning,
}: FieldEntryProperties): JSX.Element {
const validationId = fieldObject.validation.id;
const validationLink = fieldObject.validation.fig_link;
const validationName = fieldObject.validation.name;
const validationDescription = fieldObject.validation.description;
const validationIsTruncated = fieldObject.validation.is_truncated;
// eslint-disable-next-line unicorn/no-array-reduce
const additionalColumnHeaders = fieldObject.records[0].fields.reduce(
(accumulator: Field['name'][], fieldsObject) => [
Expand Down Expand Up @@ -119,6 +131,11 @@ function FieldEntry({ fieldObject }: FieldEntryProperties): JSX.Element {
</Link>
<Heading type='4'>{validationName}</Heading>
<Markdown>{validationDescription}</Markdown>
{validationIsTruncated ? (
<FilingErrorsWarningsLimit
{...{ isWarning, lei, submissionId, filingPeriod }}
/>
) : null}
</div>
<div className='mb-[0.9375rem]'>
<Table
Expand Down Expand Up @@ -160,4 +177,8 @@ function FieldEntry({ fieldObject }: FieldEntryProperties): JSX.Element {
);
}

FieldEntry.defaultProps = {
isWarning: false,
};

export default FieldEntry;
17 changes: 15 additions & 2 deletions src/pages/Filing/FilingApp/FieldSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import SectionIntro from 'components/SectionIntro';
import FieldEntry from 'pages/Filing/FilingApp/FieldEntry';
import type { ReactNode } from 'react';
import type { Detail } from 'types/filingTypes';
import type { Detail, FilingPeriodType } from 'types/filingTypes';

interface FieldProperties {
fieldArray: Detail[];
heading: string;
bottomMargin?: boolean;
children: ReactNode;
id: string;
lei: string;
submissionId: number;
filingPeriod: FilingPeriodType;
isWarning?: boolean;
}

function FieldSummary({
Expand All @@ -18,6 +22,10 @@ function FieldSummary({
children,
id,
className = '',
lei,
submissionId,
filingPeriod,
isWarning,
}: FieldProperties & JSX.IntrinsicElements['div']): JSX.Element {
return (
<div
Expand All @@ -28,14 +36,19 @@ function FieldSummary({
{children}
</SectionIntro>
{fieldArray.map(fieldObject => (
<FieldEntry key={fieldObject.validation.id} fieldObject={fieldObject} />
<FieldEntry
key={fieldObject.validation.id}
fieldObject={fieldObject}
{...{ isWarning, lei, submissionId, filingPeriod }}
/>
))}
</div>
);
}

FieldSummary.defaultProps = {
bottomMargin: false,
isWarning: false,
};

export default FieldSummary;
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const getErrorsWarningsSummary = (
};
};

// Deprecated: Count should now come from the data response object
export const getRecordsAffected = (
validationDetails: Detail[],
): Set<number> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function FilingErrorsWarningsLimit({
}: DownloadValidationReportButtonLimitProperties &
FilingErrorsWarningsLimitProperties): JSX.Element {
return (
<div className='mt-[0.9375rem] max-w-[41.875rem]'>
<div className='my-[1.875rem] max-w-[41.875rem]'>
<AlertFieldLevel
message={
isWarning ? (
Expand Down
33 changes: 22 additions & 11 deletions src/pages/Filing/FilingApp/FilingErrors/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import FormWrapper from 'components/FormWrapper';
import { LoadingContent } from 'components/Loading';
import { Paragraph, TextIntroduction } from 'design-system-react';
import FieldSummary from 'pages/Filing/FilingApp/FieldSummary';
import {
getErrorsWarningsSummary,
getRecordsAffected,
} from 'pages/Filing/FilingApp/FilingErrors/FilingErrors.helpers';
import { getErrorsWarningsSummary } from 'pages/Filing/FilingApp/FilingErrors/FilingErrors.helpers';
import FilingErrorsAlerts from 'pages/Filing/FilingApp/FilingErrors/FilingErrorsAlerts';
import { FilingSteps } from 'pages/Filing/FilingApp/FilingSteps';
import InstitutionHeading from 'pages/Filing/FilingApp/InstitutionHeading';
Expand Down Expand Up @@ -64,11 +61,16 @@ function FilingErrors(): JSX.Element {
: syntaxErrorsSingle;

// Count rows with errors per type (not total errors)
const singleFieldRowErrorsCount = getRecordsAffected(
singleFieldErrorsUsed,
).size;
const multiFieldRowErrorsCount = getRecordsAffected(logicErrorsMulti).size;
const registerLevelRowErrorsCount = getRecordsAffected(registerErrors).size;
const singleFieldCategory = isStep2 ? 'logic_errors' : 'syntax_errors';
const singleFieldRowErrorsCount =
actualDataGetSubmissionLatest?.validation_results?.[singleFieldCategory]
.single_field_count ?? 0;
const multiFieldRowErrorsCount =
actualDataGetSubmissionLatest?.validation_results?.[singleFieldCategory]
.multi_field_count ?? 0;
const registerLevelRowErrorsCount =
actualDataGetSubmissionLatest?.validation_results?.[singleFieldCategory]
.register_count ?? 0;

if (isFetchingGetSubmissionLatest || isLoadingInstitution)
return <LoadingContent />;
Expand Down Expand Up @@ -168,25 +170,31 @@ function FilingErrors(): JSX.Element {
{!errorGetSubmissionLatest && (
<>
{/* SINGLE-FIELD ERRORS */}
{errorState ? (
{errorState && actualDataGetSubmissionLatest?.id ? (
<FieldSummary
id='single-field-errors'
heading={`Single-field errors: ${singleFieldRowErrorsCount.toLocaleString()} found`}
fieldArray={singleFieldErrorsUsed}
lei={lei}
filingPeriod={year}
submissionId={actualDataGetSubmissionLatest.id}
bottomMargin={Boolean(isStep2)}
>
Each single-field validation pertains to only one specific field
in each record. These validations check that the data held in an
individual field match the values that are expected.
</FieldSummary>
) : null}
{isStep2 && errorState ? (
{isStep2 && errorState && actualDataGetSubmissionLatest?.id ? (
<>
{/* MULTI-FIELD ERRORS */}
<FieldSummary
id='multi-field-errors'
heading={`Multi-field errors: ${multiFieldRowErrorsCount.toLocaleString()} found`}
fieldArray={logicErrorsMulti}
lei={lei}
filingPeriod={year}
submissionId={actualDataGetSubmissionLatest.id}
bottomMargin
>
Multi-field validations check that the values of certain
Expand All @@ -198,6 +206,9 @@ function FilingErrors(): JSX.Element {
id='register-level-errors'
heading={`Register-level errors: ${registerLevelRowErrorsCount.toLocaleString()} found`}
fieldArray={registerErrors}
lei={lei}
filingPeriod={year}
submissionId={actualDataGetSubmissionLatest.id}
>
This validation checks that the register does not contain
duplicate IDs.
Expand Down
19 changes: 12 additions & 7 deletions src/pages/Filing/FilingApp/FilingWarnings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ import { sblHelpMail } from 'utils/common';
import useGetSubmissionLatest from 'utils/useGetSubmissionLatest';
import useInstitutionDetails from 'utils/useInstitutionDetails';
import FieldSummary from '../FieldSummary';
import {
getErrorsWarningsSummary,
getRecordsAffected,
} from '../FilingErrors/FilingErrors.helpers';
import { getErrorsWarningsSummary } from '../FilingErrors/FilingErrors.helpers';
import FilingFieldLinks from '../FilingFieldLinks';
import { FilingNavButtons } from '../FilingNavButtons';
import { FilingSteps } from '../FilingSteps';
Expand Down Expand Up @@ -72,9 +69,9 @@ function FilingWarnings(): JSX.Element {

// Count rows with warnings per type (not total errors)
const singleFieldRowWarningsCount =
getRecordsAffected(logicWarningsSingle).size;
submission?.validation_results?.logic_warnings.single_field_count ?? 0;
const multiFieldRowWarningsCount =
getRecordsAffected(logicWarningsMulti).size;
submission?.validation_results?.logic_warnings.multi_field_count ?? 0;

const isVerified =
isSubmissionAccepted(submission) || boxChecked || !hasWarnings;
Expand Down Expand Up @@ -177,13 +174,17 @@ function FilingWarnings(): JSX.Element {
hasSubmissionError: errorSubmissionFetch,
}}
/>
{!errorSubmissionFetch && hasWarnings ? (
{!errorSubmissionFetch && hasWarnings && submission.id ? (
<div className='u-mt45'>
{/* SINGLE-FIELD WARNINGS */}
<FieldSummary
id='single-field-warnings'
heading={`Single-field warnings: ${singleFieldRowWarningsCount.toLocaleString()} found`}
fieldArray={logicWarningsSingle}
lei={lei}
filingPeriod={year}
submissionId={submission.id}
isWarning
bottomMargin
>
Each single-field validation pertains to only one specific field
Expand All @@ -196,6 +197,10 @@ function FilingWarnings(): JSX.Element {
id='multi-field-warnings'
heading={`Multi-field warnings: ${multiFieldRowWarningsCount.toLocaleString()} found`}
fieldArray={logicWarningsMulti}
lei={lei}
filingPeriod={year}
submissionId={submission.id}
isWarning
bottomMargin
>
Multi-field validations check that the values of certain fields
Expand Down
6 changes: 5 additions & 1 deletion src/types/filingTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ export interface ValidationResults {
}

export interface ValidationErrorWarning {
count: number;
single_field_count: number;
multi_field_count: number;
register_count: number;
total_count: number;
details: Detail[];
}

Expand All @@ -170,6 +173,7 @@ export interface Validation {
severity: 'Error' | 'Warning';
scope: 'multi-field' | 'register' | 'single-field';
fig_link: string;
is_truncated: boolean;
}
export interface FilingPeriodSchema {
code: FilingPeriodType;
Expand Down