@openmfp/webcomponents 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/.github/workflows/pipeline.yaml +41 -0
  2. package/.storybook/main.ts +34 -0
  3. package/.storybook/preview.ts +29 -0
  4. package/.storybook/tsconfig.json +11 -0
  5. package/AGENTS.md +153 -0
  6. package/CODEOWNERS +6 -0
  7. package/CONTRIBUTING.md +95 -0
  8. package/LICENSE +201 -0
  9. package/LICENSES/Apache-2.0.txt +73 -0
  10. package/README.md +91 -0
  11. package/REUSE.toml +9 -0
  12. package/angular.json +157 -0
  13. package/docs/dashboard.md +358 -0
  14. package/docs/declarative-form.md +178 -0
  15. package/docs/declarative-table-card.md +235 -0
  16. package/docs/declarative-table.md +315 -0
  17. package/eslint.config.js +41 -0
  18. package/package.json +73 -0
  19. package/projects/ngx/cards/favorites/favorites.component.html +12 -0
  20. package/projects/ngx/cards/favorites/favorites.component.scss +50 -0
  21. package/projects/ngx/cards/favorites/favorites.component.ts +19 -0
  22. package/projects/ngx/cards/public-api.ts +4 -0
  23. package/projects/ngx/cards/service-status/service-status-card.component.html +15 -0
  24. package/projects/ngx/cards/service-status/service-status-card.component.scss +87 -0
  25. package/projects/ngx/cards/service-status/service-status-card.component.ts +36 -0
  26. package/projects/ngx/cards/stories/visited-service-card.stories.ts +149 -0
  27. package/projects/ngx/cards/visited-service-card/visited-service-card.component.html +17 -0
  28. package/projects/ngx/cards/visited-service-card/visited-service-card.component.scss +34 -0
  29. package/projects/ngx/cards/visited-service-card/visited-service-card.component.ts +22 -0
  30. package/projects/ngx/cards/whats-new/whats-new.component.html +10 -0
  31. package/projects/ngx/cards/whats-new/whats-new.component.scss +25 -0
  32. package/projects/ngx/cards/whats-new/whats-new.component.ts +46 -0
  33. package/projects/ngx/declarative-ui/dashboard/add-card-dialog/add-card-dialog.component.html +28 -0
  34. package/projects/ngx/declarative-ui/dashboard/add-card-dialog/add-card-dialog.component.scss +44 -0
  35. package/projects/ngx/declarative-ui/dashboard/add-card-dialog/add-card-dialog.component.spec.ts +85 -0
  36. package/projects/ngx/declarative-ui/dashboard/add-card-dialog/add-card-dialog.component.ts +58 -0
  37. package/projects/ngx/declarative-ui/dashboard/card/dashboard-card.component.html +29 -0
  38. package/projects/ngx/declarative-ui/dashboard/card/dashboard-card.component.scss +63 -0
  39. package/projects/ngx/declarative-ui/dashboard/card/dashboard-card.component.spec.ts +255 -0
  40. package/projects/ngx/declarative-ui/dashboard/card/dashboard-card.component.ts +75 -0
  41. package/projects/ngx/declarative-ui/dashboard/card/utils/dashboard-card-registry.spec.ts +76 -0
  42. package/projects/ngx/declarative-ui/dashboard/card/utils/dashboard-card-registry.ts +109 -0
  43. package/projects/ngx/declarative-ui/dashboard/card/utils/index.ts +4 -0
  44. package/projects/ngx/declarative-ui/dashboard/card/utils/mount-angular-card.spec.ts +141 -0
  45. package/projects/ngx/declarative-ui/dashboard/card/utils/mount-angular-card.ts +44 -0
  46. package/projects/ngx/declarative-ui/dashboard/card/utils/mount-sap-card.spec.ts +142 -0
  47. package/projects/ngx/declarative-ui/dashboard/card/utils/mount-sap-card.ts +52 -0
  48. package/projects/ngx/declarative-ui/dashboard/card/utils/mount-wc-card.spec.ts +107 -0
  49. package/projects/ngx/declarative-ui/dashboard/card/utils/mount-wc-card.ts +22 -0
  50. package/projects/ngx/declarative-ui/dashboard/dashboard/dashboard.component.html +134 -0
  51. package/projects/ngx/declarative-ui/dashboard/dashboard/dashboard.component.scss +88 -0
  52. package/projects/ngx/declarative-ui/dashboard/dashboard/dashboard.component.spec.ts +354 -0
  53. package/projects/ngx/declarative-ui/dashboard/dashboard/dashboard.component.ts +238 -0
  54. package/projects/ngx/declarative-ui/dashboard/dashboard/index.ts +1 -0
  55. package/projects/ngx/declarative-ui/dashboard/index.ts +5 -0
  56. package/projects/ngx/declarative-ui/dashboard/models/constants.ts +2 -0
  57. package/projects/ngx/declarative-ui/dashboard/models/dashboard.model.ts +50 -0
  58. package/projects/ngx/declarative-ui/dashboard/models/index.ts +1 -0
  59. package/projects/ngx/declarative-ui/dashboard/section/dashboard-section.component.html +28 -0
  60. package/projects/ngx/declarative-ui/dashboard/section/dashboard-section.component.scss +85 -0
  61. package/projects/ngx/declarative-ui/dashboard/section/dashboard-section.component.spec.ts +104 -0
  62. package/projects/ngx/declarative-ui/dashboard/section/dashboard-section.component.ts +23 -0
  63. package/projects/ngx/declarative-ui/form/declarative-form/declarative-form.component.html +62 -0
  64. package/projects/ngx/declarative-ui/form/declarative-form/declarative-form.component.scss +12 -0
  65. package/projects/ngx/declarative-ui/form/declarative-form/declarative-form.component.spec.ts +301 -0
  66. package/projects/ngx/declarative-ui/form/declarative-form/declarative-form.component.ts +166 -0
  67. package/projects/ngx/declarative-ui/form/declarative-form/index.ts +1 -0
  68. package/projects/ngx/declarative-ui/form/index.ts +2 -0
  69. package/projects/ngx/declarative-ui/form/models/form-field-definition.ts +15 -0
  70. package/projects/ngx/declarative-ui/form/models/index.ts +1 -0
  71. package/projects/ngx/declarative-ui/form/utils/set-property-by-path.ts +30 -0
  72. package/projects/ngx/declarative-ui/models/index.ts +2 -0
  73. package/projects/ngx/declarative-ui/models/resource.ts +5 -0
  74. package/projects/ngx/declarative-ui/models/ui-definition.ts +95 -0
  75. package/projects/ngx/declarative-ui/public-api.ts +4 -0
  76. package/projects/ngx/declarative-ui/stories/add-card-dialog.stories.ts +91 -0
  77. package/projects/ngx/declarative-ui/stories/background-lightblue.png +0 -0
  78. package/projects/ngx/declarative-ui/stories/dashboard.cards.ts +107 -0
  79. package/projects/ngx/declarative-ui/stories/dashboard.stories.ts +296 -0
  80. package/projects/ngx/declarative-ui/stories/declarative-form.stories.ts +149 -0
  81. package/projects/ngx/declarative-ui/stories/declarative-table-card.stories.ts +358 -0
  82. package/projects/ngx/declarative-ui/stories/declarative-table.stories.ts +363 -0
  83. package/projects/ngx/declarative-ui/stories/pods-table.config.ts +188 -0
  84. package/projects/ngx/declarative-ui/table/declarative-table/declarative-table.component.html +138 -0
  85. package/projects/ngx/declarative-ui/table/declarative-table/declarative-table.component.scss +21 -0
  86. package/projects/ngx/declarative-ui/table/declarative-table/declarative-table.component.spec.ts +345 -0
  87. package/projects/ngx/declarative-ui/table/declarative-table/declarative-table.component.ts +61 -0
  88. package/projects/ngx/declarative-ui/table/declarative-table/index.ts +1 -0
  89. package/projects/ngx/declarative-ui/table/index.ts +2 -0
  90. package/projects/ngx/declarative-ui/table/models/index.ts +14 -0
  91. package/projects/ngx/declarative-ui/table/models/table.model.ts +17 -0
  92. package/projects/ngx/declarative-ui/table/utils/cssRules.engine.spec.ts +146 -0
  93. package/projects/ngx/declarative-ui/table/utils/cssRules.engine.ts +69 -0
  94. package/projects/ngx/declarative-ui/table/utils/field-definition.utils.spec.ts +70 -0
  95. package/projects/ngx/declarative-ui/table/utils/field-definition.utils.ts +13 -0
  96. package/projects/ngx/declarative-ui/table/utils/proccess-fields.spec.ts +511 -0
  97. package/projects/ngx/declarative-ui/table/utils/proccess-fields.ts +71 -0
  98. package/projects/ngx/declarative-ui/table/utils/resource-field-by-path.spec.ts +372 -0
  99. package/projects/ngx/declarative-ui/table/utils/resource-field-by-path.ts +98 -0
  100. package/projects/ngx/declarative-ui/table/value-cell/boolean-value/boolean-cell.constants.ts +5 -0
  101. package/projects/ngx/declarative-ui/table/value-cell/boolean-value/boolean-value.component.html +1 -0
  102. package/projects/ngx/declarative-ui/table/value-cell/boolean-value/boolean-value.component.scss +0 -0
  103. package/projects/ngx/declarative-ui/table/value-cell/boolean-value/boolean-value.component.spec.ts +119 -0
  104. package/projects/ngx/declarative-ui/table/value-cell/boolean-value/boolean-value.component.ts +35 -0
  105. package/projects/ngx/declarative-ui/table/value-cell/link-value/link-value.component.html +7 -0
  106. package/projects/ngx/declarative-ui/table/value-cell/link-value/link-value.component.scss +0 -0
  107. package/projects/ngx/declarative-ui/table/value-cell/link-value/link-value.component.spec.ts +114 -0
  108. package/projects/ngx/declarative-ui/table/value-cell/link-value/link-value.component.ts +19 -0
  109. package/projects/ngx/declarative-ui/table/value-cell/secret-value/secret-value.component.html +7 -0
  110. package/projects/ngx/declarative-ui/table/value-cell/secret-value/secret-value.component.scss +10 -0
  111. package/projects/ngx/declarative-ui/table/value-cell/secret-value/secret-value.component.spec.ts +188 -0
  112. package/projects/ngx/declarative-ui/table/value-cell/secret-value/secret-value.component.ts +16 -0
  113. package/projects/ngx/declarative-ui/table/value-cell/value-cell.component.html +59 -0
  114. package/projects/ngx/declarative-ui/table/value-cell/value-cell.component.scss +33 -0
  115. package/projects/ngx/declarative-ui/table/value-cell/value-cell.component.spec.ts +316 -0
  116. package/projects/ngx/declarative-ui/table/value-cell/value-cell.component.ts +115 -0
  117. package/projects/ngx/declarative-ui/table-card/declarative-table-card.component.html +156 -0
  118. package/projects/ngx/declarative-ui/table-card/declarative-table-card.component.scss +123 -0
  119. package/projects/ngx/declarative-ui/table-card/declarative-table-card.component.spec.ts +786 -0
  120. package/projects/ngx/declarative-ui/table-card/declarative-table-card.component.ts +286 -0
  121. package/projects/ngx/declarative-ui/table-card/index.ts +2 -0
  122. package/projects/ngx/declarative-ui/table-card/models/configs.ts +46 -0
  123. package/projects/ngx/declarative-ui/tsconfig.lib.json +11 -0
  124. package/projects/ngx/declarative-ui/tsconfig.lib.prod.json +9 -0
  125. package/projects/ngx/declarative-ui/tsconfig.spec.json +9 -0
  126. package/projects/ngx/ng-package.json +8 -0
  127. package/projects/ngx/package.json +22 -0
  128. package/projects/ngx/public-api.ts +2 -0
  129. package/projects/ngx/tsconfig.lib.json +11 -0
  130. package/projects/ngx/tsconfig.lib.prod.json +9 -0
  131. package/projects/webcomponents/main.ts +92 -0
  132. package/projects/webcomponents/tsconfig.app.json +9 -0
  133. package/projects/webcomponents-dashboard/main.ts +15 -0
  134. package/projects/webcomponents-dashboard/tsconfig.app.json +9 -0
  135. package/renovate.json +6 -0
  136. package/scripts/bundle-wc.mjs +79 -0
  137. package/tsconfig.json +37 -0
  138. package/tsconfig.spec.json +8 -0
  139. package/tsconfig.storybook.json +16 -0
  140. package/vitest.config.ts +26 -0
@@ -0,0 +1,316 @@
1
+ import {
2
+ FieldDefinition,
3
+ GenericResource,
4
+ ValueCellButtonClickEvent,
5
+ } from '../../models';
6
+ import { ValueCell } from './value-cell.component';
7
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
8
+
9
+ type Fixture = ComponentFixture<ValueCell<GenericResource, FieldDefinition>>;
10
+ type Comp = ValueCell<GenericResource, FieldDefinition>;
11
+
12
+ function setup(
13
+ field: FieldDefinition,
14
+ resource?: Partial<GenericResource>,
15
+ ): { fixture: Fixture; component: Comp } {
16
+ const fixture: Fixture = TestBed.createComponent(
17
+ ValueCell as unknown as typeof ValueCell<GenericResource, FieldDefinition>,
18
+ );
19
+ const component = fixture.componentInstance;
20
+ fixture.componentRef.setInput('fieldDefinition', field);
21
+ if (resource !== undefined)
22
+ fixture.componentRef.setInput('resource', resource as GenericResource);
23
+ fixture.detectChanges();
24
+ return { fixture, component };
25
+ }
26
+
27
+ function el(fixture: Fixture, testId: string): Element | null {
28
+ return (
29
+ fixture.nativeElement.shadowRoot ?? fixture.nativeElement
30
+ ).querySelector(`[test-id="${testId}"]`);
31
+ }
32
+
33
+ function q(fixture: Fixture, selector: string): Element | null {
34
+ return (
35
+ fixture.nativeElement.shadowRoot ?? fixture.nativeElement
36
+ ).querySelector(selector);
37
+ }
38
+
39
+ describe('ValueCell', () => {
40
+ beforeEach(async () => {
41
+ await TestBed.configureTestingModule({
42
+ imports: [ValueCell],
43
+ }).compileComponents();
44
+ });
45
+
46
+ describe('testId', () => {
47
+ it('is derived from fieldDefinition.property', () => {
48
+ const { component } = setup({ property: 'name' });
49
+ expect(component.testId()).toBe('value-cell-name');
50
+ });
51
+ });
52
+
53
+ describe('default display', () => {
54
+ it('renders plain string value from resource property', () => {
55
+ const { fixture } = setup({ property: 'status' }, { status: 'Active' });
56
+ const span = q(fixture, '[test-id="value-cell-status"]');
57
+ expect(span?.textContent?.trim()).toBe('Active');
58
+ });
59
+
60
+ it('falls back to field.value when no resource is provided', () => {
61
+ const { fixture } = setup({ property: 'status', value: 'fallback' });
62
+ const span = q(fixture, '[test-id="value-cell-status"]');
63
+ expect(span?.textContent?.trim()).toBe('fallback');
64
+ });
65
+
66
+ it('renders empty when value is absent', () => {
67
+ const { fixture } = setup({ property: 'missing' }, {});
68
+ const span = q(fixture, '[test-id="value-cell-missing"]');
69
+ expect(span?.textContent?.trim()).toBe('');
70
+ });
71
+ });
72
+
73
+ describe('computed signals', () => {
74
+ it('value() resolves from resource property', () => {
75
+ const { component } = setup({ property: 'age' }, { age: 42 });
76
+ expect(component.value()).toBe(42);
77
+ });
78
+
79
+ it('boolValue() is true for string "true"', () => {
80
+ const { component } = setup({ property: 'active' }, { active: 'true' });
81
+ expect(component.boolValue()).toBe(true);
82
+ });
83
+
84
+ it('boolValue() is false for string "false"', () => {
85
+ const { component } = setup({ property: 'active' }, { active: 'false' });
86
+ expect(component.boolValue()).toBe(false);
87
+ });
88
+
89
+ it('boolValue() is undefined for non-boolean string', () => {
90
+ const { component } = setup({ property: 'status' }, { status: 'Active' });
91
+ expect(component.boolValue()).toBeUndefined();
92
+ });
93
+
94
+ it('isBoolLike() is true when boolValue is defined', () => {
95
+ const { component } = setup({ property: 'active' }, { active: 'true' });
96
+ expect(component.isBoolLike()).toBe(true);
97
+ });
98
+
99
+ it('isBoolLike() is false for non-boolean value', () => {
100
+ const { component } = setup(
101
+ { property: 'status' },
102
+ { status: 'running' },
103
+ );
104
+ expect(component.isBoolLike()).toBe(false);
105
+ });
106
+
107
+ it('stringValue() returns string value', () => {
108
+ const { component } = setup({ property: 'label' }, { label: 'hello' });
109
+ expect(component.stringValue()).toBe('hello');
110
+ });
111
+
112
+ it('stringValue() returns undefined for non-string value', () => {
113
+ const { component } = setup({ property: 'count' }, { count: 99 });
114
+ expect(component.stringValue()).toBeUndefined();
115
+ });
116
+
117
+ it('stringValue() returns undefined for blank string', () => {
118
+ const { component } = setup({ property: 'label' }, { label: ' ' });
119
+ expect(component.stringValue()).toBeUndefined();
120
+ });
121
+
122
+ it('isUrlValue() is true for valid http URL', () => {
123
+ const { component } = setup(
124
+ { property: 'link' },
125
+ { link: 'https://example.com' },
126
+ );
127
+ expect(component.isUrlValue()).toBe(true);
128
+ });
129
+
130
+ it('isUrlValue() is false for plain string', () => {
131
+ const { component } = setup({ property: 'link' }, { link: 'not-a-url' });
132
+ expect(component.isUrlValue()).toBe(false);
133
+ });
134
+ });
135
+
136
+ describe('displayAs: secret', () => {
137
+ it('renders secret-value component', () => {
138
+ const { fixture } = setup(
139
+ { property: 'token', uiSettings: { displayAs: 'secret' } },
140
+ { token: 'abc123' },
141
+ );
142
+ expect(el(fixture, 'value-cell-token-secret')).not.toBeNull();
143
+ });
144
+
145
+ it('renders toggle icon', () => {
146
+ const { fixture } = setup(
147
+ { property: 'token', uiSettings: { displayAs: 'secret' } },
148
+ { token: 'abc123' },
149
+ );
150
+ expect(el(fixture, 'value-cell-token-secret-toggle')).not.toBeNull();
151
+ });
152
+
153
+ it('toggleVisibility flips isVisible', () => {
154
+ const { component } = setup(
155
+ { property: 'token', uiSettings: { displayAs: 'secret' } },
156
+ { token: 'abc123' },
157
+ );
158
+ expect(component.isVisible()).toBe(false);
159
+ component.toggleVisibility(new MouseEvent('click'));
160
+ expect(component.isVisible()).toBe(true);
161
+ component.toggleVisibility(new MouseEvent('click'));
162
+ expect(component.isVisible()).toBe(false);
163
+ });
164
+ });
165
+
166
+ describe('displayAs: boolIcon', () => {
167
+ it('renders boolean-value when value is boolean-like', () => {
168
+ const { fixture } = setup(
169
+ { property: 'enabled', uiSettings: { displayAs: 'boolIcon' } },
170
+ { enabled: 'true' },
171
+ );
172
+ expect(el(fixture, 'value-cell-enabled-boolean')).not.toBeNull();
173
+ });
174
+
175
+ it('does not render boolean-value when value is not boolean-like', () => {
176
+ const { fixture } = setup(
177
+ { property: 'status', uiSettings: { displayAs: 'boolIcon' } },
178
+ { status: 'running' },
179
+ );
180
+ expect(el(fixture, 'value-cell-status-boolean')).toBeNull();
181
+ });
182
+ });
183
+
184
+ describe('displayAs: link', () => {
185
+ it('renders link-value for valid URL', () => {
186
+ const { fixture } = setup(
187
+ { property: 'url', uiSettings: { displayAs: 'link' } },
188
+ { url: 'https://example.com' },
189
+ );
190
+ expect(el(fixture, 'value-cell-url-link')).not.toBeNull();
191
+ });
192
+
193
+ it('does not render link-value for non-URL string', () => {
194
+ const { fixture } = setup(
195
+ { property: 'url', uiSettings: { displayAs: 'link' } },
196
+ { url: 'not-a-url' },
197
+ );
198
+ expect(el(fixture, 'value-cell-url-link')).toBeNull();
199
+ });
200
+ });
201
+
202
+ describe('displayAs: tooltip', () => {
203
+ it('renders tooltip icon', () => {
204
+ const { fixture } = setup(
205
+ { property: 'info', uiSettings: { displayAs: 'tooltip' } },
206
+ { info: 'some tooltip text' },
207
+ );
208
+ expect(el(fixture, 'value-cell-info-tooltip')).not.toBeNull();
209
+ });
210
+ });
211
+
212
+ describe('displayAs: alert', () => {
213
+ it('renders alert icon when value is falsy', () => {
214
+ const { fixture } = setup(
215
+ { property: 'flag', uiSettings: { displayAs: 'alert' } },
216
+ { flag: '' },
217
+ );
218
+ expect(el(fixture, 'value-cell-flag-icon')).not.toBeNull();
219
+ });
220
+
221
+ it('does not render alert icon when value is truthy', () => {
222
+ const { fixture } = setup(
223
+ { property: 'flag', uiSettings: { displayAs: 'alert' } },
224
+ { flag: 'ok' },
225
+ );
226
+ expect(el(fixture, 'value-cell-flag-icon')).toBeNull();
227
+ });
228
+ });
229
+
230
+ describe('displayAs: img', () => {
231
+ it('renders img element when value is set', () => {
232
+ const { fixture } = setup(
233
+ { property: 'avatar', uiSettings: { displayAs: 'img' } },
234
+ { avatar: 'https://example.com/img.png' },
235
+ );
236
+ const img = q(fixture, 'img.image-cell');
237
+ expect(img).not.toBeNull();
238
+ expect(img?.getAttribute('src')).toBe('https://example.com/img.png');
239
+ });
240
+
241
+ it('does not render img when value is absent', () => {
242
+ const { fixture } = setup(
243
+ { property: 'avatar', uiSettings: { displayAs: 'img' } },
244
+ {},
245
+ );
246
+ expect(q(fixture, 'img.image-cell')).toBeNull();
247
+ });
248
+ });
249
+
250
+ describe('withCopyButton', () => {
251
+ it('renders copy icon when withCopyButton is true', () => {
252
+ const { fixture } = setup(
253
+ { property: 'token', uiSettings: { withCopyButton: true } },
254
+ { token: 'secret' },
255
+ );
256
+ expect(el(fixture, 'value-cell-token-copy')).not.toBeNull();
257
+ });
258
+
259
+ it('does not render copy icon when withCopyButton is false', () => {
260
+ const { fixture } = setup(
261
+ { property: 'token', uiSettings: { withCopyButton: false } },
262
+ { token: 'secret' },
263
+ );
264
+ expect(el(fixture, 'value-cell-token-copy')).toBeNull();
265
+ });
266
+ });
267
+
268
+ describe('cssStyles', () => {
269
+ it('merges cssCustomization and cssRules', () => {
270
+ const { component } = setup(
271
+ {
272
+ property: 'status',
273
+ uiSettings: {
274
+ cssCustomization: { color: 'red' },
275
+ cssRules: [
276
+ {
277
+ if: { condition: 'equals', value: 'Active' },
278
+ styles: { fontWeight: 'bold' },
279
+ },
280
+ ],
281
+ },
282
+ },
283
+ { status: 'Active' },
284
+ );
285
+ expect(component.cssStyles()).toEqual({
286
+ color: 'red',
287
+ fontWeight: 'bold',
288
+ });
289
+ });
290
+ });
291
+
292
+ describe('buttonClick output', () => {
293
+ it('emits buttonClick with field and resource on buttonClicked', () => {
294
+ const field: FieldDefinition = {
295
+ property: 'action',
296
+ uiSettings: {
297
+ displayAs: 'button',
298
+ buttonSettings: { text: 'Go', action: 'navigate' },
299
+ },
300
+ };
301
+ const resource = { action: 'go' };
302
+ const { fixture, component } = setup(field, resource);
303
+
304
+ const emitted: ValueCellButtonClickEvent<GenericResource>[] = [];
305
+ component.buttonClick.subscribe((e) => emitted.push(e));
306
+
307
+ const btn = q(fixture, 'ui5-button');
308
+ btn?.dispatchEvent(new MouseEvent('click', { bubbles: true }));
309
+ fixture.detectChanges();
310
+
311
+ expect(emitted).toHaveLength(1);
312
+ expect(emitted[0].field).toEqual(field);
313
+ expect(emitted[0].resource).toEqual(resource);
314
+ });
315
+ });
316
+ });
@@ -0,0 +1,115 @@
1
+ import {
2
+ FieldDefinition,
3
+ GenericResource,
4
+ ValueCellButtonClickEvent,
5
+ } from '../../models';
6
+ import { evaluateCssRules } from '../utils/cssRules.engine';
7
+ import { getFieldValue } from '../utils/field-definition.utils';
8
+ import { BooleanValue } from './boolean-value/boolean-value.component';
9
+ import { LinkValue } from './link-value/link-value.component';
10
+ import { SecretValue } from './secret-value/secret-value.component';
11
+ import {
12
+ CUSTOM_ELEMENTS_SCHEMA,
13
+ ChangeDetectionStrategy,
14
+ Component,
15
+ ViewEncapsulation,
16
+ computed,
17
+ input,
18
+ output,
19
+ signal,
20
+ } from '@angular/core';
21
+ import { Button } from '@fundamental-ngx/ui5-webcomponents/button';
22
+ import { Icon } from '@fundamental-ngx/ui5-webcomponents/icon';
23
+ import '@ui5/webcomponents-icons/dist/AllIcons.js';
24
+
25
+ @Component({
26
+ selector: 'mfp-value-cell',
27
+ imports: [Icon, BooleanValue, LinkValue, SecretValue, Button],
28
+ templateUrl: './value-cell.component.html',
29
+ styleUrl: './value-cell.component.scss',
30
+ changeDetection: ChangeDetectionStrategy.OnPush,
31
+ encapsulation: ViewEncapsulation.ShadowDom,
32
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
33
+ })
34
+ export class ValueCell<T extends GenericResource, F extends FieldDefinition> {
35
+ fieldDefinition = input.required<F>();
36
+ resource = input<T>();
37
+ readonly buttonClick = output<ValueCellButtonClickEvent<T>>();
38
+
39
+ value = computed(() =>
40
+ getFieldValue(this.fieldDefinition(), this.resource()),
41
+ );
42
+
43
+ uiSettings = computed(() => this.fieldDefinition().uiSettings);
44
+ displayAs = computed(() => this.uiSettings()?.displayAs);
45
+ withCopyButton = computed(() => this.uiSettings()?.withCopyButton);
46
+ labelDisplay = computed(() => this.uiSettings()?.labelDisplay);
47
+ cssCustomization = computed(() => this.uiSettings()?.cssCustomization);
48
+ tooltipIcon = computed(() => this.uiSettings()?.tooltipIcon);
49
+ cssRules = computed(() =>
50
+ evaluateCssRules(this.value(), this.uiSettings()?.cssRules),
51
+ );
52
+ cssStyles = computed(() => ({
53
+ ...this.cssCustomization(),
54
+ ...this.cssRules(),
55
+ }));
56
+
57
+ isBoolLike = computed(() => this.boolValue() !== undefined);
58
+ isUrlValue = computed(() => this.checkValidUrl(this.stringValue()));
59
+ testId = computed(() => `value-cell-${this.fieldDefinition().property}`);
60
+
61
+ boolValue = computed(() => this.normalizeBoolean(this.value()));
62
+ stringValue = computed(() => this.normalizeString(this.value()));
63
+ isVisible = signal(false);
64
+
65
+ toggleVisibility(e: Event): void {
66
+ e.stopPropagation();
67
+ this.isVisible.set(!this.isVisible());
68
+ }
69
+
70
+ private normalizeBoolean(value: unknown): boolean | undefined {
71
+ const normalizedValue = value?.toString()?.toLowerCase();
72
+ if (normalizedValue === 'true') {
73
+ return true;
74
+ }
75
+ if (normalizedValue === 'false') {
76
+ return false;
77
+ }
78
+ return undefined;
79
+ }
80
+
81
+ private normalizeString(value: unknown): string | undefined {
82
+ if (typeof value !== 'string' || !value.trim()) {
83
+ return undefined;
84
+ }
85
+
86
+ return value;
87
+ }
88
+
89
+ private checkValidUrl(value: string | undefined): boolean {
90
+ if (!value) {
91
+ return false;
92
+ }
93
+
94
+ try {
95
+ new URL(value);
96
+ return true;
97
+ } catch {
98
+ return false;
99
+ }
100
+ }
101
+
102
+ public copyValue(event: Event) {
103
+ event.stopPropagation();
104
+ navigator.clipboard.writeText(this.value() || '');
105
+ }
106
+
107
+ protected buttonClicked(event: MouseEvent) {
108
+ event.stopPropagation();
109
+ this.buttonClick.emit({
110
+ event,
111
+ field: this.fieldDefinition(),
112
+ resource: this.resource(),
113
+ });
114
+ }
115
+ }
@@ -0,0 +1,156 @@
1
+ <div class="card">
2
+ <div class="card__header">
3
+ <div class="card__title">
4
+ @if (header(); as header) {
5
+ {{ header }}
6
+ @if (headerTooltip(); as tooltip) {
7
+ <ui5-icon
8
+ class="card__info-icon"
9
+ name="hint"
10
+ [showTooltip]="true"
11
+ [accessibleName]="tooltip"
12
+ />
13
+ }
14
+ }
15
+ </div>
16
+ <div class="card__actions">
17
+ @if (config().resourcesSearchable) {
18
+ @if (searchExpanded()) {
19
+ <ui5-input
20
+ #searchInput
21
+ [class]="
22
+ 'card__search-input card__search-input--' +
23
+ (searchCollapsing() ? 'leave' : 'enter')
24
+ "
25
+ [formControl]="searchControl"
26
+ (blur)="onSearchBlur()"
27
+ (animationend)="onSearchAnimationEnd()"
28
+ />
29
+ }
30
+ <ui5-button
31
+ class="card__search-btn"
32
+ design="Transparent"
33
+ [icon]="searchButtonConfig()?.icon ?? 'search'"
34
+ [tooltip]="searchButtonConfig()?.tooltip ?? 'Search'"
35
+ (click)="toggleSearch()"
36
+ />
37
+ }
38
+ @if (createFormConfig()) {
39
+ <ui5-button
40
+ class="card__create-btn"
41
+ [icon]="createButtonConfig()?.icon ?? 'add'"
42
+ [design]="createButtonConfig()?.design ?? 'Transparent'"
43
+ [tooltip]="createButtonConfig()?.tooltip"
44
+ (click)="createDialogOpen.set(true)"
45
+ >
46
+ {{ createButtonConfig()?.text ?? '' }}
47
+ </ui5-button>
48
+ }
49
+ </div>
50
+ </div>
51
+
52
+ <div class="card__body">
53
+ @if (tableConfig(); as config) {
54
+ <mfp-declarative-table
55
+ [columns]="effectiveColumns()"
56
+ [resources]="resources()"
57
+ [totalItemsCount]="config.totalItemsCount"
58
+ [paginationLimit]="config.paginationLimit ?? 5"
59
+ [hasMore]="config.hasMore ?? false"
60
+ (buttonClick)="onButtonClick($event)"
61
+ (tableRowClicked)="tableRowClicked.emit($event)"
62
+ (loadMoreResources)="loadMoreResources.emit()"
63
+ (paginationLimitChanged)="paginationLimitChanged.emit($event)"
64
+ />
65
+ }
66
+ </div>
67
+ </div>
68
+
69
+ @if (createFormConfig(); as config) {
70
+ <ui5-dialog
71
+ [open]="createDialogOpen()"
72
+ (ui5BeforeClose)="createDialogOpen.set(false)"
73
+ >
74
+ <div slot="header" class="dialog__header">
75
+ <ui5-title level="H5">{{ config.title ?? 'Create' }}</ui5-title>
76
+ </div>
77
+ <div class="dialog__body">
78
+ <mfp-declarative-form
79
+ #createForm
80
+ [fields]="config.fields"
81
+ [fieldErrors]="createFormState().fieldErrors ?? {}"
82
+ (fieldChange)="onCreateFieldChange($event)"
83
+ (formSubmit)="onCreateSubmit($event)"
84
+ />
85
+ </div>
86
+ <div slot="footer" class="dialog__footer">
87
+ <ui5-button
88
+ design="Emphasized"
89
+ [disabled]="hasErrors(createFormState())"
90
+ (click)="createForm.submit()"
91
+ >
92
+ {{ config.confirmLabel ?? 'Save' }}
93
+ </ui5-button>
94
+ <ui5-button design="Transparent" (click)="closeCreateDialog()">
95
+ {{ config.cancelLabel ?? 'Cancel' }}
96
+ </ui5-button>
97
+ </div>
98
+ </ui5-dialog>
99
+ }
100
+
101
+ @if (editFormConfig(); as config) {
102
+ <ui5-dialog
103
+ [open]="editDialogOpen()"
104
+ (ui5BeforeClose)="editDialogOpen.set(false)"
105
+ >
106
+ <div slot="header" class="dialog__header">
107
+ <ui5-title level="H5">{{ config.title ?? 'Edit' }}</ui5-title>
108
+ </div>
109
+ <div class="dialog__body">
110
+ <mfp-declarative-form
111
+ #editForm
112
+ [fields]="config.fields"
113
+ [initialValues]="editInitialValue()"
114
+ [fieldErrors]="editFormState().fieldErrors ?? {}"
115
+ (fieldChange)="onEditFieldChange($event)"
116
+ (formSubmit)="onEditSubmit($event)"
117
+ />
118
+ </div>
119
+ <div slot="footer" class="dialog__footer">
120
+ <ui5-button
121
+ design="Emphasized"
122
+ [disabled]="hasErrors(editFormState())"
123
+ (click)="editForm.submit()"
124
+ >
125
+ {{ config.confirmLabel ?? 'Edit' }}
126
+ </ui5-button>
127
+ <ui5-button design="Transparent" (click)="closeEditDialog()">
128
+ {{ config.cancelLabel ?? 'Cancel' }}
129
+ </ui5-button>
130
+ </div>
131
+ </ui5-dialog>
132
+ }
133
+
134
+ @if (deleteConfirmationConfig(); as config) {
135
+ <ui5-dialog
136
+ [open]="deleteDialogOpen()"
137
+ (ui5BeforeClose)="deleteDialogOpen.set(false)"
138
+ >
139
+ <div slot="header" class="dialog__header">
140
+ <ui5-title level="H5">{{ config.title ?? 'Confirm Delete' }}</ui5-title>
141
+ </div>
142
+ @if (config.message) {
143
+ <div class="dialog__body">
144
+ <p class="dialog__message">{{ config.message }}</p>
145
+ </div>
146
+ }
147
+ <div slot="footer" class="dialog__footer">
148
+ <ui5-button design="Negative" (click)="onDeleteSubmit()">
149
+ {{ config.confirmLabel ?? 'Delete' }}
150
+ </ui5-button>
151
+ <ui5-button design="Transparent" (click)="closeDeleteDialog()">
152
+ {{ config.cancelLabel ?? 'Cancel' }}
153
+ </ui5-button>
154
+ </div>
155
+ </ui5-dialog>
156
+ }
@@ -0,0 +1,123 @@
1
+ :host {
2
+ display: block;
3
+ }
4
+
5
+ @keyframes slide-in {
6
+ from {
7
+ opacity: 0;
8
+ transform: scaleX(0);
9
+ }
10
+ to {
11
+ opacity: 1;
12
+ transform: scaleX(1);
13
+ }
14
+ }
15
+
16
+ @keyframes slide-out {
17
+ from {
18
+ opacity: 1;
19
+ transform: scaleX(1);
20
+ }
21
+ to {
22
+ opacity: 0;
23
+ transform: scaleX(0);
24
+ }
25
+ }
26
+
27
+ .card {
28
+ display: flex;
29
+ flex-direction: column;
30
+ border: 1px solid var(--sapGroup_ContentBorderColor, #d9d9d9);
31
+ border-radius: 16px;
32
+ background: var(--sapGroup_TitleBackground, #fff);
33
+
34
+ &__header {
35
+ display: flex;
36
+ align-items: center;
37
+ justify-content: space-between;
38
+ min-height: 3rem;
39
+ padding: 0 1rem;
40
+ border-bottom: 1px solid var(--sapGroup_ContentBorderColor, #d9d9d9);
41
+ }
42
+
43
+ &__title {
44
+ color: var(--sapTile_TitleTextColor);
45
+ text-overflow: ellipsis;
46
+ font-family: var(--Font-Family-sapFontFamily, 72);
47
+ font-size: var(--Font-Size-sapFontHeader6Size, 16px);
48
+ font-style: normal;
49
+ font-weight: 700;
50
+ line-height: normal;
51
+ display: flex;
52
+ align-items: center;
53
+ }
54
+
55
+ &__actions {
56
+ display: flex;
57
+ align-items: center;
58
+ gap: 0.5rem;
59
+ }
60
+
61
+ &__info-icon {
62
+ color: var(--sapButton_IconColor, #0070f2);
63
+ margin-left: 0.5rem;
64
+ }
65
+
66
+ &__search-input {
67
+ transform-origin: right center;
68
+
69
+ &--enter {
70
+ animation: slide-in 0.2s ease-out both;
71
+ }
72
+
73
+ &--leave {
74
+ animation: slide-out 0.2s ease-in both;
75
+ }
76
+ }
77
+
78
+ &__create-btn {
79
+ min-width: auto;
80
+ color: var(--sapButton_IconColor, #0070f2);
81
+ }
82
+
83
+ &__search-btn {
84
+ min-width: auto;
85
+ color: var(--sapButton_IconColor, #0070f2);
86
+ }
87
+
88
+ &__body {
89
+ flex: 1;
90
+ overflow: auto;
91
+ }
92
+ }
93
+
94
+ .dialog {
95
+ &__header {
96
+ display: flex;
97
+ align-items: flex-start;
98
+ padding: 0.75rem 1rem;
99
+ }
100
+
101
+ &__body {
102
+ margin: -1rem;
103
+ min-width: 320px;
104
+ padding: 1rem;
105
+ }
106
+
107
+ &__message {
108
+ padding: 1rem;
109
+ margin: 0;
110
+ font-size: 0.875rem;
111
+ max-width: 320px;
112
+ }
113
+
114
+ &__footer {
115
+ display: flex;
116
+ justify-content: space-between;
117
+ align-items: center;
118
+ gap: 0.5rem;
119
+ padding: 0.5rem 1rem;
120
+ margin: 0 -1rem;
121
+ width: 100%;
122
+ }
123
+ }