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

Metadata Editor: rework search results layout, add "create record" button #805

Merged
merged 13 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'
import { NewsPageComponent } from './news-page.component'
import { NO_ERRORS_SCHEMA } from '@angular/core'
import { getGlobalConfig } from '@geonetwork-ui/util/app-config'
import { TranslateTestingModule } from '@geonetwork-ui/util/i18n'
import { TranslateTestingModule } from 'ngx-translate-testing'
import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler'

jest.mock('@geonetwork-ui/util/app-config', () => ({
Expand Down
16 changes: 8 additions & 8 deletions apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ describe('dashboard', () => {
let pageOne
describe('pagination', () => {
it('should display different results on click on arrow', () => {
cy.visit('/records/all')
cy.visit('/records/search')
cy.get('gn-ui-results-table')
.find('.table-row-cell')
.first()
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('dashboard', () => {
let originalFirstItem
let newFirstItem
it('should order the result list on click', () => {
cy.visit('/records/all')
cy.visit('/records/search')
cy.get('gn-ui-results-table')
.find('.table-row-cell')
.eq(1)
Expand Down Expand Up @@ -67,35 +67,35 @@ describe('dashboard', () => {

describe('checkboxes', () => {
it('should show the correct amount of selected records when they are selected', () => {
cy.visit('/records/all')
cy.visit('/records/search')
cy.get('gn-ui-results-table')
.find('.table-row-cell')
.get('gn-ui-checkbox')
.eq(2)
.click()
cy.get('.selected-records').contains('1 selected')
cy.get('[data-test=selected-count]').contains('1 selected')
})

it('should show nothing when none are selected', () => {
cy.visit('/records/all')
cy.visit('/records/search')
cy.get('gn-ui-results-table')
.find('.table-row-cell')
.get('gn-ui-checkbox')
.each(($checkbox) => cy.wrap($checkbox).click())
cy.get('[data-cy=records-information]').should(
'not.have.descendants',
'.selected-records'
'[data-test=selected-count]'
)
})

it('should select all records when the "select all" checkbox is checked', () => {
cy.visit('/records/all')
cy.visit('/records/search')
cy.get('gn-ui-results-table')
.find('.table-row-cell')
.get('gn-ui-checkbox')
.first()
.click()
cy.get('.selected-records').contains('14 selected')
cy.get('[data-test=selected-count]').contains('14 selected')
})
})
})
2 changes: 1 addition & 1 deletion apps/metadata-editor/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class AppModule {
ThemeService.applyCssVariables(
getThemeConfig().PRIMARY_COLOR,
getThemeConfig().SECONDARY_COLOR,
getThemeConfig().MAIN_COLOR || '#555',
getThemeConfig().MAIN_COLOR,
getThemeConfig().BACKGROUND_COLOR,
getThemeConfig().MAIN_FONT || "'Rubik', sans-serif",
getThemeConfig().TITLE_FONT || "'Readex Pro', sans-serif",
Expand Down
12 changes: 2 additions & 10 deletions apps/metadata-editor/src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Route } from '@angular/router'
import { DashboardPageComponent } from './dashboard/dashboard-page.component'
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'
Expand All @@ -21,13 +19,7 @@ export const appRoutes: Route[] = [
children: [
{
path: '',
redirectTo: 'all',
pathMatch: 'prefix',
},
{
path: 'all',
title: 'All Records',
component: AllRecordsComponent,
redirectTo: 'search',
pathMatch: 'prefix',
},
{
Expand Down Expand Up @@ -76,7 +68,7 @@ export const appRoutes: Route[] = [
],
},
{ path: 'sign-in', component: SignInPageComponent },
{ path: 'create', component: CreatePageComponent },
{ path: 'create', component: EditPageComponent },
{
path: 'edit/:uuid',
component: EditPageComponent,
Expand Down

This file was deleted.

21 changes: 0 additions & 21 deletions apps/metadata-editor/src/app/create/create-page.component.spec.ts

This file was deleted.

9 changes: 0 additions & 9 deletions apps/metadata-editor/src/app/create/create-page.component.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<a
class="menu-item"
routerLink="/records/all"
routerLink="/records/search"
routerLinkActive="btn-active"
#rlaAll="routerLinkActive"
>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div data-cy="records-information" class="flex flex-row">
<div
class="text-gray-800"
data-test="records-count"
translate
[translateParams]="{
displayed: (records$ | async).length,
hits: (recordCount$ | async)
}"
>
results.records.hits.displayedOn
</div>
<div
*ngIf="(selectedRecords$ | async).length as selectedRecordCount"
class="ml-2 text-gray-600"
data-test="selected-count"
translate
[translateParams]="{ amount: selectedRecordCount }"
>
results.records.hits.selected
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { DATASET_RECORDS } from '@geonetwork-ui/common/fixtures'
import { RecordsCountComponent } from './records-count.component'
import { By } from '@angular/platform-browser'
import { BehaviorSubject } from 'rxjs'
import { SearchFacade } from '@geonetwork-ui/feature/search'
import { SelectionService } from '@geonetwork-ui/api/repository'
import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler'
import { TranslateTestingModule } from 'ngx-translate-testing'

class SearchFacadeMock {
results$ = new BehaviorSubject(DATASET_RECORDS)
resultsHits$ = new BehaviorSubject(1000)
}
class SelectionServiceMock {
selectedRecordsIdentifiers$ = new BehaviorSubject([])
}

describe('RecordsCountComponent', () => {
let component: RecordsCountComponent
let selectionService: SelectionServiceMock
let fixture: ComponentFixture<RecordsCountComponent>

beforeEach(() => {
const testingModule = TranslateTestingModule.withTranslations({
en: {
'results.records.hits.displayedOn':
'{displayed, plural, =0{No record.} one{1 record} other{{displayed} records}} {hits, plural, other{displayed on {hits} total.}}',
'results.records.hits.selected': '{ amount } selected',
},
})
.withDefaultLanguage('en')
.withCompiler(new TranslateMessageFormatCompiler())
TestBed.configureTestingModule({
providers: [
{
provide: SearchFacade,
useClass: SearchFacadeMock,
},
{
provide: SelectionService,
useClass: SelectionServiceMock,
},
],
}).overrideComponent(RecordsCountComponent, {
add: {
providers: [...testingModule.providers],
},
})

fixture = TestBed.createComponent(RecordsCountComponent)
selectionService = TestBed.inject(SelectionService) as any
component = fixture.componentInstance
fixture.detectChanges()
})

it('should create', () => {
expect(component).toBeTruthy()
})

describe('records count', () => {
it('shows both visible and total counts', () => {
const el = fixture.debugElement.query(
By.css('[data-test=records-count]')
).nativeElement
expect(el.textContent).toContain('2 records displayed on 1000 total.')
})
})

describe('selected count', () => {
describe('if none selected', () => {
it('does not show anything', () => {
const el = fixture.debugElement.query(
By.css('[data-test=selected-count]')
)
expect(el).toBeFalsy()
})
})
describe('if some selected', () => {
beforeEach(() => {
selectionService.selectedRecordsIdentifiers$.next(['1', '2'])
fixture.detectChanges()
})
it('shows the count', () => {
const el = fixture.debugElement.query(
By.css('[data-test=selected-count]')
).nativeElement
expect(el.textContent).toContain('2 selected')
})
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
Component,
EventEmitter,
importProvidersFrom,
Output,
} from '@angular/core'
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'
import { UiInputsModule } from '@geonetwork-ui/ui/inputs'
import {
InteractiveTableColumnComponent,
InteractiveTableComponent,
} from '@geonetwork-ui/ui/layout'
import { MatIconModule } from '@angular/material/icon'
import { TranslateModule } from '@ngx-translate/core'
import { SelectionService } from '@geonetwork-ui/api/repository'
import { CommonModule } from '@angular/common'
import { SearchFacade } from '@geonetwork-ui/feature/search'

@Component({
selector: 'md-editor-records-count',
templateUrl: './records-count.component.html',
styleUrls: ['./records-count.component.css'],
standalone: true,
imports: [
CommonModule,
UiInputsModule,
InteractiveTableComponent,
InteractiveTableColumnComponent,
MatIconModule,
TranslateModule,
],
})
export class RecordsCountComponent {
@Output() recordClick = new EventEmitter<CatalogRecord>()

records$ = this.searchFacade.results$
recordCount$ = this.searchFacade.resultsHits$
selectedRecords$ = this.selectionService.selectedRecordsIdentifiers$

constructor(
private searchFacade: SearchFacade,
private selectionService: SelectionService
) {}
}
Loading
Loading