fix: add empty table text

This commit is contained in:
Taranto 2020-10-22 09:00:23 +01:00 committed by Josh Harvey
parent 97ffb7bdf1
commit 00387e0862
7 changed files with 81 additions and 48 deletions

View file

@ -1,4 +1,4 @@
import { makeStyles } from '@material-ui/core/styles' import { makeStyles, Box } from '@material-ui/core'
import classnames from 'classnames' import classnames from 'classnames'
import * as R from 'ramda' import * as R from 'ramda'
import React, { useState } from 'react' import React, { useState } from 'react'
@ -17,6 +17,7 @@ import {
Td, Td,
Th Th
} from 'src/components/fake-table/Table' } from 'src/components/fake-table/Table'
import { H4 } from 'src/components/typography'
import { ReactComponent as ExpandClosedIcon } from 'src/styling/icons/action/expand/closed.svg' import { ReactComponent as ExpandClosedIcon } from 'src/styling/icons/action/expand/closed.svg'
import { ReactComponent as ExpandOpenIcon } from 'src/styling/icons/action/expand/open.svg' import { ReactComponent as ExpandOpenIcon } from 'src/styling/icons/action/expand/open.svg'
@ -94,6 +95,8 @@ const DataTable = ({
expandable, expandable,
shouldStartExpanded, shouldStartExpanded,
onClick, onClick,
loading,
emptyText,
...props ...props
}) => { }) => {
const [expanded, setExpanded] = useState(null) const [expanded, setExpanded] = useState(null)
@ -143,38 +146,42 @@ const DataTable = ({
} }
return ( return (
<Table className={classes.table}> <Box display="flex" flex="1" flexDirection="column">
<THead> <Table className={classes.table}>
{elements.map(({ width, className, textAlign, header }, idx) => ( <THead>
<Th {elements.map(({ width, className, textAlign, header }, idx) => (
key={idx} <Th
width={width} key={idx}
className={className}
textAlign={textAlign}>
{header}
</Th>
))}
{expandable && <Th width={expWidth}></Th>}
</THead>
<TBody className={classes.body}>
<AutoSizer disableWidth>
{({ height }) => (
<List
// this has to be in a style because of how the component works
style={{ overflow: 'inherit', outline: 'none' }}
{...props}
height={height}
width={width} width={width}
rowCount={data.length} className={className}
rowHeight={cache.rowHeight} textAlign={textAlign}>
rowRenderer={rowRenderer} {header}
overscanRowCount={50} </Th>
deferredMeasurementCache={cache} ))}
/> {expandable && <Th width={expWidth}></Th>}
)} </THead>
</AutoSizer> <TBody className={classes.body}>
</TBody> {loading && <H4>Loading...</H4>}
</Table> {!loading && R.isEmpty(data) && <H4>{emptyText}</H4>}
<AutoSizer disableWidth>
{({ height }) => (
<List
// this has to be in a style because of how the component works
style={{ overflow: 'inherit', outline: 'none' }}
{...props}
height={height}
width={width}
rowCount={data.length}
rowHeight={cache.rowHeight}
rowRenderer={rowRenderer}
overscanRowCount={50}
deferredMeasurementCache={cache}
/>
)}
</AutoSizer>
</TBody>
</Table>
</Box>
) )
} }

View file

