Skip to content

Commit

Permalink
fix: filterRenderController works after selectionRenderService is usa…
Browse files Browse the repository at this point in the history
…ble (#2236)

* fix(sheet): filterRenderControoler work after selectionRenderService usable

* fix: throw usable immediately

* test(sheet): add test
  • Loading branch information
siam-ese committed May 14, 2024
1 parent 3d0c56e commit 3693e7a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ export class SheetsFilterRenderController extends RxDisposable implements IRende

private _initRenderer(): void {
// Subscribe to skeleton change and filter model change.
this._sheetSkeletonManagerService.currentSkeleton$
combineLatest([
this._selectionRenderService.usable$,
this._sheetSkeletonManagerService.currentSkeleton$,
])
.pipe(
switchMap((skeletonParams) => {
filter(([usable]) => usable),
switchMap(([_, skeletonParams]) => {
if (!skeletonParams) return of(null);

const { unitId } = skeletonParams;
Expand All @@ -91,13 +95,9 @@ export class SheetsFilterRenderController extends RxDisposable implements IRende
skeleton: skeletonParams.skeleton,
});

return combineLatest([
this._selectionRenderService.usable$,
fromCallback(this._commandService.onCommandExecuted),
]).pipe(
filter(([usable, [command]]) =>
usable
&& command.type === CommandType.MUTATION
return fromCallback(this._commandService.onCommandExecuted).pipe(
filter(([command]) =>
command.type === CommandType.MUTATION
&& (command.params as ISheetCommandSharedParams).unitId === workbook.getUnitId()
&& FILTER_MUTATIONS.has(command.id)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ describe('Test indirect', () => {

let selectionEndParam: ISelectionWithCoordAndStyle[];

let selectionServiceUsable: boolean;

beforeEach(() => {
const testBed = createCommandTestBed(undefined, [
[IShortcutService, { useClass: DesktopShortcutService }],
Expand Down Expand Up @@ -226,6 +228,10 @@ describe('Test indirect', () => {
selectionEndParam = param;
});

selectionRenderService.usable$.subscribe((param) => {
selectionServiceUsable = param;
});

selectionRenderService.eventTrigger(mockEvent);

scene.triggerPointerMove({ ...mockEvent, offsetX: 200 });
Expand All @@ -235,6 +241,8 @@ describe('Test indirect', () => {

describe('normal', () => {
it('Observer is valid', () => {
expect(selectionServiceUsable).toBeTruthy();

expect(selectionStartParam == null).toBeFalsy();

expect(selectionMovingParam == null).toBeFalsy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class SelectionRenderService implements ISelectionRenderService {
* This service relies on the scene and skeleton to work
* Use usable$ to check if this service works
*/
private readonly _usable$ = new Subject<boolean>();
private readonly _usable$ = new BehaviorSubject<boolean>(false);

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

Expand Down

0 comments on commit 3693e7a

Please sign in to comment.