Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Issue #1013 #1070

Merged
merged 7 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
build:
docker:
# specify the version you desire here
- image: cimg/node:19.7.0
- image: cimg/node:17.3.0
environment:
PG_HOST: 127.0.0.1
POSTGRES_DB: gitpay_test
Expand Down
98 changes: 73 additions & 25 deletions frontend/src/components/task/task-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
TableFooter,
TablePagination,
TableRow,
TableSortLabel,
withStyles,
Tooltip,
Chip,
Expand All @@ -31,6 +32,7 @@ import slugify from '@sindresorhus/slugify'
import logoGithub from '../../images/github-logo.png'
import logoBitbucket from '../../images/bitbucket-logo.png'
import Constants from '../../consts'
import _ from 'lodash'

const messages = defineMessages({
firstPageLabel: {
Expand Down Expand Up @@ -155,13 +157,39 @@ const styles = theme => ({
},
})

const tableHeaderMetadata ={
"task.table.head.task": { sortable: true, numeric:false, dataBaseKey:"title" },
"task.table.head.status" : {sortable: true,numeric:false, dataBaseKey:"status" },
"task.table.head.project":{sortable: true,numeric:false, dataBaseKey:"Project.name" },
"task.table.head.value" :{sortable: true,numeric:true, dataBaseKey:"value" },
"task.table.head.labels":{sortable: true,numeric:false, dataBaseKey:"Labels" },
"task.table.head.createdAt":{sortable: true,numeric:false, dataBaseKey:"createdAt" }
}

class CustomPaginationActionsTable extends React.Component {
constructor (props) {
super(props)

this.state = {
page: 0,
rowsPerPage: 10,
sortByField:null,
sortDirection:null, // at starting point of page load
tasksData: props.tasks.data,
}
}

sortHandler = (fieldId, direction) => {
if (tableHeaderMetadata[fieldId].sortable){
const sortedData = _.orderBy(
this.state.tasksData,
o =>{
if (tableHeaderMetadata[fieldId].numeric) return +(_.get(o,(tableHeaderMetadata[fieldId].dataBaseKey).split(".")))
else return _.get(o,(tableHeaderMetadata[fieldId].dataBaseKey).split("."))
},
[direction]
)
this.setState({...this.state, sortByField:fieldId.split(".")[3], sortDirection:direction, tasksData:sortedData})
}
}

Expand All @@ -186,38 +214,58 @@ class CustomPaginationActionsTable extends React.Component {
render () {
const { classes, tasks } = this.props
const { rowsPerPage, page } = this.state
const emptyRows = tasks.data.length ? rowsPerPage - Math.min(rowsPerPage, tasks.data.length - page * rowsPerPage) : 0

const emptyRows = tasks.data.length ? rowsPerPage - Math.min(rowsPerPage, tasks.data.length - page * rowsPerPage) : 0;
const TableCellWithSortLogic = ({fieldId ,defineMessage, sortHandler})=>{
return (
<TableSortLabel
active= { fieldId.split(".")[3] === this.state.sortByField}
direction={ this.state.sortDirection ==="asc" ? "desc" : "asc" }
onClick = {
() => {
this.setState({sortByField : fieldId});
return sortHandler(fieldId, this.state.sortDirection ==="asc" ? "desc" : "asc" )
}
}
>
<FormattedMessage id={fieldId} defineMessage={defineMessage}/>
</TableSortLabel>
)
}
const TableHeadNew = ()=> {
alexanmtz marked this conversation as resolved.
Show resolved Hide resolved
return (
<TableHead>
<TableRow>
<TableCell>
<TableCellWithSortLogic sortHandler={this.sortHandler} fieldId='task.table.head.task' defaultMessage='Task' />
</TableCell>
<TableCell>
<TableCellWithSortLogic sortHandler={this.sortHandler} fieldId='task.table.head.status' defaultMessage='Status' />
</TableCell>
<TableCell>
<TableCellWithSortLogic sortHandler={this.sortHandler} fieldId='task.table.head.project' defaultMessage='Project' />
</TableCell>
<TableCell>
<TableCellWithSortLogic sortHandler={this.sortHandler} fieldId='task.table.head.value' defaultMessage='Value' />
</TableCell>
<TableCell>
<TableCellWithSortLogic sortHandler={this.sortHandler} fieldId='task.table.head.labels' defaultMessage='Labels' />
</TableCell>
<TableCell>
<TableCellWithSortLogic sortHandler={this.sortHandler} fieldId='task.table.head.createdAt' defaultMessage='Created' />
</TableCell>
</TableRow>
</TableHead>
)
}
return (
<Paper className={ classes.root }>
{ tasks.completed && tasks.data.length
? <ReactPlaceholder style={ { marginBottom: 20, padding: 20 } } showLoadingAnimation type='text' rows={ 5 } ready={ tasks.completed }>
<div className={ classes.tableWrapper }>
<Table className={ classes.table }>
<TableHead>
<TableRow>
<TableCell>
<FormattedMessage id='task.table.head.task' defaultMessage='Task' />
</TableCell>
<TableCell>
<FormattedMessage id='task.table.head.status' defaultMessage='Status' />
</TableCell>
<TableCell>
<FormattedMessage id='task.table.head.project' defaultMessage='Project' />
</TableCell>
<TableCell>
<FormattedMessage id='task.table.head.value' defaultMessage='Value' />
</TableCell>
<TableCell>
<FormattedMessage id='task.table.head.labels' defaultMessage='Labels' />
</TableCell>
<TableCell>
<FormattedMessage id='task.table.head.createdAt' defaultMessage='Created' />
</TableCell>
</TableRow>
</TableHead>
<TableHeadNew />
alexanmtz marked this conversation as resolved.
Show resolved Hide resolved
<TableBody>
{ tasks.data.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map(n => {
{ this.state.tasksData.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map(n => {
const assigned = n.Assigns.find(a => a.id === n.assigned)
const assignedUser = assigned && assigned.User
return (
Expand Down