Skip to content

Commit 9263c94

Browse files
committed
feat: add ability to apply label display with other value kind
1 parent 781d8d5 commit 9263c94

File tree

8 files changed

+67
-174
lines changed

8 files changed

+67
-174
lines changed

projects/wc/src/app/components/generic-ui/value-cell/label-value/label-value.component.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

projects/wc/src/app/components/generic-ui/value-cell/label-value/label-value.component.scss

Lines changed: 0 additions & 12 deletions
This file was deleted.

projects/wc/src/app/components/generic-ui/value-cell/label-value/label-value.component.spec.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

projects/wc/src/app/components/generic-ui/value-cell/label-value/label-value.component.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

projects/wc/src/app/components/generic-ui/value-cell/value-cell.component.html

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
@if (displayAs() === 'plainText') {
2-
{{ value() }}
3-
} @else if (displayAs() === 'secret') {
4-
<wc-secret-value [value]="value()"></wc-secret-value>
5-
} @else if (isBoolLike()) {
6-
<wc-boolean-value [boolValue]="boolValue()!"></wc-boolean-value>
7-
} @else if (isUrlValue()) {
8-
<wc-link-value [urlValue]="stringValue()!"></wc-link-value>
9-
} @else if (isLabelValue()) {
10-
<wc-label-value [labelDisplay]="labelDisplayValue()!" [value]="value()"></wc-label-value>
11-
} @else {
12-
{{ value() }}
13-
}
1+
<span [class.label-value]="labelDisplay()" [style]="{
2+
backgroundColor: labelDisplay()?.backgroundColor,
3+
color: labelDisplay()?.color,
4+
fontWeight: labelDisplay()?.fontWeight,
5+
fontStyle: labelDisplay()?.fontStyle,
6+
textDecoration: labelDisplay()?.textDecoration,
7+
textTransform: labelDisplay()?.textTransform,
8+
}">
9+
@if (displayAs() === 'plainText') {
10+
{{ value() }}
11+
} @else if (displayAs() === 'secret') {
12+
<wc-secret-value [value]="value()"></wc-secret-value>
13+
} @else if (isBoolLike()) {
14+
<wc-boolean-value [boolValue]="boolValue()!"></wc-boolean-value>
15+
} @else if (isUrlValue()) {
16+
<wc-link-value [urlValue]="stringValue()!"></wc-link-value>
17+
} @else {
18+
{{ value() }}
19+
}
20+
</span>
1421

1522
@if (withCopyButton()) {
1623
<ui5-icon (click)="copyValue($event)" name="copy">

projects/wc/src/app/components/generic-ui/value-cell/value-cell.component.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,16 @@
33
align-items: center;
44
gap: 0.5rem;
55
}
6+
7+
.label-value {
8+
background-color: #01B4FF;
9+
color: #ffffff;
10+
border-radius: 1.4rem;
11+
padding-inline: 0.4375rem;
12+
letter-spacing: -0.00875rem;
13+
display: inline-block;
14+
border: 0;
15+
font-size: 0.875rem;
16+
line-height: 1.4rem;
17+
margin: 3px 0;
18+
}

projects/wc/src/app/components/generic-ui/value-cell/value-cell.component.spec.ts

