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

Node resource table and modals #3565

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dpanshug
Copy link
Contributor

@dpanshug dpanshug commented Dec 11, 2024

RHOAIENG-16256

Description

Added table and modal for Node resource for Hardware profile

image

image

image

Screenshot 2024-12-12 at 6 23 33 PM

How Has This Been Tested?

Currently this table and modal are standalone components and are not used anywhere, to tests you can import <ManageNodeResourceSection /> to any form page, like i have tested this in ManageAcceleratorProfile

Test Impact

Add unit tests for validation utility functions

Request review criteria:

Self checklist (all need to be checked):

  • The developer has manually tested the changes and verified that the changes work
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has added tests or explained why testing cannot be added (unit or cypress tests for related changes)

If you have UI changes:

  • Included any necessary screenshots or gifs if it was a UI change.
  • Included tags to the UX team if it was a UI/UX change.

After the PR is posted & before it merges:

  • The developer has tested their solution on a cluster by using the image produced by the PR to main

@vconzola

@dpanshug
Copy link
Contributor Author

dpanshug commented Dec 11, 2024

WIP: needs some clarification around UX and data validation
discussing here: https://redhat-internal.slack.com/archives/C07C0FNHVPT/p1733920395039179

Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 25.36232% with 103 lines in your changes missing coverage. Please review.

Project coverage is 85.03%. Comparing base (5d3efb2) to head (6580679).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...eProfiles/nodeResource/ManageNodeResourceModal.tsx 2.85% 34 Missing ⚠️
...s/hardwareProfiles/nodeResource/CountFormField.tsx 4.34% 22 Missing ⚠️
...hardwareProfiles/nodeResource/NodeResourceForm.tsx 4.54% 21 Missing ⚠️
...ardwareProfiles/nodeResource/NodeResourceTable.tsx 44.82% 16 Missing ⚠️
...ges/hardwareProfiles/ManageNodeResourceSection.tsx 0.00% 10 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3565      +/-   ##
==========================================
- Coverage   85.20%   85.03%   -0.18%     
==========================================
  Files        1381     1398      +17     
  Lines       31592    31881     +289     
  Branches     8832     8905      +73     
==========================================
+ Hits        26919    27109     +190     
- Misses       4673     4772      +99     
Files with missing lines Coverage Δ
...wareProfiles/nodeResource/NodeResourceTableRow.tsx 100.00% <100.00%> (ø)
...d/src/pages/hardwareProfiles/nodeResource/const.ts 100.00% <100.00%> (ø)
...d/src/pages/hardwareProfiles/nodeResource/utils.ts 100.00% <100.00%> (ø)
...ges/hardwareProfiles/ManageNodeResourceSection.tsx 0.00% <0.00%> (ø)
...ardwareProfiles/nodeResource/NodeResourceTable.tsx 44.82% <44.82%> (ø)
...hardwareProfiles/nodeResource/NodeResourceForm.tsx 4.54% <4.54%> (ø)
...s/hardwareProfiles/nodeResource/CountFormField.tsx 4.34% <4.34%> (ø)
...eProfiles/nodeResource/ManageNodeResourceModal.tsx 2.85% <2.85%> (ø)

... and 7 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 065da14...6580679. Read the comment docs.

Copy link
Contributor

openshift-ci bot commented Dec 12, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign manosnoam for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@dpanshug dpanshug changed the title [WIP] Node resource table and modals Node resource table and modals Dec 12, 2024
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress This PR is in WIP state label Dec 12, 2024
@dpanshug dpanshug force-pushed the node-table branch 2 times, most recently from 13a9f2d to 60d87b6 Compare December 12, 2024 12:47
@dpanshug
Copy link
Contributor Author

@kaedward @vconzola i have updated the mocks, please review the error message for field validation.

@dpanshug dpanshug force-pushed the node-table branch 2 times, most recently from fd5b060 to fd8a726 Compare December 12, 2024 13:02
frontend/src/types.ts Outdated Show resolved Hide resolved
@vconzola
Copy link

I believe there should be a space between the numbers and the units in the table, e.g., "1 GiB", not "1GiB", bur defer to @kaedward. Also, the units in the table should match the units in the dropdown, e.g., "GiB", not "Gi".

@Gkrumbach07
Copy link
Member

Could you also update the other table node table to now use your view only table

@DaoDaoNoCode
Copy link
Member

I think all the tables should use compact variant.

@dpanshug
Copy link
Contributor Author

I believe there should be a space between the numbers and the units in the table, e.g., "1 GiB", not "1GiB", bur defer to @kaedward. Also, the units in the table should match the units in the dropdown, e.g., "GiB", not "Gi".

@vconzola this formatting is consistent across the Dashboard, and you can see the same approach on the spawner page under cluster storage. Do you recommend we change it?

@vconzola
Copy link

@dpanshug Please keep the units and spacing consistent with what's in the dashboard today - don't change it. I thought I got it right everywhere in the mockups, but I guess not. Apologies for the confusion.

