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: filterRenderController works after selectionRenderService is usable #2236

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading