Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: move filter to general module * enhancement: add dropdown enums + translation * feat: filter proposals * enhancement: add proposal type filter * enhancement: add participated filter * fix: fix tests * chore: create combined filter type * feat/ add proposal order to filter * enhancement: add translations for proposal order * enhancement: add labelkey to filter item * fix: fix merge conflicts * chore: make label key optional * feat: add sorting logic * chore: remove sorting by date * coding convention fixes Co-authored-by: Tuditi <45079109+Tuditi@users.noreply.github.com> Co-authored-by: Jean Ribeiro <iamjeanribeiro@gmail.com> Co-authored-by: Jean Ribeiro <contact@jeanribeiro.dev>
- Loading branch information
1 parent
4a625c6
commit 0d3300f
Showing
8 changed files
with
65 additions
and
9 deletions.
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-type.enum' | ||
export * from './proposal-order-option.enum' | ||
export * from './proposal-status.enum' | ||
export * from './proposal-type.enum' |
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
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, proposal2) => orderFunction(proposal1, proposal2, isAscending)) ?? [] | ||
} | ||
|
||
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