foreman-tasks 0.15.1 → 0.15.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.babelrc +9 -1
  3. data/.eslintrc +6 -0
  4. data/.gitignore +1 -0
  5. data/.rubocop.yml +6 -0
  6. data/.storybook/webpack.config.js +51 -54
  7. data/app/controllers/foreman_tasks/api/tasks_controller.rb +0 -2
  8. data/app/controllers/foreman_tasks/tasks_controller.rb +6 -1
  9. data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +8 -0
  10. data/app/lib/actions/base.rb +7 -0
  11. data/app/lib/actions/helpers/lifecycle_logging.rb +21 -0
  12. data/app/lib/actions/proxy_action.rb +4 -2
  13. data/app/models/foreman_tasks/task.rb +23 -0
  14. data/app/models/foreman_tasks/task/summarizer.rb +96 -6
  15. data/app/models/foreman_tasks/triggering.rb +2 -2
  16. data/app/models/setting/foreman_tasks.rb +8 -1
  17. data/app/services/foreman_tasks/dashboard_table_filter.rb +47 -0
  18. data/app/services/foreman_tasks/troubleshooting_help_generator.rb +92 -0
  19. data/app/services/ui_notifications/tasks.rb +20 -0
  20. data/app/services/ui_notifications/tasks/task_paused_admin.rb +43 -0
  21. data/app/services/ui_notifications/tasks/task_paused_owner.rb +30 -0
  22. data/app/views/foreman_tasks/tasks/_details.html.erb +5 -3
  23. data/app/views/foreman_tasks/tasks/index.html.erb +13 -0
  24. data/config/routes.rb +1 -0
  25. data/db/migrate/20190318153925_add_task_state_updated_at.foreman_tasks.rb +5 -0
  26. data/db/migrate/20190404132157_add_implicit_varchar_uuid_cast.rb +25 -0
  27. data/db/seeds.d/30-notification_blueprints.rb +33 -0
  28. data/foreman-tasks.gemspec +1 -1
  29. data/lib/foreman_tasks/cleaner.rb +5 -4
  30. data/lib/foreman_tasks/engine.rb +1 -1
  31. data/lib/foreman_tasks/test_helpers.rb +10 -0
  32. data/lib/foreman_tasks/version.rb +1 -1
  33. data/package.json +14 -11
  34. data/test/controllers/tasks_controller_test.rb +10 -0
  35. data/test/foreman_tasks_test_helper.rb +4 -0
  36. data/test/support/dummy_dynflow_action.rb +29 -0
  37. data/test/support/history_tasks_builder.rb +42 -0
  38. data/test/unit/actions/action_with_sub_plans_test.rb +4 -1
  39. data/test/unit/actions/bulk_action_test.rb +2 -0
  40. data/test/unit/cleaner_test.rb +15 -0
  41. data/test/unit/dashboard_table_filter_test.rb +65 -0
  42. data/test/unit/summarizer_test.rb +39 -0
  43. data/test/unit/task_test.rb +14 -0
  44. data/test/unit/troubleshooting_help_generator_test.rb +71 -0
  45. data/test/unit/ui_notifications_test.rb +86 -0
  46. data/webpack/ForemanTasks/Components/Chart/Chart.js +128 -0
  47. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/PausedTasksCard/PausedTasksCard.js +20 -0
  48. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/PausedTasksCard/PausedTasksCard.stories.js +51 -0
  49. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/PausedTasksCard/PausedTasksCard.test.js +11 -0
  50. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/PausedTasksCard/__snapshots__/PausedTasksCard.test.js.snap +36 -0
  51. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/RunningTasksCard/RunningTasksCard.js +20 -0
  52. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/RunningTasksCard/RunningTasksCard.stories.js +51 -0
  53. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/RunningTasksCard/RunningTasksCard.test.js +11 -0
  54. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/RunningTasksCard/__snapshots__/RunningTasksCard.test.js.snap +36 -0
  55. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.js +64 -0
  56. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.scss +25 -0
  57. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.stories.js +28 -0
  58. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.test.js +18 -0
  59. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/__snapshots__/ScheduledTasksCard.test.js.snap +94 -0
  60. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.js +89 -0
  61. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.scss +46 -0
  62. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.stories.js +72 -0
  63. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.test.js +48 -0
  64. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCardHelper.js +63 -0
  65. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/__snapshots__/StoppedTasksCard.test.js.snap +973 -0
  66. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/TasksDonutCard.js +96 -0
  67. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/TasksDonutCard.scss +17 -0
  68. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/TasksDonutCard.stories.js +46 -0
  69. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/TasksDonutCard.test.js +43 -0
  70. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/__snapshots__/TasksDonutCard.test.js.snap +183 -0
  71. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChart.js +166 -0
  72. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChart.scss +24 -0
  73. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChart.stories.js +25 -0
  74. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChart.test.js +40 -0
  75. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChartConstants.js +13 -0
  76. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChartHelper.js +94 -0
  77. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChartHelper.test.js +152 -0
  78. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/__snapshots__/TasksDonutChart.test.js.snap +302 -0
  79. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/__snapshots__/TasksDonutChartHelper.test.js.snap +21 -0
  80. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/TasksCardsGrid.fixtures.js +25 -0
  81. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/TasksCardsGrid.js +72 -0
  82. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/TasksCardsGrid.stories.js +52 -0
  83. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/TasksCardsGrid.test.js +21 -0
  84. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/__snapshots__/TasksCardsGrid.test.js.snap +223 -0
  85. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js +57 -0
  86. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.scss +26 -0
  87. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.stories.js +22 -0
  88. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.test.js +57 -0
  89. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/__snapshots__/TasksLabelsRow.test.js.snap +47 -0
  90. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/TimeDropDown.js +51 -0
  91. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/TimeDropDown.stories.js +23 -0
  92. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/TimeDropDown.test.js +19 -0
  93. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/__snapshots__/TimeDropDown.test.js.snap +85 -0
  94. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/TasksTimeRow.js +33 -0
  95. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/TasksTimeRow.scss +11 -0
  96. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/TasksTimeRow.stories.js +22 -0
  97. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/TasksTimeRow.test.js +15 -0
  98. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/__snapshots__/TasksTimeRow.test.js.snap +41 -0
  99. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboard.js +77 -0
  100. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboard.scss +6 -0
  101. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js +62 -0
  102. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardConstants.js +94 -0
  103. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js +78 -0
  104. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardPropTypes.js +13 -0
  105. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardReducer.js +50 -0
  106. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardSelectors.js +44 -0
  107. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboard.test.js +13 -0
  108. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardActions.test.js +37 -0
  109. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardHelper.test.js +36 -0
  110. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardReducer.test.js +58 -0
  111. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardSelectors.test..js +59 -0
  112. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/__snapshots__/TasksDashboard.test.js.snap +51 -0
  113. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/__snapshots__/TasksDashboardActions.test.js.snap +61 -0
  114. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/__snapshots__/TasksDashboardReducer.test.js.snap +280 -0
  115. data/webpack/ForemanTasks/Components/TasksDashboard/index.js +25 -0
  116. data/webpack/ForemanTasks/ForemanTasksReducers.js +10 -0
  117. data/webpack/ForemanTasks/ForemanTasksSelectors.js +1 -0
  118. data/webpack/__mocks__/foremanReact/API.js +7 -0
  119. data/webpack/__mocks__/foremanReact/common/I18n.js +5 -0
  120. data/webpack/__mocks__/foremanReact/common/helpers.js +3 -0
  121. data/webpack/index.js +13 -1
  122. data/webpack/stories/decorators/index.js +1 -0
  123. data/webpack/stories/decorators/withCardsDecorator.js +14 -0
  124. data/webpack/stories/index.js +1 -3
  125. data/webpack/stories/index.scss +6 -0
  126. metadata +101 -8
  127. data/webpack/ForemanTasks/components/Hello/Hello.stories.js +0 -5
  128. data/webpack/ForemanTasks/components/Hello/__tests__/Hello.test.js +0 -11
  129. data/webpack/ForemanTasks/components/Hello/__tests__/__snapshots__/Hello.test.js.snap +0 -7
  130. data/webpack/ForemanTasks/components/Hello/index.js +0 -5
