@stapel/search-react 0.24.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -0
- package/MODULE.md +21 -9
- package/README.md +109 -15
- package/dist/api/generated/schema.d.ts +18 -3
- package/dist/api/generated/schema.d.ts.map +1 -1
- package/dist/api/types.d.ts +39 -4
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/types.js.map +1 -1
- package/dist/default/FacetGroupControl.d.ts +20 -13
- package/dist/default/FacetGroupControl.d.ts.map +1 -1
- package/dist/default/FacetGroupControl.js +29 -21
- package/dist/default/FacetGroupControl.js.map +1 -1
- package/dist/default/FacetPanelPane.d.ts +15 -4
- package/dist/default/FacetPanelPane.d.ts.map +1 -1
- package/dist/default/FacetPanelPane.js +10 -5
- package/dist/default/FacetPanelPane.js.map +1 -1
- package/dist/default/OtherCategoriesLine.d.ts +49 -0
- package/dist/default/OtherCategoriesLine.d.ts.map +1 -0
- package/dist/default/OtherCategoriesLine.js +127 -0
- package/dist/default/OtherCategoriesLine.js.map +1 -0
- package/dist/default/SearchPage.d.ts +36 -0
- package/dist/default/SearchPage.d.ts.map +1 -1
- package/dist/default/SearchPage.js +12 -4
- package/dist/default/SearchPage.js.map +1 -1
- package/dist/default/SearchResultsPane.d.ts +15 -0
- package/dist/default/SearchResultsPane.d.ts.map +1 -1
- package/dist/default/SearchResultsPane.js +4 -1
- package/dist/default/SearchResultsPane.js.map +1 -1
- package/dist/default/index.d.ts +2 -0
- package/dist/default/index.d.ts.map +1 -1
- package/dist/default/index.js +1 -0
- package/dist/default/index.js.map +1 -1
- package/dist/headless/SearchStateProvider.d.ts +12 -2
- package/dist/headless/SearchStateProvider.d.ts.map +1 -1
- package/dist/headless/SearchStateProvider.js +58 -6
- package/dist/headless/SearchStateProvider.js.map +1 -1
- package/dist/headless/useOtherCategories.d.ts +52 -0
- package/dist/headless/useOtherCategories.d.ts.map +1 -0
- package/dist/headless/useOtherCategories.js +92 -0
- package/dist/headless/useOtherCategories.js.map +1 -0
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +3 -0
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/generated/errors.es.gen.d.ts.map +1 -1
- package/dist/i18n/generated/errors.es.gen.js +1 -0
- package/dist/i18n/generated/errors.es.gen.js.map +1 -1
- package/dist/i18n/generated/errors.gen.d.ts +6 -0
- package/dist/i18n/generated/errors.gen.d.ts.map +1 -1
- package/dist/i18n/generated/errors.gen.js +3 -0
- package/dist/i18n/generated/errors.gen.js.map +1 -1
- package/dist/i18n/generated/errors.ru.gen.d.ts.map +1 -1
- package/dist/i18n/generated/errors.ru.gen.js +1 -0
- package/dist/i18n/generated/errors.ru.gen.js.map +1 -1
- package/dist/i18n/keys.d.ts +25 -0
- package/dist/i18n/keys.d.ts.map +1 -1
- package/dist/i18n/keys.js +29 -0
- package/dist/i18n/keys.js.map +1 -1
- package/dist/i18n/ru.d.ts.map +1 -1
- package/dist/i18n/ru.js +4 -0
- package/dist/i18n/ru.js.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/model/queries.d.ts.map +1 -1
- package/dist/model/queries.js +9 -1
- package/dist/model/queries.js.map +1 -1
- package/dist/state/facets.d.ts +62 -11
- package/dist/state/facets.d.ts.map +1 -1
- package/dist/state/facets.js +141 -29
- package/dist/state/facets.js.map +1 -1
- package/dist/state/urlState.d.ts +77 -2
- package/dist/state/urlState.d.ts.map +1 -1
- package/dist/state/urlState.js +80 -6
- package/dist/state/urlState.js.map +1 -1
- package/llms.txt +4 -2
- package/manifest.json +45 -1
- package/nav-manifest.json +1 -1
- package/package.json +10 -10
- package/src/analytics/generated/events.json +1 -1
- package/src/api/generated/schema.ts +18 -3
- package/src/api/types.ts +42 -4
- package/src/default/FacetGroupControl.tsx +27 -23
- package/src/default/FacetPanelPane.tsx +30 -8
- package/src/default/OtherCategoriesLine.tsx +238 -0
- package/src/default/SearchPage.tsx +57 -1
- package/src/default/SearchResultsPane.tsx +28 -0
- package/src/default/index.ts +13 -0
- package/src/headless/SearchStateProvider.tsx +94 -4
- package/src/headless/useOtherCategories.ts +193 -0
- package/src/i18n/es.ts +4 -0
- package/src/i18n/generated/errors.es.gen.ts +1 -0
- package/src/i18n/generated/errors.gen.ts +3 -0
- package/src/i18n/generated/errors.json +9 -0
- package/src/i18n/generated/errors.ru.gen.ts +1 -0
- package/src/i18n/keys.ts +32 -0
- package/src/i18n/ru.ts +5 -0
- package/src/index.ts +23 -1
- package/src/model/queries.ts +11 -1
- package/src/state/facets.ts +173 -30
- package/src/state/urlState.ts +137 -5
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "The same query, in another section" — the categories THIS answer is made
|
|
3
|
+
* of, read out of the answer that drew the cards.
|
|
4
|
+
*
|
|
5
|
+
* ## What it replaces
|
|
6
|
+
*
|
|
7
|
+
* A storefront drew this as a full-width block under the results: one row per
|
|
8
|
+
* category, fetched from `/suggest` AFTER the page had settled, so a tall
|
|
9
|
+
* panel appeared a beat late and pushed everything a person was already
|
|
10
|
+
* reading. Both halves were avoidable. The block was tall where one line
|
|
11
|
+
* says the same thing, and the request was a second ask for something the
|
|
12
|
+
* page already had: `/query` answers with `facet_meta.categories` — `{path,
|
|
13
|
+
* count}` for every category the candidate set contains — and that is
|
|
14
|
+
* exactly the list the block was printing.
|
|
15
|
+
*
|
|
16
|
+
* So the rows come from the SEARCH response. No request of this hook's own
|
|
17
|
+
* while there are results, and therefore nothing to arrive late.
|
|
18
|
+
*
|
|
19
|
+
* ## The one case that DOES earn a request
|
|
20
|
+
*
|
|
21
|
+
* An empty result set has no candidates, so `facet_meta.categories` is empty
|
|
22
|
+
* too — and that is precisely the screen where "this word exists in these
|
|
23
|
+
* sections" is worth the most. There, and only there, `/suggest` is asked.
|
|
24
|
+
* The bag says so through {@link OtherCategoriesBag.reserving}, so a surface
|
|
25
|
+
* can hold the row's height from the first frame instead of letting the
|
|
26
|
+
* answer push the page a second time.
|
|
27
|
+
*
|
|
28
|
+
* ## Names come from the cache, not from a request
|
|
29
|
+
*
|
|
30
|
+
* `facet_meta.categories` carries id PATHS and counts, never names — the
|
|
31
|
+
* catalogue belongs to `categories-react`. Three sources are tried, in order:
|
|
32
|
+
*
|
|
33
|
+
* 1. the host's resolver (a surface prop), which is the only one that can
|
|
34
|
+
* name an id path with certainty;
|
|
35
|
+
* 2. the `/suggest` answer ALREADY IN THE QUERY CACHE — the type-ahead asked
|
|
36
|
+
* about this same word a keystroke earlier, and its rows carry the
|
|
37
|
+
* server's own names. `useSuggest` with `enabled: false` hands back a
|
|
38
|
+
* cached answer and fires nothing, so this costs no request;
|
|
39
|
+
* 3. the path's last segment, when it is a slug rather than a number.
|
|
40
|
+
*
|
|
41
|
+
* A row none of the three can name is DROPPED rather than printed as "163" —
|
|
42
|
+
* the same rule `categoryLeaf` states for the category chip.
|
|
43
|
+
*/
|
|
44
|
+
import type { SearchResponse, SuggestCategory } from "../api/types.js";
|
|
45
|
+
import { useSearchQuery, useSuggest } from "../model/queries.js";
|
|
46
|
+
import { offerableCategories } from "./useSearchBox.js";
|
|
47
|
+
import { useSearchState } from "./SearchStateProvider.js";
|
|
48
|
+
|
|
49
|
+
/** How many entries the line prints before it folds the rest. */
|
|
50
|
+
export const OTHER_CATEGORIES_LIMIT = 8;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The phone's cap.
|
|
54
|
+
*
|
|
55
|
+
* Half the desktop's, because the requirement is a LINE and at 390px eight
|
|
56
|
+
* entries are not one — they are the block this replaces, wearing a comma.
|
|
57
|
+
* Four short section names plus the fold marker are the two rows a phone can
|
|
58
|
+
* spend on a navigation aid above a list of cards.
|
|
59
|
+
*/
|
|
60
|
+
export const OTHER_CATEGORIES_PHONE_LIMIT = 4;
|
|
61
|
+
|
|
62
|
+
/** One category the current answer reached, with the count that answer gives it. */
|
|
63
|
+
export interface OtherCategoryRow {
|
|
64
|
+
/** The slash-joined id path — the same string the `category` filter takes,
|
|
65
|
+
* so narrowing to it needs no translation and no tree. */
|
|
66
|
+
readonly category: string;
|
|
67
|
+
/** Documents matching THIS query that live there. Scoped to the query, which
|
|
68
|
+
* is why narrowing the search is the honest destination and the bare
|
|
69
|
+
* category feed is not: the feed would show a different number. */
|
|
70
|
+
readonly count: number;
|
|
71
|
+
/** The server's own name, when this row came from `/suggest` or when a
|
|
72
|
+
* cached suggest answer named the same path. */
|
|
73
|
+
readonly name?: string;
|
|
74
|
+
/** Display names root→leaf, when the server sent them. */
|
|
75
|
+
readonly path?: readonly string[];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface OtherCategoriesBag {
|
|
79
|
+
/** Every row, uncapped and in the order the line should print them. Capping
|
|
80
|
+
* is a decision about the SURFACE (a phone takes fewer), so it is not made
|
|
81
|
+
* here. */
|
|
82
|
+
readonly rows: readonly OtherCategoryRow[];
|
|
83
|
+
/**
|
|
84
|
+
* Where the rows came from. `"results"` — the search response itself, drawn
|
|
85
|
+
* in the same frame as the cards. `"suggest"` — the empty-result path, the
|
|
86
|
+
* only one with a request behind it. `"none"` — nothing to offer.
|
|
87
|
+
*/
|
|
88
|
+
readonly source: "results" | "suggest" | "none";
|
|
89
|
+
/**
|
|
90
|
+
* The empty-result path is active, so a row is coming from a request that
|
|
91
|
+
* has not landed (or landed empty). A surface keeps the height either way:
|
|
92
|
+
* space reserved from the first frame is space nothing can push.
|
|
93
|
+
*/
|
|
94
|
+
readonly reserving: boolean;
|
|
95
|
+
/** That request is in flight right now. */
|
|
96
|
+
readonly pending: boolean;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const NO_ROWS: readonly OtherCategoryRow[] = [];
|
|
100
|
+
|
|
101
|
+
/** The path's last segment, when it names something — never a bare id. */
|
|
102
|
+
export function otherCategoryLeaf(category: string): string | undefined {
|
|
103
|
+
const parts = category.split("/").filter((part) => part.length > 0);
|
|
104
|
+
const leaf = parts[parts.length - 1];
|
|
105
|
+
if (leaf === undefined || /^\d+$/.test(leaf)) return undefined;
|
|
106
|
+
return leaf;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The rows the ANSWER carries, busiest first and without the section the
|
|
110
|
+
* search is already in. */
|
|
111
|
+
function rowsFromResponse(
|
|
112
|
+
answer: SearchResponse | undefined,
|
|
113
|
+
applied: string | undefined,
|
|
114
|
+
named: ReadonlyMap<string, SuggestCategory>
|
|
115
|
+
): readonly OtherCategoryRow[] {
|
|
116
|
+
const meta = answer?.facet_meta.categories ?? [];
|
|
117
|
+
const rows = meta
|
|
118
|
+
// "Other" than the one the search is in. Descendants stay: narrowing from
|
|
119
|
+
// a branch to one of its leaves is a different section and the move this
|
|
120
|
+
// line exists for.
|
|
121
|
+
.filter((row) => row.category !== applied)
|
|
122
|
+
.map((row) => {
|
|
123
|
+
const match = named.get(row.category);
|
|
124
|
+
return {
|
|
125
|
+
category: row.category,
|
|
126
|
+
count: row.count,
|
|
127
|
+
...(match !== undefined ? { name: match.name, path: match.path } : {}),
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
// The server documents "busiest first" and the cap has to take the busiest
|
|
131
|
+
// eight; asserting the order here is cheaper than trusting it and being
|
|
132
|
+
// wrong about which eight a person sees.
|
|
133
|
+
return [...rows].sort((a, b) =>
|
|
134
|
+
b.count === a.count ? a.category.localeCompare(b.category) : b.count - a.count
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function useOtherCategories(
|
|
139
|
+
options: { readonly enabled?: boolean } = {}
|
|
140
|
+
): OtherCategoriesBag {
|
|
141
|
+
const { state } = useSearchState();
|
|
142
|
+
const enabled = options.enabled ?? true;
|
|
143
|
+
|
|
144
|
+
// The SAME query the results pane runs: identical key, identical cache
|
|
145
|
+
// entry, no second request. This hook can therefore be mounted anywhere
|
|
146
|
+
// under the provider without the envelope having to be threaded to it.
|
|
147
|
+
const query = useSearchQuery(state, { enabled });
|
|
148
|
+
const answer = query.data;
|
|
149
|
+
|
|
150
|
+
// Ready AND empty. `answer === undefined` is "still loading", which is not
|
|
151
|
+
// an empty result and must not spend a request.
|
|
152
|
+
const resultsEmpty = enabled && answer !== undefined && answer.items.length === 0;
|
|
153
|
+
|
|
154
|
+
// `enabled: false` still returns whatever the box already put in the cache
|
|
155
|
+
// and asks nothing — which is how a page WITH results gets the server's
|
|
156
|
+
// names for free. A page WITHOUT results turns the same hook into the one
|
|
157
|
+
// request this feature ever makes.
|
|
158
|
+
const suggest = useSuggest({ type: state.type, q: state.q, enabled: resultsEmpty });
|
|
159
|
+
// Through the pair's own reader, which is where "this server sent no
|
|
160
|
+
// categories key at all" is already distinguished from "nothing matched".
|
|
161
|
+
const suggested = offerableCategories(suggest.data);
|
|
162
|
+
const named = new Map(suggested.map((row) => [row.category, row]));
|
|
163
|
+
|
|
164
|
+
const fromResults = rowsFromResponse(answer, state.category, named);
|
|
165
|
+
|
|
166
|
+
const pending = resultsEmpty && suggest.isLoading && suggest.fetchStatus === "fetching";
|
|
167
|
+
|
|
168
|
+
if (fromResults.length > 0) {
|
|
169
|
+
return { rows: fromResults, source: "results", reserving: false, pending: false };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (resultsEmpty) {
|
|
173
|
+
// The server's rank order is kept as sent: `/suggest` ranks by match grade
|
|
174
|
+
// and stock before count, and re-sorting by count here would throw that
|
|
175
|
+
// away for a number that is not what ranked them.
|
|
176
|
+
const rows = suggested
|
|
177
|
+
.filter((row) => row.category !== state.category)
|
|
178
|
+
.map((row) => ({
|
|
179
|
+
category: row.category,
|
|
180
|
+
count: row.count,
|
|
181
|
+
name: row.name,
|
|
182
|
+
path: row.path,
|
|
183
|
+
}));
|
|
184
|
+
return {
|
|
185
|
+
rows,
|
|
186
|
+
source: rows.length > 0 ? "suggest" : "none",
|
|
187
|
+
reserving: true,
|
|
188
|
+
pending,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return { rows: NO_ROWS, source: "none", reserving: false, pending: false };
|
|
193
|
+
}
|
package/src/i18n/es.ts
CHANGED
|
@@ -131,6 +131,10 @@ export const searchI18nBundleEs: I18nDictionary = {
|
|
|
131
131
|
"search.empty.widen_radius": "Buscar en un radio de {km} km",
|
|
132
132
|
"search.empty.anywhere": "Buscar en todas partes",
|
|
133
133
|
"search.empty.drop_filter": "Sin «{name}»",
|
|
134
|
+
|
|
135
|
+
"search.other_categories.label": "Buscar en otras categorías:",
|
|
136
|
+
"search.other_categories.narrow": "Buscar en {name}",
|
|
137
|
+
"search.other_categories.more": "{count} más",
|
|
134
138
|
"search.category.title": "Categoría",
|
|
135
139
|
"search.category.clear": "Buscar en todo el catálogo",
|
|
136
140
|
"search.category.current": "Buscando dentro de {path}",
|
|
@@ -35,6 +35,7 @@ export const searchErrorBundleEs: Record<SearchErrorCode, string> = {
|
|
|
35
35
|
"error.400.search_sort_needs_center": "Ordenar por distancia requiere lat y lon",
|
|
36
36
|
"error.400.search_too_many_facets": "Demasiados filtros de faceta (límite {limit})",
|
|
37
37
|
"error.400.search_too_many_ranges": "Demasiados filtros de rango (límite {limit})",
|
|
38
|
+
"error.400.search_unknown_category": "No existe la categoría «{category}». `category` admite el id del nodo o su ruta raíz/hoja.",
|
|
38
39
|
"error.400.search_unknown_doc_type": "Tipo de búsqueda desconocido «{doc_type}»",
|
|
39
40
|
"error.400.search_unknown_sort": "Orden desconocido «{sort}»",
|
|
40
41
|
"error.400.search_window_exceeded": "Esta página de resultados supera el límite de {window}. Acote la búsqueda en lugar de avanzar más páginas.",
|
|
@@ -58,6 +58,7 @@ export const SEARCH_ERRORS = {
|
|
|
58
58
|
"error.400.search_sort_needs_center": { status: 400, params: [], remediation: "fix_input", en: "Sorting by distance needs lat and lon" },
|
|
59
59
|
"error.400.search_too_many_facets": { status: 400, params: ["limit"], remediation: "fix_input", en: "Too many facet filters (limit {limit})" },
|
|
60
60
|
"error.400.search_too_many_ranges": { status: 400, params: ["limit"], remediation: "fix_input", en: "Too many range filters (limit {limit})" },
|
|
61
|
+
"error.400.search_unknown_category": { status: 400, params: ["category"], remediation: "fix_input", en: "No category '{category}' exists. `category` takes the node id or its root/leaf path." },
|
|
61
62
|
"error.400.search_unknown_doc_type": { status: 400, params: ["doc_type"], remediation: "fix_input", en: "Unknown search type '{doc_type}'" },
|
|
62
63
|
"error.400.search_unknown_sort": { status: 400, params: ["sort"], remediation: "fix_input", en: "Unknown sort '{sort}'" },
|
|
63
64
|
"error.400.search_window_exceeded": { status: 400, params: ["window"], remediation: "fix_input", en: "This result page is beyond the maximum window of {window}. Narrow the search instead of paging deeper." },
|
|
@@ -118,6 +119,7 @@ export const SEARCH_ERROR_CODES: readonly SearchErrorCode[] = [
|
|
|
118
119
|
"error.400.search_sort_needs_center",
|
|
119
120
|
"error.400.search_too_many_facets",
|
|
120
121
|
"error.400.search_too_many_ranges",
|
|
122
|
+
"error.400.search_unknown_category",
|
|
121
123
|
"error.400.search_unknown_doc_type",
|
|
122
124
|
"error.400.search_unknown_sort",
|
|
123
125
|
"error.400.search_window_exceeded",
|
|
@@ -180,6 +182,7 @@ export const searchErrorBundleEn: Record<SearchErrorCode, string> = {
|
|
|
180
182
|
"error.400.search_sort_needs_center": "Sorting by distance needs lat and lon",
|
|
181
183
|
"error.400.search_too_many_facets": "Too many facet filters (limit {limit})",
|
|
182
184
|
"error.400.search_too_many_ranges": "Too many range filters (limit {limit})",
|
|
185
|
+
"error.400.search_unknown_category": "No category '{category}' exists. `category` takes the node id or its root/leaf path.",
|
|
183
186
|
"error.400.search_unknown_doc_type": "Unknown search type '{doc_type}'",
|
|
184
187
|
"error.400.search_unknown_sort": "Unknown sort '{sort}'",
|
|
185
188
|
"error.400.search_window_exceeded": "This result page is beyond the maximum window of {window}. Narrow the search instead of paging deeper.",
|
|
@@ -195,6 +195,15 @@
|
|
|
195
195
|
"remediation": "fix_input",
|
|
196
196
|
"en": "Too many range filters (limit {limit})"
|
|
197
197
|
},
|
|
198
|
+
{
|
|
199
|
+
"code": "error.400.search_unknown_category",
|
|
200
|
+
"status": 400,
|
|
201
|
+
"params": [
|
|
202
|
+
"category"
|
|
203
|
+
],
|
|
204
|
+
"remediation": "fix_input",
|
|
205
|
+
"en": "No category '{category}' exists. `category` takes the node id or its root/leaf path."
|
|
206
|
+
},
|
|
198
207
|
{
|
|
199
208
|
"code": "error.400.search_unknown_doc_type",
|
|
200
209
|
"status": 400,
|
|
@@ -35,6 +35,7 @@ export const searchErrorBundleRu: Record<SearchErrorCode, string> = {
|
|
|
35
35
|
"error.400.search_sort_needs_center": "Сортировка по расстоянию требует координат (lat и lon)",
|
|
36
36
|
"error.400.search_too_many_facets": "Слишком много фильтров-фасетов (предел {limit})",
|
|
37
37
|
"error.400.search_too_many_ranges": "Слишком много диапазонных фильтров (предел {limit})",
|
|
38
|
+
"error.400.search_unknown_category": "Категории «{category}» не существует. В `category` передаётся id узла или путь корень/лист.",
|
|
38
39
|
"error.400.search_unknown_doc_type": "Неизвестный тип поиска «{doc_type}»",
|
|
39
40
|
"error.400.search_unknown_sort": "Неизвестная сортировка «{sort}»",
|
|
40
41
|
"error.400.search_window_exceeded": "Эта страница выдачи выходит за предел в {window} результатов. Уточните запрос вместо перелистывания вглубь.",
|
package/src/i18n/keys.ts
CHANGED
|
@@ -282,6 +282,33 @@ export const SEARCH_I18N_KEYS = {
|
|
|
282
282
|
/** "Without {name}" — one applied filter, named as its own chip names it. */
|
|
283
283
|
emptyDropFilter: "search.empty.drop_filter",
|
|
284
284
|
|
|
285
|
+
// ── the same query, in another section (one line, from the answer) ───────
|
|
286
|
+
/**
|
|
287
|
+
* The line's lead-in — "Search in other categories:". It ends in a colon
|
|
288
|
+
* because what follows is a list on the same line, and a translator who is
|
|
289
|
+
* shown the string without one has no way to know that.
|
|
290
|
+
*
|
|
291
|
+
* Not `search.box.categories` ("Sections", the type-ahead's group heading):
|
|
292
|
+
* that one titles a menu of destinations while a person types, this one
|
|
293
|
+
* introduces a row of narrowings beside a result list. Same noun, two
|
|
294
|
+
* surfaces, and the languages that decline it need both.
|
|
295
|
+
*/
|
|
296
|
+
otherCategoriesLabel: "search.other_categories.label",
|
|
297
|
+
/**
|
|
298
|
+
* The accessible name of one entry. The visible caption is "Cars 12" — a
|
|
299
|
+
* name and a number, which says nothing about what pressing it DOES. This
|
|
300
|
+
* does: it narrows the search that is already on screen, and it keeps the
|
|
301
|
+
* query, which is why the number beside it stays true afterwards.
|
|
302
|
+
*/
|
|
303
|
+
otherCategoriesNarrow: "search.other_categories.narrow",
|
|
304
|
+
/**
|
|
305
|
+
* The fold at the end of the line: how many sections it did not print.
|
|
306
|
+
* `{count}` is a bare number after a word, not a counted noun in a
|
|
307
|
+
* sentence, so this is not a plural family — the same shape as
|
|
308
|
+
* `facetsAllFilters` and `filtersChipOverflow`.
|
|
309
|
+
*/
|
|
310
|
+
otherCategoriesMore: "search.other_categories.more",
|
|
311
|
+
|
|
285
312
|
// ── category (a host slot, plus the control that removes it) ─────────────
|
|
286
313
|
categoryTitle: "search.category.title",
|
|
287
314
|
categoryClear: "search.category.clear",
|
|
@@ -573,6 +600,11 @@ export const searchI18nBundleEn: Record<string, string> = {
|
|
|
573
600
|
"search.empty.widen_radius": "Search within {km} km",
|
|
574
601
|
"search.empty.anywhere": "Search anywhere",
|
|
575
602
|
"search.empty.drop_filter": "Without {name}",
|
|
603
|
+
|
|
604
|
+
"search.other_categories.label": "Search in other categories:",
|
|
605
|
+
"search.other_categories.narrow": "Search in {name}",
|
|
606
|
+
"search.other_categories.more": "{count} more",
|
|
607
|
+
|
|
576
608
|
"search.category.title": "Category",
|
|
577
609
|
"search.category.clear": "Search the whole catalogue",
|
|
578
610
|
"search.category.current": "Searching inside {path}",
|
package/src/i18n/ru.ts
CHANGED
|
@@ -166,6 +166,11 @@ export const searchI18nBundleRu: I18nDictionary = {
|
|
|
166
166
|
"search.empty.widen_radius": "Искать в радиусе {km} км",
|
|
167
167
|
"search.empty.anywhere": "Искать везде",
|
|
168
168
|
"search.empty.drop_filter": "Без «{name}»",
|
|
169
|
+
|
|
170
|
+
// One line, out of the same answer the cards came from: section and count.
|
|
171
|
+
"search.other_categories.label": "Поиск в других категориях:",
|
|
172
|
+
"search.other_categories.narrow": "Искать в разделе «{name}»",
|
|
173
|
+
"search.other_categories.more": "ещё {count}",
|
|
169
174
|
"search.category.title": "Категория",
|
|
170
175
|
"search.category.clear": "Искать по всему каталогу",
|
|
171
176
|
"search.category.current": "Ищем внутри {path}",
|
package/src/index.ts
CHANGED
|
@@ -77,11 +77,16 @@ export type {
|
|
|
77
77
|
|
|
78
78
|
// ── state (pure: no React, no router) ────────────────────────────────────────
|
|
79
79
|
export {
|
|
80
|
+
EMPTY_FACET_KEYS,
|
|
80
81
|
FILTER_PREFIX,
|
|
81
82
|
RANGE_PREFIX,
|
|
82
83
|
SEARCH_PARAM,
|
|
83
84
|
activeFilterCount,
|
|
85
|
+
buildFacetKeyMap,
|
|
84
86
|
clearFilters,
|
|
87
|
+
facetKeyForSlug,
|
|
88
|
+
facetKeyMapFromLabels,
|
|
89
|
+
facetSlugForKey,
|
|
85
90
|
ownsParam,
|
|
86
91
|
parseSearchState,
|
|
87
92
|
patchSearchState,
|
|
@@ -91,6 +96,7 @@ export {
|
|
|
91
96
|
writeSearchState,
|
|
92
97
|
} from "./state/urlState.js";
|
|
93
98
|
export type {
|
|
99
|
+
FacetKeyMap,
|
|
94
100
|
ParseSearchStateOptions,
|
|
95
101
|
ParsedSearchState,
|
|
96
102
|
SearchStateIssue,
|
|
@@ -118,6 +124,7 @@ export {
|
|
|
118
124
|
buildFacetGroups,
|
|
119
125
|
facetGroupHasEvidence,
|
|
120
126
|
facetGroupIsDrawable,
|
|
127
|
+
facetGroupIsVocabularyBacked,
|
|
121
128
|
facetOptionLabel,
|
|
122
129
|
isFacetableFeature,
|
|
123
130
|
orderFacetGroupsBySchema,
|
|
@@ -177,7 +184,12 @@ export { useRankingDisclosure, useSearchQuery, useSuggest } from "./model/querie
|
|
|
177
184
|
|
|
178
185
|
// ── headless (renderless components) ─────────────────────────────────────────
|
|
179
186
|
export { SearchProvider } from "./headless/SearchProvider.js";
|
|
180
|
-
export {
|
|
187
|
+
export {
|
|
188
|
+
SearchStateProvider,
|
|
189
|
+
useFacetKeys,
|
|
190
|
+
usePublishFacetKeys,
|
|
191
|
+
useSearchState,
|
|
192
|
+
} from "./headless/SearchStateProvider.js";
|
|
181
193
|
export type {
|
|
182
194
|
SearchParamsAdapter,
|
|
183
195
|
SearchStateBag,
|
|
@@ -194,6 +206,16 @@ export type {
|
|
|
194
206
|
} from "./headless/useFacetLabels.js";
|
|
195
207
|
export { useAppliedSort } from "./headless/useAppliedSort.js";
|
|
196
208
|
export { offerableCategories, useSearchBox } from "./headless/useSearchBox.js";
|
|
209
|
+
export {
|
|
210
|
+
OTHER_CATEGORIES_LIMIT,
|
|
211
|
+
OTHER_CATEGORIES_PHONE_LIMIT,
|
|
212
|
+
otherCategoryLeaf,
|
|
213
|
+
useOtherCategories,
|
|
214
|
+
} from "./headless/useOtherCategories.js";
|
|
215
|
+
export type {
|
|
216
|
+
OtherCategoriesBag,
|
|
217
|
+
OtherCategoryRow,
|
|
218
|
+
} from "./headless/useOtherCategories.js";
|
|
197
219
|
export type { SearchBoxBag, UseSearchBoxOptions } from "./headless/useSearchBox.js";
|
|
198
220
|
export { countQueryState, useSearchCount } from "./headless/useSearchCount.js";
|
|
199
221
|
export type {
|
package/src/model/queries.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
SuggestAnswer,
|
|
10
10
|
} from "../api/types.js";
|
|
11
11
|
import { SUGGEST_MAX_LIMIT, SUGGEST_MIN_CHARS } from "../state/limits.js";
|
|
12
|
+
import { usePublishFacetKeys } from "../headless/SearchStateProvider.js";
|
|
12
13
|
import { useSearchApi } from "./context.js";
|
|
13
14
|
import { searchQueryKeys } from "./queryKeys.js";
|
|
14
15
|
|
|
@@ -53,13 +54,22 @@ export function useSearchQuery(
|
|
|
53
54
|
): UseQueryResult<SearchResponse, StapelApiError> {
|
|
54
55
|
const api = useSearchApi();
|
|
55
56
|
const params = searchQueryParams(state);
|
|
56
|
-
|
|
57
|
+
const query = useQuery<SearchResponse, StapelApiError>({
|
|
57
58
|
queryKey: searchQueryKeys.query(params),
|
|
58
59
|
queryFn: ({ signal }) => api.query(state, { signal }),
|
|
59
60
|
enabled: (options?.enabled ?? true) && state.type.length > 0,
|
|
60
61
|
placeholderData: keepPreviousData,
|
|
61
62
|
retry: false,
|
|
62
63
|
});
|
|
64
|
+
// The answer states what each axis is called IN THE ADDRESS
|
|
65
|
+
// (`facet_labels[slug].url_key`); the codec that writes the address sits
|
|
66
|
+
// above this hook, so the map is handed up. Every surface reads through
|
|
67
|
+
// this one hook, so there is exactly one place the address learns its own
|
|
68
|
+
// spelling — and outside a `<SearchStateProvider>` it is a no-op.
|
|
69
|
+
usePublishFacetKeys(
|
|
70
|
+
query.data === undefined ? undefined : query.data.facet_labels
|
|
71
|
+
);
|
|
72
|
+
return query;
|
|
63
73
|
}
|
|
64
74
|
|
|
65
75
|
/**
|