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

Add expandable section for image vulnerability components table #5218

Merged

Conversation

dvail
Copy link
Contributor

@dvail dvail commented Mar 13, 2023

Description

Adds the expandable section to image single page table rows. This section contains another table with details on all image components that are affected by this CVE.

Follow ups

  • Figure out why fixedIn and location fields always return empty strings (BE bug?)
  • Figure out why layerIndex is always null (BE bug?)
  • Reset the expanded/collapsed state on all rows when the table is sorted or paginated (depends on Add pagination and sorting to image single table #5258)

Checklist

  • Investigated and inspected CI test results
  • Unit test and regression tests added
  • Evaluated and added CHANGELOG entry if required
  • Determined and documented upgrade steps
  • Documented user facing changes (create PR based on openshift/openshift-docs and merge into rhacs-docs)

If any of these don't apply, please comment below.

Testing Performed

Load an image single page and see that expandable arrows are now present.
image

Expand a row by clicking on the expand arrow on the left side of the table.
image
Collapse the row by clicking the arrow again.
image

Verify that multiple rows can be expanded at the same time.
image

Verify that a row with multiple components contains the correct number of rows in the embedded table.
image

@openshift-ci
Copy link

openshift-ci bot commented Mar 13, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@dvail dvail force-pushed the dv/ROX-15056-add-table-workload-cve-images-single branch from 6b6392d to 318fa0c Compare March 13, 2023 15:36
@dvail dvail force-pushed the dv/ROX-15056-add-expandable-section-workload-cve-image-table branch from 25e78fc to 12b592e Compare March 13, 2023 15:36
@roxbot
Copy link
Contributor

roxbot commented Mar 13, 2023

Images are ready for the commit at 9f3f51b.

To use with deploy scripts, first export MAIN_IMAGE_TAG=3.74.x-411-g9f3f51b506.

@dvail dvail force-pushed the dv/ROX-15056-add-table-workload-cve-images-single branch from 318fa0c to e2e729f Compare March 13, 2023 16:44
@dvail dvail force-pushed the dv/ROX-15056-add-expandable-section-workload-cve-image-table branch from 12b592e to dc03751 Compare March 13, 2023 16:44
@dvail dvail force-pushed the dv/ROX-15056-add-table-workload-cve-images-single branch from e2e729f to 38a80a2 Compare March 13, 2023 16:49
@dvail dvail force-pushed the dv/ROX-15056-add-expandable-section-workload-cve-image-table branch 2 times, most recently from c86b935 to 4938269 Compare March 13, 2023 17:17
@dvail dvail force-pushed the dv/ROX-15056-add-table-workload-cve-images-single branch from 38a80a2 to 7771160 Compare March 13, 2023 19:57
@dvail dvail force-pushed the dv/ROX-15056-add-expandable-section-workload-cve-image-table branch from 4938269 to 7960f16 Compare March 13, 2023 19:58
@dvail dvail force-pushed the dv/ROX-15056-add-table-workload-cve-images-single branch 2 times, most recently from fc72d3a to 57fa3a3 Compare March 14, 2023 20:57
Base automatically changed from dv/ROX-15056-add-table-workload-cve-images-single to master March 15, 2023 12:28
@dvail dvail force-pushed the dv/ROX-15056-add-expandable-section-workload-cve-image-table branch 3 times, most recently from d181a49 to 524b1f6 Compare March 15, 2023 20:24
expect(result.current.has(objB)).toBeTruthy();
});

