forked from grafana/grafana
-
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.
Rewrite user profile edit to react (grafana#17917)
* rewrite user profile edit to react (grafana#17525) * disableLogin change, still need to fix tooltip * left out disable form for other auth * PR changes - wrapper to render, userId instead of bool, optional user in state, change provider child param order * moved directive to angular_wrappers * catch api error * finally * move user arg back to end- optional * optional type sig
- Loading branch information
Shavonn Brown
committed
Aug 19, 2019
1 parent
50058de
commit e3e2cd8
Showing
11 changed files
with
193 additions
and
89 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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import { UserProvider } from 'app/core/utils/UserProvider'; | ||
import { UserProfileEditForm } from './UserProfileEditForm'; | ||
import { SharedPreferences } from 'app/core/components/SharedPreferences/SharedPreferences'; | ||
import { config } from '@grafana/runtime'; | ||
|
||
export const ReactProfileWrapper = () => ( | ||
<UserProvider userId={config.bootData.user.id}> | ||
{(api, states, user) => { | ||
return ( | ||
<> | ||
{!states.loadUser && ( | ||
<UserProfileEditForm | ||
updateProfile={api.updateUserProfile} | ||
isSavingUser={states.updateUserProfile} | ||
user={user} | ||
/> | ||
)} | ||
<SharedPreferences resourceUri="user" /> | ||
</> | ||
); | ||
}} | ||
</UserProvider> | ||
); | ||
|
||
export default ReactProfileWrapper; |
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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import React, { PureComponent, ChangeEvent, MouseEvent } from 'react'; | ||
import { Button, FormLabel, Input, Tooltip } from '@grafana/ui'; | ||
import { User } from 'app/types'; | ||
import config from 'app/core/config'; | ||
import { ProfileUpdateFields } from 'app/core/utils/UserProvider'; | ||
|
||
export interface Props { | ||
user: User; | ||
isSavingUser: boolean; | ||
updateProfile: (payload: ProfileUpdateFields) => void; | ||
} | ||
|
||
export interface State { | ||
name: string; | ||
email: string; | ||
login: string; | ||
} | ||
|
||
export class UserProfileEditForm extends PureComponent<Props, State> { | ||
constructor(props: Props) { | ||
super(props); | ||
|
||
const { | ||
user: { name, email, login }, | ||
} = this.props; | ||
|
||
this.state = { | ||
name, | ||
email, | ||
login, | ||
}; | ||
} | ||
|
||
onNameChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
this.setState({ name: event.target.value }); | ||
}; | ||
|
||
onEmailChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
this.setState({ email: event.target.value }); | ||
}; | ||
|
||
onLoginChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
this.setState({ login: event.target.value }); | ||
}; | ||
|
||
onSubmitProfileUpdate = (event: MouseEvent<HTMLInputElement>) => { | ||
event.preventDefault(); | ||
this.props.updateProfile({ ...this.state }); | ||
}; | ||
|
||
render() { | ||
const { name, email, login } = this.state; | ||
const { isSavingUser } = this.props; | ||
const { disableLoginForm } = config; | ||
|
||
return ( | ||
<> | ||
<h3 className="page-sub-heading">Edit Profile</h3> | ||
<form name="userForm" className="gf-form-group"> | ||
<div className="gf-form max-width-30"> | ||
<FormLabel className="width-8">Name</FormLabel> | ||
<Input className="gf-form-input max-width-22" type="text" onChange={this.onNameChange} value={name} /> | ||
</div> | ||
<div className="gf-form max-width-30"> | ||
<FormLabel className="width-8">Email</FormLabel> | ||
<Input | ||
className="gf-form-input max-width-22" | ||
type="text" | ||
onChange={this.onEmailChange} | ||
value={email} | ||
disabled={disableLoginForm} | ||
/> | ||
{disableLoginForm && ( | ||
<Tooltip content="Login Details Locked - managed in another system."> | ||
<i className="fa fa-lock gf-form-icon--right-absolute" /> | ||
</Tooltip> | ||
)} | ||
</div> | ||
<div className="gf-form max-width-30"> | ||
<FormLabel className="width-8">Username</FormLabel> | ||
<Input | ||
className="gf-form-input max-width-22" | ||
type="text" | ||
onChange={this.onLoginChange} | ||
value={login} | ||
disabled={disableLoginForm} | ||
/> | ||
{disableLoginForm && ( | ||
<Tooltip content="Login Details Locked - managed in another system."> | ||
<i className="fa fa-lock gf-form-icon--right-absolute" /> | ||
</Tooltip> | ||
)} | ||
</div> | ||
<div className="gf-form-button-row"> | ||
<Button variant="primary" onClick={this.onSubmitProfileUpdate} disabled={isSavingUser}> | ||
Save | ||
</Button> | ||
</div> | ||
</form> | ||
</> | ||
); | ||
} | ||
} | ||
|
||
export default UserProfileEditForm; |
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,2 +1 @@ | ||
import './ProfileCtrl'; | ||
import './PrefControlCtrl'; |
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
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