Skip to content
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
16 changes: 15 additions & 1 deletion projects/common/src/navigation/navigation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
UrlTree
} from '@angular/router';
import { from, Observable, of } from 'rxjs';
import { filter, map, share, skip, take } from 'rxjs/operators';
import { distinctUntilChanged, filter, map, share, skip, startWith, take } from 'rxjs/operators';
import { throwIfNil } from '../utilities/lang/lang-utils';
import { Dictionary } from '../utilities/types/types';
import { TraceRoute } from './trace-route';
Expand Down Expand Up @@ -185,6 +185,20 @@ export class NavigationService {
return route;
}

public isPathActiveAndChanges(path: string[]): Observable<boolean> {
const urlTree = this.router.createUrlTree(path);

return this.router.events.pipe(
startWith(),
map(() => this.router.isActive(urlTree, false)),
distinctUntilChanged()
);
}

public isPathActive(path: string[]): boolean {
return this.router.isActive(this.router.createUrlTree(path), false);
}

public isRelativePathActive(path: string[], relativeTo: ActivatedRoute = this.getCurrentActivatedRoute()): boolean {
return this.router.isActive(this.router.createUrlTree(path, { relativeTo: relativeTo }), false);
}
Expand Down
9 changes: 8 additions & 1 deletion projects/components/src/link/link.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@
text-decoration-line: none;
text-decoration: none;
color: inherit;
@include link-hover;

&:not(.disabled) {
@include link-hover;
}

.disabled {
pointer-events: none;
}
}
38 changes: 35 additions & 3 deletions projects/components/src/link/link.component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ describe('Link component', () => {
]
});

expect(spectator.query('.ht-link')).toExist();
const anchorElement = spectator.query('.ht-link');
expect(anchorElement).toExist();
expect(anchorElement).not.toHaveClass('disabled');
const routerLinkDirective = spectator.query(RouterLinkWithHref);

expect(routerLinkDirective).toBeDefined();
Expand Down Expand Up @@ -73,7 +75,9 @@ describe('Link component', () => {
]
});

expect(spectator.query('.ht-link')).toExist();
const anchorElement = spectator.query('.ht-link');
expect(anchorElement).toExist();
expect(anchorElement).not.toHaveClass('disabled');
const routerLinkDirective = spectator.query(RouterLinkWithHref);

expect(routerLinkDirective).toBeDefined();
Expand All @@ -96,7 +100,35 @@ describe('Link component', () => {
]
});

expect(spectator.query('.ht-link')).toExist();
const anchorElement = spectator.query('.ht-link');
expect(anchorElement).toExist();
expect(anchorElement).not.toHaveClass('disabled');
const routerLinkDirective = spectator.query(RouterLinkWithHref);

expect(routerLinkDirective).toBeDefined();
expect(routerLinkDirective?.routerLink).toEqual(['/test']);
expect(routerLinkDirective?.skipLocationChange).toBeUndefined();
expect(routerLinkDirective?.queryParams).toBeUndefined();
expect(routerLinkDirective?.queryParamsHandling).toBeUndefined();
expect(routerLinkDirective?.replaceUrl).toBeUndefined();
});

test('should apply disabled style when disabled', () => {
spectator = createHost(`<ht-link [paramsOrUrl]="paramsOrUrl" [disabled]="true"></ht-link>`, {
hostProps: {
paramsOrUrl: '/test'
},
providers: [
mockProvider(NavigationService, {
buildNavigationParams: jest.fn().mockReturnValue({ path: ['/test'], extras: {} })
})
]
});

const anchorElement = spectator.query('.ht-link');
expect(anchorElement).toExist();
expect(anchorElement).toHaveClass('ht-link disabled');

const routerLinkDirective = spectator.query(RouterLinkWithHref);

expect(routerLinkDirective).toBeDefined();
Expand Down
4 changes: 4 additions & 0 deletions projects/components/src/link/link.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { NavigationParams, NavigationPath, NavigationService } from '@hypertrace
<a
*ngIf="this.navigationPath"
class="ht-link"
[ngClass]="{ disabled: this.disabled }"
[routerLink]="this.navigationPath"
[queryParams]="this.navigationOptions?.queryParams"
[queryParamsHandling]="this.navigationOptions?.queryParamsHandling"
Expand All @@ -24,6 +25,9 @@ export class LinkComponent implements OnChanges {
@Input()
public paramsOrUrl?: NavigationParams | string;

@Input()
public disabled?: boolean;

public navigationPath?: NavigationPath;
public navigationOptions?: NavigationExtras;

Expand Down