foreman-tasks 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc +2 -22
  3. data/app/controllers/foreman_tasks/api/tasks_controller.rb +1 -1
  4. data/{.babelrc.js → babel.config.js} +0 -0
  5. data/lib/foreman_tasks/engine.rb +1 -1
  6. data/lib/foreman_tasks/version.rb +1 -1
  7. data/package.json +17 -69
  8. data/test/controllers/api/tasks_controller_test.rb +9 -0
  9. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Errors.test.js +1 -1
  10. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Locks.test.js +1 -1
  11. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Raw.test.js +1 -1
  12. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/RunningSteps.test.js +1 -1
  13. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Task.test.js +1 -1
  14. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/TaskInfo.test.js +1 -1
  15. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetails.stories.js +6 -2
  16. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetails.test.js +1 -1
  17. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsActions.test.js +1 -1
  18. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsReducer.test.js +1 -1
  19. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/integration.test.js +1 -1
  20. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/PausedTasksCard/PausedTasksCard.stories.js +44 -40
  21. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/PausedTasksCard/PausedTasksCard.test.js +1 -1
  22. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/RunningTasksCard/RunningTasksCard.stories.js +45 -40
  23. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/RunningTasksCard/RunningTasksCard.test.js +1 -1
  24. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.stories.js +27 -22
  25. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.test.js +1 -1
  26. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.stories.js +61 -56
  27. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.test.js +1 -1
  28. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/TasksDonutCard.stories.js +40 -35
  29. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/TasksDonutCard.test.js +1 -1
  30. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChart.stories.js +21 -20
  31. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChart.test.js +1 -1
  32. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/TasksCardsGrid.stories.js +40 -39
  33. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/TasksCardsGrid.test.js +1 -1
  34. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.stories.js +16 -17
  35. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.test.js +1 -2
  36. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/TimeDropDown.stories.mdx +57 -0
  37. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/TimeDropDown.test.js +1 -1
  38. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/TasksTimeRow.stories.js +36 -18
  39. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/TasksTimeRow.test.js +1 -1
  40. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboard.test.js +1 -1
  41. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardActions.test.js +1 -1
  42. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardReducer.test.js +1 -1
  43. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardSelectors.test.js +1 -1
  44. data/webpack/ForemanTasks/Components/TasksTable/Components/CancelConfirm.js +53 -0
  45. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmationModals.js +56 -0
  46. data/webpack/ForemanTasks/Components/TasksTable/Components/ResumeConfirm.js +52 -0
  47. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/ActionSelectButton.test.js +1 -1
  48. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/CancelConfirm.test.js +26 -0
  49. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/ConfirmationModals.test.js +24 -0
  50. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/ResumeConfirm.test.js +26 -0
  51. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/TableSelectionCell.test.js +1 -1
  52. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/TableSelectionHeaderCell.test.js +1 -1
  53. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/CancelConfirm.test.js.snap +65 -0
  54. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/ConfirmationModals.test.js.snap +30 -0
  55. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/ResumeConfirm.test.js.snap +63 -0
  56. data/webpack/ForemanTasks/Components/TasksTable/TasksTable.js +22 -12
  57. data/webpack/ForemanTasks/Components/TasksTable/TasksTableActions.js +15 -18
  58. data/webpack/ForemanTasks/Components/TasksTable/TasksTableConstants.js +6 -2
  59. data/webpack/ForemanTasks/Components/TasksTable/TasksTablePage.js +54 -18
  60. data/webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js +5 -7
  61. data/webpack/ForemanTasks/Components/TasksTable/TasksTableSelectors.js +18 -16
  62. data/webpack/ForemanTasks/Components/TasksTable/__tests__/SubTasksPage.test.js +1 -1
  63. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksIndexPage.test.js +1 -1
  64. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTable.fixtures.js +7 -3
  65. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTable.test.js +1 -1
  66. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableActions.test.js +1 -1
  67. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTablePage.test.js +1 -1
  68. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableReducer.test.js +6 -7
  69. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/SubTasksPage.test.js.snap +9 -3
  70. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksIndexPage.test.js.snap +9 -3
  71. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTablePage.test.js.snap +116 -18
  72. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTableReducer.test.js.snap +9 -16
  73. data/webpack/ForemanTasks/Components/TasksTable/index.js +3 -2
  74. data/webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js +4 -4
  75. data/webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.test.js +1 -1
  76. data/webpack/ForemanTasks/Components/common/ActionButtons/CancelButton.test.js +1 -2
  77. data/webpack/ForemanTasks/Components/common/ActionButtons/ResumeButton.test.js +2 -2
  78. data/webpack/ForemanTasks/Components/common/ActionButtons/__snapshots__/ActionButton.test.js.snap +3 -3
  79. data/webpack/ForemanTasks/ForemanTasks.test.js +1 -1
  80. data/webpack/ForemanTasks/Routes/ForemanTasksRouter.test.js +1 -1
  81. data/webpack/ForemanTasks/Routes/ForemanTasksRoutes.test.js +2 -3
  82. data/webpack/ForemanTasks/Routes/ShowTask/__tests__/ShowTask.test.js +1 -1
  83. data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalActions.js +2 -0
  84. data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalHooks.js +10 -0
  85. data/webpack/__mocks__/foremanReact/components/ForemanModal/index.js +4 -0
  86. metadata +16 -16
  87. data/.storybook/addons.js +0 -2
  88. data/.storybook/config.js +0 -7
  89. data/.storybook/webpack.config.js +0 -84
  90. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/TimeDropDown.stories.js +0 -23
  91. data/webpack/ForemanTasks/Components/TasksTable/Components/ActionConfirmation.js +0 -49
  92. data/webpack/ForemanTasks/Components/TasksTable/Components/CancelResumeConfirm.js +0 -51
  93. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/ActionConfirmation.test.js +0 -18
  94. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/CancelResumeConfirm.test.js +0 -28
  95. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/ActionConfirmation.test.js.snap +0 -89
  96. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/CancelResumeConfirm.test.js.snap +0 -37
  97. data/webpack/stories/index.js +0 -10
  98. data/webpack/stories/index.scss +0 -7
  99. data/webpack/test_setup.js +0 -7
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import TableSelectionCell from '../TableSelectionCell';
4
4
 
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import TableSelectionHeaderCell from '../TableSelectionHeaderCell';
4
4
 
