Skip to content

Commit

Permalink
Various fixes in search behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinvanschoren committed Jan 10, 2024
1 parent d2ade1a commit a276840
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 13 deletions.
1 change: 0 additions & 1 deletion app/src/components/search/ResultTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ const ResultsTable = ({ results, columns }) => {
// Go to detail page on click
const handleRowClick = (params) => {
// Assuming 'id' is the field you want to use for navigation
console.log(params);
const basePath = router.pathname.split("/")[1];
const id = params.row.id;
router.push(`/${basePath}/${id}`);
Expand Down
13 changes: 9 additions & 4 deletions app/src/components/search/Sort.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useEffect } from "react";
import React, { useState } from "react";

import { Sorting, withSearch } from "@elastic/react-search-ui";
import {
Box,
Expand All @@ -17,6 +18,9 @@ import {
const SortView = ({ options, value, onChange }) => {
if (value === "|||") {
value = "[]";
} else {
// The Select component matches against the default setting
value = value.replace('"direction":"asc"', '"direction":"desc"');
}
return (
<Box>
Expand Down Expand Up @@ -52,12 +56,13 @@ function Sort({ sortOptions, setSort, sortList }) {
? "desc"
: "asc";

// Update the sort in the Search UI state
let newSortList = [];
if (sortList.length > 0) {
sortList[0]["direction"] = newDirection;
newSortList = [{ field: sortList[0]["field"], direction: newDirection }];
}

setSort(newSortList); // Update the Search UI state
setSortDirection(newDirection); // Update the local state (for button)
setSort(sortList); // Update the Search UI state
};

//Translate sort options
Expand Down
1 change: 0 additions & 1 deletion app/src/components/sidebar/SidebarNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const SidebarNav = ({ items }) => {
acc[item.index] = item.count;
return acc;
}, {});
console.log("Count fetched:", counts);
setCount(counts);
})
.catch((error) => {
Expand Down
6 changes: 4 additions & 2 deletions app/src/components/sidebar/SidebarNavListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ const SidebarNavListItem = (props) => {

// Extract the query string from the URL
const router = useRouter();
const currentQuery = router.asPath.split("?")[1];
let currentQuery = router.asPath.split("?")[1];
const params = new URLSearchParams(currentQuery);
const qValue = params.get("q");
currentQuery = qValue ? `q=${qValue}` : null;

const {
title,
Expand Down Expand Up @@ -139,7 +142,6 @@ const SidebarNavListItem = (props) => {
</React.Fragment>
);
}

return (
<Link
href={`${href}${currentQuery ? `?${currentQuery}` : ""}`}
Expand Down
5 changes: 2 additions & 3 deletions app/src/pages/api/count.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default async function handler(req, res) {
const elasticsearchEndpoint = `${ELASTICSEARCH_SERVER}/_msearch`;
const indices = ["data", "task", "flow", "run", "study", "measure"];

// Prepare the multi-search body
// Multi-search body to count all indices at once
let requestBody = "";
indices.forEach((index) => {
requestBody += `{ "index": "${index}" }\n{ "size": 0 }\n`;
Expand All @@ -19,10 +19,9 @@ export default async function handler(req, res) {
// Extract counts for each index
const counts = response.data.responses.map((r, i) => ({
index: indices[i],
count: r.hits.total.value || r.hits.total, // Adjust based on Elasticsearch version
count: r.hits.total.value || r.hits.total,
}));

console.log(counts);
res.status(200).json(counts);
} catch (error) {
res.status(500).json({ error: "Error fetching counts from Elasticsearch" });
Expand Down
1 change: 0 additions & 1 deletion app/src/pages/r/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ const columns = [

function RunSearchContainer() {
const combinedConfig = useNextRouting(runConfig, "<baseUrl>");

return (
<SearchContainer
config={combinedConfig}
Expand Down
3 changes: 3 additions & 0 deletions app/src/search_configs/flowConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const searchConfig = {
field: { name: { raw: {} } },
},
},
initialState: {
sortList: [{ field: "runs", direction: "desc" }],
},
autocompleteQuery: {
results: {
resultsPerPage: 100,
Expand Down
3 changes: 3 additions & 0 deletions app/src/search_configs/runConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const searchConfig = {
field: { name: { raw: {} } },
},
},
initialState: {
sortList: [{ field: "date", direction: "desc" }],
},
autocompleteQuery: {
results: {
resultsPerPage: 100,
Expand Down
3 changes: 3 additions & 0 deletions app/src/search_configs/taskConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const searchConfig = {
field: { name: { raw: {} } },
},
},
initialState: {
sortList: [{ field: "runs", direction: "desc" }],
},
autocompleteQuery: {
results: {
resultsPerPage: 100,
Expand Down
2 changes: 1 addition & 1 deletion app/src/services/SearchAPIConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class SearchAPIConnector {
// Use index data by default
constructor(indexName = "data") {
this.indexName = indexName;
console.log("created connector for", indexName);
//console.log("created connector for", indexName);
}

onResultClick() {
Expand Down

0 comments on commit a276840

Please sign in to comment.