Skip to content

Commit

Permalink
feat(datahub): Sort formats in filter dropdown by format priority (#621)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Angi-Kinas authored Sep 19, 2023
1 parent f9f9064 commit 7a2367a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
13 changes: 11 additions & 2 deletions libs/feature/record/src/lib/data-view/data-view.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ 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',
url: new URL('https://test.org/some_file_name.csv'),
type: 'download',
},
]

const GEODATALINKS_FIXTURE: DatasetDistribution[] = [
{
description: 'Geojson file',
Expand Down Expand Up @@ -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]),
},
{
Expand All @@ -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])
})
})

Expand All @@ -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
)
})
})
})
Expand Down
10 changes: 8 additions & 2 deletions libs/feature/record/src/lib/data-view/data-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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) {
Expand Down

0 comments on commit 7a2367a

Please sign in to comment.