-
Notifications
You must be signed in to change notification settings - Fork 214
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
feat: updates form components to support long form items plus specs #1062
Conversation
Nx Cloud ReportCI ran the following commands for commit ebcae05. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch
Sent with 💌 from NxCloud. |
implements OnInit, OnDestroy, OnChanges, ControlValueAccessor { | ||
@Input() field: Option; | ||
|
||
export class AutocompleteComponent implements OnInit, ControlValueAccessor { |
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.
I don't really think this needs to be a ControlValueAccessor with the input connected thru ControlContainer, but I'll save that for later. Same with FieldComponent; seems like it should just be a pass thru to child form components using the built in ControlValueAccessors.
@@ -114,6 +92,21 @@ export class AutocompleteComponent | |||
) | |||
).pipe(startWith(false), debounceTime(300), shareReplay(1)); | |||
|
|||
this.visibleOptions = this._options$.pipe( | |||
switchMap((options) => | |||
this.control.valueChanges.pipe( |
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.
- moved all setup to OnInit
- Fixed Autocomplete component doesn't retain the filtered options in the list when you select an option or click outside after typing in the input. #984 with this change from
startWith('')
tostartWith(this.control.value || '')
) | ||
) | ||
); | ||
|
||
this.selectedOption$ = this.isFocused$.pipe( |
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.
selectedOption$
is a little bit 😬 but I left it alone. I did remove the subscribe to it below though.
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.
Yea, that subscribe is a weird pattern..
} | ||
|
||
ngOnChanges(changes: SimpleChanges) { | ||
if (changes.field) { |
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.
move this to set field()
import { ItemsWithEnum, Option } from '@nx-console/schema'; | ||
|
||
export const getOptionItems = (field: Option): string[] | undefined => { | ||
return ( |
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.
this typing can be a little annoying on items, especially to access these items in the template, so the pipe
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.
Nice!
@@ -46,9 +47,6 @@ export class FieldComponent implements ControlValueAccessor, OnDestroy { | |||
valueChangeSub: Subscription; | |||
OptionComponent = OptionComponent; | |||
|
|||
control = new FormControl(''); |
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.
finally removing all of this new FormControl down in these components and just connecting thru the ControlContainer 😸
this.subscriptions.add( | ||
this.selectControl.valueChanges.subscribe((value) => | ||
this.valueChange.emit(value) | ||
) | ||
); | ||
if (this.field.items) { |
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.
Another significant change I made is to not set items OnInit but instead just access them from the field.
OnInit was fine given the form is created each time a new generator or executor is opened, but it was a pain to build tests around. Now the fields update OnChange as you would expect.
}); | ||
}); | ||
|
||
it('should show long form options', () => { |
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 SelectComponent wasn't supporting long form items
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.
Everything looks good for me! I tested it locally, and things are good 😄
vscode-ui-feature-task-execution-form-e2e
was failing because the tests expected support for long form options, which was not consistently supported across the dropdown components. Should be fixed.