Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourcesWidget Logos and details toggle #164

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
55 changes: 39 additions & 16 deletions src/api/OlsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Select } from "../model/interfaces/Select";
import { OLSSelectResult } from "../model/ols-model/OLSSelectResult";
import { Ts4nfdiSearchResult } from "../model/ts4nfdi-model/Ts4nfdiSearchResult";
import { EntityData } from "../app/types";
import {OLS4Ontologies} from "../model/ols4-model";

// used to filter entities not be shown in hierarchy
function isTop(iri: string): boolean {
Expand Down Expand Up @@ -205,36 +206,58 @@ export class OlsApi implements HierarchyBuilder {
return this.check_for_errors(response);
}

public getOntologies: apiCallFn = async (paginationParams, sortingParams, contentParams, parameter) => {
return this.makeCall("ontologies", { params: this.buildParamsForGet(paginationParams, sortingParams, contentParams, parameter) }, true);
public getOntologies: apiCallFn = async (paginationParams, sortingParams, contentParams, parameter, useLegacy = true) => {
return this.makeCall("ontologies", { params: this.buildParamsForGet(paginationParams, sortingParams, contentParams, parameter) }, useLegacy);
}

/**
* Fetch all ontologies. Currently only available for useLegacy since parameters aren't allowed in the OLS v2 API ontologies endpoint
* @param parameter
* @param useLegacy
*/
public async getOntologiesData(parameter?: string): Promise<Ontologies> {
public async getOntologiesData(parameter?: string, useLegacy = true): Promise<Ontologies> {
let response;
let ontologiesData: OLS3Ontology[] = [];
let ontologiesData: Ontology[] = [];

let pageNum = 0;
const pageSize = 500;

do {
response = await this.getOntologies({ size: pageSize.toString(), page: pageNum.toString() }, undefined, undefined, parameter); // assuming there are no more than 500 ontologies
if (!response || !response["_embedded"] || !response["_embedded"]["ontologies"]) {
throw new Error("Ontologies data not found"); //TODO consistent error handling
} else {
if(useLegacy) {
do {
response = await this.getOntologies({ size: pageSize.toString(), page: pageNum.toString() }, undefined, undefined, parameter, useLegacy); // assuming there are no more than 500 ontologies

ontologiesData = ontologiesData.concat(response["_embedded"]["ontologies"].map((ontologyData: any) => {
return createModelObject(ontologyData);
}));
}
if (!response || !response["_embedded"] || !response["_embedded"]["ontologies"]) {
throw new Error("Ontologies data not found"); //TODO consistent error handling
} else {

ontologiesData = ontologiesData.concat(response["_embedded"]["ontologies"].map((ontologyData: any) => {
return createModelObject(ontologyData);
}));
}

pageNum += 1;
} while(pageNum < response["page"]["totalPages"]);

pageNum += 1;
} while (pageNum < response["page"]["totalPages"]);
return new OLS3Ontologies(ontologiesData);
}
else {
do {
response = await this.getOntologies({ size: pageSize.toString(), page: pageNum.toString() }, undefined, undefined, parameter, useLegacy); // assuming there are no more than 500 ontologies

return new OLS3Ontologies(ontologiesData);
if (!response || !response["elements"]) {
throw new Error("Ontologies data not found"); //TODO consistent error handling
} else {

ontologiesData = ontologiesData.concat(response["elements"].map((ontologyData: any) => {
return createModelObject(ontologyData);
}));
}

pageNum += 1;
} while(pageNum < response["totalPages"]);

return new OLS4Ontologies(ontologiesData);
}
}

/**
Expand Down
23 changes: 12 additions & 11 deletions src/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export type MetadataWidgetProps =

export type OntologyInfoWidgetProps = ApiObj & ForcedOntologyIdObj & HasTitleObj & ShowBadgesObj & ParameterObj & UseLegacyObj & ContainerWidthObj & OnNavigates;

export type ResourcesWidgetProps = ApiObj & TargetLinkObj & ParameterObj & {
export type ResourcesWidgetProps = ApiObj & TargetLinkObj & ParameterObj & UseLegacyObj & {
/**
* Initial number of entries displayed per page.
*/
Expand Down Expand Up @@ -485,15 +485,16 @@ export type OlsResource = ForcedOntologyIdObj & {
numberOfProperties: number;
numberOfIndividuals: number;
config: {
title: string;
description: string;
preferredPrefix: string;
allowDownload: boolean;
fileLocation: string;
version?: string;
logo?: string;
title: string;
description: string;
preferredPrefix: string;
allowDownload: boolean;
fileLocation: string;
version?: string;
[otherFields: string]: unknown;
};
[otherFields: string]: unknown;
};
[otherFields: string]: unknown;
}

export type SearchBarWidgetProps = ApiObj & ParameterObj & {
Expand Down Expand Up @@ -555,11 +556,11 @@ export type MetadataCompactProps = Partial<Omit<EuiCardProps, "layout">> & ApiOb
export type TermDepictionWidgetProps = ApiObj & ForcedIriObj & ForcedOntologyIdObj & UseLegacyObj;

export type GraphViewWidgetProps = ApiObj & ForcedIriObj & ForcedOntologyIdObj &
{
{
/**
* When true, the graph will show the tree hierarchy for the target node in form of a graph.
*/
rootWalk?: boolean;
rootWalk?: boolean;
};

export type OlsGraphNode = {
Expand Down
2 changes: 2 additions & 0 deletions src/app/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from "../model/ModelTypeCheck";
import {StoryContext} from "@storybook/react";

export const OBO_FOUNDRY_REPO_URL_RAW = "https://raw.githubusercontent.com/OBOFoundry/OBOFoundry.github.io/master" as const;

export function asArray<T>(obj: T | T[]): T[] {
if (Array.isArray(obj)) {
return obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export default {
export {
ResourcesWidget1,
WithActions,
WithActionsAndSafety
WithActionsAndSafety,
ResourcesWidgetLogos
} from "./ResourcesWidgetStories"
Loading
Loading