-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NNS1-3504: Sort selectable universes by actionable proposals (#6131)
# Motivation On the voting page we want to sort the universes (both in the selector and in the actionable proposals) based on the number of actionably proposals or otherwise alphabetically. Both the selector and the actionable proposals sections are rendered based on `selectableUniversesStore`. (This store is also used for other things, such as [finding the currently selected universe](https://github.com/dfinity/nns-dapp/blob/58b8d349c2912b678f69b1060342430f6992fb12/frontend/src/lib/components/accounts/IcrcWalletPage.svelte#L166), which is why it can still also contain non-voting universes such as ckBTC.) # Changes 1. Sort `selectableUniversesStore` based on actionable proposal count and title. # Tests 1. Simplify the existing tests for `selectableUniversesStore`. Because of the re-ordering, the tests were confusing in their previous form. 2. Add unit tests with multiple SNS projects. 3. Adapt `ActionableProposals.spec.ts` to the new ordering. 4. Manually tested at https://qsgjb-riaaa-aaaaa-aaaga-cai.dskloet-ingress.devenv.dfinity.network/proposals/?actionable # Todos - [x] Add entry to changelog (if necessary).
- Loading branch information
Showing
4 changed files
with
171 additions
and
60 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,30 +1,80 @@ | ||
import { OWN_CANISTER_ID_TEXT } from "$lib/constants/canister-ids.constants"; | ||
import { | ||
actionableProposalCountStore, | ||
type ActionableProposalCountData, | ||
} from "$lib/derived/actionable-proposals.derived"; | ||
import { | ||
icrcCanistersStore, | ||
type IcrcCanistersStore, | ||
type IcrcCanistersStoreData, | ||
} from "$lib/derived/icrc-canisters.derived"; | ||
import { pageStore, type Page } from "$lib/derived/page.derived"; | ||
import type { Universe } from "$lib/types/universe"; | ||
import { | ||
createAscendingComparator, | ||
createDescendingComparator, | ||
mergeComparators, | ||
} from "$lib/utils/sort.utils"; | ||
import { isAllTokensPath, isUniverseCkBTC } from "$lib/utils/universe.utils"; | ||
import { isNullish } from "@dfinity/utils"; | ||
import { derived, type Readable } from "svelte/store"; | ||
import { universesStore } from "./universes.derived"; | ||
|
||
type UniverseWithActionableProposalCount = { | ||
universe: Universe; | ||
actionableProposalCount: number; | ||
}; | ||
|
||
const compareNnsFirst = createDescendingComparator( | ||
({ universe: { canisterId } }: UniverseWithActionableProposalCount) => | ||
canisterId === OWN_CANISTER_ID_TEXT | ||
); | ||
|
||
const compareActionableProposalCount = createDescendingComparator( | ||
({ actionableProposalCount }: UniverseWithActionableProposalCount) => | ||
actionableProposalCount | ||
); | ||
|
||
const compareTitle = createAscendingComparator( | ||
({ universe: { title } }: UniverseWithActionableProposalCount) => | ||
title.toLowerCase() | ||
); | ||
|
||
export const selectableUniversesStore = derived< | ||
[Readable<Universe[]>, Readable<Page>, IcrcCanistersStore], | ||
[ | ||
Readable<Universe[]>, | ||
Readable<Page>, | ||
IcrcCanistersStore, | ||
Readable<ActionableProposalCountData>, | ||
], | ||
Universe[] | ||
>( | ||
[universesStore, pageStore, icrcCanistersStore], | ||
([universes, page, icrcCanisters]: [ | ||
[universesStore, pageStore, icrcCanistersStore, actionableProposalCountStore], | ||
([universes, page, icrcCanisters, actionableProposalCounts]: [ | ||
Universe[], | ||
Page, | ||
IcrcCanistersStoreData, | ||
ActionableProposalCountData, | ||
]) => | ||
// Non-governance paths show all universes | ||
// The rest show all universes except for ckBTC, and ICRC Tokens | ||
universes.filter( | ||
({ canisterId }) => | ||
isAllTokensPath(page) || | ||
(!isUniverseCkBTC(canisterId) && isNullish(icrcCanisters[canisterId])) | ||
) | ||
universes | ||
.filter( | ||
({ canisterId }) => | ||
isAllTokensPath(page) || | ||
(!isUniverseCkBTC(canisterId) && isNullish(icrcCanisters[canisterId])) | ||
) | ||
.map((universe) => ({ | ||
universe, | ||
actionableProposalCount: | ||
actionableProposalCounts[universe.canisterId] ?? 0, | ||
})) | ||
.sort( | ||
mergeComparators([ | ||
compareNnsFirst, | ||
compareActionableProposalCount, | ||
compareTitle, | ||
]) | ||
) | ||
.map(({ universe }) => universe) | ||
); |
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