mirror of https://github.com/grafana/grafana
Previews: capability check (#44601)
* add SQL migrations * dashboard previews from sql: poc * added todos * refactor: use the same enums where possible * use useEffect, always return json * added todo * refactor + delete files after use * refactor + fix manual thumbnail upload * refactor: move all interactions with sqlStore to thumbnail repo * refactor: remove file operations in thumb crawler/service * refactor: fix dashboard_thumbs sql store * refactor: extracted thumbnail fetching/updating to a hook * refactor: store thumbnails in redux store * refactor: store thumbnails in redux store * refactor: private'd repo methods * removed redux storage, saving images as blobs * allow for configurable rendering timeouts * added 1) query for dashboards with stale thumbnails, 2) command for marking thumbnails as stale * use sql-based queue in crawler * ui for marking thumbnails as stale * replaced `stale` boolean prop with `state` enum * introduce rendering session * compilation errors * fix crawler stop button * rename thumbnail state frozen to locked * #44449: fix merge conflicts * #44449: remove thumb methods from `Store` interface * #44449: clean filepath, defer file closing * #44449: fix rendering.Theme cyclic import * #44449: linting * #44449: linting * #44449: mutex'd crawlerStatus access * #44449: added integration tests for `sqlstore.dashboard_thumbs` * #44449: added comments to explain the `ThumbnailState` enum * #44449: use os.ReadFile rather then os.Open * #44449: always enable dashboardPreviews feature during integration tests * #44449: add /previews/system-requirements API * #44449: remove sleep time, adjust number of threads * #44449: review fix: add `orgId` to `DashboardThumbnailMeta` * #44449: review fix: automatic parsing of thumbnailState * #44449: update returned json * #44449: UI changes - dashboard previews sytem req check * #44449: lint fixes * #44449: fix tests * #44449: typo * #44449: fix getSystemRequirements API: return 200 even if we plugin version is invalid * #44449: fix getSystemRequirements API: don't return SemverConstraint on error * #44449: fix getSystemRequirements API * #44449: fix previews sytem requirements text * #44449: add `doThumbnailsExist` to repo * #44449: remove redux api * #44449: add missing model * #44449: implement frontedsettings-driven capability check * #44449: simplify * #44449: revert test changes * #44449: add dummy setup settings * #44449: implicit typing over `FC<Props>` * #44449: refactor conditionals * #44449: replace `getText` with a react component * #44449: fix component interface * #44449: add onRemove to `PreviewsSystemRequirements` alert * #44449: add bottom/top margin to previewSystemRequirements modal * #44449: merge conflict fix * #44449: remove console.log Co-authored-by: Ryan McKinley <ryantxu@gmail.com> Co-authored-by: Alexander Emelin <frvzmb@gmail.com>pull/45482/head
parent
1554bffcb8
commit
6c76aa71e8
@ -0,0 +1,93 @@ |
||||
import { Alert, useStyles2 } from '@grafana/ui'; |
||||
import React from 'react'; |
||||
import { config } from '@grafana/runtime/src'; |
||||
import { css } from '@emotion/css'; |
||||
|
||||
export interface Props { |
||||
showPreviews?: boolean; |
||||
/** On click handler for alert button, mostly used for dismissing the alert */ |
||||
onRemove?: (event: React.MouseEvent) => void; |
||||
topSpacing?: number; |
||||
bottomSpacing?: number; |
||||
} |
||||
|
||||
const MessageLink = ({ text }: { text: string }) => ( |
||||
<a |
||||
href="https://grafana.com/grafana/plugins/grafana-image-renderer" |
||||
target="_blank" |
||||
rel="noopener noreferrer" |
||||
className="external-link" |
||||
> |
||||
{text} |
||||
</a> |
||||
); |
||||
|
||||
const Message = ({ requiredImageRendererPluginVersion }: { requiredImageRendererPluginVersion?: string }) => { |
||||
if (requiredImageRendererPluginVersion) { |
||||
return ( |
||||
<> |
||||
You must update the <MessageLink text="Grafana image renderer plugin" /> to version{' '} |
||||
{requiredImageRendererPluginVersion} to enable dashboard previews. Please contact your Grafana administrator to |
||||
update the plugin. |
||||
</> |
||||
); |
||||
} |
||||
|
||||
return ( |
||||
<> |
||||
You must install the <MessageLink text="Grafana image renderer plugin" /> to enable dashboard previews. Please |
||||
contact your Grafana administrator to install the plugin. |
||||
</> |
||||
); |
||||
}; |
||||
|
||||
export const PreviewsSystemRequirements = ({ showPreviews, onRemove, topSpacing, bottomSpacing }: Props) => { |
||||
const styles = useStyles2(getStyles); |
||||
|
||||
const previewsEnabled = config.featureToggles.dashboardPreviews; |
||||
const rendererAvailable = config.rendererAvailable; |
||||
|
||||
const { |
||||
systemRequirements: { met: systemRequirementsMet, requiredImageRendererPluginVersion }, |
||||
thumbnailsExist, |
||||
} = config.dashboardPreviews; |
||||
|
||||
const arePreviewsEnabled = previewsEnabled && showPreviews; |
||||
const areRequirementsMet = (rendererAvailable && systemRequirementsMet) || thumbnailsExist; |
||||
const shouldDisplayRequirements = arePreviewsEnabled && !areRequirementsMet; |
||||
|
||||
const title = requiredImageRendererPluginVersion |
||||
? 'Image renderer plugin needs to be updated' |
||||
: 'Image renderer plugin not installed'; |
||||
|
||||
return ( |
||||
<> |
||||
{shouldDisplayRequirements && ( |
||||
<div className={styles.wrapper}> |
||||
<Alert |
||||
className={styles.alert} |
||||
topSpacing={topSpacing} |
||||
bottomSpacing={bottomSpacing} |
||||
severity="info" |
||||
title={title} |
||||
onRemove={onRemove} |
||||
> |
||||
<Message requiredImageRendererPluginVersion={requiredImageRendererPluginVersion} /> |
||||
</Alert> |
||||
</div> |
||||
)} |
||||
</> |
||||
); |
||||
}; |
||||
|
||||
const getStyles = () => { |
||||
return { |
||||
wrapper: css` |
||||
display: flex; |
||||
justify-content: center; |
||||
`,
|
||||
alert: css` |
||||
max-width: 800px; |
||||
`,
|
||||
}; |
||||
}; |
Loading…
Reference in new issue