From 93f49f795e35307896921df34482faa43b722c4b Mon Sep 17 00:00:00 2001 From: andykawabata Date: Wed, 3 Jul 2024 10:57:01 -0400 Subject: [PATCH] make endpoint more generic --- backend/django/core/views/api_admin.py | 29 +++++++------------ frontend/src/actions/adminTables.js | 7 +++-- frontend/src/components/AdminTable/index.jsx | 12 ++++---- .../src/containers/adminTable_container.jsx | 2 +- frontend/src/styles/smart.scss | 4 +++ 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/backend/django/core/views/api_admin.py b/backend/django/core/views/api_admin.py index 979d5492..f574a368 100644 --- a/backend/django/core/views/api_admin.py +++ b/backend/django/core/views/api_admin.py @@ -5,6 +5,7 @@ from postgres_stats.aggregates import Percentile from rest_framework.decorators import api_view, permission_classes from rest_framework.response import Response +from core.serializers import IRRLogModelSerializer from core.models import ( AssignedData, @@ -289,29 +290,21 @@ def perc_agree_table(request, project_pk): @api_view(["GET"]) @permission_classes((IsAdminOrCreator,)) def irr_log(request, project_pk): - """Gets IRR user labels for a project. - Only gets IRR logs with label disagreements i.e. data in the admin queue.""" + """ + Gets IRR user labels for a project. Optionally filters to include only + logs with label disagreements (i.e., data in the admin queue) based on a query parameter. + """ project = Project.objects.get(pk=project_pk) - irr_logs = IRRLog.objects.filter( - data__project=project, - data__queues__type='admin' - ) - - data_labels = {} - - for log in irr_logs: - data_id = log.data_id - username = log.profile.user.username - label_id = log.label_id + admin_queue_only = request.query_params.get('admin', 'false').lower() == 'true' - if data_id not in data_labels: - data_labels[data_id] = {"data_id": data_id} - data_labels[data_id][username] = label_id + irr_log = IRRLog.objects.filter(data__project=project) + if admin_queue_only: + irr_log = irr_log.filter(data__queues__type='admin') - response_data = list(data_labels.values()) + irr_log_serialized = IRRLogModelSerializer(irr_log, many=True).data - return Response({"data": response_data}) + return Response({"irr_log": irr_log_serialized}) diff --git a/frontend/src/actions/adminTables.js b/frontend/src/actions/adminTables.js index c20b54de..f5ec30c9 100644 --- a/frontend/src/actions/adminTables.js +++ b/frontend/src/actions/adminTables.js @@ -54,8 +54,11 @@ export const getAdmin = (projectID) => { }; }; -export const getIrrLog = (projectID) => { +export const getIrrLog = (projectID, adminOnly = false) => { let apiURL = `/api/irr_log/${projectID}/`; + + if (adminOnly) apiURL += '?admin=true'; + return dispatch => { return fetch(apiURL, getConfig()) .then(response => { @@ -71,7 +74,7 @@ export const getIrrLog = (projectID) => { if ('error' in response) { return dispatch(setMessage(response.error)); } else { - dispatch(set_irr_log(response.data)); + dispatch(set_irr_log(response.irr_log)); } }); }; diff --git a/frontend/src/components/AdminTable/index.jsx b/frontend/src/components/AdminTable/index.jsx index d7f89785..872db43c 100644 --- a/frontend/src/components/AdminTable/index.jsx +++ b/frontend/src/components/AdminTable/index.jsx @@ -31,16 +31,16 @@ class AdminTable extends React.Component { const { admin_data, irr_log, labels, message, adminLabel, discardData } = this.props; const getIrrEntry = data_id => { - const irr_entry = irr_log.find(entry => entry.data_id === data_id); + const relevant_irr_entries = irr_log.filter(entry => entry.data === data_id); const irr_entry_formatted = {}; - for (let user in irr_entry) { - if (user === "data_id") continue; - const label_id = irr_entry[user]; + for (let entry of relevant_irr_entries) { + const username = entry.profile; + const label_id = entry.label; if (!label_id) { // situation where the irr data was adjudicated instead of labeled - irr_entry_formatted[user] = { name: "", description: "" }; + irr_entry_formatted[username] = { name: "", description: "" }; } else { - irr_entry_formatted[user] = labels.find(label => label.pk === label_id); + irr_entry_formatted[username] = labels.find(label => label.pk === label_id); } } return irr_entry_formatted; diff --git a/frontend/src/containers/adminTable_container.jsx b/frontend/src/containers/adminTable_container.jsx index 1facbf5b..51f57e51 100644 --- a/frontend/src/containers/adminTable_container.jsx +++ b/frontend/src/containers/adminTable_container.jsx @@ -27,7 +27,7 @@ const mapDispatchToProps = (dispatch) => { dispatch(getAdmin(PROJECT_ID)); }, getIrrLog: () => { - dispatch(getIrrLog(PROJECT_ID)); + dispatch(getIrrLog(PROJECT_ID, true)); }, discardData: (dataID) => { dispatch(discardData(dataID, PROJECT_ID)); diff --git a/frontend/src/styles/smart.scss b/frontend/src/styles/smart.scss index ea2752d5..f86b87ed 100644 --- a/frontend/src/styles/smart.scss +++ b/frontend/src/styles/smart.scss @@ -758,6 +758,10 @@ li.disabled { > :first-child { flex-grow: 1; display: block !important; + + p { + max-width: 500px; + } } .irr-card {