From 7a2367a4f41280068dac11734dad46b73ca0eeb5 Mon Sep 17 00:00:00 2001 From: Angi-Kinas <133115263+Angi-Kinas@users.noreply.github.com> Date: Tue, 19 Sep 2023 10:58:51 +0200 Subject: [PATCH] feat(datahub): Sort formats in filter dropdown by format priority (#621) * feat(datahub):Sort formats in filter dropdown by format priority * feat(datahub): Undo previous changes, sort data-view dropdown formats by priority * feat(datahub): Remove unused imports --- .../src/lib/data-view/data-view.component.spec.ts | 13 +++++++++++-- .../record/src/lib/data-view/data-view.component.ts | 10 ++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/libs/feature/record/src/lib/data-view/data-view.component.spec.ts b/libs/feature/record/src/lib/data-view/data-view.component.spec.ts index 6672e3f67e..170845356a 100644 --- a/libs/feature/record/src/lib/data-view/data-view.component.spec.ts +++ b/libs/feature/record/src/lib/data-view/data-view.component.spec.ts @@ -12,8 +12,10 @@ import { DataViewComponent } from './data-view.component' import { TranslateModule } from '@ngx-translate/core' import { DatavizConfigurationModel } from '@geonetwork-ui/common/domain/dataviz-configuration.model' import { DatasetDistribution } from '@geonetwork-ui/common/domain/record' +import { LINK_FIXTURES } from '@geonetwork-ui/common/fixtures' const DATALINKS_FIXTURE: DatasetDistribution[] = [ + LINK_FIXTURES.dataXls, { description: 'CSV file', name: 'some_file_name.csv', @@ -21,6 +23,7 @@ const DATALINKS_FIXTURE: DatasetDistribution[] = [ type: 'download', }, ] + const GEODATALINKS_FIXTURE: DatasetDistribution[] = [ { description: 'Geojson file', @@ -134,6 +137,10 @@ describe('DataViewComponent', () => { expect(dropdownComponent.choices).toEqual([ { label: 'CSV file (csv)', + value: JSON.stringify(DATALINKS_FIXTURE[1]), + }, + { + label: 'Data in XLS format (excel)', value: JSON.stringify(DATALINKS_FIXTURE[0]), }, { @@ -147,7 +154,7 @@ describe('DataViewComponent', () => { ]) }) it('displays link in the table', () => { - expect(tableViewComponent.link).toEqual(DATALINKS_FIXTURE[0]) + expect(tableViewComponent.link).toEqual(DATALINKS_FIXTURE[1]) }) }) @@ -160,7 +167,9 @@ describe('DataViewComponent', () => { fixture.detectChanges() })) it('displays link in the table', () => { - expect(tableViewComponent.link).toEqual(GEODATALINKS_FIXTURE[1]) + expect(tableViewComponent.link.description).toEqual( + GEODATALINKS_FIXTURE[1].description + ) }) }) }) diff --git a/libs/feature/record/src/lib/data-view/data-view.component.ts b/libs/feature/record/src/lib/data-view/data-view.component.ts index c2c5429feb..95fb586b56 100644 --- a/libs/feature/record/src/lib/data-view/data-view.component.ts +++ b/libs/feature/record/src/lib/data-view/data-view.component.ts @@ -4,7 +4,7 @@ import { Input, Output, } from '@angular/core' -import { getLinkLabel } from '@geonetwork-ui/util/shared' +import { getLinkLabel, getLinkPriority } from '@geonetwork-ui/util/shared' import { BehaviorSubject, combineLatest } from 'rxjs' import { map, tap } from 'rxjs/operators' import { MdViewFacade } from '../state' @@ -23,7 +23,13 @@ export class DataViewComponent { compatibleDataLinks$ = combineLatest([ this.mdViewFacade.dataLinks$, this.mdViewFacade.geoDataLinks$, - ]).pipe(map(([dataLinks, geoDataLinks]) => [...dataLinks, ...geoDataLinks])) + ]).pipe( + map(([dataLinks, geoDataLinks]) => { + const a = [...dataLinks, ...geoDataLinks] + a.sort((a, b) => getLinkPriority(b) - getLinkPriority(a)) + return a + }) + ) dropdownChoices$ = this.compatibleDataLinks$.pipe( tap((links) => { if (links.indexOf(this.selectedLink$.value) === -1) {