Skip to content

Commit

Permalink
Merge pull request #186 from awanlin/feat/add-home-plugin
Browse files Browse the repository at this point in the history
feat: added Home plugin
  • Loading branch information
awanlin authored Nov 24, 2023
2 parents a2915cf + 421aea8 commit fca3688
Show file tree
Hide file tree
Showing 10 changed files with 8,829 additions and 10,725 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"eslint-plugin-jest": "*",
"node-fetch": "^2.6.7",
"prettier": "^2.3.2",
"typescript": "^4.5.5"
"typescript": "~5.2.0"
},
"prettier": "@spotify/prettier-config",
"lint-staged": {
Expand Down
5 changes: 4 additions & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@backstage/plugin-explore": "^0.4.14-next.0",
"@backstage/plugin-github-actions": "^0.6.9-next.0",
"@backstage/plugin-graphiql": "^0.3.1-next.1",
"@backstage/plugin-home": "^0.5.10-next.2",
"@backstage/plugin-org": "^0.6.18-next.0",
"@backstage/plugin-search": "^1.4.4-next.1",
"@backstage/plugin-search-react": "^1.7.4-next.0",
Expand All @@ -49,7 +50,9 @@
"@types/jest": "^26.0.7",
"@types/node": "^12.0.0",
"@types/react-dom": "*",
"cross-env": "^7.0.0"
"@types/uuid": "^9.0.0",
"cross-env": "^7.0.0",
"uuid": "^9.0.1"
},
"scripts": {
"start": "backstage-cli package start",
Expand Down
20 changes: 17 additions & 3 deletions packages/app/src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import React from 'react';
import { renderWithEffects } from '@backstage/test-utils';
import App from './App';
import { v4 } from 'uuid';

describe('App', () => {
const mockRandomUUID = () =>
v4() as `${string}-${string}-${string}-${string}-${string}`;

beforeEach(() => {
window.crypto.randomUUID = mockRandomUUID;
});

it('should render', async () => {
process.env = {
NODE_ENV: 'test',
APP_CONFIG: [
{
data: {
app: { title: 'Test' },
backend: { baseUrl: 'http://localhost:7000' },
app: {
title: 'Test',
support: { url: 'http://localhost:7007/support' },
},
backend: { baseUrl: 'http://localhost:7007' },
lighthouse: {
baseUrl: 'http://localhost:3003',
},
techdocs: {
storageUrl: 'http://localhost:7000/api/techdocs/static/docs',
storageUrl: 'http://localhost:7007/api/techdocs/static/docs',
},
},
context: 'test',
Expand Down
24 changes: 20 additions & 4 deletions packages/app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as plugins from './plugins';

import { AlertDisplay, OAuthRequestDialog } from '@backstage/core-components';
import { AppRouter, FlatRoutes } from '@backstage/core-app-api';
import { AppRouter, FeatureFlagged, FlatRoutes } from '@backstage/core-app-api';
import {
CatalogEntityPage,
CatalogIndexPage,
Expand All @@ -17,7 +17,7 @@ import {
CostInsightsProjectGrowthInstructionsPage,
} from '@backstage/plugin-cost-insights';
import { ExplorePage } from '@backstage/plugin-explore';
import { Navigate, Route } from 'react-router';
import { Route } from 'react-router';
import {
TechDocsIndexPage,
TechDocsReaderPage,
Expand All @@ -39,6 +39,9 @@ import { entityPage } from './components/catalog/EntityPage';
import { orgPlugin } from '@backstage/plugin-org';
import { searchPage } from './components/search/SearchPage';
import { CssBaseline } from '@material-ui/core';
import { HomepageCompositionRoot, VisitListener } from '@backstage/plugin-home';
import { HomePage } from './components/home/HomePage';
import { CustomizableHomePage } from './components/home/CustomizableHomePage';

const app = createApp({
apis,
Expand Down Expand Up @@ -87,9 +90,21 @@ const app = createApp({

const routes = (
<FlatRoutes>
<Navigate key="/" to="catalog" replace />
<FeatureFlagged with="customizable-home-page-preview">
<Route path="/home" element={<HomepageCompositionRoot />}>
<CustomizableHomePage />
</Route>
</FeatureFlagged>
<FeatureFlagged without="customizable-home-page-preview">
<Route path="/home" element={<HomepageCompositionRoot />}>
<HomePage />
</Route>
</FeatureFlagged>
<Route path="/api-docs" element={<ApiExplorerPage />} />
<Route path="/catalog" element={<CatalogIndexPage initiallySelectedFilter='all' />} />
<Route
path="/"
element={<CatalogIndexPage initiallySelectedFilter="all" />}
/>
<Route
path="/catalog/:namespace/:kind/:name"
element={<CatalogEntityPage />}
Expand Down Expand Up @@ -129,6 +144,7 @@ export default app.createRoot(
<AlertDisplay />
<OAuthRequestDialog />
<AppRouter>
<VisitListener />
<Root>{routes}</Root>
</AppRouter>
</>,
Expand Down
19 changes: 17 additions & 2 deletions packages/app/src/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import {
errorApiRef,
configApiRef,
AnyApiFactory,
identityApiRef,
} from '@backstage/core-plugin-api';

import { GithubAuth } from '@backstage/core-app-api';
import { visitsApiRef, VisitsWebStorageApi } from '@backstage/plugin-home';

export const apis: AnyApiFactory[] = [
createApiFactory({
Expand All @@ -48,13 +50,17 @@ export const apis: AnyApiFactory[] = [
}),
createApiFactory({
api: graphQlBrowseApiRef,
deps: { errorApi: errorApiRef, githubAuthApi: githubAuthApiRef, discoveryApi: discoveryApiRef },
deps: {
errorApi: errorApiRef,
githubAuthApi: githubAuthApiRef,
discoveryApi: discoveryApiRef,
},
factory: ({ errorApi, githubAuthApi, discoveryApi }) =>
GraphQLEndpoints.from([
GraphQLEndpoints.create({
id: 'backstage',
title: 'GraphQL Backend',
url: discoveryApi.getBaseUrl('graphql')
url: discoveryApi.getBaseUrl('graphql'),
}),
GraphQLEndpoints.github({
id: 'github',
Expand All @@ -75,4 +81,13 @@ export const apis: AnyApiFactory[] = [
]),
}),
createApiFactory(costInsightsApiRef, new ExampleCostInsightsClient()),
createApiFactory({
api: visitsApiRef,
deps: {
identityApi: identityApiRef,
errorApi: errorApiRef,
},
factory: ({ identityApi, errorApi }) =>
VisitsWebStorageApi.create({ identityApi, errorApi }),
}),
];
4 changes: 3 additions & 1 deletion packages/app/src/components/Root/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import SearchIcon from '@material-ui/icons/Search';
import { appThemeApiRef, useApi } from '@backstage/core-plugin-api';
import { ApertureLogoFull } from './ApertureLogoFull';
import { ApertureLogoIcon } from './ApertureLogoIcon';
import CategoryIcon from '@material-ui/icons/Category';

const useSidebarLogoStyles = makeStyles<Theme, { themeId: string }>({
root: {
Expand Down Expand Up @@ -79,7 +80,8 @@ export const Root = ({ children }: PropsWithChildren<{}>) => (
</SidebarGroup>
<SidebarDivider />
<SidebarGroup label="Menu" icon={<MenuIcon />}>
<SidebarItem icon={HomeIcon} to="catalog" text="Home" />
<SidebarItem icon={HomeIcon} to="home" text="Home" />
<SidebarItem icon={CategoryIcon} to="/" text="Catalog" />
<SidebarItem icon={ExtensionIcon} to="api-docs" text="APIs" />
<SidebarItem icon={LibraryBooks} to="docs" text="Docs" />
<SidebarItem icon={LayersIcon} to="explore" text="Explore" />
Expand Down
79 changes: 79 additions & 0 deletions packages/app/src/components/home/CustomizableHomePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Page, Content } from '@backstage/core-components';
import {
HomePageCompanyLogo,
TemplateBackstageLogo,
HomePageStarredEntities,
HomePageToolkit,
CustomHomepageGrid,
HomePageRandomJoke,
HomePageTopVisited,
HomePageRecentlyVisited,
} from '@backstage/plugin-home';
import { HomePageSearchBar } from '@backstage/plugin-search';
import { Grid } from '@material-ui/core';
import React from 'react';
import { tools, useLogoStyles } from './shared';

const defaultConfig = [
{
component: 'HomePageSearchBar',
x: 0,
y: 0,
width: 24,
height: 2,
},
{
component: 'HomePageRecentlyVisited',
x: 0,
y: 1,
width: 5,
height: 4,
},
{
component: 'HomePageTopVisited',
x: 5,
y: 1,
width: 5,
height: 4,
},
{
component: 'HomePageStarredEntities',
x: 0,
y: 2,
width: 6,
height: 4,
},
{
component: 'HomePageToolkit',
x: 6,
y: 6,
width: 4,
height: 4,
},
];

export const CustomizableHomePage = () => {
const { svg, path, container } = useLogoStyles();

return (
<Page themeId="home">
<Content>
<Grid container justifyContent="center">
<HomePageCompanyLogo
className={container}
logo={<TemplateBackstageLogo classes={{ svg, path }} />}
/>
</Grid>

<CustomHomepageGrid config={defaultConfig}>
<HomePageSearchBar />
<HomePageRecentlyVisited />
<HomePageTopVisited />
<HomePageToolkit tools={tools} />
<HomePageStarredEntities />
<HomePageRandomJoke />
</CustomHomepageGrid>
</Content>
</Page>
);
};
74 changes: 74 additions & 0 deletions packages/app/src/components/home/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Page, Content } from '@backstage/core-components';
import {
HomePageCompanyLogo,
TemplateBackstageLogo,
HomePageStarredEntities,
HomePageToolkit,
HomePageTopVisited,
HomePageRecentlyVisited,
} from '@backstage/plugin-home';
import { HomePageSearchBar } from '@backstage/plugin-search';
import { SearchContextProvider } from '@backstage/plugin-search-react';
import { Grid, makeStyles } from '@material-ui/core';
import React from 'react';
import { tools, useLogoStyles } from './shared';

const useStyles = makeStyles(theme => ({
searchBarInput: {
maxWidth: '60vw',
margin: 'auto',
backgroundColor: theme.palette.background.paper,
borderRadius: '50px',
boxShadow: theme.shadows[1],
},
searchBarOutline: {
borderStyle: 'none',
},
}));

export const HomePage = () => {
const classes = useStyles();
const { svg, path, container } = useLogoStyles();

return (
<SearchContextProvider>
<Page themeId="home">
<Content>
<Grid container justifyContent="center" spacing={2}>
<HomePageCompanyLogo
className={container}
logo={<TemplateBackstageLogo classes={{ svg, path }} />}
/>
<Grid container item xs={12} justifyContent="center">
<HomePageSearchBar
InputProps={{
classes: {
root: classes.searchBarInput,
notchedOutline: classes.searchBarOutline,
},
}}
placeholder="Search"
/>
</Grid>
<Grid container item xs={12}>
<Grid item xs={12} md={6}>
<HomePageTopVisited />
</Grid>
<Grid item xs={12} md={6}>
<HomePageRecentlyVisited />
</Grid>
</Grid>
<Grid container item xs={12}>
<Grid item xs={7}>
<HomePageStarredEntities />
</Grid>
<Grid item xs={5}>
<HomePageToolkit tools={tools} />
</Grid>
</Grid>
</Grid>
</Content>
</Page>
</SearchContextProvider>
);
};
44 changes: 44 additions & 0 deletions packages/app/src/components/home/shared.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { TemplateBackstageLogoIcon } from '@backstage/plugin-home';
import { makeStyles } from '@material-ui/core/styles';
import React from 'react';

export const useLogoStyles = makeStyles(theme => ({
container: {
margin: theme.spacing(5, 0),
},
svg: {
width: 'auto',
height: 100,
},
path: {
fill: '#7df3e1',
},
}));

export const tools = [
{
url: 'https://backstage.io/docs',
label: 'Docs',
icon: <TemplateBackstageLogoIcon />,
},
{
url: 'https://github.com/backstage/backstage',
label: 'GitHub',
icon: <TemplateBackstageLogoIcon />,
},
{
url: 'https://github.com/backstage/backstage/blob/master/CONTRIBUTING.md',
label: 'Contributing',
icon: <TemplateBackstageLogoIcon />,
},
{
url: 'https://backstage.io/plugins',
label: 'Plugins Directory',
icon: <TemplateBackstageLogoIcon />,
},
{
url: 'https://github.com/backstage/backstage/issues/new/choose',
label: 'Submit New Issue',
icon: <TemplateBackstageLogoIcon />,
},
];
Loading

0 comments on commit fca3688

Please sign in to comment.