2022-09-03 06:38:35 +08:00
|
|
|
import { css } from '@emotion/css';
|
2024-06-25 19:43:47 +08:00
|
|
|
import { useMemo, useEffect } from 'react';
|
2022-09-03 06:38:35 +08:00
|
|
|
import AutoSizer from 'react-virtualized-auto-sizer';
|
|
|
|
|
2024-10-04 02:38:18 +08:00
|
|
|
import { PanelPlugin, GrafanaTheme2 } from '@grafana/data';
|
2025-06-12 17:03:52 +08:00
|
|
|
import { Trans, t } from '@grafana/i18n';
|
2022-09-15 03:54:09 +08:00
|
|
|
import { config } from '@grafana/runtime';
|
2022-09-03 06:38:35 +08:00
|
|
|
import {
|
|
|
|
Drawer,
|
|
|
|
Tab,
|
|
|
|
TabsBar,
|
|
|
|
CodeEditor,
|
|
|
|
useStyles2,
|
|
|
|
Field,
|
|
|
|
InlineSwitch,
|
|
|
|
Button,
|
|
|
|
Spinner,
|
|
|
|
Alert,
|
|
|
|
Select,
|
2022-09-15 03:54:09 +08:00
|
|
|
ClipboardButton,
|
2023-11-07 00:15:52 +08:00
|
|
|
Stack,
|
2025-04-15 17:05:03 +08:00
|
|
|
TextLink,
|
2022-09-03 06:38:35 +08:00
|
|
|
} from '@grafana/ui';
|
2022-09-15 03:54:09 +08:00
|
|
|
import { contextSrv } from 'app/core/services/context_srv';
|
2024-12-06 23:01:51 +08:00
|
|
|
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
2025-07-09 12:15:33 +08:00
|
|
|
import { AccessControlAction } from 'app/types/accessControl';
|
2022-09-03 06:38:35 +08:00
|
|
|
|
2022-09-15 03:54:09 +08:00
|
|
|
import { ShowMessage, SnapshotTab, SupportSnapshotService } from './SupportSnapshotService';
|
2022-09-03 06:38:35 +08:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
panel: PanelModel;
|
|
|
|
plugin?: PanelPlugin | null;
|
|
|
|
onClose: () => void;
|
|
|
|
}
|
|
|
|
|
2022-09-16 23:51:14 +08:00
|
|
|
export function HelpWizard({ panel, plugin, onClose }: Props) {
|
2022-09-03 06:38:35 +08:00
|
|
|
const styles = useStyles2(getStyles);
|
2022-09-15 03:54:09 +08:00
|
|
|
const service = useMemo(() => new SupportSnapshotService(panel), [panel]);
|
|
|
|
|
|
|
|
const {
|
|
|
|
currentTab,
|
|
|
|
loading,
|
|
|
|
error,
|
|
|
|
options,
|
|
|
|
showMessage,
|
|
|
|
snapshotSize,
|
|
|
|
markdownText,
|
|
|
|
snapshotText,
|
|
|
|
randomize,
|
|
|
|
panelTitle,
|
2023-04-18 14:45:14 +08:00
|
|
|
scene,
|
2022-09-15 03:54:09 +08:00
|
|
|
} = service.useState();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
service.buildDebugDashboard();
|
|
|
|
}, [service, plugin, randomize]);
|
|
|
|
|
2022-09-03 06:38:35 +08:00
|
|
|
if (!plugin) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const tabs = [
|
2025-05-29 04:14:43 +08:00
|
|
|
{ label: t('dashboard.help-wizard.tabs.label.snapshot', 'Snapshot'), value: SnapshotTab.Support },
|
|
|
|
{ label: t('dashboard.help-wizard.tabs.label.data', 'Data'), value: SnapshotTab.Data },
|
2022-09-03 06:38:35 +08:00
|
|
|
];
|
|
|
|
|
2023-01-31 23:12:20 +08:00
|
|
|
const hasSupportBundleAccess =
|
2023-09-06 23:07:49 +08:00
|
|
|
config.supportBundlesEnabled && contextSrv.hasPermission(AccessControlAction.ActionSupportBundlesCreate);
|
2023-01-31 23:12:20 +08:00
|
|
|
|
2022-09-03 06:38:35 +08:00
|
|
|
return (
|
|
|
|
<Drawer
|
2025-04-15 17:05:03 +08:00
|
|
|
title={t('dashboard.help-wizard.title-get-help-with-this-panel', 'Get help with this panel')}
|
2023-05-05 17:31:02 +08:00
|
|
|
size="lg"
|
2022-09-03 06:38:35 +08:00
|
|
|
onClose={onClose}
|
|
|
|
subtitle={
|
2022-09-15 03:54:09 +08:00
|
|
|
<Stack direction="column" gap={1}>
|
2022-09-16 23:51:14 +08:00
|
|
|
<Stack direction="row" gap={1}>
|
2025-04-15 17:05:03 +08:00
|
|
|
<TextLink href="https://grafana.com/docs/grafana/latest/troubleshooting/" external>
|
|
|
|
<Trans i18nKey="dashboard.help-wizard.troubleshooting-docs">Troubleshooting docs</Trans>
|
|
|
|
</TextLink>
|
2022-09-16 23:51:14 +08:00
|
|
|
</Stack>
|
2022-09-15 03:54:09 +08:00
|
|
|
<span className="muted">
|
2024-10-04 02:38:18 +08:00
|
|
|
<Trans i18nKey="help-wizard.troubleshooting-help">
|
|
|
|
To request troubleshooting help, send a snapshot of this panel to Grafana Labs Technical Support. The
|
|
|
|
snapshot contains query response data and panel settings.
|
|
|
|
</Trans>
|
2022-09-15 03:54:09 +08:00
|
|
|
</span>
|
2023-01-31 23:12:20 +08:00
|
|
|
{hasSupportBundleAccess && (
|
|
|
|
<span className="muted">
|
2024-10-04 02:38:18 +08:00
|
|
|
<Trans i18nKey="help-wizard.support-bundle">
|
|
|
|
You can also retrieve a support bundle containing information concerning your Grafana instance and
|
2025-08-06 23:04:03 +08:00
|
|
|
configured datasources in the <TextLink href="/support-bundles">support bundles section</TextLink>.
|
2024-10-04 02:38:18 +08:00
|
|
|
</Trans>
|
2023-01-31 23:12:20 +08:00
|
|
|
</span>
|
|
|
|
)}
|
2022-09-15 03:54:09 +08:00
|
|
|
</Stack>
|
2022-09-03 06:38:35 +08:00
|
|
|
}
|
|
|
|
tabs={
|
|
|
|
<TabsBar>
|
2022-09-15 03:54:09 +08:00
|
|
|
{tabs.map((t, index) => (
|
|
|
|
<Tab
|
|
|
|
key={`${t.value}-${index}`}
|
|
|
|
label={t.label}
|
|
|
|
active={t.value === currentTab}
|
|
|
|
onChangeTab={() => service.onCurrentTabChange(t.value!)}
|
|
|
|
/>
|
|
|
|
))}
|
2022-09-03 06:38:35 +08:00
|
|
|
</TabsBar>
|
|
|
|
}
|
|
|
|
>
|
2022-09-15 03:54:09 +08:00
|
|
|
{loading && <Spinner />}
|
|
|
|
{error && <Alert title={error.title}>{error.message}</Alert>}
|
2022-09-03 06:38:35 +08:00
|
|
|
|
2022-09-15 03:54:09 +08:00
|
|
|
{currentTab === SnapshotTab.Data && (
|
2022-09-03 06:38:35 +08:00
|
|
|
<div className={styles.code}>
|
|
|
|
<div className={styles.opts}>
|
2025-04-03 16:26:24 +08:00
|
|
|
<Field label={t('dashboard.help-wizard.label-template', 'Template')} className={styles.field}>
|
2022-09-15 03:54:09 +08:00
|
|
|
<Select options={options} value={showMessage} onChange={service.onShowMessageChange} />
|
2022-09-03 06:38:35 +08:00
|
|
|
</Field>
|
|
|
|
|
2022-09-15 03:54:09 +08:00
|
|
|
{showMessage === ShowMessage.GithubComment ? (
|
|
|
|
<ClipboardButton icon="copy" getText={service.onGetMarkdownForClipboard}>
|
2025-04-03 16:26:24 +08:00
|
|
|
<Trans i18nKey="dashboard.help-wizard.copy-to-clipboard">Copy to clipboard</Trans>
|
2022-09-15 03:54:09 +08:00
|
|
|
</ClipboardButton>
|
2022-09-03 06:38:35 +08:00
|
|
|
) : (
|
2022-09-15 03:54:09 +08:00
|
|
|
<Button icon="download-alt" onClick={service.onDownloadDashboard}>
|
2025-04-15 17:05:03 +08:00
|
|
|
<Trans i18nKey="dashboard.help-wizard.download-snapshot">Download ({{ snapshotSize }})</Trans>
|
2022-09-03 06:38:35 +08:00
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<AutoSizer disableWidth>
|
|
|
|
{({ height }) => (
|
|
|
|
<CodeEditor
|
|
|
|
width="100%"
|
|
|
|
height={height}
|
2022-09-15 03:54:09 +08:00
|
|
|
language={showMessage === ShowMessage.GithubComment ? 'markdown' : 'json'}
|
2022-09-03 06:38:35 +08:00
|
|
|
showLineNumbers={true}
|
|
|
|
showMiniMap={true}
|
2022-09-15 03:54:09 +08:00
|
|
|
value={showMessage === ShowMessage.GithubComment ? markdownText : snapshotText}
|
2022-09-03 06:38:35 +08:00
|
|
|
readOnly={false}
|
2022-09-15 03:54:09 +08:00
|
|
|
onBlur={service.onSetSnapshotText}
|
2022-09-03 06:38:35 +08:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</AutoSizer>
|
|
|
|
</div>
|
2022-09-15 03:54:09 +08:00
|
|
|
)}
|
|
|
|
{currentTab === SnapshotTab.Support && (
|
2022-09-09 02:20:56 +08:00
|
|
|
<>
|
2022-09-03 06:38:35 +08:00
|
|
|
<Field
|
2025-04-03 16:26:24 +08:00
|
|
|
label={t('dashboard.help-wizard.label-obfuscate-data', 'Obfuscate data')}
|
2025-04-15 17:05:03 +08:00
|
|
|
description={t(
|
|
|
|
'dashboard.help-wizard.description-obfuscate-data',
|
|
|
|
'Modify the original data to hide sensitve information. Note the lengths will stay the same, and duplicate values will be equal.'
|
|
|
|
)}
|
2022-09-03 06:38:35 +08:00
|
|
|
>
|
2024-10-04 02:38:18 +08:00
|
|
|
<Stack direction="row" gap={1}>
|
2022-09-15 03:54:09 +08:00
|
|
|
<InlineSwitch
|
2025-04-03 16:26:24 +08:00
|
|
|
label={t('dashboard.help-wizard.randomize-labels-label-labels', 'Labels')}
|
2022-09-15 03:54:09 +08:00
|
|
|
id="randomize-labels"
|
|
|
|
showLabel={true}
|
|
|
|
value={Boolean(randomize.labels)}
|
|
|
|
onChange={() => service.onToggleRandomize('labels')}
|
|
|
|
/>
|
|
|
|
<InlineSwitch
|
2025-04-03 16:26:24 +08:00
|
|
|
label={t('dashboard.help-wizard.randomize-field-names-label-field-names', 'Field names')}
|
2022-09-15 03:54:09 +08:00
|
|
|
id="randomize-field-names"
|
|
|
|
showLabel={true}
|
|
|
|
value={Boolean(randomize.names)}
|
|
|
|
onChange={() => service.onToggleRandomize('names')}
|
|
|
|
/>
|
|
|
|
<InlineSwitch
|
2025-04-03 16:26:24 +08:00
|
|
|
label={t('dashboard.help-wizard.randomize-string-values-label-string-values', 'String values')}
|
2022-09-15 03:54:09 +08:00
|
|
|
id="randomize-string-values"
|
|
|
|
showLabel={true}
|
|
|
|
value={Boolean(randomize.values)}
|
|
|
|
onChange={() => service.onToggleRandomize('values')}
|
|
|
|
/>
|
2024-10-04 02:38:18 +08:00
|
|
|
</Stack>
|
2022-09-15 03:54:09 +08:00
|
|
|
</Field>
|
|
|
|
|
2025-04-03 16:26:24 +08:00
|
|
|
<Field
|
|
|
|
label={t('dashboard.help-wizard.label-support-snapshot', 'Support snapshot')}
|
2025-04-16 16:25:18 +08:00
|
|
|
description={t('dashboard.help-wizard.description-support-snapshot', 'Panel: {{panelTitle}}', {
|
|
|
|
panelTitle,
|
|
|
|
})}
|
2025-04-03 16:26:24 +08:00
|
|
|
>
|
2022-09-15 03:54:09 +08:00
|
|
|
<Stack>
|
|
|
|
<Button icon="download-alt" onClick={service.onDownloadDashboard}>
|
2025-04-15 17:05:03 +08:00
|
|
|
<Trans i18nKey="help-wizard.download-snapshot">Download snapshot ({{ snapshotSize }})</Trans>
|
2022-09-15 03:54:09 +08:00
|
|
|
</Button>
|
|
|
|
<ClipboardButton
|
|
|
|
icon="github"
|
|
|
|
getText={service.onGetMarkdownForClipboard}
|
2025-04-03 16:26:24 +08:00
|
|
|
title={t(
|
|
|
|
'dashboard.help-wizard.title-complete-git-hub-comment-clipboard',
|
|
|
|
'Copy a complete GitHub comment to the clipboard'
|
|
|
|
)}
|
2022-09-15 03:54:09 +08:00
|
|
|
>
|
2024-10-04 02:38:18 +08:00
|
|
|
<Trans i18nKey="help-wizard.github-comment">Copy Github comment</Trans>
|
2022-09-15 03:54:09 +08:00
|
|
|
</ClipboardButton>
|
|
|
|
</Stack>
|
2022-09-03 06:38:35 +08:00
|
|
|
</Field>
|
|
|
|
|
2022-09-09 02:20:56 +08:00
|
|
|
<AutoSizer disableWidth>
|
|
|
|
{({ height }) => (
|
2023-04-18 14:45:14 +08:00
|
|
|
<div style={{ height, overflow: 'auto' }}>{scene && <scene.Component model={scene} />}</div>
|
2022-09-09 02:20:56 +08:00
|
|
|
)}
|
|
|
|
</AutoSizer>
|
|
|
|
</>
|
2022-09-03 06:38:35 +08:00
|
|
|
)}
|
|
|
|
</Drawer>
|
|
|
|
);
|
2022-09-10 05:35:52 +08:00
|
|
|
}
|
2022-09-03 06:38:35 +08:00
|
|
|
|
|
|
|
const getStyles = (theme: GrafanaTheme2) => ({
|
2024-04-26 03:18:02 +08:00
|
|
|
code: css({
|
|
|
|
flexGrow: 1,
|
|
|
|
height: '100%',
|
|
|
|
overflow: 'scroll',
|
|
|
|
}),
|
|
|
|
field: css({
|
|
|
|
width: '100%',
|
|
|
|
}),
|
|
|
|
opts: css({
|
|
|
|
display: 'flex',
|
|
|
|
width: '100%',
|
|
|
|
flexGrow: 0,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'flex-end',
|
|
|
|
button: {
|
|
|
|
marginLeft: '8px',
|
|
|
|
},
|
|
|
|
}),
|
2022-09-03 06:38:35 +08:00
|
|
|
});
|