Skip to content

Commit

Permalink
Change ToolsView/ schema.org page to support new api structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedhamidawan committed Sep 27, 2023
1 parent 8f4b954 commit 5981b5e
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import flushPromises from "flush-promises";
import { getLocalVue } from "tests/jest/helpers";

import testToolsListResponse from "../testData/toolsList";
import testToolsListInPanelResponse from "../testData/toolsListInPanel";
import ToolsJson from "./ToolsJson";

const localVue = getLocalVue();
Expand All @@ -17,13 +18,16 @@ describe("ToolSchemaJson/ToolsView.vue", () => {

beforeEach(async () => {
axiosMock = new MockAdapter(axios);
axiosMock.onGet("/api/tools?tool_help=True").reply(200, testToolsListResponse);
axiosMock.onGet("/api/tools?in_panel=False&tool_help=True").reply(200, testToolsListResponse);
axiosMock.onGet("/api/tools").reply(200, testToolsListInPanelResponse);
wrapper = shallowMount(ToolsJson, { localVue });
await flushPromises();
});

it("schema.org script element is created", async () => {
const tools = wrapper.vm.createToolsJson(testToolsListResponse);
const toolsList = testToolsListResponse.tools;
const toolsListInPanel = testToolsListInPanelResponse.default;
const tools = wrapper.vm.createToolsJson(toolsList, toolsListInPanel);
const schemaElement = document.getElementById("schema-json");
const schemaText = JSON.parse(schemaElement.text);
expect(tools["@graph"].length === 5).toBeTruthy();
Expand Down
47 changes: 30 additions & 17 deletions client/src/components/ToolsView/ToolsSchemaJson/ToolsJson.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,39 @@ export default {
data() {
return { schemaTagObj: {} };
},
created() {
axios
.get(`${getAppRoot()}api/tools?tool_help=True`)
.then((response) => {
this.schemaTagObj = this.createToolsJson(response.data);
const el = document.createElement("script");
el.id = "schema-json";
el.type = "application/ld+json";
el.text = JSON.stringify(this.schemaTagObj);
document.head.appendChild(el);
async created() {
let tools = {};
await axios
.get(`${getAppRoot()}api/tools?in_panel=False&tool_help=True`)
.then(({ data }) => {
tools = data.tools;
})
.catch((error) => {
console.error(error);
console.error("All tools by id not loaded", error);
});
if (Object.keys(tools).length > 0) {
await axios
.get(`${getAppRoot()}api/tools`)
.then(({ data }) => {
this.schemaTagObj = this.createToolsJson(tools, data.default);
const el = document.createElement("script");
el.id = "schema-json";
el.type = "application/ld+json";
el.text = JSON.stringify(this.schemaTagObj);
document.head.appendChild(el);
})
.catch((error) => {
console.error("Tool sections not loaded", error);
});
}
},
methods: {
createToolsJson(tools) {
createToolsJson(tools, panel) {
const sections = Object.values(panel);
function extractSections(acc, section) {
function extractTools(_acc, tool) {
return tool.name
function extractTools(_acc, toolId) {
const tool = tools[toolId];
return tool && tool.name
? [
..._acc,
{
Expand All @@ -44,15 +57,15 @@ export default {
]
: _acc;
}
if ("elems" in section) {
return acc.concat(section.elems.reduce(extractTools, []));
if ("tools" in section) {
return acc.concat(section.tools.reduce(extractTools, []));
} else {
return acc;
}
}
return {
"@context": "http://schema.org",
"@graph": tools.reduce(extractSections, []),
"@graph": sections.reduce(extractSections, []),
};
},
},
Expand Down
228 changes: 103 additions & 125 deletions client/src/components/ToolsView/testData/toolsList.json
Original file line number Diff line number Diff line change
@@ -1,126 +1,104 @@
[
{
"elems": [
{
"panel_section_name": "Collection Operations",
"xrefs": [],
"description": "",
"is_workflow_compatible": true,
"labels": [],
"help": "<p>This tool takes a paired dataset collection and builds two datasets from it. If mapped over a list of paired datasets, this tool will produce two lists of datasets.<\/p>\n<hr class=\"docutils\" />\n<p><strong>Example<\/strong><\/p>\n<p>If a collection consists of two forward and two reverse datasets (e.g., forward and reverse reads from a sequencing experiment) this tool will output two collections: one consisting of forward reads and one of reverse reads.<\/p>\n<p class=\"infomark\">This tool will create new history datasets from your collection but your quota usage will not increase.<\/p>\n",
"edam_operations": [],
"form_style": "regular",
"edam_topics": [],
"panel_section_id": "collection_operations",
"version": "1.0.0",
"link": "/tool_runner?tool_id=__UNZIP_COLLECTION__",
"target": "galaxy_main",
"min_width": -1,
"model_class": "UnzipCollectionTool",
"hidden": "",
"id": "__UNZIP_COLLECTION__",
"name": "Unzip Collection"
},
{
"panel_section_name": "Collection Operations",
"xrefs": [],
"description": "",
"is_workflow_compatible": true,
"labels": [],
"help": "<p>This tool takes two datasets and creates a dataset pair from them. Mapping over two lists, this tool can be used to build a list of dataset pairs from two individual lists of datasets.<\/p>\n<hr class=\"docutils\" />\n<p><strong>Example<\/strong><\/p>\n<p>If you have one collection containing only forward reads and one containing only reverse, this tools will &quot;zip&quot; them together into a simple paired collection.<\/p>\n<p class=\"infomark\">This tool will create new history datasets for your collection but your quota usage will not increase.<\/p>\n",
"edam_operations": [],
"form_style": "regular",
"edam_topics": [],
"panel_section_id": "collection_operations",
"version": "1.0.0",
"link": "/tool_runner?tool_id=__ZIP_COLLECTION__",
"target": "galaxy_main",
"min_width": -1,
"model_class": "ZipCollectionTool",
"hidden": "",
"id": "__ZIP_COLLECTION__",
"name": "Zip Collection"
},
{
"panel_section_name": "Collection Operations",
"xrefs": [],
"description": "datasets from a collection",
"is_workflow_compatible": true,
"labels": [],
"help": "<p>This tool takes a dataset collection and filters out datasets in the failed state. This is useful for continuing a multi-sample analysis when one of more of the samples fails at some point.<\/p>\n<p class=\"infomark\">This tool will create new history datasets from your collection but your quota usage will not increase.<\/p>\n",
"edam_operations": [],
"form_style": "regular",
"edam_topics": [],
"panel_section_id": "collection_operations",
"version": "1.0.0",
"link": "/tool_runner?tool_id=__FILTER_FAILED_DATASETS__",
"target": "galaxy_main",
"min_width": -1,
"model_class": "FilterFailedDatasetsTool",
"hidden": "",
"id": "__FILTER_FAILED_DATASETS__",
"name": "Filter failed"
},
{
"panel_section_name": "Collection Operations",
"xrefs": [],
"description": "datasets from a collection",
"is_workflow_compatible": true,
"labels": [],
"help": "<p>This tool takes a dataset collection and filters out empty datasets. This is useful for continuing a multi-sample analysis when downstream tools require datasets to have content.<\/p>\n<p class=\"infomark\">This tool will create new history datasets from your collection but your quota usage will not increase.<\/p>\n",
"edam_operations": [],
"form_style": "regular",
"edam_topics": [],
"panel_section_id": "collection_operations",
"version": "1.0.0",
"link": "/tool_runner?tool_id=__FILTER_EMPTY_DATASETS__",
"target": "galaxy_main",
"min_width": -1,
"model_class": "FilterEmptyDatasetsTool",
"hidden": "",
"id": "__FILTER_EMPTY_DATASETS__",
"name": "Filter empty"
}
],
"model_class": "ToolSection",
"version": "",
"id": "collection_operations",
"name": "Collection Operations"
},
{
"elems": [
{
"panel_section_name": "Lift-Over",
"xrefs": [],
"description": "between assemblies and genomes",
"is_workflow_compatible": true,
"labels": [],
"help": "<p class=\"warningmark\">Make sure that the genome build of the input dataset is specified (click the pencil icon in the history item to set it if necessary).<\/p>\n<p class=\"warningmark\">This tool can work with interval, GFF, and GTF datasets. It requires the interval datasets to have chromosome in column 1,\nstart co-ordinate in column 2 and end co-ordinate in column 3. BED comments\nand track and browser lines will be ignored, but if other non-interval lines\nare present the tool will return empty output datasets.<\/p>\n<hr class=\"docutils\" />\n<p class=\"infomark\"><strong>What it does<\/strong><\/p>\n<p>This tool is based on the LiftOver utility and Chain track from <a class=\"reference external\" href=\"http://genome.ucsc.edu/\">the UC Santa Cruz Genome Browser<\/a>.<\/p>\n<p>It converts coordinates and annotations between assemblies and genomes. It produces 2 files, one containing all the mapped coordinates and the other containing the unmapped coordinates, if any.<\/p>\n<blockquote>\n<\/blockquote>\n<hr class=\"docutils\" />\n<p><strong>Example<\/strong><\/p>\n<p>Converting the following hg16 intervals to hg18 intervals:<\/p>\n<pre class=\"literal-block\">\nchrX 85170 112199 AK002185 0 +\nchrX 110458 112199 AK097346 0 +\nchrX 112203 121212 AK074528 0 -\n<\/pre>\n<p>will produce the following hg18 intervals:<\/p>\n<pre class=\"literal-block\">\nchrX 132991 160020 AK002185 0 +\nchrX 158279 160020 AK097346 0 +\nchrX 160024 169033 AK074528 0 -\n<\/pre>\n",
"edam_operations": [],
"form_style": "regular",
"edam_topics": [],
"panel_section_id": "liftOver",
"version": "1.0.6",
"link": "/tool_runner?tool_id=liftOver1",
"target": "galaxy_main",
"min_width": -1,
"model_class": "Tool",
"hidden": "",
"id": "liftOver1",
"name": "Convert genome coordinates"
}
],
"model_class": "ToolSection",
"version": "",
"id": "liftOver",
"name": "Lift-Over"
},
{
"model_class": "ToolSectionLabel",
"id": "testlabel3",
"text": null,
"version": "",
"description": null,
"links": null
{
"tools": {
"__UNZIP_COLLECTION__": {
"panel_section_name": "Collection Operations",
"xrefs": [],
"description": "",
"is_workflow_compatible": true,
"labels": [],
"help": "<p>This tool takes a paired dataset collection and builds two datasets from it. If mapped over a list of paired datasets, this tool will produce two lists of datasets.<\/p>\n<hr class=\"docutils\" />\n<p><strong>Example<\/strong><\/p>\n<p>If a collection consists of two forward and two reverse datasets (e.g., forward and reverse reads from a sequencing experiment) this tool will output two collections: one consisting of forward reads and one of reverse reads.<\/p>\n<p class=\"infomark\">This tool will create new history datasets from your collection but your quota usage will not increase.<\/p>\n",
"edam_operations": [],
"form_style": "regular",
"edam_topics": [],
"panel_section_id": "collection_operations",
"version": "1.0.0",
"link": "/tool_runner?tool_id=__UNZIP_COLLECTION__",
"target": "galaxy_main",
"min_width": -1,
"model_class": "UnzipCollectionTool",
"hidden": "",
"id": "__UNZIP_COLLECTION__",
"name": "Unzip Collection"
},
"__ZIP_COLLECTION__": {
"panel_section_name": "Collection Operations",
"xrefs": [],
"description": "",
"is_workflow_compatible": true,
"labels": [],
"help": "<p>This tool takes two datasets and creates a dataset pair from them. Mapping over two lists, this tool can be used to build a list of dataset pairs from two individual lists of datasets.<\/p>\n<hr class=\"docutils\" />\n<p><strong>Example<\/strong><\/p>\n<p>If you have one collection containing only forward reads and one containing only reverse, this tools will &quot;zip&quot; them together into a simple paired collection.<\/p>\n<p class=\"infomark\">This tool will create new history datasets for your collection but your quota usage will not increase.<\/p>\n",
"edam_operations": [],
"form_style": "regular",
"edam_topics": [],
"panel_section_id": "collection_operations",
"version": "1.0.0",
"link": "/tool_runner?tool_id=__ZIP_COLLECTION__",
"target": "galaxy_main",
"min_width": -1,
"model_class": "ZipCollectionTool",
"hidden": "",
"id": "__ZIP_COLLECTION__",
"name": "Zip Collection"
},
"__FILTER_FAILED_DATASETS__": {
"panel_section_name": "Collection Operations",
"xrefs": [],
"description": "datasets from a collection",
"is_workflow_compatible": true,
"labels": [],
"help": "<p>This tool takes a dataset collection and filters out datasets in the failed state. This is useful for continuing a multi-sample analysis when one of more of the samples fails at some point.<\/p>\n<p class=\"infomark\">This tool will create new history datasets from your collection but your quota usage will not increase.<\/p>\n",
"edam_operations": [],
"form_style": "regular",
"edam_topics": [],
"panel_section_id": "collection_operations",
"version": "1.0.0",
"link": "/tool_runner?tool_id=__FILTER_FAILED_DATASETS__",
"target": "galaxy_main",
"min_width": -1,
"model_class": "FilterFailedDatasetsTool",
"hidden": "",
"id": "__FILTER_FAILED_DATASETS__",
"name": "Filter failed"
},
"__FILTER_EMPTY_DATASETS__": {
"panel_section_name": "Collection Operations",
"xrefs": [],
"description": "datasets from a collection",
"is_workflow_compatible": true,
"labels": [],
"help": "<p>This tool takes a dataset collection and filters out empty datasets. This is useful for continuing a multi-sample analysis when downstream tools require datasets to have content.<\/p>\n<p class=\"infomark\">This tool will create new history datasets from your collection but your quota usage will not increase.<\/p>\n",
"edam_operations": [],
"form_style": "regular",
"edam_topics": [],
"panel_section_id": "collection_operations",
"version": "1.0.0",
"link": "/tool_runner?tool_id=__FILTER_EMPTY_DATASETS__",
"target": "galaxy_main",
"min_width": -1,
"model_class": "FilterEmptyDatasetsTool",
"hidden": "",
"id": "__FILTER_EMPTY_DATASETS__",
"name": "Filter empty"
},
"liftOver1": {
"panel_section_name": "Lift-Over",
"xrefs": [],
"description": "between assemblies and genomes",
"is_workflow_compatible": true,
"labels": [],
"help": "<p class=\"warningmark\">Make sure that the genome build of the input dataset is specified (click the pencil icon in the history item to set it if necessary).<\/p>\n<p class=\"warningmark\">This tool can work with interval, GFF, and GTF datasets. It requires the interval datasets to have chromosome in column 1,\nstart co-ordinate in column 2 and end co-ordinate in column 3. BED comments\nand track and browser lines will be ignored, but if other non-interval lines\nare present the tool will return empty output datasets.<\/p>\n<hr class=\"docutils\" />\n<p class=\"infomark\"><strong>What it does<\/strong><\/p>\n<p>This tool is based on the LiftOver utility and Chain track from <a class=\"reference external\" href=\"http://genome.ucsc.edu/\">the UC Santa Cruz Genome Browser<\/a>.<\/p>\n<p>It converts coordinates and annotations between assemblies and genomes. It produces 2 files, one containing all the mapped coordinates and the other containing the unmapped coordinates, if any.<\/p>\n<blockquote>\n<\/blockquote>\n<hr class=\"docutils\" />\n<p><strong>Example<\/strong><\/p>\n<p>Converting the following hg16 intervals to hg18 intervals:<\/p>\n<pre class=\"literal-block\">\nchrX 85170 112199 AK002185 0 +\nchrX 110458 112199 AK097346 0 +\nchrX 112203 121212 AK074528 0 -\n<\/pre>\n<p>will produce the following hg18 intervals:<\/p>\n<pre class=\"literal-block\">\nchrX 132991 160020 AK002185 0 +\nchrX 158279 160020 AK097346 0 +\nchrX 160024 169033 AK074528 0 -\n<\/pre>\n",
"edam_operations": [],
"form_style": "regular",
"edam_topics": [],
"panel_section_id": "liftOver",
"version": "1.0.6",
"link": "/tool_runner?tool_id=liftOver1",
"target": "galaxy_main",
"min_width": -1,
"model_class": "Tool",
"hidden": "",
"id": "liftOver1",
"name": "Convert genome coordinates"
}
}
]
}
28 changes: 28 additions & 0 deletions client/src/components/ToolsView/testData/toolsListInPanel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"default": {
"collection_operations": {
"tools": [
"__UNZIP_COLLECTION__", "__ZIP_COLLECTION__", "__FILTER_FAILED_DATASETS__", "__FILTER_EMPTY_DATASETS__"
],
"model_class": "ToolSection",
"version": "",
"id": "collection_operations",
"name": "Collection Operations"
},
"liftOver": {
"tools": ["liftOver1"],
"model_class": "ToolSection",
"version": "",
"id": "liftOver",
"name": "Lift-Over"
},
"testlabel1": {
"model_class": "ToolSectionLabel",
"id": "testlabel1",
"text": null,
"version": "",
"description": null,
"links": null
}
}
}
2 changes: 0 additions & 2 deletions client/src/components/providers/storeProviders.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,3 @@ export const StoreProvider = (storeAction, storeGetter) => {
},
};
};

export const CollectionElementsProvider = StoreProvider("fetchCollectionElements", "getCollectionElements");

0 comments on commit 5981b5e

Please sign in to comment.