Skip to content

Commit

Permalink
Revert "fix: add validation when creating new workspace with conflict…
Browse files Browse the repository at this point in the history
…ing name"

This reverts commit 98f6cdd.
  • Loading branch information
vsavkin committed Oct 9, 2018
1 parent 532ab8a commit 34e9ac5
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
<mat-form-field class="workspace-name-form-field" fxFlex>
<mat-label>Workspace Name</mat-label>
<input matInput placeholder="MyNewWorkspace" required formControlName="name" name="name">
<mat-error *ngIf="form.get('name').invalid && form.get('name').errors.nameTaken">
This name is already taken
</mat-error>
</mat-form-field>
</mat-expansion-panel>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,12 @@ import {
ViewChildren,
ViewEncapsulation
} from '@angular/core';
import {
AsyncValidatorFn,
ValidationErrors,
AbstractControl,
FormControl,
FormGroup,
Validators
} from '@angular/forms';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { MatDialog, MatExpansionPanel } from '@angular/material';
import { ContextualActionBarService } from '@nrwl/angular-console-enterprise-frontend';
import { Apollo } from 'apollo-angular';
import gql from 'graphql-tag';
import { of, BehaviorSubject, Observable, Subject } from 'rxjs';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import {
filter,
map,
Expand All @@ -31,8 +24,6 @@ import {
NewWorkspaceDialogComponent,
NgNewInvocation
} from './new-workspace-dialog.component';
import { Directory } from '@angular-console/schema';
import { Finder } from '@angular-console/utils';

interface SchematicCollectionForNgNew {
name: string;
Expand All @@ -58,18 +49,13 @@ export class NewWorkspaceComponent implements OnInit {
constructor(
private readonly apollo: Apollo,
private readonly contextActionService: ContextualActionBarService,
private readonly matDialog: MatDialog,
private readonly finderService: Finder
private readonly matDialog: MatDialog
) {}

private static newFormGroup(finderService: Finder): FormGroup {
private static newFormGroup(): FormGroup {
return new FormGroup({
name: new FormControl(null, Validators.required),
path: new FormControl(null, Validators.required),
name: new FormControl(
null,
Validators.required,
makeNameAvailableValidator(finderService)
),
collection: new FormControl(null, Validators.required)
});
}
Expand All @@ -81,9 +67,7 @@ export class NewWorkspaceComponent implements OnInit {
panel.close();
});
this.selectedNode = null;
this.ngNewForm$.next(
NewWorkspaceComponent.newFormGroup(this.finderService)
);
this.ngNewForm$.next(NewWorkspaceComponent.newFormGroup());
}
});

Expand All @@ -106,9 +90,7 @@ export class NewWorkspaceComponent implements OnInit {
);

this.schematicCollectionsForNgNew$.subscribe(() => {
this.ngNewForm$.next(
NewWorkspaceComponent.newFormGroup(this.finderService)
);
this.ngNewForm$.next(NewWorkspaceComponent.newFormGroup());
});

this.createNewWorkspace$.subscribe(() => {
Expand Down Expand Up @@ -182,22 +164,3 @@ export class NewWorkspaceComponent implements OnInit {
}
}
}

export function makeNameAvailableValidator(
finderService: Finder
): AsyncValidatorFn {
return (control: AbstractControl): Observable<ValidationErrors | null> => {
const form = control.parent;
const path = form.get('path');
const name = form.get('name');
return of(name && path ? `${path.value}/${name.value}` : null).pipe(
switchMap(
(path: null | string): Observable<null | Directory> =>
path ? finderService.listFiles(path) : of(null)
),
map(
(d: null | Directory) => (!d || !d.exists ? null : { nameTaken: true })
)
);
};
}
1 change: 0 additions & 1 deletion libs/schema/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export interface LocalFile {

export interface Directory {
path: string;
exists: boolean;
files: Array<LocalFile>;
}

Expand Down
1 change: 0 additions & 1 deletion libs/utils/src/lib/finder.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class Finder {
query($path: String!, $onlyDirectories: Boolean) {
directory(path: $path, onlyDirectories: $onlyDirectories) {
path
exists
files {
name
type
Expand Down
17 changes: 6 additions & 11 deletions server/src/api/read-directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export function readDirectory(
onlyDirectories: boolean,
showHidden: boolean
): Observable<Directory> {
if (dirName === '') {
return _defaultRootDirectory(onlyDirectories, showHidden);
if (dirName === '' && os.platform() === 'win32') {
return mountPoints();
} else if (dirName === '') {
return _readDirectory('/', onlyDirectories, showHidden);
} else {
if (dirName !== '/' && !directoryExists(dirName)) {
return of(null);
throw new Error(`Cannot find directory: '${dirName}'`);
}
return _readDirectory(dirName, onlyDirectories, showHidden);
}
Expand Down Expand Up @@ -88,7 +90,6 @@ function _readDirectory(
(files: Array<LocalFile | null>): Directory => {
return {
path: dirName,
exists: true,
files: files.filter(t => {
if (!t) return false;

Expand All @@ -107,12 +108,6 @@ function _readDirectory(
);
}

function _defaultRootDirectory(onlyDirectories: boolean, showHidden: boolean) {
return os.platform() === 'win32'
? mountPoints()
: _readDirectory('/', onlyDirectories, showHidden);
}

export function mountPoints(): Observable<Directory> {
const res = new Subject<Directory>();

Expand All @@ -132,7 +127,7 @@ export function mountPoints(): Observable<Directory> {
})
];
});
res.next({ path: '', exists: true, files: mountpoints });
res.next({ path: '', files: mountpoints });
res.complete();
}
});
Expand Down
7 changes: 0 additions & 7 deletions server/src/graphql-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ export interface IsNodeInstalledResult {

export interface FilesType {
path: string;
exists: boolean;
files?: (FileListType | null)[] | null;
}

Expand Down Expand Up @@ -1057,7 +1056,6 @@ export namespace IsNodeInstalledResultResolvers {
export namespace FilesTypeResolvers {
export interface Resolvers<Context = any> {
path?: PathResolver<string, any, Context>;
exists?: ExistsResolver<boolean, any, Context>;
files?: FilesResolver<(FileListType | null)[] | null, any, Context>;
}

Expand All @@ -1066,11 +1064,6 @@ export namespace FilesTypeResolvers {
Parent,
Context
>;
export type ExistsResolver<
R = boolean,
Parent = any,
Context = any
> = Resolver<R, Parent, Context>;
export type FilesResolver<
R = (FileListType | null)[] | null,
Parent = any,
Expand Down
2 changes: 1 addition & 1 deletion server/src/schema/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ const Database: DatabaseResolvers.Resolvers = {
args.showHidden
).toPromise();
if (!v) {
return { path: args.path, exists: false, files: [] };
return { path: args.path, files: [] };
}
return v;
} catch (e) {
Expand Down
1 change: 0 additions & 1 deletion server/src/schema/type-defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export const typeDefs = gql`
type FilesType {
path: String!
exists: Boolean!
files: [FileListType]
}
Expand Down

0 comments on commit 34e9ac5

Please sign in to comment.