@@ -0,0 +1,86 @@
1
+ require 'foreman_tasks_test_helper'
2
+
3
+ module ForemanTasks
4
+ class UiNotificationsTest < ActiveSupport::TestCase
5
+ include ForemanTasks::TestHelpers::WithInThreadExecutor
6
+
7
+ let(:admin_user) { @admin_user }
8
+ let(:task_owner) { FactoryBot.create(:user) }
9
+
10
+ let :sample_troubleshooting_url do
11
+ 'https://theforeman.org/manuals/%{version}/tasks_troubleshooting.html#%{label}'
12
+ end
13
+
14
+ before do
15
+ Setting::ForemanTasks.load_defaults
16
+ ::ForemanTasks::Task.delete_all
17
+ load File.join(ForemanTasks::Engine.root, 'db', 'seeds.d', '30-notification_blueprints.rb')
18
+ @admin_user = FactoryBot.create(:user, :admin)
19
+ Setting[:foreman_tasks_troubleshooting_url] = sample_troubleshooting_url
20
+ end
21
+
22
+ describe UINotifications::Tasks::TaskPausedAdmin do
23
+ it 'notifies all admins about current amount of paused tasks when some paused task occurs' do
24
+ trigger_task
25
+ notification = user_notifications(admin_user).first
26
+ notification.message.must_equal "There is 1 paused task in the system that need attention"
27
+ links = notification.actions['links']
28
+ links.must_include('href' => '/foreman_tasks/tasks?search=state%3Dpaused',
29
+ 'title' => 'List of tasks')
30
+ links.must_include('name' => 'troubleshooting',
31
+ 'title' => 'Troubleshooting Documentation',
32
+ 'description' => 'See %{link} for more details on how to resolve the issue',
33
+ 'href' => "https://theforeman.org/manuals/#{SETTINGS[:version].short}/tasks_troubleshooting.html#",
34
+ 'external' => true)
35
+ end
36
+
37
+ it 'aggregates the notification when multiple tasks get paused' do
38
+ trigger_task
39
+ recipient1 = NotificationRecipient.find_by(user_id: admin_user)
40
+ recipient1.notification.message.must_match(/1 paused task/)
41
+
42
+ new_admin_user = FactoryBot.create(:user, :admin)
43
+
44
+ trigger_task
45
+
46
+ NotificationRecipient.find_by(id: recipient1.id).must_be_nil
47
+ Notification.find_by(id: recipient1.notification.id).must_be_nil
48
+ recipient2 = NotificationRecipient.find_by(user_id: admin_user)
49
+ recipient2.notification.message.must_match(/2 paused tasks/)
50
+
51
+ new_recipient = NotificationRecipient.find_by(user_id: new_admin_user)
52
+ new_recipient.notification.must_equal recipient2.notification
53
+ end
54
+ end
55
+
56
+ describe UINotifications::Tasks::TaskPausedOwner do
57
+ it 'notifies the owner about the paused task' do
58
+ task = trigger_task
59
+ notifications = user_notifications(task_owner)
60
+ assert_equal 1, notifications.size, 'Only notification for the main action should be triggered'
61
+ notification = notifications.first
62
+ notification.message.must_equal "The task 'Dummy pause action' got paused"
63
+ links = notification.actions['links']
64
+ links.must_include("href" => "/foreman_tasks/tasks/#{task.id}",
65
+ "title" => "Task Details")
66
+ links.must_include('name' => 'troubleshooting',
67
+ 'title' => 'Troubleshooting Documentation',
68
+ 'description' => 'See %{link} for more details on how to resolve the issue',
69
+ 'href' => "https://theforeman.org/manuals/#{SETTINGS[:version].short}/tasks_troubleshooting.html#Support::DummyPauseAction",
70
+ 'external' => true)
71
+ end
72
+ end
73
+
74
+ def trigger_task
75
+ as_user task_owner do
76
+ t = ForemanTasks.trigger(::Support::DummyPauseAction)
77
+ t.finished.wait
78
+ ForemanTasks::Task.find_by(external_id: t.execution_plan_id)
79
+ end
80
+ end
81
+
82
+ def user_notifications(user)
83
+ Notification.joins(:notification_recipients).where('notification_recipients.user_id' => user.id)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,128 @@
1
+ /*
2
+ Copied from react-c3js: https://github.com/bcbcarl/react-c3js/blob/master/src/index.js
3
+ Added missing features:
4
+ * onChartCreate
5
+ * onChartUpdate
6
+
7
+ TODO: update react-c3js or move to patternfly-react
8
+ */
9
+
10
+ /* eslint-disable global-require,
11
+ import/no-extraneous-dependencies,
12
+ react/no-find-dom-node,
13
+ react/no-unused-prop-types,
14
+ react/require-default-props
15
+ */
16
+ import React from 'react';
17
+ import PropTypes from 'prop-types';
18
+ import { findDOMNode } from 'react-dom';
19
+
20
+ let c3;
21
+
22
+ class C3Chart extends React.Component {
23
+ componentDidMount() {
24
+ c3 = require('c3');
25
+ this.updateChart(this.props);
26
+ }
27
+
28
+ componentWillReceiveProps(newProps) {
29
+ this.updateChart(newProps);
30
+ if (newProps.onPropsChanged) {
31
+ newProps.onPropsChanged(this.props, newProps, this.chart);
32
+ }
33
+ }
34
+
35
+ componentWillUnmount() {
36
+ this.destroyChart();
37
+ }
38
+
39
+ destroyChart() {
40
+ try {
41
+ this.chart = this.chart.destroy();
42
+ } catch (err) {
43
+ throw new Error('Internal C3 error', err);
44
+ }
45
+ }
46
+
47
+ generateChart(config) {
48
+ const newConfig = Object.assign({ bindto: findDOMNode(this) }, config);
49
+ return c3.generate(newConfig);
50
+ }
51
+
52
+ loadNewData(data) {
53
+ this.chart.load(data);
54
+ }
55
+
56
+ unloadData() {
57
+ this.chart.unload();
58
+ }
59
+
60
+ createChart(config) {
61
+ const { onChartCreate } = this.props;
62
+ this.chart = this.generateChart(config);
63
+
64
+ if (onChartCreate) onChartCreate(this.chart, config);
65
+ }
66
+
67
+ updateChart(config) {
68
+ const { onChartUpdate } = this.props;
69
+
70
+ if (!this.chart) {
71
+ this.createChart(config);
72
+ }
73
+
74
+ if (config.unloadBeforeLoad) {
75
+ this.unloadData();
76
+ }
77
+
78
+ this.loadNewData(config.data);
79
+
80
+ if (onChartUpdate) onChartUpdate(this.chart, config);
81
+ }
82
+
83
+ render() {
84
+ const className = this.props.className ? ` ${this.props.className}` : '';
85
+ const style = this.props.style ? this.props.style : {};
86
+ return <div className={className} style={style} />;
87
+ }
88
+ }
89
+
90
+ C3Chart.displayName = 'C3Chart';
91
+
92
+ C3Chart.propTypes = {
93
+ data: PropTypes.object.isRequired,
94
+ title: PropTypes.object,
95
+ size: PropTypes.object,
96
+ padding: PropTypes.object,
97
+ color: PropTypes.object,
98
+ interaction: PropTypes.object,
99
+ transition: PropTypes.object,
100
+ oninit: PropTypes.func,
101
+ onrendered: PropTypes.func,
102
+ onmouseover: PropTypes.func,
103
+ onmouseout: PropTypes.func,
104
+ onresize: PropTypes.func,
105
+ onresized: PropTypes.func,
106
+ axis: PropTypes.object,
107
+ grid: PropTypes.object,
108
+ regions: PropTypes.array,
109
+ legend: PropTypes.object,
110
+ tooltip: PropTypes.object,
111
+ subchart: PropTypes.object,
112
+ zoom: PropTypes.object,
113
+ point: PropTypes.object,
114
+ line: PropTypes.object,
115
+ area: PropTypes.object,
116
+ bar: PropTypes.object,
117
+ pie: PropTypes.object,
118
+ donut: PropTypes.object,
119
+ gauge: PropTypes.object,
120
+ className: PropTypes.string,
121
+ style: PropTypes.object,
122
+ unloadBeforeLoad: PropTypes.bool,
123
+ onPropsChanged: PropTypes.func,
124
+ onChartCreate: PropTypes.func,
125
+ onChartUpdate: PropTypes.func,
126
+ };
127
+
128
+ export default C3Chart;
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { translate as __ } from 'foremanReact/common/I18n';
3
+
4
+ import TasksDonutCard from '../TasksDonutCard/TasksDonutCard';
5
+
6
+ const PausedTasksCard = ({ ...props }) => (
7
+ <TasksDonutCard title={__('Paused')} wantedQueryState="paused" {...props} />
8
+ );
9
+
10
+ const filterUnwantedFields = obj => {
11
+ const { title, wantedQueryState, ...newObj } = obj;
12
+ return newObj;
13
+ };
14
+
15
+ PausedTasksCard.propTypes = filterUnwantedFields(TasksDonutCard.propTypes);
16
+ PausedTasksCard.defaultProps = filterUnwantedFields(
17
+ TasksDonutCard.defaultProps
18
+ );
19
+
20
+ export default PausedTasksCard;
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ import { storiesOf } from '@storybook/react';
3
+ import { withKnobs, number, select } from '@storybook/addon-knobs';
4
+ import { action } from '@storybook/addon-actions';
5
+ import { withCardsDecorator } from '../../../../../../../stories/decorators';
6
+
7
+ import {
8
+ TASKS_DASHBOARD_AVAILABLE_QUERY_MODES,
9
+ TASKS_DASHBOARD_AVAILABLE_TIMES,
10
+ TASKS_DASHBOARD_AVAILABLE_QUERY_STATES,
11
+ } from '../../../../TasksDashboardConstants';
12
+ import PausedTasksCard from './PausedTasksCard';
13
+
14
+ storiesOf('TasksDashboard/TasksCardsGrid', module)
15
+ .addDecorator(withKnobs)
16
+ .addDecorator(withCardsDecorator)
17
+ .add('PausedTasksCard', () => {
18
+ const selectTime = select(
19
+ 'time',
20
+ TASKS_DASHBOARD_AVAILABLE_TIMES,
21
+ PausedTasksCard.defaultProps.time
22
+ );
23
+
24
+ const selectMode = select(
25
+ 'mode',
26
+ { ...TASKS_DASHBOARD_AVAILABLE_QUERY_MODES, NONE: 'none', TOTAL: null },
27
+ 'none'
28
+ );
29
+ return (
30
+ <PausedTasksCard
31
+ data={{
32
+ last: number('data.last', 3),
33
+ older: number('data.older', 5),
34
+ }}
35
+ time={selectTime}
36
+ query={{
37
+ state: select(
38
+ 'query.state',
39
+ {
40
+ ...TASKS_DASHBOARD_AVAILABLE_QUERY_STATES,
41
+ NONE: null,
42
+ },
43
+ TASKS_DASHBOARD_AVAILABLE_QUERY_STATES.PAUSED
44
+ ),
45
+ mode: selectMode,
46
+ time: selectTime,
47
+ }}
48
+ updateQuery={action('updateQuery')}
49
+ />
50
+ );
51
+ });
@@ -0,0 +1,11 @@
1
+ import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
2
+
3
+ import PausedTasksCard from './PausedTasksCard';
4
+
5
+ const fixtures = {
6
+ 'render with minimal props': {},
7
+ 'render with some props': { some: 'prop' },
8
+ };
9
+
10
+ describe('PausedTasksCard', () =>
11
+ testComponentSnapshotsWithFixtures(PausedTasksCard, fixtures));
@@ -0,0 +1,36 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`PausedTasksCard render with minimal props 1`] = `
4
+ <TasksDonutCard
5
+ className=""
6
+ data={
7
+ Object {
8
+ "last": 0,
9
+ "older": 0,
10
+ }
11
+ }
12
+ query={Object {}}
13
+ time="H24"
14
+ title="Paused"
15
+ updateQuery={[Function]}
16
+ wantedQueryState="paused"
17
+ />
18
+ `;
19
+
20
+ exports[`PausedTasksCard render with some props 1`] = `
21
+ <TasksDonutCard
22
+ className=""
23
+ data={
24
+ Object {
25
+ "last": 0,
26
+ "older": 0,
27
+ }
28
+ }
29
+ query={Object {}}
30
+ some="prop"
31
+ time="H24"
32
+ title="Paused"
33
+ updateQuery={[Function]}
34
+ wantedQueryState="paused"
35
+ />
36
+ `;
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { translate as __ } from 'foremanReact/common/I18n';
3
+
4
+ import TasksDonutCard from '../TasksDonutCard/TasksDonutCard';
5
+
6
+ const RunningTasksCard = ({ ...props }) => (
7
+ <TasksDonutCard title={__('Running')} wantedQueryState="running" {...props} />
8
+ );
9
+
10
+ const filterUnwantedFields = obj => {
11
+ const { title, wantedQueryState, ...newObj } = obj;
12
+ return newObj;
13
+ };
14
+
15
+ RunningTasksCard.propTypes = filterUnwantedFields(TasksDonutCard.propTypes);
16
+ RunningTasksCard.defaultProps = filterUnwantedFields(
17
+ TasksDonutCard.defaultProps
18
+ );
19
+
20
+ export default RunningTasksCard;
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ import { storiesOf } from '@storybook/react';
3
+ import { withKnobs, number, select } from '@storybook/addon-knobs';
4
+ import { action } from '@storybook/addon-actions';
5
+ import { withCardsDecorator } from '../../../../../../../stories/decorators';
6
+
7
+ import {
8
+ TASKS_DASHBOARD_AVAILABLE_QUERY_MODES,
9
+ TASKS_DASHBOARD_AVAILABLE_TIMES,
10
+ TASKS_DASHBOARD_AVAILABLE_QUERY_STATES,
11
+ } from '../../../../TasksDashboardConstants';
12
+ import RunningTasksCard from './RunningTasksCard';
13
+
14
+ storiesOf('TasksDashboard/TasksCardsGrid', module)
15
+ .addDecorator(withKnobs)
16
+ .addDecorator(withCardsDecorator)
17
+ .add('RunningTasksCard', () => {
18
+ const selectTime = select(
19
+ 'time',
20
+ TASKS_DASHBOARD_AVAILABLE_TIMES,
21
+ RunningTasksCard.defaultProps.time
22
+ );
23
+
24
+ const selectMode = select(
25
+ 'mode',
26
+ { ...TASKS_DASHBOARD_AVAILABLE_QUERY_MODES, NONE: 'none', TOTAL: null },
27
+ 'none'
28
+ );
29
+ return (
30
+ <RunningTasksCard
31
+ data={{
32
+ last: number('data.last', 3),
33
+ older: number('data.older', 5),
34
+ }}
35
+ time={selectTime}
36
+ query={{
37
+ state: select(
38
+ 'query.state',
39
+ {
40
+ ...TASKS_DASHBOARD_AVAILABLE_QUERY_STATES,
41
+ NONE: null,
42
+ },
43
+ TASKS_DASHBOARD_AVAILABLE_QUERY_STATES.RUNNING
44
+ ),
45
+ mode: selectMode,
46
+ time: selectTime,
47
+ }}
48
+ updateQuery={action('updateQuery')}
49
+ />
50
+ );
51
+ });
@@ -0,0 +1,11 @@
1
+ import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
2
+
3
+ import RunningTasksCard from './RunningTasksCard';
4
+
5
+ const fixtures = {
6
+ 'render with minimal props': {},
7
+ 'render with some props': { some: 'prop' },
8
+ };
9
+
10
+ describe('RunningTasksCard', () =>
11
+ testComponentSnapshotsWithFixtures(RunningTasksCard, fixtures));
@@ -0,0 +1,36 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`RunningTasksCard render with minimal props 1`] = `
4
+ <TasksDonutCard
5
+ className=""
6
+ data={
7
+ Object {
8
+ "last": 0,
9
+ "older": 0,
10
+ }
11
+ }
12
+ query={Object {}}
13
+ time="H24"
14
+ title="Running"
15
+ updateQuery={[Function]}
16
+ wantedQueryState="running"
17
+ />
18
+ `;
19
+
20
+ exports[`RunningTasksCard render with some props 1`] = `
21
+ <TasksDonutCard
22
+ className=""
23
+ data={
24
+ Object {
25
+ "last": 0,
26
+ "older": 0,
27
+ }
28
+ }
29
+ query={Object {}}
30
+ some="prop"
31
+ time="H24"
32
+ title="Running"
33
+ updateQuery={[Function]}
34
+ wantedQueryState="running"
35
+ />
36
+ `;