mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Swagger: show user icon (#96736)
This commit is contained in:
parent
b0fe898fa1
commit
e0b93f055f
@ -5626,7 +5626,8 @@ exports[`better eslint`] = {
|
||||
],
|
||||
"public/swagger/SwaggerPage.tsx:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "1"]
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "1"],
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "2"]
|
||||
],
|
||||
"public/swagger/index.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
|
@ -4,7 +4,7 @@ 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 { Stack, Select, UserIcon, UserView, Button } from '@grafana/ui';
|
||||
import { setMonacoEnv } from 'app/core/monacoEnv';
|
||||
import { ThemeProvider } from 'app/core/utils/ConfigProvider';
|
||||
|
||||
@ -49,16 +49,34 @@ export const Page = () => {
|
||||
return urls;
|
||||
});
|
||||
|
||||
const [userView, setUserView] = useState<UserView>();
|
||||
|
||||
const namespace = useAsync(async () => {
|
||||
const response = await fetch('api/frontend/settings');
|
||||
if (!response.ok) {
|
||||
console.warn('No settings found');
|
||||
return '';
|
||||
return 'default';
|
||||
}
|
||||
const val = await response.json();
|
||||
return val.namespace;
|
||||
});
|
||||
|
||||
useAsync(async () => {
|
||||
const response = await fetch('api/user');
|
||||
if (!response.ok) {
|
||||
console.warn('No user found, show login button');
|
||||
return;
|
||||
}
|
||||
const val = await response.json();
|
||||
setUserView({
|
||||
user: {
|
||||
name: val.email || val.login,
|
||||
avatarUrl: val.avatarUrl,
|
||||
},
|
||||
lastActiveAt: new Date(),
|
||||
});
|
||||
});
|
||||
|
||||
return (
|
||||
<div>
|
||||
<ThemeProvider value={theme}>
|
||||
@ -83,6 +101,15 @@ export const Page = () => {
|
||||
value={url}
|
||||
isLoading={urls.loading}
|
||||
/>
|
||||
<div style={{ marginTop: '5px' }}>
|
||||
{userView ? (
|
||||
<UserIcon userView={userView} />
|
||||
) : (
|
||||
<a href="/login">
|
||||
<Button variant="primary">Login</Button>
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
</Stack>
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user