Skip to content

Commit

Permalink
fix(formula): clear progress when formula calculation stoped
Browse files Browse the repository at this point in the history
  • Loading branch information
Dushusir committed Oct 26, 2024
1 parent 2063e66 commit 017428a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 33 deletions.
20 changes: 0 additions & 20 deletions packages/engine-formula/src/services/dependency-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,26 +289,6 @@ export class DependencyManagerService extends Disposable implements IDependencyM
child?.parents.delete(shouldBeClearTree.treeId);
}

const parentsArray: FormulaDependencyTree[] = [];
const childrenArray: FormulaDependencyTree[] = [];

for (const parentTreeId of parents) {
const parent = allTreeMap.get(parentTreeId);
if (parent) {
parentsArray.push(parent);
}
}

for (const childTreeId of children) {
const child = allTreeMap.get(childTreeId);
if (child) {
childrenArray.push(child);
}
}

this._buildDependencyTree(parentsArray, childrenArray);
this._buildReverseDependency(parentsArray, childrenArray);

shouldBeClearTree.dispose();
}

Expand Down
11 changes: 5 additions & 6 deletions packages/engine-formula/src/services/runtime.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,12 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime

const arrayFormulaRange = this._unitArrayFormulaRange[unitId]!;

let arrayData = new ObjectMatrix<IRange>();

if (arrayFormulaRange[sheetId]) {
arrayData = new ObjectMatrix(arrayFormulaRange[sheetId]);
if (arrayFormulaRange[sheetId] === null || arrayFormulaRange[sheetId] === undefined) {
arrayFormulaRange[sheetId] = {};
}

const arrayData = new ObjectMatrix<IRange>(arrayFormulaRange[sheetId]);

if (this._runtimeArrayFormulaCellData[unitId] === undefined) {
this._runtimeArrayFormulaCellData[unitId] = {};
}
Expand Down Expand Up @@ -522,10 +522,9 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime
endColumn: endColumn - startColumn + column,
};

// Do not use getData to synchronize arrayData to arrayFormulaRange[sheetId] anymore, they are already linked, otherwise it will cause performance issues
arrayData.setValue(row, column, arrayRange);

arrayFormulaRange[sheetId] = arrayData.getData();

if (
this._checkIfArrayFormulaRangeHasData(unitId, sheetId, row, column, arrayRange) ||
this._checkIfArrayFormulaExceeded(rowCount, columnCount, arrayRange)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,15 @@ export class TriggerCalculationController extends Disposable {

this.disposeWithMe(

// eslint-disable-next-line max-lines-per-function
// eslint-disable-next-line max-lines-per-function, complexity
this._commandService.onCommandExecuted((command: ICommandInfo) => {
if (command.id === SetFormulaCalculationStartMutation.id) {
const { forceCalculation } = command.params as ISetFormulaCalculationStartMutation;
if (forceCalculation) {
this._forceCalculating = true;
}
} else if (command.id === SetFormulaCalculationStopMutation.id) {
this.clearProgress();
}

if (command.id !== SetFormulaCalculationNotificationMutation.id) {
Expand Down Expand Up @@ -359,8 +361,6 @@ export class TriggerCalculationController extends Disposable {
break;
case FormulaExecutedStateType.STOP_EXECUTION:
result = 'The execution of the formula has been stopped';
// this._executingCommandQueue = [];
this.clearProgress();
calculationProcessCount = 0;
break;
case FormulaExecutedStateType.SUCCESS:
Expand Down
24 changes: 20 additions & 4 deletions packages/ui/src/components/progress-bar/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,30 @@ export function ProgressBar(props: IProgressBarProps) {
// Introduce a state variable for visibility
const [visible, setVisible] = useState(count > 0);

const [prevCount, setPrevCount] = useState(0);
const [prevDone, setPrevDone] = useState(0);

useEffect(() => {
if (!progressBarInnerRef.current) return;

const progressBarInner = progressBarInnerRef.current;

// Hide immediately if both count and done are zero
if (count === 0 && done === 0) {
setVisible(false);
}
// Handle the special case if count and done are equal for the first time and not from a previous progress change
else if (count === done && prevCount === 0 && prevDone === 0) {
setVisible(true);
progressBarInner.style.width = '0%';
requestAnimationFrame(() => {
progressBarInner.style.width = '100%';
});
}
// Update the width of the progress bar
if (count > 0) {
else if (count > 0) {
setVisible(true);
progressBarInner.style.width = `${Math.floor((done / count) * 100)}%`;
} else if (count === 0 && done === 0) {
// Hide immediately if both count and done are zero
setVisible(false);
}
// Else, wait for the transition to end before hiding

Expand All @@ -70,6 +82,10 @@ export function ProgressBar(props: IProgressBarProps) {

progressBarInner.addEventListener('transitionend', handleTransitionEnd);

// Update prevCount and prevDone
setPrevCount(count);
setPrevDone(done);

// Clean up the event listener on unmount or when dependencies change
return () => {
progressBarInner.removeEventListener('transitionend', handleTransitionEnd);
Expand Down

0 comments on commit 017428a

Please sign in to comment.