This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Add routed tabs to the Settings page to prepare for Conversion Hosts settings #851
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c488a74
Break GeneralSettings out from Settings component
mturley c7e88b4
Add tab bar connected to routes
mturley f5043e3
Fix existing tests
mturley f89f74c
Turn off the new tabs for now
mturley db48bd1
Switch to direct Tab component import
mturley b700cdd
Move GeneralSettings into its own container component
mturley 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 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,100 +1,47 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { reduxForm, Field } from 'redux-form'; | ||
import { Breadcrumb, Form, Button, Spinner } from 'patternfly-react'; | ||
import { Breadcrumb, Tabs, Tab } from 'patternfly-react'; | ||
import Toolbar from '../../../config/Toolbar'; | ||
import NumberInput from '../common/forms/NumberInput'; | ||
import GeneralSettings from './screens/GeneralSettings'; | ||
import ConversionHostsSettings from './screens/ConversionHostsSettings'; | ||
|
||
export class Settings extends React.Component { | ||
componentDidMount() { | ||
const { fetchServersAction, fetchServersUrl, fetchSettingsAction, fetchSettingsUrl } = this.props; | ||
fetchServersAction(fetchServersUrl); | ||
fetchSettingsAction(fetchSettingsUrl); | ||
} | ||
const Settings = props => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function |
||
const { match, redirectTo } = props; | ||
|
||
onApplyClick = () => { | ||
const { patchSettingsAction, servers, settingsForm } = this.props; | ||
patchSettingsAction(servers, settingsForm.values); | ||
}; | ||
// TODO remove this when we are ready to release ConversionHostsSettings | ||
const hideConversionHostSettings = true; | ||
|
||
render() { | ||
const { isFetchingServers, isFetchingSettings, isSavingSettings, savedSettings, settingsForm } = this.props; | ||
|
||
const toolbarContent = ( | ||
return ( | ||
<React.Fragment> | ||
<Toolbar> | ||
<Breadcrumb.Item href="/dashboard/maintab?tab=compute">{__('Compute')}</Breadcrumb.Item> | ||
<Breadcrumb.Item href="#/plans">{__('Migration')}</Breadcrumb.Item> | ||
<Breadcrumb.Item active>{__('Migration Settings')}</Breadcrumb.Item> | ||
</Toolbar> | ||
); | ||
|
||
const hasUnsavedChanges = | ||
settingsForm && | ||
settingsForm.values && | ||
Object.keys(savedSettings).some(key => savedSettings[key] !== settingsForm.values[key]); | ||
|
||
const settingsContent = ( | ||
<Spinner loading={isFetchingServers || isFetchingSettings} style={{ marginTop: 15 }}> | ||
<div className="migration-settings"> | ||
{hideConversionHostSettings ? ( | ||
<React.Fragment> | ||
<h2>{__('Concurrent Migrations')}</h2> | ||
<Form style={{ padding: '0 20px' }}> | ||
<Form.FormGroup> | ||
<Form.ControlLabel>{__('Maximum concurrent migrations per conversion host')}</Form.ControlLabel> | ||
<div style={{ width: 100 }}> | ||
<Field | ||
id="max_concurrent_tasks_per_host" | ||
name="max_concurrent_tasks_per_host" | ||
component={NumberInput} | ||
normalize={NumberInput.normalizeStringToInt} | ||
min={1} | ||
/> | ||
</div> | ||
</Form.FormGroup> | ||
<Form.FormGroup> | ||
<Button bsStyle="primary" onClick={this.onApplyClick} disabled={!hasUnsavedChanges || isSavingSettings}> | ||
{__('Apply')} | ||
</Button> | ||
<br /> | ||
{isSavingSettings && ( | ||
<div style={{ paddingTop: 10 }}> | ||
<Spinner loading size="xs" inline /> | ||
{__(' Applying...')} | ||
</div> | ||
)} | ||
</Form.FormGroup> | ||
</Form> | ||
<GeneralSettings /> | ||
</React.Fragment> | ||
) : ( | ||
<div style={{ marginTop: 10 }}> | ||
<Tabs id="settings-tabs" activeKey={match.path} onSelect={key => redirectTo(key)}> | ||
<Tab eventKey="/settings" title={__('Concurrent Migrations')}> | ||
<GeneralSettings /> | ||
</Tab> | ||
<Tab eventKey="/settings/conversion_hosts" title={__('Conversion Hosts')}> | ||
<ConversionHostsSettings /> | ||
</Tab> | ||
</Tabs> | ||
</div> | ||
</Spinner> | ||
); | ||
|
||
return ( | ||
<React.Fragment> | ||
{toolbarContent} | ||
{settingsContent} | ||
</React.Fragment> | ||
); | ||
} | ||
} | ||
|
||
Settings.propTypes = { | ||
fetchServersAction: PropTypes.func, | ||
fetchSettingsAction: PropTypes.func, | ||
patchSettingsAction: PropTypes.func, | ||
isFetchingServers: PropTypes.bool, | ||
isFetchingSettings: PropTypes.bool, | ||
isSavingSettings: PropTypes.bool, | ||
servers: PropTypes.array, | ||
savedSettings: PropTypes.object, | ||
settingsForm: PropTypes.object, | ||
fetchServersUrl: PropTypes.string, | ||
fetchSettingsUrl: PropTypes.string | ||
)} | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
Settings.defaultProps = { | ||
fetchServersUrl: '/api/servers', | ||
fetchSettingsUrl: '/api/settings' | ||
Settings.propTypes = { | ||
match: PropTypes.object, | ||
redirectTo: PropTypes.func | ||
}; | ||
|
||
export default reduxForm({ | ||
form: 'settings' | ||
})(Settings); | ||
export default Settings; |
97 changes: 0 additions & 97 deletions
97
app/javascript/react/screens/App/Settings/__tests__/__snapshots__/Settings.test.js.snap
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,16 @@ | ||
import { connect } from 'react-redux'; | ||
import Settings from './Settings'; | ||
|
||
import * as SettingsActions from './SettingsActions'; | ||
import * as NotificationActions from '../common/NotificationList/NotificationListActions'; | ||
|
||
import reducer from './SettingsReducer'; | ||
import * as RouterActions from '../../../../redux/actions/routerActions'; | ||
|
||
export const reducers = { settings: reducer }; | ||
|
||
const mapStateToProps = ({ settings, form }, ownProps) => ({ | ||
...settings, | ||
...ownProps.data, | ||
settingsForm: form.settings, | ||
initialValues: settings.savedSettings, | ||
enableReinitialize: true, | ||
destroyOnUnmount: false | ||
}); | ||
const mapStateToProps = () => ({}); | ||
|
||
const mergeProps = (stateProps, dispatchProps, ownProps) => Object.assign(stateProps, ownProps.data, dispatchProps); | ||
|
||
export default connect( | ||
mapStateToProps, | ||
Object.assign(SettingsActions, NotificationActions), | ||
RouterActions, | ||
mergeProps | ||
)(Settings); |
5 changes: 5 additions & 0 deletions
5
...ipt/react/screens/App/Settings/screens/ConversionHostsSettings/ConversionHostsSettings.js
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,5 @@ | ||
import React from 'react'; | ||
|
||
const ConversionHostsSettings = () => <h2>Hello World</h2>; | ||
|
||
export default ConversionHostsSettings; |
3 changes: 3 additions & 0 deletions
3
app/javascript/react/screens/App/Settings/screens/ConversionHostsSettings/index.js
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,3 @@ | ||
import ConversionHostsSettings from './ConversionHostsSettings'; | ||
|
||
export default ConversionHostsSettings; |
83 changes: 83 additions & 0 deletions
83
app/javascript/react/screens/App/Settings/screens/GeneralSettings/GeneralSettings.js
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,83 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { reduxForm, Field } from 'redux-form'; | ||
import { Form, Button, Spinner } from 'patternfly-react'; | ||
import NumberInput from '../../../common/forms/NumberInput'; | ||
|
||
export class GeneralSettings extends React.Component { | ||
componentDidMount() { | ||
const { fetchServersAction, fetchServersUrl, fetchSettingsAction, fetchSettingsUrl } = this.props; | ||
fetchServersAction(fetchServersUrl); | ||
fetchSettingsAction(fetchSettingsUrl); | ||
} | ||
|
||
onApplyClick = () => { | ||
const { patchSettingsAction, servers, settingsForm } = this.props; | ||
patchSettingsAction(servers, settingsForm.values); | ||
}; | ||
|
||
render() { | ||
const { isFetchingServers, isFetchingSettings, isSavingSettings, savedSettings, settingsForm } = this.props; | ||
|
||
const hasUnsavedChanges = | ||
settingsForm && | ||
settingsForm.values && | ||
Object.keys(savedSettings).some(key => savedSettings[key] !== settingsForm.values[key]); | ||
|
||
return ( | ||
<Spinner loading={isFetchingServers || isFetchingSettings} style={{ marginTop: 15 }}> | ||
<div className="migration-settings"> | ||
<Form style={{ padding: '0 20px' }}> | ||
<Form.FormGroup> | ||
<Form.ControlLabel>{__('Maximum concurrent migrations per conversion host')}</Form.ControlLabel> | ||
<div style={{ width: 100 }}> | ||
<Field | ||
id="max_concurrent_tasks_per_host" | ||
name="max_concurrent_tasks_per_host" | ||
component={NumberInput} | ||
normalize={NumberInput.normalizeStringToInt} | ||
min={1} | ||
/> | ||
</div> | ||
</Form.FormGroup> | ||
<Form.FormGroup> | ||
<Button bsStyle="primary" onClick={this.onApplyClick} disabled={!hasUnsavedChanges || isSavingSettings}> | ||
{__('Apply')} | ||
</Button> | ||
<br /> | ||
{isSavingSettings && ( | ||
<div style={{ paddingTop: 10 }}> | ||
<Spinner loading size="xs" inline /> | ||
{__(' Applying...')} | ||
</div> | ||
)} | ||
</Form.FormGroup> | ||
</Form> | ||
</div> | ||
</Spinner> | ||
); | ||
} | ||
} | ||
|
||
GeneralSettings.propTypes = { | ||
fetchServersAction: PropTypes.func, | ||
fetchSettingsAction: PropTypes.func, | ||
patchSettingsAction: PropTypes.func, | ||
isFetchingServers: PropTypes.bool, | ||
isFetchingSettings: PropTypes.bool, | ||
isSavingSettings: PropTypes.bool, | ||
servers: PropTypes.array, | ||
savedSettings: PropTypes.object, | ||
settingsForm: PropTypes.object, | ||
fetchServersUrl: PropTypes.string, | ||
fetchSettingsUrl: PropTypes.string | ||
}; | ||
|
||
GeneralSettings.defaultProps = { | ||
fetchServersUrl: '/api/servers', | ||
fetchSettingsUrl: '/api/settings' | ||
}; | ||
|
||
export default reduxForm({ | ||
form: 'settings' | ||
})(GeneralSettings); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just making sure... we don't need an entry here for
settings/general
because by default, entering thesettings
route opens the general tab?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelkro That's correct. There's no
/settings/general
route,/settings
and/settings/conversion_hosts
are the routes to each tab.