-
Notifications
You must be signed in to change notification settings - Fork 11.9k
feat(@angular/cli): adding checkbox prompt support #13004
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,7 +99,7 @@ export interface PromptDefinition { | |
| id: string; | ||
| type: string; | ||
| message: string; | ||
| default?: string | number | boolean | null; | ||
| default?: string | string[] | number | boolean | null; | ||
| priority: number; | ||
| validator?: (value: string) => boolean | string | Promise<boolean | string>; | ||
|
|
||
|
|
@@ -109,7 +109,7 @@ export interface PromptDefinition { | |
| } | ||
|
|
||
| export type PromptProvider = (definitions: Array<PromptDefinition>) | ||
| => SubscribableOrPromise<{ [id: string]: JsonValue }>; | ||
| => SubscribableOrPromise<{ [id: string]: JsonValue } | { [id: string]: JsonValue }[]>; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't need to be changed. Each
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. This was a bit of an artifact from trying to resolve some typing errors I had caused while debugging. Good catch! |
||
|
|
||
| export interface SchemaRegistry { | ||
| compile(schema: Object): Observable<SchemaValidator>; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -262,6 +262,45 @@ describe('Prompt Provider', () => { | |
| .toPromise().then(done, done.fail); | ||
| }); | ||
|
|
||
| it('analyzes enums WITH explicit checkbox type', done => { | ||
| const registry = new CoreSchemaRegistry(); | ||
| const data: any = {}; | ||
|
|
||
| registry.usePromptProvider(async definitions => { | ||
| expect(definitions.length).toBe(1); | ||
| expect(definitions[0].type).toBe('checkbox'); | ||
| expect(definitions[0].items).toEqual([ | ||
| 'one', | ||
| 'two', | ||
| 'three', | ||
| ]); | ||
|
|
||
| return [{ [definitions[0].id]: 'one' }, { [definitions[0].id]: 'two' } ]; | ||
| }); | ||
|
|
||
| registry | ||
| .compile({ | ||
| properties: { | ||
| test: { | ||
| type: 'array', | ||
| enum: [ | ||
| 'one', | ||
| 'two', | ||
| 'three', | ||
| ], | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an invalid schema, something cannot be an array and also be equal to |
||
| 'x-prompt': { | ||
| 'type': 'checkbox', | ||
| 'message': 'test-message', | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| .pipe( | ||
| mergeMap(validator => validator(data)), | ||
| ) | ||
| .toPromise().then(done, done.fail); | ||
| }); | ||
|
|
||
| it('analyzes enums WITHOUT explicit list type', done => { | ||
| const registry = new CoreSchemaRegistry(); | ||
| const data: any = {}; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,24 @@ | ||
| import { Injectable } from '@angular/core'; | ||
| import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; | ||
| import { <%= implementationImports %>ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; | ||
| import { Observable } from 'rxjs'; | ||
|
|
||
| @Injectable({ | ||
| providedIn: 'root' | ||
| }) | ||
| export class <%= classify(name) %>Guard implements CanActivate { | ||
| canActivate( | ||
| export class <%= classify(name) %>Guard implements <%= implementations %> { | ||
| <% if (implements && implements.includes('CanActivate')) { %>canActivate( | ||
| next: ActivatedRouteSnapshot, | ||
| state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean { | ||
| return true; | ||
| } | ||
| <% } %><% if (implements && implements.includes('CanActivateChild')) { %>canActivateChild( | ||
| next: ActivatedRouteSnapshot, | ||
| state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean { | ||
| return true; | ||
| } | ||
| <% } %><% if (implements && implements.includes('CanLoad')) { %>canLoad( | ||
| route: Route, | ||
| segments: UrlSegment[]): Observable<boolean> | Promise<boolean> | boolean { | ||
| return true; | ||
| }<% } %> | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initial plan for this concept was to model this as a
multiselectquestion option on the list type itself. Could you make that change?