Merge pull request #21232 from mvdbeek/tool_link_fix

[25.1] Fix href for tool links
This commit is contained in:
John Chilton
2025-11-05 12:52:31 +01:00
committed by GitHub
4 changed files with 55 additions and 5 deletions
@@ -1,3 +1,4 @@
import { createTestingPinia } from "@pinia/testing";
import { mount } from "@vue/test-utils";
import { getLocalVue } from "tests/jest/helpers";
@@ -7,11 +8,15 @@ const localVue = getLocalVue();
describe("Tool", () => {
test("test tool", () => {
const pinia = createTestingPinia();
const wrapper = mount(Tool, {
propsData: {
tool: {},
tool: {
id: "test_tool",
},
},
localVue,
pinia,
});
const nameElement = wrapper.findAll(".name");
expect(nameElement.at(0).text()).toBe("");
@@ -25,15 +30,18 @@ describe("Tool", () => {
expect(wrapper.emitted().onOperation).toBeDefined();
});
test("test tool operation", () => {
const pinia = createTestingPinia();
const wrapper = mount(Tool, {
propsData: {
tool: {
id: "test_tool",
name: "name",
},
operationIcon: "operationIconClass",
operationTitle: "operationTitle",
},
localVue,
pinia,
});
const nameElement = wrapper.findAll(".name");
expect(nameElement.at(0).text()).toBe("name");
@@ -43,15 +51,18 @@ describe("Tool", () => {
expect(title).toBe("operationTitle");
});
test("test tool hide name, test description", () => {
const pinia = createTestingPinia();
const wrapper = mount(Tool, {
propsData: {
tool: {
id: "test_tool",
name: "name",
description: "description",
},
hideName: true,
},
localVue,
pinia,
});
const nameElement = wrapper.findAll(".name");
expect(nameElement.length).toBe(0);
+17 -2
View File
@@ -8,8 +8,8 @@
v-else
:class="targetClass"
:data-tool-id="tool.id"
:href="tool.link"
:target="tool.target"
:href="toolLink"
:target="toolTarget"
:title="tool.help"
@click="onClick">
<span class="labels">
@@ -36,6 +36,8 @@ import BootstrapVue from "bootstrap-vue";
import ariaAlert from "utils/ariaAlert";
import Vue from "vue";
import { useToolStore } from "@/stores/toolStore";
Vue.use(BootstrapVue);
export default {
@@ -66,7 +68,20 @@ export default {
default: false,
},
},
setup() {
const toolStore = useToolStore();
return {
getLinkById: toolStore.getLinkById,
getTargetById: toolStore.getTargetById,
};
},
computed: {
toolLink() {
return this.getLinkById(this.tool.id);
},
toolTarget() {
return this.getTargetById(this.tool.id);
},
targetClass() {
if (this.toolKey) {
return `tool-menu-item-${this.tool[this.toolKey]} title-link cursor-pointer`;
+24
View File
@@ -103,6 +103,28 @@ export const useToolStore = defineStore("toolStore", () => {
return toolSections.value[effectiveView] || {};
});
const getLinkById = computed(() => {
return (toolId: string) => {
const tool = toolsById.value[toolId];
const appRoot = getAppRoot();
if (tool && tool.model_class === "DataSourceTool") {
return `${appRoot}tool_runner/data_source_redirect?tool_id=${encodeURIComponent(toolId)}`;
} else if (tool?.model_class) {
return `${appRoot}?tool_id=${encodeURIComponent(toolId)}&version=latest`;
} else {
// accommodates hacky toolbox markdown directive overload
return undefined;
}
};
});
const getTargetById = computed(() => {
return (toolId: string) => {
const tool = toolsById.value[toolId];
return tool?.model_class === "DataSourceTool" ? "_top" : "galaxy_main";
};
});
const getToolsById = computed(() => {
return (q?: string) => {
if (!q?.trim()) {
@@ -299,6 +321,8 @@ export const useToolStore = defineStore("toolStore", () => {
fetchPanels,
fetchToolForId,
fetchTools,
getLinkById,
getTargetById,
helpDataCached,
initializePanel,
isPanelPopulated,
+2 -2
View File
@@ -399,8 +399,8 @@ tool_panel:
selectors:
edam_link: 'a[href^="https://edamontology.github.io/edam-browser"]'
tool_box: '[data-description="panel toolbox"]'
tool_link: 'a[href$$="tool_runner?tool_id=${tool_id}"]'
outer_tool_link: '.toolTitle a[href$$="tool_runner?tool_id=${tool_id}"]'
tool_link: 'a[href$$="/?tool_id=${tool_id}&version=latest"]'
outer_tool_link: '.toolTitle a[href$$="/?tool_id=${tool_id}&version=latest"]'
data_source_tool_link: 'a[href$$="tool_runner/data_source_redirect?tool_id=${tool_id}"]'
search: '.search-query'
toolbox: '[data-description="panel toolbox"]'