@backstage/plugin-search-react 1.2.2-next.0 → 1.3.0-next.2

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/dist/index.esm.js CHANGED
@@ -45,10 +45,7 @@ const HighlightedSearchResultText = ({
45
45
  [postTag, preTag, text]
46
46
  );
47
47
  return /* @__PURE__ */ React.createElement(React.Fragment, null, terms.map(
48
- (t, idx) => t.includes(preTag) ? /* @__PURE__ */ React.createElement("mark", {
49
- className: classes.highlight,
50
- key: idx
51
- }, t.replace(new RegExp(`${preTag}|${postTag}`, "g"), "")) : t
48
+ (t, idx) => t.includes(preTag) ? /* @__PURE__ */ React.createElement("mark", { className: classes.highlight, key: idx }, t.replace(new RegExp(`${preTag}|${postTag}`, "g"), "")) : t
52
49
  ));
53
50
  };
54
51
 
@@ -139,38 +136,43 @@ const useSearchContextValue = (initialValue = searchInitialState) => {
139
136
  const LocalSearchContext = (props) => {
140
137
  const { initialState, children } = props;
141
138
  const value = useSearchContextValue(initialState);
142
- return /* @__PURE__ */ React.createElement(AnalyticsContext, {
143
- attributes: { searchTypes: value.types.sort().join(",") }
144
- }, /* @__PURE__ */ React.createElement(SearchContext.Provider, {
145
- value: createVersionedValueMap({ 1: value })
146
- }, children));
139
+ return /* @__PURE__ */ React.createElement(
140
+ AnalyticsContext,
141
+ {
142
+ attributes: { searchTypes: value.types.sort().join(",") }
143
+ },
144
+ /* @__PURE__ */ React.createElement(SearchContext.Provider, { value: createVersionedValueMap({ 1: value }) }, children)
145
+ );
147
146
  };
148
147
  const SearchContextProvider = (props) => {
149
148
  const { initialState, inheritParentContextIfAvailable, children } = props;
150
149
  const hasParentContext = useSearchContextCheck();
151
- return hasParentContext && inheritParentContextIfAvailable ? /* @__PURE__ */ React.createElement(React.Fragment, null, children) : /* @__PURE__ */ React.createElement(LocalSearchContext, {
152
- initialState
153
- }, children);
150
+ return hasParentContext && inheritParentContextIfAvailable ? /* @__PURE__ */ React.createElement(React.Fragment, null, children) : /* @__PURE__ */ React.createElement(LocalSearchContext, { initialState }, children);
154
151
  };
155
152
 
156
153
  const TrackSearch = ({ children }) => {
154
+ var _a, _b;
155
+ const useHasChanged = (value) => {
156
+ const previousVal = usePrevious(value);
157
+ return previousVal !== value;
158
+ };
157
159
  const analytics = useAnalytics();
158
- const { term } = useSearch();
160
+ const { term, result } = useSearch();
161
+ const numberOfResults = (_b = (_a = result.value) == null ? void 0 : _a.numberOfResults) != null ? _b : void 0;
162
+ const hasStartedLoading = useHasChanged(result.loading);
163
+ const hasFinishedLoading = hasStartedLoading && !result.loading;
159
164
  useEffect(() => {
160
- if (term) {
161
- analytics.captureEvent("search", term);
165
+ if (term && hasFinishedLoading) {
166
+ analytics.captureEvent("search", term, {
167
+ value: numberOfResults
168
+ });
162
169
  }
163
- }, [analytics, term]);
170
+ }, [analytics, term, numberOfResults, hasFinishedLoading]);
164
171
  return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
165
172
  };
166
173
 
167
174
  function withContext$1(Component) {
168
- return forwardRef((props, ref) => /* @__PURE__ */ React.createElement(SearchContextProvider, {
169
- inheritParentContextIfAvailable: true
170
- }, /* @__PURE__ */ React.createElement(Component, {
171
- ...props,
172
- ref
173
- })));
175
+ return forwardRef((props, ref) => /* @__PURE__ */ React.createElement(SearchContextProvider, { inheritParentContextIfAvailable: true }, /* @__PURE__ */ React.createElement(Component, { ...props, ref })));
174
176
  }
175
177
  const SearchBarBase = withContext$1(
176
178
  forwardRef((props, ref) => {
@@ -222,33 +224,24 @@ const SearchBarBase = withContext$1(
222
224
  }
223
225
  }, [onChange, onClear]);
224
226
  const placeholder = defaultPlaceholder != null ? defaultPlaceholder : `Search in ${configApi.getOptionalString("app.title") || "Backstage"}`;
225
- const startAdornment = /* @__PURE__ */ React.createElement(InputAdornment, {
226
- position: "start"
227
- }, /* @__PURE__ */ React.createElement(IconButton, {
228
- "aria-label": "Query",
229
- size: "small",
230
- disabled: true
231
- }, /* @__PURE__ */ React.createElement(SearchIcon, null)));
232
- const endAdornment = /* @__PURE__ */ React.createElement(InputAdornment, {
233
- position: "end"
234
- }, /* @__PURE__ */ React.createElement(IconButton, {
235
- "aria-label": "Clear",
236
- size: "small",
237
- onClick: handleClear
238
- }, /* @__PURE__ */ React.createElement(ClearButton, null)));
239
- return /* @__PURE__ */ React.createElement(TrackSearch, null, /* @__PURE__ */ React.createElement(InputBase, {
240
- "data-testid": "search-bar-next",
241
- ref,
242
- value,
243
- placeholder,
244
- startAdornment,
245
- endAdornment: clearButton ? endAdornment : defaultEndAdornment,
246
- inputProps: { "aria-label": "Search", ...defaultInputProps },
247
- fullWidth,
248
- onChange: handleChange,
249
- onKeyDown: handleKeyDown,
250
- ...rest
251
- }));
227
+ const startAdornment = /* @__PURE__ */ React.createElement(InputAdornment, { position: "start" }, /* @__PURE__ */ React.createElement(IconButton, { "aria-label": "Query", size: "small", disabled: true }, /* @__PURE__ */ React.createElement(SearchIcon, null)));
228
+ const endAdornment = /* @__PURE__ */ React.createElement(InputAdornment, { position: "end" }, /* @__PURE__ */ React.createElement(IconButton, { "aria-label": "Clear", size: "small", onClick: handleClear }, /* @__PURE__ */ React.createElement(ClearButton, null)));
229
+ return /* @__PURE__ */ React.createElement(TrackSearch, null, /* @__PURE__ */ React.createElement(
230
+ InputBase,
231
+ {
232
+ "data-testid": "search-bar-next",
233
+ ref,
234
+ value,
235
+ placeholder,
236
+ startAdornment,
237
+ endAdornment: clearButton ? endAdornment : defaultEndAdornment,
238
+ inputProps: { "aria-label": "Search", ...defaultInputProps },
239
+ fullWidth,
240
+ onChange: handleChange,
241
+ onKeyDown: handleKeyDown,
242
+ ...rest
243
+ }
244
+ ));
252
245
  })
