* 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',
|
||||
state: ProposalState.STATE_REJECTED,
|
||||
state: ProposalState.STATE_FAILED,
|
||||
terms: {
|
||||
closingDatetime: lastMonth.toString(),
|
||||
enactmentDatetime: lastMonth.toString(),
|
||||
},
|
||||
});
|
||||
|
||||
const failedProposal = generateProposal({
|
||||
id: 'proposal5',
|
||||
state: ProposalState.STATE_FAILED,
|
||||
});
|
||||
|
||||
const renderComponent = (proposals: Proposals_proposals[]) => (
|
||||
<Router>
|
||||
<MockedProvider mocks={[networkParamsQueryMock]}>
|
||||
@ -90,14 +85,6 @@ describe('Proposals list', () => {
|
||||
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', () => {
|
||||
render(renderComponent([]));
|
||||
expect(
|
||||
@ -121,7 +108,7 @@ describe('Proposals list', () => {
|
||||
openProposalClosesNextWeek,
|
||||
openProposalClosesNextMonth,
|
||||
enactedProposalClosedLastWeek,
|
||||
rejectedProposalClosedLastMonth,
|
||||
failedProposalClosedLastMonth,
|
||||
])
|
||||
);
|
||||
const openProposals = within(screen.getByTestId('open-proposals'));
|
||||
@ -135,7 +122,7 @@ describe('Proposals list', () => {
|
||||
it('Orders proposals correctly by closingDateTime', () => {
|
||||
render(
|
||||
renderComponent([
|
||||
rejectedProposalClosedLastMonth,
|
||||
failedProposalClosedLastMonth,
|
||||
openProposalClosesNextMonth,
|
||||
openProposalClosesNextWeek,
|
||||
enactedProposalClosedLastWeek,
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { isFuture } from 'date-fns';
|
||||
import React, { useState } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Heading } from '../../../../components/heading';
|
||||
import { ProposalsListItem } from '../proposals-list-item';
|
||||
@ -8,7 +8,6 @@ import type { Proposals_proposals } from '../../proposals/__generated__/Proposal
|
||||
import Routes from '../../../routes';
|
||||
import { Button } from '@vegaprotocol/ui-toolkit';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { ProposalState } from '@vegaprotocol/types';
|
||||
|
||||
interface ProposalsListProps {
|
||||
proposals: Proposals_proposals[];
|
||||
@ -23,11 +22,7 @@ export const ProposalsList = ({ proposals }: ProposalsListProps) => {
|
||||
const { t } = useTranslation();
|
||||
const [filterString, setFilterString] = useState('');
|
||||
|
||||
const failedProposalsCulled = proposals.filter(
|
||||
({ state }) => state !== ProposalState.STATE_FAILED
|
||||
);
|
||||
|
||||
const sortedProposals = failedProposalsCulled.reduce(
|
||||
const sortedProposals = proposals.reduce(
|
||||
(acc: SortedProposalsProps, proposal) => {
|
||||
if (isFuture(new Date(proposal.terms.closingDatetime))) {
|
||||
acc.open.push(proposal);
|
||||
@ -59,7 +54,7 @@ export const ProposalsList = ({ proposals }: ProposalsListProps) => {
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{failedProposalsCulled.length > 0 && (
|
||||
{proposals.length > 0 && (
|
||||
<ProposalsListFilter setFilterString={setFilterString} />
|
||||
)}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
import { ProposalState } from '@vegaprotocol/types';
|
||||
import { Callout, Intent, Splash } from '@vegaprotocol/ui-toolkit';
|
||||
import compact from 'lodash/compact';
|
||||
import filter from 'lodash/filter';
|
||||
import flow from 'lodash/flow';
|
||||
import orderBy from 'lodash/orderBy';
|
||||
import React from 'react';
|
||||
@ -35,6 +37,8 @@ export const ProposalsContainer = () => {
|
||||
|
||||
return flow([
|
||||
compact,
|
||||
(arr) =>
|
||||
filter(arr, ({ state }) => state !== ProposalState.STATE_REJECTED),
|
||||
(arr) =>
|
||||
orderBy(
|
||||
arr,
|
||||
|
Loading…
Reference in New Issue
Block a user