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

Add scrollable Review List and fix some sorting #7

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 16 additions & 14 deletions django_project/dashboard/api_views/reviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,12 @@ def _filter_queryset(self, queryset, request):
if 'status' in dict(request.data):
filter_values = sorted(dict(request.data).get('status', []))
if not filter_values or \
filter_values == [APPROVED, 'Pending', REJECTED]:
filter_values == [APPROVED, 'Pending']:
return queryset.filter(**filter_kwargs)

non_pending_filter_combinations = [
[APPROVED],
[REJECTED],
[APPROVED, REJECTED]
[REJECTED]
]
pending_status = [
choice[0] for choice in EntityUploadStatus.STATUS_CHOICES if
Expand All @@ -181,17 +180,8 @@ def _filter_queryset(self, queryset, request):
]
}
)
elif REJECTED in filter_values:
filter_kwargs.update(
{
'status__in': [
*pending_status, REJECTED
]
}
)
else:
filter_kwargs.update({'status__in': [pending_status]})

filter_kwargs.update({'status__in': pending_status})
return queryset.filter(**filter_kwargs)

def _search_queryset(self, queryset, request):
Expand Down Expand Up @@ -219,6 +209,18 @@ def _sort_queryset(self, queryset, request):
sort_by = 'id'
if not sort_direction:
sort_direction = 'asc'

ordering_mapping = {
'level_0_entity': 'revised_geographical_entity__label',
'upload': 'upload_session__source',
'revision': 'revised_geographical_entity__revision_number',
'dataset': 'upload_session__dataset__label',
'start_date': 'upload_session__started_at',
'submitted_by': 'upload_session__uploader__username',
'module': 'upload_session__dataset__module__name',
'is_comparison_ready': 'comparison_data_ready',
}
sort_by = ordering_mapping.get(sort_by, sort_by)
ordering = sort_by if sort_direction == 'asc' else f"-{sort_by}"
queryset = queryset.order_by(ordering)
return queryset
Expand Down Expand Up @@ -246,6 +248,7 @@ def post(self, request, *args, **kwargs):
paginated_entities,
many=True
).data
output = output
return Response({
'count': paginator.count,
'page': page,
Expand Down Expand Up @@ -295,7 +298,6 @@ def fetch_dataset(self):
def fetch_status(self):
return [
APPROVED,
REJECTED,
'Pending'
]

Expand Down
5 changes: 5 additions & 0 deletions django_project/dashboard/api_views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ def _sort_queryset(self, queryset, request):
sort_by = 'name'
if not sort_direction:
sort_direction = 'asc'

ordering_mapping = {
'dataset': 'dataset__label'
}
sort_by = ordering_mapping.get(sort_by, sort_by)
ordering = sort_by if sort_direction == 'asc' else f"-{sort_by}"
queryset = queryset.order_by(ordering)
return queryset
Expand Down
4 changes: 3 additions & 1 deletion django_project/dashboard/src/views/Review/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,79 +293,81 @@
navigate(`/${moduleName}/review_detail?id=${rowData[0]}`)
}

return (
loading ?
<div className={"loading-container"}><Loading/></div> :
<div className="AdminContentMain review-list main-data-list">
<Fragment>
<div className='AdminList' ref={ref}>
<ResizeTableEvent containerRef={ref} onBeforeResize={() => setTableHeight(0)}
onResize={(clientHeight: number) => setTableHeight(clientHeight - TABLE_OFFSET_HEIGHT)}/>
<div className='AdminTable'>
<MUIDataTable
title=''
data={data}
columns={columns}
options={{
serverSide: true,
page: pagination.page,
count: totalCount,
rowsPerPage: pagination.rowsPerPage,
rowsPerPageOptions: rowsPerPageOptions,
sortOrder: pagination.sortOrder as MUISortOptions,
jumpToPage: true,
isRowSelectable: (dataIndex: number, selectedRows: any) => {
return canRowBeSelected(dataIndex, data[dataIndex])
},
onRowSelectionChange: (currentRowsSelected, allRowsSelected, rowsSelected) => {
// @ts-ignore
const rowDataSelected = rowsSelected.map((index) => data[index]['id'])
selectionChanged(rowDataSelected)
},
onRowClick: (rowData: string[], rowMeta: { dataIndex: number, rowIndex: number }) => {
handleRowClick(rowData, rowMeta)
},
onTableChange: (action: string, tableState: any) => onTableChangeState(action, tableState),
customSearchRender: debounceSearchRender(500),
selectableRows: selectableRowsMode,
selectToolbarPlacement: 'none',
textLabels: {
body: {
noMatch: loading ?
<Loading/> :
'Sorry, there is no matching data to display',
},
},
onSearchChange: (searchText: string) => {
handleSearchOnChange(searchText)
},
customFilterDialogFooter: (currentFilterList, applyNewFilters) => {
return (
<div style={{marginTop: '40px'}}>
<Button variant="contained" onClick={() => handleFilterSubmit(applyNewFilters)}>Apply
Filters</Button>
</div>
);
},
onFilterChange: (column, filterList, type) => {
var newFilters = () => (filterList)
handleFilterSubmit(newFilters)
},
searchText: currentFilters.search_text,
searchOpen: (currentFilters.search_text != null && currentFilters.search_text.length > 0),
filter: true,
filterType: 'multiselect',
confirmFilters: true
confirmFilters: true,
tableBodyHeight: `${tableHeight}px`,
tableBodyMaxHeight: `${tableHeight}px`,
}}
components={{
icons: {
FilterIcon
}
}}
/>
</div>
</div>
</Fragment>
</div>

Check warning on line 371 in django_project/dashboard/src/views/Review/List.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
)

Check warning on line 372 in django_project/dashboard/src/views/Review/List.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}
6 changes: 0 additions & 6 deletions django_project/dashboard/src/views/View/Views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ export default function Views() {

useEffect(() => {
const fetchFilterValuesData = async () => {

let filterVals: any = {}
if (filterValues.mode.length > 0 ) {
filterVals = filterValues
Expand Down Expand Up @@ -435,11 +434,6 @@ export default function Views() {
onTableChange: (action: string, tableState: any) => onTableChangeState(action, tableState),
customSearchRender: debounceSearchRender(500),
selectableRows: 'none',
onRowSelectionChange: (currentRowsSelected: Array<any>, allRowsSelected: Array<any>, rowsSelected: Array<any>) => {
console.log(currentRowsSelected)
console.log(allRowsSelected)
console.log(rowsSelected)
},
tableBodyHeight: `${tableHeight}px`,
tableBodyMaxHeight: `${tableHeight}px`,
textLabels: {
Expand Down
2 changes: 1 addition & 1 deletion django_project/dashboard/tests/test_review_filter_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,5 @@ def test_list_status(self):
response = list_view(request, 'status')
self.assertEquals(
response.data,
[APPROVED, REJECTED, 'Pending']
[APPROVED, 'Pending']
)
Loading