foreman-tasks 0.17.6 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc +2 -22
  3. data/.rubocop.yml +12 -12
  4. data/.rubocop_todo.yml +34 -116
  5. data/.travis.yml +2 -2
  6. data/app/controllers/foreman_tasks/api/recurring_logics_controller.rb +20 -1
  7. data/app/controllers/foreman_tasks/api/tasks_controller.rb +66 -11
  8. data/app/controllers/foreman_tasks/concerns/hosts_controller_extension.rb +1 -1
  9. data/app/controllers/foreman_tasks/recurring_logics_controller.rb +19 -0
  10. data/app/controllers/foreman_tasks/tasks_controller.rb +3 -11
  11. data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +0 -2
  12. data/app/lib/actions/helpers/humanizer.rb +1 -3
  13. data/app/lib/actions/proxy_action.rb +33 -12
  14. data/app/lib/foreman_tasks/concerns/polling_action_extensions.rb +12 -0
  15. data/app/models/foreman_tasks/concerns/action_triggering.rb +1 -1
  16. data/app/models/foreman_tasks/recurring_logic.rb +1 -0
  17. data/app/models/foreman_tasks/remote_task.rb +1 -0
  18. data/app/models/foreman_tasks/task.rb +8 -0
  19. data/app/models/foreman_tasks/task/dynflow_task.rb +1 -1
  20. data/app/models/foreman_tasks/task/search.rb +11 -1
  21. data/app/models/setting/foreman_tasks.rb +7 -2
  22. data/app/services/ui_notifications/tasks/task_bulk_cancel.rb +36 -0
  23. data/app/services/ui_notifications/tasks/task_bulk_resume.rb +38 -0
  24. data/app/services/ui_notifications/tasks/task_bulk_stop.rb +36 -0
  25. data/app/views/foreman_tasks/api/recurring_logics/base.json.rabl +2 -1
  26. data/app/views/foreman_tasks/api/tasks/details.json.rabl +1 -1
  27. data/app/views/foreman_tasks/api/tasks/show.json.rabl +1 -1
  28. data/app/views/foreman_tasks/recurring_logics/index.html.erb +30 -0
  29. data/app/views/foreman_tasks/tasks/show.html.erb +3 -0
  30. data/babel.config.js +3 -0
  31. data/config/routes.rb +8 -0
  32. data/db/migrate/20200517215015_rename_bookmarks_controller.rb +35 -0
  33. data/db/migrate/20200519093217_drop_dynflow_allow_dangerous_actions_setting.foreman_tasks.rb +5 -0
  34. data/db/seeds.d/30-notification_blueprints.rb +21 -0
  35. data/foreman-tasks.gemspec +5 -6
  36. data/gemfile.d/foreman-tasks.rb +1 -0
  37. data/lib/foreman_tasks/dynflow/console_authorizer.rb +2 -2
  38. data/lib/foreman_tasks/engine.rb +17 -14
  39. data/lib/foreman_tasks/tasks/cleanup.rake +1 -1
  40. data/lib/foreman_tasks/tasks/export_tasks.rake +2 -2
  41. data/lib/foreman_tasks/test_extensions.rb +1 -1
  42. data/lib/foreman_tasks/version.rb +1 -1
  43. data/locale/action_names.rb +2 -2
  44. data/locale/en/foreman_tasks.po +227 -41
  45. data/locale/foreman_tasks.pot +579 -288
  46. data/package.json +19 -79
  47. data/script/rails +2 -2
  48. data/script/travis_run_js_tests.sh +2 -2
  49. data/test/controllers/api/tasks_controller_test.rb +9 -0
  50. data/test/factories/task_factory.rb +34 -2
  51. data/test/foreman_tasks_test_helper.rb +4 -0
  52. data/test/lib/concerns/polling_action_extensions_test.rb +34 -0
  53. data/test/unit/actions/action_with_sub_plans_test.rb +1 -1
  54. data/test/unit/task_test.rb +160 -74
  55. data/webpack/ForemanTasks/Components/TaskActions/TaskAction.test.js +60 -0
  56. data/webpack/ForemanTasks/Components/TaskActions/TaskActionHelpers.js +67 -0
  57. data/webpack/ForemanTasks/Components/TaskActions/TaskActionHelpers.test.js +46 -0
  58. data/webpack/ForemanTasks/Components/TaskActions/TaskActionsConstants.js +16 -0
  59. data/webpack/ForemanTasks/Components/TaskActions/UnlockModals.js +60 -0
  60. data/webpack/ForemanTasks/Components/TaskActions/UnlockModals.test.js +14 -0
  61. data/webpack/ForemanTasks/Components/TaskActions/__snapshots__/TaskAction.test.js.snap +233 -0
  62. data/webpack/ForemanTasks/Components/TaskActions/__snapshots__/UnlockModals.test.js.snap +25 -0
  63. data/webpack/ForemanTasks/Components/TaskActions/index.js +115 -0
  64. data/webpack/ForemanTasks/Components/TaskDetails/Components/Task.js +132 -150
  65. data/webpack/ForemanTasks/Components/TaskDetails/Components/TaskInfo.js +1 -4
  66. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Errors.test.js +1 -1
  67. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Locks.test.js +1 -1
  68. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Raw.test.js +1 -1
  69. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/RunningSteps.test.js +1 -1
  70. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Task.test.js +68 -3
  71. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/TaskInfo.test.js +1 -2
  72. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/Task.test.js.snap +104 -71
  73. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/TaskInfo.test.js.snap +9 -15
  74. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetails.stories.js +6 -2
  75. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsActions.js +2 -17
  76. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsConstants.js +0 -5
  77. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsReducer.js +0 -6
  78. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsSelectors.js +3 -9
  79. data/webpack/ForemanTasks/Components/TaskDetails/TasksDetailsHelper.js +6 -1
  80. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetails.test.js +6 -1
  81. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsActions.test.js +1 -1
  82. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsReducer.test.js +1 -1
  83. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetails.test.js.snap +3 -7
  84. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/integration.test.js +5 -1
  85. data/webpack/ForemanTasks/Components/TaskDetails/index.js +6 -8
  86. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/PausedTasksCard/PausedTasksCard.stories.js +44 -40
  87. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/PausedTasksCard/PausedTasksCard.test.js +1 -1
  88. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/RunningTasksCard/RunningTasksCard.stories.js +45 -40
  89. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/RunningTasksCard/RunningTasksCard.test.js +1 -1
  90. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.stories.js +27 -22
  91. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.test.js +1 -1
  92. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.stories.js +61 -56
  93. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.test.js +1 -1
  94. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/TasksDonutCard.stories.js +40 -35
  95. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/TasksDonutCard.test.js +1 -1
  96. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChart.stories.js +21 -20
  97. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChart.test.js +1 -1
  98. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/TasksCardsGrid.stories.js +40 -39
  99. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/TasksCardsGrid.test.js +1 -1
  100. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.stories.js +16 -17
  101. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.test.js +1 -2
  102. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/TimeDropDown.stories.mdx +57 -0
  103. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/TimeDropDown.test.js +1 -1
  104. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/TasksTimeRow.stories.js +36 -18
  105. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/TasksTimeRow.test.js +1 -1
  106. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardConstants.js +5 -0
  107. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js +3 -2
  108. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboard.test.js +1 -1
  109. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardActions.test.js +1 -1
  110. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardReducer.test.js +1 -1
  111. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardSelectors.test.js +1 -1
  112. data/webpack/ForemanTasks/Components/TasksTable/Components/ActionSelectButton.js +14 -1
  113. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/ConfirmModal.js +83 -0
  114. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/ConfirmModalActions.js +106 -0
  115. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/ConfirmModalReducer.js +38 -0
  116. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/ConfirmModalSelectors.js +45 -0
  117. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/ConfirmModal.test.js +36 -0
  118. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/ConfirmModalActions.test.js +205 -0
  119. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/ConfirmModalReducer.test.js +27 -0
  120. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/ConfirmModalSelectors.test.js +54 -0
  121. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/__snapshots__/ConfirmModal.test.js.snap +41 -0
  122. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/__snapshots__/ConfirmModalReducer.test.js.snap +19 -0
  123. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/__snapshots__/ConfirmModalSelectors.test.js.snap +30 -0
  124. data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/index.js +29 -0
  125. data/webpack/ForemanTasks/Components/TasksTable/Components/SelectAllAlert.js +43 -0
  126. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/ActionSelectButton.test.js +2 -1
  127. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/SelectAllAlert.test.js +29 -0
  128. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/TableSelectionCell.test.js +1 -1
  129. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/TableSelectionHeaderCell.test.js +1 -1
  130. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/ActionSelectButton.test.js.snap +11 -0
  131. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/SelectAllAlert.test.js.snap +75 -0
  132. data/webpack/ForemanTasks/Components/TasksTable/SubTasksPage.js +4 -1
  133. data/webpack/ForemanTasks/Components/TasksTable/TasksBulkActions.js +247 -0
  134. data/webpack/ForemanTasks/Components/TasksTable/TasksTable.js +50 -22
  135. data/webpack/ForemanTasks/Components/TasksTable/TasksTableActions.js +62 -101
  136. data/webpack/ForemanTasks/Components/TasksTable/TasksTableConstants.js +18 -5
  137. data/webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js +4 -3
  138. data/webpack/ForemanTasks/Components/TasksTable/TasksTablePage.js +65 -38
  139. data/webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js +26 -9
  140. data/webpack/ForemanTasks/Components/TasksTable/TasksTableSchema.js +2 -2
  141. data/webpack/ForemanTasks/Components/TasksTable/TasksTableSelectors.js +27 -16
  142. data/webpack/ForemanTasks/Components/TasksTable/__tests__/SubTasksPage.test.js +1 -1
  143. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksBulkActions.test.js +147 -0
  144. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksIndexPage.test.js +1 -1
  145. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTable.fixtures.js +4 -7
  146. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTable.test.js +1 -1
  147. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableActions.test.js +46 -74
  148. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableHelpers.test.js +17 -1
  149. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTablePage.test.js +10 -2
  150. data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableReducer.test.js +28 -8
  151. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/SubTasksPage.test.js.snap +5 -7
  152. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksBulkActions.test.js.snap +336 -0
  153. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksIndexPage.test.js.snap +4 -7
  154. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTableActions.test.js.snap +22 -158
  155. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTablePage.test.js.snap +66 -44
  156. data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTableReducer.test.js.snap +43 -16
  157. data/webpack/ForemanTasks/Components/TasksTable/formatters/__test__/selectionHeaderCellFormatter.test.js +1 -1
  158. data/webpack/ForemanTasks/Components/TasksTable/formatters/selectionHeaderCellFormatter.js +2 -2
  159. data/webpack/ForemanTasks/Components/TasksTable/index.js +11 -4
  160. data/webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js +49 -21
  161. data/webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.test.js +61 -14
  162. data/webpack/ForemanTasks/Components/common/ActionButtons/__snapshots__/ActionButton.test.js.snap +80 -21
  163. data/webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.scss +9 -0
  164. data/webpack/ForemanTasks/Components/common/ClickConfirmation/ClickConfirmation.test.js +44 -0
  165. data/webpack/ForemanTasks/Components/common/ClickConfirmation/__snapshots__/ClickConfirmation.test.js.snap +52 -0
  166. data/webpack/ForemanTasks/Components/common/ClickConfirmation/index.js +59 -66
  167. data/webpack/ForemanTasks/Components/common/ToastsHelpers/ToastTypesConstants.js +11 -0
  168. data/webpack/ForemanTasks/Components/common/ToastsHelpers/index.js +15 -0
  169. data/webpack/ForemanTasks/ForemanTasks.test.js +1 -1
  170. data/webpack/ForemanTasks/ForemanTasksReducers.js +2 -0
  171. data/webpack/ForemanTasks/Routes/ForemanTasksRouter.test.js +1 -1
  172. data/webpack/ForemanTasks/Routes/ForemanTasksRoutes.test.js +4 -4
  173. data/webpack/ForemanTasks/Routes/ShowTask/__tests__/ShowTask.test.js +1 -1
  174. data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalActions.js +2 -0
  175. data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalHooks.js +10 -0
  176. data/webpack/__mocks__/foremanReact/components/ForemanModal/index.js +18 -0
  177. data/webpack/__mocks__/foremanReact/components/common/ActionButtons/ActionButtons.js +3 -0
  178. metadata +71 -30
  179. data/.babelrc +0 -35
  180. data/.storybook/addons.js +0 -2
  181. data/.storybook/config.js +0 -7
  182. data/.storybook/webpack.config.js +0 -63
  183. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/TimeDropDown.stories.js +0 -23
  184. data/webpack/ForemanTasks/Components/TasksTable/Components/ActionConfirmation.js +0 -49
  185. data/webpack/ForemanTasks/Components/TasksTable/Components/CancelResumeConfirm.js +0 -51
  186. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/ActionConfirmation.test.js +0 -18
  187. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/CancelResumeConfirm.test.js +0 -28
  188. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/ActionConfirmation.test.js.snap +0 -89
  189. data/webpack/ForemanTasks/Components/TasksTable/Components/__test__/__snapshots__/CancelResumeConfirm.test.js.snap +0 -37
  190. data/webpack/ForemanTasks/Components/common/ActionButtons/CancelButton.js +0 -23
  191. data/webpack/ForemanTasks/Components/common/ActionButtons/CancelButton.test.js +0 -27
  192. data/webpack/ForemanTasks/Components/common/ActionButtons/ResumeButton.js +0 -23
  193. data/webpack/ForemanTasks/Components/common/ActionButtons/ResumeButton.test.js +0 -27
  194. data/webpack/ForemanTasks/Components/common/ActionButtons/__snapshots__/CancelButton.test.js.snap +0 -15
  195. data/webpack/ForemanTasks/Components/common/ActionButtons/__snapshots__/ResumeButton.test.js.snap +0 -15
  196. data/webpack/stories/index.js +0 -10
  197. data/webpack/stories/index.scss +0 -7
  198. data/webpack/test_setup.js +0 -6