253
246
  );
254
247
  const SearchBar = withContext$1(
@@ -270,23 +263,26 @@ const SearchBar = withContext$1(
270
263
  },
271
264
  [onChange, setTerm]
272
265
  );
273
- return /* @__PURE__ */ React.createElement(AnalyticsContext, {
274
- attributes: { pluginId: "search", extension: "SearchBar" }
275
- }, /* @__PURE__ */ React.createElement(SearchBarBase, {
276
- ...rest,
277
- ref,
278
- value: term,
279
- onChange: handleChange
280
- }));
266
+ return /* @__PURE__ */ React.createElement(
267
+ AnalyticsContext,
268
+ {
269
+ attributes: { pluginId: "search", extension: "SearchBar" }
270
+ },
271
+ /* @__PURE__ */ React.createElement(
272
+ SearchBarBase,
273
+ {
274
+ ...rest,
275
+ ref,
276
+ value: term,
277
+ onChange: handleChange
278
+ }
279
+ )
280
+ );
281
281
  })
282
282
  );
283
283
 
284
284
  const withContext = (Component) => {
285
- return (props) => /* @__PURE__ */ React.createElement(SearchContextProvider, {
286
- inheritParentContextIfAvailable: true
287
- }, /* @__PURE__ */ React.createElement(Component, {
288
- ...props
289
- }));
285
+ return (props) => /* @__PURE__ */ React.createElement(SearchContextProvider, { inheritParentContextIfAvailable: true }, /* @__PURE__ */ React.createElement(Component, { ...props }));
290
286
  };
291
287
  const SearchAutocomplete = withContext(
292
288
  function SearchAutocompleteComponent(props) {
@@ -332,33 +328,42 @@ const SearchAutocomplete = withContext(
332
328
  InputProps: { ref, endAdornment },
333
329
  InputLabelProps,
334
330
  ...params
335
- }) => /* @__PURE__ */ React.createElement(SearchBar, {
336
- ...params,
337
- ref,
338
- clearButton: false,
339
- value: inputValue,
340
- placeholder: inputPlaceholder,
341
- debounceTime: inputDebounceTime,
342
- endAdornment: loading ? /* @__PURE__ */ React.createElement(CircularProgress, {
343
- "data-testid": "search-autocomplete-progressbar",
344
- color: "inherit",
345
- size: 20
346
- }) : endAdornment
347
- }),
331
+ }) => /* @__PURE__ */ React.createElement(
332
+ SearchBar,
333
+ {
334
+ ...params,
335
+ ref,
336
+ clearButton: false,
337
+ value: inputValue,
338
+ placeholder: inputPlaceholder,
339
+ debounceTime: inputDebounceTime,
340
+ endAdornment: loading ? /* @__PURE__ */ React.createElement(
341
+ CircularProgress,
342
+ {
343
+ "data-testid": "search-autocomplete-progressbar",
344
+ color: "inherit",
345
+ size: 20
346
+ }
347
+ ) : endAdornment
348
+ }
349
+ ),
348
350
  [loading, inputValue, inputPlaceholder, inputDebounceTime]
349
351
  );
350
- return /* @__PURE__ */ React.createElement(Autocomplete, {
351
- ...rest,
352
- "data-testid": dataTestId,
353
- value,
354
- onChange: handleChange,
355
- options,
356
- getOptionLabel,
357
- renderInput,
358
- freeSolo,
359
- fullWidth,
360
- clearOnBlur
361
- });
352
+ return /* @__PURE__ */ React.createElement(
353
+ Autocomplete,
354
+ {
355
+ ...rest,
356
+ "data-testid": dataTestId,
357
+ value,
358
+ onChange: handleChange,
359
+ options,
360
+ getOptionLabel,
361
+ renderInput,
362
+ freeSolo,
363
+ fullWidth,
364
+ clearOnBlur
365
+ }
366
+ );
362
367
  }
363
368
  );
364
369
 
@@ -369,13 +374,16 @@ const SearchAutocompleteDefaultOption = ({
369
374
  secondaryText,
370
375
  secondaryTextTypographyProps,
371
376
  disableTextTypography
372
- }) => /* @__PURE__ */ React.createElement(React.Fragment, null, icon ? /* @__PURE__ */ React.createElement(ListItemIcon, null, icon) : null, /* @__PURE__ */ React.createElement(ListItemText, {
373
- primary: primaryText,
374
- primaryTypographyProps: primaryTextTypographyProps,
375
- secondary: secondaryText,
376
- secondaryTypographyProps: secondaryTextTypographyProps,
377
- disableTypography: disableTextTypography
378
- }));
377
+ }) => /* @__PURE__ */ React.createElement(React.Fragment, null, icon ? /* @__PURE__ */ React.createElement(ListItemIcon, null, icon) : null, /* @__PURE__ */ React.createElement(
378
+ ListItemText,
379
+ {
380
+ primary: primaryText,
381
+ primaryTypographyProps: primaryTextTypographyProps,
382
+ secondary: secondaryText,
383
+ secondaryTypographyProps: secondaryTextTypographyProps,
384
+ disableTypography: disableTextTypography
385
+ }
386
+ ));
379
387
 
