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

🐞 - Routable dialog bug when it's navigate to another route #6636

Closed
4 of 9 tasks
emiryumak opened this issue Feb 1, 2024 · 2 comments · Fixed by #6885
Closed
4 of 9 tasks

🐞 - Routable dialog bug when it's navigate to another route #6636

emiryumak opened this issue Feb 1, 2024 · 2 comments · Fixed by #6885
Assignees
Labels
bug Something isn't working community contribution This issue was closed by a PR from the community P2 This issue has medium priority S2 This issue has medium severity

Comments

@emiryumak
Copy link

Playground Link

No response

Description

When a router is navigated through the dialog while the dialog is open, the close event immediately runs and routes to its parent. Therefore, an event is run as if the dialog is closed. If the route has changed, there is no need to change the route in close.

Angular version

17.0.7

Taiga UI version

3.63.0

Which browsers have you used?

  • Chrome
  • Firefox
  • Safari
  • Edge

Which operating systems have you used?

  • macOS
  • Windows
  • Linux
  • iOS
  • Android
@emiryumak emiryumak added bug Something isn't working state: need triage labels Feb 1, 2024
@emiryumak
Copy link
Author

I took the code into my own project, edited it this way and fixed the bug. Maybe it will help

constructor(
	@Inject(ActivatedRoute) private readonly route: ActivatedRoute,
	@Inject(Router) private readonly router: Router,
	@Inject(TuiDialogService) dialogs: TuiDialogService,
	@Inject(Injector) injector: Injector,
	@Self() @Inject(TuiDestroyService) destroy$: TuiDestroyService
) {
	dialogs
		.open(
			new PolymorpheusComponent(this.route.snapshot.data['dialog'], injector),
			this.route.snapshot.data['dialogOptions']
		)
		.pipe(takeUntil(destroy$))
		.subscribe({
			complete: () => this.navigateToParent(),
		});
}

ngOnInit(): void {
	this.dialogUrl = this.router.url;
	this.parentUrl = this.getParentUrl();
}

private navigateToParent(): void {
	if (this.dialogUrl !== this.router.url) {
		return;
	}

	void this.router.navigate([this.parentUrl], {
		relativeTo: this.route,
		queryParamsHandling: 'preserve',
	});
}

private getParentUrl(): string {
	const isLazy = this.route.snapshot.data['isLazy'];

	const backUrl = isLazy ? this.getLazyLoadedBackUrl() : this.route.snapshot.data['backUrl'];

	return backUrl;
}

private getLazyLoadedBackUrl(): string {
	const urlSegments: UrlSegment[] = this.route.parent?.snapshot.url || [];

	return urlSegments.map(() => '..').join('/');
}

@waterplea waterplea added P2 This issue has medium priority S2 This issue has medium severity and removed state: need triage labels Feb 26, 2024
@Reactiver
Copy link
Contributor

Thank you for your feedback about this bug! The code example helped to understand the incorrect behavior

Fix will be in this PR — #6885

@waterplea waterplea added the community contribution This issue was closed by a PR from the community label Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working community contribution This issue was closed by a PR from the community P2 This issue has medium priority S2 This issue has medium severity
Development

Successfully merging a pull request may close this issue.

3 participants