-
Notifications
You must be signed in to change notification settings - Fork 748
OCPBUGS-85013: Fix Topology page TypeError when resource is null #17071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,15 +11,15 @@ import { getResource } from './topology-utils'; | |
| export const withEditReviewAccess: WithEditReviewAccess = (verb) => (WrappedComponent) => { | ||
| const Component: FC<WithEditReviewAccessComponentProps> = (props) => { | ||
| const resourceObj = getResource(props.element); | ||
| const resourceModel = modelFor(referenceFor(resourceObj)); | ||
| const resourceModel = resourceObj ? modelFor(referenceFor(resourceObj)) : undefined; | ||
| const editAccess = useAccessReview({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great observation — fixed in 7e9ae24. When |
||
| group: resourceModel.apiGroup, | ||
| group: resourceModel?.apiGroup, | ||
| verb, | ||
| resource: resourceModel.plural, | ||
| name: resourceObj.metadata.name, | ||
| namespace: resourceObj.metadata.namespace, | ||
| resource: resourceModel?.plural, | ||
| name: resourceObj?.metadata?.name, | ||
| namespace: resourceObj?.metadata?.namespace, | ||
| }); | ||
| return <WrappedComponent {...(props as any)} canEdit={editAccess} />; | ||
| return <WrappedComponent {...(props as any)} canEdit={resourceObj ? editAccess : false} />; | ||
| }; | ||
| Component.displayName = `withEditReviewAccess(${ | ||
| WrappedComponent.displayName || WrappedComponent.name | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resourceis of typeK8sResourceKindbut it's potentiallynullThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right about the type gap. The
GetTopologyResourceObjectSDK type declares the return asK8sResourceKind, but the implementation can returnnull. Since updating the SDK type would be a breaking API change, we handle nullability at each call site with optional chaining (resource?.kind,resource?.metadata?.namespace). TheusePodsWatcherhook also uses optional chaining internally, so null is handled gracefully at runtime — it skips watching when kind is undefined.