@backstage/plugin-search-react 1.4.0 → 1.5.0-next.1

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 CHANGED
@@ -1,5 +1,38 @@
1
1
  # @backstage/plugin-search-react
2
2
 
3
+ ## 1.5.0-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 66e2aab4c4: `ListItem` wrapper component moved to `SearchResultListItemExtension` for all `*SearchResultListItems` that are exported as extensions. This is to make sure the list only contains list elements.
8
+
9
+ Note: If you have implemented a custom result list item, we recommend you to remove the list item wrapper to avoid nested `<li>` elements.
10
+
11
+ - Updated dependencies
12
+ - @backstage/core-components@0.12.4-next.1
13
+ - @backstage/core-plugin-api@1.3.0
14
+ - @backstage/theme@0.2.16
15
+ - @backstage/types@1.0.2
16
+ - @backstage/version-bridge@1.0.3
17
+ - @backstage/plugin-search-common@1.2.1
18
+
19
+ ## 1.5.0-next.0
20
+
21
+ ### Minor Changes
22
+
23
+ - 0eaa579f89: - Create the search results extensions, for more details see the documentation [here](https://backstage.io/docs/features/search/how-to-guides#how-to-render-search-results-using-extensions);
24
+ - Update the `SearchResult`, `SearchResultList` and `SearchResultGroup` components to use extensions and default their props to optionally accept a query, when the query is not passed, the component tries to get it from the search context.
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies
29
+ - @backstage/core-components@0.12.4-next.0
30
+ - @backstage/core-plugin-api@1.3.0
31
+ - @backstage/theme@0.2.16
32
+ - @backstage/types@1.0.2
33
+ - @backstage/version-bridge@1.0.3
34
+ - @backstage/plugin-search-common@1.2.1
35
+
3
36
  ## 1.4.0
4
37
 
5
38
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
3
- import { SearchQuery, SearchResultSet, SearchResult as SearchResult$1, SearchDocument, ResultHighlight } from '@backstage/plugin-search-common';
4
- import React, { ForwardRefExoticComponent, ReactNode, ReactElement, PropsWithChildren } from 'react';
5
- import { InputBaseProps, ListItemTextProps, ListProps, TypographyProps } from '@material-ui/core';
3
+ import { Extension } from '@backstage/core-plugin-api';
4
+ import { SearchQuery, SearchResultSet, SearchDocument, SearchResult as SearchResult$1, ResultHighlight } from '@backstage/plugin-search-common';
5
+ import React, { PropsWithChildren, ReactNode, ForwardRefExoticComponent, ReactElement } from 'react';
6
+ import { ListItemProps, ListProps, InputBaseProps, ListItemTextProps, TypographyProps } from '@material-ui/core';
6
7
  import { AutocompleteProps } from '@material-ui/lab';
7
8
  import { AsyncState } from 'react-use/lib/useAsync';
8
9
  import { JsonValue, JsonObject } from '@backstage/types';
@@ -29,6 +30,62 @@ declare class MockSearchApi implements SearchApi {
29
30
  query(): Promise<SearchResultSet>;
30
31
  }
31
32
 
33
+ /**
34
+ * @public
35
+ * Extends props for any search result list item extension
36
+ */
37
+ declare type SearchResultListItemExtensionProps<Props extends {} = {}> = Props & PropsWithChildren<{
38
+ rank?: number;
39
+ result?: SearchDocument;
40
+ noTrack?: boolean;
41
+ } & Omit<ListItemProps, 'button'>>;
42
+ /**
43
+ * @public
44
+ * Options for {@link createSearchResultListItemExtension}.
45
+ */
46
+ declare type SearchResultListItemExtensionOptions<Component extends (props: any) => JSX.Element | null> = {
47
+ /**
48
+ * The extension name.
49
+ */
50
+ name: string;
51
+ /**
52
+ * The extension component.
53
+ */
54
+ component: () => Promise<Component>;
55
+ /**
56
+ * When an extension defines a predicate, it returns true if the result should be rendered by that extension.
57
+ * Defaults to a predicate that returns true, which means it renders all sorts of results.
58
+ */
59
+ predicate?: (result: SearchResult$1) => boolean;
60
+ };
61
+ /**
62
+ * @public
63
+ * Creates a search result item extension.
64
+ * @param options - The extension options, see {@link SearchResultListItemExtensionOptions} for more details.
65
+ */
66
+ declare const createSearchResultListItemExtension: <Component extends (props: any) => JSX.Element | null>(options: SearchResultListItemExtensionOptions<Component>) => Extension<Component>;
67
+ /**
68
+ * @public
69
+ * Returns a function that renders a result using extensions.
70
+ */
71
+ declare const useSearchResultListItemExtensions: (children: ReactNode) => (result: SearchResult$1, key?: number) => JSX.Element;
72
+ /**
73
+ * @public
74
+ * Props for {@link SearchResultListItemExtensions}
75
+ */
76
+ declare type SearchResultListItemExtensionsProps = Omit<ListProps, 'results'> & {
77
+ /**
78
+ * Search result list.
79
+ */
80
+ results: SearchResult$1[];
81
+ };
82
+ /**
83
+ * @public
84
+ * Render results using search extensions.
85
+ * @param props - see {@link SearchResultListItemExtensionsProps}
86
+ */
87
+ declare const SearchResultListItemExtensions: (props: SearchResultListItemExtensionsProps) => JSX.Element;
88
+
32
89
  /**
33
90
  * Props for {@link HighlightedSearchResultText}.
34
91
  *
@@ -186,6 +243,92 @@ declare const SearchFilter: {
186
243
  Autocomplete(props: SearchAutocompleteFilterProps): JSX.Element;
187
244
  };
188
245
 
246
+ /**
247
+ * A page limit option, this value must not be greater than 100.
248
+ * @public
249
+ */
250
+ declare type SearchPaginationLimitOption<Current extends number = 101, Accumulator extends number[] = []> = Accumulator['length'] extends Current ? Accumulator[number] : SearchPaginationLimitOption<Current, [
251
+ ...Accumulator,
252
+ Accumulator['length']
253
+ ]>;
254
+ /**
255
+ * A page limit text, this function is called with a "\{ from, to, page, count \}" object.
256
+ * @public
257
+ */
258
+ declare type SearchPaginationLimitText = (params: {
259
+ from: number;
260
+ to: number;
261
+ page: number;
262
+ count: number;
263
+ }) => ReactNode;
264
+ /**
265
+ * Props for {@link SearchPaginationBase}.
266
+ * @public
267
+ */
268
+ declare type SearchPaginationBaseProps = {
269
+ /**
270
+ * The component class name.
271
+ */
272
+ className?: string;
273
+ /**
274
+ * The total number of results.
275
+ * For an unknown number of items, provide -1.
276
+ * Defaults to -1.
277
+ */
278
+ total?: number;
279
+ /**
280
+ * The cursor for the current page.
281
+ */
282
+ cursor?: string;
283
+ /**
284
+ * Callback fired when the current page cursor is changed.
285
+ */
286
+ onCursorChange?: (pageCursor: string) => void;
287
+ /**
288
+ * The limit of results per page.
289
+ * Set -1 to display all the results.
290
+ */
291
+ limit?: number;
292
+ /**
293
+ * Customize the results per page label.
294
+ * Defaults to "Results per page:".
295
+ */
296
+ limitLabel?: ReactNode;
297
+ /**
298
+ * Customize the results per page text.
299
+ * Defaults to "(\{ from, to, count \}) =\> count \> 0 ? `of $\{count\}` : `$\{from\}-$\{to\}`".
300
+ */
301
+ limitText?: SearchPaginationLimitText;
302
+ /**
303
+ * Options for setting how many results show per page.
304
+ * If less than two options are available, no select field will be displayed.
305
+ * Use -1 for the value with a custom label to show all the results.
306
+ * Defaults to [10, 25, 50, 100].
307
+ */
308
+ limitOptions?: SearchPaginationLimitOption[];
309
+ /**
310
+ * Callback fired when the number of results per page is changed.
311
+ */
312
+ onLimitChange?: (value: number) => void;
313
+ };
314
+ /**
315
+ * A component with controls for search results pagination.
316
+ * @param props - See {@link SearchPaginationBaseProps}.
317
+ * @public
318
+ */
319
+ declare const SearchPaginationBase: (props: SearchPaginationBaseProps) => JSX.Element;
320
+ /**
321
+ * Props for {@link SearchPagination}.
322
+ * @public
323
+ */
324
+ declare type SearchPaginationProps = Omit<SearchPaginationBaseProps, 'pageLimit' | 'onPageLimitChange' | 'pageCursor' | 'onPageCursorChange'>;
325
+ /**
326
+ * A component for setting the search context page limit and cursor.
327
+ * @param props - See {@link SearchPaginationProps}.
328
+ * @public
329
+ */
330
+ declare const SearchPagination: (props: SearchPaginationProps) => JSX.Element;
331
+
189
332
  /**
190
333
  * Props for {@link SearchResultContext}
191
334
  * @public
@@ -194,7 +337,7 @@ declare type SearchResultContextProps = {
194
337
  /**
195
338
  * A child function that receives an asynchronous result set and returns a react element.
196
339
  */
197
- children: (state: AsyncState<SearchResultSet>) => JSX.Element | null;
340
+ children: (state: AsyncState<SearchResultSet>, query: Partial<SearchQuery>) => JSX.Element | null;
198
341
  };
