diff options
author | Quentin Gliech <quentingliech@gmail.com> | 2020-01-24 00:43:02 +0100 |
---|---|---|
committer | Quentin Gliech <quentingliech@gmail.com> | 2020-01-24 01:12:01 +0100 |
commit | fa13550115144a6f39888960a80cc24890f83536 (patch) | |
tree | c84027d0163286c08e72ae3f2cae1eb900e38c3d /webui | |
parent | 9f7953161f3ef8a6081b7950b3cc274e34666116 (diff) | |
download | git-bug-fa13550115144a6f39888960a80cc24890f83536.tar.gz |
webui: enhance the issue list page
This starts some ground work for filtering & moves the pagination logic
in the query params.
Also has a nice loading placeholder.
Diffstat (limited to 'webui')
-rw-r--r-- | webui/package-lock.json | 67 | ||||
-rw-r--r-- | webui/package.json | 6 | ||||
-rw-r--r-- | webui/src/list/BugRow.js | 3 | ||||
-rw-r--r-- | webui/src/list/Filter.js | 32 | ||||
-rw-r--r-- | webui/src/list/List.js | 48 | ||||
-rw-r--r-- | webui/src/list/ListQuery.js | 237 |
6 files changed, 297 insertions, 96 deletions
diff --git a/webui/package-lock.json b/webui/package-lock.json index 34384e95..8e8648b5 100644 --- a/webui/package-lock.json +++ b/webui/package-lock.json @@ -2086,14 +2086,14 @@ } }, "@material-ui/core": { - "version": "4.8.3", - "resolved": "https://registry.npmjs.org/@material-ui/core/-/core-4.8.3.tgz", - "integrity": "sha512-ZJbfJQmkuZCSQTf0nzpfZwizmDdCq8ruZxnPNFnhoKDqgJpMvV8TJRi8vdI9ls1tMuTqxlhyhw8556fxOpWpFQ==", + "version": "4.9.0", + "resolved": "https://registry.npmjs.org/@material-ui/core/-/core-4.9.0.tgz", + "integrity": "sha512-zrrr8mPU5DDBYaVil4uJYauW41PjSn5otn7cqGsmWOY0t90fypr9nNgM7rRJaPz2AP6oRSDx1kBQt2igf5uelg==", "requires": { "@babel/runtime": "^7.4.4", - "@material-ui/styles": "^4.8.2", + "@material-ui/styles": "^4.9.0", "@material-ui/system": "^4.7.1", - "@material-ui/types": "^4.1.1", + "@material-ui/types": "^5.0.0", "@material-ui/utils": "^4.7.1", "@types/react-transition-group": "^4.2.0", "clsx": "^1.0.2", @@ -2114,26 +2114,38 @@ "@babel/runtime": "^7.4.4" } }, + "@material-ui/lab": { + "version": "4.0.0-alpha.40", + "resolved": "https://registry.npmjs.org/@material-ui/lab/-/lab-4.0.0-alpha.40.tgz", + "integrity": "sha512-VwXCNFJKfctu9Ot9XP5u2SSzXpm2Fn7F/o08bUfrJDkMCuRc8MCGVnNhT+guZRZa35rR97uWKc3SGQ/LAv8yEg==", + "requires": { + "@babel/runtime": "^7.4.4", + "@material-ui/utils": "^4.7.1", + "clsx": "^1.0.4", + "prop-types": "^15.7.2", + "react-is": "^16.8.0" + } + }, "@material-ui/styles": { - "version": "4.8.2", - "resolved": "https://registry.npmjs.org/@material-ui/styles/-/styles-4.8.2.tgz", - "integrity": "sha512-r5U+93pkpwQOmHTmwyn2sqTio6PHd873xvSHiKP6fdybAXXX6CZgVvh3W8saZNbYr/QXsS8OHmFv7sYJLt5Yfg==", + "version": "4.9.0", + "resolved": "https://registry.npmjs.org/@material-ui/styles/-/styles-4.9.0.tgz", + "integrity": "sha512-nJHum4RqYBPWsjL/9JET8Z02FZ9gSizlg/7LWVFpIthNzpK6OQ5OSRR4T4x9/p+wK3t1qNn3b1uI4XpnZaPxOA==", "requires": { "@babel/runtime": "^7.4.4", "@emotion/hash": "^0.7.4", - "@material-ui/types": "^4.1.1", + "@material-ui/types": "^5.0.0", "@material-ui/utils": "^4.7.1", "clsx": "^1.0.2", "csstype": "^2.5.2", "hoist-non-react-statics": "^3.2.1", - "jss": "^10.0.0", - "jss-plugin-camel-case": "^10.0.0", - "jss-plugin-default-unit": "^10.0.0", - "jss-plugin-global": "^10.0.0", - "jss-plugin-nested": "^10.0.0", - "jss-plugin-props-sort": "^10.0.0", - "jss-plugin-rule-value-function": "^10.0.0", - "jss-plugin-vendor-prefixer": "^10.0.0", + "jss": "^10.0.3", + "jss-plugin-camel-case": "^10.0.3", + "jss-plugin-default-unit": "^10.0.3", + "jss-plugin-global": "^10.0.3", + "jss-plugin-nested": "^10.0.3", + "jss-plugin-props-sort": "^10.0.3", + "jss-plugin-rule-value-function": "^10.0.3", + "jss-plugin-vendor-prefixer": "^10.0.3", "prop-types": "^15.7.2" } }, @@ -2148,12 +2160,9 @@ } }, "@material-ui/types": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/@material-ui/types/-/types-4.1.1.tgz", - "integrity": "sha512-AN+GZNXytX9yxGi0JOfxHrRTbhFybjUJ05rnsBVjcB+16e466Z0Xe5IxawuOayVZgTBNDxmPKo5j4V6OnMtaSQ==", - "requires": { - "@types/react": "*" - } + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@material-ui/types/-/types-5.0.0.tgz", + "integrity": "sha512-UeH2BuKkwDndtMSS0qgx1kCzSMw+ydtj0xx/XbFtxNSTlXydKwzs5gVW5ZKsFlAkwoOOQ9TIsyoCC8hq18tOwg==" }, "@material-ui/utils": { "version": "4.7.1", @@ -2471,9 +2480,9 @@ "integrity": "sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw==" }, "@types/react": { - "version": "16.9.18", - "resolved": "https://registry.npmjs.org/@types/react/-/react-16.9.18.tgz", - "integrity": "sha512-MvjiKX/kUE8o49ipppg49RDZ97p4XfW1WWksp/UlTUSJpisyhzd62pZAMXxAscFLoxfYOflkGANAnGkSeHTFQg==", + "version": "16.9.19", + "resolved": "https://registry.npmjs.org/@types/react/-/react-16.9.19.tgz", + "integrity": "sha512-LJV97//H+zqKWMms0kvxaKYJDG05U2TtQB3chRLF8MPNs+MQh/H1aGlyDUxjaHvu08EAGerdX2z4LTBc7ns77A==", "requires": { "@types/prop-types": "*", "csstype": "^2.2.0" @@ -12382,9 +12391,9 @@ } }, "popper.js": { - "version": "1.16.0", - "resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.16.0.tgz", - "integrity": "sha512-+G+EkOPoE5S/zChTpmBSSDYmhXJ5PsW8eMhH8cP/CQHMFPBG/kC9Y5IIw6qNYgdJ+/COf0ddY2li28iHaZRSjw==" + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.16.1.tgz", + "integrity": "sha512-Wb4p1J4zyFTbM+u6WuO4XstYx4Ky9Cewe4DWrel7B0w6VVICvPwdOpotjzcf6eD8TsckVnIMNONQyPIUFOUbCQ==" }, "portfinder": { "version": "1.0.25", diff --git a/webui/package.json b/webui/package.json index 5926f547..e1055d75 100644 --- a/webui/package.json +++ b/webui/package.json @@ -3,9 +3,11 @@ "version": "0.1.0", "private": true, "dependencies": { - "@material-ui/core": "^4.3.3", + "@apollo/react-hooks": "^3.1.3", + "@material-ui/core": "^4.9.0", "@material-ui/icons": "^4.2.1", - "@material-ui/styles": "^4.3.3", + "@material-ui/lab": "^4.0.0-alpha.40", + "@material-ui/styles": "^4.9.0", "apollo-boost": "^0.4.7", "graphql": "^14.3.0", "moment": "^2.24.0", diff --git a/webui/src/list/BugRow.js b/webui/src/list/BugRow.js index 23414a36..add5c12f 100644 --- a/webui/src/list/BugRow.js +++ b/webui/src/list/BugRow.js @@ -3,6 +3,7 @@ import TableCell from '@material-ui/core/TableCell/TableCell'; import TableRow from '@material-ui/core/TableRow/TableRow'; import Tooltip from '@material-ui/core/Tooltip/Tooltip'; import ErrorOutline from '@material-ui/icons/ErrorOutline'; +import CheckCircleOutline from '@material-ui/icons/CheckCircleOutline'; import gql from 'graphql-tag'; import React from 'react'; import { Link } from 'react-router-dom'; @@ -18,7 +19,7 @@ const Open = ({ className }) => ( const Closed = ({ className }) => ( <Tooltip title="Closed"> - <ErrorOutline htmlColor="#cb2431" className={className} /> + <CheckCircleOutline htmlColor="#cb2431" className={className} /> </Tooltip> ); diff --git a/webui/src/list/Filter.js b/webui/src/list/Filter.js new file mode 100644 index 00000000..ce457d03 --- /dev/null +++ b/webui/src/list/Filter.js @@ -0,0 +1,32 @@ +import React from 'react'; +import { makeStyles } from '@material-ui/styles'; + +const useStyles = makeStyles(theme => ({ + element: { + ...theme.typography.body2, + color: ({ active }) => (active ? '#333' : '#444'), + padding: theme.spacing(0, 1), + fontWeight: ({ active }) => (active ? 500 : 400), + textDecoration: 'none', + display: 'flex', + alignSelf: ({ end }) => (end ? 'flex-end' : 'auto'), + background: 'none', + border: 'none', + }, + icon: { + paddingRight: theme.spacing(0.5), + }, +})); + +function Filter({ active, children, icon: Icon, end, ...props }) { + const classes = useStyles({ active, end }); + + return ( + <button {...props} className={classes.element}> + {Icon && <Icon fontSize="small" classes={{ root: classes.icon }} />} + <div>{children}</div> + </button> + ); +} + +export default Filter; diff --git a/webui/src/list/List.js b/webui/src/list/List.js index 54b2fe97..63b73545 100644 --- a/webui/src/list/List.js +++ b/webui/src/list/List.js @@ -1,49 +1,17 @@ -import { makeStyles } from '@material-ui/styles'; -import IconButton from '@material-ui/core/IconButton'; import Table from '@material-ui/core/Table/Table'; import TableBody from '@material-ui/core/TableBody/TableBody'; -import KeyboardArrowLeft from '@material-ui/icons/KeyboardArrowLeft'; -import KeyboardArrowRight from '@material-ui/icons/KeyboardArrowRight'; import React from 'react'; import BugRow from './BugRow'; -const useStyles = makeStyles(theme => ({ - main: { - maxWidth: 600, - margin: 'auto', - marginTop: theme.spacing(4), - }, - pagination: { - ...theme.typography.overline, - display: 'flex', - alignItems: 'center', - justifyContent: 'flex-end', - }, -})); - -function List({ bugs, nextPage, prevPage }) { - const classes = useStyles(); - const { hasNextPage, hasPreviousPage } = bugs.pageInfo; +function List({ bugs }) { return ( - <main className={classes.main}> - <Table className={classes.table}> - <TableBody> - {bugs.edges.map(({ cursor, node }) => ( - <BugRow bug={node} key={cursor} /> - ))} - </TableBody> - </Table> - - <div className={classes.pagination}> - <div>Total: {bugs.totalCount}</div> - <IconButton onClick={prevPage} disabled={!hasPreviousPage}> - <KeyboardArrowLeft /> - </IconButton> - <IconButton onClick={nextPage} disabled={!hasNextPage}> - <KeyboardArrowRight /> - </IconButton> - </div> - </main> + <Table> + <TableBody> + {bugs.edges.map(({ cursor, node }) => ( + <BugRow bug={node} key={cursor} /> + ))} + </TableBody> + </Table> ); } diff --git a/webui/src/list/ListQuery.js b/webui/src/list/ListQuery.js index 869bca79..9cbfab67 100644 --- a/webui/src/list/ListQuery.js +++ b/webui/src/list/ListQuery.js @@ -1,19 +1,90 @@ -// @flow -import CircularProgress from '@material-ui/core/CircularProgress'; +import { makeStyles } from '@material-ui/styles'; +import IconButton from '@material-ui/core/IconButton'; +import Toolbar from '@material-ui/core/Toolbar'; +import KeyboardArrowLeft from '@material-ui/icons/KeyboardArrowLeft'; +import KeyboardArrowRight from '@material-ui/icons/KeyboardArrowRight'; +import ErrorOutline from '@material-ui/icons/ErrorOutline'; +import CheckCircleOutline from '@material-ui/icons/CheckCircleOutline'; +import Paper from '@material-ui/core/Paper'; +import Filter from './Filter'; +import Skeleton from '@material-ui/lab/Skeleton'; import gql from 'graphql-tag'; -import React, { useState } from 'react'; -import { Query } from 'react-apollo'; +import React from 'react'; +import { useQuery } from '@apollo/react-hooks'; +import { useLocation, Link } from 'react-router-dom'; import BugRow from './BugRow'; import List from './List'; +const useStyles = makeStyles(theme => ({ + main: { + maxWidth: 800, + margin: 'auto', + marginTop: theme.spacing(4), + marginBottom: theme.spacing(4), + overflow: 'hidden', + }, + pagination: { + ...theme.typography.overline, + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + }, + toolbar: { + backgroundColor: theme.palette.grey['100'], + borderColor: theme.palette.grey['300'], + borderWidth: '1px 0', + borderStyle: 'solid', + margin: theme.spacing(0, -1), + }, + header: { + ...theme.typography.h6, + padding: theme.spacing(2, 4), + }, + spacer: { + flex: 1, + }, + placeholderRow: { + padding: theme.spacing(1), + borderBottomColor: theme.palette.grey['300'], + borderBottomWidth: '1px', + borderBottomStyle: 'solid', + display: 'flex', + alignItems: 'center', + }, + placeholderRowStatus: { + margin: theme.spacing(1, 2), + }, + placeholderRowText: { + flex: 1, + }, + noBug: { + ...theme.typography.h5, + padding: theme.spacing(8), + textAlign: 'center', + borderBottomColor: theme.palette.grey['300'], + borderBottomWidth: '1px', + borderBottomStyle: 'solid', + '& > p': { + margin: '0', + }, + }, +})); + const QUERY = gql` - query($first: Int, $last: Int, $after: String, $before: String) { + query( + $first: Int + $last: Int + $after: String + $before: String + $query: String + ) { defaultRepository { bugs: allBugs( first: $first last: $last after: $after before: $before + query: $query ) { totalCount edges { @@ -35,30 +106,148 @@ const QUERY = gql` ${BugRow.fragment} `; +function editParams(params, callback) { + const cloned = new URLSearchParams(params.toString()); + callback(cloned); + return cloned; +} + +// TODO: factor this out +const Placeholder = ({ count }) => { + const classes = useStyles(); + return ( + <> + {new Array(count).fill(null).map((_, i) => ( + <div key={i} className={classes.placeholderRow}> + <Skeleton + className={classes.placeholderRowStatus} + variant="circle" + width={20} + height={20} + /> + <div className={classes.placeholderRowText}> + <Skeleton height={22} /> + <Skeleton height={24} width="60%" /> + </div> + </div> + ))} + </> + ); +}; + +// TODO: factor this out +const NoBug = () => { + const classes = useStyles(); + return ( + <div className={classes.noBug}> + <ErrorOutline fontSize="large" /> + <p>No results matched your search.</p> + </div> + ); +}; + function ListQuery() { - const [page, setPage] = useState({ first: 10, after: null }); + const classes = useStyles(); + const location = useLocation(); + const params = new URLSearchParams(location.search); + const query = params.get('q'); + const page = { + first: params.get('first'), + last: params.get('last'), + after: params.get('after'), + before: params.get('before'), + }; + + // If nothing set, show the first 10 items + if (!page.first && !page.last) { + page.first = 10; + } const perPage = page.first || page.last; - const nextPage = pageInfo => - setPage({ first: perPage, after: pageInfo.endCursor }); - const prevPage = pageInfo => - setPage({ last: perPage, before: pageInfo.startCursor }); + + const { loading, error, data } = useQuery(QUERY, { + variables: { + ...page, + query, + }, + }); + + let nextPage = null; + let previousPage = null; + let hasNextPage = false; + let hasPreviousPage = false; + let count = 0; + if (!loading && !error && data.defaultRepository.bugs) { + const bugs = data.defaultRepository.bugs; + hasNextPage = bugs.pageInfo.hasNextPage; + hasPreviousPage = bugs.pageInfo.hasPreviousPage; + count = bugs.totalCount; + // This computes the URL for the next page + nextPage = { + ...location, + search: editParams(params, p => { + p.delete('last'); + p.delete('before'); + p.set('first', perPage); + p.set('after', bugs.pageInfo.endCursor); + }).toString(), + }; + // and this for the previous page + previousPage = { + ...location, + search: editParams(params, p => { + p.delete('first'); + p.delete('after'); + p.set('last', perPage); + p.set('before', bugs.pageInfo.startCursor); + }).toString(), + }; + } + + let content; + if (loading) { + content = <Placeholder count={10} />; + } else if (error) { + content = <p>Error: {JSON.stringify(error)}</p>; + } else { + const bugs = data.defaultRepository.bugs; + + if (bugs.totalCount === 0) { + content = <NoBug />; + } else { + content = <List bugs={bugs} />; + } + } return ( - <Query query={QUERY} variables={page}> - {({ loading, error, data }) => { - if (loading) return <CircularProgress />; - if (error) return <p>Error: {error}</p>; - const bugs = data.defaultRepository.bugs; - return ( - <List - bugs={bugs} - nextPage={() => nextPage(bugs.pageInfo)} - prevPage={() => prevPage(bugs.pageInfo)} - /> - ); - }} - </Query> + <Paper className={classes.main}> + <header className={classes.header}>Issues</header> + <Toolbar className={classes.toolbar}> + {/* TODO */} + <Filter active icon={ErrorOutline}> + 123 open + </Filter> + <Filter icon={CheckCircleOutline}>456 closed</Filter> + <div className={classes.spacer} /> + <Filter>Author</Filter> + <Filter>Label</Filter> + <Filter>Sort</Filter> + </Toolbar> + {content} + <div className={classes.pagination}> + <IconButton + component={Link} + to={previousPage} + disabled={!hasPreviousPage} + > + <KeyboardArrowLeft /> + </IconButton> + <div>{loading ? 'Loading' : `Total: ${count}`}</div> + <IconButton component={Link} to={nextPage} disabled={!hasNextPage}> + <KeyboardArrowRight /> + </IconButton> + </div> + </Paper> ); } |