Skip to content

Commit

Permalink
Issue #614: fix call search
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzov96 committed Sep 28, 2023
1 parent 788a7bf commit d42d3a5
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
3 changes: 3 additions & 0 deletions js-packages/search-frontend/src/components/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type FiltersProps = {
sortAfterKey: string;
isCollapsable?: boolean;
numberItems?: number | null | undefined;
numberOfResults: number;
};
function Filters({
searchQuery,
Expand All @@ -40,6 +41,7 @@ function Filters({
sortAfterKey,
isCollapsable = true,
numberItems,
numberOfResults,
}: FiltersProps) {
const suggestionCategories = useSuggestionCategories();
const { t } = useTranslation();
Expand All @@ -50,6 +52,7 @@ function Filters({
sort,
language,
sortAfterKey,
numberOfResults,
);
React.useEffect(() => {
if (!isPreviousData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type FiltersProps = {
dynamicFilters: boolean;
language: string;
sortAfterKey: string;
numberOfResults: number;
};
function FiltersHorizontal({
searchQuery,
Expand All @@ -51,6 +52,7 @@ function FiltersHorizontal({
dynamicFilters,
language,
sortAfterKey,
numberOfResults,
}: FiltersProps) {
const suggestionCategories = useSuggestionCategories();
const [lastSearchQueryWithResults, setLastSearchQueryWithResults] =
Expand All @@ -60,6 +62,7 @@ function FiltersHorizontal({
sort,
language,
sortAfterKey,
numberOfResults,
);
React.useEffect(() => {
if (!isPreviousData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type FiltersMobileProps<E> = {
language: string;
sortAfterKey: string;
isCollapsable?: boolean;
numberOfResults: number;
};
function FiltersMobileLiveChange<E>({
dynamicFilters,
Expand All @@ -65,12 +66,14 @@ function FiltersMobileLiveChange<E>({
viewTabs = false,
sortAfterKey,
isCollapsable = true,
numberOfResults,
}: FiltersMobileProps<E>) {
const results = useInfiniteResults<any>(
searchQuery,
sort,
language,
sortAfterKey,
numberOfResults,
);
const { t } = useTranslation();
const componet = (
Expand Down Expand Up @@ -165,6 +168,7 @@ function FiltersMobileLiveChange<E>({
language={language}
sortAfterKey={sortAfterKey}
isCollapsable={isCollapsable}
numberOfResults={numberOfResults}
preFilters={
viewTabs ? (
<ViewAllTabs
Expand Down
15 changes: 14 additions & 1 deletion js-packages/search-frontend/src/components/ResultList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ResultsProps<E> = {
setSortAfterKey: React.Dispatch<React.SetStateAction<string>>;
sortAfterKey: string;
setTotalResult: React.Dispatch<React.SetStateAction<number | null>>;
numberOfResults: number;
};
function Results<E>({
displayMode,
Expand All @@ -47,6 +48,7 @@ function Results<E>({
setSortAfterKey,
sortAfterKey,
setTotalResult,
numberOfResults,
}: ResultsProps<E>) {
const renderers = useRenderers();

Expand All @@ -66,6 +68,7 @@ function Results<E>({
overChangeCard={overChangeCard}
language={language}
sortAfterKey={sortAfterKey}
numberOfResults={numberOfResults}
/>
);
case "infinite":
Expand All @@ -83,6 +86,7 @@ function Results<E>({
language={language}
setSortAfterKey={setSortAfterKey}
sortAfterKey={sortAfterKey}
numberOfResults={numberOfResults}
/>
);
case "virtual":
Expand All @@ -99,6 +103,7 @@ function Results<E>({
overChangeCard={overChangeCard}
language={language}
sortAfterKey={sortAfterKey}
numberOfResults={numberOfResults}
/>
);
}
Expand Down Expand Up @@ -199,6 +204,7 @@ type ResulListProps<E> = {
overChangeCard?: boolean;
language: string;
setTotalResult: React.Dispatch<React.SetStateAction<number | null>>;
numberOfResults: number;
};

type FiniteResultsProps<E> = ResulListProps<E> & { sortAfterKey: string };
Expand All @@ -214,12 +220,14 @@ export function FiniteResults<E>({
language,
sortAfterKey,
setTotalResult,
numberOfResults,
}: FiniteResultsProps<E>) {
const results = useInfiniteResults<E>(
searchQuery,
sort,
language,
sortAfterKey,
numberOfResults,
);

setTotalResult(results.data?.pages[0].total ?? null);
Expand Down Expand Up @@ -278,12 +286,14 @@ export function InfiniteResults<E>({
setSortAfterKey,
sortAfterKey,
setTotalResult,
numberOfResults,
}: InfiniteResultsProps<E>) {
const results = useInfiniteResults<E>(
searchQuery,
sort,
language,
sortAfterKey,
numberOfResults,
);

const { t } = useTranslation();
Expand Down Expand Up @@ -435,12 +445,14 @@ export function VirtualResults<E>({
language,
sortAfterKey,
setTotalResult,
numberOfResults,
}: VirtualResultsProps<E>) {
const results = useInfiniteResults<E>(
searchQuery,
sort,
language,
sortAfterKey,
numberOfResults,
);
const resultsFlat = results.data?.pages.flatMap((page) => page.result);
const thereAreResults = Boolean(
Expand Down Expand Up @@ -538,8 +550,9 @@ export function useInfiniteResults<E>(
sort: SortField[],
language: string,
sortAfterKey: string,
numberOfResults: number,
) {
const pageSize = 25;
const pageSize = numberOfResults;
const client = useOpenK9Client();
return useInfiniteQuery(
["results", searchQuery, sort, language, sortAfterKey] as const,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,17 @@ function useInfiniteResults<E>(
) {
const pageSize = elementForPage;
const client = useOpenK9Client();
console.log(
searchQuery,
sort,
language,
sortAfterKey,
elementForPage,
result,
);

return useInfiniteQuery(
["results", searchQuery, sort, language, sortAfterKey, result] as const,
["results", searchQuery, sort, language, sortAfterKey] as const,
async ({ queryKey: [, searchQuery, sort], pageParam = 0 }) => {
const RangePage: [number, number] =
sortAfterKey === "" ? [result, pageSize] : [0, pageSize];
Expand Down
10 changes: 8 additions & 2 deletions js-packages/search-frontend/src/embeddable/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function Main({
}, [languageQuery.data, i18n]);
const [sortAfterKey, setSortAfterKey] = React.useState("");
const [totalResult, setTotalResult] = React.useState<number | null>(null);

const numberOfResults = configuration.numberResult || 7;
return (
<React.Fragment>
{renderPortal(
Expand Down Expand Up @@ -215,6 +215,7 @@ export function Main({
<FiltersMemo
searchQuery={searchQuery}
onAddFilterToken={addFilterToken}
numberOfResults={numberOfResults}
onRemoveFilterToken={removeFilterToken}
onConfigurationChange={onConfigurationChange}
filtersSelect={configuration.filterTokens}
Expand Down Expand Up @@ -242,6 +243,7 @@ export function Main({
configuration.filtersConfigurable?.isCollapsable ?? true
}
numberItems={configuration.filtersConfigurable?.numberItems}
numberOfResults={numberOfResults}
/>
</I18nextProvider>,
configuration.filtersConfigurable
Expand All @@ -263,6 +265,7 @@ export function Main({
<FiltersHorizontalMemo
searchQuery={searchQuery}
onAddFilterToken={addFilterToken}
numberOfResults={numberOfResults}
sortAfterKey={sortAfterKey}
onRemoveFilterToken={removeFilterToken}
onConfigurationChange={onConfigurationChange}
Expand Down Expand Up @@ -296,6 +299,7 @@ export function Main({
language={languageSelect}
setSortAfterKey={setSortAfterKey}
sortAfterKey={sortAfterKey}
numberOfResults={numberOfResults}
/>
</I18nextProvider>,
configuration.results,
Expand All @@ -321,6 +325,7 @@ export function Main({
language={languageSelect}
setSortAfterKey={setSortAfterKey}
sortAfterKey={sortAfterKey}
numberOfResults={numberOfResults}
/>
</I18nextProvider>,
configuration.resultList ? configuration.resultList.element : null,
Expand All @@ -341,7 +346,7 @@ export function Main({
setSortAfterKey={setSortAfterKey}
sortAfterKey={sortAfterKey}
numberOfResults={totalResult || 0}
pagination={7}
pagination={numberOfResults}
currentPage={currentPage}
setCurrentPage={setCurrentPage}
/>
Expand Down Expand Up @@ -457,6 +462,7 @@ export function Main({
isCollapsable={
configuration.filtersMobileLiveChange?.isCollapsable ?? true
}
numberOfResults={numberOfResults}
/>
</I18nextProvider>,
configuration.filtersMobileLiveChange?.element !== undefined
Expand Down
2 changes: 2 additions & 0 deletions js-packages/search-frontend/src/embeddable/entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export type Configuration = {
defaultTokens: Array<SearchToken>;
resultsDisplayMode: ResultsDisplayMode;
tenant: string | null;
numberResult: number | null | undefined;
isQueryAnalysis: boolean | null;
token: string | null;
totalResult: Element | string | null;
Expand Down Expand Up @@ -310,6 +311,7 @@ const defaultConfiguration: Configuration = {
searchAutoselect: true,
searchReplaceText: true,
isQueryAnalysis: true,
numberResult: null,
filterTokens: [],
defaultTokens: [],
resultsDisplayMode: { type: "infinite" },
Expand Down

0 comments on commit d42d3a5

Please sign in to comment.