-
Notifications
You must be signed in to change notification settings - Fork 43
src/app/manager-dashboard/requests/requests-table.component.ts (fixes #9327) #9328
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -13,13 +13,19 @@ import { DialogsListComponent } from '../../shared/dialogs/dialogs-list.componen | |
| import { StateService } from '../../shared/state.service'; | ||
| import { PlanetMessageService } from '../../shared/planet-message.service'; | ||
| import { DialogsFormService } from '../../shared/dialogs/dialogs-form.service'; | ||
| import { UntypedFormBuilder } from '@angular/forms'; | ||
| import { AbstractControl, FormBuilder, FormControl, FormGroup } from '@angular/forms'; | ||
| import { CustomValidators } from '../../validators/custom-validators'; | ||
| import { DialogsLoadingService } from '../../shared/dialogs/dialogs-loading.service'; | ||
| import { ValidatorService } from '../../validators/validator.service'; | ||
| import { ReportsService } from '../reports/reports.service'; | ||
| import { findDocuments } from '../../shared/mangoQueries'; | ||
|
|
||
| interface EditChildNameFormValue { | ||
| name: string; | ||
| } | ||
|
|
||
| type EditChildNameFormGroup = FormGroup<{ name: FormControl<EditChildNameFormValue['name']> }>; | ||
|
|
||
| @Component({ | ||
| selector: 'planet-requests-table', | ||
| templateUrl: './requests-table.component.html' | ||
|
|
@@ -53,7 +59,7 @@ export class RequestsTableComponent implements OnChanges, AfterViewInit, OnDestr | |
| private couchService: CouchService, | ||
| private dialogsListService: DialogsListService, | ||
| private dialog: MatDialog, | ||
| private fb: UntypedFormBuilder, | ||
| private fb: FormBuilder, | ||
| private stateService: StateService, | ||
| private planetMessageService: PlanetMessageService, | ||
| private dialogsFormService: DialogsFormService, | ||
|
|
@@ -205,25 +211,29 @@ export class RequestsTableComponent implements OnChanges, AfterViewInit, OnDestr | |
| } | ||
|
|
||
| openEditChildNameDialog(planet) { | ||
| const exceptions = [ planet.nameDoc ? planet.nameDoc.name : planet.doc.name ]; | ||
| const currentName = planet.nameDoc ? planet.nameDoc.name : planet.doc.name; | ||
| const exceptions = [ currentName ]; | ||
| const form = this.fb.nonNullable.group({ | ||
| name: this.fb.nonNullable.control(currentName, { | ||
| validators: [ CustomValidators.required ], | ||
| asyncValidators: [ (control: AbstractControl<string>) => this.validatorService.isUnique$(this.dbName, 'name', control, { exceptions }) ] | ||
| }) | ||
| }); | ||
| this.dialogsFormService.openDialogsForm( | ||
| $localize`Edit ${this.reportsService.planetTypeText(planet.doc.planetType)} Name`, | ||
| [ { 'label': $localize`Name`, 'type': 'textbox', 'name': 'name', 'placeholder': $localize`Name`, 'required': true } ], | ||
| this.fb.group({ name: [ | ||
| planet.nameDoc ? planet.nameDoc.name : planet.doc.name, | ||
| CustomValidators.required, | ||
| ac => this.validatorService.isUnique$(this.dbName, 'name', ac, { exceptions }) | ||
| ] }), | ||
| form, | ||
| { onSubmit: this.editChildName(planet).bind(this) } | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| editChildName({ doc, nameDoc }) { | ||
| return (form) => { | ||
| return (form: EditChildNameFormGroup) => { | ||
| const { name } = form.getRawValue(); | ||
|
Comment on lines
231
to
+233
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.
The new Useful? React with 👍 / 👎. |
||
| this.couchService.updateDocument( | ||
| this.dbName, | ||
| { ...nameDoc, 'name': form.name, 'docType': 'parentName', 'planetId': doc._id, createdDate: this.couchService.datePlaceholder } | ||
| { ...nameDoc, 'name': name, 'docType': 'parentName', 'planetId': doc._id, createdDate: this.couchService.datePlaceholder } | ||
| ).pipe( | ||
| finalize(() => this.dialogsLoadingService.stop()) | ||
| ).subscribe(() => { | ||
|
|
||
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 rename dialog now passes a typed
FormGroup(form) intoopenDialogsForm, butDialogsFormComponentonly uses the provided group directly when it is anUntypedFormGroup; otherwise it rebuilds it viafb.group(dialogs-form.component.ts:56-60). A typed form therefore gets treated as a plain config object, producing controls for FormGroup internals rather than thenamecontrol, so the dialog renders/validates incorrectly and cannot submit. Please supply anUntypedFormGroupor update the dialog to accept typed groups before opening the rename modal.Useful? React with 👍 / 👎.