Skip to content

Commit

Permalink
fix(navigation): i#3902 projects name include kanban or settings
Browse files Browse the repository at this point in the history
  • Loading branch information
cocotime committed Sep 8, 2023
1 parent 21d4750 commit fc79bb6
Show file tree
Hide file tree
Showing 15 changed files with 242 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export class ProjectEffects {
'project',
project.id,
project.slug,
'overview',
]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ export const ProjectInvitationGuard = (route: ActivatedRouteSnapshot) => {
}),
tap((project) => {
if (project) {
void router.navigate(['/project', project.id, project.slug]);
void router.navigate([
'/project',
project.id,
project.slug,
'overview',
]);
}
return EMPTY;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { Location } from '@angular/common';
import { ChangeDetectionStrategy, Component, ViewChild } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { Router } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { concatLatestFrom } from '@ngrx/effects';
import { Store } from '@ngrx/store';
Expand All @@ -28,15 +28,7 @@ import {
Status,
Workflow,
} from '@taiga/data';
import {
combineLatest,
filter,
map,
merge,
pairwise,
startWith,
take,
} from 'rxjs';
import { combineLatest, filter, map, merge, pairwise, take } from 'rxjs';
import * as ProjectActions from '~/app/modules/project/data-access/+state/actions/project.actions';
import {
selectCurrentProject,
Expand Down Expand Up @@ -120,6 +112,7 @@ export class ProjectFeatureKanbanComponent {
private wsService: WsService,
private permissionService: PermissionsService,
private router: Router,
private route: ActivatedRoute,
private appService: AppService,
private location: Location,
public shortcutsService: ShortcutsService,
Expand Down Expand Up @@ -151,11 +144,7 @@ export class ProjectFeatureKanbanComponent {
);
this.state.connect(
'showStoryDetail',
this.routeHistoryService.urlChanged.pipe(
map((it) => it.url),
startWith(this.router.url),
map((url) => url.includes('/stories/'))
)
this.route.data.pipe(map((data) => !!data.stories))
);

this.state.connect(
Expand Down Expand Up @@ -193,7 +182,12 @@ export class ProjectFeatureKanbanComponent {
concatLatestFrom(() => this.project$.pipe(filterNil()))
)
.subscribe(([, project]) => {
void this.router.navigate(['project', project.id, project.slug]);
void this.router.navigate([
'project',
project.id,
project.slug,
'overview',
]);

this.appService.toastNotification({
message: 'lost_kanban_access',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
(focusout)="out()"
[attr.data-text]="'project'"
[class.active-dialog]="dialog.type === 'project'"
[routerLink]="['/project', project.id, project.slug]">
[routerLink]="['/project', project.id, project.slug, 'overview']">
<tg-ui-avatar
class="project-logo-image"
type="light"
Expand All @@ -39,7 +39,7 @@
<a
class="workspace-data-project"
data-test="project-name"
[routerLink]="['/project', project.id, project.slug]">
[routerLink]="['/project', project.id, project.slug, 'overview']">
{{ project.name }}
</a>
<a
Expand Down Expand Up @@ -80,7 +80,12 @@
[attr.aria-label]="collapsed ? t('commons.overview') : null"
class="menu-option-item"
[class.active-dialog]="dialog.type === 'overview'"
[routerLink]="['/project', project.id, project.slug]"
[routerLink]="[
'/project',
project.id,
project.slug,
'overview'
]"
routerLinkActive
#overviewActive="routerLinkActive"
[routerLinkActiveOptions]="{ exact: true }">
Expand Down Expand Up @@ -224,7 +229,7 @@
[style.height.px]="dialog.mainLinkHeight">
<a
class="workspace-data-project"
[routerLink]="['/project', project.id, project.slug]">
[routerLink]="['/project', project.id, project.slug, 'overview']">
{{ project.name }}
</a>
<a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Copyright (c) 2023-present Kaleidos INC
*/

import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import '@ng-web-apis/universal/mocks';
import { randDomainSuffix, randUuid, randWord } from '@ngneat/falso';
Expand All @@ -33,28 +33,31 @@ describe('ProjectSettingsComponent', () => {
component: ProjectNavigationSettingsComponent,
imports: [getTranslocoModule(), RouterTestingModule],
declareComponent: false,
mocks: [RouteHistoryService],
providers: [
mockProvider(ProjectNavigationComponent, {
animationEvents$,
}),
{
provide: ActivatedRoute,
useValue: {
fragment,
snapshot: {
params: {
id: projectId,
slug: projectName,
},
},
},
},
],
mocks: [RouteHistoryService, Router],
});

beforeEach(() => {
spectator = createComponent({
providers: [
mockProvider(ProjectNavigationComponent, {
animationEvents$,
}),
{
provide: ActivatedRoute,
useValue: {
fragment,
snapshot: {
params: {
id: projectId,
slug: projectName,
},
data: {
settings: true,
},
},
},
},
],
detectChanges: false,
});
spectator.component.project = ProjectMockFactory();
Expand All @@ -71,6 +74,7 @@ describe('ProjectSettingsComponent', () => {
spectator.component.getRouter = jest
.fn()
.mockReturnValue({ url: '/router' });
spectator.component.isSettings = jest.fn().mockReturnValue(false);

const routeHistory =
spectator.inject<RouteHistoryService>(RouteHistoryService);
Expand All @@ -89,6 +93,7 @@ describe('ProjectSettingsComponent', () => {
spectator.component.getRouter = jest
.fn()
.mockReturnValue({ url: '/router' });
spectator.component.isSettings = jest.fn().mockReturnValue(false);

const routeHistory =
spectator.inject<RouteHistoryService>(RouteHistoryService);
Expand All @@ -107,21 +112,22 @@ describe('ProjectSettingsComponent', () => {
spectator.component.getRouter = jest
.fn()
.mockReturnValue({ url: '/router' });
spectator.component.isSettings = jest.fn().mockReturnValue(true);

const routeHistory =
spectator.inject<RouteHistoryService>(RouteHistoryService);
routeHistory.getPreviousUrl.mockReturnValue('');

spectator.component.getRouter = jest
.fn()
.mockReturnValue({ url: '/settings' });
spectator.component.getRouter = jest.fn().mockReturnValue({
url: `/settings`,
});

spectator.detectChanges();

spectator.component.getHistoryNav();

expect(spectator.component.previousUrl).toEqual(
`/project/${projectId}/${projectName}`
`/project/${projectId}/${projectName}/overview`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import {
Output,
ViewChild,
} from '@angular/core';
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
import {
ActivatedRoute,
Router,
RouterModule,
ActivatedRouteSnapshot,
} from '@angular/router';
import { TRANSLOCO_SCOPE } from '@ngneat/transloco';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { TuiSvgModule } from '@taiga-ui/core';
Expand Down Expand Up @@ -90,10 +95,12 @@ export class ProjectNavigationSettingsComponent implements OnInit {
public getHistoryNav() {
this.previousUrl =
this.routeHistory.getPreviousUrl() || this.getRouter().url;
if (this.previousUrl.includes('/settings')) {
if (this.previousUrl.includes('/settings') && this.isSettings()) {
const id: string = this.route.snapshot.params.id;
const slug: string = this.route.snapshot.params.slug;
this.previousUrl = `/project/${id}/${slug}`;
const slug: string =
this.route.snapshot.params.slug ||
(this.route.snapshot.data.project as Project).slug;
this.previousUrl = `/project/${id}/${slug}/overview`;
}
}

Expand All @@ -112,4 +119,14 @@ export class ProjectNavigationSettingsComponent implements OnInit {
public getRouter() {
return this.router;
}

public isSettings() {
const getActiveRoute = (
route: ActivatedRouteSnapshot
): ActivatedRouteSnapshot => {
return route.firstChild ? getActiveRoute(route.firstChild) : route;
};
const active = getActiveRoute(this.route.snapshot);
return !!active.data.settings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { CommonModule } from '@angular/common';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Router } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import {
createComponentFactory,
mockProvider,
Expand All @@ -28,16 +28,26 @@ describe('ProjectNavigationComponent', () => {
imports: [CommonModule, getTranslocoModule()],
schemas: [NO_ERRORS_SCHEMA],
mocks: [LocalStorageService],
providers: [
mockProvider(Router, {
events: events$,
url: '/settings',
}),
],
});

beforeEach(() => {
spectator = createComponent({
providers: [
mockProvider(Router, {
events: events$,
url: '/settings',
}),
{
provide: ActivatedRoute,
useValue: {
snapshot: {
data: {
settings: true,
},
},
},
},
],
detectChanges: false,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
Input,
OnInit,
} from '@angular/core';
import { Router } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { RxState } from '@rx-angular/state';
import { Project } from '@taiga/data';
import { Subject } from 'rxjs';
Expand Down Expand Up @@ -194,32 +194,27 @@ export class ProjectNavigationComponent implements OnInit, AfterViewInit {
constructor(
private el: ElementRef,
private localStorage: LocalStorageService,
private router: Router
private router: Router,
private route: ActivatedRoute
) {}

public ngOnInit() {
this.collapsed = !!LocalStorageService.get('projectnav-collapsed');
this.router.events.subscribe(() => {
!this.router.url.includes('/settings')
? (this.showProjectSettings = false)
: (this.showProjectSettings = true);
this.showProjectSettings = this.isSettings();
});
this.showProjectSettings = this.router.isActive(
this.router.createUrlTree(['project', this.project.id, 'settings']),
{
paths: 'subset',
queryParams: 'ignored',
fragment: 'ignored',
matrixParams: 'ignored',
}
);
this.showProjectSettings = this.isSettings();
}

public ngAfterViewInit() {
const size = this.calcBlockSize();
this.updateBlockSize(size);
}

public isSettings() {
return !!this.route.snapshot.data.settings;
}

public calcBlockSize() {
const el = this.el.nativeElement as HTMLElement;
const header = getComputedStyle(el).getPropertyValue('--header-height');
Expand Down
Loading

0 comments on commit fc79bb6

Please sign in to comment.