diff --git a/.changeset/silver-donkeys-eat.md b/.changeset/silver-donkeys-eat.md new file mode 100644 index 0000000000..0995a2025c --- /dev/null +++ b/.changeset/silver-donkeys-eat.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-stack-overflow': patch +--- + +Export api ref and StackOverflowApi type diff --git a/packages/app/src/components/home/templates/DefaultTemplate.stories.tsx b/packages/app/src/components/home/templates/DefaultTemplate.stories.tsx index 638fe8bc29..9cf2e8ab35 100644 --- a/packages/app/src/components/home/templates/DefaultTemplate.stories.tsx +++ b/packages/app/src/components/home/templates/DefaultTemplate.stories.tsx @@ -19,7 +19,7 @@ import { HomePageCompanyLogo, HomePageStarredEntities, TemplateBackstageLogo, - TemplateBackstageLogoIcon + TemplateBackstageLogoIcon, } from '@backstage/plugin-home'; import { wrapInTestApp, TestApiProvider } from '@backstage/test-utils'; import { Content, Page, InfoCard } from '@backstage/core-components'; @@ -31,12 +31,12 @@ import { } from '@backstage/plugin-catalog-react'; import { configApiRef } from '@backstage/core-plugin-api'; import { ConfigReader } from '@backstage/config'; +import { HomePageSearchBar, searchPlugin } from '@backstage/plugin-search'; import { - HomePageSearchBar, - searchPlugin, -} from '@backstage/plugin-search'; -import { searchApiRef, SearchContextProvider } from '@backstage/plugin-search-react'; -import { HomePageStackOverflowQuestions } from '@backstage/plugin-stack-overflow'; + searchApiRef, + SearchContextProvider, +} from '@backstage/plugin-search-react'; +import { stackOverflowApiRef, HomePageStackOverflowQuestions } from '@backstage/plugin-stack-overflow'; import { Grid, makeStyles } from '@material-ui/core'; import React, { ComponentType } from 'react'; @@ -79,6 +79,25 @@ const mockCatalogApi = { getEntities: async () => ({ items: entities }), }; +const mockStackOverflowApi = { + listQuestions: async () => [ + { + title: 'Customizing Spotify backstage UI', + link: 'stackoverflow.question/1', + answer_count: 0, + tags: ['backstage'], + owner: { 'some owner': 'name' }, + }, + { + title: 'Customizing Spotify backstage UI', + link: 'stackoverflow.question/1', + answer_count: 0, + tags: ['backstage'], + owner: { 'some owner': 'name' }, + }, + ], +}; + const starredEntitiesApi = new MockStarredEntitiesApi(); starredEntitiesApi.toggleStarred('component:default/example-starred-entity'); starredEntitiesApi.toggleStarred('component:default/example-starred-entity-2'); @@ -93,6 +112,7 @@ export default { <> Promise.resolve({ results: [] }) }], diff --git a/plugins/stack-overflow/api-report.md b/plugins/stack-overflow/api-report.md index fe2a970c13..598bd06a04 100644 --- a/plugins/stack-overflow/api-report.md +++ b/plugins/stack-overflow/api-report.md @@ -5,6 +5,7 @@ ```ts /// +import { ApiRef } from '@backstage/core-plugin-api'; import { BackstagePlugin } from '@backstage/core-plugin-api'; import { CardExtensionProps } from '@backstage/plugin-home'; import { ReactNode } from 'react'; @@ -15,6 +16,16 @@ export const HomePageStackOverflowQuestions: ( props: CardExtensionProps, ) => JSX.Element; +// @public (undocumented) +export type StackOverflowApi = { + listQuestions(options?: { + requestParams: StackOverflowQuestionsRequestParams; + }): Promise; +}; + +// @public (undocumented) +export const stackOverflowApiRef: ApiRef; + // @public export const StackOverflowIcon: () => JSX.Element; diff --git a/plugins/stack-overflow/src/api/StackOverflowApi.ts b/plugins/stack-overflow/src/api/StackOverflowApi.ts index 6e76f51409..d470e879e7 100644 --- a/plugins/stack-overflow/src/api/StackOverflowApi.ts +++ b/plugins/stack-overflow/src/api/StackOverflowApi.ts @@ -20,10 +20,16 @@ import { StackOverflowQuestionsRequestParams, } from '../types'; +/** + * @public + */ export const stackOverflowApiRef = createApiRef({ id: 'plugin.stackoverflow.service', }); +/** + * @public + */ export type StackOverflowApi = { listQuestions(options?: { requestParams: StackOverflowQuestionsRequestParams; diff --git a/plugins/stack-overflow/src/home/StackOverflowQuestions/StackOverflowQuestions.stories.tsx b/plugins/stack-overflow/src/home/StackOverflowQuestions/StackOverflowQuestions.stories.tsx index 35ace44c14..aed1ed25aa 100644 --- a/plugins/stack-overflow/src/home/StackOverflowQuestions/StackOverflowQuestions.stories.tsx +++ b/plugins/stack-overflow/src/home/StackOverflowQuestions/StackOverflowQuestions.stories.tsx @@ -21,6 +21,26 @@ import { ConfigReader } from '@backstage/config'; import { Grid } from '@material-ui/core'; import React, { ComponentType } from 'react'; import { StackOverflowIcon } from '../../icons'; +import { stackOverflowApiRef } from '../../api'; + +const mockStackOverflowApi = { + listQuestions: async () => [ + { + title: 'Customizing Spotify backstage UI', + link: 'stackoverflow.question/1', + answer_count: 0, + tags: ['backstage'], + owner: { 'some owner': 'name' }, + }, + { + title: 'Customizing Spotify backstage UI', + link: 'stackoverflow.question/1', + answer_count: 0, + tags: ['backstage'], + owner: { 'some owner': 'name' }, + }, + ], +}; export default { title: 'Plugins/Home/Components/StackOverflow', @@ -39,6 +59,7 @@ export default { }, }), ], + [stackOverflowApiRef, mockStackOverflowApi], ]} > diff --git a/plugins/stack-overflow/src/index.ts b/plugins/stack-overflow/src/index.ts index 5965d66983..a796f563eb 100644 --- a/plugins/stack-overflow/src/index.ts +++ b/plugins/stack-overflow/src/index.ts @@ -30,3 +30,5 @@ export type { StackOverflowQuestionsContentProps, StackOverflowQuestionsRequestParams, } from './types'; +export { stackOverflowApiRef } from './api'; +export type { StackOverflowApi } from './api';