Skip to content

Commit

Permalink
recent limit set to 5
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmehta committed Nov 15, 2023
1 parent 3696fdf commit e795e0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function GlobalSearchList({ inputValue }) {
)}

{/* no input value search suggestions */}
{!inputValue && recentItems.length < 4 && SearchSuggestionEl}
{!inputValue && SearchSuggestionEl}
</>
);
}
Expand Down
20 changes: 10 additions & 10 deletions packages/ui/src/components/GlobalSearch/utils/searchUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { format } from "d3-format";

const mapStandardKeys = (origionalKey) => {
const mapStandardKeys = origionalKey => {
switch (origionalKey) {
case "studyId":
return "id";
Expand All @@ -17,7 +17,7 @@ const mapStandardKeys = (origionalKey) => {
}
};

const flattenObj = (ob) => {
const flattenObj = ob => {
const result = {};

Object.entries(ob).forEach(([key, value]) => {
Expand All @@ -36,10 +36,10 @@ const flattenObj = (ob) => {
return result;
};

const isArray = (value) => Array.isArray(value) && value.length > 0;
const isArray = value => Array.isArray(value) && value.length > 0;

const exceedsArrayLengthLimit = (array) => {
const limitLength = 9;
const exceedsArrayLengthLimit = array => {
const limitLength = 4;
let exceedsLimit = false;

if (array.length > limitLength) {
Expand All @@ -48,21 +48,21 @@ const exceedsArrayLengthLimit = (array) => {
return exceedsLimit;
};

export const formatSearchData = (unformattedData) => {
export const formatSearchData = unformattedData => {
const formattedData = {};

Object.entries(unformattedData).forEach(([key, value]) => {
const typesArray = [];
if (isArray(value)) {
value.map((i) =>
value.map(i =>
typesArray.push({
type: key === "topHit" ? "topHit" : key,
entity: key,
...flattenObj(i),
})
);
} else if (isArray(value.hits)) {
value.hits.map((i) =>
value.hits.map(i =>
typesArray.push({
type: key === "topHit" ? "topHit" : i.entity,
entity: i.entity,
Expand All @@ -86,7 +86,7 @@ export const containsObject = (obj, list) => {
return -1;
};

export const addSearchToLocalStorage = (item) => {
export const addSearchToLocalStorage = item => {
const recentItems = JSON.parse(localStorage.getItem("search-history")) || [];
const newItem = { ...item };
delete newItem.description;
Expand All @@ -108,7 +108,7 @@ export const clearAllRecent = () => {
window.dispatchEvent(new Event("storage"));
};

export const clearRecentItem = (item) => {
export const clearRecentItem = item => {
const recentItems = JSON.parse(localStorage.getItem("search-history"));
const removedItems = [...recentItems];
const existingIndex = containsObject(item, removedItems);
Expand Down

0 comments on commit e795e0f

Please sign in to comment.