Skip to content

Commit

Permalink
Remove optional_condition for tables
Browse files Browse the repository at this point in the history
Due to strange behaviour across pages. Solving this for multiple
pages would involve lookups across all items.

See #2044
Closes #3523
  • Loading branch information
jmsmkn committed Sep 4, 2024
1 parent d3ff825 commit 45892a5
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 36 deletions.
11 changes: 2 additions & 9 deletions app/grandchallenge/algorithms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,15 +648,8 @@ class JobsList(PaginatedTableListView):
Column(title="Creator", sort_field="creator__username"),
Column(title="Status", sort_field="status"),
Column(title="Visibility", sort_field="public"),
Column(
title="Comment",
sort_field="comment",
optional_condition=lambda obj: bool(obj.comment),
),
Column(
title="Result",
optional_condition=lambda obj: bool(obj.rendered_result_text),
),
Column(title="Comment", sort_field="comment"),
Column(title="Result"),
Column(title="Results"),
Column(title="Viewer"),
]
Expand Down
6 changes: 1 addition & 5 deletions app/grandchallenge/components/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,7 @@ class CivSetListView(
Column(title=""),
Column(title="Detail"),
Column(title="ID", sort_field="pk"),
Column(
title="Title",
sort_field="title",
optional_condition=lambda obj: bool(obj.title),
),
Column(title="Title", sort_field="title"),
Column(title="Values"),
Column(title="Viewer"),
Column(title="Edit"),
Expand Down
7 changes: 0 additions & 7 deletions app/grandchallenge/datatables/static/js/datatables/list.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ $(document).ready(() => {
],
ajax: {
url: "",
dataSrc: json => {
const table = $("#ajaxDataTable").DataTable();
for (const [index, visible] of json.showColumns.entries()) {
table.column(index).visible(visible);
}
return json.data;
},
},
ordering: true,
});
Expand Down
13 changes: 0 additions & 13 deletions app/grandchallenge/datatables/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections.abc import Callable
from dataclasses import dataclass
from functools import reduce
from operator import or_
Expand Down Expand Up @@ -57,19 +56,12 @@ def draw_response(self, *, form_data):
paginator = self.get_paginator(queryset=data, per_page=page_size)
objects = paginator.page(page)

show_columns = []
for c in self.columns:
show_columns.append(
c.optional_condition is None
or any(c.optional_condition(o) for o in objects)
)
return JsonResponse(
{
"draw": int(form_data.get("draw")),
"recordsTotal": self.object_list.count(),
"recordsFiltered": paginator.count,
"data": self.render_rows(object_list=objects),
"showColumns": show_columns,
}
)

Expand Down Expand Up @@ -103,11 +95,6 @@ class Column:
classes: tuple[str, ...] = ()
identifier: str = ""

# A column will be hidden when the `optional_condition` evaluates to False
# for every object shown in the current list (page). `optional_condition`
# is a function that consumes the current object as argument
optional_condition: Callable | None = None

def __post_init__(self):
if not self.sort_field:
self.classes = (*self.classes, "nonSortable")
2 changes: 0 additions & 2 deletions app/tests/core_tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def test_paginated_table_list_view_get():
"recordsTotal": 0,
"recordsFiltered": 0,
"data": [],
"showColumns": [],
}


Expand All @@ -62,7 +61,6 @@ def test_paginated_table_list_view_post():
"recordsTotal": 0,
"recordsFiltered": 0,
"data": [],
"showColumns": [],
}


Expand Down

0 comments on commit 45892a5

Please sign in to comment.