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

feat(display-edit): disable delete depending on cardinality (DSP-1814) #329

Merged
merged 4 commits into from Aug 12, 2021
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
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions projects/dsp-ui/src/assets/style/_viewer.scss
Expand Up @@ -82,6 +82,14 @@

.button-container {

button.mat-button-disabled {

.mat-icon {
color: #aaaaaa;
}

}

button {
cursor: pointer;
border: none;
Expand Down
Expand Up @@ -28,7 +28,7 @@
<div class="button-container">
<button mat-button
class="edit"
title="edit"
[matTooltip]="'edit'"
*ngIf="!readOnlyValue && canModify && !editModeActive"
(click)="activateEditMode()">
<mat-icon>edit</mat-icon>
Expand All @@ -46,13 +46,15 @@
(click)="toggleComment()">
<mat-icon>comment</mat-icon>
</button>
<button mat-button
<span [matTooltip]="(canDelete ? 'delete' : 'This value cannot be deleted because at least one value is required')">
<button mat-button
class="delete"
title="delete"
*ngIf="!readOnlyValue && canModify && !editModeActive"
[disabled]="!canDelete"
(click)="openDialog()">
<mat-icon>delete</mat-icon>
</button>
<mat-icon>delete</mat-icon>
</button>
</span>
</div>
</div>
</div>
Expand Down
Expand Up @@ -256,6 +256,7 @@ class TestDateValueComponent {
<dsp-display-edit *ngIf="readValue" #displayEditVal [parentResource]="readResource"
[displayValue]="readValue"
[propArray]="propArray"
[canDelete]="deleteIsAllowed"
(referredResourceClicked)="internalLinkClicked($event)"
(referredResourceHovered)="internalLinkHovered($event)"
></dsp-display-edit>`
Expand All @@ -270,6 +271,8 @@ class TestHostDisplayValueComponent implements OnInit {

mode: 'read' | 'update' | 'create' | 'search';

deleteIsAllowed: boolean;

linkValClicked: ReadLinkValue | string = 'init'; // "init" is set because there is a test that checks that this does not emit for standoff links
// (and if it emits undefined because of a bug, we cannot check)
linkValHovered: ReadLinkValue | string = 'init'; // see comment above
Expand All @@ -280,6 +283,8 @@ class TestHostDisplayValueComponent implements OnInit {
this.readResource = res;

this.mode = 'read';

this.deleteIsAllowed = true;
});
}

Expand Down Expand Up @@ -1183,5 +1188,14 @@ describe('DisplayEditComponent', () => {
expect(valuesSpy.v2.values.deleteValue).toHaveBeenCalledTimes(1);
});
});

it('should disable the delete button', async () => {
testHostComponent.displayEditValueComponent.canDelete = false;

testHostFixture.detectChanges();

const deleteButton = await rootLoader.getHarness(MatButtonHarness.with({selector: '.delete'}));
expect(deleteButton.isDisabled).toBeTruthy;
});
});
});
Expand Up @@ -75,6 +75,8 @@ export class DisplayEditComponent implements OnInit {

@Input() configuration?: object;

@Input() canDelete: boolean;

@Output() referredResourceClicked: EventEmitter<ReadLinkValue> = new EventEmitter<ReadLinkValue>();

@Output() referredResourceHovered: EventEmitter<ReadLinkValue> = new EventEmitter<ReadLinkValue>();
Expand Down
Expand Up @@ -25,6 +25,7 @@
[parentResource]="parentResource"
[displayValue]="val"
[propArray]="propArray"
[canDelete]="deleteValueIsAllowed(prop)"
(referredResourceClicked)="referredResourceClicked.emit($event)"
(referredResourceHovered)="referredResourceHovered.emit($event)">
</dsp-display-edit>
Expand Down
Expand Up @@ -113,6 +113,7 @@ class TestDisplayValueComponent {
@Input() displayValue: ReadValue;
@Input() propArray: PropertyInfoValues[];
@Input() configuration?: object;
@Input() canDelete: boolean;

@Output() referredResourceClicked: EventEmitter<ReadLinkValue> = new EventEmitter<ReadLinkValue>();
@Output() referredResourceHovered: EventEmitter<ReadLinkValue> = new EventEmitter<ReadLinkValue>();
Expand Down
Expand Up @@ -131,4 +131,16 @@ export class PropertyViewComponent implements OnInit, OnDestroy {
// user has write permissions
return isAllowed && this.propID !== prop.propDef.id && this.addButtonIsVisible;
}

/**
* Given a resource property, check if its cardinality allows a value to be deleted
*
* @param prop the resource property
*/
deleteValueIsAllowed(prop: PropertyInfoValues): boolean {
const isAllowed = CardinalityUtil.deleteValueForPropertyAllowed(
prop.propDef.id, prop.values.length, this.parentResource.entityInfo.classes[this.parentResource.type]);

return isAllowed;
}
}