From 5ee86d440ef6dca38b2cb9ecd9a8adba8a5ac04e Mon Sep 17 00:00:00 2001 From: Zakki Date: Thu, 3 Aug 2023 11:56:15 +0700 Subject: [PATCH] Add scrollable Review List and fix some sorting --- django_project/dashboard/api_views/reviews.py | 30 ++++++++++--------- django_project/dashboard/api_views/views.py | 5 ++++ .../dashboard/src/views/Review/List.tsx | 4 ++- .../dashboard/src/views/View/Views.tsx | 6 ---- .../tests/test_review_filter_value.py | 2 +- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/django_project/dashboard/api_views/reviews.py b/django_project/dashboard/api_views/reviews.py index c96632cb..405a48c4 100644 --- a/django_project/dashboard/api_views/reviews.py +++ b/django_project/dashboard/api_views/reviews.py @@ -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 @@ -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): @@ -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 @@ -246,6 +248,7 @@ def post(self, request, *args, **kwargs): paginated_entities, many=True ).data + output = output return Response({ 'count': paginator.count, 'page': page, @@ -295,7 +298,6 @@ def fetch_dataset(self): def fetch_status(self): return [ APPROVED, - REJECTED, 'Pending' ] diff --git a/django_project/dashboard/api_views/views.py b/django_project/dashboard/api_views/views.py index 7df6c90b..13837242 100644 --- a/django_project/dashboard/api_views/views.py +++ b/django_project/dashboard/api_views/views.py @@ -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 diff --git a/django_project/dashboard/src/views/Review/List.tsx b/django_project/dashboard/src/views/Review/List.tsx index 895f96c0..6df149d1 100644 --- a/django_project/dashboard/src/views/Review/List.tsx +++ b/django_project/dashboard/src/views/Review/List.tsx @@ -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: { diff --git a/django_project/dashboard/src/views/View/Views.tsx b/django_project/dashboard/src/views/View/Views.tsx index 18ed96fe..b4db5440 100644 --- a/django_project/dashboard/src/views/View/Views.tsx +++ b/django_project/dashboard/src/views/View/Views.tsx @@ -215,7 +215,6 @@ export default function Views() { useEffect(() => { const fetchFilterValuesData = async () => { - let filterVals: any = {} if (filterValues.mode.length > 0 ) { filterVals = filterValues @@ -435,11 +434,6 @@ export default function Views() { onTableChange: (action: string, tableState: any) => onTableChangeState(action, tableState), customSearchRender: debounceSearchRender(500), selectableRows: 'none', - onRowSelectionChange: (currentRowsSelected: Array, allRowsSelected: Array, rowsSelected: Array) => { - console.log(currentRowsSelected) - console.log(allRowsSelected) - console.log(rowsSelected) - }, tableBodyHeight: `${tableHeight}px`, tableBodyMaxHeight: `${tableHeight}px`, textLabels: { diff --git a/django_project/dashboard/tests/test_review_filter_value.py b/django_project/dashboard/tests/test_review_filter_value.py index 91e9b904..145571f2 100644 --- a/django_project/dashboard/tests/test_review_filter_value.py +++ b/django_project/dashboard/tests/test_review_filter_value.py @@ -136,5 +136,5 @@ def test_list_status(self): response = list_view(request, 'status') self.assertEquals( response.data, - [APPROVED, REJECTED, 'Pending'] + [APPROVED, 'Pending'] )