From 710cda56566239ad5aefaca5256fa2ab05781a6d Mon Sep 17 00:00:00 2001 From: Mayur Date: Thu, 9 Jan 2025 12:55:26 +0530 Subject: [PATCH] feat: Added Column Warning --- .../do-review/re-review-data.usecase.ts | 2 ++ .../app/shared/services/sandbox/contents.ts | 23 ++++++++++++++++++- .../src/components/Common/Table/Table.tsx | 9 ++++++++ libs/dal/src/dal.service.ts | 4 ++-- .../src/repositories/record/record.entity.ts | 2 ++ .../src/repositories/record/record.schema.ts | 1 + .../src/entities/Record/Record.interface.ts | 1 + 7 files changed, 39 insertions(+), 3 deletions(-) diff --git a/apps/api/src/app/review/usecases/do-review/re-review-data.usecase.ts b/apps/api/src/app/review/usecases/do-review/re-review-data.usecase.ts index 18d05dbcc..e97105783 100644 --- a/apps/api/src/app/review/usecases/do-review/re-review-data.usecase.ts +++ b/apps/api/src/app/review/usecases/do-review/re-review-data.usecase.ts @@ -28,6 +28,7 @@ interface ISaveResults { interface IDataItem { index: number; errors?: Record; + wanings?: Record; isValid: boolean; record: Record; updated: Record; @@ -268,6 +269,7 @@ export class DoReReview extends BaseReview { update: { $set: { errors: record.errors, + warnings: record.warnings, isValid: record.isValid, updated: {}, }, diff --git a/apps/api/src/app/shared/services/sandbox/contents.ts b/apps/api/src/app/shared/services/sandbox/contents.ts index e873aca1c..71f525c59 100644 --- a/apps/api/src/app/shared/services/sandbox/contents.ts +++ b/apps/api/src/app/shared/services/sandbox/contents.ts @@ -42,7 +42,26 @@ function processErrors(batchData, errors) { if(!Array.isArray(errors) || (Array.isArray(errors) && errors.length === 0)) { return batchData; } - let rowIndexToUpdate, combinedErrors, isErrorsEmpty; + + errors.forEach(error => { + if (error.warnings && typeof error.warnings === 'object') { + const rowIndexToUpdate = batchData.data.findIndex(data => data.index === error.index); + + if (rowIndexToUpdate > -1) { + // Initialize warnings object if it doesn't exist + if (!batchData.data[rowIndexToUpdate].warnings) { + batchData.data[rowIndexToUpdate].warnings = {}; + } + + batchData.data[rowIndexToUpdate].warnings = { + ...batchData.data[rowIndexToUpdate].warnings, + ...error.warnings + }; + } + } + }); + + let rowIndexToUpdate, combinedErrors, isErrorsEmpty, combinedWarnings; errors.forEach(error => { rowIndexToUpdate = batchData.data.findIndex(data => data.index === error.index); if( @@ -50,9 +69,11 @@ function processErrors(batchData, errors) { (typeof error.errors === 'object' && !Array.isArray(error.errors) && error.errors !== null) ) { combinedErrors = Object.assign(batchData.data[rowIndexToUpdate]?.errors || {}, error.errors); + combinedWarnings = batchData.data[rowIndexToUpdate]?.warnings || {}; isErrorsEmpty = isObjectEmpty(combinedErrors); batchData.data[rowIndexToUpdate] = { ...batchData.data[rowIndexToUpdate], + warnings: combinedWarnings, errors: combinedErrors, isValid: isErrorsEmpty } diff --git a/apps/widget/src/components/Common/Table/Table.tsx b/apps/widget/src/components/Common/Table/Table.tsx index 92c645e64..5af0374a9 100644 --- a/apps/widget/src/components/Common/Table/Table.tsx +++ b/apps/widget/src/components/Common/Table/Table.tsx @@ -64,6 +64,7 @@ const createErrorSvg = memoize(() => { const memoizedStyles = { errorUpdated: 'vertical-align: middle;float: right;cursor: pointer;color:#795e00;', errorOnly: 'vertical-align: middle;float: right;cursor: pointer;color:#ff1111;', + warningOnly: 'vertical-align: middle;float: right;cursor: pointer;#795e00;', }; Handsontable.renderers.registerRenderer( @@ -72,6 +73,7 @@ Handsontable.renderers.registerRenderer( const name = String(prop).replace('record.', ''); const sourceData = instance.getSourceDataAtRow(row) as IRecord; const hasError = sourceData.errors?.[name]; + const hasWarnings = sourceData.warnings?.[name]; const isUpdated = sourceData.updated?.[name]; TD.className = 'custom-cell'; @@ -109,6 +111,13 @@ Handsontable.renderers.registerRenderer( errorSvg.setAttribute('style', memoizedStyles.errorOnly); TD.appendChild(errorSvg); TD.style.backgroundColor = '#fdebeb'; + } else if (hasWarnings) { + TD.ariaLabel = hasWarnings; + TD.dataset.cooltipzDir = row < 5 ? 'bottom' : 'top'; + TD.dataset.cooltipzSize = 'fit'; + errorSvg.setAttribute('style', hasWarnings ? memoizedStyles.warningOnly : memoizedStyles.errorUpdated); + TD.appendChild(errorSvg); + TD.style.backgroundColor = '#ffda5b'; } return TD; diff --git a/libs/dal/src/dal.service.ts b/libs/dal/src/dal.service.ts index c5ad0eacb..811716282 100644 --- a/libs/dal/src/dal.service.ts +++ b/libs/dal/src/dal.service.ts @@ -57,7 +57,7 @@ export class DalService { const conditions = type === 'all' ? {} : { isValid: type === 'valid' }; return model - .find(conditions, 'index isValid errors record updated') + .find(conditions, 'index isValid errors warnings record updated') .skip(Math.max(0, (page - 1) * limit)) // when page is 0, it was skiping 0*n records .limit(limit) .exec(); @@ -132,7 +132,7 @@ export class DalService { const model = this.getRecordCollection(_uploadId); if (!model) return; - return model.find({}, 'index isValid errors record'); + return model.find({}, 'index isValid errors warnings record'); } getFieldData(_uploadId: string, fields: string[]) { const model = this.getRecordCollection(_uploadId); diff --git a/libs/dal/src/repositories/record/record.entity.ts b/libs/dal/src/repositories/record/record.entity.ts index bbe206cf9..dffc3578a 100644 --- a/libs/dal/src/repositories/record/record.entity.ts +++ b/libs/dal/src/repositories/record/record.entity.ts @@ -7,6 +7,8 @@ export class RecordEntity { errors: Record; + warnings: Record; + record: Record; updated: Record; diff --git a/libs/dal/src/repositories/record/record.schema.ts b/libs/dal/src/repositories/record/record.schema.ts index 531bff111..58a50944f 100644 --- a/libs/dal/src/repositories/record/record.schema.ts +++ b/libs/dal/src/repositories/record/record.schema.ts @@ -7,6 +7,7 @@ const RecordSchema = new Schema({ }, isValid: Boolean, errors: Schema.Types.Mixed, + warnings: Schema.Types.Mixed, record: Schema.Types.Mixed, updated: Schema.Types.Mixed, }); diff --git a/libs/shared/src/entities/Record/Record.interface.ts b/libs/shared/src/entities/Record/Record.interface.ts index 129be485b..f80f81eb5 100644 --- a/libs/shared/src/entities/Record/Record.interface.ts +++ b/libs/shared/src/entities/Record/Record.interface.ts @@ -4,5 +4,6 @@ export interface IRecord { isValid: boolean; record: Record; errors?: Record; + warnings?: Record; updated: Record; }