Skip to content

Commit

Permalink
feat(metadata-editor): organize fields into pages and sections.
Browse files Browse the repository at this point in the history
  • Loading branch information
Romuald Caplier committed Jul 16, 2024
1 parent 55a2990 commit 6357e36
Show file tree
Hide file tree
Showing 41 changed files with 941 additions and 252 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<div class="w-full flex flex-row p-8 items-center gap-6">
<ng-container
*ngFor="let page of pages; let index = index; let isLast = last"
>
<div class="flex flex-row items-center gap-4">
<div class="flex flex-row items-center gap-4 hover:cursor-pointer">
<gn-ui-button
(buttonClick)="pageSectionClickHandler(index)"
class="flex flex-row items-center"
[type]="selectedPage === index ? 'primary' : 'default'"
extraClass="bg-transparent border-none"
>
<div
class="w-10 h-10 rounded-[8px] pt-3 text-center"
[ngClass]="
selectedPage === index ? 'bg-primary font-bold' : 'bg-gray-200'
"
>
{{ index }}
</div>
<div
class="ms-4"
[ngClass]="
selectedPage === index
? 'text-center text-black font-bold'
: 'text-gray-400'
"
translate
>
{{ page.label }}
</div>
</gn-ui-button>
</div>
<div *ngIf="!isLast" class="w-10">
<hr class="border-t-[2px]" />
</div>
</div>
</ng-container>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { BehaviorSubject } from 'rxjs'
import { TranslateModule } from '@ngx-translate/core'
import { BreadcrumbsComponent } from './breadcrumbs.component'
import { EDITOR_CONFIG } from '@geonetwork-ui/feature/editor'

class EditorFacadeMock {
changedSinceSave$ = new BehaviorSubject(false)
alreadySavedOnce$ = new BehaviorSubject(false)
}

describe('BreadcrumbsComponent', () => {
let component: BreadcrumbsComponent
let fixture: ComponentFixture<BreadcrumbsComponent>
let editorFacade: EditorFacadeMock

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [TranslateModule.forRoot()],
providers: [],
})
// .overrideComponent(TopToolbarComponent, {
// add: {
// imports: [MockPublishButtonComponent],
// },
// remove: {
// imports: [PublishButtonComponent],
// },
// })
.compileComponents()

fixture = TestBed.createComponent(BreadcrumbsComponent)
component = fixture.componentInstance
component.pages = EDITOR_CONFIG().pages
component.selectedPage = 0
fixture.detectChanges()
})

