CloudAdminPage.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { css } from '@emotion/css';
  2. import React, { useEffect, useState } from 'react';
  3. import { GrafanaTheme } from '@grafana/data';
  4. import { getBackendSrv } from '@grafana/runtime';
  5. import { useStyles } from '@grafana/ui';
  6. import Page from 'app/core/components/Page/Page';
  7. import { useNavModel } from 'app/core/hooks/useNavModel';
  8. import { GrafanaCloudBackend } from './types';
  9. export default function CloudAdminPage() {
  10. const navModel = useNavModel('live-cloud');
  11. const [cloud, setCloud] = useState<GrafanaCloudBackend[]>([]);
  12. const [error, setError] = useState<string>();
  13. const styles = useStyles(getStyles);
  14. useEffect(() => {
  15. getBackendSrv()
  16. .get(`api/live/write-configs`)
  17. .then((data) => {
  18. setCloud(data.writeConfigs);
  19. })
  20. .catch((e) => {
  21. if (e.data) {
  22. setError(JSON.stringify(e.data, null, 2));
  23. }
  24. });
  25. }, []);
  26. return (
  27. <Page navModel={navModel}>
  28. <Page.Contents>
  29. {error && <pre>{error}</pre>}
  30. {!cloud && <>Loading cloud definitions</>}
  31. {cloud &&
  32. cloud.map((v) => {
  33. return (
  34. <div key={v.uid}>
  35. <h2>{v.uid}</h2>
  36. <pre className={styles.row}>{JSON.stringify(v.settings, null, 2)}</pre>
  37. </div>
  38. );
  39. })}
  40. </Page.Contents>
  41. </Page>
  42. );
  43. }
  44. const getStyles = (theme: GrafanaTheme) => {
  45. return {
  46. row: css`
  47. cursor: pointer;
  48. `,
  49. };
  50. };