Skip to content

Commit

Permalink
fix(ui): progress clear message
Browse files Browse the repository at this point in the history
  • Loading branch information
Dushusir committed Oct 26, 2024
1 parent 1168d73 commit 2063e66
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@ export function FormulaProgressBar() {
commandService.executeCommand(SetFormulaCalculationStopMutation.id);
}, [commandService]);

return <ProgressBar progress={progress} onTerminate={terminateCalculation} />;
const clearProgress = useCallback(() => {
triggerCalculationController.clearProgress();
}, [triggerCalculationController]);

return <ProgressBar progress={progress} onTerminate={terminateCalculation} onClearProgress={clearProgress} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class TriggerCalculationController extends Disposable {
this._emitProgress();
}

private _clearProgress(): void {
clearProgress(): void {
this._doneCalculationTaskCount = 0;
this._totalCalculationTaskCount = 0;
this._emitProgress();
Expand Down Expand Up @@ -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:
Expand All @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion packages/ui/src/components/progress-bar/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
};

Expand Down

0 comments on commit 2063e66

Please sign in to comment.