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
Cleanup OverviewItem removing unnecessary fields, retrieve data as necessary #7207
Cleanup OverviewItem removing unnecessary fields, retrieve data as necessary #7207
Conversation
5f7907c
to
462f3da
Compare
@@ -1,6 +1,7 @@ | |||
import * as React from 'react'; | |||
import { Button } from '@patternfly/react-core'; | |||
import { useExtensions, OverviewTabSection, LazyLoader } from '@console/plugin-sdk'; | |||
import { KnativeServiceOverviewItem } from '@console/knative-plugin/src/topology/topology-types'; |
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.
Can we do the test without knative dependency?
React.useEffect(() => { | ||
if (!loadError && loaded) { | ||
const updatedPods = podData.pods as PodKind[]; | ||
setPods(updatedPods); | ||
} | ||
}, [podData, loadError, loaded]); |
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.
This doesn't need to be done inside an effect. Instead derive in place or use useMemo
.
const donutStatus: PodRCData = React.useMemo(() => { | ||
if (!loadError && loaded) { | ||
return podData; | ||
} | ||
return null; | ||
}, [loadError, loaded, podData]); |
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.
You don't need useMemo
here because there isn't savings on efficiency:
const donutStatus: PodRCData = React.useMemo(() => { | |
if (!loadError && loaded) { | |
return podData; | |
} | |
return null; | |
}, [loadError, loaded, podData]); | |
const donutStatus: PodRCData = !loadError && loaded ? podData : null; |
const deploymentData = React.useMemo( | ||
() => podData?.current?.obj?.metadata?.ownerReferences?.[0], | ||
[podData], | ||
); |
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.
Why would we need useMemo
here instead of:
const deploymentData = React.useMemo( | |
() => podData?.current?.obj?.metadata?.ownerReferences?.[0], | |
[podData], | |
); | |
const deploymentData = podData?.current?.obj?.metadata?.ownerReferences?.[0]; |
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
const revisions = React.useMemo(() => [obj], [obj.metadata.uid]); |
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.
Whenever you disable any lint rules, please add a comment as to why.
This is a bit odd. If usePodsForRevisions
only needs the uid's of the revisions, the API should probably be changed.
const revisionIds = useDeepCompareMemoize( | ||
revisions?.map((r) => r.metadata.uid).sort((a, b) => a.localeCompare(b)), | ||
); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
const revisionResources = React.useMemo(() => [...revisions], [revisionIds]); |
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.
Same comment as before.
The issue is more noticeable now.
React.useEffect(() => { | ||
if (loaded) { | ||
const revisionsPods = []; | ||
pods.forEach((pod) => { | ||
if (pod.pods) { | ||
revisionsPods.push( | ||
...pod.pods.filter((p) => podPhase(p as PodKind) !== AllPodStatus.AutoScaledTo0), | ||
); | ||
} | ||
}); | ||
setServicePods(revisionsPods); | ||
} | ||
}, [loaded, pods]); |
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.
use useMemo
instead
React.useEffect(() => { | ||
if (loaded) { | ||
const [current, previous] = pods; | ||
const isRollingOut = !!current && !!previous; | ||
setDonutStatus({ | ||
obj: resource, | ||
current, | ||
previous, | ||
isRollingOut, | ||
pods: [...(current?.pods || []), ...(previous?.pods || [])], | ||
}); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [loaded, pods]); |
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.
use useMemo
instead
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
const revisions = React.useMemo(() => [resource], [resource.metadata.uid]); |
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.
Same comment as before.
@@ -951,7 +936,7 @@ export const transformKnNodeData = ( | |||
item, | |||
type, | |||
getImageForIconClass(`icon-openshift`), | |||
); | |||
) as any; |
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.
Why cast too any
?
357fc55
to
3ec42ab
Compare
@christianvogt updated per comments. Moved test data around a to remove some of the undesirable dependencies. |
if (loaded && !loadError) { | ||
return pods.reduce((acc, pod) => { | ||
if (pod.pods) { | ||
acc.push(...pod.pods.filter((p) => podPhase(p as PodKind) !== AUTOSCALED)); |
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.
acc.push(...pod.pods.filter((p) => podPhase(p as PodKind) !== AUTOSCALED)); | |
acc.push(...pod.pods.filter((p) => podPhase(p as PodKind) !== AllPodStatus.AutoScaledTo0)); |
fa10167
to
6a52b81
Compare
6a52b81
to
a8048a6
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: christianvogt, jeff-phillips-18 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
/test e2e-gcp-console |
/retest Please review the full test history for this PR and help us cut down flakes. |
1 similar comment
/retest Please review the full test history for this PR and help us cut down flakes. |
Fixes:
https://issues.redhat.com/browse/ODC-5088
Solution Description:
Remove pod information from OverviewItem. Create separate type for knative overview items. Cleanup resources fetched during topology load and fetch pod data when necessary.
Non-Functional Change
Browser conformance:
/kind cleanup