forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ui): migrate
UserInfo
to functional component (argoproj#11793
) Signed-off-by: Anton Gilgur <[email protected]>
- Loading branch information
Showing
2 changed files
with
81 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,93 @@ | ||
import {Page} from 'argo-ui'; | ||
import * as React from 'react'; | ||
import {RouteComponentProps} from 'react-router-dom'; | ||
import {useEffect, useState} from 'react'; | ||
import {GetUserInfoResponse} from '../../../models'; | ||
import {uiUrl} from '../../shared/base'; | ||
import {BasePage} from '../../shared/components/base-page'; | ||
import {ErrorNotice} from '../../shared/components/error-notice'; | ||
import {Notice} from '../../shared/components/notice'; | ||
import {services} from '../../shared/services'; | ||
import {CliHelp} from './cli-help'; | ||
|
||
interface State { | ||
error?: Error; | ||
userInfo?: GetUserInfoResponse; | ||
} | ||
|
||
export class UserInfo extends BasePage<RouteComponentProps<any>, State> { | ||
constructor(props: RouteComponentProps<any>, context: any) { | ||
super(props, context); | ||
this.state = {}; | ||
} | ||
export function UserInfo() { | ||
const [error, setError] = useState<Error>(null); | ||
const [userInfo, setUserInfo] = useState<GetUserInfoResponse>(); | ||
|
||
public componentDidMount() { | ||
services.info | ||
.getUserInfo() | ||
.then(userInfo => this.setState({error: null, userInfo})) | ||
.catch(error => this.setState({error})); | ||
} | ||
useEffect(() => { | ||
(async function getUserInfoWrapper() { | ||
try { | ||
const newUserInfo = await services.info.getUserInfo(); | ||
setUserInfo(newUserInfo); | ||
setError(null); | ||
} catch (newError) { | ||
setError(newError); | ||
} | ||
})(); | ||
}); | ||
|
||
public render() { | ||
return ( | ||
<Page title='User Info' toolbar={{breadcrumbs: [{title: 'User Info'}]}}> | ||
{<ErrorNotice error={this.state.error} />} | ||
<Notice> | ||
<h3> | ||
<i className='fa fa-user-alt' /> User Info | ||
</h3> | ||
{this.state.userInfo && ( | ||
<> | ||
{this.state.userInfo.issuer && ( | ||
<dl> | ||
<dt>Issuer:</dt> | ||
<dd>{this.state.userInfo.issuer}</dd> | ||
</dl> | ||
)} | ||
{this.state.userInfo.subject && ( | ||
<dl> | ||
<dt>Subject:</dt> | ||
<dd>{this.state.userInfo.subject}</dd> | ||
</dl> | ||
)} | ||
{this.state.userInfo.groups && this.state.userInfo.groups.length > 0 && ( | ||
<dl> | ||
<dt>Groups:</dt> | ||
<dd>{this.state.userInfo.groups.join(', ')}</dd> | ||
</dl> | ||
)} | ||
{this.state.userInfo.name && ( | ||
<dl> | ||
<dt>Name:</dt> | ||
<dd>{this.state.userInfo.name}</dd> | ||
</dl> | ||
)} | ||
{this.state.userInfo.email && ( | ||
<dl> | ||
<dt>Email:</dt> | ||
<dd>{this.state.userInfo.email}</dd> | ||
</dl> | ||
)} | ||
{this.state.userInfo.emailVerified && ( | ||
<dl> | ||
<dt>Email Verified:</dt> | ||
<dd>{this.state.userInfo.emailVerified}</dd> | ||
</dl> | ||
)} | ||
{this.state.userInfo.serviceAccountName && ( | ||
<dl> | ||
<dt>Service Account:</dt> | ||
<dd>{this.state.userInfo.serviceAccountName}</dd> | ||
</dl> | ||
)} | ||
{this.state.userInfo.serviceAccountNamespace && ( | ||
<dl> | ||
<dt>Service Account Namespace:</dt> | ||
<dd>{this.state.userInfo.serviceAccountNamespace}</dd> | ||
</dl> | ||
)} | ||
</> | ||
)} | ||
<a className='argo-button argo-button--base-o' href={uiUrl('login')}> | ||
<i className='fa fa-shield-alt' /> Login / Logout | ||
</a> | ||
</Notice> | ||
<CliHelp /> | ||
</Page> | ||
); | ||
} | ||
return ( | ||
<Page title='User Info' toolbar={{breadcrumbs: [{title: 'User Info'}]}}> | ||
<ErrorNotice error={error} /> | ||
<Notice> | ||
<h3> | ||
<i className='fa fa-user-alt' /> User Info | ||
</h3> | ||
{userInfo && ( | ||
<> | ||
{userInfo.issuer && ( | ||
<dl> | ||
<dt>Issuer:</dt> | ||
<dd>{userInfo.issuer}</dd> | ||
</dl> | ||
)} | ||
{userInfo.subject && ( | ||
<dl> | ||
<dt>Subject:</dt> | ||
<dd>{userInfo.subject}</dd> | ||
</dl> | ||
)} | ||
{userInfo.groups && userInfo.groups.length > 0 && ( | ||
<dl> | ||
<dt>Groups:</dt> | ||
<dd>{userInfo.groups.join(', ')}</dd> | ||
</dl> | ||
)} | ||
{userInfo.name && ( | ||
<dl> | ||
<dt>Name:</dt> | ||
<dd>{userInfo.name}</dd> | ||
</dl> | ||
)} | ||
{userInfo.email && ( | ||
<dl> | ||
<dt>Email:</dt> | ||
<dd>{userInfo.email}</dd> | ||
</dl> | ||
)} | ||
{userInfo.emailVerified && ( | ||
<dl> | ||
<dt>Email Verified:</dt> | ||
<dd>{userInfo.emailVerified}</dd> | ||
</dl> | ||
)} | ||
{userInfo.serviceAccountName && ( | ||
<dl> | ||
<dt>Service Account:</dt> | ||
<dd>{userInfo.serviceAccountName}</dd> | ||
</dl> | ||
)} | ||
{userInfo.serviceAccountNamespace && ( | ||
<dl> | ||
<dt>Service Account Namespace:</dt> | ||
<dd>{userInfo.serviceAccountNamespace}</dd> | ||
</dl> | ||
)} | ||
</> | ||
)} | ||
<a className='argo-button argo-button--base-o' href={uiUrl('login')}> | ||
<i className='fa fa-shield-alt' /> Login / Logout | ||
</a> | ||
</Notice> | ||
<CliHelp /> | ||
</Page> | ||
); | ||
} |