From d0501bb8c267fdbc871b0deeb197df6141a6794e Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 19 Aug 2024 15:13:38 +0200 Subject: [PATCH] search-react: removed deprecated extension creators Signed-off-by: Patrik Oldsberg --- .../src/alpha/extensions.test.tsx | 171 ------------------ plugins/search-react/src/alpha/extensions.tsx | 133 -------------- plugins/search-react/src/alpha/index.ts | 1 - 3 files changed, 305 deletions(-) delete mode 100644 plugins/search-react/src/alpha/extensions.test.tsx delete mode 100644 plugins/search-react/src/alpha/extensions.tsx diff --git a/plugins/search-react/src/alpha/extensions.test.tsx b/plugins/search-react/src/alpha/extensions.test.tsx deleted file mode 100644 index 5194fadd1c..0000000000 --- a/plugins/search-react/src/alpha/extensions.test.tsx +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright 2023 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. - */ - -import { - createExtensionInput, - createPageExtension, - createSchemaFromZod, -} from '@backstage/frontend-plugin-api'; -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 { createSearchResultListItemExtension } from './extensions'; -import { BaseSearchResultListItemProps } from './blueprints'; - -describe('createSearchResultListItemExtension', () => { - it('Should use the correct result component', async () => { - type TechDocsSearchResultListItemProps = BaseSearchResultListItemProps<{ - lineClamp: number; - }>; - const TechDocsSearchResultItemComponent = ( - props: TechDocsSearchResultListItemProps, - ) => ( -
- TechDocs - Rank: {props.rank} - Line clamp: {props.lineClamp} -
- ); - - const TechDocsSearchResultItemExtension = - createSearchResultListItemExtension({ - namespace: 'techdocs', - configSchema: createSchemaFromZod(z => - z - .object({ - noTrack: z.boolean().default(true), - lineClamp: z.number().default(5), - }) - .default({}), - ), - predicate: result => result.type === 'techdocs', - component: - async ({ config }) => - props => - , - }); - - const ExploreSearchResultItemComponent = ( - props: BaseSearchResultListItemProps, - ) =>
Explore - Rank: {props.rank}
; - - const ExploreSearchResultItemExtension = - createSearchResultListItemExtension({ - namespace: 'explore', - predicate: result => result.type === 'explore', - component: async () => ExploreSearchResultItemComponent, - }); - - const SearchPageExtension = createPageExtension({ - namespace: 'search', - defaultPath: '/', - inputs: { - items: createExtensionInput({ - item: createSearchResultListItemExtension.itemDataRef, - }), - }, - loader: async ({ inputs }) => { - const results = [ - { - type: 'techdocs', - rank: 1, - document: { - title: 'Title1', - text: 'Text1', - location: '/location1', - }, - }, - { - type: 'explore', - rank: 2, - document: { - title: 'Title2', - text: 'Text2', - location: '/location2', - }, - }, - { - type: 'other', - rank: 3, - document: { - title: 'Title3', - text: 'Text3', - location: '/location3', - }, - }, - ]; - - const DefaultResultItem = (props: BaseSearchResultListItemProps) => ( -
Default - Rank: {props.rank}
- ); - - const getResultItemComponent = (result: SearchResult) => { - const value = inputs.items.find(item => - item?.output.item.predicate?.(result), - ); - return value?.output.item.component ?? DefaultResultItem; - }; - - const Component = () => { - return ( -
-

Search Page

-
    - {results.map((result, index) => { - const SearchResultListItem = getResultItemComponent(result); - return ( - - ); - })} -
-
- ); - }; - - return ; - }, - }); - - createExtensionTester(SearchPageExtension) - .add(TechDocsSearchResultItemExtension, { - // TODO(Rugvip): We need to make the config input type available for use here - config: { - lineClamp: 3, - } as any, - }) - .add(ExploreSearchResultItemExtension) - .render(); - - expect(await screen.findByText(/Search Page/)).toBeInTheDocument(); - - expect( - await screen.findByText(/TechDocs - Rank: 1 - Line clamp: 3/, { - exact: false, - }), - ).toBeInTheDocument(); - - expect( - await screen.findByText(/Explore - Rank: 2/, { exact: false }), - ).toBeInTheDocument(); - - expect( - await screen.findByText(/Default - Rank: 3/, { exact: false }), - ).toBeInTheDocument(); - }); -}); diff --git a/plugins/search-react/src/alpha/extensions.tsx b/plugins/search-react/src/alpha/extensions.tsx deleted file mode 100644 index db09510a1e..0000000000 --- a/plugins/search-react/src/alpha/extensions.tsx +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2023 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. - */ - -import React, { lazy } from 'react'; -import { - ExtensionBoundary, - PortableSchema, - createExtension, - createSchemaFromZod, -} from '@backstage/frontend-plugin-api'; -import { - SearchResultItemExtensionComponent, - SearchResultItemExtensionPredicate, -} from './blueprints'; -import { SearchResultListItemExtension } from '../extensions'; -import { searchResultListItemDataRef } from './blueprints/types'; - -/** - * @alpha - * @deprecated Use {@link SearchResultListItemBlueprint} instead - */ -export type SearchResultItemExtensionOptions< - TConfig extends { noTrack?: boolean }, -> = { - /** - * The extension namespace. - */ - namespace?: string; - /** - * The extension name. - */ - name?: string; - /** - * The extension attachment point (e.g., search modal or page). - */ - attachTo?: { id: string; input: string }; - /** - * Optional extension config schema. - */ - configSchema?: PortableSchema; - /** - * The extension component. - */ - component: (options: { - config: TConfig; - }) => Promise; - /** - * When an extension defines a predicate, it returns true if the result should be rendered by that extension. - * Defaults to a predicate that returns true, which means it renders all sorts of results. - */ - predicate?: SearchResultItemExtensionPredicate; -}; - -/** - * Creates items for the search result list. - * - * @alpha - * @deprecated Use {@link SearchResultListItemBlueprint} instead - */ -export function createSearchResultListItemExtension< - TConfig extends { noTrack?: boolean }, ->(options: SearchResultItemExtensionOptions) { - const configSchema = - 'configSchema' in options - ? options.configSchema - : (createSchemaFromZod(z => - z.object({ - noTrack: z.boolean().default(false), - }), - ) as PortableSchema); - - return createExtension({ - kind: 'search-result-list-item', - namespace: options.namespace, - name: options.name, - attachTo: options.attachTo ?? { - id: 'page:search', - input: 'items', - }, - configSchema, - output: { - item: createSearchResultListItemExtension.itemDataRef, - }, - factory({ config, node }) { - const ExtensionComponent = lazy(() => - options - .component({ config }) - .then(component => ({ default: component })), - ) as unknown as SearchResultItemExtensionComponent; - - return { - item: { - predicate: options.predicate, - component: props => ( - - - - - - ), - }, - }; - }, - }); -} - -/** - * @alpha - * @deprecated Use {@link SearchResultListItemBlueprint} instead - */ -export namespace createSearchResultListItemExtension { - /** - * @deprecated Use {@link SearchResultListItemBlueprint#dataRefs.item} instead - */ - export const itemDataRef = searchResultListItemDataRef; -} diff --git a/plugins/search-react/src/alpha/index.ts b/plugins/search-react/src/alpha/index.ts index 04026d629d..239ffa89dd 100644 --- a/plugins/search-react/src/alpha/index.ts +++ b/plugins/search-react/src/alpha/index.ts @@ -13,5 +13,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export * from './extensions'; export * from './blueprints';