Skip to content

Commit

Permalink
Merge pull request #7 from unicef-drp/feature/825-Review-Listing-Serv…
Browse files Browse the repository at this point in the history
…er-Side

Add scrollable Review List and fix some sorting
  • Loading branch information
danangmassandy authored Aug 3, 2023
2 parents 11e5968 + 5ee86d4 commit bb0b847
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
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 @@ -355,7 +355,9 @@ export default function ReviewList() {
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: {
Expand Down
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']
)

1 comment on commit bb0b847

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report for django_project/dashboard

St.
Category Percentage Covered / Total
🔴 Statements 5.88% 406/6904
🔴 Branches 0.91% 34/3744
🔴 Functions 2.95% 52/1761
🔴 Lines 5.93% 401/6757

Test suite run success

12 tests passing in 5 suites.

Report generated by 🧪jest coverage report action from bb0b847

Please sign in to comment.