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

feat: sort proposals #5675

Merged
merged 23 commits into from Jan 27, 2023
Merged
Show file tree
Hide file tree
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 Jan 23, 2023
078474f
enhancement: add dropdown enums + translation
MarkNerdi996 Jan 23, 2023
2f0205d
feat: filter proposals
MarkNerdi996 Jan 24, 2023
641b19e
enhancement: add proposal type filter
MarkNerdi996 Jan 24, 2023
84d1f52
enhancement: add participated filter
MarkNerdi996 Jan 24, 2023
ac68773
fix: fix tests
MarkNerdi996 Jan 24, 2023
18cca41
chore: create combined filter type
MarkNerdi996 Jan 25, 2023
7646403
Merge commit '5843caacbdbd321ee11fddea351bba730d9563df' into feat/fil…
MarkNerdi996 Jan 25, 2023
d8b68f4
feat/ add proposal order to filter
MarkNerdi996 Jan 25, 2023
9b15052
Merge branch 'develop' into feat/filter-proposals
Tuditi Jan 25, 2023
81a0f8b
enhancement: add translations for proposal order
MarkNerdi996 Jan 25, 2023
9d3deda
enhancement: add labelkey to filter item
MarkNerdi996 Jan 25, 2023
9fcd56a
Merge commit '9d3dedab1de4c88b25abfa8ebade1419e1d7301e' into feat/sor…
MarkNerdi996 Jan 25, 2023
0b4e071
fix: fix merge conflicts
MarkNerdi996 Jan 25, 2023
a55aef0
chore: make label key optional
MarkNerdi996 Jan 25, 2023
e65ea4d
Merge commit 'a55aef09528bacb877f3145ee374ca51357a1122' into feat/sor…
MarkNerdi996 Jan 26, 2023
fcb59cd
feat: add sorting logic
MarkNerdi996 Jan 26, 2023
4a077e6
Merge commit 'ae67555ef4a790e43219dca9e373cd5f0dd620c9' into feat/sor…
MarkNerdi996 Jan 26, 2023
c15e09a
chore: remove sorting by date
MarkNerdi996 Jan 26, 2023
01e38f6
Merge branch 'develop' into feat/sort-proposals
jeeanribeiro Jan 26, 2023
e578942
Merge branch 'develop' into feat/sort-proposals
jeeanribeiro Jan 26, 2023
622e290
Merge branch 'develop' into feat/sort-proposals
jeeanribeiro Jan 27, 2023
7e44dce
coding convention fixes
jeeanribeiro Jan 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/shared/components/Proposals.svelte
Expand Up @@ -5,12 +5,12 @@
import { IProposal } from '@contexts/governance/interfaces'
import { proposalFilter } from '@contexts/governance'
import { isVisibleProposal } from '@contexts/governance/utils/isVisibleProposal'
import { sortProposals } from '@contexts/governance/utils/sortProposals'
Copy link
Contributor

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

Suggested change
import { isVisibleProposal } from '@contexts/governance/utils/isVisibleProposal'
import { sortProposals } from '@contexts/governance/utils/sortProposals'
import { isVisibleProposal, sortProposals } from '@contexts/governance/utils'


export let proposals: IProposal[] = []

$: sortedProposals = proposals
.filter((proposal) => isVisibleProposal(proposal, $proposalFilter))
.sort((a, b) => (a.id < b.id ? -1 : 1))
$: visibleProposals = proposals.filter((proposal) => isVisibleProposal(proposal, $proposalFilter))
$: sortedProposals = sortProposals(visibleProposals, $proposalFilter)
</script>

<proposals-container class="flex flex-col h-full">
Expand Down
1 change: 1 addition & 0 deletions packages/shared/lib/contexts/governance/enums/index.ts
@@ -1,2 +1,3 @@
export * from './proposal-order-option.enum'
export * from './proposal-type.enum'
export * from './proposal-status.enum'
Copy link
Contributor

Choose a reason for hiding this comment

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

just sorting this by alphabetic order

Suggested change
export * from './proposal-type.enum'
export * from './proposal-status.enum'
export * from './proposal-status.enum'
export * from './proposal-type.enum'

@@ -0,0 +1,4 @@
export enum ProposalOrderOption {
Phase = 'phase',
Name = 'name',
}
@@ -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
}
@@ -1,6 +1,6 @@
import { BooleanFilterOption } from '@core/utils/enums/filters'
import { BooleanFilterOption, OrderOption } from '@core/utils/enums/filters'
import { writable, Writable } from 'svelte/store'
import { ProposalFilter, ProposalStatus, ProposalType } from '..'
import { ProposalFilter, ProposalStatus, ProposalType, ProposalOrderOption } from '..'

export const proposalFilter: Writable<ProposalFilter> = writable({
phase: {
Expand All @@ -25,4 +25,12 @@ export const proposalFilter: Writable<ProposalFilter> = writable({
selected: BooleanFilterOption.Yes,
choices: [BooleanFilterOption.Yes, BooleanFilterOption.No],
},
order: {
active: false,
type: 'order',
localeKey: 'filters.proposalOrder',
selected: ProposalOrderOption.Name,
ascDesc: OrderOption.Asc,
choices: [ProposalOrderOption.Name, ProposalOrderOption.Phase],
},
})
36 changes: 36 additions & 0 deletions packages/shared/lib/contexts/governance/utils/sortProposals.ts
@@ -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)) ?? []
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

Suggested change
return proposals?.sort((proposal1, propsal2) => orderFunction(proposal1, propsal2, isAscending)) ?? []
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
}
5 changes: 5 additions & 0 deletions packages/shared/locales/en.json
Expand Up @@ -1584,6 +1584,11 @@
"label": "Participated",
"yes": "Yes",
"no": "No"
},
"proposalOrder": {
"label": "Order",
"name": "Name",
"phase": "Phase"
}
},
"dates": {
Expand Down