feat: small refactor for the search package
Co-authored-by: Fredrik Adelöw <freben@users.noreply.github.com> Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
/// <reference types="react" />
|
||||
|
||||
import { ConfigurableExtensionDataRef } from '@backstage/frontend-plugin-api';
|
||||
import { ExtensionBlueprint } from '@backstage/frontend-plugin-api';
|
||||
import { ExtensionDefinition } from '@backstage/frontend-plugin-api';
|
||||
import { ListItemProps } from '@material-ui/core/ListItem';
|
||||
import { PortableSchema } from '@backstage/frontend-plugin-api';
|
||||
@@ -18,7 +19,7 @@ export type BaseSearchResultListItemProps<T = {}> = T & {
|
||||
result?: SearchDocument;
|
||||
} & Omit<ListItemProps, 'button'>;
|
||||
|
||||
// @alpha (undocumented)
|
||||
// @alpha @deprecated
|
||||
export function createSearchResultListItemExtension<
|
||||
TConfig extends {
|
||||
noTrack?: boolean;
|
||||
@@ -35,9 +36,9 @@ export function createSearchResultListItemExtension<
|
||||
string | undefined
|
||||
>;
|
||||
|
||||
// @alpha (undocumented)
|
||||
// @alpha @deprecated (undocumented)
|
||||
export namespace createSearchResultListItemExtension {
|
||||
const // (undocumented)
|
||||
const // @deprecated (undocumented)
|
||||
itemDataRef: ConfigurableExtensionDataRef<
|
||||
{
|
||||
predicate?: SearchResultItemExtensionPredicate | undefined;
|
||||
@@ -55,7 +56,7 @@ export type SearchResultItemExtensionComponent = <
|
||||
props: P,
|
||||
) => JSX.Element | null;
|
||||
|
||||
// @alpha (undocumented)
|
||||
// @alpha @deprecated (undocumented)
|
||||
export type SearchResultItemExtensionOptions<
|
||||
TConfig extends {
|
||||
noTrack?: boolean;
|
||||
@@ -79,5 +80,48 @@ export type SearchResultItemExtensionPredicate = (
|
||||
result: SearchResult,
|
||||
) => boolean;
|
||||
|
||||
// @alpha
|
||||
export const SearchResultListItemBlueprint: ExtensionBlueprint<
|
||||
'search-result-list-item',
|
||||
undefined,
|
||||
undefined,
|
||||
SearchResultListItemBlueprintParams,
|
||||
ConfigurableExtensionDataRef<
|
||||
{
|
||||
predicate?: SearchResultItemExtensionPredicate | undefined;
|
||||
component: SearchResultItemExtensionComponent;
|
||||
},
|
||||
'search.search-result-list-item.item',
|
||||
{}
|
||||
>,
|
||||
{},
|
||||
{
|
||||
noTrack: boolean;
|
||||
},
|
||||
{
|
||||
noTrack?: boolean | undefined;
|
||||
},
|
||||
{
|
||||
item: ConfigurableExtensionDataRef<
|
||||
{
|
||||
predicate?: SearchResultItemExtensionPredicate | undefined;
|
||||
component: SearchResultItemExtensionComponent;
|
||||
},
|
||||
'search.search-result-list-item.item',
|
||||
{}
|
||||
>;
|
||||
}
|
||||
>;
|
||||
|
||||
// @alpha (undocumented)
|
||||
export interface SearchResultListItemBlueprintParams {
|
||||
component: (options: {
|
||||
config: {
|
||||
noTrack?: boolean;
|
||||
};
|
||||
}) => Promise<SearchResultItemExtensionComponent>;
|
||||
predicate?: SearchResultItemExtensionPredicate;
|
||||
}
|
||||
|
||||
// (No @packageDocumentation comment for this package)
|
||||
```
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./alpha": "./src/alpha.tsx",
|
||||
"./alpha": "./src/alpha/index.ts",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"main": "src/index.ts",
|
||||
@@ -36,7 +36,7 @@
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"alpha": [
|
||||
"src/alpha.tsx"
|
||||
"src/alpha/index.ts"
|
||||
],
|
||||
"package.json": [
|
||||
"package.json"
|
||||
|
||||
+6
-1
@@ -27,8 +27,9 @@ import {
|
||||
import {
|
||||
SearchResultListItemExtension,
|
||||
SearchResultListItemExtensionProps,
|
||||
} from '../extensions';
|
||||
} from '../../extensions';
|
||||
|
||||
/** @alpha */
|
||||
export interface SearchResultListItemBlueprintParams {
|
||||
/**
|
||||
* The extension component.
|
||||
@@ -43,6 +44,10 @@ export interface SearchResultListItemBlueprintParams {
|
||||
predicate?: SearchResultItemExtensionPredicate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
* Creates SearchResultListItem extensions
|
||||
*/
|
||||
export const SearchResultListItemBlueprint = createExtensionBlueprint({
|
||||
kind: 'search-result-list-item',
|
||||
attachTo: {
|
||||
+2
-4
@@ -23,10 +23,8 @@ import { createExtensionTester } from '@backstage/frontend-test-utils';
|
||||
import { SearchResult } from '@backstage/plugin-search-common';
|
||||
import { screen } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import {
|
||||
BaseSearchResultListItemProps,
|
||||
createSearchResultListItemExtension,
|
||||
} from './alpha';
|
||||
import { createSearchResultListItemExtension } from './extensions';
|
||||
import { BaseSearchResultListItemProps } from './blueprints';
|
||||
|
||||
describe('createSearchResultListItemExtension', () => {
|
||||
it('Should use the correct result component', async () => {
|
||||
@@ -21,14 +21,12 @@ import {
|
||||
createExtension,
|
||||
createSchemaFromZod,
|
||||
} from '@backstage/frontend-plugin-api';
|
||||
import { SearchResultListItemExtension } from './extensions';
|
||||
import {
|
||||
SearchResultItemExtensionComponent,
|
||||
SearchResultItemExtensionPredicate,
|
||||
searchResultListItemDataRef,
|
||||
} from './blueprints/types';
|
||||
|
||||
export * from './blueprints';
|
||||
} from './blueprints';
|
||||
import { SearchResultListItemExtension } from '../extensions';
|
||||
import { searchResultListItemDataRef } from './blueprints/types';
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
@@ -128,5 +126,8 @@ export function createSearchResultListItemExtension<
|
||||
* @deprecated Use {@link SearchResultListItemBlueprint} instead
|
||||
*/
|
||||
export namespace createSearchResultListItemExtension {
|
||||
/**
|
||||
* @deprecated Use {@link SearchResultListItemBlueprint#dataRefs.item} instead
|
||||
*/
|
||||
export const itemDataRef = searchResultListItemDataRef;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export * from './extensions';
|
||||
export * from './blueprints';
|
||||
Reference in New Issue
Block a user