Skip to content

Commit

Permalink
Change api/tool_panel to api/tool_panels/...
Browse files Browse the repository at this point in the history
As discussed in https://matrix.to/#/!NhNWKNcgINoFZdbUbY:gitter.im/$uw-EVkllUcG91TXjmX5OaicOLHy6zhs5wDHMoPO2cnY?via=gitter.im&via=matrix.org,

The new (alternate) tool panel api structure being used in the client
now would make more sense if:
- Our source of tools for the toolStore is: `api/tools?in_panel=False`
- Each panel view (also stored in the toolStore) comes from:
  `api/tool_panels/{view}`
- Dict of available tool panel views comes from:
  `api/tool_panels`

This means, we get rid of the `in_panel` and `view` (and other) params
for the `api/tool_panels` api (they still exist for the older
`api/tools` api.
  • Loading branch information
ahmedhamidawan committed Oct 26, 2023
1 parent 4fcf3b5 commit 48ad326
Show file tree
Hide file tree
Showing 16 changed files with 278 additions and 319 deletions.
11 changes: 7 additions & 4 deletions client/src/components/Panels/ToolBox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ useConfig.mockReturnValue({
});

describe("ToolBox", () => {
const toolsMock = toolsList.tools;
const toolPanelMock = toolsListInPanel.default;
const toolsMock = toolsList.reduce((acc, item) => {
acc[item.id] = item;
return acc;
}, {});
const toolPanelMock = toolsListInPanel;
const resultsMock = ["liftOver1", "__FILTER_EMPTY_DATASETS__", "__UNZIP_COLLECTION__"];
let axiosMock;

Expand All @@ -26,9 +29,9 @@ describe("ToolBox", () => {

it("test filter functions correctly matching: (1) Tools store array-of-objects with (2) Results array", async () => {
axiosMock
.onGet(`/api/tool_panel`)
.onGet(`/api/tool_panels/default`)
.replyOnce(200, toolsListInPanel)
.onGet(`/api/tool_panel?in_panel=False`)
.onGet(`/api/tools?in_panel=False`)
.replyOnce(200, toolsMock)
.onGet(/api\/tools?.*/)
.replyOnce(200, resultsMock);
Expand Down
58 changes: 22 additions & 36 deletions client/src/components/Panels/utilities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ describe("test helpers in tool searching utilities", () => {
"__ZIP_COLLECTION__",
],
keys: { description: 1, name: 0 },
tools: Object.values(toolsList.tools),
panel: toolsListInPanel.default,
tools: toolsList,
panel: toolsListInPanel,
},
{
// name prioritized
Expand All @@ -93,16 +93,16 @@ describe("test helpers in tool searching utilities", () => {
"__FILTER_EMPTY_DATASETS__",
],
keys: { description: 0, name: 1 },
tools: Object.values(toolsList.tools),
panel: toolsListInPanel.default,
tools: toolsList,
panel: toolsListInPanel,
},
{
// whitespace precedes to ensure query.trim() works
q: " filter empty datasets",
expectedResults: ["__FILTER_EMPTY_DATASETS__"],
keys: { description: 1, name: 2, combined: 0 },
tools: Object.values(toolsList.tools),
panel: toolsListInPanel.default,
tools: toolsList,
panel: toolsListInPanel,
},
{
// hyphenated tool-name is searchable
Expand All @@ -125,16 +125,16 @@ describe("test helpers in tool searching utilities", () => {
q: "__ZIP_COLLECTION__",
expectedResults: [],
keys: { description: 1, name: 2 },
tools: Object.values(toolsList.tools),
panel: toolsListInPanel.default,
tools: toolsList,
panel: toolsListInPanel,
},
{
// id is searchable if provided "id:"
q: "id:__ZIP_COLLECTION__",
expectedResults: ["__ZIP_COLLECTION__"],
keys: { description: 1, name: 2 },
tools: Object.values(toolsList.tools),
panel: toolsListInPanel.default,
tools: toolsList,
panel: toolsListInPanel,
},
{
// id is searchable if provided "tool_id:"
Expand All @@ -152,8 +152,8 @@ describe("test helpers in tool searching utilities", () => {
q: "filter datasets",
expectedResults: ["__FILTER_FAILED_DATASETS__", "__FILTER_EMPTY_DATASETS__"],
keys: { combined: 1, wordMatch: 0 },
tools: Object.values(toolsList.tools),
panel: toolsListInPanel.default,
tools: toolsList,
panel: toolsListInPanel,
},
];
searches.forEach((search) => {
Expand All @@ -168,55 +168,41 @@ describe("test helpers in tool searching utilities", () => {
// Testing if just names work with DL search
const filterQueries = ["Fillter", "FILYER", " Fitler", " filtr"];
filterQueries.forEach((q) => {
const { results, closestTerm } = searchToolsByKeys(
Object.values(toolsList.tools),
keys,
q,
"default",
toolsListInPanel.default
);
const { results, closestTerm } = searchToolsByKeys(toolsList, keys, q, "default", toolsListInPanel);
expect(results).toEqual(expectedResults);
expect(closestTerm).toEqual("filter");
});
// Testing if names and description function with DL search
let queries = ["datases from a collection", "from a colleection", "from a colleection"];
queries.forEach((q) => {
const { results } = searchToolsByKeys(
Object.values(toolsList.tools),
keys,
q,
"default",
toolsListInPanel.default
);
const { results } = searchToolsByKeys(toolsList, keys, q, "default", toolsListInPanel);
expect(results).toEqual(expectedResults);
});
// Testing if different length queries correctly trigger changes in max DL distance
queries = ["datae", "ppasetsfrom", "datass from a cppollection"];
queries.forEach((q) => {
const { results } = searchToolsByKeys(
Object.values(toolsList.tools),
keys,
q,
"default",
toolsListInPanel.default
);
const { results } = searchToolsByKeys(toolsList, keys, q, "default", toolsListInPanel);
expect(results).toEqual(expectedResults);
});
});

it("test tool filtering helpers on toolsList given list of ids", async () => {
const ids = ["__FILTER_FAILED_DATASETS__", "liftOver1"];
// check length of first section from imported const toolsList
expect(toolsListInPanel.default["collection_operations"].tools).toHaveLength(4);
expect(toolsListInPanel["collection_operations"].tools).toHaveLength(4);
// check length of same section from filtered toolsList
const matchedTools = ids.map((id) => {
return { id: id, sections: [], order: 0 };
});
const toolResultsPanel = createSortedResultObject(matchedTools, toolsListInPanel.default);
const toolResultsPanel = createSortedResultObject(matchedTools, toolsListInPanel);
const toolResultsSection = toolResultsPanel.resultPanel["collection_operations"];
expect(toolResultsSection.tools).toHaveLength(1);
// check length of filtered tools (regardless of sections)
const filteredToolIds = Object.keys(filterTools(toolsList.tools, ids));
const toolsById = toolsList.reduce((acc, item) => {
acc[item.id] = item;
return acc;
}, {});
const filteredToolIds = Object.keys(filterTools(toolsById, ids));
expect(filteredToolIds).toHaveLength(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ describe("ToolSchemaJson/ToolsView.vue", () => {

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

it("schema.org script element is created", async () => {
const toolsList = testToolsListResponse.tools;
const toolsListInPanel = testToolsListInPanelResponse.default;
const toolsList = testToolsListResponse.reduce((acc, item) => {
acc[item.id] = item;
return acc;
}, {});
const toolsListInPanel = testToolsListInPanelResponse;
const tools = wrapper.vm.createToolsJson(toolsList, toolsListInPanel);
const schemaElement = document.getElementById("schema-json");
const schemaText = JSON.parse(schemaElement.text);
Expand Down
17 changes: 10 additions & 7 deletions client/src/components/ToolsView/ToolsSchemaJson/ToolsJson.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,31 @@ export default {
return { schemaTagObj: {} };
},
async created() {
let tools = {};
let tools = [];
await axios
.get(`${getAppRoot()}api/tool_panel?in_panel=False&tool_help=True`)
.get(`${getAppRoot()}api/tools?in_panel=False&tool_help=True`)
.then(({ data }) => {
tools = data.tools;
tools = data.reduce((acc, item) => {
acc[item.id] = item;
return acc;
}, {});
})
.catch((error) => {
console.error("All tools by id not loaded", error);
console.error("List of all tools not loaded", error);
});
if (Object.keys(tools).length > 0) {
await axios
.get(`${getAppRoot()}api/tool_panel`)
.get(`${getAppRoot()}api/tool_panels/default`)
.then(({ data }) => {
this.schemaTagObj = this.createToolsJson(tools, data.default);
this.schemaTagObj = this.createToolsJson(tools, 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);
})
.catch((error) => {
console.error("Tool sections not loaded", error);
console.error("Tool sections by id not loaded", error);
});
}
},
Expand Down
Loading

0 comments on commit 48ad326

Please sign in to comment.