199
342
  /**
200
343
  * Provides context-based results to a child function.
@@ -293,8 +436,8 @@ declare const SearchResultState: (props: SearchResultStateProps) => JSX.Element;
293
436
  * Props for {@link SearchResult}
294
437
  * @public
295
438
  */
296
- declare type SearchResultProps = Pick<SearchResultStateProps, 'query'> & {
297
- children: (resultSet: SearchResultSet) => JSX.Element;
439
+ declare type SearchResultProps = Pick<SearchResultStateProps, 'query'> & Omit<SearchResultListItemExtensionsProps, 'results' | 'children'> & {
440
+ children?: ReactNode | ((resultSet: SearchResultSet) => JSX.Element);
298
441
  noResultsComponent?: JSX.Element;
299
442
  };
300
443
  /**
@@ -312,101 +455,18 @@ declare const SearchResultComponent: (props: SearchResultProps) => JSX.Element;
312
455
  declare const SearchResult: (props: SearchResultProps) => JSX.Element;
313
456
 
314
457
  /**
458
+ * Props for {@link SearchResultListLayout}
315
459
  * @public
316
460
  */
317
- declare const SearchResultPager: () => JSX.Element;
318
-
319
- /**
320
- * A page limit option, this value must not be greater than 100.
321
- * @public
322
- */
323
- declare type SearchPaginationLimitOption<Current extends number = 101, Accumulator extends number[] = []> = Accumulator['length'] extends Current ? Accumulator[number] : SearchPaginationLimitOption<Current, [
324
- ...Accumulator,
325
- Accumulator['length']
326
- ]>;
327
- /**
328
- * A page limit text, this function is called with a "\{ from, to, page, count \}" object.
329
- * @public
330
- */
331
- declare type SearchPaginationLimitText = (params: {
332
- from: number;
333
- to: number;
334
- page: number;
335
- count: number;
336
- }) => ReactNode;
337
- /**
338
- * Props for {@link SearchPaginationBase}.
339
- * @public
340
- */
341
- declare type SearchPaginationBaseProps = {
342
- /**
343
- * The component class name.
344
- */
345
- className?: string;
346
- /**
347
- * The total number of results.
348
- * For an unknown number of items, provide -1.
349
- * Defaults to -1.
350
- */
351
- total?: number;
352
- /**
353
- * The cursor for the current page.
354
- */
355
- cursor?: string;
356
- /**
357
- * Callback fired when the current page cursor is changed.
358
- */
359
- onCursorChange?: (pageCursor: string) => void;
360
- /**
361
- * The limit of results per page.
362
- * Set -1 to display all the results.
363
- */
364
- limit?: number;
365
- /**
366
- * Customize the results per page label.
367
- * Defaults to "Results per page:".
368
- */
369
- limitLabel?: ReactNode;
370
- /**
371
- * Customize the results per page text.
372
- * Defaults to "(\{ from, to, count \}) =\> count \> 0 ? `of $\{count\}` : `$\{from\}-$\{to\}`".
373
- */
374
- limitText?: SearchPaginationLimitText;
461
+ declare type SearchResultListLayoutProps = ListProps & {
375
462
  /**
376
- * Options for setting how many results show per page.
377
- * If less than two options are available, no select field will be displayed.
378
- * Use -1 for the value with a custom label to show all the results.
379
- * Defaults to [10, 25, 50, 100].
463
+ * If defined, will render a default error panel.
380
464
  */
381
- limitOptions?: SearchPaginationLimitOption[];
465
+ error?: Error;
382
466
  /**
383
- * Callback fired when the number of results per page is changed.
467
+ * If defined, will render a default loading progress.
384
468
  */
385
- onLimitChange?: (value: number) => void;
386
- };
387
- /**
388
- * A component with controls for search results pagination.
389
- * @param props - See {@link SearchPaginationBaseProps}.
390
- * @public
391
- */
392
- declare const SearchPaginationBase: (props: SearchPaginationBaseProps) => JSX.Element;
393
- /**
394
- * Props for {@link SearchPagination}.
395
- * @public
396
- */
397
- declare type SearchPaginationProps = Omit<SearchPaginationBaseProps, 'pageLimit' | 'onPageLimitChange' | 'pageCursor' | 'onPageCursorChange'>;
398
- /**
399
- * A component for setting the search context page limit and cursor.
400
- * @param props - See {@link SearchPaginationProps}.
401
- * @public
402
- */
403
- declare const SearchPagination: (props: SearchPaginationProps) => JSX.Element;
404
-
405
- /**
406
- * Props for {@link SearchResultListLayout}
407
- * @public
408
- */
409
- declare type SearchResultListLayoutProps = ListProps & {
469
+ loading?: boolean;
410
470
  /**
411
471
  * Search results to be rendered as a list.
412
472
  */
@@ -415,18 +475,14 @@ declare type SearchResultListLayoutProps = ListProps & {
415
475
  * Function to customize how result items are rendered.
416
476
  */
417
477
  renderResultItem?: (value: SearchResult$1, index: number, array: SearchResult$1[]) => JSX.Element | null;
418
- /**
419
- * If defined, will render a default error panel.
420
- */
421
- error?: Error;
422
- /**
423
- * If defined, will render a default loading progress.
424
- */
425
- loading?: boolean;
426
478
  /**
427
479
  * Optional component to render when no results. Default to <EmptyState /> component.
428
480
  */
429
481
  noResultsComponent?: ReactNode;
482
+ /**
483
+ * Optional property to provide if component should not render the component when no results are found.
484
+ */
485
+ disableRenderingWithNoResults?: boolean;
430
486
  };
431
487
  /**
432
488
  * Default layout for rendering search results in a list.
@@ -438,16 +494,7 @@ declare const SearchResultListLayout: (props: SearchResultListLayoutProps) => JS
438
494
  * Props for {@link SearchResultList}.
439
495
  * @public
440
496
  */
441
- declare type SearchResultListProps = Omit<SearchResultListLayoutProps, 'loading' | 'error' | 'resultItems'> & {
442
- /**
443
- * A search query used for requesting the results to be listed.
444
- */
445
- query: Partial<SearchQuery>;
446
- /**
447
- * Optional property to provide if component should not render the component when no results are found.
448
- */
449
- disableRenderingWithNoResults?: boolean;
450
- };
497
+ declare type SearchResultListProps = Pick<SearchResultStateProps, 'query'> & Omit<SearchResultListLayoutProps, 'loading' | 'error' | 'resultItems'>;
451
498
  /**
452
499
  * Given a query, search for results and render them as a list.
453
500
  * @param props - See {@link SearchResultListProps}.
@@ -529,6 +576,14 @@ declare const SearchResultGroupSelectFilterField: (props: SearchResultGroupSelec
529
576
  * @public
530
577
  */
531
578
  declare type SearchResultGroupLayoutProps<FilterOption> = ListProps & {
579
+ /**
580
+ * If defined, will render a default error panel.
581
+ */
582
+ error?: Error;
583
+ /**
584
+ * If defined, will render a default loading progress.
585
+ */
586
+ loading?: boolean;
532
587
  /**
533
588
  * Icon that representing a result group.
534
589
  */
@@ -574,18 +629,14 @@ declare type SearchResultGroupLayoutProps<FilterOption> = ListProps & {
574
629
  * Function to customize how result items are rendered.
575
630
  */
576
631
  renderResultItem?: (value: SearchResult$1, index: number, array: SearchResult$1[]) => JSX.Element | null;
577
- /**
578
- * If defined, will render a default error panel.
579
- */
580
- error?: Error;
581
- /**
582
- * If defined, will render a default loading progress.
583
- */
584
- loading?: boolean;
585
632
  /**
586
633
  * Optional component to render when no results. Default to <EmptyState /> component.
587
634
  */
588
635
  noResultsComponent?: ReactNode;
636
+ /**
637
+ * Optional property to provide if component should not render the component when no results are found.
638
+ */
639
+ disableRenderingWithNoResults?: boolean;
589
640
  };
590
641
  /**
591
642
  * Default layout for rendering search results in a group.
@@ -597,16 +648,7 @@ declare function SearchResultGroupLayout<FilterOption>(props: SearchResultGroupL
597
648
  * Props for {@link SearchResultGroup}.
598
649
  * @public
599
650
  */
600
- declare type SearchResultGroupProps<FilterOption> = Omit<SearchResultGroupLayoutProps<FilterOption>, 'loading' | 'error' | 'resultItems' | 'filterFields'> & {
601
- /**
602
- * A search query used for requesting the results to be grouped.
603
- */
604
- query: Partial<SearchQuery>;
605
- /**
606
- * Optional property to provide if component should not render the group when no results are found.
607
- */
608
- disableRenderingWithNoResults?: boolean;
609
- };
651
+ declare type SearchResultGroupProps<FilterOption> = Pick<SearchResultStateProps, 'query'> & Omit<SearchResultGroupLayoutProps<FilterOption>, 'loading' | 'error' | 'resultItems' | 'filterFields'>;
610
652
  /**
611
653
  * Given a query, search for results and render them as a group.
612
654
  * @param props - See {@link SearchResultGroupProps}.
@@ -614,6 +656,11 @@ declare type SearchResultGroupProps<FilterOption> = Omit<SearchResultGroupLayout
614
656
  */
615
657
  declare function SearchResultGroup<FilterOption>(props: SearchResultGroupProps<FilterOption>): JSX.Element;
616
658
 
659
+ /**
660
+ * @public
661
+ */
662
+ declare const SearchResultPager: () => JSX.Element;
663
+
617
664
  /**
618
665
  * Props for {@link DefaultResultListItem}
619
666
  *
@@ -622,10 +669,11 @@ declare function SearchResultGroup<FilterOption>(props: SearchResultGroupProps<F
622
669
  declare type DefaultResultListItemProps = {
623
670
  icon?: ReactNode;
624
671
  secondaryAction?: ReactNode;
625
- result: SearchDocument;
672
+ result?: SearchDocument;
626
673
  highlight?: ResultHighlight;
627
674
  rank?: number;
628
675
  lineClamp?: number;
676
+ toggleModal?: () => void;
629
677
  };
630
678
  /**
631
679
  * @public
@@ -700,4 +748,4 @@ declare type SearchContextProviderProps = PropsWithChildren<{
700
748
  */
701
749
  declare const SearchContextProvider: (props: SearchContextProviderProps) => JSX.Element;
702
750
 
703
- export { AutocompleteFilter, CheckboxFilter, HigherOrderDefaultResultListItem as DefaultResultListItem, DefaultResultListItemProps, HighlightedSearchResultText, HighlightedSearchResultTextProps, MockSearchApi, SearchApi, SearchAutocomplete, SearchAutocompleteComponent, SearchAutocompleteDefaultOption, SearchAutocompleteDefaultOptionProps, SearchAutocompleteFilterProps, SearchAutocompleteProps, SearchBar, SearchBarBase, SearchBarBaseProps, SearchBarProps, SearchContextProvider, SearchContextProviderProps, SearchContextState, SearchContextValue, SearchFilter, SearchFilterComponentProps, SearchFilterWrapperProps, SearchPagination, SearchPaginationBase, SearchPaginationBaseProps, SearchPaginationLimitOption, SearchPaginationLimitText, SearchPaginationProps, SearchResult, SearchResultApi, SearchResultApiProps, SearchResultComponent, SearchResultContext, SearchResultContextProps, SearchResultGroup, SearchResultGroupFilterFieldLayout, SearchResultGroupFilterFieldLayoutProps, SearchResultGroupFilterFieldPropsWith, SearchResultGroupLayout, SearchResultGroupLayoutProps, SearchResultGroupProps, SearchResultGroupSelectFilterField, SearchResultGroupSelectFilterFieldProps, SearchResultGroupTextFilterField, SearchResultGroupTextFilterFieldProps, SearchResultList, SearchResultListLayout, SearchResultListLayoutProps, SearchResultListProps, SearchResultPager, SearchResultProps, SearchResultState, SearchResultStateProps, SelectFilter, searchApiRef, useSearch, useSearchContextCheck };
751
+ export { AutocompleteFilter, CheckboxFilter, HigherOrderDefaultResultListItem as DefaultResultListItem, DefaultResultListItemProps, HighlightedSearchResultText, HighlightedSearchResultTextProps, MockSearchApi, SearchApi, SearchAutocomplete, SearchAutocompleteComponent, SearchAutocompleteDefaultOption, SearchAutocompleteDefaultOptionProps, SearchAutocompleteFilterProps, SearchAutocompleteProps, SearchBar, SearchBarBase, SearchBarBaseProps, SearchBarProps, SearchContextProvider, SearchContextProviderProps, SearchContextState, SearchContextValue, SearchFilter, SearchFilterComponentProps, SearchFilterWrapperProps, SearchPagination, SearchPaginationBase, SearchPaginationBaseProps, SearchPaginationLimitOption, SearchPaginationLimitText, SearchPaginationProps, SearchResult, SearchResultApi, SearchResultApiProps, SearchResultComponent, SearchResultContext, SearchResultContextProps, SearchResultGroup, SearchResultGroupFilterFieldLayout, SearchResultGroupFilterFieldLayoutProps, SearchResultGroupFilterFieldPropsWith, SearchResultGroupLayout, SearchResultGroupLayoutProps, SearchResultGroupProps, SearchResultGroupSelectFilterField, SearchResultGroupSelectFilterFieldProps, SearchResultGroupTextFilterField, SearchResultGroupTextFilterFieldProps, SearchResultList, SearchResultListItemExtensionOptions, SearchResultListItemExtensionProps, SearchResultListItemExtensions, SearchResultListItemExtensionsProps, SearchResultListLayout, SearchResultListLayoutProps, SearchResultListProps, SearchResultPager, SearchResultProps, SearchResultState, SearchResultStateProps, SelectFilter, createSearchResultListItemExtension, searchApiRef, useSearch, useSearchContextCheck, useSearchResultListItemExtensions };