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

AAE-23521 Fix improve dropdown reactive form #10040

Merged
merged 9 commits into from
Aug 7, 2024

Conversation

kathrine0
Copy link
Contributor

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (check one with "x")

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation
  • Other... Please describe:

What is the current behaviour? (You can also link to an open issue here)

AAE-23521

What is the new behaviour?

Does this PR introduce a breaking change? (check one with "x")

  • Yes
  • No

If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...

Other information:

@eromano
Copy link
Contributor

eromano commented Aug 5, 2024

Copy link
Contributor

@tomgny tomgny left a comment

Choose a reason for hiding this comment

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

added some notes and small suggestions

*ngIf="isRequired()">*</span>
<div
class="adf-dropdown-widget {{field.className}}"
[class.adf-invalid]="dropdownControl.invalid && dropdownControl.touched"
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we can also replate it by getter?
something like

Suggested change
[class.adf-invalid]="dropdownControl.invalid && dropdownControl.touched"
get isDropdownInvalidAndTouched(): boolean {
return this.dropdownControl.invalid && this.dropdownControl.touched;
}

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 think it's not needed here - no additional code

MatSelectModule,
ErrorWidgetComponent,
TranslateModule,
CardViewModule // imported for adf-select-filter-input
Copy link
Contributor

Choose a reason for hiding this comment

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

i think this comment is not needed

Copy link
Contributor Author

@kathrine0 kathrine0 Aug 5, 2024

Choose a reason for hiding this comment

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

I left it here because I hope that soon we will modify the adf-select-filter-input to be standalone and then this import can be removed

this.dropdownControl.disable({ emitEvent: false });
}

this.dropdownControl.valueChanges
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we can move this subscriptions to separate method? what do you think?

class="adf-dropdown-failed-message"
*ngIf="variableOptionsFailed"
required="{{ 'FORM.FIELD.VARIABLE_DROPDOWN_OPTIONS_FAILED' | translate }}"
></error-widget>
Copy link
Contributor

Choose a reason for hiding this comment

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

i think we can display errors using only one error-widget (by assign errors to the validationSummary property), but its something optional, in the future i believe we will replace this by mat-error (we have ticket for it)
so its just a suggestion

@@ -51,22 +50,6 @@ export class RequiredFieldValidator implements FormFieldValidator {

validate(field: FormFieldModel): boolean {
if (this.isSupported(field) && field.isVisible) {
if (field.type === FormFieldTypes.DROPDOWN) {
if (field.hasMultipleValues) {
Copy link
Contributor

Choose a reason for hiding this comment

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

just a note, please make sure we still have a correct behaviour of form validity as a whole, like disable 'Complete' button where field.hasMultipleValues and Array.isArray(field.value) && !!field.value.length return false

@kathrine0
Copy link
Contributor Author

does the https://github.com/Alfresco/alfresco-ng2-components/tree/develop/lib/process-services/src/lib/form/widgets/dropdown needs any change with this modify?

That's right, I modified the dropdown widget as well

Copy link
Contributor

@tomgny tomgny left a comment

Choose a reason for hiding this comment

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

good job

}

isReadOnlyType(): boolean {
return this.field.type === 'readonly';
private initFormControl() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private initFormControl() {
private initFormControl(): void {

}

showRequiredMessage(): boolean {
return (this.isInvalidFieldRequired() || this.field.value === 'empty') && this.isTouched();
private handleErrors() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private handleErrors() {
private handleErrors(): void {

}

get isReadOnlyField(): boolean {
return this.field.readOnly;
private setOptionValue(option: string | FormFieldOption, field: FormFieldModel) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private setOptionValue(option: string | FormFieldOption, field: FormFieldModel) {
private setOptionValue(option: string | FormFieldOption, field: FormFieldModel): void {

}

private isReadOnlyForm(): boolean {
return !!this.field?.form?.readOnly;
private getOptionValue(value?: string | FormFieldOption) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private getOptionValue(value?: string | FormFieldOption) {
private getOptionValue(value?: string | FormFieldOption): FormFieldOption | undefined {

</mat-option>
<mat-option id="readonlyOption" *ngIf="isReadOnlyType()" [value]="field.value">{{field.value}}</mat-option>
<mat-select class="adf-select" [id]="field.id" [formControl]="dropdownControl">
<mat-option *ngFor="let opt of field.options" [value]="opt" [id]="opt.id">{{opt.name}} </mat-option>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<mat-option *ngFor="let opt of field.options" [value]="opt" [id]="opt.id">{{opt.name}} </mat-option>
<mat-option *ngFor="let opt of field.options" [value]="opt" [id]="opt.id">{{opt.name}}</mat-option>

:D

@@ -1,5 +1,6 @@
.adf-error {
display: flex;
align-items: center;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this expected? the error under each field should be centered, not left-aligned?

Copy link

sonarqubecloud bot commented Aug 6, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
3.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@kathrine0 kathrine0 merged commit f88ff10 into develop Aug 7, 2024
32 of 33 checks passed
@kathrine0 kathrine0 deleted the fix/AAE-23521-improve-dropdown-reactive-form branch August 7, 2024 13:21
VitoAlbano added a commit that referenced this pull request Aug 9, 2024
ehsan-2019 pushed a commit that referenced this pull request Aug 9, 2024
VitoAlbano added a commit that referenced this pull request Aug 9, 2024
ehsan-2019 pushed a commit that referenced this pull request Aug 9, 2024
* Revert "AAE-23521 Fix improve dropdown reactive form (#10040)"

This reverts commit f88ff10.

* Revert "AAE-24371 Fix invalid endpoint is called when process with form is st… (#10052)"

This reverts commit d38e782.

* Revert "Revert "AAE-24371 Fix invalid endpoint is called when process with form is st… (#10052)""

This reverts commit 125ada7.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants