Skip to content

Commit

Permalink
refactor (confirmation components):
Browse files Browse the repository at this point in the history
 - renamed ConfirmationDialogPayload to ConfirmationDialogValueDeletionPayload
 - refactored the deletion comment to be optional so that it will be undefined instead of null if a comment is not provided
  • Loading branch information
mdelez committed Oct 6, 2020
1 parent 8a09c7e commit 050a4cd
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { MAT_DIALOG_DATA, MatDialog, MatDialogModule, MatDialogRef } from '@angu
import { MatDialogHarness } from '@angular/material/dialog/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MockResource, ReadIntValue, ReadValue } from '@dasch-swiss/dsp-js';
import { ConfirmationDialogComponent, ConfirmationDialogPayload } from './confirmation-dialog.component';
import { ConfirmationDialogComponent, ConfirmationDialogValueDeletionPayload } from './confirmation-dialog.component';

/**
* Test host component to simulate parent component with a confirmation dialog.
Expand Down Expand Up @@ -39,7 +39,7 @@ class ConfirmationDialogTestHostComponent implements OnInit {
buttonTextOk: 'OK',
buttonTextCancel: 'Cancel'
}
}).afterClosed().subscribe((payload: ConfirmationDialogPayload) => {
}).afterClosed().subscribe((payload: ConfirmationDialogValueDeletionPayload) => {
if (payload.confirmed) {
this.confirmationDialogResponse = 'Action was confirmed!';
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export class ConfirmationDialogData {
buttonTextCancel: string;
}

export class ConfirmationDialogPayload {
export class ConfirmationDialogValueDeletionPayload {
confirmed: boolean;
deletionComment: string;
deletionComment?: string;
}

@Component({
Expand All @@ -30,9 +30,9 @@ export class ConfirmationDialogComponent {
) { }

onConfirmClick(): void {
const payload = new ConfirmationDialogPayload();
const payload = new ConfirmationDialogValueDeletionPayload();
payload.confirmed = true;
payload.deletionComment = this.confirmationMessageComponent.comment ? this.confirmationMessageComponent.comment : null;
payload.deletionComment = this.confirmationMessageComponent.comment ? this.confirmationMessageComponent.comment : undefined;
this._dialogRef.close(payload);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ReadValue } from '@dasch-swiss/dsp-js';
export class ConfirmationMessageComponent {

@Input() value: ReadValue;
comment: string;
comment?: string;

constructor() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ describe('DisplayEditComponent', () => {
const deleteVal = new DeleteValue();
deleteVal.id = 'http://rdfh.ch/0001/H6gBWUuJSuuO-CilHV8kQw/values/dJ1ES8QTQNepFKF5-EAqdg';
deleteVal.type = 'http://api.knora.org/ontology/knora-api/v2#IntValue';
deleteVal.deleteComment = null;
deleteVal.deleteComment = undefined;

expectedUpdateResource.value = deleteVal;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { mergeMap } from 'rxjs/operators';
import {
ConfirmationDialogComponent,
ConfirmationDialogData,
ConfirmationDialogPayload
ConfirmationDialogValueDeletionPayload
} from '../../../action/components/confirmation-dialog/confirmation-dialog.component';
import { DspApiConnectionToken } from '../../../core/core.module';
import {
Expand Down Expand Up @@ -223,7 +223,7 @@ export class DisplayEditComponent implements OnInit {
const dialogRef =
this._dialog.open<ConfirmationDialogComponent, ConfirmationDialogData>(ConfirmationDialogComponent, { data: dialogData});

dialogRef.afterClosed().subscribe((payload: ConfirmationDialogPayload) => {
dialogRef.afterClosed().subscribe((payload: ConfirmationDialogValueDeletionPayload) => {
if (payload && payload.confirmed) {
this.deleteValue(payload.deletionComment);
}
Expand Down

0 comments on commit 050a4cd

Please sign in to comment.