apply review feedback

Signed-off-by: Anders Näsman <andersn@spotify.com>
This commit is contained in:
Anders Näsman
2022-06-07 16:30:04 +02:00
committed by Eric Peterson
parent 295eb30778
commit 2dc4818541
13 changed files with 32 additions and 150 deletions
+3 -3
View File
@@ -1,6 +1,6 @@
---
'@backstage/plugin-search': minor
'@backstage/plugin-search-react': minor
'@backstage/plugin-search': patch
'@backstage/plugin-search-react': patch
---
Components `<DefaultResultListItem>`, `<SearchBar>` (including `<SearchBarBase>`), `<SearchFilter>` (including `.Checkbox`, `.Select`, and `.Autocomplete` static prop components), `<SearchResult>`, `<SearchResultPager>`, and `<SearchTracker>` are now exported from `@backstage/plugin-search-react`. They are now deprecated in `@backstage/plugin-search` and will be removed in a future release.
Components `<DefaultResultListItem>`, `<SearchBar>` (including `<SearchBarBase>`), `<SearchFilter>` (including `.Checkbox`, `.Select`, and `.Autocomplete` static prop components), `<SearchResult>`, and `<SearchResultPager>` are now exported from `@backstage/plugin-search-react`. They are now deprecated in `@backstage/plugin-search` and will be removed in a future release.
+6 -13
View File
@@ -8,17 +8,10 @@ To upgrade your App, update the following in `packages/app/src/components/search
```diff
import {
- SearchBar
- SearchFilter
- SearchResult
SearchType,
- DefaultResultListItem
} from `@backstage/plugin-search`;
import {
+ DefaultResultListItem
+ SearchBar
+ SearchFilter
+ SearchResult
useSearch,
} from `@backstage/plugin-search-react`;
DefaultResultListItem
SearchBar
SearchFilter
SearchResult
- } from `@backstage/plugin-search`;
+ } from `@backstage/plugin-search-react`;
```
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-search': minor
---
The pre-alpha `<SearchPageNext>`, `<SearchBarNext>`, `etc...` components have been removed. In the unlikely event you were still using/referencing them, please update to using their non-`*Next` equivalents from either `@backstage/plugin-search-react` or `@backstage/plugin-search`.
-7
View File
@@ -187,13 +187,6 @@ export type SearchResultProps = {
// @public (undocumented)
export const SelectFilter: (props: SearchFilterComponentProps) => JSX.Element;
// @public
export const TrackSearch: ({
children,
}: {
children: React_2.ReactChild;
}) => JSX.Element;
// @public
export const useAsyncFilterValues: (
fn: ((partial: string) => Promise<string[]>) | undefined,
@@ -101,8 +101,6 @@ export const DefaultResultListItemComponent = ({
};
/**
* A higher order function providing AnalyticsContext to the DefaultResultListItemComponent.
*
* @public
*/
const HigherOrderDefaultResultListItem = (
@@ -65,8 +65,6 @@ export const SearchResultComponent = ({ children }: SearchResultProps) => {
};
/**
* A higher order function providing AnalyticsContext to the SearchResultComponent.
*
* @public
*/
const HigherOrderSearchResult = (props: SearchResultProps) => {
@@ -20,8 +20,6 @@ import { useSearch } from '../../context';
/**
* Capture search event on term change.
*
* @public
*/
export const TrackSearch = ({ children }: { children: React.ReactChild }) => {
const analytics = useAnalytics();
@@ -19,5 +19,4 @@ export * from './SearchFilter';
export * from './SearchResult';
export * from './SearchResultPager';
export * from './SearchBar';
export * from './SearchTracker';
export * from './DefaultResultListItem';
+1 -1
View File
@@ -99,7 +99,7 @@ export const SearchBarBase: ({
inputProps: defaultInputProps,
endAdornment: defaultEndAdornment,
...props
}: SearchBarBaseProps) => JSX.Element;
}: SearchBarBaseProps_2) => JSX.Element;
// @public @deprecated
export type SearchBarBaseProps = Omit<InputBaseProps, 'onChange'> & {
@@ -14,36 +14,20 @@
* limitations under the License.
*/
import React, {
ChangeEvent,
KeyboardEvent,
useState,
useEffect,
useCallback,
} from 'react';
import useDebounce from 'react-use/lib/useDebounce';
import { configApiRef, useApi } from '@backstage/core-plugin-api';
import {
InputBase,
InputBaseProps,
InputAdornment,
IconButton,
} from '@material-ui/core';
import SearchIcon from '@material-ui/icons/Search';
import ClearButton from '@material-ui/icons/Clear';
import React, { useCallback } from 'react';
import { InputBaseProps } from '@material-ui/core';
import {
SearchContextProvider,
SearchBarBase as RealSearchBarBase,
useSearch,
useSearchContextCheck,
TrackSearch,
} from '@backstage/plugin-search-react';
/**
* Props for {@link SearchBarBase}.
*
* @public
* @deprecated Moved to `@backstage/plugin-search-react`.
* @deprecated Import from `@backstage/plugin-search-react` instead.
*/
export type SearchBarBaseProps = Omit<InputBaseProps, 'onChange'> & {
debounceTime?: number;
@@ -59,102 +43,15 @@ export type SearchBarBaseProps = Omit<InputBaseProps, 'onChange'> & {
* Recommended if you don't use Search Provider or Search Context.
*
* @public
* @deprecated Moved to `@backstage/plugin-search-react`.
* @deprecated Import from `@backstage/plugin-search-react` instead.
*/
export const SearchBarBase = ({
onChange,
onKeyDown,
onSubmit,
debounceTime = 200,
clearButton = true,
fullWidth = true,
value: defaultValue,
inputProps: defaultInputProps = {},
endAdornment: defaultEndAdornment,
...props
}: SearchBarBaseProps) => {
const configApi = useApi(configApiRef);
const [value, setValue] = useState<string>(defaultValue as string);
const hasSearchContext = useSearchContextCheck();
useEffect(() => {
setValue(prevValue =>
prevValue !== defaultValue ? (defaultValue as string) : prevValue,
);
}, [defaultValue]);
useDebounce(() => onChange(value), debounceTime, [value]);
const handleChange = useCallback(
(e: ChangeEvent<HTMLInputElement>) => {
setValue(e.target.value);
},
[setValue],
);
const handleKeyDown = useCallback(
(e: KeyboardEvent<HTMLInputElement>) => {
if (onKeyDown) onKeyDown(e);
if (onSubmit && e.key === 'Enter') {
onSubmit();
}
},
[onKeyDown, onSubmit],
);
const handleClear = useCallback(() => {
onChange('');
}, [onChange]);
const placeholder = `Search in ${
configApi.getOptionalString('app.title') || 'Backstage'
}`;
const startAdornment = (
<InputAdornment position="start">
<IconButton aria-label="Query" disabled>
<SearchIcon />
</IconButton>
</InputAdornment>
);
const endAdornment = (
<InputAdornment position="end">
<IconButton aria-label="Clear" onClick={handleClear}>
<ClearButton />
</IconButton>
</InputAdornment>
);
const searchBar = (
<TrackSearch>
<InputBase
data-testid="search-bar-next"
value={value}
placeholder={placeholder}
startAdornment={startAdornment}
endAdornment={clearButton ? endAdornment : defaultEndAdornment}
inputProps={{ 'aria-label': 'Search', ...defaultInputProps }}
fullWidth={fullWidth}
onChange={handleChange}
onKeyDown={handleKeyDown}
{...props}
/>
</TrackSearch>
);
return hasSearchContext ? (
searchBar
) : (
<SearchContextProvider>{searchBar}</SearchContextProvider>
);
};
export const SearchBarBase = RealSearchBarBase;
/**
* Props for {@link SearchBar}.
*
* @public
* @deprecated Moved to `@backstage/plugin-search-react`.
* @deprecated Import from `@backstage/plugin-search-react` instead.
*/
export type SearchBarProps = Partial<SearchBarBaseProps>;
@@ -162,7 +59,7 @@ export type SearchBarProps = Partial<SearchBarBaseProps>;
* Recommended search bar when you use the Search Provider or Search Context.
*
* @public
* @deprecated Moved to `@backstage/plugin-search-react`.
* @deprecated Import from `@backstage/plugin-search-react` instead.
*/
export const SearchBar = ({ onChange, ...props }: SearchBarProps) => {
const { term, setTerm } = useSearch();
@@ -25,7 +25,7 @@ import {
/**
* @public
* @deprecated Moved to `@backstage/plugin-search-react`.
* @deprecated Import from `@backstage/plugin-search-react` instead.
*/
export type SearchFilterComponentProps = {
className?: string;
@@ -48,7 +48,7 @@ export type SearchFilterComponentProps = {
/**
* @public
* @deprecated Moved to `@backstage/plugin-search-react`.
* @deprecated Import from `@backstage/plugin-search-react` instead.
*/
export type SearchFilterWrapperProps = SearchFilterComponentProps & {
component: (props: SearchFilterComponentProps) => ReactElement;
@@ -57,7 +57,7 @@ export type SearchFilterWrapperProps = SearchFilterComponentProps & {
/**
* @public
* @deprecated Moved to `@backstage/plugin-search-react`.
* @deprecated Import from `@backstage/plugin-search-react` instead.
*/
const SearchFilter = ({
component: Element,
@@ -65,7 +65,7 @@ const SearchFilter = ({
}: SearchFilterWrapperProps) => <Element {...props} />;
/**
* @deprecated Moved to `@backstage/plugin-search-react`.
* @deprecated Import from `@backstage/plugin-search-react` instead.
*/
SearchFilter.Checkbox = (
props: Omit<SearchFilterWrapperProps, 'component'> &
@@ -73,7 +73,7 @@ SearchFilter.Checkbox = (
) => <SearchFilter {...props} component={CheckboxFilter} />;
/**
* @deprecated Moved to `@backstage/plugin-search-react`.
* @deprecated Import from `@backstage/plugin-search-react` instead.
*/
SearchFilter.Select = (
props: Omit<SearchFilterWrapperProps, 'component'> &
@@ -86,7 +86,7 @@ SearchFilter.Select = (
* which returns values may be provided instead.
*
* @public
* @deprecated Moved to `@backstage/plugin-search-react`.
* @deprecated Import from `@backstage/plugin-search-react` instead.
*/
SearchFilter.Autocomplete = (props: SearchAutocompleteFilterProps) => (
<SearchFilter {...props} component={AutocompleteFilter} />
@@ -31,7 +31,7 @@ const useStyles = makeStyles(theme => ({
/**
* @public
* @deprecated Moved to `@backstage/plugin-search-react`.
* @deprecated Import from `@backstage/plugin-search-react` instead.
*/
export const SearchResultPager = () => {
const { fetchNextPage, fetchPreviousPage } = useSearch();
+1
View File
@@ -256,6 +256,7 @@ const NO_WARNING_PACKAGES = [
'plugins/scaffolder-backend-module-rails',
'plugins/scaffolder-backend-module-yeoman',
'plugins/scaffolder-common',
'plugins/search',
'plugins/search-backend',
'plugins/search-backend-node',
'plugins/search-backend-module-elasticsearch',