it('should create', () => {
expect(component).toBeTruthy()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
Output,
} from '@angular/core'
import { CommonModule } from '@angular/common'
import { ButtonComponent } from '@geonetwork-ui/ui/inputs'
import { TranslateModule } from '@ngx-translate/core'
import { EditorFieldPage } from '@geonetwork-ui/feature/editor'

@Component({
selector: 'md-editor-breadcrumbs',
standalone: true,
imports: [CommonModule, ButtonComponent, TranslateModule],
templateUrl: './breadcrumbs.component.html',
styleUrls: ['./breadcrumbs.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BreadcrumbsComponent {
@Input() selectedPage = 0
@Input() pages: EditorFieldPage[]

@Output() selectedPageChange = new EventEmitter<number>()

pageSectionClickHandler(index: number) {
this.selectedPageChange.emit(index)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="flex flex-row items-center w-full">
<div class="flex flex-row items-center w-full border-b-[1px]">
<gn-ui-button type="light">
<mat-icon class="material-symbols-outlined">side_navigation</mat-icon>
</gn-ui-button>
Expand Down
45 changes: 36 additions & 9 deletions apps/metadata-editor/src/app/edit/edit-page.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
<div class="flex flex-col h-full">
<div class="w-full h-auto shrink-0">
<md-editor-top-toolbar></md-editor-top-toolbar>
</div>
<div class="grow overflow-auto relative">
<div class="absolute top-0 left-0 w-2/3 z-10 pointer-events-none">
<gn-ui-notifications-container></gn-ui-notifications-container>
<ng-container *ngIf="fields$ | async as fields">
<div class="flex flex-col h-full">
<div class="w-full h-auto shrink-0">
<md-editor-top-toolbar></md-editor-top-toolbar>
<md-editor-breadcrumbs
[pages]="fields.pages"
[selectedPage]="selectedPage"
(selectedPageChange)="selectedPageChange($event)"
></md-editor-breadcrumbs>
</div>
<div class="grow overflow-auto relative">
<div class="absolute top-0 left-0 w-2/3 z-10 pointer-events-none">
<gn-ui-notifications-container></gn-ui-notifications-container>
</div>
<gn-ui-record-form
[page]="fields.pages | find: selectedPage"
></gn-ui-record-form>
</div>
<div class="p-8 mt-auto flex flex-row justify-between">
<gn-ui-button
type="secondary"
(buttonClick)="previousPageButtonHandler()"
translate
>
{{
selectedPage === 0
? ('editor.record.form.bottomButtons.comeBackLater' | translate)
: ('editor.record.form.bottomButtons.previous' | translate)
}}
</gn-ui-button>
<gn-ui-button type="primary" (buttonClick)="nextPageButtonHandler()"
><span translate
>editor.record.form.bottomButtons.next</span
></gn-ui-button
>
</div>
<gn-ui-record-form></gn-ui-record-form>
</div>
</div>
</ng-container>
12 changes: 10 additions & 2 deletions apps/metadata-editor/src/app/edit/edit-page.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { EditPageComponent } from './edit-page.component'
import { ActivatedRoute, Router } from '@angular/router'
import { EditorFacade } from '@geonetwork-ui/feature/editor'
import { EDITOR_CONFIG, EditorFacade } from '@geonetwork-ui/feature/editor'
import { NO_ERRORS_SCHEMA } from '@angular/core'
import { DATASET_RECORDS } from '@geonetwork-ui/common/fixtures'
import { BehaviorSubject, Subject } from 'rxjs'
import { NotificationsService } from '@geonetwork-ui/feature/notifications'
import { TranslateModule } from '@ngx-translate/core'
import { FindPipe } from '../pipes/filter.pipe'
import { BreadcrumbsComponent } from './components/breadcrumbs/breadcrumbs.component'

const getRoute = () => ({
snapshot: {
Expand All @@ -25,6 +27,7 @@ class RouterMock {

class EditorFacadeMock {
record$ = new BehaviorSubject(DATASET_RECORDS[0])
recordFields$ = new BehaviorSubject(EDITOR_CONFIG())
openRecord = jest.fn()
saveError$ = new Subject<string>()
saveSuccess$ = new Subject()
Expand All @@ -42,7 +45,12 @@ describe('EditPageComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [EditPageComponent, TranslateModule.forRoot()],
imports: [
EditPageComponent,
TranslateModule.forRoot(),
FindPipe,
BreadcrumbsComponent,
],
schemas: [NO_ERRORS_SCHEMA],
providers: [
{
Expand Down
41 changes: 39 additions & 2 deletions apps/metadata-editor/src/app/edit/edit-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ import {
NotificationsContainerComponent,
NotificationsService,
} from '@geonetwork-ui/feature/notifications'
import { TranslateService } from '@ngx-translate/core'
import { TranslateModule, TranslateService } from '@ngx-translate/core'
import { filter, Subscription, take } from 'rxjs'
import { FindPipe } from '../pipes/filter.pipe'
import { BreadcrumbsComponent } from './components/breadcrumbs/breadcrumbs.component'
import { marker } from '@biesbjerg/ngx-translate-extract-marker'

marker('editor.record.form.bottomButtons.comeBackLater')
marker('editor.record.form.bottomButtons.previous')
marker('editor.record.form.bottomButtons.next')

@Component({
selector: 'md-editor-edit',
Expand All @@ -29,18 +36,31 @@ import { filter, Subscription, take } from 'rxjs'
PublishButtonComponent,
TopToolbarComponent,
NotificationsContainerComponent,
FindPipe,
BreadcrumbsComponent,
TranslateModule,
],
})
export class EditPageComponent implements OnInit, OnDestroy {
subscription = new Subscription()

fields$ = this.facade.recordFields$
totalPages = 0
selectedPage = 0

constructor(
private route: ActivatedRoute,
private facade: EditorFacade,
private notificationsService: NotificationsService,
private translateService: TranslateService,
private router: Router
) {}
) {
this.subscription.add(
this.fields$.subscribe((fields) => {
this.totalPages = fields.pages.length
})
)
}

ngOnInit(): void {
const [currentRecord, currentRecordSource, currentRecordAlreadySaved] =
Expand Down Expand Up @@ -109,4 +129,21 @@ export class EditPageComponent implements OnInit, OnDestroy {
ngOnDestroy() {
this.subscription.unsubscribe()
}

previousPageButtonHandler() {
if (this.selectedPage === 0) {
this.router.navigate(['catalog', 'search'])
} else {
this.selectedPage--
}
}

nextPageButtonHandler() {
if (this.selectedPage === this.totalPages - 1) return
this.selectedPage++
}

selectedPageChange(index: number) {
this.selectedPage = index
}
}
4 changes: 2 additions & 2 deletions apps/metadata-editor/src/app/pipes/filter.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Pipe, PipeTransform } from '@angular/core'

@Pipe({
name: 'filter',
name: 'find',
standalone: true,
})
export class FilterPipe implements PipeTransform {
export class FindPipe implements PipeTransform {
transform(array: any[], index: number): any {
return array.find((item) => item.index === index)
}
Expand Down
6 changes: 1 addition & 5 deletions apps/metadata-editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"target": "es2020",
"lib": [
"dom",
"es2020",
"dom.iterable"
],
"lib": ["dom", "es2020", "dom.iterable"],
"downlevelIteration": true
},
"angularCompilerOptions": {
Expand Down
1 change: 1 addition & 0 deletions libs/feature/editor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './lib/components/record-form/record-form.component'
export * from './lib/components/wizard/wizard.component'
export * from './lib/components/wizard-field/wizard-field.component'
export * from './lib/components/wizard-summarize/wizard-summarize.component'
export * from './lib/fixtures'
4 changes: 2 additions & 2 deletions libs/feature/editor/src/lib/+state/editor.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Action, createReducer, on } from '@ngrx/store'
import * as EditorActions from './editor.actions'
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'
import { SaveRecordError } from './editor.models'
import { EditorFieldsConfig } from '../models/fields.model'
import { EditorConfig } from '../models'
import { DEFAULT_FIELDS } from '../fields.config'

export const EDITOR_FEATURE_KEY = 'editor'
Expand All @@ -22,7 +22,7 @@ export interface EditorState {
saving: boolean
saveError: SaveRecordError | null
changedSinceSave: boolean
fieldsConfig: EditorFieldsConfig
fieldsConfig: EditorConfig
}

export interface EditorPartialState {
Expand Down
Loading

0 comments on commit 6357e36

Please sign in to comment.