@ -92,7 +92,7 @@ const CustomerProfile = memo(() => {
const history = useHistory() const history = useHistory()
const { id: customerId } = useParams() const { id: customerId } = useParams()
const { data: customerResponse, refetch: getCustomer } = useQuery( const { data: customerResponse, refetch: getCustomer, loading } = useQuery(
GET_CUSTOMER, GET_CUSTOMER,
{ {
variables: { customerId } variables: { customerId }
@ -171,7 +171,7 @@ const CustomerProfile = memo(() => {
/> />
</Box> </Box>
</div> </div>
<TransactionsList data={sortedTransactions} /> <TransactionsList data={sortedTransactions} loading={loading} />
</> </>
) )
}) })

View file

@ -24,7 +24,7 @@ const GET_CUSTOMERS = gql`
const Customers = () => { const Customers = () => {
const history = useHistory() const history = useHistory()
const { data: customersResponse } = useQuery(GET_CUSTOMERS) const { data: customersResponse, loading } = useQuery(GET_CUSTOMERS)
const handleCustomerClicked = customer => const handleCustomerClicked = customer =>
history.push(`/compliance/customer/${customer.id}`) history.push(`/compliance/customer/${customer.id}`)
@ -33,7 +33,13 @@ const Customers = () => {
R.path(['customers'])(customersResponse) ?? [] R.path(['customers'])(customersResponse) ?? []
) )
return <CustomersList data={customersData} onClick={handleCustomerClicked} /> return (
<CustomersList
data={customersData}
onClick={handleCustomerClicked}
loading={loading}
/>
)
} }
export default Customers export default Customers

View file

@ -14,7 +14,7 @@ import styles from './CustomersList.styles'
const useStyles = makeStyles(styles) const useStyles = makeStyles(styles)
const CustomersList = ({ data, onClick }) => { const CustomersList = ({ data, onClick, loading }) => {
const classes = useStyles() const classes = useStyles()
const elements = [ const elements = [
@ -75,7 +75,13 @@ const CustomersList = ({ data, onClick }) => {
{ label: 'Cash-out', icon: <TxOutIcon /> } { label: 'Cash-out', icon: <TxOutIcon /> }
]} ]}
/> />
<DataTable elements={elements} data={data} onClick={onClick} /> <DataTable
loading={loading}
emptyText="No customers so far"
elements={elements}
data={data}
onClick={onClick}
/>
</> </>
) )
} }

View file

@ -15,7 +15,7 @@ import mainStyles from '../CustomersList.styles'
const useStyles = makeStyles(mainStyles) const useStyles = makeStyles(mainStyles)
const TransactionsList = ({ data }) => { const TransactionsList = ({ data, loading }) => {
const classes = useStyles() const classes = useStyles()
const hasData = !(R.isEmpty(data) || R.isNil(data)) const hasData = !(R.isEmpty(data) || R.isNil(data))
@ -82,7 +82,9 @@ const TransactionsList = ({ data }) => {
<div className={classes.titleWrapper}> <div className={classes.titleWrapper}>
<div className={classes.titleAndButtonsContainer}> <div className={classes.titleAndButtonsContainer}>
<H4> <H4>
{hasData {loading
? 'Loading'
: hasData
? 'All transactions from this customer' ? 'All transactions from this customer'
: 'No transactions so far'} : 'No transactions so far'}
</H4> </H4>

View file

@ -1,5 +1,5 @@
import { useQuery } from '@apollo/react-hooks' import { useQuery } from '@apollo/react-hooks'
import { makeStyles } from '@material-ui/core/styles' import { makeStyles } from '@material-ui/core'
import BigNumber from 'bignumber.js' import BigNumber from 'bignumber.js'
import gql from 'graphql-tag' import gql from 'graphql-tag'
import moment from 'moment' import moment from 'moment'
@ -54,7 +54,7 @@ const GET_TRANSACTIONS = gql`
const Transactions = () => { const Transactions = () => {
const classes = useStyles() const classes = useStyles()
const { data: txResponse } = useQuery(GET_TRANSACTIONS, { const { data: txResponse, loading } = useQuery(GET_TRANSACTIONS, {
variables: { variables: {
limit: NUM_LOG_RESULTS limit: NUM_LOG_RESULTS
} }
@ -160,6 +160,8 @@ const Transactions = () => {
</div> </div>
</div> </div>
<DataTable <DataTable
loading={loading}
emptyText="No transactions so far"
elements={elements} elements={elements}
data={R.path(['transactions'])(txResponse)} data={R.path(['transactions'])(txResponse)}
Details={DetailsRow} Details={DetailsRow}

View file

@ -6,11 +6,11 @@ import React, { useState } from 'react'
import { v4 } from 'uuid' import { v4 } from 'uuid'
import Tooltip from 'src/components/Tooltip' import Tooltip from 'src/components/Tooltip'
import { Link } from 'src/components/buttons' import { Link, Button } from 'src/components/buttons'
import { Table as EditableTable } from 'src/components/editableTable' import { Table as EditableTable } from 'src/components/editableTable'
import { Switch } from 'src/components/inputs' import { Switch } from 'src/components/inputs'
import TitleSection from 'src/components/layout/TitleSection' import TitleSection from 'src/components/layout/TitleSection'
import { P, Label2 } from 'src/components/typography' import { P, Label2, H2 } from 'src/components/typography'
import { fromNamespace, toNamespace, namespaces } from 'src/utils/config' import { fromNamespace, toNamespace, namespaces } from 'src/utils/config'
import styles from './Triggers.styles' import styles from './Triggers.styles'
@ -36,7 +36,7 @@ const Triggers = () => {
const [wizard, setWizard] = useState(false) const [wizard, setWizard] = useState(false)
const [error, setError] = useState(false) const [error, setError] = useState(false)
const { data } = useQuery(GET_INFO) const { data, loading } = useQuery(GET_INFO)
const triggers = fromServer(data?.config?.triggers ?? []) const triggers = fromServer(data?.config?.triggers ?? [])
const complianceConfig = const complianceConfig =
@ -108,9 +108,11 @@ const Triggers = () => {
className={classes.tableWidth} className={classes.tableWidth}
display="flex" display="flex"
justifyContent="end"> justifyContent="end">
<Link color="primary" onClick={() => setWizard(true)}> {!loading && !R.isEmpty(triggers) && (
+ Add new trigger <Link color="primary" onClick={() => setWizard(true)}>
</Link> + Add new trigger
</Link>
)}
</Box> </Box>
<EditableTable <EditableTable
data={triggers} data={triggers}
@ -131,6 +133,14 @@ const Triggers = () => {
onClose={() => setWizard(null)} onClose={() => setWizard(null)}
/> />
)} )}
{!loading && R.isEmpty(triggers) && (
<Box display="flex" alignItems="center" flexDirection="column" mt={15}>
<H2>
It seems there are no active compliance triggers on your network
</H2>
<Button onClick={() => setWizard(true)}>Add first trigger</Button>
</Box>
)}
</> </>
) )
} }