Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dataset page] Main block #11

Merged
merged 23 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
385bbd1
chore(font): add font weights and title font
tkohr Feb 2, 2024
f75563b
feat(button-primary): add a button component
tkohr Feb 2, 2024
1987316
feat(dataset-header): add dataset-header component with corresponding…
tkohr Feb 2, 2024
21dd91c
feat(styles): define container class
tkohr Feb 2, 2024
cf058bb
feat(dataset-downloads): add component for downloads
tkohr Feb 5, 2024
28bd6e7
feat(dataset-header): only display buttons if section present
tkohr Feb 5, 2024
3dcd058
feat(dataset-header): add content ghost for description
tkohr Feb 5, 2024
99ef398
feat(dataset): add max-lines component and use it for abstract
tkohr Feb 5, 2024
0fe7bc8
feat(dataset-header): add favorite-heart component to edit favorites
tkohr Feb 5, 2024
9a40bc7
feat(results-list): subscribe to favorite changes to update search state
tkohr Feb 6, 2024
041163b
refactor(assets): move icon to dedicated folder
tkohr Feb 6, 2024
78b57bd
feat(e2e): add utility commands from gn-ui
tkohr Feb 7, 2024
f48914a
feat(e2e): add e2e tests fro dataset page
tkohr Feb 7, 2024
3651a3c
refactor(favorites): add heart-toggle ui component and extend favorit…
tkohr Feb 7, 2024
c96001c
refactor(text-expand): extend gn-ui max-lines.component instead of co…
tkohr Feb 7, 2024
6d77fb0
feat(dataset-header): use gn-ui-markdown-parser for abstract
tkohr Feb 7, 2024
a0d9b33
test(e2e): fix and restructure tests
tkohr Feb 7, 2024
9e7ef94
chore(package.json): update gn-ui
tkohr Feb 7, 2024
329013b
review(button): address review comments
tkohr Feb 8, 2024
2cf3fde
fix(results-list): fix subscription after rebase
tkohr Feb 8, 2024
f47db9b
fix(results-card-favorite): fix missing cursor-pointer and refactor c…
tkohr Feb 8, 2024
85102fb
test(e2e): simplify scroll tests
tkohr Feb 8, 2024
55848bd
feat(favorite-heart): style links in tippy tooltips
tkohr Feb 8, 2024
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
93 changes: 93 additions & 0 deletions apps/datahub-e2e/src/e2e/dataset.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
describe('datasets', () => {
describe('when not logged in', () => {
beforeEach(() => cy.visit('/dataset/8698bf0b-fceb-4f0f-989b-111e7c4af0a4'))

it('should display the favorite button disabled', () => {
cy.get('mel-datahub-button-primary')
.eq(0)
.find('button')
.as('favoriteButton')
cy.get('@favoriteButton').should('be.disabled')
cy.get('@favoriteButton').should('have.class', 'bg-primary-light')
})

it('should scroll down when clicking on download button', () => {
cy.get('mel-datahub-button-primary').eq(1).as('downloadButton')
cy.get('@downloadButton').click()
cy.get('@downloadButton').should(() => {
const scrollPosition = Cypress.dom.getWindowByElement(
cy.state('window')
).scrollY
expect(scrollPosition).to.be.greaterThan(0)
})
})

it('should scroll down when clicking on api button', () => {
cy.get('mel-datahub-button-primary').eq(2).as('apiButton')
cy.get('@apiButton').click()
cy.get('@apiButton').should(() => {
const scrollPosition = Cypress.dom.getWindowByElement(
cy.state('window')
).scrollY
expect(scrollPosition).to.be.greaterThan(0)
})
})

it('should display the title', () => {
cy.get('.mel-page-title').should('be.visible')
cy.get('.mel-page-title').should('have.text', ' Alpenkonvention ')
})

it('should display the abstract in collapsed mode applying gradient', () => {
cy.get('mel-datahub-text-expand').should('be.visible')
cy.get('mel-datahub-text-expand')
.find('mel-datahub-button-primary')
.should('have.text', ' En savoir plus ')
cy.get('mel-datahub-text-expand')
.find('mel-datahub-button-primary')
.find('img')
.should('have.attr', 'src', '/assets/icons/arrow.svg')
cy.get('mel-datahub-text-expand')
.find('.bg-gradient-to-b')
.should('have.css', 'max-height', '72px')
})

it('should display the abstract in expanded mode without gradient', () => {
cy.get('mel-datahub-text-expand').should('be.visible')
cy.get('mel-datahub-text-expand')
.find('mel-datahub-button-primary')
.click()
cy.get('mel-datahub-text-expand')
.find('mel-datahub-button-primary')
.should('have.text', ' Reduire ')
cy.get('mel-datahub-text-expand')
.find('mel-datahub-button-primary')
.find('img')
.should('have.attr', 'src', '/assets/icons/arrow-up.svg')
cy.get('mel-datahub-text-expand')
.find('.bg-gradient-to-b')
.should('not.exist')
cy.get('mel-datahub-text-expand')
.find('.ease-in')
.should('have.css', 'max-height')
.and('satisfy', (maxHeight) => parseInt(maxHeight, 10) > 110)
})
})
describe('when logged in', () => {
beforeEach(() => {
cy.login()
cy.clearFavorites()
cy.visit('/dataset/8698bf0b-fceb-4f0f-989b-111e7c4af0a4')
})
it('should toggle the favorite button', () => {
cy.get('mel-datahub-button-primary').eq(0).as('favoriteButton')
cy.get('@favoriteButton')
.find('img')
.should('have.attr', 'src', '/assets/icons/heart.svg')
cy.get('@favoriteButton').click()
cy.get('@favoriteButton')
.find('img')
.should('have.attr', 'src', '/assets/icons/heart-filled.svg')
})
})
})
87 changes: 71 additions & 16 deletions apps/datahub-e2e/src/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,77 @@
declare namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
login(email: string, password: string): void;
login(username?: string, password?: string, redirect?: boolean)
signOut(): void
clearFavorites()
}
}

