Skip to content

Commit

Permalink
Merge pull request #889 from mturley/conv-host-tasks-polling
Browse files Browse the repository at this point in the history
Conversion Host Configuration - List view #3 - Polling for tasks and rendering enable/disable status

(cherry picked from commit d4ea6f6)

https://bugzilla.redhat.com/show_bug.cgi?id=1696423
  • Loading branch information
mzazrivec authored and simaishi committed Apr 5, 2019
1 parent fde5b64 commit 4f06604
Show file tree
Hide file tree
Showing 19 changed files with 583 additions and 146 deletions.
2 changes: 1 addition & 1 deletion app/javascript/react/screens/App/Settings/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Settings = props => {
</React.Fragment>
) : (
<div style={{ marginTop: 10 }}>
<Tabs id="settings-tabs" activeKey={match.path} onSelect={key => redirectTo(key)}>
<Tabs id="settings-tabs" activeKey={match.path} onSelect={key => redirectTo(key)} unmountOnExit>
<Tab eventKey="/settings" title={__('Migration Throttling')}>
<GeneralSettings />
</Tab>
Expand Down
9 changes: 9 additions & 0 deletions app/javascript/react/screens/App/Settings/Settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@
.conversion-hosts-list .list-view-pf-main-info {
padding: 10px 0;
}

.conversion-hosts-list .spinner.spinner-inline {
margin-right: 10px;
}

.conversion-hosts-list-actions {
min-width: 150px;
text-align: right;
}
12 changes: 12 additions & 0 deletions app/javascript/react/screens/App/Settings/SettingsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
V2V_FETCH_SETTINGS,
V2V_PATCH_SETTINGS,
FETCH_V2V_CONVERSION_HOSTS,
FETCH_V2V_CONVERSION_HOST_TASKS,
SHOW_V2V_CONVERSION_HOST_WIZARD,
HIDE_V2V_CONVERSION_HOST_WIZARD,
V2V_CONVERSION_HOST_WIZARD_EXITED,
Expand Down Expand Up @@ -69,6 +70,17 @@ export const fetchConversionHostsAction = url => {
return _getConversionHostsActionCreator(uri.toString());
};

const _getConversionHostTasksActionCreator = url => dispatch =>
dispatch({
type: FETCH_V2V_CONVERSION_HOST_TASKS,
payload: API.get(url)
});

export const fetchConversionHostTasksAction = url => {
const uri = new URI(url);
return _getConversionHostTasksActionCreator(uri.toString());
};

export const showConversionHostWizardAction = () => dispatch => dispatch({ type: SHOW_V2V_CONVERSION_HOST_WIZARD });

export const hideConversionHostWizardAction = () => dispatch => dispatch({ type: HIDE_V2V_CONVERSION_HOST_WIZARD });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const V2V_FETCH_SERVERS = 'V2V_FETCH_SERVERS';
export const V2V_FETCH_SETTINGS = 'V2V_FETCH_SETTINGS';
export const V2V_PATCH_SETTINGS = 'V2V_PATCH_SETTINGS';
export const FETCH_V2V_CONVERSION_HOSTS = 'FETCH_V2V_CONVERSION_HOSTS';
export const FETCH_V2V_CONVERSION_HOST_TASKS = 'FETCH_V2V_CONVERSION_HOST_TASKS';
export const SHOW_V2V_CONVERSION_HOST_WIZARD = 'SHOW_V2V_CONVERSION_HOST_WIZARD';
export const HIDE_V2V_CONVERSION_HOST_WIZARD = 'HIDE_V2V_CONVERSION_HOST_WIZARD';
export const V2V_CONVERSION_HOST_WIZARD_EXITED = 'V2V_CONVERSION_HOST_WIZARD_EXITED';
Expand Down
63 changes: 47 additions & 16 deletions app/javascript/react/screens/App/Settings/SettingsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
V2V_FETCH_SETTINGS,
V2V_PATCH_SETTINGS,
FETCH_V2V_CONVERSION_HOSTS,
FETCH_V2V_CONVERSION_HOST_TASKS,
SHOW_V2V_CONVERSION_HOST_WIZARD,
HIDE_V2V_CONVERSION_HOST_WIZARD,
V2V_CONVERSION_HOST_WIZARD_EXITED,
Expand All @@ -15,15 +16,23 @@ import {
DELETE_V2V_CONVERSION_HOST
} from './SettingsConstants';

import { getFormValuesFromApiSettings } from './helpers';
import {
getFormValuesFromApiSettings,
parseConversionHostTasksMetadata,
indexConversionHostTasksByResource
} from './helpers';

export const initialState = Immutable({
conversionHosts: [],
conversionHostTasks: [],
conversionHostTasksByResource: {},
conversionHostToDelete: null,
conversionHostDeleteModalVisible: false,
conversionHostWizardMounted: false,
conversionHostWizardVisible: false,
errorDeleteConversionHost: false,
errorFetchingConversionHosts: null,
errorFetchingConversionHostTasks: null,
errorFetchingServers: null,
errorFetchingSettings: null,
errorPostingConversionHosts: null,
Expand All @@ -32,18 +41,19 @@ export const initialState = Immutable({
fetchingSettingsRejected: false,
isDeletingConversionHost: false,
isFetchingConversionHosts: false,
isFetchingConversionHostTasks: false,
isFetchingServers: false,
isFetchingSettings: false,
isRejectedConversionHost: false,
isRejectedConversionHosts: false,
isPostingConversionHosts: false,
isRejectedDeletingConversionHost: false,
isRejectedFetchingConversionHosts: false,
isRejectedFetchingConversionHostTasks: false,
isRejectedPostingConversionHosts: false,
isSavingSettings: false,
postConversionHostsResults: [],
savedSettings: {},
savingSettingsRejected: false,
servers: [],
showConversionHostDeleteModal: false
servers: []
});

export default (state = initialState, action) => {
Expand Down Expand Up @@ -102,22 +112,41 @@ export default (state = initialState, action) => {
case `${FETCH_V2V_CONVERSION_HOSTS}_PENDING`:
return state
.set('isFetchingConversionHosts', true)
.set('isRejectedConversionHosts', false)
.set('isRejectedFetchingConversionHosts', false)
.set('errorFetchingConversionHosts', null);
case `${FETCH_V2V_CONVERSION_HOSTS}_FULFILLED`:
return state
.set('conversionHosts', action.payload.data.resources)
.set('isFetchingConversionHosts', false)
.set('isRejectedConversionHosts', false)
.set('showConversionHostDeleteModal', false)
.set('isRejectedFetchingConversionHosts', false)
.set('errorFetchingConversionHosts', null);
case `${FETCH_V2V_CONVERSION_HOSTS}_REJECTED`:
return state
.set('isFetchingConversionHosts', false)
.set('isRejectedConversionHosts', true)
.set('showConversionHostDeleteModal', false)
.set('isRejectedFetchingConversionHosts', true)
.set('errorFetchingConversionHosts', action.payload);

case `${FETCH_V2V_CONVERSION_HOST_TASKS}_PENDING`:
return state
.set('isFetchingConversionHostTasks', true)
.set('isRejectedFetchingConversionHostTasks', false)
.set('errorFetchingConversionHostTasks', null);
case `${FETCH_V2V_CONVERSION_HOST_TASKS}_FULFILLED`: {
const tasksWithMetadata = parseConversionHostTasksMetadata(action.payload.data.resources);
const tasksByResource = indexConversionHostTasksByResource(tasksWithMetadata);
return state
.set('conversionHostTasks', tasksWithMetadata)
.set('conversionHostTasksByResource', tasksByResource)
.set('isFetchingConversionHostTasks', false)
.set('isRejectedFetchingConversionHostTasks', false)
.set('errorFetchingConversionHostTasks', null);
}
case `${FETCH_V2V_CONVERSION_HOST_TASKS}_REJECTED`:
return state
.set('isFetchingConversionHostTasks', false)
.set('isRejectedFetchingConversionHostTasks', true)
.set('errorFetchingConversionHostTasks', action.payload);

case SHOW_V2V_CONVERSION_HOST_WIZARD:
return state.set('conversionHostWizardMounted', true).set('conversionHostWizardVisible', true);
case HIDE_V2V_CONVERSION_HOST_WIZARD:
Expand All @@ -144,23 +173,25 @@ export default (state = initialState, action) => {
case SET_V2V_CONVERSION_HOST_TO_DELETE:
return state.set('conversionHostToDelete', action.payload);
case SHOW_V2V_CONVERSION_HOST_DELETE_MODAL:
return state.set('showConversionHostDeleteModal', true);
return state.set('conversionHostDeleteModalVisible', true);
case HIDE_V2V_CONVERSION_HOST_DELETE_MODAL:
return state.set('showConversionHostDeleteModal', false);
return state.set('conversionHostDeleteModalVisible', false);

case `${DELETE_V2V_CONVERSION_HOST}_PENDING`:
return state.set('isDeletingConversionHost', action.payload);
case `${DELETE_V2V_CONVERSION_HOST}_FULFILLED`:
return state
.set('deleteConversionHostResponse', action.payload.data)
.set('isDeletingConversionHost', null)
.set('isRejectedConversionHost', false)
.set('errorDeleteConversionHost', null);
.set('isRejectedDeletingConversionHost', false)
.set('errorDeleteConversionHost', null)
.set('conversionHostDeleteModalVisible', false);
case `${DELETE_V2V_CONVERSION_HOST}_REJECTED`:
return state
.set('errorDeleteConversionHost', action.payload)
.set('isRejectedConversionHost', true)
.set('isDeletingConversionHost', null);
.set('isRejectedDeletingConversionHost', true)
.set('isDeletingConversionHost', null)
.set('conversionHostDeleteModalVisible', false);

default:
return state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('fetching conversion hosts', () => {
const action = {
type: `${FETCH_V2V_CONVERSION_HOSTS}_PENDING`
};
const prevState = initialState.set('isRejectedConversionHosts', true);
const prevState = initialState.set('isRejectedFetchingConversionHosts', true);
const state = settingsReducer(prevState, action);
expect(state).toMatchSnapshot();
});
Expand All @@ -135,7 +135,9 @@ describe('fetching conversion hosts', () => {
type: `${FETCH_V2V_CONVERSION_HOSTS}_FULFILLED`,
payload: { data: { resources: [{ mock: 'conversionHost' }] } }
};
const prevState = initialState.set('isRejectedConversionHosts', true).set('isFetchingConversionHosts', true);
const prevState = initialState
.set('isRejectedFetchingConversionHosts', true)
.set('isFetchingConversionHosts', true);
const state = settingsReducer(prevState, action);
expect(state).toMatchSnapshot();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ exports[`Settings component renders correctly 1`] = `
activeKey="/settings"
id="settings-tabs"
onSelect={[Function]}
unmountOnExit={true}
>
<Tab
eventKey="/settings"
Expand Down
Loading

0 comments on commit 4f06604

Please sign in to comment.