-
Notifications
You must be signed in to change notification settings - Fork 994
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #24041 - Move HW Models Table to pf-react
- Loading branch information
Showing
50 changed files
with
1,129 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
require 'integration_test_helper' | ||
|
||
class ModelJSTest < IntegrationTestWithJavascript | ||
test "index page" do | ||
assert_index_page(models_path, "Hardware Models", "Create Model") | ||
class ModelIntegrationTest < IntegrationTestWithJavascript | ||
test "create new page" do | ||
assert_new_button(models_path, "Create Model", new_model_path) | ||
fill_in "model_name", :with => "IBM 123" | ||
fill_in "model_hardware_model", :with => "IBMabcde" | ||
fill_in "model_vendor_class", :with => "ABCDE" | ||
fill_in "model_info", :with => "description text" | ||
assert_submit_button(models_path) | ||
assert page.has_link? "IBM 123" | ||
end | ||
|
||
test "edit page" do | ||
visit models_path | ||
click_link "KVM" | ||
fill_in "model_name", :with => "RHEV 123" | ||
assert_submit_button(models_path) | ||
assert page.has_link? 'RHEV 123' | ||
end | ||
end |
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
84 changes: 84 additions & 0 deletions
84
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTable.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,84 @@ | ||
import React from 'react'; | ||
import { LoadingState } from 'patternfly-react'; | ||
import PropTypes from 'prop-types'; | ||
import { Table } from '../common/table'; | ||
import { STATUS } from '../../constants'; | ||
import MessageBox from '../common/MessageBox'; | ||
import { translate as __ } from '../../common/I18n'; | ||
import createModelsTableSchema from './ModelsTableSchema'; | ||
import { getURIQuery } from '../../common/helpers'; | ||
import Pagination from '../Pagination/Pagination'; | ||
|
||
class ModelsTable extends React.Component { | ||
componentDidMount() { | ||
this.props.getTableItems('models', getURIQuery(window.location.href)); | ||
} | ||
|
||
render() { | ||
const { | ||
getTableItems, | ||
sortBy, | ||
sortOrder, | ||
error, | ||
status, | ||
results, | ||
data: { pagination }, | ||
} = this.props; | ||
|
||
const renderTable = | ||
status === STATUS.ERROR ? ( | ||
<MessageBox | ||
key="models-table-error" | ||
icontype="error-circle-o" | ||
msg={__(`Could not receive data: ${error && error.message}`)} | ||
/> | ||
) : ( | ||
<React.Fragment> | ||
<Table | ||
key="models-table" | ||
columns={createModelsTableSchema(getTableItems, sortBy, sortOrder)} | ||
rows={results} | ||
/> | ||
<div id="pagination"> | ||
<Pagination data={pagination} /> | ||
</div> | ||
</React.Fragment> | ||
); | ||
|
||
return ( | ||
<LoadingState | ||
size="lg" | ||
loading={status === STATUS.PENDING} | ||
timeout={2500} | ||
> | ||
{renderTable} | ||
</LoadingState> | ||
); | ||
} | ||
} | ||
|
||
ModelsTable.propTypes = { | ||
data: PropTypes.shape({ | ||
pagination: PropTypes.shape({ | ||
viewType: PropTypes.string, | ||
perPageOptions: PropTypes.arrayOf(PropTypes.number), | ||
itemCount: PropTypes.number, | ||
perPage: PropTypes.number, | ||
}).isRequired, | ||
}).isRequired, | ||
results: PropTypes.array.isRequired, | ||
getTableItems: PropTypes.func.isRequired, | ||
status: PropTypes.oneOf(Object.keys(STATUS)), | ||
sortBy: PropTypes.string, | ||
sortOrder: PropTypes.string, | ||
error: PropTypes.object, | ||
}; | ||
|
||
ModelsTable.defaultProps = { | ||
status: STATUS.PENDING, | ||
sortBy: '', | ||
sortOrder: '', | ||
error: null, | ||
}; | ||
|
||
export default ModelsTable; |
38 changes: 38 additions & 0 deletions
38
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTable.test.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,38 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import ModelsTable from './ModelsTable'; | ||
import { Table } from '../common/table'; | ||
import MessageBox from '../common/MessageBox'; | ||
|
||
const data = { | ||
pagination: { | ||
vieType: 'table', | ||
perPageOptions: [1, 2, 3], | ||
itemCount: 5, | ||
perPage: 1, | ||
}, | ||
}; | ||
|
||
describe('ModelsTable', () => { | ||
it('render table on sucess', () => { | ||
const getModelItems = jest.fn().mockReturnValue([]); | ||
const view = shallow( | ||
<ModelsTable results={[]} getTableItems={getModelItems} data={data} /> | ||
); | ||
expect(getModelItems.mock.calls).toHaveLength(1); | ||
expect(view.find(Table)).toHaveLength(1); | ||
}); | ||
|
||
it('render error message box on failure', () => { | ||
const view = shallow( | ||
<ModelsTable | ||
getTableItems={jest.fn(() => [])} | ||
results={[]} | ||
error={Error('some error message')} | ||
status="ERROR" | ||
data={data} | ||
/> | ||
); | ||
expect(view.find(MessageBox)).toHaveLength(1); | ||
}); | ||
}); |
6 changes: 6 additions & 0 deletions
6
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTableConstants.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,6 @@ | ||
import createTableActionTypes from '../common/table/actionsHelpers/actionTypeCreator'; | ||
|
||
export const MODELS_TABLE_CONTROLLER = 'models'; | ||
export const MODELS_TABLE_ACTION_TYPES = createTableActionTypes( | ||
MODELS_TABLE_CONTROLLER | ||
); |
34 changes: 34 additions & 0 deletions
34
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTableReducer.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,34 @@ | ||
import Immutable from 'seamless-immutable'; | ||
import { STATUS } from '../../constants'; | ||
import { MODELS_TABLE_ACTION_TYPES } from './ModelsTableConstants'; | ||
|
||
const initState = Immutable({ | ||
error: null, | ||
sortBy: '', | ||
sortOrder: '', | ||
results: [], | ||
status: STATUS.PENDING, | ||
}); | ||
export default (state = initState, action) => { | ||
const { REQUEST, FAILURE, SUCCESS } = MODELS_TABLE_ACTION_TYPES; | ||
switch (action.type) { | ||
case REQUEST: | ||
return state.set('status', STATUS.PENDING); | ||
case SUCCESS: | ||
return Immutable.merge(state, { | ||
error: null, | ||
status: STATUS.RESOLVED, | ||
results: action.payload.results, | ||
sortBy: action.payload.sort.by, | ||
sortOrder: action.payload.sort.order, | ||
}); | ||
case FAILURE: | ||
return Immutable.merge(state, { | ||
error: action.payload.error, | ||
status: STATUS.ERROR, | ||
results: [], | ||
}); | ||
default: | ||
return state; | ||
} | ||
}; |
36 changes: 36 additions & 0 deletions
36
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTableReducer.test.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,36 @@ | ||
import { testReducerSnapshotWithFixtures } from '../../common/testHelpers'; | ||
import reducer from './ModelsTableReducer'; | ||
import { MODELS_TABLE_ACTION_TYPES } from './ModelsTableConstants'; | ||
|
||
const fixtures = { | ||
'should return initial state': {}, | ||
'should handle MODELS_TABLE_REQUEST': { | ||
action: { | ||
type: MODELS_TABLE_ACTION_TYPES.REQUEST, | ||
}, | ||
}, | ||
'should handle MODELS_TABLE_SUCCESS': { | ||
action: { | ||
type: MODELS_TABLE_ACTION_TYPES.SUCCESS, | ||
payload: { | ||
search: 'name=model', | ||
results: [{ id: 23, name: 'model' }], | ||
page: 1, | ||
per_page: 5, | ||
total: 20, | ||
sort: { by: 'name', order: 'ASC' }, | ||
}, | ||
}, | ||
}, | ||
'should handle MODELS_TABLE_FAILURE': { | ||
action: { | ||
type: MODELS_TABLE_ACTION_TYPES.FAILURE, | ||
payload: { | ||
error: new Error('ooops!'), | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
describe('ModelsTable reducer', () => | ||
testReducerSnapshotWithFixtures(reducer, fixtures)); |
48 changes: 48 additions & 0 deletions
48
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTableSchema.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,48 @@ | ||
import { | ||
sortControllerFactory, | ||
column, | ||
sortableColumn, | ||
headerFormatterWithProps, | ||
cellFormatterWithProps, | ||
nameCellFormatter, | ||
hostsCountCellFormatter, | ||
deleteActionCellFormatter, | ||
cellFormatter, | ||
} from '../common/table'; | ||
|
||
/** | ||
* Generate a table schema to the Hardware Models page. | ||
* @param {Function} apiCall a Redux async action that fetches and stores table data in Redux. | ||
* See actions/common/getTableItemsAction. | ||
* @param {String} by by which column the table is sorted. | ||
* If none then set it to undefined/null. | ||
* @param {String} order in what order to sort a column. If none then set it to undefined/null. | ||
* Otherwise, 'ASC' for ascending and 'DESC' for descending | ||
* @return {Array} | ||
*/ | ||
const createModelsTableSchema = (apiCall, by, order) => { | ||
const sortController = sortControllerFactory(apiCall, by, order); | ||
return [ | ||
sortableColumn('name', __('Name'), 4, sortController, [ | ||
nameCellFormatter('models'), | ||
]), | ||
sortableColumn('vendor_class', __('Vendor Class'), 3, sortController), | ||
sortableColumn('hardware_model', __('Hardware Model'), 3, sortController), | ||
column( | ||
'hosts_count', | ||
__('Hosts'), | ||
[headerFormatterWithProps], | ||
[hostsCountCellFormatter('model'), cellFormatterWithProps], | ||
{ className: 'col-md-1' }, | ||
{ align: 'right' } | ||
), | ||
column( | ||
'actions', | ||
__('Actions'), | ||
[headerFormatterWithProps], | ||
[deleteActionCellFormatter('models'), cellFormatter] | ||
), | ||
]; | ||
}; | ||
|
||
export default createModelsTableSchema; |
Oops, something went wrong.