* Feat/1011: Filter rejected proposals rather than failed ones on proposals list * chore: use enum for ProposalState.STATE_REJECTED Co-authored-by: Matthew Russell <mattrussell36@gmail.com>
This commit is contained in:
parent
457c914fd5
commit
9979c25a13
@ -49,20 +49,15 @@ const enactedProposalClosedLastWeek = generateProposal({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const rejectedProposalClosedLastMonth = generateProposal({
|
const failedProposalClosedLastMonth = generateProposal({
|
||||||
id: 'proposal4',
|
id: 'proposal4',
|
||||||
state: ProposalState.STATE_REJECTED,
|
state: ProposalState.STATE_FAILED,
|
||||||
terms: {
|
terms: {
|
||||||
closingDatetime: lastMonth.toString(),
|
closingDatetime: lastMonth.toString(),
|
||||||
enactmentDatetime: lastMonth.toString(),
|
enactmentDatetime: lastMonth.toString(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const failedProposal = generateProposal({
|
|
||||||
id: 'proposal5',
|
|
||||||
state: ProposalState.STATE_FAILED,
|
|
||||||
});
|
|
||||||
|
|
||||||
const renderComponent = (proposals: Proposals_proposals[]) => (
|
const renderComponent = (proposals: Proposals_proposals[]) => (
|
||||||
<Router>
|
<Router>
|
||||||
<MockedProvider mocks={[networkParamsQueryMock]}>
|
<MockedProvider mocks={[networkParamsQueryMock]}>
|
||||||
@ -90,14 +85,6 @@ describe('Proposals list', () => {
|
|||||||
expect(screen.getByTestId('new-proposal-link')).toBeInTheDocument();
|
expect(screen.getByTestId('new-proposal-link')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Culls failed proposals', () => {
|
|
||||||
render(renderComponent([failedProposal]));
|
|
||||||
expect(screen.queryByTestId('open-proposals')).not.toBeInTheDocument();
|
|
||||||
expect(screen.getByTestId('no-open-proposals')).toBeInTheDocument();
|
|
||||||
expect(screen.queryByTestId('closed-proposals')).not.toBeInTheDocument();
|
|
||||||
expect(screen.getByTestId('no-closed-proposals')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Will hide filter if no proposals', () => {
|
it('Will hide filter if no proposals', () => {
|
||||||
render(renderComponent([]));
|
render(renderComponent([]));
|
||||||
expect(
|
expect(
|
||||||
@ -121,7 +108,7 @@ describe('Proposals list', () => {
|
|||||||
openProposalClosesNextWeek,
|
openProposalClosesNextWeek,
|
||||||
openProposalClosesNextMonth,
|
openProposalClosesNextMonth,
|
||||||
enactedProposalClosedLastWeek,
|
enactedProposalClosedLastWeek,
|
||||||
rejectedProposalClosedLastMonth,
|
failedProposalClosedLastMonth,
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
const openProposals = within(screen.getByTestId('open-proposals'));
|
const openProposals = within(screen.getByTestId('open-proposals'));
|
||||||
@ -135,7 +122,7 @@ describe('Proposals list', () => {
|
|||||||
it('Orders proposals correctly by closingDateTime', () => {
|
it('Orders proposals correctly by closingDateTime', () => {
|
||||||
render(
|
render(
|
||||||
renderComponent([
|
renderComponent([
|
||||||
rejectedProposalClosedLastMonth,
|
failedProposalClosedLastMonth,
|
||||||
openProposalClosesNextMonth,
|
openProposalClosesNextMonth,
|
||||||
openProposalClosesNextWeek,
|
openProposalClosesNextWeek,
|
||||||
enactedProposalClosedLastWeek,
|
enactedProposalClosedLastWeek,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { isFuture } from 'date-fns';
|
import { isFuture } from 'date-fns';
|
||||||
import React, { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Heading } from '../../../../components/heading';
|
import { Heading } from '../../../../components/heading';
|
||||||
import { ProposalsListItem } from '../proposals-list-item';
|
import { ProposalsListItem } from '../proposals-list-item';
|
||||||
@ -8,7 +8,6 @@ import type { Proposals_proposals } from '../../proposals/__generated__/Proposal
|
|||||||
import Routes from '../../../routes';
|
import Routes from '../../../routes';
|
||||||
import { Button } from '@vegaprotocol/ui-toolkit';
|
import { Button } from '@vegaprotocol/ui-toolkit';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { ProposalState } from '@vegaprotocol/types';
|
|
||||||
|
|
||||||
interface ProposalsListProps {
|
interface ProposalsListProps {
|
||||||
proposals: Proposals_proposals[];
|
proposals: Proposals_proposals[];
|
||||||
@ -23,11 +22,7 @@ export const ProposalsList = ({ proposals }: ProposalsListProps) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [filterString, setFilterString] = useState('');
|
const [filterString, setFilterString] = useState('');
|
||||||
|
|
||||||
const failedProposalsCulled = proposals.filter(
|
const sortedProposals = proposals.reduce(
|
||||||
({ state }) => state !== ProposalState.STATE_FAILED
|
|
||||||
);
|
|
||||||
|
|
||||||
const sortedProposals = failedProposalsCulled.reduce(
|
|
||||||
(acc: SortedProposalsProps, proposal) => {
|
(acc: SortedProposalsProps, proposal) => {
|
||||||
if (isFuture(new Date(proposal.terms.closingDatetime))) {
|
if (isFuture(new Date(proposal.terms.closingDatetime))) {
|
||||||
acc.open.push(proposal);
|
acc.open.push(proposal);
|
||||||
@ -59,7 +54,7 @@ export const ProposalsList = ({ proposals }: ProposalsListProps) => {
|
|||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{failedProposalsCulled.length > 0 && (
|
{proposals.length > 0 && (
|
||||||
<ProposalsListFilter setFilterString={setFilterString} />
|
<ProposalsListFilter setFilterString={setFilterString} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { gql, useQuery } from '@apollo/client';
|
import { gql, useQuery } from '@apollo/client';
|
||||||
|
import { ProposalState } from '@vegaprotocol/types';
|
||||||
import { Callout, Intent, Splash } from '@vegaprotocol/ui-toolkit';
|
import { Callout, Intent, Splash } from '@vegaprotocol/ui-toolkit';
|
||||||
import compact from 'lodash/compact';
|
import compact from 'lodash/compact';
|
||||||
|
import filter from 'lodash/filter';
|
||||||
import flow from 'lodash/flow';
|
import flow from 'lodash/flow';
|
||||||
import orderBy from 'lodash/orderBy';
|
import orderBy from 'lodash/orderBy';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
@ -35,6 +37,8 @@ export const ProposalsContainer = () => {
|
|||||||
|
|
||||||
return flow([
|
return flow([
|
||||||
compact,
|
compact,
|
||||||
|
(arr) =>
|
||||||
|
filter(arr, ({ state }) => state !== ProposalState.STATE_REJECTED),
|
||||||
(arr) =>
|
(arr) =>
|
||||||
orderBy(
|
orderBy(
|
||||||
arr,
|
arr,
|
||||||
|
Loading…
Reference in New Issue
Block a user