PluginDetailsBody.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { css, cx } from '@emotion/css';
  2. import React from 'react';
  3. import { AppPlugin, GrafanaTheme2, UrlQueryMap } from '@grafana/data';
  4. import { useStyles2 } from '@grafana/ui';
  5. import { VersionList } from '../components/VersionList';
  6. import { usePluginConfig } from '../hooks/usePluginConfig';
  7. import { CatalogPlugin, PluginTabIds } from '../types';
  8. import { AppConfigCtrlWrapper } from './AppConfigWrapper';
  9. import { PluginDashboards } from './PluginDashboards';
  10. type Props = {
  11. plugin: CatalogPlugin;
  12. queryParams: UrlQueryMap;
  13. pageId: string;
  14. };
  15. export function PluginDetailsBody({ plugin, queryParams, pageId }: Props): JSX.Element {
  16. const styles = useStyles2(getStyles);
  17. const { value: pluginConfig } = usePluginConfig(plugin);
  18. if (pageId === PluginTabIds.OVERVIEW) {
  19. return (
  20. <div
  21. className={cx(styles.readme, styles.container)}
  22. dangerouslySetInnerHTML={{
  23. __html: plugin.details?.readme ?? 'No plugin help or readme markdown file was found',
  24. }}
  25. />
  26. );
  27. }
  28. if (pageId === PluginTabIds.VERSIONS) {
  29. return (
  30. <div className={styles.container}>
  31. <VersionList versions={plugin.details?.versions} installedVersion={plugin.installedVersion} />
  32. </div>
  33. );
  34. }
  35. if (pageId === PluginTabIds.CONFIG && pluginConfig?.angularConfigCtrl) {
  36. return (
  37. <div className={styles.container}>
  38. <AppConfigCtrlWrapper app={pluginConfig as AppPlugin} />
  39. </div>
  40. );
  41. }
  42. if (pluginConfig?.configPages) {
  43. for (const configPage of pluginConfig.configPages) {
  44. if (pageId === configPage.id) {
  45. return (
  46. <div className={styles.container}>
  47. <configPage.body plugin={pluginConfig} query={queryParams} />
  48. </div>
  49. );
  50. }
  51. }
  52. }
  53. if (pageId === PluginTabIds.DASHBOARDS && pluginConfig) {
  54. return (
  55. <div className={styles.container}>
  56. <PluginDashboards plugin={pluginConfig?.meta} />
  57. </div>
  58. );
  59. }
  60. return (
  61. <div className={styles.container}>
  62. <p>Page not found.</p>
  63. </div>
  64. );
  65. }
  66. export const getStyles = (theme: GrafanaTheme2) => ({
  67. container: css`
  68. padding: ${theme.spacing(3, 4)};
  69. `,
  70. readme: css`
  71. & img {
  72. max-width: 100%;
  73. }
  74. h1,
  75. h2,
  76. h3 {
  77. margin-top: ${theme.spacing(3)};
  78. margin-bottom: ${theme.spacing(2)};
  79. }
  80. *:first-child {
  81. margin-top: 0;
  82. }
  83. li {
  84. margin-left: ${theme.spacing(2)};
  85. & > p {
  86. margin: ${theme.spacing()} 0;
  87. }
  88. }
  89. a {
  90. color: ${theme.colors.text.link};
  91. &:hover {
  92. color: ${theme.colors.text.link};
  93. text-decoration: underline;
  94. }
  95. }
  96. `,
  97. });