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

fix(link-value): re-validate form on cancel (DEV-611) #711

Merged
merged 1 commit into from Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/main/dialog/dialog.component.ts
Expand Up @@ -31,6 +31,10 @@ export interface ConfirmationWithComment {
comment?: string;
}

export enum DialogEvent {
DialogCanceled
}

@Component({
selector: 'app-material-dialog',
templateUrl: './dialog.component.html',
Expand Down
Expand Up @@ -16,7 +16,7 @@
</app-select-properties>
<div class="form-panel form-action">
<span>
<button mat-button type="button" (click)="closeDialog.emit()">
<button mat-button type="button" (click)="onCancel()">
{{ 'appLabels.form.action.cancel' | translate }}
</button>
</span>
Expand Down
Expand Up @@ -14,6 +14,7 @@ import {
ResourcePropertyDefinition
} from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { DialogEvent } from 'src/app/main/dialog/dialog.component';
import { ErrorHandlerService } from 'src/app/main/error/error-handler.service';
import { SelectPropertiesComponent } from '../../resource-instance-form/select-properties/select-properties.component';

Expand All @@ -29,7 +30,7 @@ export class CreateLinkResourceComponent implements OnInit {
@Input() resourceClassDef: string;
@Input() currentOntoIri: string;

@Output() closeDialog: EventEmitter<ReadResource> = new EventEmitter<ReadResource>();
@Output() closeDialog: EventEmitter<ReadResource | DialogEvent> = new EventEmitter<ReadResource | DialogEvent>();

@ViewChild('selectProps') selectPropertiesComponent: SelectPropertiesComponent;

Expand Down Expand Up @@ -140,6 +141,11 @@ export class CreateLinkResourceComponent implements OnInit {
}
}

onCancel() {
// emit DialogCanceled event
this.closeDialog.emit(DialogEvent.DialogCanceled);
}

setFileValue(file: CreateFileValue) {
this.fileValue = file;
}
Expand Down
Expand Up @@ -27,7 +27,7 @@ import {
} from '@dasch-swiss/dsp-js';
import { Subscription } from 'rxjs';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { DialogComponent } from 'src/app/main/dialog/dialog.component';
import { DialogComponent, DialogEvent } from 'src/app/main/dialog/dialog.component';
import { BaseValueDirective } from 'src/app/main/directive/base-value.directive';

export function resourceValidator(control: AbstractControl) {
Expand Down Expand Up @@ -264,14 +264,25 @@ export class LinkValueComponent extends BaseValueDirective implements OnInit, On

const dialogRef = this._dialog.open(DialogComponent, dialogConfig);

dialogRef.afterClosed().subscribe((event: any) => {
const newResource = event as ReadResource;
dialogRef.afterClosed().subscribe((event: ReadResource | DialogEvent) => {
// save button clicked
if (event instanceof ReadResource ) {
const newResource = event as ReadResource;

// set value of value form control to the newly created resource
this.form.controls.value.setValue(newResource);
// set value of value form control to the newly created resource
this.form.controls.value.setValue(newResource);

// hide the autocomplete results
this.autocomplete.closePanel();
// hide the autocomplete results
this.autocomplete.closePanel();
}

// cancel button clicked
if (event === DialogEvent.DialogCanceled){
this.resetFormControl();

// hide the autocomplete results
this.autocomplete.closePanel();
}
});
}
}