@@ -0,0 +1,65 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`CancelConfirm renders CANCEL modal 1`] = `
4
+ <ForemanModal
5
+ id="cancelConfirmModal"
6
+ title="Cancel Selected Tasks"
7
+ >
8
+ <Component />
9
+ This will cancel 1 task(s), putting them in the stopped state. Are you sure?
10
+ <Component>
11
+ <Button
12
+ active={false}
13
+ block={false}
14
+ bsClass="btn"
15
+ bsStyle="default"
16
+ disabled={false}
17
+ onClick={[Function]}
18
+ >
19
+ No
20
+ </Button>
21
+ <Button
22
+ active={false}
23
+ block={false}
24
+ bsClass="btn"
25
+ bsStyle="primary"
26
+ disabled={false}
27
+ onClick={[Function]}
28
+ >
29
+ Yes
30
+ </Button>
31
+ </Component>
32
+ </ForemanModal>
33
+ `;
34
+
35
+ exports[`CancelConfirm renders CANCEL_SELECTED modal 1`] = `
36
+ <ForemanModal
37
+ id="cancelSelectedConfirmModal"
38
+ title="Cancel Selected Tasks"
39
+ >
40
+ <Component />
41
+ This will cancel 1 task(s), putting them in the stopped state. Are you sure?
42
+ <Component>
43
+ <Button
44
+ active={false}
45
+ block={false}
46
+ bsClass="btn"
47
+ bsStyle="default"
48
+ disabled={false}
49
+ onClick={[Function]}
50
+ >
51
+ No
52
+ </Button>
53
+ <Button
54
+ active={false}
55
+ block={false}
56
+ bsClass="btn"
57
+ bsStyle="primary"
58
+ disabled={false}
59
+ onClick={[Function]}
60
+ >
61
+ Yes
62
+ </Button>
63
+ </Component>
64
+ </ForemanModal>
65
+ `;
@@ -0,0 +1,30 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ConfirmationModals renders ConfirmationModals 1`] = `
4
+ <Fragment>
5
+ <CancelConfirm
6
+ action={[MockFunction]}
7
+ closeModal={[MockFunction]}
8
+ id="cancelConfirmModal"
9
+ selectedRowsLen={1}
10
+ />
11
+ <ResumeConfirm
12
+ action={[MockFunction]}
13
+ closeModal={[MockFunction]}
14
+ id="resumeConfirmModal"
15
+ selectedRowsLen={1}
16
+ />
17
+ <CancelConfirm
18
+ action={[MockFunction]}
19
+ closeModal={[MockFunction]}
20
+ id="cancelSelectedConfirmModal"
21
+ selectedRowsLen={7}
22
+ />
23
+ <ResumeConfirm
24
+ action={[MockFunction]}
25
+ closeModal={[MockFunction]}
26
+ id="resumeSelectedConfirmModal"
27
+ selectedRowsLen={7}
28
+ />
29
+ </Fragment>
30
+ `;
@@ -0,0 +1,63 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ResumeConfirm renders RESUME modal 1`] = `
4
+ <ForemanModal
5
+ id="resumeConfirmModal"
6
+ title="Resume Selected Tasks"
7
+ >
8
+ This will resume 3 task(s), putting them in the running state. Are you sure?
9
+ <Component>
10
+ <Button
11
+ active={false}
12
+ block={false}
13
+ bsClass="btn"
14
+ bsStyle="default"
15
+ disabled={false}
16
+ onClick={[Function]}
17
+ >
18
+ No
19
+ </Button>
20
+ <Button
21
+ active={false}
22
+ block={false}
23
+ bsClass="btn"
24
+ bsStyle="primary"
25
+ disabled={false}
26
+ onClick={[Function]}
27
+ >
28
+ Yes
29
+ </Button>
30
+ </Component>
31
+ </ForemanModal>
32
+ `;
33
+
34
+ exports[`ResumeConfirm renders RESUME_SELECTED modal 1`] = `
35
+ <ForemanModal
36
+ id="resumeSelectedConfirmModal"
37
+ title="Resume Selected Tasks"
38
+ >
39
+ This will resume 3 task(s), putting them in the running state. Are you sure?
40
+ <Component>
41
+ <Button
42
+ active={false}
43
+ block={false}
44
+ bsClass="btn"
45
+ bsStyle="default"
46
+ disabled={false}
47
+ onClick={[Function]}
48
+ >
49
+ No
50
+ </Button>
51
+ <Button
52
+ active={false}
53
+ block={false}
54
+ bsClass="btn"
55
+ bsStyle="primary"
56
+ disabled={false}
57
+ onClick={[Function]}
58
+ >
59
+ Yes
60
+ </Button>
61
+ </Component>
62
+ </ForemanModal>
63
+ `;
@@ -17,21 +17,20 @@ const TasksTable = ({
17
17
  history,
18
18
  itemCount,
19
19
  pagination,
20
- cancelTask,
21
- resumeTask,
22
20
  selectedRows,
23
21
  selectAllRows,
24
22
  unselectAllRows,
25
23
  selectRow,
26
24
  unselectRow,
27
- parentTaskID,
25
+ openClickedModal,
26
+ modalProps,
28
27
  }) => {
29
28
  const url = history.location.pathname + history.location.search;
30
29
  const uriQuery = getURIQuery(url);
31
30
 
32
31
  useEffect(() => {
33
32
  getTableItems(url);
34
- }, [history.location.search]);
33
+ }, [getTableItems, url]);
35
34
 
