diff --git a/modules/polling/components/filters/PollTypeFilter.tsx b/modules/polling/components/filters/PollTypeFilter.tsx
index 836e59335..42fe72c73 100644
--- a/modules/polling/components/filters/PollTypeFilter.tsx
+++ b/modules/polling/components/filters/PollTypeFilter.tsx
@@ -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 = [
{
@@ -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
@@ -72,8 +64,8 @@ export function PollTypeFilter({
{type.name}
{
- 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
}
diff --git a/modules/polling/helpers/__tests__/validatePollParameters.spec.ts b/modules/polling/helpers/__tests__/validatePollParameters.spec.ts
index 9a189119e..d22c8dcf7 100644
--- a/modules/polling/helpers/__tests__/validatePollParameters.spec.ts
+++ b/modules/polling/helpers/__tests__/validatePollParameters.spec.ts
@@ -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
@@ -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
@@ -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', () => {
diff --git a/modules/polling/helpers/validatePollParameters.ts b/modules/polling/helpers/validatePollParameters.ts
index ad36cbfe1..03c605df2 100644
--- a/modules/polling/helpers/validatePollParameters.ts
+++ b/modules/polling/helpers/validatePollParameters.ts
@@ -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:
@@ -108,13 +108,13 @@ export function validatePollParameters(params: Record): [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);
}
}
diff --git a/pages/polling.tsx b/pages/polling.tsx
index 356aba6ae..ebd33b7ea 100644
--- a/pages/polling.tsx
+++ b/pages/polling.tsx
@@ -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;
@@ -198,7 +199,7 @@ const PollingOverview = ({ polls, tags }: PollingPageData) => {
- {/* */}
+