foreman_rh_cloud 12.0.0 → 12.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -4
  3. data/app/controllers/concerns/inventory_upload/report_actions.rb +1 -1
  4. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +2 -0
  5. data/app/controllers/foreman_inventory_upload/uploads_settings_controller.rb +2 -0
  6. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +26 -22
  7. data/app/services/foreman_rh_cloud/cloud_request.rb +13 -3
  8. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +17 -3
  9. data/app/services/foreman_rh_cloud/rules_ingester.rb +12 -1
  10. data/config/routes.rb +4 -0
  11. data/lib/foreman_inventory_upload/generators/queries.rb +2 -0
  12. data/lib/foreman_inventory_upload/generators/slice.rb +83 -42
  13. data/lib/foreman_inventory_upload.rb +5 -0
  14. data/lib/foreman_rh_cloud/engine.rb +15 -3
  15. data/lib/foreman_rh_cloud/version.rb +1 -1
  16. data/lib/foreman_rh_cloud.rb +2 -0
  17. data/package.json +1 -1
  18. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +35 -2
  19. data/test/unit/slice_generator_test.rb +212 -4
  20. data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.js +5 -1
  21. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/Dashboard.test.js.snap +2 -1
  22. data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/AdvancedSettingsConstants.js +27 -8
  23. data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/index.js +11 -3
  24. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +71 -10
  25. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettingsSelectors.js +13 -1
  26. data/webpack/ForemanInventoryUpload/Components/InventorySettings/MinimalInventoryDropdown.js +107 -0
  27. data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.fixtures.js +9 -2
  28. data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.js +8 -0
  29. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/NavContainer.test.js +53 -9
  30. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +72 -58
  31. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/PageDescription.test.js +61 -6
  32. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +18 -6
  33. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/ToolbarButtons.test.js +54 -6
  34. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.fixtures.js +2 -0
  35. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.js +8 -0
  36. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/__tests__/__snapshots__/ReportGenerate.test.js.snap +4 -2
  37. data/webpack/ForemanInventoryUpload/Components/ReportUpload/ReportUpload.js +1 -8
  38. data/webpack/ForemanInventoryUpload/Components/ReportUpload/__tests__/__snapshots__/ReportUpload.test.js.snap +4 -2
  39. data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.js +47 -28
  40. data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/TabHeader.test.js +46 -8
  41. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/InventoryAutoUpload.js +2 -7
  42. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/__snapshots__/InventoryAutoUpload.test.js.snap +1 -6
  43. data/webpack/common/Switcher/SwitcherPF4.js +11 -1
  44. metadata +4 -11
  45. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/InventorySettings.test.js +0 -13
  46. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +0 -31
  47. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/__snapshots__/NavContainer.test.js.snap +0 -89
  48. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +0 -62
  49. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/__snapshots__/ToolbarButtons.test.js.snap +0 -10
  50. data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/__snapshots__/TabHeader.test.js.snap +0 -43
  51. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/components/AdvancedSettings/AdvancedSettings.js +0 -72
  52. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/components/AdvancedSettings/index.js +0 -23
@@ -1,25 +1,69 @@
1
1
  import React from 'react';
