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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
limitations under the License.

-->
<app-nav-bar [currentUser]="currentUser()" [logo]="logo()" [customLinks]="customLinks()" [forceLogin]="forceLogin()" />
<app-nav-bar [currentUser]="currentUser()" [logo]="logo()" [topBarNavigationItems]="topBarNavigationItems()" [forceLogin]="forceLogin()" />
<div class="main-container-wrapper">
<router-outlet />
</div>
Expand Down
46 changes: 23 additions & 23 deletions gravitee-apim-portal-webui-next/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { Injectable } from '@angular/core';
import { signal } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatButtonHarness } from '@angular/material/button/testing';

import { AppComponent } from './app.component';
import { PortalMenuLinksService } from '../services/portal-menu-links.service';
import { PortalNavigationItem } from '../entities/portal-navigation/portal-navigation';
import { PortalNavigationItemsService } from '../services/portal-navigation-items.service';
import { AppTestingModule } from '../testing/app-testing.module';

describe('AppComponent', () => {
Expand All @@ -45,37 +46,36 @@ describe('AppComponent', () => {
});

describe('custom links', () => {
@Injectable()
class PortalMenuLinksServiceStub {
links = () => [
beforeEach(async () => {
const mockItems: PortalNavigationItem[] = [
{
id: 'link-id-1',
type: 'external',
name: 'link-name-1',
target: 'link-target-1',
order: 1,
id: 'l1',
organizationId: 'org1',
environmentId: 'env1',
title: 'link-name-1',
type: 'LINK',
area: 'TOP_NAVBAR',
order: 0,
url: '/link1',
},
{
id: 'link-id-2',
type: 'external',
name: 'link-name-2',
target: 'link-target-2',
order: 2,
id: 'l2',
organizationId: 'org1',
environmentId: 'env1',
title: 'link-name-2',
type: 'LINK',
area: 'TOP_NAVBAR',
order: 1,
url: '/link2',
},
];
}

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AppComponent, AppTestingModule],
providers: [
{
provide: PortalMenuLinksService,
useClass: PortalMenuLinksServiceStub,
},
],
providers: [provideHttpClientTesting(), { provide: PortalNavigationItemsService, useValue: { topNavbar: signal(mockItems) } }],
}).compileComponents();
fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
harnessLoader = TestbedHarnessEnvironment.loader(fixture);
});
it('should show custom links', async () => {
Expand Down
4 changes: 2 additions & 2 deletions gravitee-apim-portal-webui-next/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { FooterComponent } from '../components/footer/footer.component';
import { NavBarComponent } from '../components/nav-bar/nav-bar.component';
import { ConfigService } from '../services/config.service';
import { CurrentUserService } from '../services/current-user.service';
import { PortalMenuLinksService } from '../services/portal-menu-links.service';
import { PortalNavigationItemsService } from '../services/portal-navigation-items.service';
import { ThemeService } from '../services/theme.service';

@Component({
Expand All @@ -35,7 +35,7 @@ export class AppComponent {
currentUser = inject(CurrentUserService).user;
logo = inject(ThemeService).logo;
favicon = inject(ThemeService).favicon;
customLinks = inject(PortalMenuLinksService).links;
topBarNavigationItems = inject(PortalNavigationItemsService).topNavbar;
private siteTitle: string;

constructor(
Expand Down
8 changes: 4 additions & 4 deletions gravitee-apim-portal-webui-next/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ import { httpRequestInterceptor } from '../interceptors/http-request.interceptor
import { AuthService } from '../services/auth.service';
import { ConfigService } from '../services/config.service';
import { CurrentUserService } from '../services/current-user.service';
import { PortalMenuLinksService } from '../services/portal-menu-links.service';
import { PortalNavigationItemsService } from '../services/portal-navigation-items.service';
import { ThemeService } from '../services/theme.service';

function initApp(
authService: AuthService,
configService: ConfigService,
themeService: ThemeService,
currentUserService: CurrentUserService,
portalMenuLinksService: PortalMenuLinksService,
portalNavigationItemsService: PortalNavigationItemsService,
router: Router,
): () => Observable<unknown> {
return () =>
Expand All @@ -47,7 +47,7 @@ function initApp(
combineLatest([
themeService.loadTheme(),
configService.loadConfiguration(),
portalMenuLinksService.loadCustomLinks(),
portalNavigationItemsService.loadTopNavBarItems(),
authService.load().pipe(switchMap(_ => currentUserService.loadUser())),
]),
),
Expand All @@ -70,7 +70,7 @@ export const appConfig: ApplicationConfig = {
inject(ConfigService),
inject(ThemeService),
inject(CurrentUserService),
inject(PortalMenuLinksService),
inject(PortalNavigationItemsService),
inject(Router),
);
return initializerFn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('LogInComponent', () => {
await submitButton.click();
httpTestingController.expectOne(`${TESTING_BASE_URL}/auth/login`).flush({});
httpTestingController.expectOne(`${TESTING_BASE_URL}/user`).flush({});
httpTestingController.expectOne(`${TESTING_BASE_URL}/portal-menu-links`).flush({});
httpTestingController.expectOne(`${TESTING_BASE_URL}/portal-navigation-items?area=TOP_NAVBAR&loadChildren=false`).flush({});
});

it('should not display log-in form', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { AuthService } from '../../services/auth.service';
import { ConfigService } from '../../services/config.service';
import { CurrentUserService } from '../../services/current-user.service';
import { IdentityProviderService } from '../../services/identity-provider.service';
import { PortalMenuLinksService } from '../../services/portal-menu-links.service';
import { PortalNavigationItemsService } from '../../services/portal-navigation-items.service';

@Component({
selector: 'app-log-in',
Expand Down Expand Up @@ -68,7 +68,7 @@ export class LogInComponent {
constructor(
private readonly authService: AuthService,
private readonly currentUserService: CurrentUserService,
private readonly portalMenuLinksService: PortalMenuLinksService,
private readonly portalNavigationItemsService: PortalNavigationItemsService,
private readonly router: Router,
private readonly destroyRef: DestroyRef,
) {}
Expand All @@ -78,7 +78,7 @@ export class LogInComponent {
.login(this.logInForm.value.username, this.logInForm.value.password)
.pipe(
switchMap(_ => this.currentUserService.loadUser()),
switchMap(_ => this.portalMenuLinksService.loadCustomLinks()),
switchMap(_ => this.portalNavigationItemsService.loadTopNavBarItems()),
tap(_ => this.router.navigate([this.redirectUrl()])),
takeUntilDestroyed(this.destroyRef),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('LogOutComponent', () => {
fixture.detectChanges();

httpTestingController.expectOne(`${TESTING_BASE_URL}/auth/logout`).flush({});
httpTestingController.expectOne(`${TESTING_BASE_URL}/portal-menu-links`).flush({});
httpTestingController.expectOne(`${TESTING_BASE_URL}/portal-navigation-items?area=TOP_NAVBAR&loadChildren=false`).flush({});
expect(router.navigate).toHaveBeenCalledTimes(1);
expect(router.navigate).toHaveBeenCalledWith(['']);
expect(currentUserService.user()).toEqual({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { switchMap, tap } from 'rxjs';

import { AuthService } from '../../services/auth.service';
import { CurrentUserService } from '../../services/current-user.service';
import { PortalMenuLinksService } from '../../services/portal-menu-links.service';
import { PortalNavigationItemsService } from '../../services/portal-navigation-items.service';

@Component({
selector: 'app-log-out',
Expand All @@ -33,7 +33,7 @@ export class LogOutComponent implements OnInit {
constructor(
private readonly authService: AuthService,
private readonly currentUserService: CurrentUserService,
private readonly portalMenuLinksService: PortalMenuLinksService,
private readonly portalNavigationItemsService: PortalNavigationItemsService,
private readonly router: Router,
) {}

Expand All @@ -43,7 +43,7 @@ export class LogOutComponent implements OnInit {
.logout()
.pipe(
tap(_ => this.currentUserService.clear()),
switchMap(_ => this.portalMenuLinksService.loadCustomLinks()),
switchMap(_ => this.portalNavigationItemsService.loadTopNavBarItems()),
tap(_ => this.router.navigate([''])),
takeUntilDestroyed(this.destroyRef),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@
<div class="menu-items">
<app-nav-bar-button i18n="@@catalog" [path]="['catalog']">Catalog</app-nav-bar-button>
<app-nav-bar-button i18n="@@guides" [path]="['guides']">Guides</app-nav-bar-button>
@for (link of customLinks(); track link.id) {
<a
[href]="link.target"
mat-stroked-button
color="primary"
class="menu-items__custom_link"
[target]="link.type === 'external' ? '_blank' : ''">
{{ link.name }}
</a>
@for (navigationItem of topBarNavigationItems(); track navigationItem.id) {
@switch (navigationItem.type) {
@case ('LINK') {
<a [href]="navigationItem.url" target="_blank" mat-stroked-button color="primary" class="menu-items__custom_link">
{{ navigationItem.title }}
</a>
}
@default {
<a [routerLink]="['/documentation', navigationItem.id]" mat-stroked-button color="primary" class="menu-items__custom_link">
{{ navigationItem.title }}
</a>
}
}
}
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { MatAnchor, MatButton } from '@angular/material/button';
import { RouterLink } from '@angular/router';
import { isEmpty } from 'lodash';

import { PortalNavigationItem } from '../../../entities/portal-navigation/portal-navigation';
import { User } from '../../../entities/user/user';
import { PortalMenuLink } from '../../../services/portal-menu-links.service';
import { UserAvatarComponent } from '../../user-avatar/user-avatar.component';
import { NavBarButtonComponent } from '../nav-bar-button/nav-bar-button.component';

Expand All @@ -31,7 +31,7 @@ import { NavBarButtonComponent } from '../nav-bar-button/nav-bar-button.componen
})
export class DesktopNavBarComponent {
currentUser: InputSignal<User> = input({});
customLinks: InputSignal<PortalMenuLink[]> = input<PortalMenuLink[]>([]);
topBarNavigationItems: InputSignal<PortalNavigationItem[]> = input<PortalNavigationItem[]>([]);
protected isLoggedIn = computed(() => {
return !isEmpty(this.currentUser());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@
}
<a class="mobile-menu__link" i18n="@@catalog" [routerLink]="['catalog']" routerLinkActive="active" (click)="closeMenu()">Catalog</a>
<a class="mobile-menu__link" i18n="@@guides" [routerLink]="['guides']" routerLinkActive="active" (click)="closeMenu()">Guides</a>
@for (link of customLinks(); track link.id) {
<a class="mobile-menu__link" [href]="link.target" [attr.target]="link.type === 'external' ? '_blank' : null" (click)="closeMenu()">
{{ link.name }}
</a>
@for (navigationItem of topBarNavigationItems(); track navigationItem.id) {
@switch (navigationItem.type) {
@case ('LINK') {
<a class="mobile-menu__link" [href]="navigationItem.url" [attr.target]="'_blank'" (click)="closeMenu()">
{{ navigationItem.title }}
</a>
}
@default {
<a class="mobile-menu__link" [routerLink]="['/documentation', navigationItem.id]" routerLinkActive="active" (click)="closeMenu()">
{{ navigationItem.title }}
</a>
}
}
}
<div class="mobile-menu__hr"></div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { isEmpty } from 'lodash';
import { catchError, map } from 'rxjs';
import { of } from 'rxjs/internal/observable/of';

import { PortalNavigationItem } from '../../../entities/portal-navigation/portal-navigation';
import { User } from '../../../entities/user/user';
import { PortalMenuLink } from '../../../services/portal-menu-links.service';
import { PortalService } from '../../../services/portal.service';

@Component({
Expand All @@ -34,7 +34,7 @@ import { PortalService } from '../../../services/portal.service';
})
export class MobileNavBarComponent {
currentUser: InputSignal<User> = input({});
customLinks: InputSignal<PortalMenuLink[]> = input<PortalMenuLink[]>([]);
topBarNavigationItems: InputSignal<PortalNavigationItem[]> = input<PortalNavigationItem[]>([]);
hasHomepage = toSignal(
inject(PortalService)
.getPortalHomepages()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<app-company-title [logo]="logo()" />
@if (!forceLogin() || isLoggedIn()) {
@if (isMobile()) {
<app-mobile-nav-bar [currentUser]="currentUser()" [customLinks]="customLinks()" />
<app-mobile-nav-bar [currentUser]="currentUser()" [topBarNavigationItems]="topBarNavigationItems()" />
} @else {
<app-desktop-nav-bar [currentUser]="currentUser()" [customLinks]="customLinks()" />
<app-desktop-nav-bar [currentUser]="currentUser()" [topBarNavigationItems]="topBarNavigationItems()" />
}
}
</div>
Loading