Skip to content

Commit

Permalink
fix: remove mei row in meiData when cleared
Browse files Browse the repository at this point in the history
Refs: #117
  • Loading branch information
kunfang98927 committed Jul 12, 2024
1 parent 2d2001a commit e208967
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
18 changes: 10 additions & 8 deletions src/Editor/CressTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,18 @@ export class CressTable {
changes?.forEach(([row, prop, oldValue, newValue]) => {
if (prop === 'mei' && oldValue !== newValue) {
// validate the new edited mei data and update the validation status
this.meiTools.setProcessStatus(newValue);
this.meiTools.updateMeiData(row, newValue, undefined, undefined);
this.table.render();
this.validationTools
.meiValidator(newValue)
.then(([isValid, errorMsg]) => {
this.meiTools.updateMeiData(row, undefined, isValid, errorMsg);
this.table.render();
this.meiTools.setResultStatus();
});
if (newValue !== '') {
this.meiTools.setProcessStatus(newValue);
this.validationTools
.meiValidator(newValue)
.then(([isValid, errorMsg]) => {
this.meiTools.updateMeiData(row, undefined, isValid, errorMsg);
this.table.render();
this.meiTools.setResultStatus();
});
}
}
});
}
Expand Down
13 changes: 9 additions & 4 deletions src/Editor/MeiTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export class MeiTools {
) {
const meiData = this.meiData.find((meiData) => meiData.row === row);
if (meiData) {
// if the mei cell is empty, remove the row from meiData
if (mei === '') {
this.meiData = this.meiData.filter((meiData) => meiData.row !== row);
return;
}
if (mei !== undefined) {
meiData.mei = mei;
}
Expand All @@ -52,10 +57,10 @@ export class MeiTools {
}
} else {
this.meiData.push({
row,
mei: mei ?? meiData.mei,
isValid: isValid ?? meiData.isValid,
errorMsg: errorMsg ?? meiData.errorMsg,
row: row,
mei: mei ?? '',
isValid: isValid ?? null,
errorMsg: errorMsg ?? null,
});
}
}
Expand Down

0 comments on commit e208967

Please sign in to comment.