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

fix(FR-386): add max value for User/Project setting modal #3050

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nowgnuesLee
Copy link
Contributor

@nowgnuesLee nowgnuesLee commented Jan 20, 2025

resolves #3055 (FR-386)

  • Set the max value for each time in the setting modal on the Resource Policypage
  • Display error messages using usePainkilerr

changes

  • add error handling on onCompleted
  • add const values MAX_CPU_QUOTA, SIGNED_32BIT_MAX_INT
  • In the case of MAX_CPU_QUOTA, since the CPU type is a float, we limited the range to 1e16 after consulting with @fregataa.

Checklist: (if applicable)

  • Documentation
  • Minium required manager version
  • Specific setting for review (eg., KB link, endpoint or how to setup)
  • Minimum requirements to check during review
  • Test case(s) to demonstrate the difference of before/after

Copy link

graphite-app bot commented Jan 20, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • flow:merge-queue - adds this PR to the back of the merge queue
  • flow:hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has required the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@github-actions github-actions bot added the size:L 100~500 LoC label Jan 20, 2025
@nowgnuesLee nowgnuesLee changed the title fix: add max value for User/Project setting modal fix(FR-386): add max value for User/Project setting modal Jan 20, 2025
Copy link

github-actions bot commented Jan 20, 2025

Coverage report for ./react

St.
Category Percentage Covered / Total
🔴 Statements
4.95% (+0.03% 🔼)
400/8077
🔴 Branches
4.25% (+0.01% 🔼)
239/5621
🔴 Functions
2.95% (+0% 🔼)
78/2640
🔴 Lines
4.87% (+0.04% 🔼)
385/7902

Test suite run success

124 tests passing in 14 suites.

Report generated by 🧪jest coverage report action from a7b2451

@nowgnuesLee nowgnuesLee marked this pull request as ready for review January 21, 2025 02:06
Comment on lines 226 to 228
message.error(
painKiller.relieve(res.create_keypair_resource_policy.msg),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Basically, I think we've been talking about returning a massage that shows the graphql error message directly to the user, so we don't need to include the message handling logic in painkiller.

I looked through the history, but I didn't find anything, so please check this again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with that. That’s why I plan to use a painkiller only when the error message might be undefined, as I think it’s strange not to show any message for an error. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. For the future, I think fixing the error message is the right way to go. For now, It would be better to output a specific phrase via i18n when the error message is undefined, rather than via painkiller.

Teams

react/src/components/KeypairResourcePolicySettingModal.tsx Outdated Show resolved Hide resolved
Comment on lines +337 to +344
{_.chain(resourceSlots)
.keys()
.chunk(2)
.map((resourceSlotKeys, index) => (
<Row gutter={[16, 16]} key={index}>
{_.map(resourceSlotKeys, (resourceSlotKey) => (
<Col
span={12}
key={resourceSlotKey}
style={{ alignSelf: 'end', marginBottom: token.marginLG }}
>
<FormItemWithUnlimited
unlimitedValue={undefined}
label={
_.get(mergedResourceSlots, resourceSlotKey)
?.description || resourceSlotKey
}
name={['parsedTotalResourceSlots', resourceSlotKey]}
rules={[
{
validator(__, value) {
if (
_.includes(resourceSlotKey, 'mem') &&
value &&
// @ts-ignore
convertBinarySizeUnit(value, 'p').number >
{_.chain(resourceSlotKeys)
.map((resourceSlotKey) => (
<Col
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The structure of HOF (Higher-Order Functions) often requires reading the code from right to left, which I believe negatively impacts readability. (And honestly, I switched to the chaining approach because I found the code difficult to read.)

Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion, that code doesn't use lodash methods enough to use chains, so the addition of chains actually makes it less readable. The second chain only uses the map method, so there's no need to use them too.

react/src/components/KeypairResourcePolicySettingModal.tsx Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L 100~500 LoC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need to add rule for max value in User/Project Resource Policy setting modal
2 participants