Swagger: show user icon (#96736)
This commit is contained in:
+2
-1
@@ -5626,7 +5626,8 @@ exports[`better eslint`] = {
|
|||||||
],
|
],
|
||||||
"public/swagger/SwaggerPage.tsx:5381": [
|
"public/swagger/SwaggerPage.tsx:5381": [
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
[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": [
|
"public/swagger/index.tsx:5381": [
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
[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 SwaggerUI from 'swagger-ui-react';
|
||||||
|
|
||||||
import { createTheme, monacoLanguageRegistry, SelectableValue } from '@grafana/data';
|
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 { setMonacoEnv } from 'app/core/monacoEnv';
|
||||||
import { ThemeProvider } from 'app/core/utils/ConfigProvider';
|
import { ThemeProvider } from 'app/core/utils/ConfigProvider';
|
||||||
|
|
||||||
@@ -49,16 +49,34 @@ export const Page = () => {
|
|||||||
return urls;
|
return urls;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [userView, setUserView] = useState<UserView>();
|
||||||
|
|
||||||
const namespace = useAsync(async () => {
|
const namespace = useAsync(async () => {
|
||||||
const response = await fetch('api/frontend/settings');
|
const response = await fetch('api/frontend/settings');
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.warn('No settings found');
|
console.warn('No settings found');
|
||||||
return '';
|
return 'default';
|
||||||
}
|
}
|
||||||
const val = await response.json();
|
const val = await response.json();
|
||||||
return val.namespace;
|
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 (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<ThemeProvider value={theme}>
|
<ThemeProvider value={theme}>
|
||||||
@@ -83,6 +101,15 @@ export const Page = () => {
|
|||||||
value={url}
|
value={url}
|
||||||
isLoading={urls.loading}
|
isLoading={urls.loading}
|
||||||
/>
|
/>
|
||||||
|
<div style={{ marginTop: '5px' }}>
|
||||||
|
{userView ? (
|
||||||
|
<UserIcon userView={userView} />
|
||||||
|
) : (
|
||||||
|
<a href="/login">
|
||||||
|
<Button variant="primary">Login</Button>
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</Stack>
|
</Stack>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user