380
388
  const useAsyncFilterValues = (fn, inputValue, defaultValues = [], debounce = 250) => {
381
389
  const valuesMemo = useRef({});
@@ -455,32 +463,34 @@ const AutocompleteFilter = (props) => {
455
463
  return { ...others };
456
464
  });
457
465
  };
458
- const renderInput = (params) => /* @__PURE__ */ React.createElement(TextField, {
459
- ...params,
460
- name: "search",
461
- variant: "outlined",
462
- label,
463
- fullWidth: true
464
- });
465
- const renderTags = (tagValue, getTagProps) => tagValue.map((option, index) => /* @__PURE__ */ React.createElement(Chip, {
466
- label: option,
467
- color: "primary",
468
- ...getTagProps({ index })
469
- }));
470
- return /* @__PURE__ */ React.createElement(Autocomplete, {
471
- filterSelectedOptions,
472
- limitTags,
473
- multiple,
474
- className,
475
- id: `${multiple ? "multi-" : ""}select-filter-${name}--select`,
476
- options: values || [],
477
- loading,
478
- value: filterValue,
479
- onChange: handleChange,
480
- onInputChange: (_, newValue) => setInputValue(newValue),
481
- renderInput,
482
- renderTags
483
- });
466
+ const renderInput = (params) => /* @__PURE__ */ React.createElement(
467
+ TextField,
468
+ {
469
+ ...params,
470
+ name: "search",
471
+ variant: "outlined",
472
+ label,
473
+ fullWidth: true
474
+ }
475
+ );
476
+ const renderTags = (tagValue, getTagProps) => tagValue.map((option, index) => /* @__PURE__ */ React.createElement(Chip, { label: option, color: "primary", ...getTagProps({ index }) }));
477
+ return /* @__PURE__ */ React.createElement(
478
+ Autocomplete,
479
+ {
480
+ filterSelectedOptions,
481
+ limitTags,
482
+ multiple,
483
+ className,
484
+ id: `${multiple ? "multi-" : ""}select-filter-${name}--select`,
485
+ options: values || [],
486
+ loading,
487
+ value: filterValue,
488
+ onChange: handleChange,
489
+ onInputChange: (_, newValue) => setInputValue(newValue),
490
+ renderInput,
491
+ renderTags
492
+ }
493
+ );
484
494
  };
485
495
 
486
496
  const useStyles$2 = makeStyles({
@@ -519,29 +529,38 @@ const CheckboxFilter = (props) => {
519
529
  return items.length ? { ...others, [name]: items } : others;
520
530
  });
521
531
  };
522
- return /* @__PURE__ */ React.createElement(FormControl, {
523
- className,
524
- disabled: loading,
525
- fullWidth: true,
526
- "data-testid": "search-checkboxfilter-next"
527
- }, label ? /* @__PURE__ */ React.createElement(FormLabel, {
528
- className: classes.label
529
- }, label) : null, values.map((value) => {
530
- var _a;
531
- return /* @__PURE__ */ React.createElement(FormControlLabel, {
532
- key: value,
533
- control: /* @__PURE__ */ React.createElement(Checkbox, {
534
- color: "primary",
535
- tabIndex: -1,
536
- inputProps: { "aria-labelledby": value },
537
- value,
538
- name: value,
539
- onChange: handleChange,
540
- checked: ((_a = filters[name]) != null ? _a : []).includes(value)
541
- }),
542
- label: value
543
- });
544
- }));
532
+ return /* @__PURE__ */ React.createElement(
533
+ FormControl,
534
+ {
535
+ className,
536
+ disabled: loading,
537
+ fullWidth: true,
538
+ "data-testid": "search-checkboxfilter-next"
539
+ },
540
+ label ? /* @__PURE__ */ React.createElement(FormLabel, { className: classes.label }, label) : null,
541
+ values.map((value) => {
542
+ var _a;
543
+ return /* @__PURE__ */ React.createElement(
544
+ FormControlLabel,
545
+ {
546
+ key: value,
547
+ control: /* @__PURE__ */ React.createElement(
548
+ Checkbox,
549
+ {
550
+ color: "primary",
551
+ tabIndex: -1,
552
+ inputProps: { "aria-labelledby": value },
553
+ value,
554
+ name: value,
555
+ onChange: handleChange,
556
+ checked: ((_a = filters[name]) != null ? _a : []).includes(value)
557
+ }
558
+ ),
559
+ label: value
560
+ }
561
+ );
562
+ })
563
+ );
545
564
  };
546
565
  const SelectFilter = (props) => {
547
566
  const {
@@ -572,44 +591,35 @@ const SelectFilter = (props) => {
572
591
  return value ? { ...others, [name]: value } : others;
573
592
  });
574
593
  };
575
- return /* @__PURE__ */ React.createElement(FormControl, {
576
- disabled: loading,
577
- className,
578
- variant: "filled",
579
- fullWidth: true,
580
- "data-testid": "search-selectfilter-next"
581
- }, label ? /* @__PURE__ */ React.createElement(InputLabel, {
582
- className: classes.label,
583
- margin: "dense"
584
- }, label) : null, /* @__PURE__ */ React.createElement(Select, {
585
- variant: "outlined",
586
- value: filters[name] || "",
587
- onChange: handleChange
588
- }, /* @__PURE__ */ React.createElement(MenuItem, {
589
- value: ""
590
- }, /* @__PURE__ */ React.createElement("em", null, "All")), values.map((value) => /* @__PURE__ */ React.createElement(MenuItem, {
591
- key: value,
592
- value
593
- }, value))));
594
+ return /* @__PURE__ */ React.createElement(
595
+ FormControl,
596
+ {
597
+ disabled: loading,
598
+ className,
599
+ variant: "filled",
600
+ fullWidth: true,
601
+ "data-testid": "search-selectfilter-next"
602
+ },
603
+ label ? /* @__PURE__ */ React.createElement(InputLabel, { className: classes.label, margin: "dense" }, label) : null,
604
+ /* @__PURE__ */ React.createElement(
605
+ Select,
606
+ {
607
+ variant: "outlined",
608
+ value: filters[name] || "",
609
+ onChange: handleChange
610
+ },
611
+ /* @__PURE__ */ React.createElement(MenuItem, { value: "" }, /* @__PURE__ */ React.createElement("em", null, "All")),
612
+ values.map((value) => /* @__PURE__ */ React.createElement(MenuItem, { key: value, value }, value))
613
+ )
614
+ );
594
615
  };
