Skip to content
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

Merged
merged 4 commits into from
Apr 16, 2021

Conversation

sandikbarr
Copy link
Contributor

@nx-cloud
Copy link

nx-cloud bot commented Apr 15, 2021

Nx Cloud Report

CI 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

Status Command
#000000 nx run-many --all --parallel --target=build
#000000 nx run-many --all --parallel --target=lint
#000000 nx run-many --all --parallel --target=test

Sent with 💌 from NxCloud.

implements OnInit, OnDestroy, OnChanges, ControlValueAccessor {
@Input() field: Option;

export class AutocompleteComponent implements OnInit, ControlValueAccessor {
Copy link
Contributor Author

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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)
)
);

this.selectedOption$ = this.isFocused$.pipe(
Copy link
Contributor Author

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.

Copy link
Member

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) {
Copy link
Contributor Author

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 (
Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@sandikbarr sandikbarr changed the title updates form components to support long form items plus specs feat: updates form components to support long form items plus specs Apr 15, 2021
@@ -46,9 +47,6 @@ export class FieldComponent implements ControlValueAccessor, OnDestroy {
valueChangeSub: Subscription;
OptionComponent = OptionComponent;

control = new FormControl('');
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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', () => {
Copy link
Contributor Author

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

Copy link
Member

@Cammisuli Cammisuli left a 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 😄

@sandikbarr sandikbarr merged commit 0373a56 into nrwl:master Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants