Skip to content

Commit 3512cbd

Browse files
**Enhance property field handling with transformations** (#115)
* **Enhance property field handling with transformations** - Added support for property field transformations in `FieldDefinition`, including `uppercase`, `lowercase`, `capitalize`, `encode`, and `decode`. - Updated utilities like `getResourceValueByJsonPath` to apply these transformations. - Enhanced documentation to reflect the new `propertyField` behavior. - Added unit tests to validate transformations and edge cases. - Updated dependencies in `package-lock.json` and `package.json`. * fix tests --------- Co-authored-by: Grzegorz Krajniak <[email protected]>
1 parent 033c1b6 commit 3512cbd

File tree

9 files changed

+497
-85
lines changed

9 files changed

+497
-85
lines changed

docs/readme-generic-ui.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ Each field definition supports the following properties:
5252

5353
- `"label"`: Display name for the field
5454
- `"property"`: JSON path to the resource property (string or array of strings for fallback values)
55+
- `"propertyField"`: In case the property is a scalar value that represents an object, this property can be used to specify the field to be used for display within that object
56+
- `"key"`: The name of the field to be used for display
57+
- `"transform"`: An array of text manipulations to be applied to the value, the available are:
58+
| 'uppercase'
59+
| 'lowercase'
60+
| 'capitalize'
61+
| 'decode'
62+
| 'encode'
5563
- `"jsonPathExpression"`: Alternative JSONPath expression for complex data access (takes precedence over `property`)
5664
- `"required"`: Boolean flag indicating if the field is mandatory (for create views)
5765
- `"values"`: Array of predefined values for selection
@@ -106,7 +114,7 @@ Below is an example content-configuration for an accounts node using the generic
106114
"namespace": null,
107115
"readyCondition": {
108116
"jsonPathExpression": "status.conditions[?(@.type=='Ready' && @.status=='True')]",
109-
"property": ["status.conditions.status", "status.conditions.type"],
117+
"property": ["status.conditions.status", "status.conditions.type"]
110118
},
111119
"ui": {
112120
"logoUrl": "https://www.kcp.io/icons/logo.svg",
@@ -120,6 +128,14 @@ Below is an example content-configuration for an accounts node using the generic
120128
"label": "Display Name",
121129
"property": "spec.displayName"
122130
},
131+
{
132+
"label": "Key",
133+
"property": "data",
134+
"propertyField": {
135+
"key": "OPENAI_API_KEY",
136+
"transform": ["uppercase", "encode"]
137+
}
138+
},
123139
{
124140
"label": "Type",
125141
"property": "spec.type",
@@ -213,7 +229,7 @@ Below is an example content-configuration for an accounts node using the generic
213229
"operation": "cities",
214230
"gqlQuery": "subscription { cities { data { id name } } }",
215231
"value": "data.id",
216-
"key": "data.name",
232+
"key": "data.name"
217233
}
218234
}
219235
]

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040
"@types/jmespath": "0.15.2",
4141
"@types/jsonpath": "0.2.4",
4242
"@ui5/webcomponents-ngx": "0.5.6",
43-
"kubernetes-types": "1.30.0",
4443
"cpx2": "8.0.0",
4544
"jest": "29.7.0",
4645
"jest-jasmine2": "29.7.0",
4746
"jest-junit": "16.0.0",
4847
"jest-mock-extended": "3.0.7",
4948
"jmespath": "0.16.0",
49+
"kubernetes-types": "1.30.0",
5050
"mkdirp": "3.0.1",
5151
"move-cli": "2.0.0",
5252
"ng-packagr": "20.3.0",

projects/lib/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
branches: 90,
1111
functions: 95,
1212
lines: 95,
13-
statements: -3,
13+
statements: -4,
1414
},
1515
},
1616
moduleNameMapper: {

projects/lib/models/models/resource.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Condition, ObjectMeta } from 'kubernetes-types/meta/v1';
22

3-
43
export interface LabelDisplay {
54
backgroundColor?: string;
65
color?: string;
@@ -10,9 +9,22 @@ export interface LabelDisplay {
109
textTransform?: string;
1110
}
1211

12+
export type TransformType =
13+
| 'uppercase'
14+
| 'lowercase'
15+
| 'capitalize'
16+
| 'decode'
17+
| 'encode';
18+
19+
export interface PropertyField {
20+
key: string;
21+
transform?: TransformType[];
22+
}
23+
1324
export interface FieldDefinition {
1425
label?: string;
1526
property: string | string[];
27+
propertyField?: PropertyField;
1628
jsonPathExpression?: string;
1729
required?: boolean;
1830
values?: string[];
@@ -56,6 +68,7 @@ export interface Resource extends Record<string, any> {
5668
status?: ResourceStatus;
5769
__typename?: string;
5870
ready?: boolean;
71+
data?: Record<string, any>;
5972
}
6073

6174
export interface ResourceDefinition {
@@ -83,4 +96,4 @@ export interface UIDefinition {
8396
detailView?: UiView;
8497
}
8598

86-
export type KubernetesScope = 'Cluster' | 'Namespaced';
99+
export type KubernetesScope = 'Cluster' | 'Namespaced';

projects/lib/utils/utils/get-value-by-path.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ export const getValueByPath = <T extends object, R = unknown>(
77
): R | undefined => {
88
return getResourceValueByJsonPath(obj as Resource, {
99
jsonPathExpression: path,
10-
property: '',
1110
});
1211
};

0 commit comments

Comments
 (0)