test('useSet should correctly toggle items and report their membership', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As straightforward as it looks, this test actually helped uncover a bug. The toggle function in useSet was relying on a closure value, which failed to update correctly when multiple toggle calls happened in a row. Using the alternate form of useState fixed the issue in the below diff:

     const [itemSet, setItemSet] = useState(initialSet);

     function toggle(key: T, isOn?: boolean) {
-        const nextSet = new Set(itemSet);
-        const shouldAdd = typeof isOn === 'undefined' ? !itemSet.has(key) : isOn;
-        if (shouldAdd) {
-            nextSet.add(key);
-        } else {
-            nextSet.delete(key);
-        }
-        setItemSet(nextSet);
+        setItemSet((prevSet) => {
+            const nextSet = new Set(prevSet);
+            const shouldAdd = typeof isOn === 'undefined' ? !itemSet.has(key) : isOn;
+            if (shouldAdd) {
+                nextSet.add(key);
+            } else {
+                nextSet.delete(key);
+            }
+            return nextSet;
+        });
     }

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, please share this at the next team meeting. Return on your investment to write tests!

@dvail dvail requested review from alwayshooin and a team March 15, 2023 20:25
@dvail dvail marked this pull request as ready for review March 15, 2023 20:25
Tbody,
Td,
ExpandableRowContent,
} from '@patternfly/react-table';
Copy link
Contributor

Choose a reason for hiding this comment

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

Prettier wrapping caused me to notice partial alphabetical order.

Do you mind to reorder here, and also in ImageComponentsTable above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aha, I've been pretty good about checking these and this one slipped by.

<Th>CVE</Th>
<Th>Severity</Th>
<Th>CVE Status</Th>
<Th>CVE status</Th>
Copy link
Contributor

Choose a reason for hiding this comment

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

Bravo!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All credit to @alwayshooin for pointing this one out.

) => {
const SeverityIcon: React.FC<SVGIconProps> | undefined =
SeverityIcons[severity];
const severityLabel: string | undefined = vulnerabilitySeverityLabels[severity];
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this is an answer to the question that I asked above about severity keys?

Copy link
Contributor Author

@dvail dvail Mar 17, 2023

Choose a reason for hiding this comment

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

I've been using the long form LOW_VULNERABILITY_SEVERITY as the canonical severity type since it is what is declared in our cve.proto.ts file and what is returned in the BE queries. The explicit undefined checks here are for a few reasons:

  1. The GraphQL API declares the return type of severity as string, even though from what I can tell in the code it will always be an enum type as declared in the proto. I'm not sure if there is a technical reason the API isn't declaring this as an enum as well, so I'm staying on the safe side assuming it is a string.
  2. We have "noImplicitAny": false set in our tsconfig, so indexing into the SeverityIcons here silently treats SeverityIcon as any.
  3. Even if the types were strictly declared, we could end up with an UNKNOWN_VULNERABILITY_SEVERITY here (RE: my comment on the other PR), which would be a type mismatch between the FE and BE declared types.
  4. Due to all of the above, even though indexing into SeverityIcons should be exhaustive and safe given a "Severity", there is a small chance we could end up with a React component that is undefined which would cause a runtime error here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for explaining. What you say makes sense.

To my original question, the newest query response adds a second convention for severity keys.

String union in frontend types corresponds to enum with string values in backend types.

It seems (to me) as if enum in TypeScript corresponded to other languages and, at least for strings, string union has superseded it.

Copy link
Contributor

@pedrottimark pedrottimark left a comment

Choose a reason for hiding this comment

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

The expandable table reminds me of your excellent solution to tree table in interview :)

A few comments, as usual.

@dvail dvail force-pushed the dv/ROX-15056-add-expandable-section-workload-cve-image-table branch from 524b1f6 to 9f3f51b Compare March 17, 2023 14:10
@dvail dvail enabled auto-merge (squash) March 17, 2023 14:10
@openshift-ci
Copy link

openshift-ci bot commented Mar 17, 2023

@dvail: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/gke-postgres-ui-e2e-tests 524b1f6 link false /test gke-postgres-ui-e2e-tests
ci/prow/gke-ui-e2e-tests 9f3f51b link false /test gke-ui-e2e-tests

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@dvail dvail merged commit 52a657e into master Mar 17, 2023
28 checks passed
@dvail dvail deleted the dv/ROX-15056-add-expandable-section-workload-cve-image-table branch March 17, 2023 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants