From 213a1c3c840559c311c0e45d9d255fc8275aeeab Mon Sep 17 00:00:00 2001 From: Twisha Saraiya Date: Sun, 9 Aug 2020 21:53:40 +0530 Subject: [PATCH 1/4] add button to register dummy entities --- .../components/CatalogPage/CatalogPage.tsx | 60 +++++++++++++++++-- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx b/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx index 6a3d7362aa..3eac1b7a30 100644 --- a/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx +++ b/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx @@ -14,28 +14,30 @@ * limitations under the License. */ +import { Entity } from '@backstage/catalog-model'; import { + configApiRef, Content, ContentHeader, identityApiRef, SupportButton, - configApiRef, useApi, } from '@backstage/core'; import { rootRoute as scaffolderRootRoute } from '@backstage/plugin-scaffolder'; import { Button, makeStyles } from '@material-ui/core'; import SettingsIcon from '@material-ui/icons/Settings'; import StarIcon from '@material-ui/icons/Star'; -import React, { useMemo, useState } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; import { Link as RouterLink } from 'react-router-dom'; +import { catalogApiRef } from '../../api/types'; import { EntityFilterGroupsProvider, useFilteredEntities } from '../../filter'; import { useStarredEntities } from '../../hooks/useStarredEntites'; -import { CatalogFilter, ButtonGroup } from '../CatalogFilter/CatalogFilter'; +import { ButtonGroup, CatalogFilter } from '../CatalogFilter/CatalogFilter'; import { CatalogTable } from '../CatalogTable/CatalogTable'; +import { ResultsFilter } from '../ResultsFilter/ResultsFilter'; import CatalogLayout from './CatalogLayout'; import { CatalogTabs, LabeledComponentType } from './CatalogTabs'; import { WelcomeBanner } from './WelcomeBanner'; -import { ResultsFilter } from '../ResultsFilter/ResultsFilter'; const useStyles = makeStyles(theme => ({ contentWrapper: { @@ -44,6 +46,9 @@ const useStyles = makeStyles(theme => ({ gridTemplateColumns: '250px 1fr', gridColumnGap: theme.spacing(2), }, + mockDataButton: { + marginRight: '20px', + }, })); const CatalogPageContents = () => { @@ -58,9 +63,42 @@ const CatalogPageContents = () => { const userId = useApi(identityApiRef).getUserId(); const [selectedTab, setSelectedTab] = useState(); const [selectedSidebarItem, setSelectedSidebarItem] = useState(); + const [entitiesState, setEntitiesState] = useState([]); + const [errorState, setError] = useState(); + + useEffect(() => { + setError(error); + setEntitiesState(matchingEntities); + }, [error, matchingEntities]); + const catalogApi = useApi(catalogApiRef); const orgName = useApi(configApiRef).getOptionalString('organization.name') ?? 'Company'; + const addMockData = async () => { + try { + const dummyEntities = [ + 'artist-lookup-component.yaml', + 'playback-order-component.yaml', + 'podcast-api-component.yaml', + 'queue-proxy-component.yaml', + 'searcher-component.yaml', + 'playback-lib-component.yaml', + 'www-artist-component.yaml', + 'shuffle-api-component.yaml', + ]; + const _promises = dummyEntities.map(file => + catalogApi.addLocation( + 'github', + `https://github.com/spotify/backstage/blob/master/packages/catalog-model/examples/${file}`, + ), + ); + await Promise.all(_promises); + const data: Entity[] = await catalogApi.getEntities(); + setEntitiesState(data); + } catch (err) { + setError(err); + } + }; const tabs = useMemo( () => [ { @@ -129,6 +167,16 @@ const CatalogPageContents = () => { + {entitiesState && entitiesState.length === 0 ? ( + + ) : null} - ) : null}