diff --git a/libs/api/repository/src/lib/gn4/gn4-repository.ts b/libs/api/repository/src/lib/gn4/gn4-repository.ts index 00e2015e2f..d16e72c14d 100644 --- a/libs/api/repository/src/lib/gn4/gn4-repository.ts +++ b/libs/api/repository/src/lib/gn4/gn4-repository.ts @@ -235,15 +235,12 @@ export class Gn4Repository implements RecordsRepositoryInterface { uniqueIdentifier: string ): Observable<[CatalogRecord, string, false] | null> { return this.loadRecordAsXml(uniqueIdentifier).pipe( - switchMap(async (xml) => { - const converter = findConverterForDocument(xml) - const record = await converter.readRecord(xml) - return [record, converter] as [CatalogRecord, BaseConverter] - }), - switchMap(async ([record, converter]) => { + switchMap(async (recordAsXml) => { + const converter = findConverterForDocument(recordAsXml) + const record = await converter.readRecord(recordAsXml) record.uniqueIdentifier = `TEMP-ID-${Date.now()}` record.title = `${record.title} (Copy)` - const xml = await converter.writeRecord(record) + const xml = await converter.writeRecord(record, recordAsXml) window.localStorage.setItem( this.getLocalStorageKeyForRecord(record.uniqueIdentifier), xml diff --git a/libs/ui/search/src/lib/results-table/action-menu/action-menu.component.css b/libs/ui/search/src/lib/results-table/action-menu/action-menu.component.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/ui/search/src/lib/results-table/action-menu/action-menu.component.html b/libs/ui/search/src/lib/results-table/action-menu/action-menu.component.html new file mode 100644 index 0000000000..f423d03193 --- /dev/null +++ b/libs/ui/search/src/lib/results-table/action-menu/action-menu.component.html @@ -0,0 +1,17 @@ + + more_vert + + + + diff --git a/libs/ui/search/src/lib/results-table/action-menu/action-menu.component.spec.ts b/libs/ui/search/src/lib/results-table/action-menu/action-menu.component.spec.ts new file mode 100644 index 0000000000..0477818afe --- /dev/null +++ b/libs/ui/search/src/lib/results-table/action-menu/action-menu.component.spec.ts @@ -0,0 +1,22 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing' +import { TranslateModule } from '@ngx-translate/core' +import { ActionMenuComponent } from './action-menu.component' + +describe('ActionMenuComponent', () => { + let component: ActionMenuComponent + let fixture: ComponentFixture + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [TranslateModule.forRoot()], + }).compileComponents() + + fixture = TestBed.createComponent(ActionMenuComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) + + it('should create', () => { + expect(component).toBeTruthy() + }) +}) diff --git a/libs/ui/search/src/lib/results-table/action-menu/action-menu.component.ts b/libs/ui/search/src/lib/results-table/action-menu/action-menu.component.ts new file mode 100644 index 0000000000..155692316e --- /dev/null +++ b/libs/ui/search/src/lib/results-table/action-menu/action-menu.component.ts @@ -0,0 +1,22 @@ +import { Component, EventEmitter, Output, ViewChild } from '@angular/core' +import { MatIconModule } from '@angular/material/icon' +import { MatMenuModule, MatMenuTrigger } from '@angular/material/menu' +import { ButtonComponent } from '@geonetwork-ui/ui/inputs' +import { TranslateModule } from '@ngx-translate/core' + +@Component({ + selector: 'gn-ui-action-menu', + templateUrl: './action-menu.component.html', + styleUrls: ['./action-menu.component.css'], + standalone: true, + imports: [MatIconModule, ButtonComponent, MatMenuModule, TranslateModule], +}) +export class ActionMenuComponent { + @Output() duplicate = new EventEmitter() + + @ViewChild(MatMenuTrigger) trigger: MatMenuTrigger + + openMenu() { + this.trigger.openMenu() + } +} diff --git a/libs/ui/search/src/lib/results-table/results-table.component.html b/libs/ui/search/src/lib/results-table/results-table.component.html index 8ca4f64814..c062fd521c 100644 --- a/libs/ui/search/src/lib/results-table/results-table.component.html +++ b/libs/ui/search/src/lib/results-table/results-table.component.html @@ -1,4 +1,7 @@ - + @@ -31,11 +34,7 @@ record.metadata.title -
+
{{ item.title }} - - - - + + diff --git a/libs/ui/search/src/lib/results-table/results-table.component.spec.ts b/libs/ui/search/src/lib/results-table/results-table.component.spec.ts index d484cbd6e7..53b25e12c7 100644 --- a/libs/ui/search/src/lib/results-table/results-table.component.spec.ts +++ b/libs/ui/search/src/lib/results-table/results-table.component.spec.ts @@ -134,7 +134,7 @@ describe('ResultsTableComponent', () => { }) }) - describe('clicking on a title', () => { + describe('clicking on a dataset', () => { let clickedRecord: CatalogRecord beforeEach(() => { @@ -143,10 +143,10 @@ describe('ResultsTableComponent', () => { }) it('emits a recordClick event', () => { - const tableRow = fixture.debugElement.query( - By.css('[data-test="record-title-cell"]') - ).nativeElement as HTMLDivElement - tableRow.click() + const tableRow = fixture.debugElement.queryAll( + By.css('.table-row-cell') + )[1].nativeElement as HTMLDivElement + tableRow.parentElement.click() expect(clickedRecord).toEqual(DATASET_RECORDS[0]) }) }) diff --git a/libs/ui/search/src/lib/results-table/results-table.component.ts b/libs/ui/search/src/lib/results-table/results-table.component.ts index ec3307df0c..3d7dba9f0a 100644 --- a/libs/ui/search/src/lib/results-table/results-table.component.ts +++ b/libs/ui/search/src/lib/results-table/results-table.component.ts @@ -1,7 +1,13 @@ import { CommonModule } from '@angular/common' -import { Component, EventEmitter, Input, Output } from '@angular/core' +import { + Component, + EventEmitter, + Input, + Output, + ViewChild, +} from '@angular/core' import { MatIconModule } from '@angular/material/icon' -import { MatMenuModule } from '@angular/material/menu' +import { MatMenuModule, MatMenuTrigger } from '@angular/material/menu' import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record' import { FieldSort, @@ -19,6 +25,7 @@ import { getFormatPriority, } from '@geonetwork-ui/util/shared' import { TranslateModule } from '@ngx-translate/core' +import { ActionMenuComponent } from './action-menu/action-menu.component' @Component({ selector: 'gn-ui-results-table', @@ -33,7 +40,7 @@ import { TranslateModule } from '@ngx-translate/core' MatIconModule, TranslateModule, BadgeComponent, - MatMenuModule, + ActionMenuComponent, ], }) export class ResultsTableComponent { @@ -92,8 +99,7 @@ export class ResultsTableComponent { this.recordClick.emit(item as CatalogRecord) } - handleDuplicateClick(event: Event, item: unknown) { - event.stopPropagation() + handleDuplicate(item: unknown) { this.duplicateRecord.emit(item as CatalogRecord) }