Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions src/app/manager-dashboard/requests/requests-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) }
Comment on lines 222 to 226

Choose a reason for hiding this comment

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

P1 Badge Pass compatible form instance to dialog service

The rename dialog now passes a typed FormGroup (form) into openDialogsForm, but DialogsFormComponent only uses the provided group directly when it is an UntypedFormGroup; otherwise it rebuilds it via fb.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 the name control, so the dialog renders/validates incorrectly and cannot submit. Please supply an UntypedFormGroup or update the dialog to accept typed groups before opening the rename modal.

Useful? React with 👍 / 👎.

);

}

editChildName({ doc, nameDoc }) {
return (form) => {
return (form: EditChildNameFormGroup) => {
const { name } = form.getRawValue();
Comment on lines 231 to +233

Choose a reason for hiding this comment

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

P1 Badge Fix rename submit handler expecting FormGroup

The new editChildName callback now expects the FormGroup and calls form.getRawValue(), but DialogsFormComponent invokes onSubmit with the form value object as the first argument (dialogs-form.component.ts:77–80). When the rename dialog is submitted, this function receives the plain value object and throws because getRawValue is undefined, so the update request never runs. Use the mForm argument passed by the dialog or operate on the value object instead of calling FormGroup methods.

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(() => {
Expand Down