From 09880c33f5a7ab7da135d2514e1b6c4a588e3812 Mon Sep 17 00:00:00 2001 From: Caroline Kery Date: Sun, 14 Jul 2024 14:16:00 -0400 Subject: [PATCH 1/3] add an upper bound for label suggestions --- backend/django/core/views/api_annotate.py | 4 +++- frontend/src/components/DataCard/DataCard.jsx | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/backend/django/core/views/api_annotate.py b/backend/django/core/views/api_annotate.py index 295c47b9..b94728e6 100644 --- a/backend/django/core/views/api_annotate.py +++ b/backend/django/core/views/api_annotate.py @@ -94,7 +94,8 @@ def get_labels(request, project_pk): labels: The project labels """ project = Project.objects.get(pk=project_pk) - labels = Label.objects.all().filter(project=project) + labels = Label.objects.filter(project=project) + total_labels = Label.objects.filter(project=project).count() # If the number of labels is > 100, just return the first 100 serialized_labels = LabelSerializer(labels, many=True).data @@ -104,6 +105,7 @@ def get_labels(request, project_pk): return Response( { "labels": serialized_labels, + "total_labels":total_labels } ) diff --git a/frontend/src/components/DataCard/DataCard.jsx b/frontend/src/components/DataCard/DataCard.jsx index efdf36d3..31b9f120 100644 --- a/frontend/src/components/DataCard/DataCard.jsx +++ b/frontend/src/components/DataCard/DataCard.jsx @@ -24,6 +24,7 @@ const DataCard = ({ data, page, actions }) => { const handlers = getHandlers(allHandlers, page); const labelCountLow = (labels) => labels.labels.length <= 5; + const labelCountHigh = (labels) => labels.total_labels >= 500; const show = { skipButton: handlers.handleSkip != null, @@ -31,9 +32,9 @@ const DataCard = ({ data, page, actions }) => { text: true, metadata: true, metadataEdit: page !== PAGES.RECYCLE, - labelButtons: labels && labelCountLow(labels) && handlers.handleSelectLabel != null, - labelSuggestions: labels && !labelCountLow(labels) && handlers.handleSelectLabel != null, - labelSelect: labels && !labelCountLow(labels) && handlers.handleSelectLabel != null, + labelButtons: labels && labelCountLow(labels) && (handlers.handleSelectLabel != null), + labelSuggestions: labels && (!labelCountLow(labels)) && (!labelCountHigh(labels)) && (handlers.handleSelectLabel != null), + labelSelect: labels && (!labelCountLow(labels)) && (handlers.handleSelectLabel != null), discardButton: handlers.handleDiscard != null, confirmationModal: page == PAGES.HISTORY && cardData.labelID // excludes unlabeled data }; @@ -78,6 +79,10 @@ const DataCard = ({ data, page, actions }) => { fn= { handlers.handleSelectLabel } includeModal={show.confirmationModal} /> + + )} + {show.labelSelect && ( +
Date: Sun, 14 Jul 2024 15:59:28 -0400 Subject: [PATCH 2/3] move new setting to settings --- backend/django/core/templates/smart/smart.html | 1 + backend/django/core/views/api_annotate.py | 7 +------ backend/django/core/views/frontend.py | 3 +++ backend/django/smart/settings.py | 1 + frontend/src/components/DataCard/DataCard.jsx | 3 ++- frontend/src/store.js | 2 ++ 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/backend/django/core/templates/smart/smart.html b/backend/django/core/templates/smart/smart.html index 9c84f3be..aa2188de 100644 --- a/backend/django/core/templates/smart/smart.html +++ b/backend/django/core/templates/smart/smart.html @@ -16,6 +16,7 @@ {% endif %} window.ADMIN = {{admin}}; window.PROJECT_USES_IRR = {{project_uses_irr}}; + window.PROJECT_SUGGESTION_MAX = {{project_suggestion_max}}; window.onload = function (e) { $.ajax({ diff --git a/backend/django/core/views/api_annotate.py b/backend/django/core/views/api_annotate.py index b94728e6..65904405 100644 --- a/backend/django/core/views/api_annotate.py +++ b/backend/django/core/views/api_annotate.py @@ -102,12 +102,7 @@ def get_labels(request, project_pk): if len(serialized_labels) > 100: serialized_labels = serialized_labels[:100] - return Response( - { - "labels": serialized_labels, - "total_labels":total_labels - } - ) + return Response({"labels": serialized_labels, "total_labels": total_labels}) @api_view(["GET"]) diff --git a/backend/django/core/views/frontend.py b/backend/django/core/views/frontend.py index 2bc756d9..0256bc89 100644 --- a/backend/django/core/views/frontend.py +++ b/backend/django/core/views/frontend.py @@ -10,6 +10,7 @@ from django.views.generic import DetailView, ListView, TemplateView, View from django.views.generic.edit import DeleteView, UpdateView from formtools.wizard.views import SessionWizardView +from smart.settings import PROJECT_SUGGESTION_MAX from core.forms import ( AdvancedWizardForm, @@ -81,6 +82,8 @@ def get_context_data(self, **kwargs): else: ctx["project_uses_irr"] = "false" + ctx["project_suggestion_max"] = PROJECT_SUGGESTION_MAX + return ctx diff --git a/backend/django/smart/settings.py b/backend/django/smart/settings.py index cdc262c1..7be7c614 100644 --- a/backend/django/smart/settings.py +++ b/backend/django/smart/settings.py @@ -227,6 +227,7 @@ class Dev(Configuration): DATA_UPLOAD_MAX_MEMORY_SIZE = None ADMIN_TIMEOUT_MINUTES = 15 + PROJECT_SUGGESTION_MAX = os.environ.get("PROJECT_SUGGESTION_MAX", 1000) class Prod(Dev): diff --git a/frontend/src/components/DataCard/DataCard.jsx b/frontend/src/components/DataCard/DataCard.jsx index 31b9f120..0b8752a8 100644 --- a/frontend/src/components/DataCard/DataCard.jsx +++ b/frontend/src/components/DataCard/DataCard.jsx @@ -10,6 +10,7 @@ import DataCardText from "./DataCardText"; import { useModifyLabel, useChangeToSkip, useLabels } from "../../hooks"; import DataCardLabelButtons from "./DataCardLabelButtons"; import DataCardDiscardButton from "./DataCardDiscardButton"; +import { PROJECT_SUGGESTION_MAX } from "../../store"; const DataCard = ({ data, page, actions }) => { const { data: labels } = useLabels(); @@ -24,7 +25,7 @@ const DataCard = ({ data, page, actions }) => { const handlers = getHandlers(allHandlers, page); const labelCountLow = (labels) => labels.labels.length <= 5; - const labelCountHigh = (labels) => labels.total_labels >= 500; + const labelCountHigh = (labels) => labels.total_labels >= PROJECT_SUGGESTION_MAX; const show = { skipButton: handlers.handleSkip != null, diff --git a/frontend/src/store.js b/frontend/src/store.js index 1083b2d9..3cd146c3 100644 --- a/frontend/src/store.js +++ b/frontend/src/store.js @@ -4,4 +4,6 @@ export const PROJECT_ID = window.PROJECT_ID; export const PROJECT_USES_IRR = window.PROJECT_USES_IRR; +export const PROJECT_SUGGESTION_MAX = window.PROJECT_SUGGESTION_MAX; + export const queryClient = new QueryClient(); From c6d43f4f00c9ba1aa7903851fc7ef2d2b1c29b8a Mon Sep 17 00:00:00 2001 From: Caroline Kery Date: Wed, 17 Jul 2024 09:48:00 -0400 Subject: [PATCH 3/3] set limit to 10k --- backend/django/smart/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/django/smart/settings.py b/backend/django/smart/settings.py index 7be7c614..fcfde60e 100644 --- a/backend/django/smart/settings.py +++ b/backend/django/smart/settings.py @@ -227,7 +227,7 @@ class Dev(Configuration): DATA_UPLOAD_MAX_MEMORY_SIZE = None ADMIN_TIMEOUT_MINUTES = 15 - PROJECT_SUGGESTION_MAX = os.environ.get("PROJECT_SUGGESTION_MAX", 1000) + PROJECT_SUGGESTION_MAX = os.environ.get("PROJECT_SUGGESTION_MAX", 10000) class Prod(Dev):