Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…al-v2 into adam/delegate-reqs
  • Loading branch information
adamgoth committed Jun 22, 2022
2 parents c422e5d + 0264b68 commit 0d36f25
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 49 deletions.
22 changes: 7 additions & 15 deletions modules/polling/components/filters/PollTypeFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import useUiFiltersStore from 'modules/app/stores/uiFilters';
import { useMemo } from 'react';
import { filterPolls } from '../../helpers/filterPolls';
import { PollVictoryConditions } from 'modules/polling/polling.constants';
import { TagCount } from 'modules/app/types/tag';

const VICTORY_CONDITIONS = [
{
Expand All @@ -16,21 +15,14 @@ const VICTORY_CONDITIONS = [
{
name: 'Ranked Choice',
key: PollVictoryConditions.instantRunoff
},
{
name: 'Majority',
key: PollVictoryConditions.majority
}
// {
// name: 'Majority',
// key: PollVictoryConditions.majority
// }
];

export function PollTypeFilter({
polls,
...props
}: {
tags: TagCount[];
polls: Poll[];
sx?: ThemeUIStyleObject;
}): JSX.Element {
export function PollTypeFilter({ polls, ...props }: { polls: Poll[]; sx?: ThemeUIStyleObject }): JSX.Element {
const [pollFilters, pollVictoryCondition, setPollVictoryCondition] = useUiFiltersStore(
state => [state.pollFilters, state.pollFilters.pollVictoryCondition, state.setPollVictoryCondition],
shallow
Expand Down Expand Up @@ -72,8 +64,8 @@ export function PollTypeFilter({
<Text>{type.name}</Text>
<Text sx={{ color: 'muted', ml: 3 }}>
{
filteredPolls.filter(i =>
i.parameters.victoryConditions.filter(v => v.type === type.key)
filteredPolls.filter(
i => i.parameters.victoryConditions.filter(v => v.type === type.key).length > 0
).length
}
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ parameters:
expect(errors[0]).toEqual(ERRORS_VALIDATE_POLL_PARAMETERS.victoryConditionsInvalidCombination);
});

it('should error if input_format rank-free does not have instant-runoff victory conditions', () => {
it('should error if victory_condition plurality does not have input_format single-choice conditions', () => {
const parameters = `---
parameters:
input_format: rank-free
Expand All @@ -115,10 +115,10 @@ parameters:
expect(parsed).toBe(null);
expect(errors.length).toBeGreaterThan(0);

expect(errors[0]).toEqual(ERRORS_VALIDATE_POLL_PARAMETERS.rankFreeRequiresInstantRunoff);
expect(errors[0]).toEqual(ERRORS_VALIDATE_POLL_PARAMETERS.pluralityRequiresSingleChoice);
});

it('should error if input_format single-choice does not have plurality victory conditions', () => {
it('should error if victory_conditions instant-runoff does not have a rank-free input format', () => {
const parameters = `---
parameters:
input_format: single-choice
Expand All @@ -135,7 +135,7 @@ parameters:
expect(parsed).toBe(null);
expect(errors.length).toBeGreaterThan(0);

expect(errors[0]).toEqual(ERRORS_VALIDATE_POLL_PARAMETERS.singleChoiceRequiresPlurality);
expect(errors[0]).toEqual(ERRORS_VALIDATE_POLL_PARAMETERS.instantRunoffRequiresRankFree);
});

it('should error if result_display is missing', () => {
Expand Down
12 changes: 6 additions & 6 deletions modules/polling/helpers/validatePollParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const ERRORS_VALIDATE_POLL_PARAMETERS = {
'victory_conditions must include a valid condition. Valid conditions are "plurality" or "instant_runoff"',
victoryConditionsInvalidCombination:
'victory_conditions combination not valid. instant-runoff and plurality can not be combined together.',
rankFreeRequiresInstantRunoff: 'input_format rank-free requires victory_condition instant-runoff',
singleChoiceRequiresPlurality: 'input_format single-choice requires victory_condition plurality',
instantRunoffRequiresRankFree: 'victory_condition instant-runoff requires input_format rank-free',
pluralityRequiresSingleChoice: 'victory_condition plurality requires input_format single-choice',

// TODO: Include more result_displays when allowed
requiredResultDisplay:
Expand Down Expand Up @@ -108,13 +108,13 @@ export function validatePollParameters(params: Record<string, unknown>): [PollPa
// Can not combine instant runoff and comparison , can not combine instant runoff and majority, etc

// Rank free requires instant runoff condition
if (params.input_format === PollInputFormat.rankFree && !hasVictoryConditionInstantRunOff) {
errors.push(ERRORS_VALIDATE_POLL_PARAMETERS.rankFreeRequiresInstantRunoff);
if (params.input_format !== PollInputFormat.rankFree && hasVictoryConditionInstantRunOff) {
errors.push(ERRORS_VALIDATE_POLL_PARAMETERS.instantRunoffRequiresRankFree);
}

// Single choice requires plurality
if (params.input_format === PollInputFormat.singleChoice && !hasVictoryConditionPlurality) {
errors.push(ERRORS_VALIDATE_POLL_PARAMETERS.singleChoiceRequiresPlurality);
if (params.input_format !== PollInputFormat.singleChoice && hasVictoryConditionPlurality) {
errors.push(ERRORS_VALIDATE_POLL_PARAMETERS.pluralityRequiresSingleChoice);
}
}

Expand Down
3 changes: 2 additions & 1 deletion pages/polling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { fetchPollingPageData, PollingPageData } from 'modules/polling/api/fetch
import { SupportedNetworks } from 'modules/web3/constants/networks';
import PollsSort from 'modules/polling/components/filters/PollsSort';
import usePollsStore from 'modules/polling/stores/polls';
import { PollTypeFilter } from 'modules/polling/components/filters/PollTypeFilter';

const getSortCriteria = (sort: PollsSortEnum | null) => {
if (!sort) sort = PollsSortEnum.endDateAsc;
Expand Down Expand Up @@ -198,7 +199,7 @@ const PollingOverview = ({ polls, tags }: PollingPageData) => {
<PollsSort />
<CategoryFilter tags={tags} polls={polls} sx={{ m: 2 }} />
<StatusFilter polls={polls} sx={{ m: 2 }} />
{/* <PollTypeFilter categories={categories} polls={polls} sx={{ m: 2 }} /> */}
<PollTypeFilter polls={polls} sx={{ m: 2 }} />
<DateFilter sx={{ m: 2 }} />
</Flex>
<Button
Expand Down
41 changes: 18 additions & 23 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2404,7 +2404,7 @@
"@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@protobufjs/aspromise/-/aspromise-1.1.2.tgz#9b8b0cc663d669a7d8f6f5d0893a14d348f30fbf"
integrity sha1-m4sMxmPWaafY9vXQiToU00jzD78=
integrity sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==

"@protobufjs/base64@^1.1.2":
version "1.1.2"
Expand All @@ -2419,40 +2419,40 @@
"@protobufjs/eventemitter@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz#355cbc98bafad5978f9ed095f397621f1d066b70"
integrity sha1-NVy8mLr61ZePntCV85diHx0Ga3A=
integrity sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==

"@protobufjs/fetch@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/fetch/-/fetch-1.1.0.tgz#ba99fb598614af65700c1619ff06d454b0d84c45"
integrity sha1-upn7WYYUr2VwDBYZ/wbUVLDYTEU=
integrity sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==
dependencies:
"@protobufjs/aspromise" "^1.1.1"
"@protobufjs/inquire" "^1.1.0"

"@protobufjs/float@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@protobufjs/float/-/float-1.0.2.tgz#5e9e1abdcb73fc0a7cb8b291df78c8cbd97b87d1"
integrity sha1-Xp4avctz/Ap8uLKR33jIy9l7h9E=
integrity sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==

"@protobufjs/inquire@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/inquire/-/inquire-1.1.0.tgz#ff200e3e7cf2429e2dcafc1140828e8cc638f089"
integrity sha1-/yAOPnzyQp4tyvwRQIKOjMY48Ik=
integrity sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==

"@protobufjs/path@^1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@protobufjs/path/-/path-1.1.2.tgz#6cc2b20c5c9ad6ad0dccfd21ca7673d8d7fbf68d"
integrity sha1-bMKyDFya1q0NzP0hynZz2Nf79o0=
integrity sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==

"@protobufjs/pool@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/pool/-/pool-1.1.0.tgz#09fd15f2d6d3abfa9b65bc366506d6ad7846ff54"
integrity sha1-Cf0V8tbTq/qbZbw2ZQbWrXhG/1Q=
integrity sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==

"@protobufjs/utf8@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=
integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==

"@reach/auto-id@0.10.5":
version "0.10.5"
Expand Down Expand Up @@ -3423,9 +3423,9 @@
"@types/node" "*"

"@types/long@^4.0.1":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.1.tgz#459c65fa1867dafe6a8f322c4c51695663cc55e9"
integrity sha512-5tXH6Bx/kNGd3MgffdmP4dy2Z+G4eaXw0SE81Tq3BNadtnMR5/ySMzX4SLEzHJzSmPNn4HIdpQsBvXMUykr58w==
version "4.0.2"
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.2.tgz#b74129719fc8d11c01868010082d483b7545591a"
integrity sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA==

"@types/lru-cache@^5.1.0":
version "5.1.1"
Expand Down Expand Up @@ -3454,15 +3454,10 @@
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197"
integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==

"@types/node@*":
version "17.0.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.8.tgz#50d680c8a8a78fe30abe6906453b21ad8ab0ad7b"
integrity sha512-YofkM6fGv4gDJq78g4j0mMuGMkZVxZDgtU0JRdx6FgiJDG+0fY0GKVolOV8WqVmEhLCXkQRjwDdKyPxJp/uucg==

"@types/node@>=13.7.0":
version "17.0.21"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.21.tgz#864b987c0c68d07b4345845c3e63b75edd143644"
integrity sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ==
"@types/node@*", "@types/node@>=13.7.0":
version "17.0.38"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.38.tgz#f8bb07c371ccb1903f3752872c89f44006132947"
integrity sha512-5jY9RhV7c0Z4Jy09G+NIDTsCZ5G0L5n+Z+p+Y7t5VJHM30bgwzSjVtlcBxqAj+6L/swIlvtOSzr8rBk/aNyV2g==

"@types/node@^14.14.31":
version "14.18.5"
Expand Down Expand Up @@ -11610,9 +11605,9 @@ property-information@^6.0.0:
integrity sha512-hrzC564QIl0r0vy4l6MvRLhafmUowhO/O3KgVSoXIbbA2Sz4j8HGpJc6T2cubRVwMwpdiG/vKGfhT4IixmKN9w==

protobufjs@^6.10.2:
version "6.11.2"
resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.11.2.tgz#de39fabd4ed32beaa08e9bb1e30d08544c1edf8b"
integrity sha512-4BQJoPooKJl2G9j3XftkIXjoC9C0Av2NOrWmbLWT1vH32GcSUHjM0Arra6UfTsVyfMAuFzaLucXn1sadxJydAw==
version "6.11.3"
resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.11.3.tgz#637a527205a35caa4f3e2a9a4a13ddffe0e7af74"
integrity sha512-xL96WDdCZYdU7Slin569tFX712BxsxslWwAfAhCYjQKGTq7dAU91Lomy6nLLhh/dyGhk/YH4TwTSRxTzhuHyZg==
dependencies:
"@protobufjs/aspromise" "^1.1.2"
"@protobufjs/base64" "^1.1.2"
Expand Down

0 comments on commit 0d36f25

Please sign in to comment.