mirror of https://github.com/grafana/grafana
Connections: Show a "No access" modal if the user has no permissions (#61397)
* feat: add a new modal for displaying no-access info
* feat(CardGrid): add an onClick handler for items
* feat: open a no-access modal when clicking on a connection in the catlog
* feat: update permissions
Open a "No access" modal when the user clicks a connection type but has no permissions creating a datasource out of it
* test: add tests for opening the No Access modal
* test: fix the user permissions in tests
* Wip
* Revert "Wip"
This reverts commit 7f080c7f77.
pull/61684/head
parent
58a86133af
commit
4ef82dc73f
@ -0,0 +1,117 @@ |
|||||||
|
import { css } from '@emotion/css'; |
||||||
|
import React from 'react'; |
||||||
|
|
||||||
|
import { GrafanaTheme2 } from '@grafana/data'; |
||||||
|
import { useStyles2, Modal, Icon, Button } from '@grafana/ui'; |
||||||
|
|
||||||
|
import { type CardGridItem } from '../CardGrid'; |
||||||
|
|
||||||
|
const getStyles = (theme: GrafanaTheme2) => ({ |
||||||
|
modal: css` |
||||||
|
width: 500px; |
||||||
|
`,
|
||||||
|
modalContent: css` |
||||||
|
overflow: visible; |
||||||
|
color: ${theme.colors.text.secondary}; |
||||||
|
|
||||||
|
a { |
||||||
|
color: ${theme.colors.text.link}; |
||||||
|
} |
||||||
|
`,
|
||||||
|
description: css` |
||||||
|
margin-bottom: ${theme.spacing.gridSize * 2}px; |
||||||
|
`,
|
||||||
|
bottomSection: css` |
||||||
|
display: flex; |
||||||
|
border-top: 1px solid ${theme.colors.border.weak}; |
||||||
|
padding-top: ${theme.spacing.gridSize * 3}px; |
||||||
|
margin-top: ${theme.spacing.gridSize * 3}px; |
||||||
|
`,
|
||||||
|
actionsSection: css` |
||||||
|
display: flex; |
||||||
|
justify-content: end; |
||||||
|
margin-top: ${theme.spacing.gridSize * 3}px; |
||||||
|
`,
|
||||||
|
warningIcon: css` |
||||||
|
color: ${theme.colors.warning.main}; |
||||||
|
padding-right: ${theme.spacing.gridSize}px; |
||||||
|
margin-top: ${theme.spacing.gridSize / 4}px; |
||||||
|
`,
|
||||||
|
header: css` |
||||||
|
display: flex; |
||||||
|
align-items: center; |
||||||
|
`,
|
||||||
|
headerTitle: css` |
||||||
|
margin: 0; |
||||||
|
`,
|
||||||
|
headerLogo: css` |
||||||
|
margin-right: ${theme.spacing.gridSize * 2}px; |
||||||
|
width: 32px; |
||||||
|
height: 32px; |
||||||
|
`,
|
||||||
|
}); |
||||||
|
|
||||||
|
export type NoAccessModalProps = { |
||||||
|
item: CardGridItem; |
||||||
|
isOpen: boolean; |
||||||
|
onDismiss: () => void; |
||||||
|
}; |
||||||
|
|
||||||
|
export function NoAccessModal({ item, isOpen, onDismiss }: NoAccessModalProps) { |
||||||
|
const styles = useStyles2(getStyles); |
||||||
|
|
||||||
|
return ( |
||||||
|
<Modal |
||||||
|
className={styles.modal} |
||||||
|
contentClassName={styles.modalContent} |
||||||
|
title={<NoAccessModalHeader item={item} />} |
||||||
|
isOpen={isOpen} |
||||||
|
onDismiss={onDismiss} |
||||||
|
> |
||||||
|
<div> |
||||||
|
<div> |
||||||
|
{item.description && <div className={styles.description}>{item.description}</div>} |
||||||
|
<div> |
||||||
|
Links |
||||||
|
<br /> |
||||||
|
<a |
||||||
|
href={`https://grafana.com/grafana/plugins/${item.id}`} |
||||||
|
title={`${item.name} on Grafana.com`} |
||||||
|
target="_blank" |
||||||
|
rel="noopener noreferrer" |
||||||
|
> |
||||||
|
{item.name} |
||||||
|
</a> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div className={styles.bottomSection}> |
||||||
|
<div className={styles.warningIcon}> |
||||||
|
<Icon name="exclamation-triangle" /> |
||||||
|
</div> |
||||||
|
<div> |
||||||
|
<p> |
||||||
|
Editors cannot add new connections. You may check to see if it is already configured in{' '} |
||||||
|
<a href="/connections/your-connections">Your Connections</a>. |
||||||
|
</p> |
||||||
|
<p>To add a new connection, contact your Grafana admin.</p> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div className={styles.actionsSection}> |
||||||
|
<Button onClick={onDismiss}>Okay</Button> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</Modal> |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
export function NoAccessModalHeader({ item }: { item: CardGridItem }) { |
||||||
|
const styles = useStyles2(getStyles); |
||||||
|
return ( |
||||||
|
<div> |
||||||
|
<div className={styles.header}> |
||||||
|
{item.logo && <img className={styles.headerLogo} src={item.logo} alt={`logo of ${item.name}`} />} |
||||||
|
<h4 className={styles.headerTitle}>{item.name}</h4> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
); |
||||||
|
} |
||||||
@ -0,0 +1 @@ |
|||||||
|
export * from './NoAccessModal'; |
||||||
Loading…
Reference in new issue