Skip to content

Commit

Permalink
make endpoint more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
andykawabata committed Jul 3, 2024
1 parent 19b4e3e commit 93f49f7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
29 changes: 11 additions & 18 deletions backend/django/core/views/api_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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})



Expand Down
7 changes: 5 additions & 2 deletions frontend/src/actions/adminTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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));
}
});
};
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/AdminTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/containers/adminTable_container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/styles/smart.scss
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,10 @@ li.disabled {
> :first-child {
flex-grow: 1;
display: block !important;

p {
max-width: 500px;
}
}

.irr-card {
Expand Down

0 comments on commit 93f49f7

Please sign in to comment.