-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break datatable page results into util and template
- Loading branch information
Showing
15 changed files
with
189 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,9 @@ | ||
module.exports = { | ||
testPathIgnorePatterns: ['<rootDir>/lib/', '<rootDir>/node_modules/'], | ||
setupFilesAfterEnv: ['<rootDir>/setupTests.js'], | ||
testPathIgnorePatterns: ["<rootDir>/lib/", "<rootDir>/node_modules/"], | ||
setupFilesAfterEnv: ["<rootDir>/setupTests.js"], | ||
moduleNameMapper: { | ||
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/__mocks__/fileMock.js', | ||
'\\.(css|less)$': '<rootDir>/__mocks__/styleMock.js', | ||
'^dnd-core$': 'dnd-core/dist/cjs', | ||
'^react-dnd$': 'react-dnd/dist/cjs', | ||
'^react-dnd-html5-backend$': 'react-dnd-html5-backend/dist/cjs', | ||
'^react-dnd-multi-backend$': 'react-dnd-multi-backend', | ||
'^HTML5toTouch$': 'react-dnd-html5-backend/dist/cjs', | ||
'^react-dnd-touch-backend$': 'react-dnd-touch-backend/dist/cjs', | ||
'^react-dnd-test-backend$': 'react-dnd-test-backend/dist/cjs', | ||
'^react-dnd-test-utils$': 'react-dnd-test-utils/dist/cjs', | ||
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": | ||
"<rootDir>/__mocks__/fileMock.js", | ||
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +0,0 @@ | ||
// /* eslint-disable */ | ||
// import { configure } from 'enzyme'; | ||
// import Adapter from 'enzyme-adapter-react-16'; | ||
|
||
// configure({ adapter: new Adapter() }); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
src/components/DataTablePageResults/DataTablePageResults.stories.mdx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { default as DataTablePageResults } from "./components/DataTablePageResults"; | ||
export { default as DataTablePageResults } from "./templates/DataTablePageResults"; | ||
export { default as DataTable } from "./components/DataTable"; |
12 changes: 12 additions & 0 deletions
12
src/templates/DataTablePageResults/DataTablePageResults.stories.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Meta, Story, Canvas } from "@storybook/addon-docs/blocks"; | ||
import DataTablePageResults from "./index"; | ||
|
||
<Meta title="DataTablePageResults" component={DataTablePageResults} /> | ||
|
||
# Datatable Page Results | ||
|
||
<Canvas> | ||
<Story name="Basic"> | ||
<DataTablePageResults totalRows={2000} limit={25} offset={0} /> | ||
</Story> | ||
</Canvas> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { datatablePageResults } from "../../utils/DatatablePageResults"; | ||
|
||
const DataTablePageResults = ({ totalRows, limit, offset, className }) => { | ||
// If there are no totalRows, just show 0s and skip the function overhead. | ||
if (totalRows === 0) { | ||
return <p className={className}>{`0 - 0 of 0 rows`}</p>; | ||
} | ||
|
||
const { startTotal, ofTotal, numTotalRows } = datatablePageResults( | ||
totalRows, | ||
limit, | ||
offset, | ||
true | ||
); | ||
return ( | ||
<p | ||
className={className} | ||
>{`${startTotal} - ${ofTotal} of ${numTotalRows} rows`}</p> | ||
); | ||
}; | ||
|
||
DataTablePageResults.defaultProps = { | ||
className: "data-table-results", | ||
}; | ||
|
||
DataTablePageResults.propTypes = { | ||
className: PropTypes.string, | ||
totalRows: PropTypes.number.isRequired, | ||
limit: PropTypes.number.isRequired, | ||
offset: PropTypes.number.isRequired, | ||
}; | ||
|
||
export default DataTablePageResults; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import "@testing-library/jest-dom/extend-expect"; | ||
import DataTablePageResults from "."; | ||
|
||
describe("<DataTablePageResults />", () => { | ||
test("renders correct when 0 results", () => { | ||
render(<DataTablePageResults totalRows={0} limit={25} offset={0} />); | ||
expect(screen.getByText(/0 - 0 of 0 rows/)).toBeInTheDocument(); | ||
}); | ||
test("renders correct initial results", () => { | ||
render(<DataTablePageResults totalRows={100} limit={25} offset={0} />); | ||
expect(screen.getByText(/1 - 25 of 100 rows/)).toBeInTheDocument(); | ||
}); | ||
|
||
test("renders correct results on subsequent pages", () => { | ||
render(<DataTablePageResults totalRows={100} limit={10} offset={10} />); | ||
expect(screen.getByText(/11 - 20 of 100 rows/)).toBeInTheDocument(); | ||
}); | ||
|
||
test("renders correct results with commas", () => { | ||
render(<DataTablePageResults totalRows={1500250} limit={25} offset={0} />); | ||
expect(screen.getByText(/1 - 25 of 1,500,250 rows/)).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.