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
feat: sort proposals #5675
Merged
Merged
feat: sort proposals #5675
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e27118d
chore: move filter to general module
MarkNerdi996 078474f
enhancement: add dropdown enums + translation
MarkNerdi996 2f0205d
feat: filter proposals
MarkNerdi996 641b19e
enhancement: add proposal type filter
MarkNerdi996 84d1f52
enhancement: add participated filter
MarkNerdi996 ac68773
fix: fix tests
MarkNerdi996 18cca41
chore: create combined filter type
MarkNerdi996 7646403
Merge commit '5843caacbdbd321ee11fddea351bba730d9563df' into feat/fil…
MarkNerdi996 d8b68f4
feat/ add proposal order to filter
MarkNerdi996 9b15052
Merge branch 'develop' into feat/filter-proposals
Tuditi 81a0f8b
enhancement: add translations for proposal order
MarkNerdi996 9d3deda
enhancement: add labelkey to filter item
MarkNerdi996 9fcd56a
Merge commit '9d3dedab1de4c88b25abfa8ebade1419e1d7301e' into feat/sor…
MarkNerdi996 0b4e071
fix: fix merge conflicts
MarkNerdi996 a55aef0
chore: make label key optional
MarkNerdi996 e65ea4d
Merge commit 'a55aef09528bacb877f3145ee374ca51357a1122' into feat/sor…
MarkNerdi996 fcb59cd
feat: add sorting logic
MarkNerdi996 4a077e6
Merge commit 'ae67555ef4a790e43219dca9e373cd5f0dd620c9' into feat/sor…
MarkNerdi996 c15e09a
chore: remove sorting by date
MarkNerdi996 01e38f6
Merge branch 'develop' into feat/sort-proposals
jeeanribeiro e578942
Merge branch 'develop' into feat/sort-proposals
jeeanribeiro 622e290
Merge branch 'develop' into feat/sort-proposals
jeeanribeiro 7e44dce
coding convention fixes
jeeanribeiro File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,2 +1,3 @@ | ||||||||||
export * from './proposal-order-option.enum' | ||||||||||
export * from './proposal-type.enum' | ||||||||||
export * from './proposal-status.enum' | ||||||||||
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. just sorting this by alphabetic order
Suggested change
|
4 changes: 4 additions & 0 deletions
4
packages/shared/lib/contexts/governance/enums/proposal-order-option.enum.ts
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,4 @@ | ||
export enum ProposalOrderOption { | ||
Phase = 'phase', | ||
Name = 'name', | ||
} |
3 changes: 2 additions & 1 deletion
3
packages/shared/lib/contexts/governance/interfaces/proposal-filter.interface.ts
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { SelectionFilterUnit } from '@core/utils/interfaces/filter/filter-unit.interface' | ||
import { OrderFilterUnit, SelectionFilterUnit } from '@core/utils/interfaces/filter/filter-unit.interface' | ||
|
||
export interface ProposalFilter { | ||
phase: SelectionFilterUnit | ||
type: SelectionFilterUnit | ||
participated: SelectionFilterUnit | ||
order: OrderFilterUnit | ||
} |
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
36 changes: 36 additions & 0 deletions
36
packages/shared/lib/contexts/governance/utils/sortProposals.ts
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,36 @@ | ||||||
import { OrderOption } from '@core/utils/enums/filters' | ||||||
import { ProposalOrderOption, ProposalStatus } from '../enums' | ||||||
import { IProposal, ProposalFilter } from '../interfaces' | ||||||
|
||||||
export function sortProposals(proposals: IProposal[], filter: ProposalFilter): IProposal[] { | ||||||
let orderFunction = sortByName | ||||||
let isAscending = true | ||||||
|
||||||
if (filter.order.active) { | ||||||
switch (filter.order.selected) { | ||||||
case ProposalOrderOption.Name: | ||||||
orderFunction = sortByName | ||||||
break | ||||||
case ProposalOrderOption.Phase: | ||||||
orderFunction = sortByPhase | ||||||
break | ||||||
} | ||||||
isAscending = filter.order.ascDesc === OrderOption.Asc | ||||||
} | ||||||
|
||||||
return proposals?.sort((proposal1, propsal2) => orderFunction(proposal1, propsal2, isAscending)) ?? [] | ||||||
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. typo
Suggested change
|
||||||
} | ||||||
|
||||||
function sortByName(proposal1: IProposal, proposal2: IProposal, asc: boolean): number { | ||||||
return proposal1.title.toLowerCase() > proposal2.title.toLowerCase() ? (asc ? 1 : -1) : asc ? -1 : 1 | ||||||
} | ||||||
|
||||||
function sortByPhase(proposal1: IProposal, proposal2: IProposal, asc: boolean): number { | ||||||
const phaseOrdering = { | ||||||
[ProposalStatus.Upcoming]: 0, | ||||||
[ProposalStatus.Commencing]: 1, | ||||||
[ProposalStatus.Holding]: 2, | ||||||
[ProposalStatus.Ended]: 3, | ||||||
} | ||||||
return phaseOrdering[proposal1.status] > phaseOrdering[proposal2.status] ? (asc ? 1 : -1) : asc ? -1 : 1 | ||||||
} |
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
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.
Both modules can be added to the utils index and then imported in the same line