Skip to content

Commit 4d9b747

Browse files
authored
feat(value): improve list value (DEV-951) (#757)
1 parent 3c2409a commit 4d9b747

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

‎src/app/workspace/resource/values/list-value/list-value.component.html‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
<span *ngIf="mode !== 'read' && listRootNode !== undefined">
2-
<button class="md-button" mat-stroked-button [matMenuTriggerFor]="mainMenu" type="button" placeholder="List value">
3-
<span *ngIf="!selectedNode">Select list value</span>
4-
<span *ngIf="selectedNode">{{selectedNode.label}}</span>
5-
</button>
2+
3+
<!-- button to select a list node -->
4+
<span [matTooltip]="(!selectedNode && !listRootNode.children.length) ? 'This list doesn\'t have any node values' : 'Select list value'" [matTooltipPosition]="'above'">
5+
<button mat-stroked-button [matMenuTriggerFor]="mainMenu" type="button" placeholder="List value" [disabled]="!selectedNode && !listRootNode.children.length">
6+
7+
<!-- if no node is selected: display list label; if the list does not have any list nodes, the button should be disabled -->
8+
<span *ngIf="!selectedNode">{{listRootNode.label}}</span>
9+
10+
<!-- if a node is selected: display node label -->
11+
<span *ngIf="selectedNode">{{selectedNode.label}}</span>
12+
13+
</button>
14+
</span>
615

716
<mat-menu #mainMenu="matMenu" [overlapTrigger]="false">
817
<span *ngFor="let child of listRootNode.children">
@@ -22,6 +31,7 @@
2231
</span>
2332
</span>
2433
</mat-menu>
34+
2535
<mat-error *ngIf="valueFormControl.hasError('valueNotChanged') && valueFormControl.dirty">
2636
<span class="custom-error-message">New value must be different than the current value.</span>
2737
</mat-error>

‎src/app/workspace/resource/values/list-value/list-value.component.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ describe('ListValueComponent', () => {
160160

161161
expect(valuesSpy.v2.list.getList).toHaveBeenCalledTimes(1);
162162
expect(valuesSpy.v2.list.getList).toHaveBeenCalledWith('http://rdfh.ch/lists/0001/treeList');
163-
expect(testHostComponent.inputValueComponent.listRootNode.children.length).toEqual(1);
163+
expect(testHostComponent.inputValueComponent.listRootNode.children.length).toEqual(0);
164164

165165
const openListButtonDe = valueComponentDe.query(By.css('button'));
166166

‎src/app/workspace/resource/values/list-value/list-value.component.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ export class ListValueComponent extends BaseValueDirective implements OnInit, On
6868
}
6969
if (this.valueFormControl !== undefined) {
7070
if (this.mode !== 'read') {
71-
this.listRootNode = new ListNodeV2();
7271
const rootNodeIris = this.propertyDef.guiAttributes;
7372
for (const rootNodeIri of rootNodeIris) {
74-
// get rid of the "hlist"
7573
const trimmedRootNodeIRI = rootNodeIri.substr(7, rootNodeIri.length - (1 + 7));
7674
this._dspApiConnection.v2.list.getList(trimmedRootNodeIRI).subscribe(
77-
(response2: ListNodeV2) => {
78-
this.listRootNode.children.push(response2);
75+
(response: ListNodeV2) => {
76+
this.listRootNode = response;
7977
}, (error: ApiResponseError) => {
8078
this._errorHandler.showMessage(error);
8179
});
@@ -126,11 +124,8 @@ export class ListValueComponent extends BaseValueDirective implements OnInit, On
126124
}
127125

128126
const newListValue = new CreateListValue();
129-
130-
131127
newListValue.listNode = this.valueFormControl.value;
132128

133-
134129
if (this.commentFormControl.value !== null && this.commentFormControl.value !== '') {
135130
newListValue.valueHasComment = this.commentFormControl.value;
136131
}

0 commit comments

Comments
 (0)