-
Notifications
You must be signed in to change notification settings - Fork 2
Add coordinate modal UX #1161
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
Merged
Merged
Add coordinate modal UX #1161
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/app/file-browser/components/coordinate-picker/coordinate-picker.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <pr-dialog-frame | ||
| heading="Choose GPS Coordinates" | ||
| [confirmDisabled]="!isValid()" | ||
| (cancelled)="cancel()" | ||
| (confirmed)="save()" | ||
| > | ||
| <pr-coordinate-map-input | ||
| [(coordinates)]="coordinates" | ||
| (validityChange)="onValidityChange($event)" | ||
| /> | ||
| </pr-dialog-frame> |
5 changes: 5 additions & 0 deletions
5
src/app/file-browser/components/coordinate-picker/coordinate-picker.component.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| :host { | ||
| display: block; | ||
| width: 640px; | ||
| max-width: 100%; | ||
| } |
143 changes: 143 additions & 0 deletions
143
src/app/file-browser/components/coordinate-picker/coordinate-picker.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
| import { DIALOG_DATA, DialogRef } from '@angular/cdk/dialog'; | ||
| import { GoogleMapsModule } from '@angular/google-maps'; | ||
| import { CoordinateMapInputComponent } from '@shared/components/coordinate-map-input/coordinate-map-input.component'; | ||
| import { | ||
| CoordinatePickerComponent, | ||
| CoordinatePickerData, | ||
| } from './coordinate-picker.component'; | ||
|
|
||
| const LISBON = { latitude: 38.70786, longitude: -9.400139 }; | ||
|
|
||
| describe('CoordinatePickerComponent', () => { | ||
| let fixture: ComponentFixture<CoordinatePickerComponent>; | ||
| let component: CoordinatePickerComponent; | ||
| let dialogRef: jasmine.SpyObj<DialogRef>; | ||
|
|
||
| const setUp = async (dialogData: CoordinatePickerData): Promise<void> => { | ||
| dialogRef = jasmine.createSpyObj('DialogRef', ['close']); | ||
|
|
||
| await TestBed.configureTestingModule({ | ||
| imports: [CoordinatePickerComponent], | ||
| providers: [ | ||
| { provide: DIALOG_DATA, useValue: dialogData }, | ||
| { provide: DialogRef, useValue: dialogRef }, | ||
| ], | ||
| }) | ||
| .overrideComponent(CoordinateMapInputComponent, { | ||
| remove: { imports: [GoogleMapsModule] }, | ||
| add: { schemas: [CUSTOM_ELEMENTS_SCHEMA] }, | ||
| }) | ||
| .compileComponents(); | ||
|
|
||
| fixture = TestBed.createComponent(CoordinatePickerComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| }; | ||
|
|
||
| const query = <T extends HTMLElement>(selector: string): T => | ||
| fixture.nativeElement.querySelector(selector); | ||
|
|
||
| describe('with nothing to start from', () => { | ||
| beforeEach(async () => { | ||
| await setUp({}); | ||
| }); | ||
|
|
||
| it('should render a titled dialog', () => { | ||
| expect(query('.pr-dialog-header h2').textContent.trim()).toBe( | ||
| 'Choose GPS Coordinates', | ||
| ); | ||
| }); | ||
|
|
||
| it('should hand the map input nothing to start from', () => { | ||
| expect(component.coordinates()).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when the location already has coordinates', () => { | ||
| beforeEach(async () => { | ||
| await setUp({ location: { ...LISBON, city: 'Lisbon' } }); | ||
| }); | ||
|
|
||
| it('should hand the stored pair to the map input', () => { | ||
| expect(component.coordinates()).toEqual(LISBON); | ||
| }); | ||
|
|
||
| it('should keep the address it was given when saving', () => { | ||
| component.save(); | ||
|
|
||
| expect(dialogRef.close).toHaveBeenCalledWith({ | ||
| location: { ...LISBON, city: 'Lisbon' }, | ||
| }); | ||
| }); | ||
|
|
||
| it('should clear the stored pair when the map input reports none', () => { | ||
| component.coordinates.set(null); | ||
| component.save(); | ||
|
|
||
| expect(dialogRef.close).toHaveBeenCalledWith({ | ||
| location: { latitude: null, longitude: null, city: 'Lisbon' }, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when the location has an address but no coordinates', () => { | ||
| beforeEach(async () => { | ||
| await setUp({ location: { city: 'Lisbon' } }); | ||
| }); | ||
|
|
||
| it('should still carry the address through a save', () => { | ||
| component.save(); | ||
|
|
||
| expect(dialogRef.close).toHaveBeenCalledWith({ | ||
| location: { city: 'Lisbon', latitude: null, longitude: null }, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when the map input reports unreadable text', () => { | ||
| beforeEach(async () => { | ||
| await setUp({ location: { ...LISBON } }); | ||
| }); | ||
|
|
||
| it('should disable the confirm button', () => { | ||
| component.onValidityChange(false); | ||
| fixture.detectChanges(); | ||
|
|
||
| expect(query<HTMLButtonElement>('.pr-btn-confirm').disabled).toBeTrue(); | ||
| }); | ||
|
|
||
| it('should refuse to save the pair the field is no longer showing', () => { | ||
| component.onValidityChange(false); | ||
| component.save(); | ||
|
|
||
| expect(dialogRef.close).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('leaving the dialog', () => { | ||
| beforeEach(async () => { | ||
| await setUp({}); | ||
| }); | ||
|
|
||
| it('should close with nothing when cancelled', () => { | ||
| query<HTMLButtonElement>('.pr-btn-cancel').click(); | ||
|
|
||
| expect(dialogRef.close).toHaveBeenCalledWith(); | ||
| }); | ||
|
|
||
| it('should close with nothing when dismissed from the header', () => { | ||
| query<HTMLButtonElement>('.pr-close-button').click(); | ||
|
|
||
| expect(dialogRef.close).toHaveBeenCalledWith(); | ||
| }); | ||
|
|
||
| it('should close with the pair when saved', () => { | ||
| component.coordinates.set(LISBON); | ||
| query<HTMLButtonElement>('.pr-btn-confirm').click(); | ||
|
|
||
| expect(dialogRef.close).toHaveBeenCalledWith({ location: LISBON }); | ||
| }); | ||
| }); | ||
| }); |
69 changes: 69 additions & 0 deletions
69
src/app/file-browser/components/coordinate-picker/coordinate-picker.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { Component, Inject, OnInit, Optional, signal } from '@angular/core'; | ||
| import { DIALOG_DATA, DialogRef } from '@angular/cdk/dialog'; | ||
| import { LocnVOData } from '@models'; | ||
| import { CoordinateMapInputComponent } from '@shared/components/coordinate-map-input/coordinate-map-input.component'; | ||
| import { DialogFrameComponent } from '@shared/components/dialog-frame/dialog-frame.component'; | ||
| import { | ||
| Coordinates, | ||
| coordinatesFromLocation, | ||
| } from '@shared/utilities/coordinates'; | ||
|
|
||
| export interface CoordinatePickerData { | ||
| location?: LocnVOData; | ||
| } | ||
|
|
||
| export interface CoordinatePickerResult { | ||
| location: LocnVOData; | ||
| } | ||
|
|
||
| @Component({ | ||
| selector: 'pr-coordinate-picker', | ||
| standalone: true, | ||
| imports: [CoordinateMapInputComponent, DialogFrameComponent], | ||
| templateUrl: './coordinate-picker.component.html', | ||
| styleUrls: ['./coordinate-picker.component.scss'], | ||
| }) | ||
| export class CoordinatePickerComponent implements OnInit { | ||
| coordinates = signal<Coordinates | null>(null); | ||
| isValid = signal(true); | ||
|
|
||
| private locationBeingEdited: LocnVOData = {}; | ||
|
|
||
| constructor( | ||
| @Optional() | ||
| @Inject(DIALOG_DATA) | ||
| public dialogData?: CoordinatePickerData, | ||
| @Optional() private dialogRef?: DialogRef<CoordinatePickerResult>, | ||
| ) {} | ||
|
|
||
| ngOnInit(): void { | ||
| const existing = this.dialogData?.location; | ||
| if (!existing) { | ||
| return; | ||
| } | ||
| this.locationBeingEdited = { ...existing }; | ||
| this.coordinates.set(coordinatesFromLocation(existing)); | ||
| } | ||
|
|
||
| public onValidityChange(isValid: boolean): void { | ||
| this.isValid.set(isValid); | ||
| } | ||
|
|
||
| public cancel(): void { | ||
| this.dialogRef?.close(); | ||
| } | ||
|
|
||
| public save(): void { | ||
| if (!this.isValid()) { | ||
| return; | ||
| } | ||
| const coordinates = this.coordinates(); | ||
| this.dialogRef?.close({ | ||
| location: { | ||
| ...this.locationBeingEdited, | ||
| latitude: coordinates?.latitude ?? null, | ||
| longitude: coordinates?.longitude ?? null, | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/app/shared/components/coordinate-map-input/coordinate-map-input.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <google-map | ||
| [height]="height()" | ||
| width="100%" | ||
| [options]="mapOptions" | ||
| (mapClick)="onMapClick($event)" | ||
| > | ||
| @if (markerPosition(); as position) { | ||
| <map-marker [position]="position" [options]="markerOptions" /> | ||
| } | ||
| </google-map> | ||
|
|
||
| <div class="pr-coordinate-field"> | ||
| <pr-icon-text-input | ||
|
aasandei-vsp marked this conversation as resolved.
|
||
| [icon]="coordinateIcon" | ||
| [label]="label()" | ||
| [value]="coordinateText()" | ||
| [invalid]="!isValid()" | ||
| (valueChange)="onCoordinateTextChange($event)" | ||
| /> | ||
| </div> | ||
15 changes: 15 additions & 0 deletions
15
src/app/shared/components/coordinate-map-input/coordinate-map-input.component.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| @import 'colors'; | ||
|
|
||
| :host { | ||
| display: block; | ||
| position: relative; | ||
| } | ||
|
|
||
| .pr-coordinate-field { | ||
| position: absolute; | ||
| top: 16px; | ||
| left: 16px; | ||
| right: 16px; | ||
| border-radius: 6px; | ||
| box-shadow: 0 2px 8px rgba($PR-brand-black, 0.16); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.