Lines changed: 30 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { BooleanValueComponent } from './boolean-value/boolean-value.component';
2+
import { LinkValueComponent } from './link-value/link-value.component';
3+
import { SecretValueComponent } from './secret-value/secret-value.component';
14
import { ValueCellComponent } from './value-cell.component';
25
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
36
import { ComponentFixture, TestBed } from '@angular/core/testing';
@@ -50,7 +53,15 @@ describe('ValueCellComponent', () => {
5053
beforeEach(() => {
5154
TestBed.configureTestingModule({
5255
imports: [ValueCellComponent],
53-
schemas: [CUSTOM_ELEMENTS_SCHEMA],
56+
}).overrideComponent(ValueCellComponent, {
57+
set: {
58+
imports: [
59+
BooleanValueComponent,
60+
LinkValueComponent,
61+
SecretValueComponent,
62+
],
63+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
64+
},
5465
});
5566
});
5667

@@ -164,82 +175,49 @@ describe('ValueCellComponent', () => {
164175
});
165176

166177
describe('labelDisplay functionality', () => {
167-
it('should render label-value component when labelDisplay is an object', () => {
178+
it('should apply label styles when labelDisplay is an object', () => {
168179
const labelDisplay = { backgroundColor: '#ffffff', color: '#000000' };
169180
const { fixture } = makeComponent('test-value', {
170181
uiSettings: { labelDisplay },
171182
});
172183
const compiled = fixture.nativeElement;
184+
const span = compiled.querySelector('span');
173185

174-
expect(compiled.querySelector('wc-label-value')).toBeTruthy();
175-
expect(component.isLabelValue()).toBe(true);
176-
expect(component.labelDisplayValue()).toEqual(labelDisplay);
186+
expect(span.classList.contains('label-value')).toBe(true);
187+
expect(component.labelDisplay()).toEqual(labelDisplay);
177188
});
178189

179-
it('should render label-value component when labelDisplay is true', () => {
190+
it('should apply label-value class when labelDisplay is true', () => {
180191
const { fixture } = makeComponent('test-value', {
181192
uiSettings: { labelDisplay: true },
182193
});
183194
const compiled = fixture.nativeElement;
195+
const span = compiled.querySelector('span');
184196

185-
expect(compiled.querySelector('wc-label-value')).toBeTruthy();
186-
expect(component.isLabelValue()).toBe(true);
187-
expect(component.labelDisplayValue()).toEqual({});
197+
expect(span.classList.contains('label-value')).toBe(true);
198+
expect(component.labelDisplay()).toEqual({});
188199
});
189200

190-
it('should not render label-value component when labelDisplay is false', () => {
201+
it('should not apply label-value class when labelDisplay is false', () => {
191202
const { fixture } = makeComponent('test-value', {
192203
uiSettings: { labelDisplay: false },
193204
});
194205
const compiled = fixture.nativeElement;
206+
const span = compiled.querySelector('span');
195207

196-
expect(compiled.querySelector('wc-label-value')).toBeFalsy();
197-
expect(component.isLabelValue()).toBe(false);
198-
expect(component.labelDisplayValue()).toBeUndefined();
208+
expect(span.classList.contains('label-value')).toBe(false);
209+
expect(component.labelDisplay()).toBeUndefined();
199210
});
200211

201-
it('should not render label-value component when labelDisplay is undefined', () => {
212+
it('should not apply label-value class when labelDisplay is undefined', () => {
202213
const { fixture } = makeComponent('test-value', {
203214
uiSettings: { labelDisplay: undefined },
204215
});
205216
const compiled = fixture.nativeElement;
217+
const span = compiled.querySelector('span');
206218

207-
expect(compiled.querySelector('wc-label-value')).toBeFalsy();
208-
expect(component.isLabelValue()).toBe(false);
209-
expect(component.labelDisplayValue()).toBeUndefined();
210-
});
211-
212-
it('should not render label-value component when labelDisplay is null', () => {
213-
const { fixture } = makeComponent('test-value', {
214-
uiSettings: { labelDisplay: null as any },
215-
});
216-
const compiled = fixture.nativeElement;
217-
218-
expect(compiled.querySelector('wc-label-value')).toBeFalsy();
219-
expect(component.isLabelValue()).toBe(false);
220-
expect(component.labelDisplayValue()).toBeUndefined();
221-
});
222-
223-
it('should render label-value component when labelDisplay is a string', () => {
224-
const { fixture } = makeComponent('test-value', {
225-
uiSettings: { labelDisplay: 'some-string' as any },
226-
});
227-
const compiled = fixture.nativeElement;
228-
229-
expect(compiled.querySelector('wc-label-value')).toBeTruthy();
230-
expect(component.isLabelValue()).toBe(true);
231-
expect(component.labelDisplayValue()).toEqual({});
232-
});
233-
234-
it('should render label-value component when labelDisplay is a number', () => {
235-
const { fixture } = makeComponent('test-value', {
236-
uiSettings: { labelDisplay: 42 as any },
237-
});
238-
const compiled = fixture.nativeElement;
239-
240-
expect(compiled.querySelector('wc-label-value')).toBeTruthy();
241-
expect(component.isLabelValue()).toBe(true);
242-
expect(component.labelDisplayValue()).toEqual({});
219+
expect(span.classList.contains('label-value')).toBe(false);
220+
expect(component.labelDisplay()).toBeUndefined();
243221
});
244222
});
245223

@@ -355,7 +333,6 @@ describe('ValueCellComponent', () => {
355333

356334
expect(compiled.querySelector('wc-boolean-value')).toBeFalsy();
357335
expect(compiled.querySelector('wc-link-value')).toBeFalsy();
358-
expect(compiled.querySelector('wc-label-value')).toBeFalsy();
359336
expect(compiled.querySelector('wc-secret-value')).toBeFalsy();
360337
expect(compiled.textContent.trim()).toContain('test-value');
361338
});
@@ -657,51 +634,18 @@ describe('ValueCellComponent', () => {
657634

658635
expect(compiled.querySelector('wc-boolean-value')).toBeTruthy();
659636
expect(compiled.querySelector('wc-link-value')).toBeFalsy();
660-
expect(compiled.querySelector('wc-label-value')).toBeFalsy();
661-
});
662-
663-
it('should prioritize boolean over label when both are valid', () => {
664-
const { fixture } = makeComponent('true', {
665-
uiSettings: { labelDisplay: { backgroundColor: '#ffffff' } },
666-
});
667-
const compiled = fixture.nativeElement;
668-
669-
expect(compiled.querySelector('wc-boolean-value')).toBeTruthy();
670-
expect(compiled.querySelector('wc-link-value')).toBeFalsy();
671-
expect(compiled.querySelector('wc-label-value')).toBeFalsy();
672-
});
673-
674-
it('should prioritize URL over label when both are valid', () => {
675-
const { fixture } = makeComponent('https://example.com', {
676-
uiSettings: { labelDisplay: { backgroundColor: '#ffffff' } },
677-
});
678-
const compiled = fixture.nativeElement;
679-
680-
expect(compiled.querySelector('wc-boolean-value')).toBeFalsy();
681-
expect(compiled.querySelector('wc-link-value')).toBeTruthy();
682-
expect(compiled.querySelector('wc-label-value')).toBeFalsy();
683-
});
684-
685-
it('should render label when boolean and URL are not valid but labelDisplay is provided', () => {
686-
const { fixture } = makeComponent('some-text', {
687-
uiSettings: { labelDisplay: { backgroundColor: '#ffffff' } },
688-
});
689-
const compiled = fixture.nativeElement;
690-
691-
expect(compiled.querySelector('wc-boolean-value')).toBeFalsy();
692-
expect(compiled.querySelector('wc-link-value')).toBeFalsy();
693-
expect(compiled.querySelector('wc-label-value')).toBeTruthy();
694637
});
695638

696639
it('should render plain text when no special rendering is needed', () => {
697640
const { fixture } = makeComponent('some-text', {
698641
uiSettings: { labelDisplay: false },
699642
});
700643
const compiled = fixture.nativeElement;
644+
const span = compiled.querySelector('span');
701645

702646
expect(compiled.querySelector('wc-boolean-value')).toBeFalsy();
703647
expect(compiled.querySelector('wc-link-value')).toBeFalsy();
704-
expect(compiled.querySelector('wc-label-value')).toBeFalsy();
648+
expect(span.classList.contains('label-value')).toBe(false);
705649
expect(compiled.textContent.trim()).toBe('some-text');
706650
});
707651
});

projects/wc/src/app/components/generic-ui/value-cell/value-cell.component.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { BooleanValueComponent } from './boolean-value/boolean-value.component';
2-
import { LabelValue } from './label-value/label-value.component';
32
import { LinkValueComponent } from './link-value/link-value.component';
43
import { SecretValueComponent } from './secret-value/secret-value.component';
54
import {
@@ -25,7 +24,6 @@ import { IconComponent } from '@ui5/webcomponents-ngx';
2524
IconComponent,
2625
BooleanValueComponent,
2726
LinkValueComponent,
28-
LabelValue,
2927
SecretValueComponent,
3028
],
3129
templateUrl: './value-cell.component.html',
@@ -40,19 +38,19 @@ export class ValueCellComponent {
4038
value = computed(() =>
4139
getResourceValueByJsonPath(this.resource(), this.fieldDefinition()),
4240
);
41+
4342
uiSettings = computed(() => this.fieldDefinition().uiSettings);
4443
displayAs = computed(() => this.uiSettings()?.displayAs);
4544
withCopyButton = computed(() => this.uiSettings()?.withCopyButton);
45+
labelDisplay = computed(() =>
46+
this.normalizeLabelDisplay(this.uiSettings()?.labelDisplay),
47+
);
4648

47-
isLabelValue = computed(() => this.labelDisplayValue() !== undefined);
4849
isBoolLike = computed(() => this.boolValue() !== undefined);
4950
isUrlValue = computed(() => this.checkValidUrl(this.stringValue()));
5051

5152
boolValue = computed(() => this.normalizeBoolean(this.value()));
5253
stringValue = computed(() => this.normalizeString(this.value()));
53-
labelDisplayValue = computed(() =>
54-
this.normalizeLabelDisplay(this.uiSettings()?.labelDisplay),
55-
);
5654

5755
private normalizeBoolean(value: unknown): boolean | undefined {
5856
const normalizedValue = value?.toString()?.toLowerCase();

0 commit comments

Comments
 (0)