This repository was archived by the owner on Aug 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Addition of Overview page in the dashboard #105
Merged
portante
merged 3 commits into
distributed-system-analysis:main
from
anishaswain:overviewPage
Oct 27, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,123 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { | ||
Form, | ||
FormGroup, | ||
TextInput, | ||
Checkbox, | ||
ActionGroup, | ||
Button, | ||
Title, | ||
} from '@patternfly/react-core'; | ||
import { connect } from 'dva'; | ||
import styles from './index.less'; | ||
|
||
const mapStateToProps = state => { | ||
const { auth } = state; | ||
return { auth }; | ||
}; | ||
|
||
const LoginForm = props => { | ||
const [username, setUsername] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
const [errors, setErrors] = useState({ | ||
email: '', | ||
}); | ||
const [btnDisabled, setBtnDisabled] = useState(true); | ||
|
||
const handleUsernameChange = val => { | ||
setUsername(val); | ||
setErrors({ | ||
...errors, | ||
}); | ||
}; | ||
|
||
const handleLoginSubmit = () => { | ||
const { dispatch } = props; | ||
dispatch({ | ||
type: 'auth/loginUser', | ||
payload: { | ||
username, | ||
password, | ||
}, | ||
}); | ||
}; | ||
|
||
/* eslint-disable no-restricted-syntax */ | ||
const validateForm = () => { | ||
if (username.trim() === '' || password.trim() === '') { | ||
return false; | ||
} | ||
for (const dep of Object.entries(errors)) { | ||
if (dep[1].length > 0) { | ||
return false; | ||
} | ||
} | ||
// if we reach here, it means | ||
// we have covered all of the edge cases. | ||
return true; | ||
}; | ||
|
||
useEffect( | ||
() => { | ||
if (validateForm()) { | ||
setBtnDisabled(false); | ||
} else setBtnDisabled(true); | ||
}, | ||
[username, password] | ||
); | ||
|
||
const form = ( | ||
<div className={styles.section}> | ||
<Form className={styles.section}> | ||
<FormGroup label="Username" isRequired fieldId="horizontal-form-name"> | ||
<TextInput | ||
isRequired | ||
type="text" | ||
id="horizontal-form-name" | ||
aria-describedby="horizontal-form-name-helper" | ||
name="horizontal-form-name" | ||
onChange={handleUsernameChange} | ||
/> | ||
<p className={styles.error}>{errors.email}</p> | ||
</FormGroup> | ||
<FormGroup label="Password" isRequired fieldId="horizontal-form-password"> | ||
<TextInput | ||
isRequired | ||
type="password" | ||
id="horizontal-form-password" | ||
name="horizontal-form-password" | ||
onChange={val => setPassword(val)} | ||
/> | ||
</FormGroup> | ||
<FormGroup fieldId="remember-me"> | ||
<Checkbox | ||
label="Keep me logged in" | ||
id="alt-form-checkbox-1" | ||
name="alt-form-checkbox-1" | ||
className={styles.check} | ||
/> | ||
</FormGroup> | ||
<ActionGroup> | ||
<Button | ||
isBlock | ||
onClick={handleLoginSubmit} | ||
className={styles.btn} | ||
id="submitBtn" | ||
isDisabled={btnDisabled} | ||
> | ||
<Title | ||
headingLevel="h4" | ||
size="xl" | ||
style={btnDisabled ? { color: 'black' } : { color: 'white' }} | ||
> | ||
Submit | ||
</Title> | ||
</Button> | ||
</ActionGroup> | ||
</Form> | ||
</div> | ||
); | ||
return <React.Fragment>{form}</React.Fragment>; | ||
}; | ||
|
||
export default connect(mapStateToProps)(LoginForm); | ||
aquibbaig marked this conversation as resolved.
Show resolved
Hide resolved
|
6 changes: 1 addition & 5 deletions
6
src/pages/LoginHandler/index.less → src/components/LoginForm/index.less
This file contains hidden or 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 hidden or 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 hidden or 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,94 @@ | ||
import React from 'react'; | ||
import { | ||
Modal, | ||
ModalVariant, | ||
Button, | ||
TextContent, | ||
Text, | ||
TextVariants, | ||
} from '@patternfly/react-core'; | ||
import { routerRedux } from 'dva/router'; | ||
import { connect } from 'dva'; | ||
import LoginForm from '@/components/LoginForm'; | ||
|
||
@connect(auth => ({ | ||
auth: auth.auth, | ||
})) | ||
class LoginModal extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
isModalOpen: false, | ||
modalView: false, | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
this.handleModalToggle(); | ||
} | ||
|
||
handleModalToggle = () => { | ||
this.setState(({ isModalOpen }) => ({ | ||
isModalOpen: !isModalOpen, | ||
})); | ||
}; | ||
|
||
handleModalCancel = () => { | ||
const { dispatch } = this.props; | ||
this.setState(({ isModalOpen }) => ({ | ||
isModalOpen: !isModalOpen, | ||
})); | ||
dispatch(routerRedux.push(`/`)); | ||
}; | ||
|
||
handleLoginModal = () => { | ||
this.setState({ | ||
modalView: true, | ||
}); | ||
}; | ||
|
||
handleSignupModal = () => { | ||
const { dispatch } = this.props; | ||
this.setState(({ isModalOpen }) => ({ | ||
isModalOpen: !isModalOpen, | ||
})); | ||
dispatch(routerRedux.push(`/signup`)); | ||
}; | ||
|
||
render() { | ||
const { isModalOpen, modalView } = this.state; | ||
const loginAction = ( | ||
<div> | ||
<TextContent> | ||
<Text component={TextVariants.h4}> | ||
This action requires login. Please login to Pbench Dashboard to continue. | ||
</Text> | ||
</TextContent> | ||
<Button key="confirm" variant="primary" onClick={this.handleLoginModal}> | ||
Login | ||
</Button> | ||
<Button key="confirm" variant="link" onClick={this.handleSignupModal}> | ||
Signup | ||
</Button> | ||
<Button key="cancel" variant="link" onClick={this.handleModalCancel}> | ||
Cancel | ||
</Button> | ||
</div> | ||
); | ||
const modalContent = !modalView ? loginAction : <LoginForm />; | ||
return ( | ||
<React.Fragment> | ||
<Modal | ||
variant={ModalVariant.small} | ||
isOpen={isModalOpen} | ||
onClose={this.handleModalCancel} | ||
showClose="false" | ||
> | ||
{modalContent} | ||
anishaswain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Modal> | ||
</React.Fragment> | ||
); | ||
} | ||
} | ||
|
||
export default LoginModal; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.