diff --git a/plugins/catalog-react/src/hooks/useEntityListProvider.tsx b/plugins/catalog-react/src/hooks/useEntityListProvider.tsx index 8ca3efd243..7db2205deb 100644 --- a/plugins/catalog-react/src/hooks/useEntityListProvider.tsx +++ b/plugins/catalog-react/src/hooks/useEntityListProvider.tsx @@ -84,6 +84,9 @@ export type EntityListContextProps< */ queryParameters: Partial>; + showFiltersDrawer: boolean; + toggleFiltersDrawer: (showFiltersDrawer: boolean) => void; + loading: boolean; error?: Error; }; @@ -108,6 +111,8 @@ export const EntityListProvider = ({ const [requestedFilters, setRequestedFilters] = useState( {} as EntityFilters, ); + // Show + const [showFiltersDrawer, toggleFiltersDrawer] = useState(false); const [outputState, setOutputState] = useState>({ appliedFilters: {} as EntityFilters, entities: [], @@ -203,6 +208,8 @@ export const EntityListProvider = ({ updateFilters, queryParameters: outputState.queryParameters, loading, + showFiltersDrawer, + toggleFiltersDrawer, error, }} > diff --git a/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx b/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx index 50fb2433df..3df46ff0c0 100644 --- a/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx +++ b/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx @@ -16,8 +16,6 @@ import { Content, - ContentHeader, - ContentHeaderTitle, PageWithHeader, SupportButton, TableColumn, @@ -34,15 +32,16 @@ import { UserListFilterKind, UserListPicker, } from '@backstage/plugin-catalog-react'; -import { BackstageTheme } from '@backstage/theme'; -import { Box, Grid, IconButton, useMediaQuery } from '@material-ui/core'; -import FilterListIcon from '@material-ui/icons/FilterList'; -import React, { useState } from 'react'; +import React from 'react'; import { CatalogTable } from '../CatalogTable'; import { EntityRow } from '../CatalogTable/types'; import { CreateComponentButton } from '../CreateComponentButton/CreateComponentButton'; -import { FilterContainer } from '../FilterContainer'; -import { FilteredTableLayout } from '../FilteredTableLayout'; +import { + FilteredTableLayout, + TableContainer, + FilterContainer, +} from '../FilteredTableLayout'; +import { CatalogPageHeader } from './CatalogPageHeader'; export type CatalogPageProps = { initiallySelectedFilter?: UserListFilterKind; @@ -50,74 +49,24 @@ export type CatalogPageProps = { actions?: TableProps['actions']; }; -const CatalogPageHeaderAction = ({ - showFilter, - toggleFilter, - isMidSizeScreen, -}: { - showFilter: boolean; - toggleFilter: (showFilter: boolean) => void; - isMidSizeScreen: boolean; -}) => - isMidSizeScreen ? ( - - - toggleFilter(!showFilter)}> - - - - ) : ( - - ); - -const CatalogPageHeader = ({ - children, - ...props -}: React.PropsWithChildren<{ - showFilter: boolean; - toggleFilter: (showFilter: boolean) => void; - isMidSizeScreen: boolean; -}>) => { - return ( - } - > - {children} - - ); -}; - export const CatalogPage = ({ columns, actions, initiallySelectedFilter = 'owned', }: CatalogPageProps) => { - const [showFilter, toggleFilter] = useState(false); - const isMidSizeScreen = useMediaQuery(theme => - theme.breakpoints.down('md'), - ); - const orgName = useApi(configApiRef).getOptionalString('organization.name') ?? 'Backstage'; return ( - - - All your software catalog entities - + + + All your software catalog entities + - + - + - + diff --git a/plugins/catalog/src/components/CatalogPage/CatalogPageHeader.tsx b/plugins/catalog/src/components/CatalogPage/CatalogPageHeader.tsx new file mode 100644 index 0000000000..f628aef596 --- /dev/null +++ b/plugins/catalog/src/components/CatalogPage/CatalogPageHeader.tsx @@ -0,0 +1,50 @@ +/* + * Copyright 2021 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 { ContentHeader, ContentHeaderTitle } from '@backstage/core-components'; +import { useEntityListProvider } from '@backstage/plugin-catalog-react'; +import { BackstageTheme } from '@backstage/theme'; +import { Box, IconButton, useMediaQuery } from '@material-ui/core'; +import FilterListIcon from '@material-ui/icons/FilterList'; +import React from 'react'; + +const CatalogPageHeaderAction = () => { + const isMidSizeScreen = useMediaQuery(theme => + theme.breakpoints.down('md'), + ); + const { showFiltersDrawer, toggleFiltersDrawer } = useEntityListProvider(); + + return isMidSizeScreen ? ( + + + toggleFiltersDrawer(!showFiltersDrawer)}> + + + + ) : ( + + ); +}; + +export const CatalogPageHeader = ({ + children, +}: React.PropsWithChildren<{}>) => { + return ( + }> + {children} + + ); +}; diff --git a/plugins/catalog/src/components/CreateComponentButton/CreateComponentButton.tsx b/plugins/catalog/src/components/CreateComponentButton/CreateComponentButton.tsx index 482a0c0a3c..4be93c1aa0 100644 --- a/plugins/catalog/src/components/CreateComponentButton/CreateComponentButton.tsx +++ b/plugins/catalog/src/components/CreateComponentButton/CreateComponentButton.tsx @@ -23,9 +23,7 @@ import { useRouteRef } from '@backstage/core-plugin-api'; export const CreateComponentButton = () => { const createComponentLink = useRouteRef(createComponentRouteRef); - if (!createComponentLink) return null; - - return ( + return !createComponentLink ? null : (