36
35
  const getSelectionController = () => {
37
36
  const checkAllRowsSelected = () => results.length === selectedRows.length;
@@ -82,11 +81,19 @@ const TasksTable = ({
82
81
  };
83
82
 
84
83
  const taskActions = {
85
- cancel: (id, name) => {
86
- cancelTask(id, name, url, parentTaskID);
84
+ cancelTask: (taskId, taskName) => {
85
+ openClickedModal({
86
+ taskId,
87
+ taskName,
88
+ setModalOpen: modalProps.cancelModal.setModalOpen,
89
+ });
87
90
  },
88
- resume: (id, name) => {
89
- resumeTask(id, name, url, parentTaskID);
91
+ resumeTask: (taskId, taskName) => {
92
+ openClickedModal({
93
+ taskId,
94
+ taskName,
95
+ setModalOpen: modalProps.resumeModal.setModalOpen,
96
+ });
90
97
  },
91
98
  };
92
99
 
@@ -126,14 +133,18 @@ TasksTable.propTypes = {
126
133
  perPage: PropTypes.number,
127
134
  }),
128
135
  history: PropTypes.object.isRequired,
129
- cancelTask: PropTypes.func.isRequired,
130
- resumeTask: PropTypes.func.isRequired,
136
+ openClickedModal: PropTypes.func.isRequired,
131
137
  selectedRows: PropTypes.array,
132
138
  selectAllRows: PropTypes.func.isRequired,
133
139
  unselectAllRows: PropTypes.func.isRequired,
134
140
  selectRow: PropTypes.func.isRequired,
135
141
  unselectRow: PropTypes.func.isRequired,
136
- parentTaskID: PropTypes.string,
142
+ modalProps: PropTypes.shape({
143
+ cancelSelectedModal: PropTypes.object,
144
+ resumeSelectedModal: PropTypes.object,
145
+ cancelModal: PropTypes.object,
146
+ resumeModal: PropTypes.object,
147
+ }).isRequired,
137
148
  };
138
149
 
139
150
  TasksTable.defaultProps = {
@@ -144,7 +155,6 @@ TasksTable.defaultProps = {
144
155
  perPage: 20,
145
156
  },
146
157
  selectedRows: [],
147
- parentTaskID: null,
148
158
  };
149
159
 
150
160
  export default TasksTable;
@@ -8,10 +8,9 @@ import {
8
8
  SELECT_ROWS,
9
9
  UNSELECT_ALL_ROWS,
10
10
  UNSELECT_ROWS,
11
- TASKS_TABLE_SELECTED_MODAL,
12
- CLOSED,
13
11
  RESUME,
14
12
  CANCEL,
13
+ UPDATE_CLICKED,
15
14
  } from './TasksTableConstants';
16
15
  import { getApiPathname } from './TasksTableHelpers';
17
16
  import { fetchTasksSummary } from '../TasksDashboard/TasksDashboardActions';
@@ -94,7 +93,12 @@ export const unselectRow = id => ({
94
93
  payload: id,
95
94
  });
96
95
 
97
- export const actionSelected = (actionType, selected, url) => async dispatch => {
96
+ export const actionSelected = (
97
+ actionType,
98
+ selected,
99
+ url,
100
+ parentTaskID
101
+ ) => async dispatch => {
98
102
  let notAllActionable = false;
99
103
  let someActionable = false;
100
104
  const promises = selected.map(task => {
@@ -122,21 +126,14 @@ export const actionSelected = (actionType, selected, url) => async dispatch => {
122
126
  if (someActionable) {
123
127
  await Promise.all(promises);
124
128
  dispatch(getTableItems(url));
125
- dispatch(fetchTasksSummary(getURIQuery(url).time));
129
+ dispatch(fetchTasksSummary(getURIQuery(url).time, parentTaskID));
126
130
  }
127
131
  };
128
132
 
129
- export const showCancelSelcetedModal = () => ({
130
- type: TASKS_TABLE_SELECTED_MODAL,
131
- payload: CANCEL,
132
- });
133
-
134
- export const showResumeSelcetedModal = () => ({
135
- type: TASKS_TABLE_SELECTED_MODAL,
136
- payload: RESUME,
137
- });
138
-
139
- export const hideSelcetedModal = () => ({
140
- type: TASKS_TABLE_SELECTED_MODAL,
141
- payload: CLOSED,
142
- });
133
+ export const openClickedModal = ({ taskId, taskName, setModalOpen }) => {
134
+ setModalOpen();
135
+ return {
136
+ type: UPDATE_CLICKED,
137
+ payload: { clicked: { taskId, taskName } },
138
+ };
139
+ };
@@ -10,7 +10,11 @@ export const UNSELECT_ROWS = 'UNSELECT_ROWS';
10
10
  export const UNSELECT_ALL_ROWS = 'UNSELECT_ALL_ROWS';
11
11
  export const CANCEL = 'CANCEL';
12
12
  export const RESUME = 'RESUME';
13
- export const CLOSED = 'CLOSED';
14
13
 
15
- export const TASKS_TABLE_SELECTED_MODAL = 'TASKS_TABLE_SELECTED_MODAL';
14
+ export const CANCEL_CONFIRM_MODAL_ID = 'cancelConfirmModal';
15
+ export const RESUME_CONFIRM_MODAL_ID = 'resumeConfirmModal';
16
+ export const CANCEL_SELECTED_CONFIRM_MODAL_ID = 'cancelSelectedConfirmModal';
17
+ export const RESUME_SELECTED_CONFIRM_MODAL_ID = 'resumeSelectedConfirmModal';
18
+ export const UPDATE_CLICKED = 'UPDATE_CLICKED';
19
+
16
20
  export const TASKS_SEARCH_PROPS = getControllerSearchProps('tasks');
@@ -7,20 +7,24 @@ import { translate as __ } from 'foremanReact/common/I18n';
7
7
  import { getURIQuery } from 'foremanReact/common/helpers';
8
8
  import ExportButton from 'foremanReact/routes/common/PageLayout/components/ExportButton/ExportButton';
9
9
  import { STATUS } from 'foremanReact/constants';
10
+ import { useForemanModal } from 'foremanReact/components/ForemanModal/ForemanModalHooks';
10
11
  import TasksDashboard from '../TasksDashboard';
11
12
  import TasksTable from './TasksTable';
12
13
  import { resolveSearchQuery, addSearchToURL } from './TasksTableHelpers';
13
- import { CancelResumeConfirm } from './Components/CancelResumeConfirm';
14
+ import { ConfirmationModals } from './Components/ConfirmationModals';
14
15
  import {
15
16
  TASKS_SEARCH_PROPS,
16
17
  RESUME,
17
18
  CANCEL,
18
- CLOSED,
19
+ CANCEL_SELECTED_CONFIRM_MODAL_ID,
20
+ RESUME_SELECTED_CONFIRM_MODAL_ID,
21
+ RESUME_CONFIRM_MODAL_ID,
22
+ CANCEL_CONFIRM_MODAL_ID,
19
23
  } from './TasksTableConstants';
20
24
  import { ActionSelectButton } from './Components/ActionSelectButton';
21
25
  import './TasksTablePage.scss';
22
26
 
23
- const TasksTablePage = ({ getBreadcrumbs, history, ...props }) => {
27
+ const TasksTablePage = ({ getBreadcrumbs, history, clicked, ...props }) => {
24
28
  const url = history.location.pathname + history.location.search;
25
29
  const uriQuery = getURIQuery(url);
26
30
  const onSearch = searchQuery => {
@@ -40,18 +44,47 @@ const TasksTablePage = ({ getBreadcrumbs, history, ...props }) => {
40
44
  }));
41
45
  };
42
46
 
43
- const TaskSelectedAction = (id, name) => {
44
- props.actionSelected(id, name, url);
47
+ const modalProps = {
48
+ cancelSelectedModal: useForemanModal({
49
+ id: CANCEL_SELECTED_CONFIRM_MODAL_ID,
50
+ }),
51
+ resumeSelectedModal: useForemanModal({
52
+ id: RESUME_SELECTED_CONFIRM_MODAL_ID,
53
+ }),
54
+ cancelModal: useForemanModal({ id: CANCEL_CONFIRM_MODAL_ID }),
55
+ resumeModal: useForemanModal({ id: RESUME_CONFIRM_MODAL_ID }),
45
56
  };
46
57
 
58
+ const tasksActions = {
59
+ cancelSelectedTasks: () => {
60
+ props.actionSelected(CANCEL, getSelected(), url, props.parentTaskID);
61
+ },
62
+ cancelTask: () => {
63
+ props.cancelTask(
64
+ clicked.taskId,
65
+ clicked.taskName,
66
+ url,
67
+ props.parentTaskID
68
+ );
69
+ },
70
+ resumeSelectedTasks: () => {
71
+ props.actionSelected(RESUME, getSelected(), url, props.parentTaskID);
72
+ },
73
+ resumeTask: () => {
74
+ props.resumeTask(
75
+ clicked.taskId,
76
+ clicked.taskName,
77
+ url,
78
+ props.parentTaskID
79
+ );
80
+ },
81
+ };
47
82
  return (
48
83
  <div className="tasks-table-wrapper">
49
- <CancelResumeConfirm
50
- closeModal={props.hideSelcetedModal}
51
- action={TaskSelectedAction}
52
- selected={getSelected()}
53
- modalStatus={props.modalStatus}
84
+ <ConfirmationModals
85
+ tasksActions={tasksActions}
54
86
  selectedRowsLen={props.selectedRows.length}
87
+ modalProps={modalProps}
55
88
  />
56
89
  <PageLayout
57
90
  searchable
@@ -68,8 +101,8 @@ const TasksTablePage = ({ getBreadcrumbs, history, ...props }) => {
68
101
  />
69
102
  <ActionSelectButton
70
103
  disabled={props.selectedRows.length < 1}
71
- onCancel={props.showCancelSelcetedModal}
72
- onResume={props.showResumeSelcetedModal}
104
+ onCancel={modalProps.cancelSelectedModal.setModalOpen}
105
+ onResume={modalProps.resumeSelectedModal.setModalOpen}
73
106
  />
74
107
  </React.Fragment>
75
108
  }
@@ -78,7 +111,7 @@ const TasksTablePage = ({ getBreadcrumbs, history, ...props }) => {
78
111
  <TasksDashboard history={history} parentTaskID={props.parentTaskID} />
79
112
  }
80
113
  >
81
- <TasksTable history={history} {...props} />
114
+ <TasksTable history={history} {...props} modalProps={modalProps} />
82
115
  </PageLayout>
83
116
  </div>
84
117
  );
@@ -92,20 +125,23 @@ TasksTablePage.propTypes = {
92
125
  status: PropTypes.oneOf(Object.keys(STATUS)),
93
126
  history: PropTypes.object.isRequired,
94
127
  actionSelected: PropTypes.func.isRequired,
128
+ cancelTask: PropTypes.func.isRequired,
129
+ resumeTask: PropTypes.func.isRequired,
95
130
  selectedRows: PropTypes.arrayOf(PropTypes.string),
96
- showResumeSelcetedModal: PropTypes.func.isRequired,
97
- showCancelSelcetedModal: PropTypes.func.isRequired,
98
- hideSelcetedModal: PropTypes.func.isRequired,
99
- modalStatus: PropTypes.oneOf([CANCEL, RESUME, CLOSED]),
100
131
  parentTaskID: PropTypes.string,
132
+ clicked: PropTypes.shape({
133
+ taskId: PropTypes.string,
134
+ taskName: PropTypes.string,
135
+ parentTaskID: PropTypes.string,
136
+ }),
101
137
  };
102
138
 
103
139
  TasksTablePage.defaultProps = {
104
140
  actionName: '',
105
141
  status: STATUS.PENDING,
106
142
  selectedRows: [],
107
- modalStatus: CLOSED,
108
143
  parentTaskID: null,
144
+ clicked: {},
109
145
  };
110
146
 
111
147
  export default TasksTablePage;