2
- import { mount, testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
+ import { Provider } from 'react-redux';
3
+ import configureMockStore from 'redux-mock-store';
4
+ import thunk from 'redux-thunk';
5
+ import { screen, render } from '@testing-library/react';
6
+ import { mount } from '@theforeman/test';
3
7
  import NavContainer from '../NavContainer';
4
8
  import { props } from '../NavContainer.fixtures';
5
9
 
6
- const fixtures = {
7
- 'render without Props': {},
8
- 'render with Props': props,
9
- };
10
+ const middlewares = [thunk];
11
+ const mockStore = configureMockStore(middlewares);
10
12
 
11
13
  describe('NavContainer', () => {
12
- describe('rendering', () =>
13
- testComponentSnapshotsWithFixtures(NavContainer, fixtures));
14
+ const renderOptions = {
15
+ API: {
16
+ INVENTORY_SETTINGS: {
17
+ response: { subscriptionConnectionEnabled: false },
18
+ },
19
+ },
20
+ };
14
21
 
15
- it('click should call onTabClick prop', () => {
22
+ test('click should call onTabClick prop', () => {
16
23
  const onTabClick = jest.fn();
17
24
  const modifiedProps = {
18
25
  ...props,
19
26
  };
20
27
  modifiedProps.items[0].onClick = onTabClick;
21
- const wrapper = mount(<NavContainer {...modifiedProps} />);
28
+ const store = mockStore(renderOptions);
29
+
30
+ const wrapper = mount(
31
+ <Provider store={store}>
32
+ <NavContainer {...modifiedProps} />
33
+ </Provider>
34
+ );
22
35
  wrapper.find('NavItem a').simulate('click');
23
36
  expect(onTabClick).toBeCalled();
24
37
  });
38
+
39
+ test('when subscription connection is enabled', () => {
40
+ const options = {
41
+ API: {
42
+ INVENTORY_SETTINGS: {
43
+ response: { subscriptionConnectionEnabled: true },
44
+ },
45
+ },
46
+ };
47
+ const store = mockStore(options);
48
+ render(
49
+ <Provider store={store}>
50
+ <NavContainer {...props} />
51
+ </Provider>
52
+ );
53
+
54
+ expect(screen.queryAllByText('Generating')).toHaveLength(1);
55
+ expect(screen.queryAllByText('Uploading')).toHaveLength(1);
56
+ });
57
+
58
+ test('when subscription connection is not enabled', () => {
59
+ const store = mockStore(renderOptions);
60
+ render(
61
+ <Provider store={store}>
62
+ <NavContainer {...props} />
63
+ </Provider>
64
+ );
65
+
66
+ expect(screen.queryAllByText('Generating')).toHaveLength(1);
67
+ expect(screen.queryAllByText('Uploading')).toHaveLength(0);
68
+ });
25
69
  });
@@ -1,68 +1,82 @@
1
1
  import React from 'react';
2
2
  import { Text } from '@patternfly/react-core';
3
+ import { useSelector } from 'react-redux';
3
4
 
4
5
  import { translate as __ } from 'foremanReact/common/I18n';
5
6
  import { FormattedMessage } from 'react-intl';
7
+ import { selectSubscriptionConnectionEnabled } from '../../../InventorySettings/InventorySettingsSelectors';
6
8
 
7
- export const PageDescription = () => (
8
- <div id="inventory_page_description">
9
- <Text>
10
- {__(
11
- 'The Red Hat Hybrid Cloud Console provides a set of cloud services, including Red Hat Insights and Subscriptions, that provide predictive analysis, remediation of issues, and unified subscription reporting for this Foreman instance.'
12
- )}
13
- </Text>
14
- <Text>
15
- {__(
16
- 'The Foreman inventory upload plugin automatically uploads Foreman host inventory data to the Inventory service of Insights, where it can also be used by the Subscriptions service for subscription reporting. If you use the Subscriptions service, enabling inventory uploads is required.'
17
- )}
18
- </Text>
19
- <Text>
20
- <FormattedMessage
21
- id="enable-upload-hint"
22
- defaultMessage={__(
23
- 'To enable this reporting for all Foreman organizations, set {uploadButtonName} to on. The data will be reported automatically once per day.'
9
+ export const PageDescription = () => {
10
+ const subscriptionConnectionEnabled = useSelector(
11
+ selectSubscriptionConnectionEnabled
12
+ );
13
+
14
+ return (
15
+ <div id="inventory_page_description">
16
+ <Text>
17
+ {__(
18
+ 'The Red Hat Hybrid Cloud Console provides a set of cloud services, including Red Hat Insights and Subscriptions, that provide predictive analysis, remediation of issues, and unified subscription reporting for this Foreman instance.'
24
19
  )}
25
- values={{
26
- uploadButtonName: <strong>{__('Automatic inventory upload')}</strong>,
27
- }}
28
- />
29
- </Text>
30
- <Text>
31
- <FormattedMessage
32
- id="restart-button-hint"
33
- defaultMessage={__(
34
- 'To manually upload the data for a specific organization, select an organization and click {restartButtonName}.'
20
+ </Text>
21
+ <Text>
22
+ {__(
23
+ 'The Foreman inventory upload plugin automatically uploads Foreman host inventory data to the Inventory service of Insights, where it can also be used by the Subscriptions service for subscription reporting. If you use the Subscriptions service, enabling inventory uploads is required.'
35
24
  )}
36
- values={{
37
- restartButtonName: (
38
- <strong>{__('Generate and upload report')}</strong>
39
- ),
40
- }}
41
- />
42
- </Text>
43
- <Text>
44
- {__('For more information about the Subscriptions service, see:')}
45
- &nbsp;
46
- <a
47
- href="https://docs.redhat.com/en/documentation/subscription_central/1-latest/html/getting_started_with_the_subscriptions_service/index"
48
- target="_blank"
49
- rel="noopener noreferrer"
50
- >
51
- {__('About subscription watch')}
52
- </a>
53
- </Text>
54
- <Text>
55
- {__('For more information about Insights and Cloud Connector, see:')}
56
- &nbsp;
57
- <a
58
- href="https://console.redhat.com/security/insights/"
59
- target="_blank"
60
- rel="noopener noreferrer"
61
- >
62
- {__('Red Hat Insights Data and Application Security')}
63
- </a>
64
- </Text>
65
- </div>
66
- );
25
+ </Text>
26
+ {subscriptionConnectionEnabled && (
27
+ <Text>
28
+ <FormattedMessage
29
+ id="enable-upload-hint"
30
+ defaultMessage={__(
31
+ 'To enable this reporting for all Foreman organizations, set {uploadButtonName} to on. The data will be reported automatically once per day.'
32
+ )}
33
+ values={{
34
+ uploadButtonName: (
35
+ <strong>{__('Automatic inventory upload')}</strong>
36
+ ),
37
+ }}
38
+ />
39
+ </Text>
40
+ )}
41
+ {subscriptionConnectionEnabled && (
42
+ <Text>
43
+ <FormattedMessage
44
+ id="restart-button-hint"
45
+ defaultMessage={__(
46
+ 'To manually upload the data for a specific organization, select an organization and click {restartButtonName}.'
47
+ )}
48
+ values={{
49
+ restartButtonName: (
50
+ <strong>{__('Generate and upload report')}</strong>
51
+ ),
52
+ }}
53
+ />
54
+ </Text>
55
+ )}
56
+ <Text>
57
+ {__('For more information about the Subscriptions service, see:')}
58
+ &nbsp;
59
+ <a
60
+ href="https://docs.redhat.com/en/documentation/subscription_central/1-latest/html/getting_started_with_the_subscriptions_service/index"
61
+ target="_blank"
62
+ rel="noopener noreferrer"
63
+ >
64
+ {__('About subscription watch')}
65
+ </a>
66
+ </Text>
67
+ <Text>
68
+ {__('For more information about Insights and Cloud Connector, see:')}
69
+ &nbsp;
70
+ <a
71
+ href="https://console.redhat.com/security/insights/"
72
+ target="_blank"
73
+ rel="noopener noreferrer"
74
+ >
75
+ {__('Red Hat Insights Data and Application Security')}
76
+ </a>
77
+ </Text>
78
+ </div>
79
+ );
80
+ };
67
81
 
68
82
  export default PageDescription;
@@ -1,11 +1,66 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
1
+ import React from 'react';
2
+ import { Provider } from 'react-redux';
3
+ import configureMockStore from 'redux-mock-store';
4
+ import thunk from 'redux-thunk';
5
+ import { screen, render } from '@testing-library/react';
2
6
  import { PageDescription } from '../PageDescription';
3
7
 
4
- const fixtures = {
5
- 'render without Props': {},
6
- };
8
+ jest.mock('react-intl', () => {
9
+ const actualReactIntl = jest.requireActual('react-intl');
10
+ return {
11
+ ...actualReactIntl,
12
+ FormattedMessage: ({ defaultMessage, id }) => defaultMessage || id,
13
+ useIntl: () => ({
14
+ formatMessage: ({ defaultMessage, id }) => defaultMessage || id,
15
+ }),
16
+ };
17
+ });
18
+ const middlewares = [thunk];
19
+ const mockStore = configureMockStore(middlewares);
7
20
 
8
21
  describe('PageDescription', () => {
9
- describe('rendering', () =>
10
- testComponentSnapshotsWithFixtures(PageDescription, fixtures));
22
+ test('when subscription connection is enabled', () => {
23
+ const renderOptions = {
24
+ API: {
25
+ INVENTORY_SETTINGS: {
26
+ response: { subscriptionConnectionEnabled: true },
27
+ },
28
+ },
29
+ };
30
+ const store = mockStore(renderOptions);
31
+
32
+ render(
33
+ <Provider store={store}>
34
+ <PageDescription />
35
+ </Provider>
36
+ );
37
+ expect(
38
+ screen.queryAllByText(
39
+ /To enable this reporting for all Foreman organizations/
40
+ )
41
+ ).toHaveLength(1);
42
+ });
43
+
44
+ test('when subscription connection is not enabled', () => {
45
+ const renderOptions = {
46
+ API: {
47
+ INVENTORY_SETTINGS: {
48
+ response: { subscriptionConnectionEnabled: false },
49
+ },
50
+ },
51
+ };
52
+ const store = mockStore(renderOptions);
53
+
54
+ render(
55
+ <Provider store={store}>
56
+ <PageDescription />
57
+ </Provider>
58
+ );
59
+
60
+ expect(
61
+ screen.queryAllByText(
62
+ /To enable this reporting for all Foreman organizations/
63
+ )
64
+ ).toHaveLength(0);
65
+ });
11
66
  });
@@ -1,13 +1,25 @@
1
1
  import React from 'react';
2
+ import { useSelector } from 'react-redux';
2
3
  import SyncButton from '../SyncButton';
3
4
  import CloudConnectorButton from '../CloudConnectorButton';
4
5
  import './toolbarButtons.scss';
6
+ import { selectSubscriptionConnectionEnabled } from '../../../InventorySettings/InventorySettingsSelectors';
5
7
 
6
- const ToolbarButtons = () => (
7
- <div className="inventory_toolbar_buttons">
8
- <CloudConnectorButton />
9
- <SyncButton />
10
- </div>
11
- );
8
+ const ToolbarButtons = () => {
9
+ const subscriptionConnectionEnabled = useSelector(
10
+ selectSubscriptionConnectionEnabled
11
+ );
12
+
13
+ if (!subscriptionConnectionEnabled) {
14
+ return null;
15
+ }
16
+
17
+ return (
18
+ <div className="inventory_toolbar_buttons">
19
+ <CloudConnectorButton />
20
+ <SyncButton />
21
+ </div>
22
+ );
23
+ };
12
24
 
13
25
  export default ToolbarButtons;
@@ -1,12 +1,60 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
-
1
+ import React from 'react';
2
+ import { Provider } from 'react-redux';
3
+ import configureMockStore from 'redux-mock-store';
4
+ import thunk from 'redux-thunk';
5
+ import { screen, render } from '@testing-library/react';
3
6
  import ToolbarButtons from '../ToolbarButtons';
4
7
 
5
- const fixtures = {
6
- 'render without Props': {},
8
+ const middlewares = [thunk];
9
+ const mockStore = configureMockStore(middlewares);
10
+
11
+ const renderOptions = {
12
+ API: {
13
+ INVENTORY_SETTINGS: {
14
+ response: { subscriptionConnectionEnabled: true },
15
+ },
16
+ },
17
+ ForemanRhCloud: {
18
+ inventoryUpload: {
19
+ accountsList: {
20
+ CloudConnectorStatus: {},
21
+ },
22
+ },
23
+ },
7
24
  };
8
25
 
9
26
  describe('ToolbarButtons', () => {
10
- describe('rendering', () =>
11
- testComponentSnapshotsWithFixtures(ToolbarButtons, fixtures));
27
+ test('when subscription connection is enabled', () => {
28
+ const store = mockStore(renderOptions);
29
+
30
+ render(
31
+ <Provider store={store}>
32
+ <ToolbarButtons />
33
+ </Provider>
34
+ );
35
+ expect(screen.queryAllByText('Configure cloud connector')).toHaveLength(1);
36
+ expect(screen.queryAllByText('Sync all inventory status')).toHaveLength(1);
37
+ });
38
+
39
+ test('when subscription connection is not enabled', () => {
40
+ const localSetting = {
41
+ API: {
42
+ INVENTORY_SETTINGS: {
43
+ response: { subscriptionConnectionEnabled: false },
44
+ },
45
+ },
46
+ };
47
+ const store = mockStore({
48
+ ...renderOptions,
49
+ ...localSetting,
50
+ });
51
+
52
+ render(
53
+ <Provider store={store}>
54
+ <ToolbarButtons />
55
+ </Provider>
56
+ );
57
+ expect(screen.queryAllByText('Configure cloud connector')).toHaveLength(0);
58
+ expect(screen.queryAllByText('Sync all inventory status')).toHaveLength(0);
59
+ });
12
60
  });
@@ -4,6 +4,7 @@ export const exitCode = 'exit 0';
4
4
  export const logs = ['No running process'];
5
5
  export const completed = 0;
6
6
  export const restartProcess = noop;
7
+ export const downloadReports = noop;
7
8
  export const error = null;
8
9
  export const scheduled = '2019-08-21T16:14:16.520+03:00';
9
10
  export const props = {
@@ -11,6 +12,7 @@ export const props = {
11
12
  logs,
12
13
  completed,
13
14
  restartProcess,
15
+ downloadReports,
14
16
  error,
15
17
  scheduled,
16
18
  };
@@ -12,6 +12,8 @@ const ReportGenerate = ({
12
12
  completed,
13
13
  error,
14
14
  restartProcess,
15
+ downloadReports,
16
+ downloadButtonDisabled,
15
17
  toggleFullScreen,
16
18
  scheduled,
17
19
  }) => (
@@ -19,6 +21,8 @@ const ReportGenerate = ({
19
21
  <TabHeader
20
22
  exitCode={exitCode}
21
23
  onRestart={restartProcess}
24
+ onDownload={downloadReports}
25
+ downloadButtonDisabled={downloadButtonDisabled}
22
26
  toggleFullScreen={toggleFullScreen}
23
27
  />
24
28
  <TabBody
@@ -40,6 +44,8 @@ ReportGenerate.propTypes = {
40
44
  completed: PropTypes.number,
41
45
  error: PropTypes.string,
42
46
  restartProcess: PropTypes.func,
47
+ downloadReports: PropTypes.func,
48
+ downloadButtonDisabled: PropTypes.func,
43
49
  toggleFullScreen: PropTypes.func,
44
50
  scheduled: PropTypes.string,
45
51
  };
@@ -50,6 +56,8 @@ ReportGenerate.defaultProps = {
50
56
  completed: 0,
51
57
  error: null,
52
58
  restartProcess: noop,
59
+ downloadReports: noop,
60
+ downloadButtonDisabled: noop,
53
61
  toggleFullScreen: noop,
54
62
  scheduled: null,
55
63
  };
@@ -5,8 +5,9 @@ exports[`ReportGenerate rendering render with Props 1`] = `
5
5
  className="report-generate"
6
6
  >
7
7
  <TabHeader
8
+ downloadButtonDisabled={[Function]}
8
9
  exitCode="exit 0"
9
- onDownload={null}
10
+ onDownload={[Function]}
10
11
  onRestart={[Function]}
11
12
  toggleFullScreen={[Function]}
12
13
  />
@@ -29,8 +30,9 @@ exports[`ReportGenerate rendering render without Props 1`] = `
29
30
  className="report-generate"
30
31
  >
31
32
  <TabHeader
33
+ downloadButtonDisabled={[Function]}
32
34
  exitCode=""
33
- onDownload={null}
35
+ onDownload={[Function]}
34
36
  onRestart={[Function]}
35
37
  toggleFullScreen={[Function]}
36
38
  />
@@ -10,16 +10,11 @@ const ReportUpload = ({
10
10
  exitCode,
11
11
  logs,
12
12
  completed,
13
- downloadReports,
14
13
  error,
15
14
  toggleFullScreen,
16
15
  }) => (
17
16
  <TabContainer className="report-upload">
18
- <TabHeader
19
- exitCode={exitCode}
20
- onDownload={downloadReports}
21
- toggleFullScreen={toggleFullScreen}
22
- />
17
+ <TabHeader exitCode={exitCode} toggleFullScreen={toggleFullScreen} />
23
18
  <TabBody
24
19
  exitCode={exitCode}
25
20
  logs={logs}
@@ -36,7 +31,6 @@ ReportUpload.propTypes = {
36
31
  PropTypes.string,
37
32
  ]),
38
33
  completed: PropTypes.number,
39
- downloadReports: PropTypes.func,
40
34
  error: PropTypes.string,
41
35
  toggleFullScreen: PropTypes.func,
42
36
  };
@@ -45,7 +39,6 @@ ReportUpload.defaultProps = {
45
39
  exitCode: '',
46
40
  logs: null,
47
41
  completed: 0,
48
- downloadReports: noop,
49
42
  error: null,
50
43
  toggleFullScreen: noop,
51
44
  };
@@ -5,8 +5,9 @@ exports[`ReportUpload rendering render with Props 1`] = `
5
5
  className="report-upload"
6
6
  >
7
7
  <TabHeader
8
+ downloadButtonDisabled={[Function]}
8
9
  exitCode="exit 0"
9
- onDownload={[Function]}
10
+ onDownload={null}
10
11
  onRestart={null}
11
12
  toggleFullScreen={[Function]}
12
13
  />
@@ -29,8 +30,9 @@ exports[`ReportUpload rendering render without Props 1`] = `
29
30
  className="report-upload"
30
31
  >
31
32
  <TabHeader
33
+ downloadButtonDisabled={[Function]}
32
34
  exitCode=""
33
- onDownload={[Function]}
35
+ onDownload={null}
34
36
  onRestart={null}
35
37
  toggleFullScreen={[Function]}
36
38
  />
@@ -1,45 +1,63 @@
1
1
  import React from 'react';
2
+ import { useSelector } from 'react-redux';
2
3
  import PropTypes from 'prop-types';
3
4
  import { Grid, Button, Icon } from 'patternfly-react';
4
5
  import { noop } from 'foremanReact/common/helpers';
5
6
  import { sprintf, translate as __ } from 'foremanReact/common/I18n';
7
+ import { selectSubscriptionConnectionEnabled } from '../InventorySettings/InventorySettingsSelectors';
6
8
  import { isExitCodeLoading } from '../../ForemanInventoryHelpers';
7
9
  import './tabHeader.scss';
8
10
 
9
- const TabHeader = ({ exitCode, onRestart, onDownload, toggleFullScreen }) => (
10
- <Grid.Row className="tab-header">
11
- <Grid.Col sm={6}>
12
- <p>{sprintf(__('Exit Code: %s'), exitCode)}</p>
13
- </Grid.Col>
14
- <Grid.Col sm={6}>
15
- <div className="tab-action-buttons">
16
- {onRestart ? (
17
- <Button
18
- bsStyle="primary"
19
- onClick={onRestart}
20
- disabled={isExitCodeLoading(exitCode)}
21
- >
22
- {__('Generate and upload report')}
23
- </Button>
24
- ) : null}
25
- {onDownload ? (
26
- <Button onClick={onDownload}>
27
- {__('Download Report')} <Icon name="download" />
11
+ const TabHeader = ({
12
+ exitCode,
13
+ onRestart,
14
+ onDownload,
15
+ downloadButtonDisabled,
16
+ toggleFullScreen,
17
+ }) => {
18
+ const subscriptionConnectionEnabled = useSelector(
19
+ selectSubscriptionConnectionEnabled
20
+ );
21
+ const buttonGenerateLabel = subscriptionConnectionEnabled
22
+ ? __('Generate and upload report')
23
+ : __('Generate report');
24
+
25
+ return (
26
+ <Grid.Row className="tab-header">
27
+ <Grid.Col sm={6}>
28
+ <p>{sprintf(__('Exit Code: %s'), exitCode)}</p>
29
+ </Grid.Col>
30
+ <Grid.Col sm={6}>
31
+ <div className="tab-action-buttons">
32
+ {onRestart ? (
33
+ <Button
34
+ bsStyle="primary"
35
+ onClick={onRestart}
36
+ disabled={isExitCodeLoading(exitCode)}
37
+ >
38
+ {buttonGenerateLabel}
39
+ </Button>
40
+ ) : null}
41
+ {onDownload ? (
42
+ <Button onClick={onDownload} disabled={downloadButtonDisabled()}>
43
+ {__('Download Report')} <Icon name="download" />
44
+ </Button>
45
+ ) : null}
46
+ <Button onClick={toggleFullScreen}>
47
+ {__('Full Screen')}
48
+ <Icon name="arrows-alt" />
28
49
  </Button>
29
- ) : null}
30
- <Button onClick={toggleFullScreen}>
31
- {__('Full Screen')}
32
- <Icon name="arrows-alt" />
33
- </Button>
34
- </div>
35
- </Grid.Col>
36
- </Grid.Row>
37
- );
50
+ </div>
51
+ </Grid.Col>
52
+ </Grid.Row>
53
+ );
54
+ };
38
55
 
39
56
  TabHeader.propTypes = {
40
57
  onRestart: PropTypes.func,
41
58
  onDownload: PropTypes.func,
42
59
  exitCode: PropTypes.string,
60
+ downloadButtonDisabled: PropTypes.func,
43
61
  toggleFullScreen: PropTypes.func,
44
62
  };
45
63
 
@@ -47,6 +65,7 @@ TabHeader.defaultProps = {
47
65
  onRestart: null,
48
66
  exitCode: '',
49
67
  onDownload: null,
68
+ downloadButtonDisabled: noop,
50
69
  toggleFullScreen: noop,
51
70
  };
52
71