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

Datahub: Fix display of ESRI data on map #652

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 13 additions & 2 deletions libs/feature/dataviz/src/lib/service/data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,22 @@ describe('DataService', () => {
it('builds a proxied url', () => {
expect(
service.getDownloadUrlFromEsriRest(
'http://esri.rest/local/',
'http://esri.rest/local',
'geojson'
)
).toBe(
'http://proxy.local/?url=http%3A%2F%2Fesri.rest%2Flocal%2F%2Fquery%3Ff%3Dgeojson%26where%3D1%3D1%26outFields%3D*'
'http://proxy.local/?url=http%3A%2F%2Fesri.rest%2Flocal%2Fquery%3Ff%3Dgeojson%26where%3D1%3D1%26outFields%3D*'
fgravin marked this conversation as resolved.
Show resolved Hide resolved
)
})
it('calls DataFetcher.openDataset with a proxied url', () => {
service.getDataset({
url: new URL('http://esri.rest/local'),
accessServiceProtocol: 'esriRest',
type: 'service',
})
expect(openDataset).toHaveBeenCalledWith(
'http://proxy.local/?url=http%3A%2F%2Fesri.rest%2Flocal%2Fquery%3Ff%3Dgeojson%26where%3D1%3D1%26outFields%3D*',
'geojson'
)
})
})
Expand Down
11 changes: 7 additions & 4 deletions libs/feature/dataviz/src/lib/service/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,8 @@ export class DataService {
}

getDataset(link: DatasetDistribution): Observable<BaseReader> {
const linkUrl = this.proxy.getProxiedUrl(link.url.toString())
if (link.type === 'service' && link.accessServiceProtocol === 'wfs') {
return this.getDownloadUrlsFromWfs(linkUrl, link.name).pipe(
return this.getDownloadUrlsFromWfs(link.url.toString(), link.name).pipe(
switchMap((urls) => {
if (urls.geojson) return openDataset(urls.geojson, 'geojson')
if (urls.gml)
Expand All @@ -187,17 +186,21 @@ export class DataService {
})
)
} else if (link.type === 'download') {
const linkProxifiedUrl = this.proxy.getProxiedUrl(link.url.toString())
const format = getFileFormat(link)
const supportedType =
SupportedTypes.indexOf(format as any) > -1
? (format as SupportedType)
: undefined
return from(openDataset(linkUrl, supportedType)).pipe()
return from(openDataset(linkProxifiedUrl, supportedType)).pipe()
} else if (
link.type === 'service' &&
link.accessServiceProtocol === 'esriRest'
) {
const url = this.getDownloadUrlFromEsriRest(linkUrl, 'geojson')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the linkUrl was not explicit enough...
Should be linkProxifiedUrl, could have help to know to not use it, as getDownloadUrlFromEsriRest also proxifies the url.

By the way, I also see that in the same function, the call of getDownloadUrlsFromWfs also proxifies the URL twice, so to me, the codeflow within this method is confusing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, true I'll rename it and see if I can improve more, like removing the double proxying for WFS, which does not cause errors right now thanks to ogc-client.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've adapted my previous commit accordingly.

const url = this.getDownloadUrlFromEsriRest(
link.url.toString(),
'geojson'
)
return from(openDataset(url, 'geojson')).pipe()
}
return throwError(() => 'protocol not supported')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
>
record.metadata.about
</p>
<div class="mb-6 md-description sm:mb-4 sm:pr-16">
<div class="mb-6 md-description sm:mb-4 sm:pr-16" *ngIf="metadata.abstract">
<gn-ui-content-ghost ghostClass="h-32" [showContent]="fieldReady('abstract')">
<p
class="whitespace-pre-line break-words"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('MetadataInfoComponent', () => {
component = fixture.componentInstance
component.metadata = {
...DATASET_RECORDS[0],
abstract: null,
useLimitations: null,
accessConstraints: null,
extras: {
Expand All @@ -40,6 +41,11 @@ describe('MetadataInfoComponent', () => {
fixture.nativeElement.querySelector('ng-container')
expect(displayedElement).toBeFalsy()
})
it('should not display the abstract section', () => {
const displayedElement =
fixture.nativeElement.querySelector('.md-description')
expect(displayedElement).toBeFalsy()
})
})

describe('When a section is not empty', () => {
Expand All @@ -53,7 +59,6 @@ describe('MetadataInfoComponent', () => {
const displayedElement = fixture.nativeElement.querySelector('.noUsage')
expect(displayedElement).toBeFalsy()
})

it('should display the keywords section', () => {
// Use waitForAsync to handle asynchronous changes in the DOM.
fixture.whenStable().then(() => {
Expand All @@ -62,5 +67,10 @@ describe('MetadataInfoComponent', () => {
expect(displayedElement).toBeTruthy()
})
})
it('should display the abstract section', () => {
const displayedElement =
fixture.nativeElement.querySelector('.md-description')
expect(displayedElement).toBeTruthy()
})
})
})
Loading