Skip to content

Commit

Permalink
Merge pull request #981 from geonetwork/ME/polish-ui
Browse files Browse the repository at this point in the history
[Editor] : Polish editor form
  • Loading branch information
jahow authored Sep 13, 2024
2 parents dcc96ff + 94713f1 commit 344a92f
Show file tree
Hide file tree
Showing 81 changed files with 697 additions and 438 deletions.
7 changes: 2 additions & 5 deletions apps/datahub-e2e/src/e2e/header.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,10 @@ describe('header', () => {
})
it('should delete text input on click on cancel button', () => {
cy.get('gn-ui-fuzzy-search').type('velo')
cy.get('mat-icon')
cy.get('gn-ui-fuzzy-search [data-test=clear-btn]')
.contains('close')
.trigger('click', { waitForAnimations: false })
cy.get('gn-ui-autocomplete')
.find('div')
.find('input')
.should('have.value', '')
cy.get('gn-ui-autocomplete').find('input').should('have.value', '')
})
describe('when on search url path', () => {
it('should reset search results on click on cancel button', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
></div>
<gn-ui-fuzzy-search
class="text-[18px] pointer-events-auto"
style="
--gn-ui-text-input-padding: 1.1em;
--gn-ui-text-input-border-size: 0px;
"
(itemSelected)="onFuzzySearchSelection($event)"
[autoFocus]="true"
></gn-ui-fuzzy-search>
Expand Down
16 changes: 6 additions & 10 deletions apps/datahub/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ body {
margin: 0;
}

.container-sm {
max-width: 640px;
}
.container-md {
max-width: 768px;
}
.container-lg {
max-width: 1024px;
}

html.record-page-active {
scroll-padding-top: 220px;
}
Expand All @@ -43,3 +33,9 @@ html.record-page-active {
.tippy-box a:hover {
@apply text-primary-lightest;
}

/* this targets the main search field */
gn-ui-autocomplete .gn-ui-text-input {
@apply focus:outline-white focus:outline-2 focus:outline-dotted focus:outline-offset-2
shadow-xl focus:shadow-[0_0_24px_0_rgba(21,40,184,0.09)];
}
59 changes: 44 additions & 15 deletions apps/metadata-editor-e2e/src/e2e/edit.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('editor form', () => {

cy.get('[data-test=displayedRoles]')
.children()
.get('[data-test=removeContactButton]')
.get('[data-cy=remove-item]')
.click()

cy.get('[data-test=displayedRoles]')
Expand Down Expand Up @@ -240,32 +240,56 @@ describe('editor form', () => {

describe('Spatial coverage', () => {
it('toggle between national and regional spatial coverage', () => {
cy.get('gn-ui-switch-toggle').should('exist')
cy.get('gn-ui-form-field-spatial-extent')
.find('gn-ui-switch-toggle')
.should('exist')

cy.get('gn-ui-switch-toggle').find('mat-button-toggle').eq(0).click()
cy.get('mat-button-toggle')
cy.get('gn-ui-form-field-spatial-extent')
.find('gn-ui-switch-toggle')
.find('mat-button-toggle')
.eq(0)
.click()
cy.get('gn-ui-form-field-spatial-extent')
.find('mat-button-toggle')
.eq(0)
.should('have.class', 'mat-button-toggle-checked')
cy.get('mat-button-toggle')
cy.get('gn-ui-form-field-spatial-extent')
.find('mat-button-toggle')
.eq(1)
.should('not.have.class', 'mat-button-toggle-checked')

cy.get('gn-ui-switch-toggle').find('mat-button-toggle').eq(1).click()
cy.get('mat-button-toggle')
cy.get('gn-ui-form-field-spatial-extent')
.find('gn-ui-switch-toggle')
.find('mat-button-toggle')
.eq(1)
.click()
cy.get('gn-ui-form-field-spatial-extent')
.find('mat-button-toggle')
.eq(1)
.should('have.class', 'mat-button-toggle-checked')
cy.get('mat-button-toggle')
cy.get('gn-ui-form-field-spatial-extent')
.find('mat-button-toggle')
.eq(0)
.should('not.have.class', 'mat-button-toggle-checked')
})

it('should display place keywords', () => {
cy.get('gn-ui-autocomplete').should('have.length', 1)
cy.get('gn-ui-autocomplete').type('afr')
cy.get('gn-ui-form-field-spatial-extent')
.find('gn-ui-autocomplete')
.should('have.length', 1)
cy.get('gn-ui-form-field-spatial-extent')
.find('gn-ui-autocomplete')
.type('afr')
cy.get('mat-option').should('have.length', 10)
cy.get('mat-option').eq(0).click()
cy.get('gn-ui-badge').should('have.length', 4)
cy.get('gn-ui-badge').eq(0).find('span').should('have.text', 'Africa ')
cy.get('gn-ui-form-field-spatial-extent')
.find('gn-ui-badge')
.should('have.length', 4)
cy.get('gn-ui-form-field-spatial-extent')
.find('gn-ui-badge')
.eq(0)
.find('span')
.should('have.text', 'Africa ')
})
})
})
Expand Down Expand Up @@ -294,8 +318,11 @@ describe('editor form', () => {
cy.get('gn-ui-form-field-keywords').find('gn-ui-autocomplete').click()
cy.get('mat-option').should('have.length', 10)
cy.get('mat-option').eq(0).click()
cy.get('gn-ui-badge').should('have.length', 20)
cy.get('gn-ui-badge')
cy.get('gn-ui-form-field-keywords')
.find('gn-ui-badge')
.should('have.length', 20)
cy.get('gn-ui-form-field-keywords')
.find('gn-ui-badge')
.eq(19)
.find('span')
.should('have.text', 'Addresses ')
Expand All @@ -321,7 +348,9 @@ describe('editor form', () => {
// add a date range
cy.get('gn-ui-form-field-temporal-extents gn-ui-button').eq(1).click()
// open the date picker
cy.get('gn-ui-form-field-temporal-extents mat-datepicker-toggle').click()
cy.get(
'gn-ui-form-field-temporal-extents [data-cy=date-picker-button] button'
).click()
// select a date
cy.get('mat-calendar').contains('1').click()
// the date picker should still be open
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@
<div
class="w-full flex flex-row p-8 items-center gap-6"
class="w-full flex flex-row items-center gap-[8px]"
data-test="pageSelectorButtons"
>
<ng-container
*ngFor="let page of pages$ | async; 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]="
(facade.currentPage$ | async) === index ? 'primary' : 'default'
"
extraClass="bg-transparent border-none"
>
<div
class="w-10 h-10 rounded-[8px] pt-3 text-center"
[ngClass]="
(facade.currentPage$ | async) === index
? 'bg-primary font-bold'
: 'bg-gray-200'
"
>
{{ index + 1 }}
</div>
<div
class="ms-4"
[ngClass]="
(facade.currentPage$ | async) === index
? 'text-center text-black font-bold'
: 'text-gray-400'
"
translate
>
{{ page.labelKey }}
</div>
</gn-ui-button>
<gn-ui-button
(buttonClick)="pageSectionClickHandler(index)"
class="flex flex-row items-center"
type="light"
extraClass="bg-transparent border-none"
style="--gn-ui-button-padding: 0 16px 0 0"
*ngrxLet="isCurrentPage(index) as isCurrentPage"
>
<div
class="w-[40px] h-[40px] rounded-[8px] grid items-center font-bold transition-colors"
data-test="page-number"
[ngClass]="isCurrentPage ? 'bg-primary text-white' : 'bg-gray-200'"
>
{{ index + 1 }}
</div>
<div *ngIf="!isLast" class="w-10">
<hr class="border-t-[2px]" />
<div
class="ms-[16px] transition-colors"
[ngClass]="isCurrentPage ? 'text-black font-bold' : 'text-gray-600'"
translate
>
{{ page.labelKey }}
</div>
</div>
</gn-ui-button>
<div
*ngIf="!isLast"
class="w-10 mr-[8px] border-t-[2px] border-gray-500"
></div>
</ng-container>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ describe('PageSelectorComponent', () => {
})

it('should render the correct number of pages', () => {
const pages = fixture.debugElement.queryAll(By.css('.w-10.h-10'))
const pages = fixture.debugElement.queryAll(
By.css('[data-test=page-number]')
)
expect(pages.length).toBe(editorConfigFixture().pages.length)
})

it('should highlight the current page', () => {
const currentPageIndex = facade.currentPage$.getValue()
const currentPageElement = fixture.debugElement.queryAll(
By.css('.w-10.h-10')
By.css('[data-test=page-number]')
)[currentPageIndex]
expect(currentPageElement.nativeElement.classList).toContain('bg-primary')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { ButtonComponent } from '@geonetwork-ui/ui/inputs'
import { TranslateModule } from '@ngx-translate/core'
import { EditorFacade } from '@geonetwork-ui/feature/editor'
import { map } from 'rxjs/operators'
import { LetDirective } from '@ngrx/component'

@Component({
selector: 'md-editor-page-selector',
standalone: true,
imports: [CommonModule, ButtonComponent, TranslateModule],
imports: [CommonModule, ButtonComponent, TranslateModule, LetDirective],
templateUrl: './page-selector.component.html',
styleUrls: ['./page-selector.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
Expand All @@ -21,4 +22,10 @@ export class PageSelectorComponent {
pageSectionClickHandler(index: number) {
this.facade.setCurrentPage(index)
}

isCurrentPage(index: number) {
return this.facade.currentPage$.pipe(
map((currentPage) => currentPage === index)
)
}
}
1 change: 1 addition & 0 deletions apps/metadata-editor/src/app/edit/edit-page.component.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
:host {
--gn-ui-text-input-rounded: 8px;
--gn-ui-text-input-padding: 14px;
--gn-ui-text-input-font-size: 14px;
}

.card {
Expand Down
69 changes: 39 additions & 30 deletions apps/metadata-editor/src/app/edit/edit-page.component.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
<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-page-selector></md-editor-page-selector>
</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 class="flex flex-row h-full">
<aside class="w-[370px] shrink-0 border-r">
<md-editor-sidebar></md-editor-sidebar>
</aside>
<div class="flex flex-col h-full w-full">
<div class="w-full h-auto shrink-0 relative">
<md-editor-top-toolbar></md-editor-top-toolbar>
<div class="absolute top-full left-0 w-2/3 z-10 pointer-events-none">
<gn-ui-notifications-container></gn-ui-notifications-container>
</div>
</div>
<div class="grow overflow-auto p-[32px]" #scrollContainer>
<div class="container-lg mx-auto flex flex-col gap-[32px]">
<md-editor-page-selector></md-editor-page-selector>
<gn-ui-record-form></gn-ui-record-form>
<div
data-test="previousNextPageButtons"
class="mt-auto flex flex-row justify-between"
>
<gn-ui-button
type="gray"
(buttonClick)="previousPageButtonHandler()"
translate
>
{{
(currentPage$ | async) === 0
? ('editor.record.form.bottomButtons.comeBackLater' | translate)
: ('editor.record.form.bottomButtons.previous' | translate)
}}
</gn-ui-button>
<gn-ui-button
type="primary"
(buttonClick)="nextPageButtonHandler()"
[disabled]="isLastPage$ | async"
>
<span translate>editor.record.form.bottomButtons.next</span>
</gn-ui-button>
</div>
</div>
</div>
<gn-ui-record-form></gn-ui-record-form>
</div>
<div
data-test="previousNextPageButtons"
class="p-8 mt-auto flex flex-row justify-between"
>
<gn-ui-button
type="secondary"
(buttonClick)="previousPageButtonHandler()"
translate
>
{{
(currentPage$ | async) === 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>
</div>
21 changes: 20 additions & 1 deletion apps/metadata-editor/src/app/edit/edit-page.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
datasetRecordsFixture,
editorConfigFixture,
} from '@geonetwork-ui/common/fixtures'
import { BehaviorSubject, Subject } from 'rxjs'
import { BehaviorSubject, firstValueFrom, Subject } from 'rxjs'
import { NotificationsService } from '@geonetwork-ui/feature/notifications'
import { EditorFacade } from '@geonetwork-ui/feature/editor'
import { MockBuilder } from 'ng-mocks'
Expand Down Expand Up @@ -36,6 +36,8 @@ class EditorFacadeMock {
saveSuccess$ = new Subject()
draftSaveSuccess$ = new Subject()
editorConfig$ = new BehaviorSubject(editorConfigFixture())
currentPage$ = new BehaviorSubject(0)
pagesCount$ = new BehaviorSubject(2)
}
class NotificationsServiceMock {
showNotification = jest.fn()
Expand Down Expand Up @@ -172,4 +174,21 @@ describe('EditPageComponent', () => {
expect(navigateSpy).toHaveBeenCalledWith(['edit', 'new-uuid'])
})
})

describe('isLastPage$', () => {
let editorFacade: EditorFacadeMock
beforeEach(() => {
editorFacade = TestBed.inject(EditorFacade) as unknown as EditorFacadeMock
})
it('returns true if last page', async () => {
editorFacade.currentPage$.next(3)
editorFacade.pagesCount$.next(4)
expect(await firstValueFrom(component.isLastPage$)).toBe(true)
})
it('returns false if not', async () => {
editorFacade.currentPage$.next(1)
editorFacade.pagesCount$.next(3)
expect(await firstValueFrom(component.isLastPage$)).toBe(false)
})
})
})
Loading

0 comments on commit 344a92f

Please sign in to comment.