foreman_rh_cloud 3.0.16 → 3.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/insights_cloud/candlepin_cache.rb +28 -0
- data/app/controllers/concerns/insights_cloud/client_authentication.rb +23 -0
- data/app/controllers/foreman_inventory_upload/accounts_controller.rb +1 -1
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +1 -8
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +73 -0
- data/app/controllers/insights_cloud/hits_controller.rb +3 -3
- data/app/controllers/insights_cloud/tasks_controller.rb +6 -1
- data/app/models/insights_hit.rb +16 -1
- data/app/models/insights_resolution.rb +3 -0
- data/app/models/insights_rule.rb +3 -0
- data/app/models/setting/rh_cloud.rb +12 -2
- data/app/services/foreman_rh_cloud/branch_info.rb +57 -0
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +102 -0
- data/config/routes.rb +10 -0
- data/db/migrate/20210214000001_create_rules_and_resolutions.foreman_rh_cloud.rb +24 -0
- data/db/migrate/20210214000002_add_rule_id_to_hits.foreman_rh_cloud.rb +5 -0
- data/lib/foreman_inventory_upload/generators/slice.rb +3 -3
- data/lib/foreman_rh_cloud.rb +9 -0
- data/lib/foreman_rh_cloud/engine.rb +1 -0
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/insights_cloud.rb +4 -0
- data/lib/insights_cloud/async/insights_full_sync.rb +29 -0
- data/lib/insights_cloud/async/insights_rules_sync.rb +80 -0
- data/lib/insights_cloud/async/rules_result.rb +13 -0
- data/package.json +1 -1
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +107 -0
- data/test/factories/insights_factories.rb +2 -1
- data/test/factories/inventory_upload_factories.rb +12 -0
- data/test/jobs/insights_full_sync_test.rb +17 -0
- data/test/jobs/insights_rules_sync_test.rb +198 -0
- data/test/unit/services/foreman_rh_cloud/branch_info_test.rb +60 -0
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +106 -0
- data/test/unit/slice_generator_test.rb +29 -3
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +1 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +2 -2
- data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardActions.js +1 -1
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardActions.test.js +4 -4
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +2 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.scss +12 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +1 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/SettingsWarning.js +64 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/SettingsWarning.test.js +18 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/__snapshots__/SettingsWarning.test.js.snap +30 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/index.js +25 -0
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButton.js +2 -2
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButton.test.js +1 -1
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +9 -5
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +55 -30
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableConstants.js +10 -9
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js +14 -6
- data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableSelectors.js +4 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/SelectAllAlert.js +4 -10
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTableActions.test.js +48 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +11 -24
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +132 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableSelectors.test.js.snap +1 -0
- data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/fixtures.js +1 -1
- data/webpack/InsightsCloudSync/Components/InsightsTable/table.scss +10 -0
- data/webpack/InsightsCloudSync/InsightsCloudSync.js +18 -16
- data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +23 -20
- data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +1 -1
- data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +36 -36
- data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncActions.test.js +9 -0
- data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +11 -0
- data/webpack/__mocks__/foremanReact/redux/API/index.js +1 -0
- metadata +29 -2
@@ -0,0 +1,25 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { useSelector } from 'react-redux';
|
3
|
+
import { SettingsWarning } from './SettingsWarning';
|
4
|
+
import {
|
5
|
+
selectAutoUploadEnabled,
|
6
|
+
selectHostObfuscationEnabled,
|
7
|
+
} from '../../../AccountList/AccountListSelectors';
|
8
|
+
import { CONNECTOR_STATUS } from '../CloudConnectorButton/CloudConnectorConstants';
|
9
|
+
import { selectStatus } from '../CloudConnectorButton/CloudConnectorSelectors';
|
10
|
+
|
11
|
+
const ConnectedSettingsWarning = () => {
|
12
|
+
const autoUpload = useSelector(selectAutoUploadEnabled);
|
13
|
+
const hostObfuscation = useSelector(selectHostObfuscationEnabled);
|
14
|
+
const isCloudConnector =
|
15
|
+
useSelector(selectStatus) === CONNECTOR_STATUS.RESOLVED;
|
16
|
+
return (
|
17
|
+
<SettingsWarning
|
18
|
+
autoUpload={autoUpload}
|
19
|
+
hostObfuscation={hostObfuscation}
|
20
|
+
isCloudConnector={isCloudConnector}
|
21
|
+
/>
|
22
|
+
);
|
23
|
+
};
|
24
|
+
|
25
|
+
export default ConnectedSettingsWarning;
|
data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButton.js
CHANGED
@@ -43,13 +43,13 @@ class SyncButton extends React.Component {
|
|
43
43
|
}
|
44
44
|
|
45
45
|
SyncButton.propTypes = {
|
46
|
-
cloudToken: PropTypes.
|
46
|
+
cloudToken: PropTypes.bool,
|
47
47
|
handleSync: PropTypes.func.isRequired,
|
48
48
|
status: PropTypes.string,
|
49
49
|
};
|
50
50
|
|
51
51
|
SyncButton.defaultProps = {
|
52
|
-
cloudToken:
|
52
|
+
cloudToken: false,
|
53
53
|
status: null,
|
54
54
|
};
|
55
55
|
|
@@ -4,7 +4,7 @@ import { noop } from 'patternfly-react';
|
|
4
4
|
import SyncButton from '../SyncButton';
|
5
5
|
|
6
6
|
const fixtures = {
|
7
|
-
'render with Props': { cloudToken:
|
7
|
+
'render with Props': { cloudToken: true, handleSync: noop },
|
8
8
|
};
|
9
9
|
|
10
10
|
describe('SyncButton', () => {
|
@@ -5,7 +5,7 @@ import { Pagination, PaginationVariant } from '@patternfly/react-core';
|
|
5
5
|
import { Table, TableHeader, TableBody } from '@patternfly/react-table';
|
6
6
|
import { useForemanSettings } from 'foremanReact/Root/Context/ForemanContext';
|
7
7
|
import SelectAllAlert from './SelectAllAlert';
|
8
|
-
import { columns
|
8
|
+
import { columns } from './InsightsTableConstants';
|
9
9
|
import TableEmptyState from './components/EmptyState';
|
10
10
|
import {
|
11
11
|
modifySelectedRows,
|
@@ -37,16 +37,20 @@ const InsightsTable = ({
|
|
37
37
|
}) => {
|
38
38
|
const { perPage: appPerPage } = useForemanSettings();
|
39
39
|
const perPage = urlPerPage || appPerPage;
|
40
|
+
const [rows, setRows] = React.useState([]);
|
40
41
|
|
41
42
|
// acts as componentDidMount
|
42
43
|
useEffect(() => {
|
43
44
|
fetchInsights({ page, perPage, query, sortBy, sortOrder });
|
44
45
|
}, []);
|
45
46
|
|
47
|
+
useEffect(() => {
|
48
|
+
setRows(modifySelectedRows(hits, selectedIds, showSelectAllAlert));
|
49
|
+
}, [hits, selectedIds]);
|
50
|
+
|
46
51
|
return (
|
47
52
|
<React.Fragment>
|
48
53
|
<SelectAllAlert
|
49
|
-
itemCount={itemCount}
|
50
54
|
selectedIds={selectedIds}
|
51
55
|
showSelectAllAlert={showSelectAllAlert}
|
52
56
|
selectAll={selectAll}
|
@@ -54,16 +58,16 @@ const InsightsTable = ({
|
|
54
58
|
isAllSelected={isAllSelected}
|
55
59
|
/>
|
56
60
|
<Table
|
61
|
+
className="recommendations-table"
|
57
62
|
aria-label="Recommendations Table"
|
58
63
|
onSelect={(_event, isSelected, rowId) =>
|
59
|
-
onTableSelect(
|
64
|
+
onTableSelect(isSelected, rowId, rows, selectedIds)
|
60
65
|
}
|
61
66
|
canSelectAll
|
62
67
|
sortBy={{ index: getSortColumnIndex(sortBy), direction: sortOrder }}
|
63
68
|
onSort={onTableSort}
|
64
69
|
cells={columns}
|
65
|
-
rows={
|
66
|
-
actions={actions}
|
70
|
+
rows={rows}
|
67
71
|
>
|
68
72
|
<TableHeader />
|
69
73
|
<TableBody />
|
@@ -1,10 +1,7 @@
|
|
1
1
|
import URI from 'urijs';
|
2
2
|
import { push } from 'connected-react-router';
|
3
3
|
import { get } from 'foremanReact/redux/API';
|
4
|
-
import {
|
5
|
-
selectIsAllSelected,
|
6
|
-
selectQueryParams,
|
7
|
-
} from './InsightsTableSelectors';
|
4
|
+
import { selectQueryParams } from './InsightsTableSelectors';
|
8
5
|
import { INSIGHTS_PATH } from '../../InsightsCloudSyncConstants';
|
9
6
|
import {
|
10
7
|
columns,
|
@@ -17,7 +14,7 @@ import {
|
|
17
14
|
|
18
15
|
export const fetchInsights = (queryParams = {}) => (dispatch, getState) => {
|
19
16
|
const state = getState();
|
20
|
-
const { page, perPage, query, sortBy, sortOrder } = {
|
17
|
+
const { page, perPage, query, sortBy, sortOrder, isSelectAll } = {
|
21
18
|
...selectQueryParams(state),
|
22
19
|
...queryParams,
|
23
20
|
};
|
@@ -32,6 +29,12 @@ export const fetchInsights = (queryParams = {}) => (dispatch, getState) => {
|
|
32
29
|
search: query,
|
33
30
|
order: `${sortBy} ${sortOrder}`,
|
34
31
|
},
|
32
|
+
handleSuccess: response => {
|
33
|
+
if (isSelectAll) {
|
34
|
+
selectAllIds(dispatch, response.data.hits || []);
|
35
|
+
dispatch(selectAll());
|
36
|
+
}
|
37
|
+
},
|
35
38
|
})
|
36
39
|
);
|
37
40
|
|
@@ -42,6 +45,7 @@ export const fetchInsights = (queryParams = {}) => (dispatch, getState) => {
|
|
42
45
|
search: query,
|
43
46
|
sort_by: sortBy,
|
44
47
|
sort_order: sortOrder,
|
48
|
+
select_all: isSelectAll,
|
45
49
|
});
|
46
50
|
|
47
51
|
dispatch(
|
@@ -51,15 +55,21 @@ export const fetchInsights = (queryParams = {}) => (dispatch, getState) => {
|
|
51
55
|
})
|
52
56
|
);
|
53
57
|
|
54
|
-
|
55
|
-
if (isAllSelected) {
|
56
|
-
dispatch(clearAllSelection());
|
57
|
-
} else {
|
58
|
+
if (!isSelectAll) {
|
58
59
|
dispatch(setSelectAllAlert(false));
|
59
|
-
dispatch(setSelectAll(false));
|
60
60
|
}
|
61
61
|
};
|
62
62
|
|
63
|
+
const selectAllIds = (dispatch, results, prevSelectedIds = {}) => {
|
64
|
+
const selectedIds = { ...prevSelectedIds };
|
65
|
+
results.forEach(row => {
|
66
|
+
if (row.disableCheckbox) return;
|
67
|
+
selectedIds[row.id] = true;
|
68
|
+
});
|
69
|
+
dispatch(selectByIds(selectedIds));
|
70
|
+
dispatch(setSelectAllAlert(true));
|
71
|
+
};
|
72
|
+
|
63
73
|
export const setSelectAllAlert = showSelectAllAlert => ({
|
64
74
|
type: INSIGHTS_SET_SELECT_ALL_ALERT,
|
65
75
|
payload: { showSelectAllAlert },
|
@@ -70,10 +80,13 @@ export const selectByIds = selectedIds => ({
|
|
70
80
|
payload: { selectedIds },
|
71
81
|
});
|
72
82
|
|
73
|
-
export const setSelectAll = isAllSelected =>
|
74
|
-
|
75
|
-
|
76
|
-
|
83
|
+
export const setSelectAll = isAllSelected => dispatch => {
|
84
|
+
dispatch(setSelectAllUrl(isAllSelected));
|
85
|
+
dispatch({
|
86
|
+
type: INSIGHTS_SET_SELECT_ALL,
|
87
|
+
payload: { isAllSelected },
|
88
|
+
});
|
89
|
+
};
|
77
90
|
|
78
91
|
export const selectAll = () => setSelectAll(true);
|
79
92
|
|
@@ -100,30 +113,42 @@ export const onTablePerPageSelect = (_event, perPageNumber) =>
|
|
100
113
|
fetchInsights({ perPage: perPageNumber });
|
101
114
|
|
102
115
|
export const onTableSelect = (
|
103
|
-
_event,
|
104
116
|
isSelected,
|
105
117
|
rowId,
|
106
|
-
|
118
|
+
rows,
|
107
119
|
prevSelectedIds
|
108
120
|
) => dispatch => {
|
109
|
-
const
|
110
|
-
|
111
|
-
|
121
|
+
const handleRegularCheckbox = () => {
|
122
|
+
const selectedIds = { ...prevSelectedIds };
|
123
|
+
if (isSelected) {
|
124
|
+
selectedIds[rows[rowId].id] = true;
|
125
|
+
} else {
|
126
|
+
dispatch(setSelectAllAlert(false));
|
127
|
+
dispatch(setSelectAll(false));
|
128
|
+
delete selectedIds[rows[rowId].id];
|
129
|
+
}
|
130
|
+
|
131
|
+
dispatch(selectByIds(selectedIds));
|
132
|
+
};
|
133
|
+
|
112
134
|
if (rowId === -1) {
|
113
135
|
if (!isSelected) return dispatch(clearAllSelection());
|
114
|
-
|
115
|
-
results.forEach(row => {
|
116
|
-
selectedIds[row.id] = true;
|
117
|
-
});
|
118
|
-
|
119
|
-
showSelectAllAlert = true;
|
136
|
+
selectAllIds(dispatch, rows, prevSelectedIds);
|
120
137
|
} else {
|
121
|
-
|
122
|
-
? (selectedIds[results[rowId].id] = true)
|
123
|
-
: delete selectedIds[results[rowId].id];
|
138
|
+
handleRegularCheckbox();
|
124
139
|
}
|
125
140
|
|
126
|
-
dispatch(selectByIds(selectedIds));
|
127
|
-
dispatch(setSelectAllAlert(showSelectAllAlert));
|
128
141
|
return null;
|
129
142
|
};
|
143
|
+
|
144
|
+
const setSelectAllUrl = selectAllValue => dispatch => {
|
145
|
+
const uri = new URI();
|
146
|
+
uri.setSearch({ select_all: selectAllValue });
|
147
|
+
|
148
|
+
dispatch(
|
149
|
+
push({
|
150
|
+
pathname: INSIGHTS_PATH,
|
151
|
+
search: uri.search(),
|
152
|
+
})
|
153
|
+
);
|
154
|
+
};
|
@@ -5,6 +5,7 @@ import {
|
|
5
5
|
Section,
|
6
6
|
} from '@redhat-cloud-services/frontend-components';
|
7
7
|
import { sortable, cellWidth } from '@patternfly/react-table';
|
8
|
+
import { CheckCircleIcon } from '@patternfly/react-icons';
|
8
9
|
import { translate as __ } from 'foremanReact/common/I18n';
|
9
10
|
import { foremanUrl } from '../../../ForemanRhCloudHelpers';
|
10
11
|
|
@@ -16,6 +17,10 @@ export const totalRiskFormatter = ({ title: totalRisk }) => ({
|
|
16
17
|
),
|
17
18
|
});
|
18
19
|
|
20
|
+
export const hasPlaybookFormatter = ({ title: hasPlaybook }) => ({
|
21
|
+
children: hasPlaybook ? <CheckCircleIcon color="green" /> : __('No'),
|
22
|
+
});
|
23
|
+
|
19
24
|
export const columns = [
|
20
25
|
{
|
21
26
|
sortKey: 'hostname',
|
@@ -25,22 +30,18 @@ export const columns = [
|
|
25
30
|
{
|
26
31
|
sortKey: 'title',
|
27
32
|
title: __('Recommendation'),
|
28
|
-
transforms: [cellWidth(
|
33
|
+
transforms: [cellWidth(50), sortable],
|
29
34
|
},
|
30
35
|
{
|
31
36
|
sortKey: 'total_risk',
|
32
37
|
title: __('Total Risk'),
|
33
|
-
transforms: [cellWidth(
|
38
|
+
transforms: [cellWidth(15), sortable],
|
34
39
|
cellTransforms: [totalRiskFormatter],
|
35
40
|
},
|
36
|
-
];
|
37
|
-
|
38
|
-
export const actions = [
|
39
41
|
{
|
40
|
-
title: __('
|
41
|
-
|
42
|
-
|
43
|
-
},
|
42
|
+
title: __('Playbook'),
|
43
|
+
transforms: [cellWidth(15)],
|
44
|
+
cellTransforms: [hasPlaybookFormatter],
|
44
45
|
},
|
45
46
|
];
|
46
47
|
|
@@ -1,14 +1,22 @@
|
|
1
1
|
/* eslint-disable camelcase */
|
2
2
|
import { columns } from './InsightsTableConstants';
|
3
3
|
|
4
|
-
export const modifySelectedRows = (hits, selectedIds) => {
|
4
|
+
export const modifySelectedRows = (hits, selectedIds, showSelectAllAlert) => {
|
5
5
|
if (hits.length === 0) return [];
|
6
6
|
|
7
|
-
return hits
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
return hits
|
8
|
+
.asMutable()
|
9
|
+
.map(({ id, hostname, title, total_risk, has_playbook }) => {
|
10
|
+
const disableCheckbox = !has_playbook;
|
11
|
+
return {
|
12
|
+
cells: [hostname, title, total_risk, has_playbook],
|
13
|
+
disableCheckbox,
|
14
|
+
id,
|
15
|
+
/** The main table checkbox will be seen as selected only if all rows are selected,
|
16
|
+
* in this case we need to select also the disabled once and hide it with css */
|
17
|
+
selected: selectedIds[id] || (disableCheckbox && showSelectAllAlert),
|
18
|
+
};
|
19
|
+
});
|
12
20
|
};
|
13
21
|
|
14
22
|
export const getSortColumnIndex = sortBy => {
|
@@ -32,6 +32,7 @@ export const selectQueryParams = state => ({
|
|
32
32
|
query: selectSearch(state),
|
33
33
|
sortBy: selectSortBy(state),
|
34
34
|
sortOrder: selectSortOrder(state),
|
35
|
+
isSelectAll: selectIsAllSelectedQuery(state),
|
35
36
|
});
|
36
37
|
|
37
38
|
export const selectStatus = state =>
|
@@ -64,6 +65,9 @@ export const selectSelectedIds = state =>
|
|
64
65
|
export const selectIsAllSelected = state =>
|
65
66
|
selectInsightsCloudTable(state).isAllSelected || false;
|
66
67
|
|
68
|
+
export const selectIsAllSelectedQuery = state =>
|
69
|
+
selectQuery(state).select_all === 'true';
|
70
|
+
|
67
71
|
export const selectShowSelectAllAlert = state =>
|
68
72
|
selectInsightsCloudTable(state).showSelectAllAlert || false;
|
69
73
|
|
@@ -5,7 +5,6 @@ import { translate as __, sprintf } from 'foremanReact/common/I18n';
|
|
5
5
|
|
6
6
|
const SelectAllAlert = ({
|
7
7
|
selectedIds,
|
8
|
-
itemCount,
|
9
8
|
showSelectAllAlert,
|
10
9
|
selectAll,
|
11
10
|
clearAllSelection,
|
@@ -14,18 +13,15 @@ const SelectAllAlert = ({
|
|
14
13
|
if (!showSelectAllAlert) return null;
|
15
14
|
const selectedCount = Object.keys(selectedIds).length;
|
16
15
|
if (!selectedCount) return null;
|
17
|
-
if (!isAllSelected
|
16
|
+
if (!isAllSelected) {
|
18
17
|
return (
|
19
18
|
<Alert
|
20
19
|
isInline
|
21
20
|
variant="info"
|
22
|
-
title={sprintf(
|
23
|
-
'All %s recommendations on this page are selected.',
|
24
|
-
selectedCount
|
25
|
-
)}
|
21
|
+
title={sprintf('Recommendations selected: %s.', selectedCount)}
|
26
22
|
actionLinks={
|
27
23
|
<AlertActionLink onClick={selectAll}>
|
28
|
-
{
|
24
|
+
{__('Select recommendations from all pages')}
|
29
25
|
</AlertActionLink>
|
30
26
|
}
|
31
27
|
/>
|
@@ -36,7 +32,7 @@ const SelectAllAlert = ({
|
|
36
32
|
<Alert
|
37
33
|
isInline
|
38
34
|
variant="info"
|
39
|
-
title={
|
35
|
+
title={__('All recommendations are now selected.')}
|
40
36
|
actionLinks={
|
41
37
|
<AlertActionLink onClick={clearAllSelection}>
|
42
38
|
{__('Clear Selection')}
|
@@ -48,7 +44,6 @@ const SelectAllAlert = ({
|
|
48
44
|
|
49
45
|
SelectAllAlert.propTypes = {
|
50
46
|
selectedIds: PropTypes.object,
|
51
|
-
itemCount: PropTypes.number,
|
52
47
|
showSelectAllAlert: PropTypes.bool,
|
53
48
|
selectAll: PropTypes.func.isRequired,
|
54
49
|
clearAllSelection: PropTypes.func.isRequired,
|
@@ -57,7 +52,6 @@ SelectAllAlert.propTypes = {
|
|
57
52
|
|
58
53
|
SelectAllAlert.defaultProps = {
|
59
54
|
selectedIds: {},
|
60
|
-
itemCount: 0,
|
61
55
|
showSelectAllAlert: false,
|
62
56
|
isAllSelected: false,
|
63
57
|
};
|
data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTableActions.test.js
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
import { testActionSnapshotWithFixtures } from '@theforeman/test';
|
2
|
+
import API from 'foremanReact/redux/API';
|
3
|
+
import {
|
4
|
+
fetchInsights,
|
5
|
+
setSelectAllAlert,
|
6
|
+
selectByIds,
|
7
|
+
setSelectAll,
|
8
|
+
selectAll,
|
9
|
+
clearAllSelection,
|
10
|
+
} from '../InsightsTableActions';
|
11
|
+
import { hits } from './fixtures';
|
12
|
+
|
13
|
+
jest.mock('foremanReact/redux/API', () => jest.fn());
|
14
|
+
API.get = jest.fn(({ handleSuccess, ...action }) => {
|
15
|
+
handleSuccess({ data: { hits } });
|
16
|
+
return { type: 'get', ...action };
|
17
|
+
});
|
18
|
+
|
19
|
+
const runWithGetState = (state, action, params) => dispatch => {
|
20
|
+
const getState = () => ({
|
21
|
+
router: {
|
22
|
+
location: {
|
23
|
+
query: {
|
24
|
+
page: '1',
|
25
|
+
per_page: '7',
|
26
|
+
search: '',
|
27
|
+
sort_by: '',
|
28
|
+
sort_order: '',
|
29
|
+
select_all: 'true',
|
30
|
+
},
|
31
|
+
},
|
32
|
+
},
|
33
|
+
});
|
34
|
+
action(params)(dispatch, getState);
|
35
|
+
};
|
36
|
+
|
37
|
+
const fixtures = {
|
38
|
+
'should fetchInsights': () =>
|
39
|
+
runWithGetState({}, fetchInsights, { page: 2, perPage: 7 }),
|
40
|
+
'should setSelectAllAlert true': () => setSelectAllAlert(true),
|
41
|
+
'should selectByIds': () => selectByIds({ 1: true, 5: true }),
|
42
|
+
'should setSelectAll false': () => setSelectAll(false),
|
43
|
+
'should selectAll': () => selectAll(),
|
44
|
+
'should clearAllSelection': () => clearAllSelection(),
|
45
|
+
};
|
46
|
+
|
47
|
+
describe('insights table actions', () =>
|
48
|
+
testActionSnapshotWithFixtures(fixtures));
|
@@ -5,20 +5,11 @@ exports[`InsightsTable rendering render with Props 1`] = `
|
|
5
5
|
<SelectAllAlert
|
6
6
|
clearAllSelection={[Function]}
|
7
7
|
isAllSelected={false}
|
8
|
-
itemCount={2}
|
9
8
|
selectAll={[Function]}
|
10
9
|
selectedIds={Object {}}
|
11
10
|
showSelectAllAlert={false}
|
12
11
|
/>
|
13
12
|
<Table
|
14
|
-
actions={
|
15
|
-
Array [
|
16
|
-
Object {
|
17
|
-
"onClick": [Function],
|
18
|
-
"title": "Remediate",
|
19
|
-
},
|
20
|
-
]
|
21
|
-
}
|
22
13
|
aria-label="Recommendations Table"
|
23
14
|
borders={true}
|
24
15
|
canSelectAll={true}
|
@@ -52,9 +43,18 @@ exports[`InsightsTable rendering render with Props 1`] = `
|
|
52
43
|
[Function],
|
53
44
|
],
|
54
45
|
},
|
46
|
+
Object {
|
47
|
+
"cellTransforms": Array [
|
48
|
+
[Function],
|
49
|
+
],
|
50
|
+
"title": "Playbook",
|
51
|
+
"transforms": Array [
|
52
|
+
[Function],
|
53
|
+
],
|
54
|
+
},
|
55
55
|
]
|
56
56
|
}
|
57
|
-
className=""
|
57
|
+
className="recommendations-table"
|
58
58
|
contentId="expanded-content"
|
59
59
|
dropdownDirection="down"
|
60
60
|
dropdownPosition="right"
|
@@ -66,20 +66,7 @@ exports[`InsightsTable rendering render with Props 1`] = `
|
|
66
66
|
ouiaSafe={true}
|
67
67
|
role="grid"
|
68
68
|
rowLabeledBy="simple-node"
|
69
|
-
rows={
|
70
|
-
Array [
|
71
|
-
Array [
|
72
|
-
"foo.example.com",
|
73
|
-
"Decreased security: Yum GPG verification disabled",
|
74
|
-
1,
|
75
|
-
],
|
76
|
-
Array [
|
77
|
-
"foo.example.com",
|
78
|
-
"Installation of packages across major releases is not supported",
|
79
|
-
2,
|
80
|
-
],
|
81
|
-
]
|
82
|
-
}
|
69
|
+
rows={Array []}
|
83
70
|
selectVariant="checkbox"
|
84
71
|
sortBy={
|
85
72
|
Object {
|