Merge pull request #8455 from Sarabadu/master
[RFC] LayoutProvider and focusContent
This commit is contained in:
@@ -24,6 +24,7 @@ import {
|
||||
Grid,
|
||||
List,
|
||||
Paper,
|
||||
useTheme,
|
||||
} from '@material-ui/core';
|
||||
import LaunchIcon from '@material-ui/icons/Launch';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
@@ -33,7 +34,7 @@ import { SearchResult } from '../SearchResult';
|
||||
import { SearchContextProvider, useSearch } from '../SearchContext';
|
||||
import { SearchResultPager } from '../SearchResultPager';
|
||||
import { useRouteRef } from '@backstage/core-plugin-api';
|
||||
import { Link } from '@backstage/core-components';
|
||||
import { Link, useContent } from '@backstage/core-components';
|
||||
import { rootRouteRef } from '../../plugin';
|
||||
|
||||
export interface SearchModalProps {
|
||||
@@ -61,9 +62,12 @@ export const Modal = ({ open = true, toggleModal }: SearchModalProps) => {
|
||||
const classes = useStyles();
|
||||
|
||||
const { term } = useSearch();
|
||||
const { focusContent } = useContent();
|
||||
const { transitions } = useTheme();
|
||||
|
||||
const handleResultClick = () => {
|
||||
toggleModal();
|
||||
setTimeout(focusContent, transitions.duration.leavingScreen);
|
||||
};
|
||||
|
||||
const handleKeyPress = () => {
|
||||
@@ -94,7 +98,13 @@ export const Modal = ({ open = true, toggleModal }: SearchModalProps) => {
|
||||
alignItems="center"
|
||||
>
|
||||
<Grid item>
|
||||
<Link onClick={toggleModal} to={`${getSearchLink()}?query=${term}`}>
|
||||
<Link
|
||||
onClick={() => {
|
||||
toggleModal();
|
||||
setTimeout(focusContent, transitions.duration.leavingScreen);
|
||||
}}
|
||||
to={`${getSearchLink()}?query=${term}`}
|
||||
>
|
||||
<span className={classes.viewResultsLink}>View Full Results</span>
|
||||
<LaunchIcon color="primary" />
|
||||
</Link>
|
||||
|
||||
@@ -18,8 +18,8 @@ import React, { useCallback } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { rootRouteRef } from '../../plugin';
|
||||
|
||||
import { SidebarSearchField } from '@backstage/core-components';
|
||||
import { useRouteRef, IconComponent } from '@backstage/core-plugin-api';
|
||||
import { SidebarSearchField, useContent } from '@backstage/core-components';
|
||||
|
||||
export type SidebarSearchProps = {
|
||||
icon?: IconComponent;
|
||||
@@ -27,14 +27,15 @@ export type SidebarSearchProps = {
|
||||
|
||||
export const SidebarSearch = (props: SidebarSearchProps) => {
|
||||
const searchRoute = useRouteRef(rootRouteRef);
|
||||
const { focusContent } = useContent();
|
||||
const navigate = useNavigate();
|
||||
const handleSearch = useCallback(
|
||||
(query: string): void => {
|
||||
const queryString = qs.stringify({ query }, { addQueryPrefix: true });
|
||||
|
||||
focusContent();
|
||||
navigate(`${searchRoute()}${queryString}`);
|
||||
},
|
||||
[navigate, searchRoute],
|
||||
[focusContent, navigate, searchRoute],
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user