// -- This is a parent command --
Cypress.Commands.add('login', (email, password) => {
console.log('Custom command example: Login', email, password);
});
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
Cypress.Commands.add(
'login',
(username = 'admin', password = 'admin', redirect = false) => {
// first request to get the XSRF cookie
cy.request({
method: 'GET',
url: '/geonetwork/srv/api/me',
headers: {
Accept: 'application/json',
},
})
cy.getCookie('XSRF-TOKEN').then((xsrfTokenCookie) => {
cy.request({
method: 'POST',
url: '/geonetwork/signin',
body: `username=${username}&password=${password}&_csrf=${xsrfTokenCookie.value}`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
followRedirect: false,
})
})
if (redirect) return cy.visit('/')
else return cy.window()
}
)

Cypress.Commands.add('signOut', () => {
cy.visit('/geonetwork/srv/eng/catalog.search#/home')
cy.get('a[title="User details"]').click()
cy.get('a[title="Sign out"]').click()
})

/**
* This will most likely fail if the user is not logged in!
*/
Cypress.Commands.add('clearFavorites', () => {
cy.request({
url: '/geonetwork/srv/api/me',
headers: { accept: 'application/json' },
})
.its('body')
.its('id')
.as('myId')

cy.window().then(function () {
cy.request({
url: `/geonetwork/srv/api/userselections/0/${this.myId}`,
headers: { accept: 'application/json' },
})
.its('body')
.as('favoritesId')
})

return cy
.getCookie('XSRF-TOKEN')
.its('value')
.then(function (token) {
const favoritesId = this.favoritesId || []
cy.request({
url: `/geonetwork/srv/api/userselections/0/${
this.myId
}?uuid=${favoritesId.join('&uuid=')}`,
method: 'DELETE',
headers: { accept: 'application/json', 'X-XSRF-TOKEN': token },
})
})
})
tkohr marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 12 additions & 0 deletions apps/datahub/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ import { ResultsCardSearchComponent } from './common/results-list-item/results-c
import { MatTabsModule } from '@angular/material/tabs'
import { DatasetApisComponent } from './dataset/dataset-apis/dataset-apis.component'
import { MelDatahubMetadataQualityComponent } from './common/metadata-quality/mel-datahub-metadata-quality.component'
import { DatasetHeaderComponent } from './dataset/dataset-header/dataset-header.component'
import { ButtonPrimaryComponent } from './common/button-primary/button-primary.component'
import { DatasetDownloadsComponent } from './dataset/dataset-downloads/dataset-downloads.component'
import { FavoriteHeartComponent } from './common/favorites/favorite-heart/favorite-heart.component'
import { HeartToggleComponent } from './common/favorites/heart-toggle/heart-toggle.component'
import { TextExpandComponent } from './common/text-expand/text-expand.component'