595
616
  const SearchFilter = ({
596
617
  component: Element,
597
618
  ...props
598
- }) => /* @__PURE__ */ React.createElement(Element, {
599
- ...props
600
- });
601
- SearchFilter.Checkbox = (props) => /* @__PURE__ */ React.createElement(SearchFilter, {
602
- ...props,
603
- component: CheckboxFilter
604
- });
605
- SearchFilter.Select = (props) => /* @__PURE__ */ React.createElement(SearchFilter, {
606
- ...props,
607
- component: SelectFilter
608
- });
609
- SearchFilter.Autocomplete = (props) => /* @__PURE__ */ React.createElement(SearchFilter, {
610
- ...props,
611
- component: AutocompleteFilter
612
- });
619
+ }) => /* @__PURE__ */ React.createElement(Element, { ...props });
620
+ SearchFilter.Checkbox = (props) => /* @__PURE__ */ React.createElement(SearchFilter, { ...props, component: CheckboxFilter });
621
+ SearchFilter.Select = (props) => /* @__PURE__ */ React.createElement(SearchFilter, { ...props, component: SelectFilter });
622
+ SearchFilter.Autocomplete = (props) => /* @__PURE__ */ React.createElement(SearchFilter, { ...props, component: AutocompleteFilter });
613
623
 
