Skip to content

Commit

Permalink
use a lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
shapiromatron committed Sep 10, 2024
1 parent 066b816 commit 6e0f54d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
2 changes: 2 additions & 0 deletions frontend/animal/EndpointForm/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const termUrlLookupMap = {
"effect_term_id-2": "/vocab/api/toxrefdb/effect/?format=json",
"effect_subtype_term_id-2": "/vocab/api/toxrefdb/effect_subtype/?format=json",
"name_term_id-2": "/vocab/api/toxrefdb/endpoint_name/?format=json",
"id-lookup-1": "/vocab/api/ehv/:id/endpoint-name-lookup/",
"id-lookup-2": "/vocab/api/toxrefdb/:id/endpoint-name-lookup/",
},
termUrlLookup = function(term, vocab) {
return termUrlLookupMap[`${term}-${vocab}`];
Expand Down
4 changes: 3 additions & 1 deletion frontend/animal/EndpointForm/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import _ from "lodash";
import {action, computed, observable} from "mobx";
import h from "shared/utils/helpers";

import {termUrlLookup} from "./constants";

const fields = ["system", "organ", "effect", "effect_subtype", "name"];

class EndpointFormStore {
Expand Down Expand Up @@ -34,7 +36,7 @@ class EndpointFormStore {

@action.bound
endpointNameLookup(val) {
const url = this.config.vocabulary_api.replace("9999", val);
const url = termUrlLookup("id-lookup", this.config.vocabulary).replace(":id", val);

if (!val) {
return;
Expand Down
1 change: 0 additions & 1 deletion hawc/apps/animal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,6 @@ def get_vocabulary_settings(cls, assessment: Assessment, form: ModelForm) -> str
return json.dumps(
{
"vocabulary": vocab.value if vocab else None,
"vocabulary_api": vocab.api_root if vocab else None,
"vocabulary_display": vocab.display_name if vocab else None,
"object": {
"system": form["system"].value() or "",
Expand Down
8 changes: 0 additions & 8 deletions hawc/apps/vocab/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ class VocabularyNamespace(IntegerChoices):
def display_choices(cls) -> list:
return [(item, item.display_name) for item in cls]

@property
def api_root(self) -> str:
match self:
case self.EHV:
return reverse("vocab:api:ehv-endpoint-name-lookup", args=(9999,))
case self.ToxRefDB:
return reverse("vocab:api:toxrefdb-endpoint-name-lookup", args=(9999,))

@property
def display_url(self) -> str:
match self:
Expand Down

0 comments on commit 6e0f54d

Please sign in to comment.