fix: add isValidatingValue state to fix call validateValue api repeatedly #2830

This commit is contained in:
fangsmile 2024-11-18 15:07:50 +08:00 committed by Rui-Sun
parent dfbec6fe0f
commit 906c46cd3e

View File

@ -10,6 +10,7 @@ import { isValid } from '@visactor/vutils';
export class EditManeger { export class EditManeger {
table: BaseTableAPI; table: BaseTableAPI;
editingEditor: IEditor; editingEditor: IEditor;
isValidatingValue: boolean = false;
editCell: { col: number; row: number }; editCell: { col: number; row: number };
constructor(table: BaseTableAPI) { constructor(table: BaseTableAPI) {
@ -121,7 +122,9 @@ export class EditManeger {
if (!this.editingEditor) { if (!this.editingEditor) {
return true; return true;
} }
if (this.isValidatingValue) {
return false;
}
const target = e?.target as HTMLElement | undefined; const target = e?.target as HTMLElement | undefined;
const { editingEditor: editor } = this; const { editingEditor: editor } = this;
@ -141,6 +144,7 @@ export class EditManeger {
console.warn('VTable Warn: `getValue` is not provided, did you forget to implement it?'); console.warn('VTable Warn: `getValue` is not provided, did you forget to implement it?');
} }
if (this.editingEditor.validateValue) { if (this.editingEditor.validateValue) {
this.isValidatingValue = true;
const maybePromiseOrValue = this.editingEditor.validateValue?.(); const maybePromiseOrValue = this.editingEditor.validateValue?.();
if (isPromise(maybePromiseOrValue)) { if (isPromise(maybePromiseOrValue)) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -150,10 +154,12 @@ export class EditManeger {
this.doExit(); this.doExit();
resolve(true); resolve(true);
} else { } else {
this.isValidatingValue = false;
resolve(false); resolve(false);
} }
}) })
.catch((err: Error) => { .catch((err: Error) => {
this.isValidatingValue = false;
console.error('VTable Error:', err); console.error('VTable Error:', err);
reject(err); reject(err);
}); });
@ -184,6 +190,7 @@ export class EditManeger {
this.editingEditor.exit?.(); this.editingEditor.exit?.();
this.editingEditor.onEnd?.(); this.editingEditor.onEnd?.();
this.editingEditor = null; this.editingEditor = null;
this.isValidatingValue = false;
} }
cancelEdit() { cancelEdit() {