614
624
  const SearchResultContext = (props) => {
615
625
  const { children } = props;
@@ -628,41 +638,39 @@ const SearchResultApi = (props) => {
628
638
  };
629
639
  const SearchResultState = (props) => {
630
640
  const { query, children } = props;
631
- return query ? /* @__PURE__ */ React.createElement(SearchResultApi, {
632
- query
633
- }, children) : /* @__PURE__ */ React.createElement(SearchResultContext, null, children);
641
+ return query ? /* @__PURE__ */ React.createElement(SearchResultApi, { query }, children) : /* @__PURE__ */ React.createElement(SearchResultContext, null, children);
634
642
  };
635
643
  const SearchResultComponent = (props) => {
636
644
  const { query, children } = props;
637
- return /* @__PURE__ */ React.createElement(SearchResultState, {
638
- query
639
- }, ({ loading, error, value }) => {
645
+ return /* @__PURE__ */ React.createElement(SearchResultState, { query }, ({ loading, error, value }) => {
640
646
  if (loading) {
641
647
  return /* @__PURE__ */ React.createElement(Progress, null);
642
648
  }
643
649
  if (error) {
644
- return /* @__PURE__ */ React.createElement(ResponseErrorPanel, {
645
- title: "Error encountered while fetching search results",
646
- error
647
- });
650
+ return /* @__PURE__ */ React.createElement(
651
+ ResponseErrorPanel,
652
+ {
653
+ title: "Error encountered while fetching search results",
654
+ error
655
+ }
656
+ );
648
657
  }
649
658
  if (!(value == null ? void 0 : value.results.length)) {
650
- return /* @__PURE__ */ React.createElement(EmptyState, {
651
- missing: "data",
652
- title: "Sorry, no results were found"
653
- });
659
+ return /* @__PURE__ */ React.createElement(EmptyState, { missing: "data", title: "Sorry, no results were found" });
654
660
  }
655
661
  return children(value);
656
662
  });
657
663
  };
658
- const SearchResult = (props) => /* @__PURE__ */ React.createElement(AnalyticsContext, {
659
- attributes: {
660
- pluginId: "search",
661
- extension: "SearchResult"
662
- }
663
- }, /* @__PURE__ */ React.createElement(SearchResultComponent, {
664
- ...props
665
- }));
664
+ const SearchResult = (props) => /* @__PURE__ */ React.createElement(
665
+ AnalyticsContext,
666
+ {
667
+ attributes: {
668
+ pluginId: "search",
669
+ extension: "SearchResult"
670
+ }
671
+ },
672
+ /* @__PURE__ */ React.createElement(SearchResultComponent, { ...props })
673
+ );
666
674
 
667
675
  const useStyles$1 = makeStyles((theme) => ({
668
676
  root: {
@@ -678,20 +686,25 @@ const SearchResultPager = () => {
678
686
  if (!fetchNextPage && !fetchPreviousPage) {
679
687
  return /* @__PURE__ */ React.createElement(React.Fragment, null);
680
688
  }
681
- return /* @__PURE__ */ React.createElement("nav", {
682
- "aria-label": "pagination navigation",
683
- className: classes.root
684
- }, /* @__PURE__ */ React.createElement(Button, {
685
- "aria-label": "previous page",
686
- disabled: !fetchPreviousPage,
687
- onClick: fetchPreviousPage,
688
- startIcon: /* @__PURE__ */ React.createElement(ArrowBackIosIcon, null)
689
- }, "Previous"), /* @__PURE__ */ React.createElement(Button, {
690
- "aria-label": "next page",
691
- disabled: !fetchNextPage,
692
- onClick: fetchNextPage,
693
- endIcon: /* @__PURE__ */ React.createElement(ArrowForwardIosIcon, null)
694
- }, "Next"));
689
+ return /* @__PURE__ */ React.createElement("nav", { "aria-label": "pagination navigation", className: classes.root }, /* @__PURE__ */ React.createElement(
690
+ Button,
691
+ {
692
+ "aria-label": "previous page",
693
+ disabled: !fetchPreviousPage,
694
+ onClick: fetchPreviousPage,
695
+ startIcon: /* @__PURE__ */ React.createElement(ArrowBackIosIcon, null)
696
+ },
697
+ "Previous"
698
+ ), /* @__PURE__ */ React.createElement(
699
+ Button,
700
+ {
701
+ "aria-label": "next page",
702
+ disabled: !fetchNextPage,
703
+ onClick: fetchNextPage,
704
+ endIcon: /* @__PURE__ */ React.createElement(ArrowForwardIosIcon, null)
705
+ },
706
+ "Next"
707
+ ));
695
708
  };
696
709
 
697
710
  const encodePageCursor = (pageCursor) => {
@@ -728,28 +741,34 @@ const SearchPaginationBase = (props) => {
728
741
  },
729
742
  [onPageLimitChange]
730
743
  );
731
- return /* @__PURE__ */ React.createElement(TablePagination, {
732
- ...rest,
733
- component: "div",
734
- count,
735
- page,
736
- onPageChange: handlePageChange,
737
- rowsPerPage,
738
- labelRowsPerPage,
739
- labelDisplayedRows,
740
- rowsPerPageOptions,
741
- onRowsPerPageChange: handleRowsPerPageChange
742
- });
744
+ return /* @__PURE__ */ React.createElement(
745
+ TablePagination,
746
+ {
747
+ ...rest,
748
+ component: "div",
749
+ count,
750
+ page,
751
+ onPageChange: handlePageChange,
752
+ rowsPerPage,
753
+ labelRowsPerPage,
754
+ labelDisplayedRows,
755
+ rowsPerPageOptions,
756
+ onRowsPerPageChange: handleRowsPerPageChange
757
+ }
758
+ );
743
759
  };
744
760
  const SearchPagination = (props) => {
745
761
  const { pageLimit, setPageLimit, pageCursor, setPageCursor } = useSearch();
746
- return /* @__PURE__ */ React.createElement(SearchPaginationBase, {
747
- ...props,
748
- limit: pageLimit,
749
- onLimitChange: setPageLimit,
750
- cursor: pageCursor,
751
- onCursorChange: setPageCursor
752
- });
762
+ return /* @__PURE__ */ React.createElement(
763
+ SearchPaginationBase,
764
+ {
765
+ ...props,
766
+ limit: pageLimit,
767
+ onLimitChange: setPageLimit,
768
+ cursor: pageCursor,
769
+ onCursorChange: setPageCursor
770
+ }
771
+ );
753
772
  };
754
773
 
755
774
  const DefaultResultListItemComponent = ({
@@ -767,44 +786,51 @@ const DefaultResultListItemComponent = ({
767
786
  value: rank
768
787
  });
769
788
  };
770
- return /* @__PURE__ */ React.createElement(Link, {
771
- noTrack: true,
772
- to: result.location,
773
- onClick: handleClick
774
- }, /* @__PURE__ */ React.createElement(ListItem, {
775
- alignItems: "center"
776
- }, icon && /* @__PURE__ */ React.createElement(ListItemIcon, null, icon), /* @__PURE__ */ React.createElement(ListItemText, {
777
- primaryTypographyProps: { variant: "h6" },
778
- primary: (highlight == null ? void 0 : highlight.fields.title) ? /* @__PURE__ */ React.createElement(HighlightedSearchResultText, {
779
- text: highlight.fields.title,
780
- preTag: highlight.preTag,
781
- postTag: highlight.postTag
782
- }) : result.title,
783
- secondary: /* @__PURE__ */ React.createElement("span", {
784
- style: {
785
- display: "-webkit-box",
786
- WebkitBoxOrient: "vertical",
787
- WebkitLineClamp: lineClamp,
788
- overflow: "hidden"
789
- }
790
- }, (highlight == null ? void 0 : highlight.fields.text) ? /* @__PURE__ */ React.createElement(HighlightedSearchResultText, {
791
- text: highlight.fields.text,
792
- preTag: highlight.preTag,
793
- postTag: highlight.postTag
794
- }) : result.text)
795
- }), secondaryAction && /* @__PURE__ */ React.createElement(Box, {
796
- alignItems: "flex-end"
797
- }, secondaryAction)), /* @__PURE__ */ React.createElement(Divider, null));
789
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ListItem, { alignItems: "center" }, icon && /* @__PURE__ */ React.createElement(ListItemIcon, null, icon), /* @__PURE__ */ React.createElement(
790
+ ListItemText,
791
+ {
792
+ primaryTypographyProps: { variant: "h6" },
793
+ primary: /* @__PURE__ */ React.createElement(Link, { noTrack: true, to: result.location, onClick: handleClick }, (highlight == null ? void 0 : highlight.fields.title) ? /* @__PURE__ */ React.createElement(
794
+ HighlightedSearchResultText,
795
+ {
796
+ text: (highlight == null ? void 0 : highlight.fields.title) || "",
797
+ preTag: (highlight == null ? void 0 : highlight.preTag) || "",
798
+ postTag: (highlight == null ? void 0 : highlight.postTag) || ""
799
+ }
800
+ ) : result.title),
801
+ secondary: /* @__PURE__ */ React.createElement(
802
+ "span",
803
+ {
804
+ style: {
805
+ display: "-webkit-box",
806
+ WebkitBoxOrient: "vertical",
807
+ WebkitLineClamp: lineClamp,
808
+ overflow: "hidden"
809
+ }
810
+ },
811
+ (highlight == null ? void 0 : highlight.fields.text) ? /* @__PURE__ */ React.createElement(
812
+ HighlightedSearchResultText,
813
+ {
814
+ text: highlight.fields.text,
815
+ preTag: highlight.preTag,
816
+ postTag: highlight.postTag
817
+ }
818
+ ) : result.text
819
+ )
820
+ }
821
+ ), secondaryAction && /* @__PURE__ */ React.createElement(Box, { alignItems: "flex-end" }, secondaryAction)), /* @__PURE__ */ React.createElement(Divider, null));
798
822
  };
799
823
  const HigherOrderDefaultResultListItem = (props) => {
800
- return /* @__PURE__ */ React.createElement(AnalyticsContext, {
801
- attributes: {
802
- pluginId: "search",
803
- extension: "DefaultResultListItem"
804
- }
805
- }, /* @__PURE__ */ React.createElement(DefaultResultListItemComponent, {
806
- ...props
807
- }));
824
+ return /* @__PURE__ */ React.createElement(
825
+ AnalyticsContext,
826
+ {
827
+ attributes: {
828
+ pluginId: "search",
829
+ extension: "DefaultResultListItem"
830
+ }
831
+ },
832
+ /* @__PURE__ */ React.createElement(DefaultResultListItemComponent, { ...props })
833
+ );
808
834
  };
809
835
 
810
836
  const SearchResultListLayout = (props) => {
@@ -812,44 +838,50 @@ const SearchResultListLayout = (props) => {
812
838
  loading,
813
839
  error,
814
840
  resultItems,
815
- renderResultItem = (resultItem) => /* @__PURE__ */ React.createElement(HigherOrderDefaultResultListItem, {
816
- key: resultItem.document.location,
817
- result: resultItem.document
818
- }),
819
- noResultsComponent = /* @__PURE__ */ React.createElement(EmptyState, {
820
- missing: "data",
821
- title: "Sorry, no results were found"
822
- }),
841
+ renderResultItem = (resultItem) => /* @__PURE__ */ React.createElement(
842
+ HigherOrderDefaultResultListItem,
843
+ {
844
+ key: resultItem.document.location,
845
+ result: resultItem.document
846
+ }
847
+ ),
848
+ noResultsComponent = /* @__PURE__ */ React.createElement(EmptyState, { missing: "data", title: "Sorry, no results were found" }),
823
849
  ...rest
824
850
  } = props;
825
- return /* @__PURE__ */ React.createElement(List, {
826
- ...rest
827
- }, loading ? /* @__PURE__ */ React.createElement(Progress, null) : null, !loading && error ? /* @__PURE__ */ React.createElement(ResponseErrorPanel, {
828
- title: "Error encountered while fetching search results",
829
- error
830
- }) : null, !loading && !error && (resultItems == null ? void 0 : resultItems.length) ? resultItems.map(renderResultItem) : null, !loading && !error && !(resultItems == null ? void 0 : resultItems.length) ? /* @__PURE__ */ React.createElement(ListItem, null, noResultsComponent) : null);
851
+ return /* @__PURE__ */ React.createElement(List, { ...rest }, loading ? /* @__PURE__ */ React.createElement(Progress, null) : null, !loading && error ? /* @__PURE__ */ React.createElement(
852
+ ResponseErrorPanel,
853
+ {
854
+ title: "Error encountered while fetching search results",
855
+ error
856
+ }
857
+ ) : null, !loading && !error && (resultItems == null ? void 0 : resultItems.length) ? resultItems.map(renderResultItem) : null, !loading && !error && !(resultItems == null ? void 0 : resultItems.length) ? /* @__PURE__ */ React.createElement(ListItem, null, noResultsComponent) : null);
831
858
  };
832
859
  const SearchResultList = (props) => {
833
860
  const { query, disableRenderingWithNoResults, ...rest } = props;
834
- return /* @__PURE__ */ React.createElement(AnalyticsContext, {
835
- attributes: {
836
- pluginId: "search",
837
- extension: "SearchResultList"
838
- }
839
- }, /* @__PURE__ */ React.createElement(SearchResultState, {
840
- query
841
- }, ({ loading, error, value }) => {
842
- var _a;
843
- if (!((_a = value == null ? void 0 : value.results) == null ? void 0 : _a.length) && disableRenderingWithNoResults) {
844
- return null;
845
- }
846
- return /* @__PURE__ */ React.createElement(SearchResultListLayout, {
847
- ...rest,
848
- loading,
849
- error,
850
- resultItems: value == null ? void 0 : value.results
851
- });
852
- }));
861
+ return /* @__PURE__ */ React.createElement(
862
+ AnalyticsContext,
863
+ {
864
+ attributes: {
865
+ pluginId: "search",
866
+ extension: "SearchResultList"
867
+ }
868
+ },
869
+ /* @__PURE__ */ React.createElement(SearchResultState, { query }, ({ loading, error, value }) => {
870
+ var _a;
871
+ if (!((_a = value == null ? void 0 : value.results) == null ? void 0 : _a.length) && disableRenderingWithNoResults) {
872
+ return null;
873
+ }
874
+ return /* @__PURE__ */ React.createElement(
875
+ SearchResultListLayout,
876
+ {
877
+ ...rest,
878
+ loading,
879
+ error,
880
+ resultItems: value == null ? void 0 : value.results
881
+ }
882
+ );
883
+ })
884
+ );
853
885
  };
854
886
 
855
887
  const useStyles = makeStyles((theme) => ({
@@ -883,12 +915,15 @@ const useStyles = makeStyles((theme) => ({
883
915
  const SearchResultGroupFilterFieldLayout = (props) => {
884
916
  const classes = useStyles();
885
917
  const { label, children, ...rest } = props;
886
- return /* @__PURE__ */ React.createElement(Chip, {
887
- ...rest,
888
- className: classes.listSubheaderFilter,
889
- variant: "outlined",
890
- label: /* @__PURE__ */ React.createElement(React.Fragment, null, label, ": ", children)
891
- });
918
+ return /* @__PURE__ */ React.createElement(
919
+ Chip,
920
+ {
921
+ ...rest,
922
+ className: classes.listSubheaderFilter,
923
+ variant: "outlined",
924
+ label: /* @__PURE__ */ React.createElement(React.Fragment, null, label, ": ", children)
925
+ }
926
+ );
892
927
  };
893
928
  const NullIcon = () => null;
894
929
  const useSearchResultGroupTextFilterStyles = makeStyles((theme) => ({
@@ -916,17 +951,18 @@ const SearchResultGroupTextFilterField = (props) => {
916
951
  },
917
952
  [onChange]
918
953
  );
919
- return /* @__PURE__ */ React.createElement(SearchResultGroupFilterFieldLayout, {
920
- label,
921
- onDelete
922
- }, /* @__PURE__ */ React.createElement(Typography, {
923
- role: "textbox",
924
- component: "span",
925
- className: classes.root,
926
- onChange: handleChange,
927
- contentEditable: true,
928
- suppressContentEditableWarning: true
929
- }, value));
954
+ return /* @__PURE__ */ React.createElement(SearchResultGroupFilterFieldLayout, { label, onDelete }, /* @__PURE__ */ React.createElement(
955
+ Typography,
956
+ {
957
+ role: "textbox",
958
+ component: "span",
959
+ className: classes.root,
960
+ onChange: handleChange,
961
+ contentEditable: true,
962
+ suppressContentEditableWarning: true
963
+ },
964
+ value
965
+ ));
930
966
  };
931
967
  const useSearchResultGroupSelectFilterStyles = makeStyles((theme) => ({
932
968
  root: {
@@ -955,18 +991,18 @@ const SearchResultGroupSelectFilterField = (props) => {
955
991
  },
956
992
  [onChange]
957
993
  );
958
- return /* @__PURE__ */ React.createElement(SearchResultGroupFilterFieldLayout, {
959
- label,
960
- onDelete
961
- }, /* @__PURE__ */ React.createElement(Select, {
962
- className: classes.root,
963
- value,
964
- onChange: handleChange,
965
- input: /* @__PURE__ */ React.createElement(InputBase, null),
966
- IconComponent: NullIcon
967
- }, /* @__PURE__ */ React.createElement(MenuItem, {
968
- value: "none"
969
- }, "None"), children));
994
+ return /* @__PURE__ */ React.createElement(SearchResultGroupFilterFieldLayout, { label, onDelete }, /* @__PURE__ */ React.createElement(
995
+ Select,
996
+ {
997
+ className: classes.root,
998
+ value,
999
+ onChange: handleChange,
1000
+ input: /* @__PURE__ */ React.createElement(InputBase, null),
1001
+ IconComponent: NullIcon
1002
+ },
1003
+ /* @__PURE__ */ React.createElement(MenuItem, { value: "none" }, "None"),
1004
+ children
1005
+ ));
970
1006
  };
971
1007
  function SearchResultGroupLayout(props) {
972
1008
  const classes = useStyles();
@@ -977,26 +1013,21 @@ function SearchResultGroupLayout(props) {
977
1013
  icon,
978
1014
  title,
979
1015
  titleProps = {},
980
- link = /* @__PURE__ */ React.createElement(React.Fragment, null, "See all", /* @__PURE__ */ React.createElement(ArrowForwardIosIcon, {
981
- className: classes.listSubheaderLinkIcon
982
- })),
1016
+ link = /* @__PURE__ */ React.createElement(React.Fragment, null, "See all", /* @__PURE__ */ React.createElement(ArrowForwardIosIcon, { className: classes.listSubheaderLinkIcon })),
983
1017
  linkProps = {},
984
1018
  filterOptions,
985
- renderFilterOption = (filterOption) => /* @__PURE__ */ React.createElement(MenuItem, {
986
- key: String(filterOption),
987
- value: String(filterOption)
988
- }, filterOption),
1019
+ renderFilterOption = (filterOption) => /* @__PURE__ */ React.createElement(MenuItem, { key: String(filterOption), value: String(filterOption) }, filterOption),
989
1020
  filterFields,
990
1021
  renderFilterField,
991
1022
  resultItems,
992
- renderResultItem = (resultItem) => /* @__PURE__ */ React.createElement(HigherOrderDefaultResultListItem, {
993
- key: resultItem.document.location,
994
- result: resultItem.document
995
- }),
996
- noResultsComponent = /* @__PURE__ */ React.createElement(EmptyState, {
997
- missing: "data",
998
- title: "Sorry, no results were found"
999
- }),
1023
+ renderResultItem = (resultItem) => /* @__PURE__ */ React.createElement(
1024
+ HigherOrderDefaultResultListItem,
1025
+ {
1026
+ key: resultItem.document.location,
1027
+ result: resultItem.document
1028
+ }
1029
+ ),
1030
+ noResultsComponent = /* @__PURE__ */ React.createElement(EmptyState, { missing: "data", title: "Sorry, no results were found" }),
1000
1031
  ...rest
1001
1032
  } = props;
1002
1033
  const handleClick = useCallback((e) => {
@@ -1005,43 +1036,49 @@ function SearchResultGroupLayout(props) {
1005
1036
  const handleClose = useCallback(() => {
1006
1037
  setAnchorEl(null);
1007
1038
  }, []);
1008
- return /* @__PURE__ */ React.createElement(List, {
1009
- ...rest
1010
- }, /* @__PURE__ */ React.createElement(ListSubheader, {
1011
- className: classes.listSubheader
1012
- }, icon, /* @__PURE__ */ React.createElement(Typography, {
1013
- className: classes.listSubheaderName,
1014
- component: "strong",
1015
- ...titleProps
1016
- }, title), filterOptions ? /* @__PURE__ */ React.createElement(Chip, {
1017
- className: classes.listSubheaderChip,
1018
- component: "button",
1019
- icon: /* @__PURE__ */ React.createElement(AddIcon, null),
1020
- variant: "outlined",
1021
- label: "Add filter",
1022
- "aria-controls": "filters-menu",
1023
- "aria-haspopup": "true",
1024
- onClick: handleClick
1025
- }) : null, filterOptions ? /* @__PURE__ */ React.createElement(Menu, {
1026
- id: "filters-menu",
1027
- anchorEl,
1028
- open: Boolean(anchorEl),
1029
- onClose: handleClose,
1030
- onClick: handleClose,
1031
- keepMounted: true
1032
- }, filterOptions.map(renderFilterOption)) : null, filterFields == null ? void 0 : filterFields.map(
1039
+ return /* @__PURE__ */ React.createElement(List, { ...rest }, /* @__PURE__ */ React.createElement(ListSubheader, { className: classes.listSubheader }, icon, /* @__PURE__ */ React.createElement(
1040
+ Typography,
1041
+ {
1042
+ className: classes.listSubheaderName,
1043
+ component: "strong",
1044
+ ...titleProps
1045
+ },
1046
+ title
1047
+ ), filterOptions ? /* @__PURE__ */ React.createElement(
1048
+ Chip,
1049
+ {
1050
+ className: classes.listSubheaderChip,
1051
+ component: "button",
1052
+ icon: /* @__PURE__ */ React.createElement(AddIcon, null),
1053
+ variant: "outlined",
1054
+ label: "Add filter",
1055
+ "aria-controls": "filters-menu",
1056
+ "aria-haspopup": "true",
1057
+ onClick: handleClick
1058
+ }
1059
+ ) : null, filterOptions ? /* @__PURE__ */ React.createElement(
1060
+ Menu,
1061
+ {
1062
+ id: "filters-menu",
1063
+ anchorEl,
1064
+ open: Boolean(anchorEl),
1065
+ onClose: handleClose,
1066
+ onClick: handleClose,
1067
+ keepMounted: true
1068
+ },
1069
+ filterOptions.map(renderFilterOption)
1070
+ ) : null, filterFields == null ? void 0 : filterFields.map(
1033
1071
  (filterField) => {
1034
1072
  var _a;
1035
1073
  return (_a = renderFilterField == null ? void 0 : renderFilterField(filterField)) != null ? _a : null;
1036
1074
  }
1037
- ), /* @__PURE__ */ React.createElement(Link, {
1038
- className: classes.listSubheaderLink,
1039
- to: "/search",
1040
- ...linkProps
1041
- }, link)), loading ? /* @__PURE__ */ React.createElement(Progress, null) : null, !loading && error ? /* @__PURE__ */ React.createElement(ResponseErrorPanel, {
1042
- title: "Error encountered while fetching search results",
1043
- error
1044
- }) : null, !loading && !error && (resultItems == null ? void 0 : resultItems.length) ? resultItems.map(renderResultItem) : null, !loading && !error && !(resultItems == null ? void 0 : resultItems.length) ? /* @__PURE__ */ React.createElement(ListItem, null, noResultsComponent) : null);
1075
+ ), /* @__PURE__ */ React.createElement(Link, { className: classes.listSubheaderLink, to: "/search", ...linkProps }, link)), loading ? /* @__PURE__ */ React.createElement(Progress, null) : null, !loading && error ? /* @__PURE__ */ React.createElement(
1076
+ ResponseErrorPanel,
1077
+ {
1078
+ title: "Error encountered while fetching search results",
1079
+ error
1080
+ }
1081
+ ) : null, !loading && !error && (resultItems == null ? void 0 : resultItems.length) ? resultItems.map(renderResultItem) : null, !loading && !error && !(resultItems == null ? void 0 : resultItems.length) ? /* @__PURE__ */ React.createElement(ListItem, null, noResultsComponent) : null);
1045
1082
  }
1046
1083
  function SearchResultGroup(props) {
1047
1084
  const {
@@ -1059,27 +1096,32 @@ function SearchResultGroup(props) {
1059
1096
  },
1060
1097
  { arrayFormat: "brackets" }
1061
1098
  )}`;
1062
- return /* @__PURE__ */ React.createElement(AnalyticsContext, {
1063
- attributes: {
1064
- pluginId: "search",
1065
- extension: "SearchResultGroup"
1066
- }
1067
- }, /* @__PURE__ */ React.createElement(SearchResultState, {
1068
- query
1069
- }, ({ loading, error, value }) => {
1070
- var _a, _b;
1071
- if (!((_a = value == null ? void 0 : value.results) == null ? void 0 : _a.length) && disableRenderingWithNoResults) {
1072
- return null;
1073
- }
1074
- return /* @__PURE__ */ React.createElement(SearchResultGroupLayout, {
1075
- ...rest,
1076
- loading,
1077
- error,
1078
- linkProps: { to, ...linkProps },
1079
- resultItems: value == null ? void 0 : value.results,
1080
- filterFields: Object.keys((_b = query.filters) != null ? _b : {})
1081
- });
1082
- }));
1099
+ return /* @__PURE__ */ React.createElement(
1100
+ AnalyticsContext,
1101
+ {
1102
+ attributes: {
1103
+ pluginId: "search",
1104
+ extension: "SearchResultGroup"
1105
+ }
1106
+ },
1107
+ /* @__PURE__ */ React.createElement(SearchResultState, { query }, ({ loading, error, value }) => {
1108
+ var _a, _b;
1109
+ if (!((_a = value == null ? void 0 : value.results) == null ? void 0 : _a.length) && disableRenderingWithNoResults) {
1110
+ return null;
1111
+ }
1112
+ return /* @__PURE__ */ React.createElement(
1113
+ SearchResultGroupLayout,
1114
+ {
1115
+ ...rest,
1116
+ loading,
1117
+ error,
1118
+ linkProps: { to, ...linkProps },
1119
+ resultItems: value == null ? void 0 : value.results,
1120
+ filterFields: Object.keys((_b = query.filters) != null ? _b : {})
1121
+ }
1122
+ );
1123
+ })
1124
+ );
1083
1125
  }
1084
1126
 
1085
1127
  export { AutocompleteFilter, CheckboxFilter, HigherOrderDefaultResultListItem as DefaultResultListItem, HighlightedSearchResultText, MockSearchApi, SearchAutocomplete, SearchAutocompleteDefaultOption, SearchBar, SearchBarBase, SearchContextProvider, SearchFilter, SearchPagination, SearchPaginationBase, SearchResult, SearchResultApi, SearchResultComponent, SearchResultContext, SearchResultGroup, SearchResultGroupFilterFieldLayout, SearchResultGroupLayout, SearchResultGroupSelectFilterField, SearchResultGroupTextFilterField, SearchResultList, SearchResultListLayout, SearchResultPager, SearchResultState, SelectFilter, searchApiRef, useSearch, useSearchContextCheck };