This repository has been archived by the owner on Jul 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(upload): prompt to rename project on conflict (fixes #99)
- Loading branch information
1 parent
3d21e36
commit 20376b9
Showing
15 changed files
with
217 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
28 changes: 28 additions & 0 deletions
28
src/app/editor/uploader/uploader-rename/uploader-rename.component.html
This file contains 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,28 @@ | ||
<h1 mat-dialog-title>Rename Bundle</h1> | ||
<div mat-dialog-content> | ||
<p>Darn, someone already took that bundle name! Try picking a different name or, if this bundle is yours, <a (click)="switchAccounts()" class="body-link">switch accounts</a>.</p> | ||
|
||
<form (ngSubmit)="submit()" [formGroup]="form"> | ||
<mat-form-field style="display:block"> | ||
<input matInput #message maxlength="60" placeholder="Project Name*" formControlName="projectName"> | ||
<mat-hint align="start">Should be globally unique.</mat-hint> | ||
<mat-error *ngIf="getInput('projectName').hasError('length')"> | ||
Your project name should be between 2 and 60 characters. | ||
</mat-error> | ||
<mat-error *ngIf="getInput('projectName').hasError('projectName')"> | ||
Your project name can only contain alphanumeric characters with dashes. | ||
</mat-error> | ||
<mat-error *ngIf="getInput('projectName').hasError('projectNameTaken')"> | ||
Shucks! That project name has already been taken. | ||
</mat-error> | ||
<mat-error *ngIf="getInput('projectName').hasError('required')"> | ||
The project name is required. | ||
</mat-error> | ||
</mat-form-field> | ||
</form> | ||
</div> | ||
<div mat-dialog-actions> | ||
<button mat-button (click)="dialogRef.close()">Cancel</button> | ||
<span class="flex-fill"></span> | ||
<button mat-button (click)="submit()" cdkFocusInitial>Rename</button> | ||
</div> |
4 changes: 4 additions & 0 deletions
4
src/app/editor/uploader/uploader-rename/uploader-rename.component.scss
This file contains 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,4 @@ | ||
:host { | ||
width: 500px; | ||
display: block; | ||
} |
75 changes: 75 additions & 0 deletions
75
src/app/editor/uploader/uploader-rename/uploader-rename.component.ts
This file contains 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,75 @@ | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { AsyncValidatorFn, FormBuilder, FormGroup, Validators } from '@angular/forms'; | ||
import { MatDialogRef } from '@angular/material'; | ||
import { Store } from '@ngrx/store'; | ||
import { timer } from 'rxjs/observable/timer'; | ||
import { map, switchMap, take } from 'rxjs/operators'; | ||
|
||
import * as forAccount from '../../account/account.actions'; | ||
import { CommonMethods } from '../../bedrock.actions'; | ||
import * as fromRoot from '../../bedrock.reducers'; | ||
import { ElectronService } from '../../electron.service'; | ||
import * as forProject from '../../project/project.actions'; | ||
import * as fromProject from '../../project/project.reducer'; | ||
import { projectNameValidator } from '../../shared/validators'; | ||
import { OpenUploader, StartUploading } from '../uploader.actions'; | ||
|
||
/** | ||
* Presents a brief into to uploading and allows users to select what | ||
* things they want to upload. | ||
*/ | ||
@Component({ | ||
selector: 'uploader-rename', | ||
templateUrl: './uploader-rename.component.html', | ||
styleUrls: ['./uploader-rename.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class UploaderRenameComponent { | ||
/** | ||
* Form for input validation. | ||
*/ | ||
public form: FormGroup; | ||
|
||
constructor( | ||
public readonly dialogRef: MatDialogRef<any>, | ||
private readonly store: Store<fromRoot.IState>, | ||
private readonly formBuilder: FormBuilder, | ||
private readonly electron: ElectronService, | ||
) { | ||
this.store | ||
.select(fromProject.projectState) | ||
.pipe(map(p => p.project && p.project.packageJson.name), take(1)) | ||
.subscribe(previousName => { | ||
this.form = this.formBuilder.group({ | ||
projectName: [ | ||
previousName || '', | ||
[Validators.required, projectNameValidator], | ||
this.checkProjectNameAvailable, | ||
], | ||
}); | ||
}); | ||
} | ||
|
||
public getInput(name: string) { | ||
return this.form.get(name)!; | ||
} | ||
|
||
public submit() { | ||
this.store.dispatch(new forProject.RenameProject(this.form.value.projectName)); | ||
this.store.dispatch(new StartUploading()); | ||
} | ||
|
||
public switchAccounts() { | ||
this.dialogRef.close(); | ||
this.store.dispatch(new forAccount.SwitchAccounts(new OpenUploader())); | ||
} | ||
|
||
private checkProjectNameAvailable: AsyncValidatorFn = control => { | ||
return timer(750).pipe( | ||
switchMap(() => | ||
this.electron.call(CommonMethods.CheckBundleNameTaken, { name: control.value }), | ||
), | ||
map(taken => (taken ? { projectNameTaken: { value: control.value } } : null)), | ||
); | ||
}; | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.