clean up search-react api report warnings
Signed-off-by: Emma Indal <emma.indahl@gmail.com>
This commit is contained in:
@@ -32,7 +32,11 @@ import useAsync, { AsyncState } from 'react-use/lib/useAsync';
|
||||
import usePrevious from 'react-use/lib/usePrevious';
|
||||
import { searchApiRef } from '../api';
|
||||
|
||||
type SearchContextValue = {
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type SearchContextValue = {
|
||||
result: AsyncState<SearchResultSet>;
|
||||
setTerm: React.Dispatch<React.SetStateAction<string>>;
|
||||
setTypes: React.Dispatch<React.SetStateAction<string[]>>;
|
||||
@@ -59,6 +63,8 @@ const SearchContext = createVersionedContext<{
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* React hook which provides the search context
|
||||
*/
|
||||
export const useSearch = () => {
|
||||
const context = useContext(SearchContext);
|
||||
@@ -85,12 +91,21 @@ const searchInitialState: SearchContextState = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Props for {@link SearchContextProvider}
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const SearchContextProvider = ({
|
||||
initialState = searchInitialState,
|
||||
children,
|
||||
}: PropsWithChildren<{ initialState?: SearchContextState }>) => {
|
||||
export type SearchContextProviderProps = PropsWithChildren<{
|
||||
initialState?: SearchContextState;
|
||||
}>;
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* Search context provider which gives you access to shared state between search components
|
||||
*/
|
||||
export const SearchContextProvider = (props: SearchContextProviderProps) => {
|
||||
const { initialState = searchInitialState, children } = props;
|
||||
const searchApi = useApi(searchApiRef);
|
||||
const [pageCursor, setPageCursor] = useState<string | undefined>(
|
||||
initialState.pageCursor,
|
||||
|
||||
@@ -18,35 +18,54 @@ import { SearchResultSet } from '@backstage/plugin-search-common';
|
||||
import { TestApiRegistry } from '@backstage/test-utils';
|
||||
import React, { ComponentProps, PropsWithChildren } from 'react';
|
||||
import { searchApiRef } from '../api';
|
||||
import { SearchContextProvider as RealSearchContextProvider } from './SearchContext';
|
||||
import { SearchContextProvider } from './SearchContext';
|
||||
|
||||
type QueryResultProps = {
|
||||
/**
|
||||
* Props for {@link SearchApiProviderForStorybook}
|
||||
* @public
|
||||
*/
|
||||
export type SearchApiProviderForStorybookProps = ComponentProps<
|
||||
typeof SearchContextProvider
|
||||
> & {
|
||||
mockedResults?: SearchResultSet;
|
||||
};
|
||||
|
||||
/**
|
||||
* Props for {@link SearchContextProviderForStorybook}
|
||||
* @public
|
||||
*/
|
||||
export type SearchContextProviderForStorybookProps = PropsWithChildren<{
|
||||
mockedResults?: SearchResultSet;
|
||||
}>;
|
||||
|
||||
/**
|
||||
* Utility api provider only for use in Storybook stories.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export function SearchApiProviderForStorybook(
|
||||
props: SearchApiProviderForStorybookProps,
|
||||
) {
|
||||
const { mockedResults, children } = props;
|
||||
const query: any = () => Promise.resolve(mockedResults || {});
|
||||
const apiRegistry = TestApiRegistry.from([searchApiRef, { query }]);
|
||||
return <ApiProvider apis={apiRegistry} children={children} />;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility context provider only for use in Storybook stories. You should use
|
||||
* the real `<SearchContextProvider>` exported by `@backstage/plugin-search-react` in
|
||||
* your app instead of this! In some cases (like the search page) it may
|
||||
* already be provided on your behalf.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const SearchContextProvider = (
|
||||
props: ComponentProps<typeof RealSearchContextProvider> & QueryResultProps,
|
||||
export const SearchContextProviderForStorybook = (
|
||||
props: SearchContextProviderForStorybookProps,
|
||||
) => {
|
||||
return (
|
||||
<SearchApiProvider {...props}>
|
||||
<RealSearchContextProvider children={props.children} />
|
||||
</SearchApiProvider>
|
||||
<SearchApiProviderForStorybook {...props}>
|
||||
<SearchContextProvider children={props.children} />
|
||||
</SearchApiProviderForStorybook>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Utility api provider only for use in Storybook stories.
|
||||
*
|
||||
*/
|
||||
export function SearchApiProvider(props: PropsWithChildren<QueryResultProps>) {
|
||||
const { mockedResults, children } = props;
|
||||
const query: any = () => Promise.resolve(mockedResults || {});
|
||||
const apiRegistry = TestApiRegistry.from([searchApiRef, { query }]);
|
||||
return <ApiProvider apis={apiRegistry} children={children} />;
|
||||
}
|
||||
|
||||
@@ -15,8 +15,16 @@
|
||||
*/
|
||||
|
||||
export { SearchContextProvider, useSearch } from './SearchContext';
|
||||
export type { SearchContextState } from './SearchContext';
|
||||
export type {
|
||||
SearchContextProviderProps,
|
||||
SearchContextState,
|
||||
SearchContextValue,
|
||||
} from './SearchContext';
|
||||
export {
|
||||
SearchContextProvider as SearchContextProviderForStorybook,
|
||||
SearchApiProvider as SearchApiProviderForStorybook,
|
||||
SearchContextProviderForStorybook,
|
||||
SearchApiProviderForStorybook,
|
||||
} from './SearchContextForStorybook.stories';
|
||||
export type {
|
||||
SearchContextProviderForStorybookProps,
|
||||
SearchApiProviderForStorybookProps,
|
||||
} from './SearchContextForStorybook.stories';
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Search Plugin frontend library
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
|
||||
export { searchApiRef } from './api';
|
||||
export type { SearchApi } from './api';
|
||||
export {
|
||||
@@ -22,4 +28,10 @@ export {
|
||||
SearchContextProviderForStorybook,
|
||||
SearchApiProviderForStorybook,
|
||||
} from './context';
|
||||
export type { SearchContextState } from './context';
|
||||
export type {
|
||||
SearchContextProviderProps,
|
||||
SearchContextState,
|
||||
SearchContextValue,
|
||||
SearchContextProviderForStorybookProps,
|
||||
SearchApiProviderForStorybookProps,
|
||||
} from './context';
|
||||
|
||||
Reference in New Issue
Block a user