-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[editor] Show records in catalog and create routing (#606)
* 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
1 parent
a79eb32
commit cce34a5
Showing
68 changed files
with
678 additions
and
516 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 25 additions & 25 deletions
50
apps/metadata-editor/src/app/dashboard/dashboard-menu/dashboard-menu.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
56 changes: 11 additions & 45 deletions
56
apps/metadata-editor/src/app/dashboard/dashboard-menu/dashboard-menu.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) | ||
}) |
21 changes: 7 additions & 14 deletions
21
apps/metadata-editor/src/app/dashboard/dashboard-menu/dashboard-menu.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
Oops, something went wrong.