Skip to content

Commit 34d0e93

Browse files
Andrea BarbassoFrancescoMolinaro
authored andcommitted
Merged in task/ux-plus-2023_02_x/UXP-161 (pull request #13)
[UXP-161] add ds-alert for missing google maps api key Approved-by: Francesco Molinaro
2 parents 4ed4f32 + c8a13f9 commit 34d0e93

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
<ds-alert *ngIf="!coordinates" [content]=" 'map.coordinates-invalid' | translate "></ds-alert>
2-
<div *ngIf="coordinates" #gmap class="map-container"></div>
2+
<ds-alert *ngIf="noKeyConfigured" [content]=" 'map.no-key-configured' | translate "></ds-alert>
3+
<div *ngIf="coordinates && !noKeyConfigured" #gmap class="map-container"></div>

src/app/shared/googlemaps/googlemaps.component.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,25 @@ describe('GooglemapsComponent', () => {
4242
expect(component).toBeTruthy();
4343
});
4444

45-
it('should rendered google map.',() => {
45+
it('should render google map.',() => {
4646
const container = fixture.debugElement.query(By.css('.map-container'));
4747
expect(container).toBeTruthy();
4848
});
4949

50-
it('should not rendered google map.',() => {
50+
it('should not render google map if coordinates are not valid.',() => {
5151
fixture = TestBed.createComponent(GooglemapsComponent);
5252
component = fixture.componentInstance;
5353
component.coordinates = '';
5454
const container = fixture.debugElement.query(By.css('.map-container'));
5555
expect(container).toBeFalsy();
5656
});
57+
58+
it('should not render google map if the google maps api key is not present.',() => {
59+
fixture = TestBed.createComponent(GooglemapsComponent);
60+
component = fixture.componentInstance;
61+
component.coordinates = coordinates;
62+
component.noKeyConfigured = true;
63+
const container = fixture.debugElement.query(By.css('.map-container'));
64+
expect(container).toBeFalsy();
65+
});
5766
});

src/app/shared/googlemaps/googlemaps.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DOCUMENT } from '@angular/common';
2-
import { Component, Inject, Input, OnInit, Renderer2, ViewChild, } from '@angular/core';
2+
import { ChangeDetectorRef, Component, Inject, Input, OnInit, Renderer2, ViewChild, } from '@angular/core';
33

44
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
55
import { getFirstCompletedRemoteData } from '../../core/shared/operators';
@@ -38,10 +38,16 @@ export class GooglemapsComponent implements OnInit {
3838
*/
3939
longitude: string;
4040

41+
/**
42+
* A flag that indicates if the google maps api key is not configured
43+
*/
44+
noKeyConfigured = false;
45+
4146
constructor(
4247
@Inject(DOCUMENT) private _document: Document,
4348
private renderer: Renderer2,
4449
private configService: ConfigurationDataService,
50+
private cdr: ChangeDetectorRef,
4551
) {
4652
}
4753

@@ -57,6 +63,9 @@ export class GooglemapsComponent implements OnInit {
5763
this.loadScript(this.buildMapUrl(res?.payload?.values[0])).then(() => {
5864
this.loadMap();
5965
});
66+
} else if (res.hasSucceeded && !res?.payload?.values[0]) {
67+
this.noKeyConfigured = true;
68+
this.cdr.detectChanges();
6069
}
6170
});
6271
}

src/assets/i18n/en.json5

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7556,6 +7556,8 @@
75567556

75577557
"map.coordinates-invalid": "Coordinates are not valid",
75587558

7559+
"map.no-key-configured": "No Google Maps key found in the configuration",
7560+
75597561
"statistics-page.export-map-as-image": "Export map",
75607562

75617563
"curation-task.task.hocr.label": "Extract text (HOCR) from images",

0 commit comments

Comments
 (0)