import getDefaultMonacoLanguages from 'lib/monaco-languages'; import { useState } from 'react'; import { useAsync } from 'react-use'; import SwaggerUI from 'swagger-ui-react'; import { createTheme, monacoLanguageRegistry, SelectableValue } from '@grafana/data'; import { Stack, Select } from '@grafana/ui'; import { setMonacoEnv } from 'app/core/monacoEnv'; import { ThemeProvider } from 'app/core/utils/ConfigProvider'; import { NamespaceContext, WrappedPlugins } from './plugins'; export const Page = () => { const theme = createTheme({ colors: { mode: 'light' } }); const [url, setURL] = useState>(); const urls = useAsync(async () => { const v2 = { label: 'Grafana API (OpenAPI v2)', key: 'openapi2', value: 'public/api-merged.json' }; const v3 = { label: 'Grafana API (OpenAPI v3)', key: 'openapi3', value: 'public/openapi3.json' }; const urls: Array> = [v2, v3]; const rsp = await fetch('openapi/v3'); const apis = await rsp.json(); for (const [key, val] of Object.entries(apis.paths)) { const parts = key.split('/'); if (parts.length === 3) { urls.push({ key: `${parts[1]}-${parts[2]}`, label: `${parts[1]}/${parts[2]}`, value: val.serverRelativeURL.substring(1), // remove initial slash }); } } let idx = 0; const urlParams = new URLSearchParams(window.location.search); const api = urlParams.get('api'); if (api) { urls.forEach((url, i) => { if (url.key === api) { idx = i; } }); } monacoLanguageRegistry.setInit(getDefaultMonacoLanguages); setMonacoEnv(); setURL(urls[idx]); // Remove to start at the generic landing page return urls; }); const namespace = useAsync(async () => { const response = await fetch('api/frontend/settings'); if (!response.ok) { console.warn('No settings found'); return ''; } const val = await response.json(); return val.namespace; }); return (
Grafana