Skip to content

Commit

Permalink
fix(sheet): filterRenderController work after selectionRenderControll… (
Browse files Browse the repository at this point in the history
#2229)

* fix(sheet): filterRenderController work after selectionRenderController readied

* chore(sheet): check usable
  • Loading branch information
siam-ese committed May 14, 2024
1 parent 9929eff commit 8f8e80d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { getCoordByCell, ISelectionRenderService, SelectionShape, SheetRenderCon
import type { IDisposable } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';

import { filter, map, of, startWith, switchMap, takeUntil, throttleTime } from 'rxjs';
import { combineLatest, filter, map, of, startWith, switchMap, takeUntil, throttleTime } from 'rxjs';
import type { ISheetsFilterButtonShapeProps } from '../views/widgets/filter-button.shape';
import { FILTER_ICON_PADDING, FILTER_ICON_SIZE, SheetsFilterButtonShape } from '../views/widgets/filter-button.shape';

Expand Down Expand Up @@ -91,17 +91,20 @@ export class SheetsFilterRenderController extends RxDisposable implements IRende
skeleton: skeletonParams.skeleton,
});

return fromCallback(this._commandService.onCommandExecuted)
.pipe(
filter(([command]) =>
command.type === CommandType.MUTATION
&& (command.params as ISheetCommandSharedParams).unitId === workbook.getUnitId()
&& FILTER_MUTATIONS.has(command.id)
),
throttleTime(20, undefined, { leading: false, trailing: true }),
map(getParams),
startWith(getParams()) // must trigger once
);
return combineLatest([
this._selectionRenderService.usable$,
fromCallback(this._commandService.onCommandExecuted),
]).pipe(
filter(([usable, [command]]) =>
usable
&& command.type === CommandType.MUTATION
&& (command.params as ISheetCommandSharedParams).unitId === workbook.getUnitId()
&& FILTER_MUTATIONS.has(command.id)
),
throttleTime(20, undefined, { leading: false, trailing: true }),
map(getParams),
startWith(getParams()) // must trigger once
);
}),
takeUntil(this.dispose$)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface ISelectionRenderService {
readonly controlFillConfig$: Observable<IControlFillConfig | null>;
readonly selectionMoving$: Observable<ISelectionWithCoordAndStyle[]>;
readonly selectionMoveStart$: Observable<ISelectionWithCoordAndStyle[]>;
readonly usable$: Observable<boolean>;

enableHeaderHighlight(): void;
disableHeaderHighlight(): void;
Expand Down Expand Up @@ -194,6 +195,14 @@ export class SelectionRenderService implements ISelectionRenderService {

private _activeViewport: Nullable<Viewport>;

/**
* This service relies on the scene and skeleton to work
* Use usable$ to check if this service works
*/
private readonly _usable$ = new Subject<boolean>();

readonly usable$ = this._usable$.asObservable();

constructor(
@Inject(ThemeService) private readonly _themeService: ThemeService,
@IShortcutService private readonly _shortcutService: IShortcutService,
Expand Down Expand Up @@ -352,6 +361,7 @@ export class SelectionRenderService implements ISelectionRenderService {
this._skeleton = skeleton;
this._scene = scene;
this._activeViewport = viewport || scene?.getViewports()[0];
this._usable$.next(Boolean(skeleton && scene));
}

getSelectionDataWithStyle(): ISelectionWithCoordAndStyle[] {
Expand Down

0 comments on commit 8f8e80d

Please sign in to comment.