-
Notifications
You must be signed in to change notification settings - Fork 176
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: sort promotions with running and pending first #1314
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Timestamp } from '@bufbuild/protobuf'; | ||
import { expect, test, describe } from 'vitest'; | ||
|
||
import { ObjectMeta } from '@ui/gen/metav1/types_pb'; | ||
import { Promotion, PromotionStatus } from '@ui/gen/v1alpha1/types_pb'; | ||
|
||
import { sortPromotions } from './utils/sort'; | ||
|
||
const newTestPromotion = (phase: string, seconds: number): Promotion => { | ||
return { | ||
metadata: { | ||
creationTimestamp: new Timestamp({ | ||
seconds: BigInt(seconds) | ||
}) | ||
} as ObjectMeta, | ||
status: { | ||
phase | ||
} as PromotionStatus | ||
} as Promotion; | ||
}; | ||
|
||
const running1 = newTestPromotion('Running', 1); | ||
const pending2 = newTestPromotion('Pending', 2); | ||
const running3 = newTestPromotion('Running', 3); | ||
const pending4 = newTestPromotion('Pending', 4); | ||
const succeeded5 = newTestPromotion('Succeeded', 5); | ||
const failed6 = newTestPromotion('Failed', 6); | ||
const unknown7 = newTestPromotion('Unknown', 7); | ||
const running8 = newTestPromotion('Running', 8); | ||
const pending9 = newTestPromotion('Pending', 9); | ||
const running10 = newTestPromotion('Running', 10); | ||
const pending11 = newTestPromotion('Pending', 11); | ||
const succeeded12 = newTestPromotion('Succeeded', 12); | ||
const errored13 = newTestPromotion('Errored', 13); | ||
const unknown14 = newTestPromotion('Unknown', 14); | ||
|
||
const testPromotions = [ | ||
running1, | ||
pending2, | ||
running3, | ||
pending4, | ||
succeeded5, | ||
failed6, | ||
unknown7, | ||
running8, | ||
pending9, | ||
running10, | ||
pending11, | ||
succeeded12, | ||
errored13, | ||
unknown14 | ||
]; | ||
|
||
const orderedPromotions = [ | ||
running10, | ||
running8, | ||
running3, | ||
running1, | ||
pending11, | ||
pending9, | ||
pending4, | ||
pending2, | ||
unknown14, | ||
errored13, | ||
succeeded12, | ||
unknown7, | ||
failed6, | ||
succeeded5 | ||
]; | ||
|
||
describe('sortPromotions', () => { | ||
test('sorts promotions', () => { | ||
expect(testPromotions.sort(sortPromotions)).toEqual(orderedPromotions); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ import { | |
faCircleCheck, | ||
faCircleExclamation, | ||
faCircleNotch, | ||
faCircleQuestion, | ||
faHourglassStart | ||
} from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
|
@@ -20,6 +19,8 @@ import { KargoService } from '@ui/gen/service/v1alpha1/service_connect'; | |
import { ListPromotionsResponse } from '@ui/gen/service/v1alpha1/service_pb'; | ||
import { Promotion } from '@ui/gen/v1alpha1/types_pb'; | ||
|
||
import { sortPromotions } from './utils/sort'; | ||
|
||
export const Promotions = () => { | ||
const client = useQueryClient(); | ||
const { name: projectName, stageName } = useParams(); | ||
|
@@ -76,16 +77,10 @@ export const Promotions = () => { | |
return () => cancel.abort(); | ||
}, [isLoading]); | ||
|
||
const promotions = React.useMemo( | ||
() => | ||
// Immutable sorting | ||
[...(promotionsResponse?.promotions || [])].sort( | ||
(a, b) => | ||
Number(b.metadata?.creationTimestamp?.seconds || 0) - | ||
Number(a.metadata?.creationTimestamp?.seconds || 0) | ||
), | ||
[promotionsResponse] | ||
); | ||
const promotions = React.useMemo(() => { | ||
// Immutable sorting | ||
return [...(promotionsResponse?.promotions || [])].sort(sortPromotions); | ||
}, [promotionsResponse]); | ||
|
||
const columns: ColumnsType<Promotion> = [ | ||
{ | ||
|
@@ -95,7 +90,11 @@ export const Promotions = () => { | |
switch (promotion.status?.phase) { | ||
case 'Succeeded': | ||
return ( | ||
<Popover content={promotion.status?.message} title={promotion.status?.phase} placement='right'> | ||
<Popover | ||
content={promotion.status?.message} | ||
title={promotion.status?.phase} | ||
placement='right' | ||
> | ||
Comment on lines
+93
to
+97
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. Nothing changed here, just ran Prettier |
||
<FontAwesomeIcon | ||
color={theme.defaultSeed.colorSuccess} | ||
icon={faCircleCheck} | ||
|
@@ -106,7 +105,11 @@ export const Promotions = () => { | |
case 'Failed': | ||
case 'Errored': | ||
return ( | ||
<Popover content={promotion.status?.message} title={promotion.status?.phase} placement='right'> | ||
<Popover | ||
content={promotion.status?.message} | ||
title={promotion.status?.phase} | ||
placement='right' | ||
> | ||
Comment on lines
+108
to
+112
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. Same here, Prettier fix |
||
<FontAwesomeIcon | ||
color={theme.defaultSeed.colorError} | ||
icon={faCircleExclamation} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Promotion } from '@ui/gen/v1alpha1/types_pb'; | ||
|
||
export const sortPromotions = (a: Promotion, b: Promotion) => { | ||
const timestampDiff = | ||
Number(b.metadata?.creationTimestamp?.seconds || 0) - | ||
Number(a.metadata?.creationTimestamp?.seconds || 0); | ||
|
||
const aIsRunning = a.status?.phase === 'Running'; | ||
const bIsRunning = b.status?.phase === 'Running'; | ||
const aIsPending = a.status?.phase === 'Pending'; | ||
const bIsPending = b.status?.phase === 'Pending'; | ||
|
||
if (aIsRunning || bIsRunning) { | ||
if (aIsRunning && bIsRunning) { | ||
return timestampDiff; | ||
} | ||
return aIsRunning ? -1 : 1; | ||
} | ||
|
||
if (aIsPending || bIsPending) { | ||
if (aIsPending && bIsPending) { | ||
return timestampDiff; | ||
} | ||
return aIsPending ? -1 : 1; | ||
} | ||
|
||
return timestampDiff; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running promotions come first, sorted by timestamp. Then pending promotions, also sorted by timestamp, and finally everything else sorted by timestamp.