Skip to content

Commit

Permalink
Merge pull request #94 from ts4nfdi/fix/ols4-search
Browse files Browse the repository at this point in the history
Fix/ols4 search
  • Loading branch information
rombaum authored Jun 20, 2024
2 parents 9a4f0d1 + 0b7d246 commit 06f47cb
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 21 deletions.
1 change: 1 addition & 0 deletions dist_plainjs/manually_maintained_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ declare global {
initialItemsPerPage?: number;
itemsPerPageOptions?: number[];
targetLink?: string;
useLegacy?: boolean;
} & Partial<Omit<EuiCardProps, "layout">>
)=>void
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export type SearchBarWidgetProps = Omit<EuiSuggestProps, "suggestions" | "onChan
onSearchValueChange: (suggestion: string) => void;
};

export type SearchResultsListWidgetProps = Partial<Omit<EuiCardProps, "layout">> & ApiObj & TargetLinkObj & ParameterObj & {
export type SearchResultsListWidgetProps = Partial<Omit<EuiCardProps, "layout">> & ApiObj & TargetLinkObj & ParameterObj & UseLegacyObj &{
/**
* The terms to search. By default, the search is performed over term labels, synonyms, descriptions, identifiers and annotation properties.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function BreadcrumbPresentation(props: BreadcrumbPresentationProps) {
<>
<span>
<EuiBadge color={props.colorFirst || "primary"}>
{props.ontologyName.toUpperCase()}
{props.ontologyName ? props.ontologyName.toUpperCase() : "No ontology name available"}
</EuiBadge>
{" > "}
<EuiBadge color={props.colorSecond || "success"}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export {
SearchResultsListNFDI4Health,
ErrorSearchResultsList,
TibNFDI4CHEM,
TibDataPlant
TibDataPlant,
SearchResultsListOls4
} from "./SearchResultsListWidgetStories"
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function SearchResultsListWidget(props: SearchResultsListWidgetProps) {
itemsPerPageOptions = DEFAULT_PAGE_SIZE_OPTIONS,
targetLink,
preselected,
useLegacy = true,
...rest
} = props;
const olsApi = new OlsApi(api);
Expand Down Expand Up @@ -130,20 +131,31 @@ function SearchResultsListWidget(props: SearchResultsListWidgetProps) {
if (response["facet_counts"] && response["facet_counts"]["facet_fields"]) {
if (response["facet_counts"]["facet_fields"]["type"]) {
updateFilterOptions(
filterByTypeOptions,
response["facet_counts"]["facet_fields"]["type"],
setFilterByTypeOptions,
(currentValue: string) => `${currentValue[0].toUpperCase()}${currentValue.slice(1)}`
);
}
if (response["facet_counts"]["facet_fields"]["ontology_name"]) {
updateFilterOptions(
filterByOntologyOptions,
response["facet_counts"]["facet_fields"]["ontology_name"],
setFilterByOntologyOptions,
(currentValue: string) => currentValue.toUpperCase()
filterByTypeOptions,
response["facet_counts"]["facet_fields"]["type"],
setFilterByTypeOptions,
(currentValue: string) => `${currentValue[0].toUpperCase()}${currentValue.slice(1)}`
);
}
if (useLegacy) {
if (response["facet_counts"]["facet_fields"]["ontology_name"]) {
updateFilterOptions(
filterByOntologyOptions,
response["facet_counts"]["facet_fields"]["ontology_name"],
setFilterByOntologyOptions,
(currentValue: string) => currentValue.toUpperCase()
);
}
} else {
if (response["facet_counts"]["facet_fields"]["ontologyId"]) {
updateFilterOptions(
filterByOntologyOptions,
response["facet_counts"]["facet_fields"]["ontologyId"],
setFilterByOntologyOptions,
(currentValue: string) => currentValue.toUpperCase()
);
}
}
}

setTotalItems(response["response"]["numFound"]);
Expand Down Expand Up @@ -208,6 +220,7 @@ function SearchResultsListWidget(props: SearchResultsListWidgetProps) {
singleSelection={true}
hasShortSelectedLabel={true}
placeholder={"Search"}
parameter={parameter}
preselected={preselected}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ window['SemLookPWidgets'].createSearchResultsList(
initialItemsPerPage:${args.initialItemsPerPage},
itemsPerPageOptions:[${args.itemsPerPageOptions}],
targetLink:"${args.targetLink}",
useLegacy:"${args.useLegacy}",
},
document.querySelector('#search_results_list_widget_container_${num}')
)
Expand All @@ -44,5 +45,8 @@ window['SemLookPWidgets'].createSearchResultsList(
export {
SearchResultsListSafety,
SearchResultsListNFDI4Health,
ErrorSearchResultsList
ErrorSearchResultsList,
TibNFDI4CHEM,
TibDataPlant,
SearchResultsListOls4
} from "./SearchResultsListWidgetStories"
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export const SearchResultsListWidgetStoryArgTypes = {
parameter: {
type: { required: false }
},
useLegacy: {
type: { required: false }
}
}

export const SearchResultsListWidgetStoryArgs = {
Expand All @@ -36,7 +39,7 @@ export const SearchResultsListSafety = {
api: "https://semanticlookup.zbmed.de/api/",
query: "d*",
targetLink: "",
parameter: "collection=safety",
parameter: "collection=safety&fieldList=description,label,iri,ontology_name,type,short_form",
}
};

Expand All @@ -45,8 +48,9 @@ export const SearchResultsListNFDI4Health = {
api: "https://semanticlookup.zbmed.de/api/",
query: "d*",
targetLink: "",
parameter: "collection=nfdi4health",
parameter: "collection=nfdi4health&fieldList=description,label,iri,ontology_name,type,short_form",
preselected: [{ label: "diabetes" }],
useLegacy: true
}
};

Expand All @@ -62,7 +66,7 @@ export const ErrorSearchResultsList = {
export const TibNFDI4CHEM = {
args: {
api: "https://service.tib.eu/ts4tib/api/",
parameter: "classification=NFDI4CHEM&schema=collection",
parameter: "classification=NFDI4CHEM&schema=collection&fieldList=description,label,iri,ontology_name,type,short_form",
query: "assay",
targetLink: "",
}
Expand All @@ -71,8 +75,18 @@ export const TibNFDI4CHEM = {
export const TibDataPlant = {
args: {
api: "https://service.tib.eu/ts4tib/api/",
parameter: "classification=DataPLANT&schema=collection",
parameter: "classification=DataPLANT&schema=collection&fieldList=description,label,iri,ontology_name,type,short_form",
query: "agriculture",
targetLink: "",
}
};
};

export const SearchResultsListOls4 = {
args: {
api: "https://www.ebi.ac.uk/ols4/api/",
query: "*",
targetLink: "/",
parameter: "",
useLegacy: false
}
};

0 comments on commit 06f47cb

Please sign in to comment.