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] : Share features for tables and maps #921

Merged
merged 9 commits into from
Jul 15, 2024
6 changes: 5 additions & 1 deletion apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'cypress-real-events'
import { tile } from 'ol/loadingstrategy'
import path from 'path'

beforeEach(() => {
Expand Down Expand Up @@ -293,7 +294,7 @@ describe('dataset pages', () => {
})
})

describe('PREVIEW SECTION : display & functions', () => {
describe.only('PREVIEW SECTION : display & functions', () => {
cmoinier marked this conversation as resolved.
Show resolved Hide resolved
beforeEach(() => {
cy.get('datahub-record-metadata')
.find('[id="preview"]')
Expand Down Expand Up @@ -355,6 +356,9 @@ describe('dataset pages', () => {
})
cy.screenshot({ capture: 'fullPage' })
})
it('should display the sharing options', () => {
cy.get('gn-ui-data-view-share').should('be.visible')
})
})
describe('features', () => {
it('MAP : should open a popup on layer click', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
</div>
</div>
<gn-ui-data-view-share
*ngIf="(selectedTabIndex$ | async) === 2"
[tabIndex]="selectedTabIndex$ | async"
></gn-ui-data-view-share>
<div
id="access"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,10 @@ describe('RecordMetadataComponent', () => {
fixture.debugElement.query(By.directive(MockDataViewComponent))
).toBeFalsy()
})
it('does not render the permalink component', () => {
it('does render the permalink component', () => {
expect(
fixture.debugElement.query(By.directive(MockDataViewShareComponent))
).toBeFalsy()
).toBeTruthy()
})
})
describe('when a DATA link present', () => {
Expand All @@ -446,10 +446,10 @@ describe('RecordMetadataComponent', () => {
.length
).toEqual(2)
})
it('does not render the permalink component', () => {
it('does render the permalink component', () => {
expect(
fixture.debugElement.query(By.directive(MockDataViewShareComponent))
).toBeFalsy()
).toBeTruthy()
})
describe('when selectedTabIndex$ is 2 (chart tab)', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
@import '../../../styles.css';
@import 'ol/ol.css';

:host {
display: block;
height: 500px;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Injector,
Input,
OnInit,
ViewEncapsulation,
} from '@angular/core'
import { MdViewFacade } from '@geonetwork-ui/feature/record'
import { SearchFacade } from '@geonetwork-ui/feature/search'
import { BaseComponent } from '../base.component'
import { LinkUsage } from '@geonetwork-ui/util/shared'
import { DatasetDistribution } from '@geonetwork-ui/common/domain/model/record'

@Component({
selector: 'wc-gn-dataset-view-map',
Expand All @@ -18,10 +22,22 @@ import { BaseComponent } from '../base.component'
providers: [SearchFacade],
})
export class GnDatasetViewMapComponent extends BaseComponent implements OnInit {
constructor(injector: Injector, private mdViewFacade: MdViewFacade) {
constructor(
injector: Injector,
private mdViewFacade: MdViewFacade,
private changeDetector: ChangeDetectorRef
) {
super(injector)
}
ngOnInit(): void {
this.mdViewFacade.loadFull('ee965118-2416-4d48-b07e-bbc696f002c2')
@Input() datasetId: string
link: DatasetDistribution
async init() {
super.init()
this.mdViewFacade.loadFull(this.datasetId)
cmoinier marked this conversation as resolved.
Show resolved Hide resolved
this.link = await this.getRecordLink(this.datasetId, [
LinkUsage.MAP_API,
LinkUsage.GEODATA,
])
this.changeDetector.detectChanges()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Web Component Demo</title>
<base href="./" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&amp;family=Inter:wght@200;300;400;500;600;700&amp;display=swap"
rel="stylesheet"
type="text/css"
/>
<style>
html,
body {
font-family: var(--font-family-main);
}
.container {
max-width: 1024px;
margin-left: auto;
margin-right: auto;
margin-top: 3rem;
}
gn-dataset-view-map {
height: 500px;
}
</style>
</head>
<body>
<main class="container">
<div style="margin: 60px 16px">
<p>
Visualize Map dataset from a Metadata Record with
<b><i>gn-dataset-view-map</i></b> web component
</p>
</div>

<script src="gn-wc.js"></script>
<gn-dataset-view-map
api-url="https://www.geo2france.fr/geonetwork/srv/api"
dataset-id="9da51f58-15c6-4325-82b1-2cf6c8e75d0f"
primary-color="#0f4395"
secondary-color="#8bc832"
main-color="#555"
background-color="#fdfbff"
main-font="'Inter', sans-serif"
title-font="'DM Serif Display', serif"
></gn-dataset-view-map>
</main>
</body>
</html>
5 changes: 4 additions & 1 deletion apps/webcomponents/src/app/webcomponents.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
import { provideGn4 } from '@geonetwork-ui/api/repository'
import { GnFigureDatasetsComponent } from './components/gn-figure-datasets/gn-figure-datasets.component'
import { UiDatavizModule } from '@geonetwork-ui/ui/dataviz'
import { GnDatasetViewMapComponent } from './components/gn-dataset-view-map/gn-dataset-view-map.component'

const CUSTOM_ELEMENTS: [new (...args) => BaseComponent, string][] = [
[GnFacetsComponent, 'gn-facets'],
Expand All @@ -46,6 +47,7 @@ const CUSTOM_ELEMENTS: [new (...args) => BaseComponent, string][] = [
[GnDatasetViewChartComponent, 'gn-dataset-view-chart'],
[GnMapViewerComponent, 'gn-map-viewer'],
[GnFigureDatasetsComponent, 'gn-figure-datasets'],
[GnDatasetViewMapComponent, 'gn-dataset-view-map'],
]

@NgModule({
Expand All @@ -61,6 +63,7 @@ const CUSTOM_ELEMENTS: [new (...args) => BaseComponent, string][] = [
GnDatasetViewChartComponent,
GnMapViewerComponent,
GnFigureDatasetsComponent,
GnDatasetViewMapComponent,
],
imports: [
CommonModule,
Expand Down Expand Up @@ -100,7 +103,7 @@ const CUSTOM_ELEMENTS: [new (...args) => BaseComponent, string][] = [
},
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
// bootstrap: [AppComponent],
bootstrap: [AppComponent],
cmoinier marked this conversation as resolved.
Show resolved Hide resolved
})
export class WebcomponentsModule {
constructor(private injector: Injector) {
Expand Down
3 changes: 3 additions & 0 deletions apps/webcomponents/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ <h1 class="text-3xl">GeoNetwork demo</h1>
>Preview dataset as chart</a
>
</li>
<li>
<a href="gn-dataset-view-map.sample.html">Preview dataset as map</a>
</li>
<li class="mt-5">
<a href="gn-map-viewer.sample.html">Map viewer</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
DataViewPermalinkComponent,
WEB_COMPONENT_EMBEDDER_URL,
} from './data-view-permalink.component'
import { BehaviorSubject, firstValueFrom } from 'rxjs'
import { BehaviorSubject, firstValueFrom, lastValueFrom, takeLast } from 'rxjs'

Check warning on line 7 in libs/feature/record/src/lib/data-view-permalink/data-view-permalink.component.spec.ts

View workflow job for this annotation

GitHub Actions / Format check, lint, unit tests

'lastValueFrom' is defined but never used

Check warning on line 7 in libs/feature/record/src/lib/data-view-permalink/data-view-permalink.component.spec.ts

View workflow job for this annotation

GitHub Actions / Format check, lint, unit tests

'takeLast' is defined but never used
import { MdViewFacade } from '../state'
import { Component, Input } from '@angular/core'
import { TranslateModule } from '@ngx-translate/core'
Expand Down Expand Up @@ -75,46 +75,87 @@
facade = TestBed.inject(MdViewFacade)
fixture = TestBed.createComponent(DataViewPermalinkComponent)
component = fixture.componentInstance
component.tabIndex$.next(2)
fixture.detectChanges()
})

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

describe('init permalinkUrl$', () => {
it('should generate URL based on configs', async () => {
const url = await firstValueFrom(component.permalinkUrl$)
expect(url).toBe(
`https://example.com/wc-embedder?v=${gnUiVersion}&e=gn-dataset-view-chart&a=api-url%3D${encodeURIComponent(
component.config.basePath
)}&a=dataset-id%3D${
metadata.uniqueIdentifier
}&a=primary-color%3D%230f4395&a=secondary-color%3D%238bc832&a=main-color%3D%23555&a=background-color%3D%23fdfbff&a=aggregation%3D${
chartConfig1.aggregation
}&a=x-property%3D${chartConfig1.xProperty}&a=y-property%3D${
chartConfig1.yProperty
}&a=chart-type%3D${chartConfig1.chartType}`
)
describe('Chart view', () => {
describe('init permalinkUrl$', () => {
it('should generate URL based on configs', async () => {
const url = await firstValueFrom(component.permalinkUrl$)
expect(url).toBe(
`https://example.com/wc-embedder?v=${gnUiVersion}&e=gn-dataset-view-chart&a=aggregation%3D${
chartConfig1.aggregation
}&a=x-property%3D${chartConfig1.xProperty}&a=y-property%3D${
chartConfig1.yProperty
}&a=chart-type%3D${
chartConfig1.chartType
}&a=api-url%3D${encodeURIComponent(
component.config.basePath
)}&a=dataset-id%3D${
metadata.uniqueIdentifier
}&a=primary-color%3D%230f4395&a=secondary-color%3D%238bc832&a=main-color%3D%23555&a=background-color%3D%23fdfbff`
)
})
})
describe('update permalinkUrl$', () => {
beforeEach(() => {
facade.chartConfig$.next(chartConfig2)
})
it('should update URL based on configs', async () => {
const url = await firstValueFrom(component.permalinkUrl$)
expect(url).toBe(
`https://example.com/wc-embedder?v=${gnUiVersion}&e=gn-dataset-view-chart&a=aggregation%3D${
chartConfig2.aggregation
}&a=x-property%3D${chartConfig2.xProperty}&a=y-property%3D${
chartConfig2.yProperty
}&a=chart-type%3D${
chartConfig2.chartType
}&a=api-url%3D${encodeURIComponent(
component.config.basePath
)}&a=dataset-id%3D${
metadata.uniqueIdentifier
}&a=primary-color%3D%230f4395&a=secondary-color%3D%238bc832&a=main-color%3D%23555&a=background-color%3D%23fdfbff`
)
})
})
})
describe('Map view', () => {
beforeEach(() => {
component.tabIndex$.next(0)
})
describe('init permalinkUrl$', () => {
it('should generate URL based on configs', async () => {
const url = await firstValueFrom(component.permalinkUrl$)
expect(url).toBe(
`https://example.com/wc-embedder?v=${gnUiVersion}&e=gn-dataset-view-map&a=api-url%3D${encodeURIComponent(
component.config.basePath
)}&a=dataset-id%3D${
metadata.uniqueIdentifier
}&a=primary-color%3D%230f4395&a=secondary-color%3D%238bc832&a=main-color%3D%23555&a=background-color%3D%23fdfbff`
)
})
})
})
describe('update permalinkUrl$', () => {
describe('Table view', () => {
beforeEach(() => {
facade.chartConfig$.next(chartConfig2)
component.tabIndex$.next(1)
})
it('should update URL based on configs', async () => {
const url = await firstValueFrom(component.permalinkUrl$)
expect(url).toBe(
`https://example.com/wc-embedder?v=${gnUiVersion}&e=gn-dataset-view-chart&a=api-url%3D${encodeURIComponent(
component.config.basePath
)}&a=dataset-id%3D${
metadata.uniqueIdentifier
}&a=primary-color%3D%230f4395&a=secondary-color%3D%238bc832&a=main-color%3D%23555&a=background-color%3D%23fdfbff&a=aggregation%3D${
chartConfig2.aggregation
}&a=x-property%3D${chartConfig2.xProperty}&a=y-property%3D${
chartConfig2.yProperty
}&a=chart-type%3D${chartConfig2.chartType}`
)
describe('init permalinkUrl$', () => {
it('should generate URL based on configs', async () => {
const url = await firstValueFrom(component.permalinkUrl$)
expect(url).toBe(
`https://example.com/wc-embedder?v=${gnUiVersion}&e=gn-dataset-view-table&a=api-url%3D${encodeURIComponent(
component.config.basePath
)}&a=dataset-id%3D${
metadata.uniqueIdentifier
}&a=primary-color%3D%230f4395&a=secondary-color%3D%238bc832&a=main-color%3D%23555&a=background-color%3D%23fdfbff`
)
})
})
})
})
Loading
Loading