This commit is contained in:
Julien Wajsberg 2019-05-03 17:15:31 +02:00
Родитель 620800cd83
Коммит 626c98f170
3 изменённых файлов: 208 добавлений и 70 удалений

Просмотреть файл

@ -15,22 +15,21 @@ const styles = {
};
function desc(a, b, orderBy) {
function propertyComparatorAscending(a, b, orderBy) {
const valueA = a[orderBy];
const valueB = b[orderBy];
// Values can either be strings or objects with a "count" property.
// Case 1: they're strings.
if (typeof valueA === 'string') {
return valueA.localeCompare(valueB);
}
// Case 2: they're objects with a count property.
const countA = valueA ? valueA.count : 0;
const countB = valueB ? valueB.count : 0;
if (countB < countA) {
return -1;
}
if (countB > countA) {
return 1;
}
return 0;
return countA - countB;
}
function stableSort(array, cmp) {
@ -45,9 +44,42 @@ function stableSort(array, cmp) {
}
function getSorting(order, orderBy) {
return order === 'desc' ? (a, b) => desc(a, b, orderBy) : (a, b) => -desc(a, b, orderBy);
return order === 'asc'
? (a, b) => propertyComparatorAscending(a, b, orderBy)
: (a, b) => -propertyComparatorAscending(a, b, orderBy);
}
function TableHeadCell({
metricUid, orderBy, order, label, onClick,
}) {
return (
<TableCell
align="right"
sortDirection={orderBy === metricUid ? order : false}
>
<Tooltip
title="Click to sort the table by this column"
placement="bottom-end"
>
<TableSortLabel
active={orderBy === metricUid}
direction={order}
onClick={onClick}
>
{label}
</TableSortLabel>
</Tooltip>
</TableCell>
);
}
TableHeadCell.propTypes = {
metricUid: PropTypes.string.isRequired,
orderBy: PropTypes.string.isRequired,
order: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
onClick: PropTypes.func.isRequired,
};
class Reportees extends React.PureComponent {
state = {
@ -78,9 +110,18 @@ class Reportees extends React.PureComponent {
handleRequestSort = (event, property) => {
const { order, orderBy } = this.state;
let newOrder = 'desc';
if (orderBy === property && order === 'desc') {
let newOrder;
// If we click on the same column several times in a row, we simply switch
// the prevous value.
if (orderBy === property) {
newOrder = order === 'asc' ? 'desc' : 'asc';
} else if (property === 'cn') {
// For most properties we want to order in the descending order first.
// ... except when sorting by cn.
newOrder = 'asc';
} else {
newOrder = 'desc';
}
this.setState({
@ -93,34 +134,29 @@ class Reportees extends React.PureComponent {
const { classes } = this.props;
const { order, orderBy } = this.state;
const metricsAsArray = Object.entries(CONFIG.reporteesMetrics);
return (
<div className={classes.root}>
<Table>
<TableHead>
<TableRow>
<TableCell />
{Object.entries(CONFIG.reporteesMetrics).map(([metricUid, { label }]) => (
<TableCell
<TableHeadCell
metricUid="cn"
orderBy={orderBy}
order={order}
label="Full Name"
onClick={this.createSortHandler('cn')}
/>
{metricsAsArray.map(([metricUid, { label }]) => (
<TableHeadCell
key={metricUid}
align="right"
sortDirection={orderBy === metricUid ? order : false}
>
<Tooltip
title="Sort"
placement="bottom-end"
>
<TableSortLabel
active={orderBy === metricUid}
direction={order}
onClick={
this.createSortHandler(metricUid)
}
>
{label}
</TableSortLabel>
</Tooltip>
</TableCell>
metricUid={metricUid}
orderBy={orderBy}
order={order}
label={label}
onClick={this.createSortHandler(metricUid)}
/>
))}
</TableRow>
</TableHead>
@ -130,12 +166,12 @@ class Reportees extends React.PureComponent {
getSorting(order, orderBy),
)
.map(({
cn, mail, bugzillaEmail, ...metrics
cn, mail, bugzillaEmail, ...metricsValues
}) => (
<TableRow key={mail}>
<TableCell key={mail}>{`${cn} `}</TableCell>
{Object.keys(CONFIG.reporteesMetrics).map((metricUid) => {
const countLink = metrics[metricUid];
<TableCell key={mail}>{cn}</TableCell>
{metricsAsArray.map(([metricUid]) => {
const countLink = metricsValues[metricUid];
return (
<TableCell align="right" key={metricUid}>
{countLink && (

Просмотреть файл

@ -30,7 +30,7 @@ const config = {
}),
},
assignedTrackedBeta: {
label: 'Assigned and tracked for beta',
label: 'Assigned & Tracked (Beta)',
parameterGenerator: mail => ({
email1: mail,
emailassigned_to1: '1',
@ -45,7 +45,7 @@ const config = {
}),
},
assignedTrackedNightly: {
label: 'Assigned and tracked for nightly',
label: 'Assigned & Tracked (Nightly)',
parameterGenerator: mail => ({
email1: mail,
emailassigned_to1: '1',

Просмотреть файл

@ -14,10 +14,44 @@ exports[`renders Manager who has reportees & metrics 1`] = `
className="MuiTableRow-root-4 MuiTableRow-head-7"
>
<th
aria-sort={null}
className="MuiTableCell-root-9 MuiTableCell-head-10"
aria-sort="ascending"
className="MuiTableCell-root-9 MuiTableCell-head-10 MuiTableCell-alignRight-19"
scope="col"
/>
>
<span
aria-describedby={null}
className="MuiButtonBase-root-34 MuiTableSortLabel-root-29 MuiTableSortLabel-active-30"
onBlur={[Function]}
onClick={[Function]}
onContextMenu={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseOver={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
role="button"
tabIndex="0"
title="Click to sort the table by this column"
>
Full Name
<svg
aria-hidden="true"
className="MuiSvgIcon-root-37 MuiTableSortLabel-icon-31 MuiTableSortLabel-iconDirectionAsc-33"
focusable="false"
role="presentation"
viewBox="0 0 24 24"
>
<path
d="M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z"
/>
</svg>
</span>
</th>
<th
aria-sort={null}
className="MuiTableCell-root-9 MuiTableCell-head-10 MuiTableCell-alignRight-19"
@ -41,7 +75,7 @@ exports[`renders Manager who has reportees & metrics 1`] = `
onTouchStart={[Function]}
role="button"
tabIndex="0"
title="Sort"
title="Click to sort the table by this column"
>
Assigned
<svg
@ -80,7 +114,7 @@ exports[`renders Manager who has reportees & metrics 1`] = `
onTouchStart={[Function]}
role="button"
tabIndex="0"
title="Sort"
title="Click to sort the table by this column"
>
Needinfo
<svg
@ -119,9 +153,9 @@ exports[`renders Manager who has reportees & metrics 1`] = `
onTouchStart={[Function]}
role="button"
tabIndex="0"
title="Sort"
title="Click to sort the table by this column"
>
Assigned and tracked for beta
Assigned & Tracked (Beta)
<svg
aria-hidden="true"
className="MuiSvgIcon-root-37 MuiTableSortLabel-icon-31 MuiTableSortLabel-iconDirectionAsc-33"
@ -158,9 +192,9 @@ exports[`renders Manager who has reportees & metrics 1`] = `
onTouchStart={[Function]}
role="button"
tabIndex="0"
title="Sort"
title="Click to sort the table by this column"
>
Assigned and tracked for nightly
Assigned & Tracked (Nightly)
<svg
aria-hidden="true"
className="MuiSvgIcon-root-37 MuiTableSortLabel-icon-31 MuiTableSortLabel-iconDirectionAsc-33"
@ -186,7 +220,7 @@ exports[`renders Manager who has reportees & metrics 1`] = `
aria-sort={null}
className="MuiTableCell-root-9 MuiTableCell-body-11"
>
Someone
Someone
</td>
<td
aria-sort={null}
@ -240,10 +274,44 @@ exports[`renders Manager who has reportees 1`] = `
className="MuiTableRow-root-4 MuiTableRow-head-7"
>
<th
aria-sort={null}
className="MuiTableCell-root-9 MuiTableCell-head-10"
aria-sort="ascending"
className="MuiTableCell-root-9 MuiTableCell-head-10 MuiTableCell-alignRight-19"
scope="col"
/>
>
<span
aria-describedby={null}
className="MuiButtonBase-root-34 MuiTableSortLabel-root-29 MuiTableSortLabel-active-30"
onBlur={[Function]}
onClick={[Function]}
onContextMenu={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseOver={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
role="button"
tabIndex="0"
title="Click to sort the table by this column"
>
Full Name
<svg
aria-hidden="true"
className="MuiSvgIcon-root-37 MuiTableSortLabel-icon-31 MuiTableSortLabel-iconDirectionAsc-33"
focusable="false"
role="presentation"
viewBox="0 0 24 24"
>
<path
d="M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z"
/>
</svg>
</span>
</th>
<th
aria-sort={null}
className="MuiTableCell-root-9 MuiTableCell-head-10 MuiTableCell-alignRight-19"
@ -267,7 +335,7 @@ exports[`renders Manager who has reportees 1`] = `
onTouchStart={[Function]}
role="button"
tabIndex="0"
title="Sort"
title="Click to sort the table by this column"
>
Assigned
<svg
@ -306,7 +374,7 @@ exports[`renders Manager who has reportees 1`] = `
onTouchStart={[Function]}
role="button"
tabIndex="0"
title="Sort"
title="Click to sort the table by this column"
>
Needinfo
<svg
@ -345,9 +413,9 @@ exports[`renders Manager who has reportees 1`] = `
onTouchStart={[Function]}
role="button"
tabIndex="0"
title="Sort"
title="Click to sort the table by this column"
>
Assigned and tracked for beta
Assigned & Tracked (Beta)
<svg
aria-hidden="true"
className="MuiSvgIcon-root-37 MuiTableSortLabel-icon-31 MuiTableSortLabel-iconDirectionAsc-33"
@ -384,9 +452,9 @@ exports[`renders Manager who has reportees 1`] = `
onTouchStart={[Function]}
role="button"
tabIndex="0"
title="Sort"
title="Click to sort the table by this column"
>
Assigned and tracked for nightly
Assigned & Tracked (Nightly)
<svg
aria-hidden="true"
className="MuiSvgIcon-root-37 MuiTableSortLabel-icon-31 MuiTableSortLabel-iconDirectionAsc-33"
@ -412,7 +480,7 @@ exports[`renders Manager who has reportees 1`] = `
aria-sort={null}
className="MuiTableCell-root-9 MuiTableCell-body-11"
>
Someone
Someone
</td>
<td
aria-sort={null}
@ -450,10 +518,44 @@ exports[`renders Someone with no reportees 1`] = `
className="MuiTableRow-root-4 MuiTableRow-head-7"
>
<th
aria-sort={null}
className="MuiTableCell-root-9 MuiTableCell-head-10"
aria-sort="ascending"
className="MuiTableCell-root-9 MuiTableCell-head-10 MuiTableCell-alignRight-19"
scope="col"
/>
>
<span
aria-describedby={null}
className="MuiButtonBase-root-34 MuiTableSortLabel-root-29 MuiTableSortLabel-active-30"
onBlur={[Function]}
onClick={[Function]}
onContextMenu={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseOver={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
role="button"
tabIndex="0"
title="Click to sort the table by this column"
>
Full Name
<svg
aria-hidden="true"
className="MuiSvgIcon-root-37 MuiTableSortLabel-icon-31 MuiTableSortLabel-iconDirectionAsc-33"
focusable="false"
role="presentation"
viewBox="0 0 24 24"
>
<path
d="M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z"
/>
</svg>
</span>
</th>
<th
aria-sort={null}
className="MuiTableCell-root-9 MuiTableCell-head-10 MuiTableCell-alignRight-19"
@ -477,7 +579,7 @@ exports[`renders Someone with no reportees 1`] = `
onTouchStart={[Function]}
role="button"
tabIndex="0"
title="Sort"
title="Click to sort the table by this column"
>
Assigned
<svg
@ -516,7 +618,7 @@ exports[`renders Someone with no reportees 1`] = `
onTouchStart={[Function]}
role="button"
tabIndex="0"
title="Sort"
title="Click to sort the table by this column"
>
Needinfo
<svg
@ -555,9 +657,9 @@ exports[`renders Someone with no reportees 1`] = `
onTouchStart={[Function]}
role="button"
tabIndex="0"
title="Sort"
title="Click to sort the table by this column"
>
Assigned and tracked for beta
Assigned & Tracked (Beta)
<svg
aria-hidden="true"
className="MuiSvgIcon-root-37 MuiTableSortLabel-icon-31 MuiTableSortLabel-iconDirectionAsc-33"
@ -594,9 +696,9 @@ exports[`renders Someone with no reportees 1`] = `
onTouchStart={[Function]}
role="button"
tabIndex="0"
title="Sort"
title="Click to sort the table by this column"
>
Assigned and tracked for nightly
Assigned & Tracked (Nightly)
<svg
aria-hidden="true"
className="MuiSvgIcon-root-37 MuiTableSortLabel-icon-31 MuiTableSortLabel-iconDirectionAsc-33"
@ -622,7 +724,7 @@ exports[`renders Someone with no reportees 1`] = `
aria-sort={null}
className="MuiTableCell-root-9 MuiTableCell-body-11"
>
Manager
Manager
</td>
<td
aria-sort={null}