-
-
Notifications
You must be signed in to change notification settings - Fork 269
refactor: nested ternary operators into independent statements #2532
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
623b972
7e3e84f
d7919b8
946f8b4
ad0edeb
6d4e998
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { faCircleCheck, faClock, faUserGear } from '@fortawesome/free-solid-svg-icons' | ||
|
|
||
| import { getMilestoneProgressIcon, getMilestoneProgressText } from 'utils/milestoneProgress' | ||
|
|
||
| describe('milestone progress helpers', () => { | ||
| describe('getMilestoneProgressText', () => { | ||
| test('returns "Completed" when progress is 100', () => { | ||
| expect(getMilestoneProgressText(100)).toBe('Completed') | ||
| }) | ||
|
|
||
| test('returns "In Progress" when progress is between 1 and 99', () => { | ||
| expect(getMilestoneProgressText(50)).toBe('In Progress') | ||
| }) | ||
|
|
||
| test('returns "Not Started" when progress is 0', () => { | ||
| expect(getMilestoneProgressText(0)).toBe('Not Started') | ||
| }) | ||
| }) | ||
|
|
||
| describe('getMilestoneProgressIcon', () => { | ||
| test('returns faCircleCheck when progress is 100', () => { | ||
| expect(getMilestoneProgressIcon(100)).toBe(faCircleCheck) | ||
| }) | ||
|
|
||
| test('returns faUserGear when progress is between 1 and 99', () => { | ||
| expect(getMilestoneProgressIcon(50)).toBe(faUserGear) | ||
| }) | ||
|
|
||
| test('returns faClock when progress is 0', () => { | ||
| expect(getMilestoneProgressIcon(0)).toBe(faClock) | ||
| }) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -73,6 +73,17 @@ const DetailsCard = ({ | |||||||||||||||||||||||||||||||||||||
| }: DetailsCardProps) => { | ||||||||||||||||||||||||||||||||||||||
| const { data } = useSession() | ||||||||||||||||||||||||||||||||||||||
| const router = useRouter() | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const secondaryCardStyles = (() => { | ||||||||||||||||||||||||||||||||||||||
| if (type === 'program' || type === 'module') { | ||||||||||||||||||||||||||||||||||||||
| return 'gap-2 md:col-span-7' | ||||||||||||||||||||||||||||||||||||||
| } else if (type !== 'chapter') { | ||||||||||||||||||||||||||||||||||||||
| return 'gap-2 md:col-span-5' | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| return 'gap-2 md:col-span-3' | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| })() | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
78
to
85
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not introduce negated conditions. This is also one of the issues we happen to have quite a few of in SonarQube and something that makes the code less readable.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kasya I'have updated the code as you have suggested. The issue you are talking about is the one which is failing CI/CD ? |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||
| <div className="min-h-screen bg-white p-8 text-gray-600 dark:bg-[#212529] dark:text-gray-300"> | ||||||||||||||||||||||||||||||||||||||
| <div className="mx-auto max-w-6xl"> | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -122,13 +133,7 @@ const DetailsCard = ({ | |||||||||||||||||||||||||||||||||||||
| <SecondaryCard | ||||||||||||||||||||||||||||||||||||||
| icon={faRectangleList} | ||||||||||||||||||||||||||||||||||||||
| title={<AnchorTitle title={`${upperFirst(type)} Details`} />} | ||||||||||||||||||||||||||||||||||||||
| className={ | ||||||||||||||||||||||||||||||||||||||
| type === 'program' || type === 'module' | ||||||||||||||||||||||||||||||||||||||
| ? 'gap-2 md:col-span-7' | ||||||||||||||||||||||||||||||||||||||
| : type !== 'chapter' | ||||||||||||||||||||||||||||||||||||||
| ? 'gap-2 md:col-span-5' | ||||||||||||||||||||||||||||||||||||||
| : 'gap-2 md:col-span-3' | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| className={secondaryCardStyles} | ||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||
| {details?.map((detail) => | ||||||||||||||||||||||||||||||||||||||
| detail?.label === 'Leaders' ? ( | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { faCircleCheck, faClock, faUserGear } from '@fortawesome/free-solid-svg-icons' | ||
|
|
||
| export const getMilestoneProgressText = (progress: number): string => { | ||
| if (progress === 100) { | ||
| return 'Completed' | ||
| } else if (progress > 0) { | ||
| return 'In Progress' | ||
| } else { | ||
| return 'Not Started' | ||
| } | ||
| } | ||
|
|
||
| export const getMilestoneProgressIcon = (progress: number) => { | ||
| if (progress === 100) { | ||
| return faCircleCheck | ||
| } else if (progress > 0) { | ||
| return faUserGear | ||
| } else { | ||
| return faClock | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.