@@ -0,0 +1,25 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ForceUnlockModal render 1`] = `
4
+ <ClickConfirmation
5
+ body="Resources for 1 task(s) will be unlocked and will not prevent other tasks from being run. As the task(s) might be still running, it should be avoided to use this unless you are really sure the task(s) got stuck."
6
+ confirmAction="Force Unlock"
7
+ confirmType="danger"
8
+ confirmationMessage="I understand that this may cause harm and have working database backups of all backend services."
9
+ id="forceUnlockModal"
10
+ onClick={[MockFunction]}
11
+ title="Force Unlock"
12
+ />
13
+ `;
14
+
15
+ exports[`UnlockModal render 1`] = `
16
+ <ClickConfirmation
17
+ body="This will unlock the resources that the task is running against. Please note that this might lead to inconsistent state and should be used with caution, after making sure that the task can't be resumed."
18
+ confirmAction="Unlock"
19
+ confirmType="warning"
20
+ confirmationMessage="I understand that this may cause harm and have working database backups of all backend services."
21
+ id="unlockModal"
22
+ onClick={[MockFunction]}
23
+ title="Unlock"
24
+ />
25
+ `;
@@ -0,0 +1,115 @@
1
+ import { sprintf } from 'foremanReact/common/I18n';
2
+ import API from 'foremanReact/API';
3
+ import { addToast } from 'foremanReact/redux/actions/toasts';
4
+ import {
5
+ TASKS_RESUME_REQUEST,
6
+ TASKS_RESUME_SUCCESS,
7
+ TASKS_RESUME_FAILURE,
8
+ TASKS_CANCEL_REQUEST,
9
+ TASKS_CANCEL_SUCCESS,
10
+ TASKS_CANCEL_FAILURE,
11
+ TASKS_FORCE_CANCEL_REQUEST,
12
+ TASKS_FORCE_CANCEL_SUCCESS,
13
+ TASKS_FORCE_CANCEL_FAILURE,
14
+ TASKS_UNLOCK_REQUEST,
15
+ TASKS_UNLOCK_SUCCESS,
16
+ TASKS_UNLOCK_FAILURE,
17
+ } from './TaskActionsConstants';
18
+ import { infoToastData } from '../common/ToastsHelpers/';
19
+ import {
20
+ resumeToastInfo,
21
+ cancelToastInfo,
22
+ forceCancelToastInfo,
23
+ unlockToastInfo,
24
+ toastDispatch,
25
+ } from './TaskActionHelpers';
26
+
27
+ export const cancelTaskRequest = (id, name) => async dispatch => {
28
+ dispatch(addToast(infoToastData(sprintf('Trying to cancel %s task', name))));
29
+ dispatch({ type: TASKS_CANCEL_REQUEST });
30
+ try {
31
+ await API.post(`/foreman_tasks/tasks/${id}/cancel`);
32
+ dispatch({ type: TASKS_CANCEL_SUCCESS });
33
+ toastDispatch({
34
+ type: 'cancelled',
35
+ name,
36
+ toastInfo: cancelToastInfo,
37
+ dispatch,
38
+ });
39
+ } catch (error) {
40
+ dispatch({ type: TASKS_CANCEL_FAILURE, payload: error });
41
+ toastDispatch({
42
+ type: 'skipped',
43
+ name,
44
+ toastInfo: cancelToastInfo,
45
+ dispatch,
46
+ });
47
+ }
48
+ };
49
+
50
+ export const resumeTaskRequest = (id, name) => async dispatch => {
51
+ dispatch({ type: TASKS_RESUME_REQUEST });
52
+ try {
53
+ await API.post(`/foreman_tasks/tasks/${id}/resume`);
54
+
55
+ dispatch({ type: TASKS_RESUME_SUCCESS });
56
+ toastDispatch({
57
+ type: 'resumed',
58
+ name,
59
+ toastInfo: resumeToastInfo,
60
+ dispatch,
61
+ });
62
+ } catch (error) {
63
+ dispatch({ type: TASKS_RESUME_FAILURE, payload: error });
64
+ toastDispatch({
65
+ type: 'failed',
66
+ name,
67
+ toastInfo: resumeToastInfo,
68
+ dispatch,
69
+ });
70
+ }
71
+ };
72
+
73
+ export const forceCancelTaskRequest = (id, name) => async dispatch => {
74
+ dispatch({ type: TASKS_FORCE_CANCEL_REQUEST });
75
+ try {
76
+ await API.post(`/foreman_tasks/tasks/${id}/force_unlock`);
77
+ dispatch({ type: TASKS_FORCE_CANCEL_SUCCESS });
78
+ toastDispatch({
79
+ type: 'forceCancelled',
80
+ name,
81
+ toastInfo: forceCancelToastInfo,
82
+ dispatch,
83
+ });
84
+ } catch ({ response }) {
85
+ dispatch({ type: TASKS_FORCE_CANCEL_FAILURE });
86
+ toastDispatch({
87
+ type: 'failed',
88
+ name,
89
+ toastInfo: forceCancelToastInfo,
90
+ dispatch,
91
+ });
92
+ }
93
+ };
94
+
95
+ export const unlockTaskRequest = (id, name) => async dispatch => {
96
+ dispatch({ type: TASKS_UNLOCK_REQUEST });
97
+ try {
98
+ await API.post(`/foreman_tasks/tasks/${id}/unlock`);
99
+ dispatch({ type: TASKS_UNLOCK_SUCCESS });
100
+ toastDispatch({
101
+ type: 'unlocked',
102
+ name,
103
+ toastInfo: unlockToastInfo,
104
+ dispatch,
105
+ });
106
+ } catch ({ response }) {
107
+ dispatch({ type: TASKS_UNLOCK_FAILURE });
108
+ toastDispatch({
109
+ type: 'failed',
110
+ name,
111
+ toastInfo: unlockToastInfo,
112
+ dispatch,
113
+ });
114
+ }
115
+ };
@@ -1,14 +1,17 @@
1
- import React, { Component } from 'react';
1
+ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { Grid, Row, Col, Button } from 'patternfly-react';
4
4
  import { translate as __ } from 'foremanReact/common/I18n';
5
+ import { useForemanModal } from 'foremanReact/components/ForemanModal/ForemanModalHooks';
5
6
  import TaskInfo from './TaskInfo';
6
- import { ClickConfirmation } from '../../common/ClickConfirmation';
7
- import { ResumeButton } from '../../common/ActionButtons/ResumeButton';
8
- import { CancelButton } from '../../common/ActionButtons/CancelButton';
7
+ import {
8
+ UNLOCK_MODAL,
9
+ FORCE_UNLOCK_MODAL,
10
+ } from '../../TaskActions/TaskActionsConstants';
11
+ import { ForceUnlockModal, UnlockModal } from '../../TaskActions/UnlockModals';
9
12
 
10
- class Task extends Component {
11
- taskProgressToggle = () => {
13
+ const Task = props => {
14
+ const taskProgressToggle = () => {
12
15
  const {
13
16
  timeoutId,
14
17
  refetchTaskDetails,
@@ -16,7 +19,7 @@ class Task extends Component {
16
19
  loading,
17
20
  taskReloadStop,
18
21
  taskReloadStart,
19
- } = this.props;
22
+ } = props;
20
23
  if (timeoutId) {
21
24
  taskReloadStop(timeoutId);
22
25
  } else {
@@ -24,153 +27,139 @@ class Task extends Component {
24
27
  }
25
28
  };
26
29
 
27
- render() {
28
- const {
29
- taskReload,
30
- externalId,
31
- id,
32
- state,
33
- allowDangerousActions,
34
- resumable,
35
- cancellable,
36
- hasSubTasks,
37
- parentTask,
38
- showUnlockModal,
39
- showForceUnlockModal,
40
- toggleUnlockModal,
41
- toggleForceUnlockModal,
42
- cancelTaskRequest,
43
- resumeTaskRequest,
44
- action,
45
- } = this.props;
46
- const modalUnlock = (
47
- <ClickConfirmation
48
- showModal={showUnlockModal}
49
- title={__('Unlock')}
50
- body={__(
51
- "This will unlock the resources that the task is running against. Please note that this might lead to inconsistent state and should be used with caution, after making sure that the task can't be resumed."
52
- )}
53
- confirmationMessage={__(
54
- 'I understand that this may cause harm and have working database backups of all backend services.'
55
- )}
56
- confirmAction={__('Unlock')}
57
- path={`/foreman_tasks/tasks/${id}/unlock`}
58
- confirmType="warning"
59
- closeModal={toggleUnlockModal}
60
- />
61
- );
30
+ const unlockModalActions = useForemanModal({
31
+ id: UNLOCK_MODAL,
32
+ });
33
+ const forceUnlockModalActions = useForemanModal({
34
+ id: FORCE_UNLOCK_MODAL,
35
+ });
62
36
 
63
- const modalForceUnlock = (
64
- <ClickConfirmation
65
- showModal={showForceUnlockModal}
66
- title={__('Force Unlock')}
67
- body={__(
68
- 'Resources will be unlocked and will not prevent other tasks from being run. As the task might be still running, it should be avoided to use this unless you are really sure the task got stuck'
69
- )}
70
- confirmationMessage={__(
71
- 'I understand that this may cause harm and have working database backups of all backend services.'
72
- )}
73
- confirmAction={__('Force Unlock')}
74
- path={`/foreman_tasks/tasks/${id}/force_unlock`}
75
- confirmType="danger"
76
- closeModal={toggleForceUnlockModal}
77
- />
78
- );
79
- return (
80
- <React.Fragment>
81
- {modalUnlock}
82
- {modalForceUnlock}
83
- <Grid>
84
- <Row>
85
- <Col xs={12}>
37
+ const {
38
+ taskReload,
39
+ externalId,
40
+ id,
41
+ state,
42
+ resumable,
43
+ cancellable,
44
+ hasSubTasks,
45
+ parentTask,
46
+ cancelTaskRequest,
47
+ resumeTaskRequest,
48
+ forceCancelTaskRequest,
49
+ unlockTaskRequest,
50
+ action,
51
+ dynflowEnableConsole,
52
+ } = props;
53
+ const forceUnlock = () => {
54
+ if (!taskReload) {
55
+ taskProgressToggle();
56
+ }
57
+ forceCancelTaskRequest(id, action);
58
+ };
59
+ const unlock = () => {
60
+ if (!taskReload) {
61
+ taskProgressToggle();
62
+ }
63
+ unlockTaskRequest(id, action);
64
+ };
65
+ return (
66
+ <React.Fragment>
67
+ <UnlockModal onClick={unlock} />
68
+ <ForceUnlockModal onClick={forceUnlock} />
69
+ <Grid>
70
+ <Row>
71
+ <Col xs={12}>
72
+ <Button
73
+ className="reload-button"
74
+ bsSize="small"
75
+ onClick={taskProgressToggle}
76
+ >
77
+ <span
78
+ className={`glyphicon glyphicon-refresh ${
79
+ taskReload ? 'spin' : ''
80
+ }`}
81
+ />
82
+ {__(`${taskReload ? 'Stop' : 'Start'} auto-reloading`)}
83
+ </Button>
84
+ <Button
85
+ className="dynflow-button"
86
+ bsSize="small"
87
+ href={`/foreman_tasks/dynflow/${externalId}`}
88
+ disabled={!dynflowEnableConsole}
89
+ >
90
+ {__('Dynflow console')}
91
+ </Button>
92
+ <Button
93
+ className="resume-button"
94
+ bsSize="small"
95
+ disabled={!resumable}
96
+ onClick={() => {
97
+ if (!taskReload) {
98
+ taskProgressToggle();
99
+ }
100
+ resumeTaskRequest(id, action);
101
+ }}
102
+ >
103
+ {__('Resume')}
104
+ </Button>
105
+ <Button
106
+ className="cancel-button"
107
+ bsSize="small"
108
+ disabled={!cancellable}
109
+ onClick={() => {
110
+ if (!taskReload) {
111
+ taskProgressToggle();
112
+ }
113
+ cancelTaskRequest(id, action);
114
+ }}
115
+ >
116
+ {__('Cancel')}
117
+ </Button>
118
+ {parentTask && (
86
119
  <Button
87
- hidden={!allowDangerousActions}
88
- className="reload-button"
120
+ className="parent-button"
89
121
  bsSize="small"
90
- onClick={this.taskProgressToggle}
122
+ href={`/foreman_tasks/tasks/${parentTask}`}
91
123
  >
92
- <span
93
- className={`glyphicon glyphicon-refresh ${
94
- taskReload ? 'spin' : ''
95
- }`}
96
- />
97
- {__(`${taskReload ? 'Stop' : 'Start'} auto-reloading`)}
124
+ {__('Parent task')}
98
125
  </Button>
126
+ )}
127
+ {hasSubTasks && (
99
128
  <Button
129
+ className="subtask-button"
100
130
  bsSize="small"
101
- href={`/foreman_tasks/dynflow/${externalId}`}
131
+ href={`/foreman_tasks/tasks/${id}/sub_tasks`}
102
132
  >
103
- {__('Dynflow console')}
133
+ {__('Sub tasks')}
104
134
  </Button>
105
- <ResumeButton
106
- id={id}
107
- onClick={() => {
108
- if (!taskReload) {
109
- this.taskProgressToggle();
110
- }
111
- resumeTaskRequest(id, action);
112
- }}
113
- name={action}
114
- disabled={!resumable}
115
- />
116
- <CancelButton
117
- id={id}
118
- name={action}
119
- disabled={!cancellable}
120
- onClick={() => {
121
- if (!taskReload) {
122
- this.taskProgressToggle();
123
- }
124
- cancelTaskRequest(id, action);
125
- }}
126
- />
127
- {parentTask && (
128
- <Button
129
- bsSize="small"
130
- href={`/foreman_tasks/tasks/${parentTask}`}
131
- >
132
- {__('Parent task')}
133
- </Button>
134
- )}
135
- {hasSubTasks && (
136
- <Button
137
- bsSize="small"
138
- href={`/foreman_tasks/tasks/${id}/sub_tasks`}
139
- >
140
- {__('Sub tasks')}
141
- </Button>
142
- )}
143
- {allowDangerousActions && (
144
- <Button
145
- bsSize="small"
146
- disabled={state !== 'paused'}
147
- onClick={toggleUnlockModal}
148
- >
149
- {__('Unlock')}
150
- </Button>
151
- )}
152
- {allowDangerousActions && (
153
- <Button
154
- bsSize="small"
155
- disabled={state === 'stopped'}
156
- onClick={toggleForceUnlockModal}
157
- >
158
- {__('Force Unlock')}
159
- </Button>
160
- )}
161
- </Col>
162
- </Row>
163
- <TaskInfo {...this.props} />
164
- </Grid>
165
- </React.Fragment>
166
- );
167
- }
168
- }
135
+ )}
136
+ <Button
137
+ className="unlock-button"
138
+ bsSize="small"
139
+ disabled={state !== 'paused'}
140
+ onClick={unlockModalActions.setModalOpen}
141
+ >
142
+ {__('Unlock')}
143
+ </Button>
144
+ <Button
145
+ className="force-unlock-button"
146
+ bsSize="small"
147
+ disabled={state === 'stopped'}
148
+ onClick={forceUnlockModalActions.setModalOpen}
149
+ >
150
+ {__('Force Unlock')}
151
+ </Button>
152
+ </Col>
153
+ </Row>
154
+ <TaskInfo {...props} />
155
+ </Grid>
156
+ </React.Fragment>
157
+ );
158
+ };
169
159
 
170
160
  Task.propTypes = {
171
161
  ...TaskInfo.PropTypes,
172
162
  state: PropTypes.string,
173
- allowDangerousActions: PropTypes.bool,
174
163
  resumable: PropTypes.bool,
175
164
  cancellable: PropTypes.bool,
176
165
  refetchTaskDetails: PropTypes.func,
@@ -182,18 +171,14 @@ Task.propTypes = {
182
171
  timeoutId: PropTypes.number,
183
172
  externalId: PropTypes.string,
184
173
  id: PropTypes.string.isRequired,
185
- showUnlockModal: PropTypes.bool,
186
- showForceUnlockModal: PropTypes.bool,
187
- toggleUnlockModal: PropTypes.func,
188
- toggleForceUnlockModal: PropTypes.func,
189
174
  cancelTaskRequest: PropTypes.func,
190
175
  resumeTaskRequest: PropTypes.func,
176
+ dynflowEnableConsole: PropTypes.bool,
191
177
  };
192
178
 
193
179
  Task.defaultProps = {
194
180
  ...TaskInfo.defaultProps,
195
181
  state: '',
196
- allowDangerousActions: false,
197
182
  resumable: false,
198
183
  cancellable: false,
199
184
  refetchTaskDetails: () => null,
@@ -204,12 +189,9 @@ Task.defaultProps = {
204
189
  taskReloadStart: () => null,
205
190
  timeoutId: null,
206
191
  externalId: '',
207
- showUnlockModal: false,
208
- showForceUnlockModal: false,
209
- toggleUnlockModal: () => null,
210
- toggleForceUnlockModal: () => null,
211
192
  cancelTaskRequest: () => null,
212
193
  resumeTaskRequest: () => null,
194
+ dynflowEnableConsole: false,
213
195
  };
214
196
 
215
197
  export default Task;