<Td dataLabel="Default">{identifier.defaultCount}</Td>
<Td dataLabel="Minimum allowed">{identifier.minCount}</Td>
<Td dataLabel="Maximum allowed">{identifier.maxCount}</Td>
{!showKebab && (
Copy link
Member

Choose a reason for hiding this comment

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

This should be showKebab && ...

const NodeResourceTable: React.FC<NodeResourceTableProps> = ({
nodeResources,
onUpdate,
viewOnly,
Copy link
Member

@DaoDaoNoCode DaoDaoNoCode Dec 18, 2024

Choose a reason for hiding this comment

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

Maybe considering change this to

const viewOnly = !onUpdate;

Because if it's not view only, it should always have an onUpdate function.

updatedIdentifiers.splice(rowIndex, 1);
onUpdate?.(updatedIdentifiers);
}}
showKebab={!!viewOnly}
Copy link
Member

Choose a reason for hiding this comment

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

Should be showKebab={!viewOnly} after you make the change in the NodeResourceTableRow

Comment on lines +72 to +73
label="Default"
fieldId="default"
Copy link
Member

Choose a reason for hiding this comment

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

These are maximum allowed.

setNodeResources: (identifiers: Identifier[]) => void;
};

export const ManageNodeResourceSection: React.FC<ManageNodeResourceSectionProps> = ({
Copy link
Member

Choose a reason for hiding this comment

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

This is a single file, maybe consider exporting it as default like other components?


return (
<Form>
<FormGroup label="Resource label" fieldId="resource-label">
Copy link
Member

Choose a reason for hiding this comment

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

Should add isRequired

/>
</FormGroup>

<FormGroup label="Resource identifier" fieldId="resource-identifier">
Copy link
Member

Choose a reason for hiding this comment

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

Should add isRequired

Comment on lines +31 to +33
if (existingIdentifier) {
return true;
}
Copy link
Member

Choose a reason for hiding this comment

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

Why are you not checking the identifier when editing? If I am editing a custom identifier, then it could be duplicated to another one, right? Try to create 2 identifiers, then edit one to change the identifier to the other and see if it throws the error.

Copy link
Member

Choose a reason for hiding this comment

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

In another word, this check only needs to be

const isUniqueIdentifier =
    identifier.identifier === existingIdentifier?.identifier ||
    !nodeResources.some((i) => i.identifier === identifier.identifier);

Comment on lines +44 to +45
existingIdentifier &&
(identifier.identifier === 'cpu' || identifier.identifier === 'memory')
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be just:

Suggested change
existingIdentifier &&
(identifier.identifier === 'cpu' || identifier.identifier === 'memory')
existingIdentifier?.identifier === 'cpu' || existingIdentifier?.identifier === 'memory'

<FormGroup label="Resource identifier" fieldId="resource-identifier">
<TextInput
value={identifier.identifier || ''}
onChange={(_, value) => setIdentifier('identifier', value)}
Copy link
Member

@DaoDaoNoCode DaoDaoNoCode Dec 18, 2024

Choose a reason for hiding this comment

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

This field should also be disabled if it's CPU or RAM based on what I saw in the mockups (Or probably disable it based on the identifier field, WDYT? @Gkrumbach07 )


return (
<Modal
title={existingIdentifier ? 'Edit resource' : 'Add resource'}
Copy link
Member

Choose a reason for hiding this comment

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

Should be Edit node resource and Add node resource here.


const [unitOptions, setUnitOptions] = React.useState<UnitOption[]>();

const isUniqueIdentifier = React.useMemo(() => {
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to use useMemo on a boolean IMO, it's always reference-stable.

}
}, [identifier]);

const isButtonDisabled = React.useMemo(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Same here, no need to use useMemo

Comment on lines +24 to +28
const [validated, setValidated] = React.useState<'default' | 'error' | 'success'>('default');

React.useEffect(() => {
setValidated(isUniqueIdentifier ? 'default' : 'error');
}, [isUniqueIdentifier]);
Copy link
Member

Choose a reason for hiding this comment

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

You don't need these at all:

Suggested change
const [validated, setValidated] = React.useState<'default' | 'error' | 'success'>('default');
React.useEffect(() => {
setValidated(isUniqueIdentifier ? 'default' : 'error');
}, [isUniqueIdentifier]);
const validated = isUniqueIdentifier ? 'default' : 'error';

existingIdentifier &&
(identifier.identifier === 'cpu' || identifier.identifier === 'memory')
}
validated={validated}
Copy link
Member

Choose a reason for hiding this comment

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

Missed error message here? Another resource with the same identifier already exists. The resource identifier must be unique.

const [isNodeResourceModalOpen, setIsNodeResourceModalOpen] = React.useState<boolean>(false);
return (
<>
<FormSection
Copy link
Member

@DaoDaoNoCode DaoDaoNoCode Dec 18, 2024

Choose a reason for hiding this comment

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

In the mockup, there is a description under this section title. Also, the button is a link style below the table but not next to the section title. However, the description is missed here in this PR and the button becomes the secondary button next to the title.

I am OK with changing the edit and delete icon to the kebab menu. However, I am not sure about the description and also the add button because it can affect how we show the empty state.

Can you check and help confirm that @vconzola?

Screenshot 2024-12-18 at 5 16 54 PM

Choose a reason for hiding this comment

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

Please implement as shown in the mockup including the description, the action icons in place of a kebab and the link button for Add resource. Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

@dpanshug Please refer to the implementation here

Copy link
Member

Choose a reason for hiding this comment

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

this is not the latest mocks. did you verify with the latest

Copy link
Member

Choose a reason for hiding this comment

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


return (
<>
<Table
Copy link
Member

Choose a reason for hiding this comment

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

You will need to use TableBase instead of Table here. Otherwise, It will automatically sort on the first column, which is Resource label even if we set sortable: false here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants