Skip to content

Commit

Permalink
#2547 Updated Error Highlight Logic (#2561)
Browse files Browse the repository at this point in the history
* Updated Error Highlight Logic

* Separate Error Messages + Improved Record Counts

* Fix Record Counts
  • Loading branch information
demariadaniel authored Feb 8, 2023
1 parent 91d4625 commit 0d49fc7
Showing 1 changed file with 28 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ const ClinicalEntityDataTable = ({
? []
: currentDonors.length
? currentDonors
: searchResults
.map(({ donorId }: ClinicalSearchResults) => donorId)
.slice(page * pageSize, nextSearchPage < totalResults ? nextSearchPage : totalResults);
: searchResults.map(({ donorId }: ClinicalSearchResults) => donorId);

const submitterDonorIds =
useDefaultQuery || currentDonors.length
Expand Down Expand Up @@ -301,10 +299,12 @@ const ClinicalEntityDataTable = ({

relatedErrors.forEach((error) => {
const { donorId } = donor;
const { errorType, fieldName } = error;
const { errorType, message, fieldName } = error;
const relatedErrorGroup = tableErrorGroups.find(
(tableErrorGroup) =>
tableErrorGroup[0].errorType === errorType && tableErrorGroup[0].fieldName === fieldName,
tableErrorGroup[0].errorType === errorType &&
tableErrorGroup[0].message === message &&
tableErrorGroup[0].fieldName === fieldName,
);
const tableError = { ...error, donorId };

Expand All @@ -325,25 +325,7 @@ const ClinicalEntityDataTable = ({
? `${fieldName} is not a field within the latest dictionary. Please remove this from the ${entityName}.tsv file before submitting.`
: message;

const entries = errorGroup
.map((error) => error.donorId)
.filter((donorId, i, originalArray) => originalArray.indexOf(donorId) === i)
.reduce((totalRecordCount, currentDonorId) => {
const currentEntityRecords =
clinicalData.clinicalEntities.find(
(entity) => reverseLookUpEntityAlias(entity.entityName) === entityType,
)?.records || [];

const currentDonorRecords = currentEntityRecords.filter(
(tableRecords) =>
tableRecords.some((record) => record.value === `${currentDonorId}`) &&
(tableRecords.some((record) => record.name === fieldName) ||
((errorType === 'MISSING_REQUIRED_FIELD' || errorType === 'INVALID_BY_SCRIPT') &&
!tableRecords.some((record) => record.name === fieldName))),
);

return totalRecordCount + currentDonorRecords.length;
}, 0);
const entries = errorGroup.length;

return {
entries,
Expand Down Expand Up @@ -411,7 +393,8 @@ const ClinicalEntityDataTable = ({
// If using default query, or using search but not filtering by donor in URL, then we display total number of search results
// Else we use the total number of results that match our query
totalDocs =
useDefaultQuery || (!currentDonors.length && totalResults > entityData.totalDocs)
(useDefaultQuery && entityType === 'donor') ||
(!currentDonors.length && totalResults > entityData.totalDocs)
? totalResults
: entityData.totalDocs;

Expand Down Expand Up @@ -470,11 +453,14 @@ const ClinicalEntityDataTable = ({
: originalDonorId,
);

const donorErrorData = clinicalErrors.find((donor) => donor.donorId === cellDonorId);
const donorErrorData = clinicalErrors
.filter((donor) => donor.donorId === cellDonorId)
.map((donor) => donor.errors)
.flat();

const columnErrorData =
donorErrorData &&
donorErrorData.errors.filter(
donorErrorData.length &&
donorErrorData.filter(
(error) =>
error &&
(error.entityName === entityType ||
Expand All @@ -489,15 +475,25 @@ const ClinicalEntityDataTable = ({
hasClinicalErrors &&
columnErrorData.filter(
(error) =>
error.info?.value === original[id] ||
(error.info?.value && error.info.value[0] === original[id]),
(error.errorType === 'INVALID_BY_SCRIPT' || error.errorType === 'INVALID_ENUM_VALUE') &&
(error.info?.value === original[id] ||
(error.info?.value && error.info.value[0] === original[id]) ||
(error.info.value === null && !Boolean(original[id]))),
);

const fieldError =
hasClinicalErrors &&
columnErrorData.filter(
(error) =>
(error.errorType === 'UNRECOGNIZED_FIELD' ||
error.errorType === 'MISSING_REQUIRED_FIELD') &&
error.fieldName === id,
);

// TODO: Only highlight specificErrors; requires update to clinical service
const errorState =
(isCompletionCell && original[id] === 0) ||
specificErrorValue?.length > 0 ||
hasClinicalErrors;
fieldError?.length > 0;

const border = getHeaderBorder(id);

Expand Down

0 comments on commit 0d49fc7

Please sign in to comment.