Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sheets): bugfix for freeze & hover-manager-service & data-validation #2233

Merged
merged 12 commits into from
May 15, 2024
Prev Previous commit
Next Next commit
feat: update
  • Loading branch information
weird94 committed May 13, 2024
commit d5d96457f29ffe781ee082da9cf61e22c08a31cd
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@


import type { ICellDataForSheetInterceptor, ICellRenderContext, Workbook } from '@univerjs/core';
import { DataValidationRenderMode, DataValidationStatus, DataValidationType, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, UniverInstanceType, WrapStrategy } from '@univerjs/core';
import { DataValidationModel, DataValidatorRegistryService } from '@univerjs/data-validation';
import { DataValidationRenderMode, DataValidationStatus, DataValidationType, ICommandService, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, sequenceExecute, UniverInstanceType, WrapStrategy } from '@univerjs/core';
import type { IUpdateDataValidationSettingCommandParams } from '@univerjs/data-validation';
import { DataValidationModel, DataValidatorRegistryService, UpdateDataValidationSettingCommand } from '@univerjs/data-validation';
import { ComponentManager, IMenuService } from '@univerjs/ui';
import { Inject, Injector } from '@wendellhu/redi';
import { AutoHeightController, IEditorBridgeService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
Expand Down Expand Up @@ -59,7 +60,8 @@ export class DataValidationRenderController extends RxDisposable {
@Inject(DataValidationDropdownManagerService) private readonly _dropdownManagerService: DataValidationDropdownManagerService,
@Inject(SheetInterceptorService) private readonly _sheetInterceptorService: SheetInterceptorService,
@Inject(Injector) private readonly _injector: Injector,
@Inject(AutoHeightController) private readonly _autoHeightController: AutoHeightController
@Inject(AutoHeightController) private readonly _autoHeightController: AutoHeightController,
@ICommandService private readonly _commandService: ICommandService
) {
super();
this._init();
Expand Down Expand Up @@ -332,12 +334,11 @@ export class DataValidationRenderController extends RxDisposable {
}

private _initAutoHeight() {
this.disposeWithMe(
this._dataValidationModel.ruleChange$.subscribe((payload) => {
if (payload.rule) {
this._autoHeightController.markRangeAutoHeightDirty(payload.rule.ranges);
}
})
);
this._dataValidationModel.ruleChange$.subscribe((info) => {
if (info.rule?.ranges) {
const mutations = this._autoHeightController.getUndoRedoParamsOfAutoHeight(info.rule.ranges);
sequenceExecute(mutations.redos, this._commandService);
}
});
}
}
22 changes: 4 additions & 18 deletions packages/sheets-ui/src/controllers/auto-height.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@ import {
} from '@univerjs/sheets';
import { Inject, Injector } from '@wendellhu/redi';

import { Subject } from 'rxjs';
import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';

@OnLifecycle(LifecycleStages.Ready, AutoHeightController)
export class AutoHeightController extends Disposable {
private _autoHeightDirtyRanges$ = new Subject<IRange[]>();
autoHeightDirtyRanges$ = this._autoHeightDirtyRanges$.asObservable();

constructor(
@Inject(Injector) private _injector: Injector,
@Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService,
Expand All @@ -52,7 +48,7 @@ export class AutoHeightController extends Disposable {
this._initialize();
}

private _getUndoRedoParamsOfAutoHeight(ranges: IRange[]) {
getUndoRedoParamsOfAutoHeight(ranges: IRange[]) {
const {
_univerInstanceService: univerInstanceService,
_sheetSkeletonManagerService: sheetSkeletonService,
Expand All @@ -71,12 +67,10 @@ export class AutoHeightController extends Disposable {
unitId,
rowsAutoHeightInfo,
};

const undoParams: ISetWorksheetRowAutoHeightMutationParams = SetWorksheetRowAutoHeightMutationFactory(
injector,
redoParams
);

return {
undos: [
{
Expand Down Expand Up @@ -106,7 +100,7 @@ export class AutoHeightController extends Disposable {
};
}

return this._getUndoRedoParamsOfAutoHeight(command.params.range);
return this.getUndoRedoParamsOfAutoHeight(command.params.range);
},
}));
// for intercept 'sheet.command.set-row-is-auto-height' command.
Expand All @@ -119,7 +113,7 @@ export class AutoHeightController extends Disposable {
};
}

return this._getUndoRedoParamsOfAutoHeight(command.params.ranges);
return this.getUndoRedoParamsOfAutoHeight(command.params.ranges);
},
}));

Expand Down Expand Up @@ -153,16 +147,8 @@ export class AutoHeightController extends Disposable {
};
}

return this._getUndoRedoParamsOfAutoHeight(selections);
return this.getUndoRedoParamsOfAutoHeight(selections);
},
}));

this.disposeWithMe(this.autoHeightDirtyRanges$.subscribe((ranges) => {
this._getUndoRedoParamsOfAutoHeight(ranges);
}));
}

markRangeAutoHeightDirty(ranges: IRange[]) {
this._autoHeightDirtyRanges$.next(ranges);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import type { BooleanNumber, IMutation, IObjectArrayPrimitiveType, IRange, Nullable } from '@univerjs/core';
import type { BooleanNumber, IMutation, IObjectArrayPrimitiveType, IRange, Nullable, Workbook } from '@univerjs/core';
import { CommandType, IUniverInstanceService } from '@univerjs/core';
import type { IRowAutoHeightInfo } from '@univerjs/engine-render';
import type { IAccessor } from '@wendellhu/redi';
Expand Down Expand Up @@ -202,7 +202,7 @@ export const SetWorksheetRowAutoHeightMutation: IMutation<ISetWorksheetRowAutoHe
handler: (accessor, params) => {
const { unitId, subUnitId, rowsAutoHeightInfo } = params;
const univerInstanceService = accessor.get(IUniverInstanceService);
const workbook = univerInstanceService.getUniverSheetInstance(unitId);
const workbook = univerInstanceService.getUnit<Workbook>(unitId);
const worksheet = workbook?.getSheetBySheetId(subUnitId);

if (!worksheet || !workbook) {
Expand Down