2018-06-20 15:09:37 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2018-08-01 16:00:45 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { IconButton, ToggleControl } from '@wordpress/components';
|
|
|
|
import { noop } from 'lodash';
|
2018-06-20 15:09:37 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2018-08-01 16:00:45 +00:00
|
|
|
import Card from 'components/card';
|
|
|
|
import { EllipsisMenu, MenuItem, MenuTitle } from 'components/ellipsis-menu';
|
|
|
|
import Pagination from 'components/pagination';
|
|
|
|
import Table from './table';
|
|
|
|
import TableSummary from './summary';
|
2018-06-20 15:09:37 +00:00
|
|
|
|
2018-08-01 16:00:45 +00:00
|
|
|
// @todo Handle toggling columns
|
2018-06-20 15:09:37 +00:00
|
|
|
|
2018-08-01 16:00:45 +00:00
|
|
|
const TableCard = ( {
|
|
|
|
headers,
|
|
|
|
onClickDownload,
|
|
|
|
onQueryChange,
|
|
|
|
query,
|
|
|
|
rows,
|
|
|
|
rowHeader,
|
|
|
|
summary,
|
|
|
|
title,
|
|
|
|
} ) => {
|
|
|
|
return (
|
|
|
|
<Card
|
|
|
|
className="woocommerce-table"
|
|
|
|
title={ title }
|
|
|
|
action={
|
|
|
|
onClickDownload && (
|
|
|
|
<IconButton onClick={ onClickDownload } icon="arrow-down" size={ 18 } isDefault>
|
|
|
|
{ __( 'Download', 'wc-admin' ) }
|
|
|
|
</IconButton>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
menu={
|
|
|
|
<EllipsisMenu label={ __( 'Choose which values to display', 'wc-admin' ) }>
|
|
|
|
<MenuTitle>{ __( 'Columns:', 'wc-admin' ) }</MenuTitle>
|
|
|
|
{ headers.map( ( label, i ) => (
|
|
|
|
<MenuItem key={ i } onInvoke={ noop }>
|
|
|
|
<ToggleControl label={ label } checked={ true } onChange={ noop } />
|
|
|
|
</MenuItem>
|
|
|
|
) ) }
|
|
|
|
</EllipsisMenu>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{ /* @todo Switch a placeholder view if we don't have rows */ }
|
|
|
|
<Table rows={ rows } headers={ headers } rowHeader={ rowHeader } caption={ title } />
|
2018-06-20 15:09:37 +00:00
|
|
|
|
2018-08-01 16:00:45 +00:00
|
|
|
{ summary && <TableSummary data={ summary } /> }
|
2018-07-13 19:36:41 +00:00
|
|
|
|
2018-08-01 16:00:45 +00:00
|
|
|
<Pagination
|
|
|
|
page={ parseInt( query.page ) || 1 }
|
|
|
|
perPage={ parseInt( query.per_page ) || 25 }
|
|
|
|
total={ 5000 }
|
|
|
|
onPageChange={ onQueryChange( 'page' ) }
|
|
|
|
onPerPageChange={ onQueryChange( 'per_page' ) }
|
|
|
|
/>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
2018-06-20 15:09:37 +00:00
|
|
|
|
2018-08-01 16:00:45 +00:00
|
|
|
TableCard.propTypes = {
|
2018-06-20 15:09:37 +00:00
|
|
|
headers: PropTypes.arrayOf( PropTypes.node ),
|
2018-08-01 16:00:45 +00:00
|
|
|
onQueryChange: PropTypes.func,
|
|
|
|
onClickDownload: PropTypes.func,
|
|
|
|
query: PropTypes.object,
|
2018-06-20 15:09:37 +00:00
|
|
|
rowHeader: PropTypes.oneOfType( [ PropTypes.number, PropTypes.bool ] ),
|
2018-08-01 16:00:45 +00:00
|
|
|
rows: PropTypes.arrayOf(
|
|
|
|
PropTypes.arrayOf(
|
|
|
|
PropTypes.shape( {
|
|
|
|
display: PropTypes.node,
|
|
|
|
value: PropTypes.oneOfType( [ PropTypes.string, PropTypes.number, PropTypes.bool ] ),
|
|
|
|
} )
|
|
|
|
)
|
|
|
|
).isRequired,
|
|
|
|
summary: PropTypes.arrayOf(
|
|
|
|
PropTypes.shape( {
|
|
|
|
label: PropTypes.node,
|
|
|
|
value: PropTypes.oneOfType( [ PropTypes.string, PropTypes.number ] ),
|
|
|
|
} )
|
|
|
|
),
|
|
|
|
title: PropTypes.string.isRequired,
|
2018-06-20 15:09:37 +00:00
|
|
|
};
|
|
|
|
|
2018-08-01 16:00:45 +00:00
|
|
|
TableCard.defaultProps = {
|
|
|
|
onQueryChange: noop,
|
|
|
|
query: {},
|
2018-06-20 15:09:37 +00:00
|
|
|
rowHeader: 0,
|
2018-08-01 16:00:45 +00:00
|
|
|
rows: [],
|
2018-06-20 15:09:37 +00:00
|
|
|
};
|
|
|
|
|
2018-08-01 16:00:45 +00:00
|
|
|
export { TableCard, Table, TableSummary };
|