-
Notifications
You must be signed in to change notification settings - Fork 468
feat(github-pull-requests-board): add composable home page component for pull request board #3997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@backstage-community/plugin-github-pull-requests-board': minor | ||
--- | ||
|
||
Adds a composable home page component to view pull requests for a team's repositories | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,8 @@ | |
"@backstage/frontend-plugin-api": "^0.10.0", | ||
"@backstage/integration": "^1.16.2", | ||
"@backstage/plugin-catalog-react": "^1.16.0", | ||
"@backstage/plugin-home": "^0.8.7", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can remove this line as we don't use anything from this package, there's a comment about this in the |
||
"@backstage/plugin-home-react": "^0.1.25", | ||
Comment on lines
+65
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 Should we generate a different package for this component? something like maybe the home is quite common, but not sure if is better to not add possible unneeded dependencies There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what you try to ask here @Sarabadu? They need to import this package as it's being used in code, in the |
||
"@material-ui/core": "^4.12.2", | ||
"@material-ui/icons": "^4.9.1", | ||
"@material-ui/lab": "4.0.0-alpha.61", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2025 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 React from 'react'; | ||
import { useTeamPullRequestsContext } from './Context'; | ||
import { EntityTeamPullRequestsCard } from '../EntityTeamPullRequestsCard'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import { EntityProvider } from '@backstage/plugin-catalog-react'; | ||
|
||
export const Content = () => { | ||
const { entity } = useTeamPullRequestsContext(); | ||
|
||
if (!entity) { | ||
return ( | ||
<Typography variant="body1"> | ||
Please select a team to view pull requests for | ||
</Typography> | ||
); | ||
} | ||
|
||
return ( | ||
<EntityProvider entity={entity}> | ||
<EntityTeamPullRequestsCard /> | ||
</EntityProvider> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright 2025 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 type { GroupEntity } from '@backstage/catalog-model'; | ||
import { useApi } from '@backstage/frontend-plugin-api'; | ||
import { | ||
catalogApiRef, | ||
CATALOG_FILTER_EXISTS, | ||
} from '@backstage/plugin-catalog-react'; | ||
import React, { | ||
createContext, | ||
useCallback, | ||
useContext, | ||
useEffect, | ||
useState, | ||
} from 'react'; | ||
|
||
type TeamPullRequestsContextValue = { | ||
loading: boolean; | ||
handleChangeType: Function; | ||
entity: GroupEntity | null; | ||
teams: GroupEntity[]; | ||
}; | ||
|
||
const TEAM_PULL_REQUEST_STORAGE_KEY = '/home/team-pull-requests-card'; | ||
|
||
const Context = createContext<TeamPullRequestsContextValue | undefined>( | ||
undefined, | ||
); | ||
|
||
export const ContextProvider = (props: { children: JSX.Element }) => { | ||
const { children } = props; | ||
|
||
const [loading, setLoading] = useState(false); | ||
const [entity, setEntity] = useState<GroupEntity | null>(() => { | ||
const stored = localStorage.getItem(TEAM_PULL_REQUEST_STORAGE_KEY); | ||
return stored ? JSON.parse(stored) : null; | ||
}); | ||
const [teams, setTeams] = useState<GroupEntity[]>([]); | ||
|
||
const catalogApi = useApi(catalogApiRef); | ||
|
||
const handleChangeType = (group: GroupEntity | null) => { | ||
setEntity(group); | ||
}; | ||
|
||
const fetchTeams = useCallback(async () => { | ||
const { items: githubTeams } = await catalogApi.getEntities({ | ||
filter: { | ||
kind: 'Group', | ||
'metadata.annotations.github.com/team-slug': CATALOG_FILTER_EXISTS, | ||
}, | ||
}); | ||
setTeams(githubTeams as GroupEntity[]); | ||
}, [catalogApi]); | ||
|
||
useEffect(() => { | ||
setLoading(true); | ||
fetchTeams(); | ||
setLoading(false); | ||
}, [fetchTeams]); | ||
|
||
// Persist entity to localStorage whenever it changes | ||
useEffect(() => { | ||
if (entity) { | ||
localStorage.setItem( | ||
TEAM_PULL_REQUEST_STORAGE_KEY, | ||
JSON.stringify(entity), | ||
); | ||
} else { | ||
localStorage.removeItem(TEAM_PULL_REQUEST_STORAGE_KEY); | ||
} | ||
}, [entity]); | ||
|
||
return ( | ||
<Context.Provider | ||
value={{ | ||
handleChangeType, | ||
loading, | ||
entity, | ||
teams, | ||
}} | ||
> | ||
{children} | ||
</Context.Provider> | ||
); | ||
}; | ||
|
||
export const useTeamPullRequestsContext = () => { | ||
const context = useContext(Context); | ||
if (!context) { | ||
throw new Error( | ||
'useTeamPullRequestsContext must be used within a ContextProvider', | ||
); | ||
} | ||
return context; | ||
}; | ||
|
||
export default ContextProvider; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2025 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 React from 'react'; | ||
import { useTeamPullRequestsContext } from './Context'; | ||
import FormControl from '@material-ui/core/FormControl'; | ||
import FormLabel from '@material-ui/core/FormLabel'; | ||
import Autocomplete from '@material-ui/lab/Autocomplete'; | ||
import type { GroupEntity } from '@backstage/catalog-model'; | ||
import TextField from '@material-ui/core/TextField'; | ||
|
||
export const Settings = () => { | ||
const { handleChangeType, teams, entity } = useTeamPullRequestsContext(); | ||
|
||
return ( | ||
<FormControl component="fieldset"> | ||
<FormLabel component="legend"> | ||
Select Team to view pull requests for | ||
</FormLabel> | ||
<Autocomplete | ||
options={teams || []} | ||
getOptionLabel={option => | ||
`${option.metadata?.annotations?.['github.com/team-slug']}` | ||
} | ||
onChange={(_event, value) => { | ||
handleChangeType(value as GroupEntity); | ||
}} | ||
value={entity} | ||
renderInput={params => <TextField {...params} />} | ||
/> | ||
</FormControl> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2025 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. | ||
*/ | ||
export * from './Content'; | ||
export * from './Context'; | ||
export * from './Settings'; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -19,6 +19,8 @@ import { | |||||
createRoutableExtension, | ||||||
} from '@backstage/core-plugin-api'; | ||||||
import { rootRouteRef } from './routes'; | ||||||
import { createCardExtension } from '@backstage/plugin-home-react'; | ||||||
import { homePlugin } from '@backstage/plugin-home'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this line |
||||||
|
||||||
const githubPullRequestsBoardPlugin = createPlugin({ | ||||||
id: 'github-pull-requests-board', | ||||||
|
@@ -52,3 +54,17 @@ export const EntityTeamPullRequestsContent = | |||||
mountPoint: rootRouteRef, | ||||||
}), | ||||||
); | ||||||
|
||||||
/** @public */ | ||||||
export const HomePageTeamPullRequestsCard = homePlugin.provide( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
You don't set this on the |
||||||
createCardExtension({ | ||||||
name: 'HomePageTeamPullRequestsCard', | ||||||
title: 'GitHub Team Pull Requests', | ||||||
components: () => import('./components/HomePageTeamPullRequestsCard'), | ||||||
description: 'Display GitHub pull requests for a team', | ||||||
layout: { | ||||||
height: { minRows: 4 }, | ||||||
width: { minColumns: 12 }, | ||||||
}, | ||||||
}), | ||||||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would de nice to include some lines on the readme on "how to use this home page component"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with this, can you please add some details about this new component to the
README
- https://github.com/backstage/community-plugins/blob/main/workspaces/github-pull-requests-board/plugins/github-pull-requests-board/README.md