From 2063e6605c230df842df7aa25cdfb029b58b6643 Mon Sep 17 00:00:00 2001 From: Dushusir <1414556676@qq.com> Date: Wed, 23 Oct 2024 12:11:02 +0800 Subject: [PATCH] fix(ui): progress clear message --- .../src/views/formula-progress/FormulaProgress.tsx | 6 +++++- .../src/controllers/trigger-calculation.controller.ts | 6 +++--- packages/ui/src/components/progress-bar/ProgressBar.tsx | 9 ++++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/sheets-formula-ui/src/views/formula-progress/FormulaProgress.tsx b/packages/sheets-formula-ui/src/views/formula-progress/FormulaProgress.tsx index d712cbb216e..ba7a66a7b1c 100644 --- a/packages/sheets-formula-ui/src/views/formula-progress/FormulaProgress.tsx +++ b/packages/sheets-formula-ui/src/views/formula-progress/FormulaProgress.tsx @@ -29,5 +29,9 @@ export function FormulaProgressBar() { commandService.executeCommand(SetFormulaCalculationStopMutation.id); }, [commandService]); - return ; + const clearProgress = useCallback(() => { + triggerCalculationController.clearProgress(); + }, [triggerCalculationController]); + + return ; } diff --git a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts index 76e08bdba4e..cf8130da13e 100644 --- a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts +++ b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts @@ -109,7 +109,7 @@ export class TriggerCalculationController extends Disposable { this._emitProgress(); } - private _clearProgress(): void { + clearProgress(): void { this._doneCalculationTaskCount = 0; this._totalCalculationTaskCount = 0; this._emitProgress(); @@ -360,7 +360,7 @@ export class TriggerCalculationController extends Disposable { case FormulaExecutedStateType.STOP_EXECUTION: result = 'The execution of the formula has been stopped'; // this._executingCommandQueue = []; - this._clearProgress(); + this.clearProgress(); calculationProcessCount = 0; break; case FormulaExecutedStateType.SUCCESS: @@ -383,7 +383,7 @@ export class TriggerCalculationController extends Disposable { // The total calculation time does not exceed 1s, and the progress bar is not displayed. clearTimeout(startDependencyTimer); startDependencyTimer = null; - this._clearProgress(); + this.clearProgress(); } else { // Manually hide the progress bar only if no other calculations are in process this._completeProgress(); diff --git a/packages/ui/src/components/progress-bar/ProgressBar.tsx b/packages/ui/src/components/progress-bar/ProgressBar.tsx index 03a339d257d..58cc3990719 100644 --- a/packages/ui/src/components/progress-bar/ProgressBar.tsx +++ b/packages/ui/src/components/progress-bar/ProgressBar.tsx @@ -23,10 +23,11 @@ export interface IProgressBarProps { progress: { done: number; count: number }; barColor?: string; onTerminate?: () => void; + onClearProgress?: () => void; // Notify the parent component of the reset progress } export function ProgressBar(props: IProgressBarProps) { - const { barColor, progress, onTerminate } = props; + const { barColor, progress, onTerminate, onClearProgress } = props; const { count, done } = progress; const themeService = useDependency(ThemeService); @@ -58,6 +59,12 @@ export function ProgressBar(props: IProgressBarProps) { setVisible(false); // Reset the width for future progress bars progressBarInner.style.width = '0%'; + + // Notify the parent component to reset the progress after the animation ends + // After the progress bar is completed 100%, the upper props data source may not be reset, resulting in count and done still being the previous values (displaying 100%) when the progress bar is triggered next time, so a message is reported here to trigger clearing. + if (done === count && onClearProgress) { + onClearProgress(); + } } };