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: do not show flagsPerUser when calculation results to NaN #6639

Merged
merged 11 commits into from
Mar 21, 2024

Conversation

andreas-unleash
Copy link
Contributor

What it says on the tin

Closes # 1-2209

Copy link

vercel bot commented Mar 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 11:25am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Mar 21, 2024 11:25am

Copy link
Contributor

@thomasheartman thomasheartman left a comment

Choose a reason for hiding this comment

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

I'm a little unsure about the approach here. I'm not sure it's actually gonna fix the issue (refer to the inline comments).

Also, might be worth adding a test to check that it renders correctly when given the right/wrong data?

condition={
flagsPerUser !== undefined &&
flagsPerUser !== '' &&
flagsPerUser !== 'NaN'
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, are you saying that the value we store here the string "NaN"? Or is it the value NaN?

I would expect this comparison to be done using the Number.isNan function, but I don't know what the value we get from the API is in this case? If it is the string, then we should fix this on the API level, right?

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 value is coming from a calculation parsed to a string. So yes the value that gets here is 'NaN' and because of the other string comparisons here, I added it here for consistency

                        count={summary.total}
                        flagsPerUser={
                            showAllProjects
                                ? (summary.total / users.total).toFixed(2)
                                : ''
                        }
                    />```

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Code Health Quality Gates: OK

  • Declining Code Health: 0 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Lightweight sanity check
View detailed results in CodeScene

✅ Improving Code Health:

showAllProjects
? (summary.total / users.total).toFixed(2)
: ''
showAllProjects ? summary.flagsPerUser : ''

Choose a reason for hiding this comment

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

✅ Getting better: Large Method
Charts:VFC<IChartsProps> decreases from 138 to 136 lines of code, threshold = 120

Why does this problem occur?

Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function. Read more.

Signed-off-by: andreas-unleash <[email protected]>
Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Code Health Quality Gates: OK

  • Declining Code Health: 0 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Lightweight sanity check
View detailed results in CodeScene

✅ Improving Code Health:

Signed-off-by: andreas-unleash <[email protected]>
Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Code Health Quality Gates: OK

  • Declining Code Health: 0 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Lightweight sanity check
View detailed results in CodeScene

✅ Improving Code Health:

return {
...sum,
flagsPerUser:
Number.isNaN(flagsPerUser) || flagsPerUser === 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we using "N/A" if flags per user is 0? If there are 0 flags, then 0 flags per user is an entirely valid value, isn't it?

@@ -124,9 +125,7 @@ export const Charts: VFC<IChartsProps> = ({
<FlagStats
count={summary.total}
flagsPerUser={
showAllProjects
? (summary.total / users.total).toFixed(2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, this has taken me a while to realize, but this is what caused us to store the string 'NaN', right?

Couldn't we have gotten around all the other changes here by instead doing something like:

const averageFlagsPerUserCalculation = summary.total / users.total
const averageFlagsPerUser = averageFlagsPerUserCalculation.isNan() ? 'N/A' : averageFlagsPerUserCalculation.toFixed(2)

and then using that value as the prop instead?

That way, we don't need to update any other files, we don't need to touch the hook, and we don't need to touch any tests, etc.

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 think it makes more sense to move the calculation to the summary hook inline with the rest of the calculations.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure. You know the system better than I do, so I'll trust you on that.

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Code Health Quality Gates: OK

  • Declining Code Health: 0 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Lightweight sanity check
View detailed results in CodeScene

✅ Improving Code Health:

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Code Health Quality Gates: OK

  • Declining Code Health: 0 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Lightweight sanity check
View detailed results in CodeScene

✅ Improving Code Health:

Copy link
Contributor

@thomasheartman thomasheartman left a comment

Choose a reason for hiding this comment

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

Nice one! Thanks for working with me on all my comments 🙌🏼

@@ -124,9 +125,7 @@ export const Charts: VFC<IChartsProps> = ({
<FlagStats
count={summary.total}
flagsPerUser={
showAllProjects
? (summary.total / users.total).toFixed(2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Sure. You know the system better than I do, so I'll trust you on that.

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Code Health Quality Gates: OK

  • Declining Code Health: 0 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Lightweight sanity check
View detailed results in CodeScene

✅ Improving Code Health:

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Code Health Quality Gates: OK

  • Declining Code Health: 0 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Lightweight sanity check
View detailed results in CodeScene

✅ Improving Code Health:

Signed-off-by: andreas-unleash <[email protected]>
Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Code Health Quality Gates: OK

  • Declining Code Health: 0 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Lightweight sanity check
View detailed results in CodeScene

✅ Improving Code Health:

@andreas-unleash andreas-unleash merged commit bce25bf into main Mar 21, 2024
13 checks passed
@andreas-unleash andreas-unleash deleted the fix/flagstats_nan branch March 21, 2024 11:29
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.

2 participants