@NgModule({
declarations: [
Expand All @@ -66,6 +72,12 @@ import { MelDatahubMetadataQualityComponent } from './common/metadata-quality/me
DatasetPageComponent,
DatasetApisComponent,
MelDatahubMetadataQualityComponent,
DatasetHeaderComponent,
ButtonPrimaryComponent,
DatasetDownloadsComponent,
FavoriteHeartComponent,
HeartToggleComponent,
TextExpandComponent,
],
imports: [
BrowserModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<button
class="h-11 flex justify-center items-center gap-2 text-white text-[15px] font-extrabold leading-[18px] py-2 px-[18px] rounded border hover:bg-primary-dark"
[class]="disabled ? 'bg-primary-light' : 'bg-primary'"
tkohr marked this conversation as resolved.
Show resolved Hide resolved
[disabled]="disabled"
>
{{ label }}
@if(src){
<img [src]="src" [alt]="placeholder" />
}
</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core'

@Component({
selector: 'mel-datahub-button-primary',
templateUrl: './button-primary.component.html',
styles: ``,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ButtonPrimaryComponent {
@Input() label: string
@Input() set icon(fileName: string) {
tkohr marked this conversation as resolved.
Show resolved Hide resolved
if (fileName) {
this.src = `/assets/icons/${fileName}.svg`
this.placeholder = fileName
}
}
@Input() disabled = false
src?: string
placeholder?: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<mel-datahub-heart-toggle
[toggled]="isFavorite$ | async"
(newValue)="toggleFavorite($event)"
[disabled]="loading || (isAnonymous$ | async)"
></mel-datahub-heart-toggle>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {
ChangeDetectionStrategy,
Component,
ElementRef,
ViewChild,
} from '@angular/core'
import { FavoriteStarComponent } from 'geonetwork-ui'
import { HeartToggleComponent } from '../heart-toggle/heart-toggle.component'

@Component({
selector: 'mel-datahub-favorite-heart',
templateUrl: './favorite-heart.component.html',
styles: ``,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FavoriteHeartComponent extends FavoriteStarComponent {
@ViewChild(HeartToggleComponent, { read: ElementRef })
override starToggleRef: ElementRef
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<mel-datahub-button-primary
[label]="'mel.dataset.favorite' | translate"
[icon]="toggled ? 'heart-filled' : 'heart'"
[disabled]="disabled"
(click)="toggle($event)"
></mel-datahub-button-primary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
Output,
} from '@angular/core'
import { propagateToDocumentOnly } from 'geonetwork-ui'

@Component({
selector: 'mel-datahub-heart-toggle',
templateUrl: './heart-toggle.component.html',
styles: ``,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class HeartToggleComponent {
@Input() toggled!: boolean
tkohr marked this conversation as resolved.
Show resolved Hide resolved
@Input() disabled = false
@Output() newValue = new EventEmitter<boolean>()

toggle(event: Event) {
if (!this.disabled) {
this.toggled = !this.toggled
this.newValue.emit(this.toggled)
}
propagateToDocumentOnly(event)
tkohr marked this conversation as resolved.
Show resolved Hide resolved
event.preventDefault()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[tabIndex]="0"
(click)="mdSelect.emit(record)"
(keyup.enter)="mdSelect.emit(record)"
class="bg-gray-8 group flex flex-col gap-[9px] justify-between h-[110px] py-3 px-4 w-[330px] rounded-lg border border-gray-6 filter hover:drop-shadow-lg z-0"
class="mel-card group gap-[9px] h-[110px] py-3 px-4 z-0"
><div class="flex justify-between">
<h1 class="font-bold text-[17px] line-clamp-1">
{{ record.title }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[tabIndex]="0"
(click)="mdSelect.emit(record)"
(keyup.enter)="mdSelect.emit(record)"
class="bg-gray-8 group flex flex-col justify-between relative h-40 p-4 w-[330px] rounded border border-gray-6 filter overflow-hidden cursor-pointer hover:drop-shadow-lg"
class="mel-card group relative h-40 p-4 overflow-hidden"
>
<h1 class="font-bold text-[17px] line-clamp-2">
{{ record.title }}
Expand Down
16 changes: 14 additions & 2 deletions apps/datahub/src/app/common/results-list/results-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
import { Component, Input, OnInit } from '@angular/core'
import { Component, Input, OnDestroy, OnInit } from '@angular/core'
import { Store } from '@ngrx/store'
import {
FIELDS_BRIEF,
FavoritesService,
RouterFacade,
SearchFacade,
SearchService,
SearchState,
} from 'geonetwork-ui'
import { CatalogRecord } from 'geonetwork-ui/libs/common/domain/src/lib/model/record'
import { Subscription } from 'rxjs'

@Component({
selector: 'mel-datahub-results-list',
template: '',
})
export class ResultsListComponent implements OnInit {
export class ResultsListComponent implements OnInit, OnDestroy {
@Input() set favoritesOnly(value: boolean) {
this.favoritesOnlyValue = value
this.searchFacade.setFavoritesOnly(value)
}
favoritesOnlyValue: boolean
@Input() numberOfResults = 10
myFavoritesSubscription: Subscription

constructor(
protected searchService: SearchService,
protected searchFacade: SearchFacade,
protected routerFacade: RouterFacade,
protected favoritesService: FavoritesService,
protected store: Store<SearchState>
) {}

Expand All @@ -33,6 +37,14 @@ export class ResultsListComponent implements OnInit {
.setConfigRequestFields([...FIELDS_BRIEF, 'createDate', 'changeDate'])
.setPageSize(this.numberOfResults)
.setSortBy(['desc', 'createDate'])
this.myFavoritesSubscription =
this.favoritesService.myFavoritesUuid$.subscribe(() => {
if (this.favoritesOnlyValue) this.searchFacade.setFavoritesOnly(true)
})
}

ngOnDestroy() {
this.myFavoritesSubscription.unsubscribe()
}

onInfoKeywordClick(keyword: string) {
Expand Down
19 changes: 19 additions & 0 deletions apps/datahub/src/app/common/text-expand/text-expand.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div
#container
class="overflow-hidden transition-[max-height] duration-300 mb-8"
[ngClass]="
isExpanded || !showToggleButton
? 'ease-in'
: 'ease-out bg-gradient-to-b from-black to-beige text-transparent bg-clip-text'
"
[style.maxHeight]="maxHeight"
>
<ng-content></ng-content>
</div>
@if(showToggleButton){
<mel-datahub-button-primary
[label]="(isExpanded ? 'mel.dataset.less' : 'mel.dataset.more') | translate"
[icon]="isExpanded ? 'arrow-up' : 'arrow'"
(click)="toggleDisplay()"
></mel-datahub-button-primary>
}
Loading
Loading