Skip to content

Commit

Permalink
DEV-489: Refactor contributor dashboard to use react-query,
Browse files Browse the repository at this point in the history
hide deleted contribs locally
  • Loading branch information
nrh-cklimas committed Nov 1, 2022
1 parent 2e7e0fb commit c4614c4
Show file tree
Hide file tree
Showing 60 changed files with 1,974 additions and 412 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Expand Up @@ -77,7 +77,7 @@ repos:
rev: v2.7.1
hooks:
- id: prettier
types: [javascript]
types: [javascript, tsx]
# JS code linter.
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.18.0
Expand Down
3 changes: 3 additions & 0 deletions spa/.storybook/preview-body.html
@@ -0,0 +1,3 @@
<!-- needed for elements/modal/Modal -->

<div id="modal-root"></div>
2 changes: 1 addition & 1 deletion spa/cypress/e2e/08-contributor.cy.js
Expand Up @@ -63,7 +63,7 @@ describe('Contributor portal', () => {
it('should display a list of contributions', () => {
cy.getByTestId('donations-table');
// DonationsTable is well tested elsewhere...
cy.get('td > p > span').should('have.length', 20);
cy.get('tbody tr').should('have.length', 10);
cy.get('li > button[aria-label="page 1"]').should('exist');
cy.get('li > button[aria-label="Go to page 2"]').should('exist');
// ... though here we should see different column headers
Expand Down
36 changes: 36 additions & 0 deletions spa/cypress/fixtures/donations/18-results.json
Expand Up @@ -8,6 +8,8 @@
"currency": "usd",
"reason": "",
"interval": "one_time",
"is_cancelable": false,
"is_modifiable": false,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand All @@ -34,6 +36,8 @@
"currency": "usd",
"reason": "",
"interval": "one_time",
"is_cancelable": false,
"is_modifiable": false,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand All @@ -60,6 +64,8 @@
"currency": "usd",
"reason": "",
"interval": "one_time",
"is_cancelable": false,
"is_modifiable": false,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand All @@ -86,6 +92,8 @@
"currency": "usd",
"reason": "",
"interval": "month",
"is_cancelable": true,
"is_modifiable": true,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand Down Expand Up @@ -113,6 +121,8 @@
"currency": "usd",
"reason": "",
"interval": "month",
"is_cancelable": true,
"is_modifiable": true,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand Down Expand Up @@ -140,6 +150,8 @@
"currency": "usd",
"reason": "",
"interval": "month",
"is_cancelable": true,
"is_modifiable": true,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand Down Expand Up @@ -167,6 +179,8 @@
"currency": "usd",
"reason": "",
"interval": "month",
"is_cancelable": true,
"is_modifiable": true,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand Down Expand Up @@ -194,6 +208,8 @@
"currency": "usd",
"reason": "",
"interval": "one_time",
"is_cancelable": true,
"is_modifiable": true,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand All @@ -220,6 +236,8 @@
"currency": "usd",
"reason": "",
"interval": "one_time",
"is_cancelable": false,
"is_modifiable": false,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand All @@ -246,6 +264,8 @@
"currency": "usd",
"reason": "",
"interval": "one_time",
"is_cancelable": false,
"is_modifiable": false,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand All @@ -272,6 +292,8 @@
"currency": "usd",
"reason": "",
"interval": "one_time",
"is_cancelable": false,
"is_modifiable": false,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand All @@ -298,6 +320,8 @@
"currency": "usd",
"reason": "",
"interval": "one_time",
"is_cancelable": false,
"is_modifiable": false,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand All @@ -324,6 +348,8 @@
"currency": "usd",
"reason": "",
"interval": "year",
"is_cancelable": true,
"is_modifiable": true,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand Down Expand Up @@ -351,6 +377,8 @@
"currency": "usd",
"reason": "",
"interval": "year",
"is_cancelable": true,
"is_modifiable": true,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand Down Expand Up @@ -378,6 +406,8 @@
"currency": "usd",
"reason": "",
"interval": "year",
"is_cancelable": true,
"is_modifiable": true,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand Down Expand Up @@ -405,6 +435,8 @@
"currency": "usd",
"reason": "",
"interval": "one_time",
"is_cancelable": false,
"is_modifiable": false,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand All @@ -431,6 +463,8 @@
"currency": "usd",
"reason": "",
"interval": "one_time",
"is_cancelable": false,
"is_modifiable": false,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand All @@ -457,6 +491,8 @@
"currency": "usd",
"reason": "",
"interval": "year",
"is_cancelable": true,
"is_modifiable": true,
"payment_provider_used": "Stripe",
"payment_provider_data": null,
"provider_payment_id": null,
Expand Down
2 changes: 1 addition & 1 deletion spa/package.json
Expand Up @@ -88,7 +88,7 @@
"collectCoverageFrom": [
"**/*.[jt]s?(x)",
"!**/node_modules/**",
"!**/*.stories.js",
"!**/*.stories.[jt]sx",
"!**/*.styled.js"
],
"transformIgnorePatterns": [
Expand Down
11 changes: 11 additions & 0 deletions spa/src/assets/assets.d.ts
@@ -0,0 +1,11 @@
// Required to import .svg files to TS files
declare module '*.svg' {
const content: any;
export default content;
}

// Required to import .png files to TS files
declare module '*.png' {
const content: any;
export default content;
}
14 changes: 14 additions & 0 deletions spa/src/components/base/Pagination/Pagination.stories.tsx
@@ -0,0 +1,14 @@
import { ComponentMeta, ComponentStory } from '@storybook/react';
import Pagination from './Pagination';
export default {
argTypes: {
count: { control: 'number', defaultValue: 5 },
page: { control: 'number', defaultValue: 2 }
},
component: Pagination,
title: 'Base/Pagination'
} as ComponentMeta<typeof Pagination>;

const Template: ComponentStory<typeof Pagination> = (props) => <Pagination {...props} />;

export const Default = Template.bind({});
20 changes: 20 additions & 0 deletions spa/src/components/base/Pagination/Pagination.test.tsx
@@ -0,0 +1,20 @@
import { axe } from 'jest-axe';
import { render, screen } from 'test-utils';
import Pagination, { PaginationProps } from './Pagination';

function tree(props?: PaginationProps) {
return render(<Pagination count={2} page={1} {...props} />);
}

describe('Pagination', () => {
it('renders a navigation', () => {
tree();
expect(screen.getByRole('navigation')).toBeVisible();
});

it('is accessible', async () => {
const { container } = tree();

expect(await axe(container)).toHaveNoViolations();
});
});
19 changes: 19 additions & 0 deletions spa/src/components/base/Pagination/Pagination.tsx
@@ -0,0 +1,19 @@
import { Pagination as MuiPagination, PaginationProps as MuiPaginationProps } from '@material-ui/lab';
import styled from 'styled-components';

export const Pagination = styled(MuiPagination)`
&& {
align-items: center;
display: flex;
justify-content: center;
button.Mui-selected {
background-color: #6fd1ec;
border-radius: 4px;
font-weight: 700;
}
}
`;

export type PaginationProps = MuiPaginationProps;
export default Pagination;
41 changes: 41 additions & 0 deletions spa/src/components/base/Table/Table.stories.tsx
@@ -0,0 +1,41 @@
import { ComponentMeta, ComponentStory } from '@storybook/react';
import Table from './Table';
import TableBody from './TableBody';
import TableCell from './TableCell';
import TableHead from './TableHead';
import TableRow from './TableRow';
export default {
component: Table,
title: 'Base/Table'
} as ComponentMeta<typeof Table>;

const Template: ComponentStory<typeof Table> = (props) => (
<Table {...props}>
<TableHead>
<TableRow>
<TableCell>ID</TableCell>
<TableCell>Color</TableCell>
<TableCell>Cost</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>1</TableCell>
<TableCell>Red</TableCell>
<TableCell>$1.99</TableCell>
</TableRow>
<TableRow>
<TableCell>2</TableCell>
<TableCell>Green</TableCell>
<TableCell>$4.99</TableCell>
</TableRow>
<TableRow>
<TableCell>3</TableCell>
<TableCell>Blue</TableCell>
<TableCell>$0.99</TableCell>
</TableRow>
</TableBody>
</Table>
);

export const Unsortable = Template.bind({});
66 changes: 66 additions & 0 deletions spa/src/components/base/Table/Table.test.tsx
@@ -0,0 +1,66 @@
import { axe } from 'jest-axe';
import { render, screen } from 'test-utils';
import Table from './Table';
import TableBody from './TableBody';
import TableCell from './TableCell';
import TableHead from './TableHead';
import TableRow from './TableRow';

// This tests all components in this directory since they should be used
// together.

function tree() {
return render(
<Table>
<TableHead>
<TableRow>
<TableCell>ID</TableCell>
<TableCell>Color</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>1</TableCell>
<TableCell>Red</TableCell>
</TableRow>
<TableRow>
<TableCell>2</TableCell>
<TableCell>Green</TableCell>
</TableRow>
<TableRow>
<TableCell>3</TableCell>
<TableCell>Blue</TableCell>
</TableRow>
</TableBody>
</Table>
);
}

describe('Table', () => {
it('renders a table', () => {
tree();
expect(screen.getByRole('table')).toBeVisible();
});

it('renders headers', () => {
tree();
expect(screen.getByRole('columnheader', { name: 'ID' })).toBeVisible();
expect(screen.getByRole('columnheader', { name: 'Color' })).toBeVisible();
});

it('renders cells', () => {
tree();
expect(screen.getByRole('cell', { name: '1' })).toBeVisible();
expect(screen.getByRole('cell', { name: '2' })).toBeVisible();
expect(screen.getByRole('cell', { name: '3' })).toBeVisible();
expect(screen.getByRole('cell', { name: 'Red' })).toBeVisible();
expect(screen.getByRole('cell', { name: 'Green' })).toBeVisible();
expect(screen.getByRole('cell', { name: 'Blue' })).toBeVisible();
});

it('is accessible', async () => {
const { container } = tree();

expect(await axe(container)).toHaveNoViolations();
});
});
5 changes: 5 additions & 0 deletions spa/src/components/base/Table/Table.tsx
@@ -0,0 +1,5 @@
import { Table as MuiTable, TableProps as MuiTableProps } from '@material-ui/core';

export const Table = MuiTable;
export type TableProps = MuiTableProps;
export default Table;
5 changes: 5 additions & 0 deletions spa/src/components/base/Table/TableBody.tsx
@@ -0,0 +1,5 @@
import { TableBody as MuiTableBody, TableBodyProps as MuiTableBodyProps } from '@material-ui/core';

export const TableBody = MuiTableBody;
export type TableBodyProps = MuiTableBodyProps;
export default TableBody;
12 changes: 12 additions & 0 deletions spa/src/components/base/Table/TableCell.tsx
@@ -0,0 +1,12 @@
import { TableCell as MuiTableCell, TableCellProps as MuiTableCellProps } from '@material-ui/core';
import styled from 'styled-components';

export const TableCell = styled(MuiTableCell)`
&& {
border: none;
font: 16px Roboto, sans-serif;
}
`;

export type TableCellProps = MuiTableCellProps;
export default TableCell;

0 comments on commit c4614c4

Please sign in to comment.