Skip to content
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

Merged

Conversation

jeff-phillips-18
Copy link
Member

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:

  • Chrome
  • Firefox
  • Safari
  • Edge

/kind cleanup

@openshift-ci-robot openshift-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. component/core Related to console core functionality labels Nov 13, 2020
@openshift-ci-robot openshift-ci-robot added component/dev-console Related to dev-console component/knative Related to knative-plugin component/kubevirt Related to kubevirt-plugin component/shared Related to console-shared labels Nov 13, 2020
@@ -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';
Copy link
Contributor

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?

Comment on lines 21 to 26
React.useEffect(() => {
if (!loadError && loaded) {
const updatedPods = podData.pods as PodKind[];
setPods(updatedPods);
}
}, [podData, loadError, loaded]);
Copy link
Contributor

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.

Comment on lines 159 to 164
const donutStatus: PodRCData = React.useMemo(() => {
if (!loadError && loaded) {
return podData;
}
return null;
}, [loadError, loaded, podData]);
Copy link
Contributor

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:

Suggested change
const donutStatus: PodRCData = React.useMemo(() => {
if (!loadError && loaded) {
return podData;
}
return null;
}, [loadError, loaded, podData]);
const donutStatus: PodRCData = !loadError && loaded ? podData : null;

Comment on lines 41 to 44
const deploymentData = React.useMemo(
() => podData?.current?.obj?.metadata?.ownerReferences?.[0],
[podData],
);
Copy link
Contributor

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:

Suggested change
const deploymentData = React.useMemo(
() => podData?.current?.obj?.metadata?.ownerReferences?.[0],
[podData],
);
const deploymentData = podData?.current?.obj?.metadata?.ownerReferences?.[0];

Comment on lines 13 to 14
// eslint-disable-next-line react-hooks/exhaustive-deps
const revisions = React.useMemo(() => [obj], [obj.metadata.uid]);
Copy link
Contributor

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.

Comment on lines 40 to 44
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]);
Copy link
Contributor

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.

Comment on lines 47 to 59
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]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use useMemo instead

Comment on lines 31 to 44
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]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use useMemo instead

Comment on lines 28 to 29
// eslint-disable-next-line react-hooks/exhaustive-deps
const revisions = React.useMemo(() => [resource], [resource.metadata.uid]);
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why cast too any ?

@jeff-phillips-18
Copy link
Member Author

@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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
acc.push(...pod.pods.filter((p) => podPhase(p as PodKind) !== AUTOSCALED));
acc.push(...pod.pods.filter((p) => podPhase(p as PodKind) !== AllPodStatus.AutoScaledTo0));

@christianvogt
Copy link
Contributor

lost the deployment and donut on revisions:
image

before:
image

@jeff-phillips-18 jeff-phillips-18 force-pushed the overview-item branch 2 times, most recently from fa10167 to 6a52b81 Compare November 17, 2020 18:28
@christianvogt
Copy link
Contributor

/lgtm
/approve

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 17, 2020
@openshift-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 17, 2020
@jeff-phillips-18
Copy link
Member Author

/retest

@jeff-phillips-18
Copy link
Member Author

/test e2e-gcp-console

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

1 similar comment
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit d70027e into openshift:master Nov 18, 2020
@spadgett spadgett added this to the v4.7 milestone Nov 30, 2020
@jeff-phillips-18 jeff-phillips-18 deleted the overview-item branch December 2, 2020 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. component/core Related to console core functionality component/dev-console Related to dev-console component/knative Related to knative-plugin component/kubevirt Related to kubevirt-plugin component/shared Related to console-shared kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants