Skip to content

Commit

Permalink
[editor] Show records in catalog and create routing (#606)
Browse files Browse the repository at this point in the history
* WIP

* WIP

* feat(editor): Clean up unnessecary code, add test file

* feat(editor): Remove duplication of records count display

* feat(editor): Remove unnessecary declaration in app.module

* feat(editor): Fix import path

* feat(editor): Make metadata-editor standalone

* WIP: Make AppComponent standalone

* feat(editor): Fix translation

* feat(editor): Restructure folders for new components

* feat(editor): Add translations, fix some tests

* feat(editor): adjustments to tests to work with standalone components

---------

Co-authored-by: Olivia Guyot <[email protected]>
  • Loading branch information
Angi-Kinas and jahow authored Sep 5, 2023
1 parent a79eb32 commit cce34a5
Show file tree
Hide file tree
Showing 68 changed files with 678 additions and 516 deletions.
2 changes: 2 additions & 0 deletions apps/datahub/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { UiDatavizModule } from '@geonetwork-ui/ui/dataviz'
import { WEB_COMPONENT_EMBEDDER_URL } from '@geonetwork-ui/feature/record'
import { LANGUAGES_LIST, UiCatalogModule } from '@geonetwork-ui/ui/catalog'
import { METADATA_LANGUAGE } from '@geonetwork-ui/api/repository'
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'

export const metaReducers: MetaReducer[] = !environment.production ? [] : []
// https://github.com/nrwl/nx/issues/191
Expand All @@ -89,6 +90,7 @@ export const metaReducers: MetaReducer[] = !environment.production ? [] : []
],
imports: [
BrowserModule,
BrowserAnimationsModule,
RouterModule.forRoot([], {
initialNavigation: 'enabledBlocking',
scrollPositionRestoration: 'enabled',
Expand Down
1 change: 1 addition & 0 deletions apps/metadata-editor/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component } from '@angular/core'

@Component({
selector: 'md-editor-root',
templateUrl: './app.component.html',
Expand Down
52 changes: 21 additions & 31 deletions apps/metadata-editor/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,40 @@
import { NgModule } from '@angular/core'
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'
import { BrowserModule } from '@angular/platform-browser'
import { importProvidersFrom, NgModule } from '@angular/core'
import { RouterModule } from '@angular/router'
import { FeatureEditorModule } from '@geonetwork-ui/feature/editor'
import { FeatureSearchModule } from '@geonetwork-ui/feature/search'
import { UiElementsModule } from '@geonetwork-ui/ui/elements'
import { UiInputsModule } from '@geonetwork-ui/ui/inputs'
import { UiSearchModule } from '@geonetwork-ui/ui/search'
import {
FeatureSearchModule,
SearchFacade,
} from '@geonetwork-ui/feature/search'
import {
TRANSLATE_DEFAULT_CONFIG,
UtilI18nModule,
} from '@geonetwork-ui/util/i18n'
import { TranslateModule } from '@ngx-translate/core'
import { AppCommonModule } from './app.common.module'

import { AppComponent } from './app.component'
import { appRoutes } from './app.routes'
import { CreatePageComponent } from './create/create-page.component'
import { DashboardModule } from './dashboard/dashboard.module'
import { EditPageComponent } from './edit/edit-page.component'
import { SignInPageComponent } from './sign-in/sign-in-page.component'
import { FeatureCatalogModule } from '@geonetwork-ui/feature/catalog'
import { DashboardSearchService } from './dashboard/dashboard-search.service'
import { FeatureAuthModule } from '@geonetwork-ui/feature/auth'
import { BrowserModule } from '@angular/platform-browser'
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'

@NgModule({
declarations: [
AppComponent,
EditPageComponent,
CreatePageComponent,
SignInPageComponent,
],
declarations: [AppComponent],
imports: [
BrowserModule,
DashboardModule,
FeatureSearchModule,
UiElementsModule,
UiSearchModule,
AppCommonModule,
BrowserAnimationsModule,
RouterModule.forRoot(appRoutes, { initialNavigation: 'enabledBlocking' }),
UiInputsModule,
FeatureEditorModule,
UtilI18nModule,
TranslateModule.forRoot(TRANSLATE_DEFAULT_CONFIG),
MatProgressSpinnerModule,
FeatureCatalogModule,
],
providers: [],
providers: [
SearchFacade,
DashboardSearchService,
importProvidersFrom(FeatureAuthModule),
importProvidersFrom(FeatureSearchModule),
importProvidersFrom(FeatureCatalogModule),
importProvidersFrom(UtilI18nModule),
importProvidersFrom(TranslateModule.forRoot(TRANSLATE_DEFAULT_CONFIG)),
importProvidersFrom(AppCommonModule),
],
bootstrap: [AppComponent],
})
export class AppModule {}
49 changes: 48 additions & 1 deletion apps/metadata-editor/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,56 @@ import { SignInPageComponent } from './sign-in/sign-in-page.component'
import { CreatePageComponent } from './create/create-page.component'
import { EditPageComponent } from './edit/edit-page.component'
import { EditRecordResolver } from './edit-record.resolver'
import { AllRecordsComponent } from './records/all-records/all-records-list.component'
import { MyOrgRecordsComponent } from './records/my-org-records/my-org-records.component'
import { MyRecordsComponent } from './records/my-records/my-records.component'
import { MyDraftComponent } from './records/my-draft/my-draft.component'
import { MyLibraryComponent } from './records/my-library/my-library.component'

export const appRoutes: Route[] = [
{ path: '', component: DashboardPageComponent },
{ path: '', component: DashboardPageComponent, pathMatch: 'prefix' },
{
path: 'records',
component: DashboardPageComponent,
outlet: 'primary',
children: [
{
path: '',
redirectTo: 'all',
pathMatch: 'prefix',
},
{
path: 'all',
title: 'All Records',
component: AllRecordsComponent,
pathMatch: 'prefix',
},
{
path: 'my-org',
title: 'My Organisation',
component: MyOrgRecordsComponent,
pathMatch: 'prefix',
},
{
path: 'my-records',
title: 'My Records',
component: MyRecordsComponent,
pathMatch: 'prefix',
},
{
path: 'my-draft',
title: 'My Draft',
component: MyDraftComponent,
pathMatch: 'prefix',
},
{
path: 'my-library',
title: 'My Library',
component: MyLibraryComponent,
pathMatch: 'prefix',
},
],
},
{ path: 'sign-in', component: SignInPageComponent },
{ path: 'create', component: CreatePageComponent },
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('CreatePageComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [CreatePageComponent],
imports: [CreatePageComponent],
}).compileComponents()

fixture = TestBed.createComponent(CreatePageComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import { Component } from '@angular/core'
selector: 'md-editor-create-page',
templateUrl: './create-page.component.html',
styleUrls: ['./create-page.component.css'],
standalone: true,
})
export class CreatePageComponent {}
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
<div class="flex flex-col gap-3">
<button
(click)="setActive('my-org')"
<a
class="menu-item"
role="buton"
[class.btn-active]="isActive$('my-org') | async"
routerLink="/records/my-org"
routerLinkActive
#rlaMyOrg="routerLinkActive"
>
<mat-icon class="material-icons-outlined">home</mat-icon>
<span translate="">editor.dashboard.myOrg</span>
</button>
<button
(click)="setActive('catalog')"
</a>
<a
class="menu-item"
role="buton"
[class.btn-active]="isActive$('catalog') | async"
routerLink="/records/all"
routerLinkActive
#rlaAll="routerLinkActive"
>
<mat-icon class="material-icons-outlined">work_outline</mat-icon>
<span translate="">editor.dashboard.catalog</span>
</button>
</a>
<div class="menu-title" translate="">editor.dashboard.mySpace</div>
<button
(click)="setActive('my-records')"
<a
class="menu-item"
role="buton"
[class.btn-active]="isActive$('my-records') | async"
routerLink="/records/my-records"
routerLinkActive
#rlaMyRecords="routerLinkActive"
>
<mat-icon class="material-icons-outlined">post_add</mat-icon>
<span translate="">editor.dashboard.myRecords</span>
</button>
<button
(click)="setActive('my-draft')"
</a>
<a
class="menu-item"
role="buton"
[class.btn-active]="isActive$('my-draft') | async"
routerLink="/records/my-draft"
routerLinkActive
#rlaMyDraft="routerLinkActive"
>
<mat-icon class="material-icons-outlined">edit_note</mat-icon>
<span translate="">editor.dashboard.myDraft</span>
</button>
<button
(click)="setActive('my-library')"
</a>
<a
class="menu-item"
role="buton"
[class.btn-active]="isActive$('my-library') | async"
routerLink="/records/my-library"
routerLinkActive
#rlaMyLibrary="routerLinkActive"
>
<mat-icon class="material-icons-outlined">bookmark_border</mat-icon>
<span translate="">editor.dashboard.myLibrary</span>
</button>
</a>
</div>
Original file line number Diff line number Diff line change
@@ -1,65 +1,31 @@
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core'
import { NO_ERRORS_SCHEMA } from '@angular/core'
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { By } from '@angular/platform-browser'
import { BehaviorSubject } from 'rxjs'
import { DashboardFacade } from '../+state/dashboard.facade'
import { ActivatedRoute } from '@angular/router'
import { TranslateModule } from '@ngx-translate/core'
import { of } from 'rxjs'
import { DashboardMenuComponent } from './dashboard-menu.component'
import clearAllMocks = jest.clearAllMocks

class DashboardFacadeMock {
setActiveMenu = jest.fn()
activeMenu$ = new BehaviorSubject('')
}

describe('DashboardMenuComponent', () => {
let component: DashboardMenuComponent
let fixture: ComponentFixture<DashboardMenuComponent>
let facade: DashboardFacadeMock

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [DashboardMenuComponent],
providers: [{ provide: DashboardFacade, useClass: DashboardFacadeMock }],
imports: [DashboardMenuComponent, TranslateModule.forRoot()],
providers: [
{
provide: ActivatedRoute,
useValue: { params: of({ id: 1 }) },
},
],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents()

facade = TestBed.inject(DashboardFacade) as unknown as DashboardFacadeMock
fixture = TestBed.createComponent(DashboardMenuComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
afterEach(() => {
clearAllMocks()
})

it('should create', () => {
expect(component).toBeTruthy()
})
describe('on menu click ', () => {
let myOrg: DebugElement
beforeEach(() => {
myOrg = fixture.debugElement.queryAll(By.css('.menu-item'))[0]
myOrg.nativeElement.click()
})
it('sets active menu', () => {
expect(facade.setActiveMenu).toHaveBeenCalledTimes(1)
})
})

describe('when a menu is active ', () => {
let myOrg: DebugElement
let catalog: DebugElement
beforeEach(() => {
facade.activeMenu$.next('my-org')
fixture.detectChanges()
myOrg = fixture.debugElement.queryAll(By.css('.menu-item'))[0]
catalog = fixture.debugElement.queryAll(By.css('.menu-item'))[1]
})
it('add active class', () => {
expect(myOrg.classes['btn-active']).toBeTruthy()
})
it('do not add active class to others menu', () => {
expect(catalog.classes['btn-active']).toBeFalsy()
})
})
})
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import { CommonModule } from '@angular/common'
import { ChangeDetectionStrategy, Component } from '@angular/core'
import { map } from 'rxjs/operators'
import { DashboardFacade } from '../+state/dashboard.facade'
import { DashboardMenuItem } from '../dashboard.model'
import { MatIconModule } from '@angular/material/icon'
import { RouterModule } from '@angular/router'
import { TranslateModule } from '@ngx-translate/core'

@Component({
selector: 'md-editor-dashboard-menu',
templateUrl: './dashboard-menu.component.html',
styleUrls: ['./dashboard-menu.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [CommonModule, RouterModule, MatIconModule, TranslateModule],
})
export class DashboardMenuComponent {
constructor(private facade: DashboardFacade) {}
setActive(activeMenu: DashboardMenuItem) {
this.facade.setActiveMenu(activeMenu)
}
isActive$(menu: DashboardMenuItem) {
return this.facade.activeMenu$.pipe(
map((activeMenu) => activeMenu === menu)
)
}
}
export class DashboardMenuComponent {}
Loading

0 comments on commit cce34a5

Please sign in to comment.