-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for links to tech-insight checks
This includes UI components to render a popup menu with these links, by default on the result icon in the scorecards view. Signed-off-by: Gustaf Räntilä <g.rantila@gmail.com>
- Loading branch information
Showing
19 changed files
with
444 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@backstage-community/plugin-tech-insights': patch | ||
--- | ||
|
||
Added support for links for checks. Static links are defined in the backend for each check. Dynamic links (based on the entity, e.g. to go to github repos, sonarqube projects, etc) are defined with functions in the frontend, when registering the tech-insights API. Two new components are added, TechInsightsCheckIcon and TechInsightsLinksMenu. The former to wrap a result icon with a popup menu with links, the second is the component to show the popup with links (which can be arbitrarily componsed in other UI views). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@backstage-community/plugin-tech-insights-backend-module-jsonfc': patch | ||
'@backstage-community/plugin-tech-insights-common': patch | ||
'@backstage-community/plugin-tech-insights-node': patch | ||
--- | ||
|
||
Added links property for checks, to allow the UI to render links for users to click and get more information about individual checks, what they mean, how to adhere to them, etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...es/tech-insights/plugins/tech-insights/src/components/ResultCheckIcon/ResultCheckIcon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright 2024 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, { | ||
ComponentProps, | ||
ComponentType, | ||
MouseEventHandler, | ||
ReactNode, | ||
useState, | ||
} from 'react'; | ||
|
||
import { useApi } from '@backstage/core-plugin-api'; | ||
import { CheckResult } from '@backstage-community/plugin-tech-insights-common'; | ||
import { Entity } from '@backstage/catalog-model'; | ||
|
||
import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import Alert from '@material-ui/lab/Alert'; | ||
|
||
import { techInsightsApiRef } from '../../api'; | ||
import { CheckResultRenderer } from '../CheckResultRenderer'; | ||
import { ResultLinksMenu, ResultLinksMenuInfo } from '../ResultLinksMenu'; | ||
|
||
type BaseComponent = ComponentType<{ onClick?: MouseEventHandler | undefined }>; | ||
|
||
/** | ||
* ResultCheckIcon props | ||
* | ||
* The only necessary prop is {@link result}, but if {@link entity} is provided, | ||
* the popup menu with links will also include links specifically for this | ||
* entity. | ||
* | ||
* {@link disableLinksMenu} will disable the popup menu. | ||
* | ||
* {@link checkResultRenderer} can optionally be provided, with a small | ||
* performance improvement, if it is already cashed upstream. | ||
* | ||
* {@link component} and {@link componentProps} can be specified to override the | ||
* default `ListItemSecondaryAction` component, e.g. with a `div` (and | ||
* optionally its props). | ||
* | ||
* {@link missingRendererComponent} can be overridden with a component to | ||
* display when no icon renderer was found for this result. | ||
* | ||
* @public | ||
*/ | ||
export interface ResultCheckIconProps<C extends BaseComponent> { | ||
result: CheckResult; | ||
entity?: Entity; | ||
checkResultRenderer?: CheckResultRenderer; | ||
disableLinksMenu?: boolean; | ||
component?: C; | ||
componentProps?: Omit<ComponentProps<C>, 'onClick'>; | ||
missingRendererComponent?: ReactNode; | ||
} | ||
|
||
export const ResultCheckIcon = < | ||
C extends BaseComponent = typeof ListItemSecondaryAction, | ||
>( | ||
props: ResultCheckIconProps<C>, | ||
) => { | ||
const { | ||
result, | ||
entity, | ||
disableLinksMenu, | ||
componentProps, | ||
missingRendererComponent = <Alert severity="error">Unknown type.</Alert>, | ||
} = props; | ||
|
||
const Component = props.component ?? ListItemSecondaryAction; | ||
|
||
const api = useApi(techInsightsApiRef); | ||
|
||
const checkResultRenderer = | ||
props.checkResultRenderer ?? | ||
api.getCheckResultRenderers([result.check.type])[0]; | ||
|
||
const [menu, setMenu] = useState<ResultLinksMenuInfo | undefined>(); | ||
|
||
const iconComponent = checkResultRenderer?.component(result); | ||
|
||
const wrapActions = (component: React.ReactElement): ReactNode => { | ||
if (!menu) { | ||
return component; | ||
} | ||
return ( | ||
<Component | ||
{...componentProps} | ||
onClick={event => menu?.open(event.currentTarget)} | ||
> | ||
<IconButton edge="end" aria-label="comments"> | ||
{component} | ||
</IconButton> | ||
</Component> | ||
); | ||
}; | ||
|
||
return ( | ||
<> | ||
{!disableLinksMenu && ( | ||
<ResultLinksMenu result={result} entity={entity} setMenu={setMenu} /> | ||
)} | ||
{wrapActions(iconComponent ?? missingRendererComponent)} | ||
</> | ||
); | ||
}; |
18 changes: 18 additions & 0 deletions
18
workspaces/tech-insights/plugins/tech-insights/src/components/ResultCheckIcon/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2024 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 type { ResultCheckIconProps } from './ResultCheckIcon'; | ||
export { ResultCheckIcon } from './ResultCheckIcon'; |
Oops, something went wrong.