Skip to content

Commit

Permalink
#23 Handle search result counts
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Jan 13, 2021
1 parent 1a8499e commit 1d68f7e
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/components/Search/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { withLoading, withErrors } from '../../utils/hocUtil';
export const getSearchQuery = (limit) => {
const getQuery = (suffix = '') => `searchQuery${suffix}(
searchQuery: $searchQuery
${(limit && suffix !== 'Count') ? `limit: ${limit}` : ''}
${(limit && !suffix.includes('Count')) ? `limit: ${limit}` : ''}
)`;
return gql`
query Search($searchQuery: String!) {
Expand All @@ -35,6 +35,9 @@ export const getSearchQuery = (limit) => {
stakeholderFullName
}
}
${getQuery('EventsCount')}
${getQuery('DocumentsCount')}
${getQuery('StakeholdersCount')}
}
`;
};
Expand All @@ -52,30 +55,28 @@ const contains = (container, containment) => container.toLowerCase()
.includes(containment.toLowerCase());

export const handleSearchResults = (props, value) => ({ data }) => {
const { stopLoading, setSearchResults } = props;
// const { stopLoading, setCounts, setSearchResults } = props;
const { stopLoading, setCounts, setSearchResults } = props;
const documents = parseDocuments(data.searchQuery.documents);
const events = parseEvents(data.searchQuery.events);
const stakeholders = parseStakeholders(data.searchQuery.stakeholders);
const allSearchResults = [...stakeholders, ...documents, ...events];
// const allSearchResults = sortBy(prop('title'), unorderedSearchResults);
const allSearchResults = [...documents, ...events, ...stakeholders];
const withHighlights = allSearchResults.filter(({ title }) => contains(title, value));
const withoutHighlights = allSearchResults.filter(({ title }) => !contains(title, value));
const searchResults = [...withHighlights, ...withoutHighlights];
// const documentCount = data.documentsCount;
// const eventCount = data.eventsCount;
// const stakeholderCount = data.stakeholdersCount;
const documentCount = data.searchQueryDocumentsCount;
const eventCount = data.searchQueryEventsCount;
const stakeholderCount = data.searchQueryStakeholdersCount;

stopLoading();
setSearchResults(searchResults);
// setCounts({
// all: eventCount
// + documentCount
// + stakeholderCount,
// event: eventCount,
// document: documentCount,
// stakeholder: stakeholderCount,
// });
setCounts({
all: eventCount
+ documentCount
+ stakeholderCount,
event: eventCount,
document: documentCount,
stakeholder: stakeholderCount,
});
};

export const withSearch = compose(
Expand Down

1 comment on commit 1d68f7e

@vercel
Copy link

@vercel vercel bot commented on 1d68f7e Jan 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.