Skip to content

Commit

Permalink
Merge pull request #350 from RTIInternational/disable_large_project_s…
Browse files Browse the repository at this point in the history
…uggestions

Disable large project suggestions
  • Loading branch information
AstridKery committed Jul 25, 2024
2 parents ae860a4 + 57ed9b8 commit 6aab45a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions backend/django/core/templates/smart/smart.html
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
9 changes: 3 additions & 6 deletions backend/django/core/views/api_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,15 @@ 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
if len(serialized_labels) > 100:
serialized_labels = serialized_labels[:100]

return Response(
{
"labels": serialized_labels,
}
)
return Response({"labels": serialized_labels, "total_labels": total_labels})


@api_view(["GET"])
Expand Down
3 changes: 3 additions & 0 deletions backend/django/core/views/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions backend/django/smart/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", 10000)


class Prod(Dev):
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/components/DataCard/DataCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -24,16 +25,17 @@ const DataCard = ({ data, page, actions }) => {
const handlers = getHandlers(allHandlers, page);

const labelCountLow = (labels) => labels.labels.length <= 5;
const labelCountHigh = (labels) => labels.total_labels >= PROJECT_SUGGESTION_MAX;

const show = {
skipButton: handlers.handleSkip != null,
adjudicateButton: handlers.handleAdjudicate != null,
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
};
Expand Down Expand Up @@ -78,6 +80,10 @@ const DataCard = ({ data, page, actions }) => {
fn= { handlers.handleSelectLabel }
includeModal={show.confirmationModal}
/>
</Fragment>
)}
{show.labelSelect && (
<Fragment>
<div className="select-discard-wrapper" >
<div className="toolbar-gap" />
<DataCardSelectLabel
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 6aab45a

Please sign in to comment.