Fix jsonPath functions (#6530)

* Fix jsonPath functions
- Add handling of / shorthand
- Update tests to show new behaviour of safeJSONPathValue so that it is more usable

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Defend CRDResourceDetails against bad jsonPaths

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Update CRDResources for new behaviour of helper function

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Update snapshots

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-11-08 10:00:23 -05:00
1 parent 206988391a
commit 4cf16e1aee
5 files changed
+42 -40

No files matched your search

@@ -45,11 +45,7 @@ exports[`<CustomResourceDetails /> with a CRD with a boolean field should displa
<span
class="value"
>
<ul>
<li>
false
</li>
</ul>
false
</span>
</div>
</div>
@@ -101,11 +97,7 @@ exports[`<CustomResourceDetails /> with a CRD with a boolean field should displa
<span
class="value"
>
<ul>
<li>
true
</li>
</ul>
true
</span>
</div>
</div>
@@ -157,11 +149,7 @@ exports[`<CustomResourceDetails /> with a CRD with a number field should display
<span
class="value"
>
<ul>
<li>
0
</li>
</ul>
0
</span>
</div>
</div>
@@ -213,11 +201,7 @@ exports[`<CustomResourceDetails /> with a CRD with a number field should display
<span
class="value"
>
<ul>
<li>
1234
</li>
</ul>
1234
</span>
</div>
</div>
@@ -15,11 +15,10 @@ import { KubeObjectMeta } from "../kube-object-meta";
import { Input } from "../input";
import type { AdditionalPrinterColumnsV1 } from "../../../common/k8s-api/endpoints/custom-resource-definition.api";
import { CustomResourceDefinition } from "../../../common/k8s-api/endpoints/custom-resource-definition.api";
import { convertKubectlJsonPathToNodeJsonPath } from "../../utils/jsonPath";
import { safeJSONPathValue } from "../../utils/jsonPath";
import type { KubeObjectMetadata, KubeObjectStatus } from "../../../common/k8s-api/kube-object";
import { KubeObject } from "../../../common/k8s-api/kube-object";
import logger from "../../../common/logger";
import { JSONPath } from "@astronautlabs/jsonpath";
export interface CustomResourceDetailsProps extends KubeObjectDetailsProps<KubeObject> {
crd: CustomResourceDefinition;
@@ -66,7 +65,7 @@ export class CustomResourceDetails extends React.Component<CustomResourceDetails
renderAdditionalColumns(resource: KubeObject, columns: AdditionalPrinterColumnsV1[]) {
return columns.map(({ name, jsonPath }) => (
<DrawerItem key={name} name={name}>
{convertSpecValue(JSONPath.query(resource, convertKubectlJsonPathToNodeJsonPath(jsonPath)))}
{convertSpecValue(safeJSONPathValue(resource, jsonPath))}
</DrawerItem>
));
}
@@ -11,7 +11,7 @@ import { KubeObjectListLayout } from "../kube-object-list-layout";
import type { IComputedValue } from "mobx";
import { computed, makeObservable } from "mobx";
import type { ApiManager } from "../../../common/k8s-api/api-manager";
import { safeJSONPathValue } from "../../utils/jsonPath";
import { formatJSONValue, safeJSONPathValue } from "../../utils/jsonPath";
import { TabLayout } from "../layout/tab-layout-2";
import { withInjectables } from "@ogre-tools/injectable-react";
import customResourcesRouteParametersInjectable from "./custom-resources-route-parameters.injectable";
@@ -73,7 +73,7 @@ class NonInjectedCustomResources extends React.Component<Dependencies> {
[columnId.age]: customResource => -customResource.getCreationTimestamp(),
...Object.fromEntries(extraColumns.map(({ name, jsonPath }) => [
name,
customResource => safeJSONPathValue(customResource, jsonPath),
customResource => formatJSONValue(safeJSONPathValue(customResource, jsonPath)),
])),
}}
searchFilters={[