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

feat: Added Column Warning #921

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface ISaveResults {
interface IDataItem {
index: number;
errors?: Record<string, string>;
wanings?: Record<string, string>;
isValid: boolean;
record: Record<string, any>;
updated: Record<string, boolean>;
Expand Down Expand Up @@ -268,6 +269,7 @@ export class DoReReview extends BaseReview {
update: {
$set: {
errors: record.errors,
warnings: record.warnings,
isValid: record.isValid,
updated: {},
},
Expand Down
23 changes: 22 additions & 1 deletion apps/api/src/app/shared/services/sandbox/contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,38 @@ 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(
rowIndexToUpdate > -1 &&
(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
}
Expand Down
9 changes: 9 additions & 0 deletions apps/widget/src/components/Common/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions libs/dal/src/dal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions libs/dal/src/repositories/record/record.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export class RecordEntity {

errors: Record<string, string>;

warnings: Record<string, string>;

record: Record<string, any>;

updated: Record<string, boolean>;
Expand Down
1 change: 1 addition & 0 deletions libs/dal/src/repositories/record/record.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
1 change: 1 addition & 0 deletions libs/shared/src/entities/Record/Record.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export interface IRecord {
isValid: boolean;
record: Record<string, any>;
errors?: Record<string, string>;
warnings?: Record<string, any>;
updated: Record<string, boolean>;
}
Loading