Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ClusterRules): Add impacted to single Cluster page #366

Merged
merged 4 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"disabled_at": "2021-09-14T12:48:22Z",
"internal": false,
"user_vote": 1,
"impacted": "2022-06-13T22:00:00.000Z",
"extra_data": {
"error_key": "ERROR_KEY_N1",
"op": {
Expand Down Expand Up @@ -70,6 +71,7 @@
"disabled_at": "2021-09-14T12:48:22Z",
"internal": false,
"user_vote": 1,
"impacted": "2022-06-26T22:00:00.000Z",
"extra_data": {
"error_key": "ERROR_KEY_N2",
"op": {
Expand Down Expand Up @@ -119,6 +121,7 @@
"disabled_at": "2021-09-14T12:48:22Z",
"internal": false,
"user_vote": 1,
"impacted": "2022-06-26T22:00:00.000Z",
"extra_data": {
"error_key": "ERROR_KEY_N3",
"op": {
Expand Down Expand Up @@ -168,6 +171,7 @@
"disabled_at": "2021-09-14T12:48:22Z",
"internal": false,
"user_vote": 1,
"impacted": "2022-06-26T22:00:00.000Z",
"extra_data": {
"error_key": "ERROR_KEY_N4",
"op": {
Expand Down Expand Up @@ -217,6 +221,7 @@
"disabled_at": "2021-09-14T12:48:22Z",
"internal": false,
"user_vote": 1,
"impacted": "2022-06-26T22:00:00.000Z",
"extra_data": {
"error_key": "ERROR_KEY_N5",
"op": {
Expand Down Expand Up @@ -266,6 +271,7 @@
"disabled_at": "2021-09-14T12:48:22Z",
"internal": false,
"user_vote": 1,
"impacted": "2022-06-26T22:00:00.000Z",
"extra_data": {
"error_key": "ERROR_KEY_N6",
"op": {
Expand Down Expand Up @@ -300,7 +306,7 @@
},
"tags": ["security"]
}
]
]
},
"status": "ok"
}
5 changes: 5 additions & 0 deletions src/AppConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export const CLUSTER_RULES_COLUMNS_KEYS = [
'', // reserved for expand button
'description',
'created_at',
'impacted',
'total_risk',
];
export const CLUSTER_RULES_COLUMNS = [
Expand All @@ -300,6 +301,10 @@ export const CLUSTER_RULES_COLUMNS = [
title: intl.formatMessage(messages.modified),
transforms: [sortable, cellWidth(15)],
},
{
title: intl.formatMessage(messages.impacted),
transforms: [sortable, cellWidth(15)],
},
{
title: intl.formatMessage(messages.totalRisk),
transforms: [sortable, cellWidth(15)],
Expand Down
35 changes: 18 additions & 17 deletions src/Components/ClusterRules/ClusterRules.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,24 +205,25 @@ describe('cluster rules table', () => {

describe('sorting', () => {
// all tables must preserve original ordering
_.zip(['description', 'created_at', 'total_risk'], TABLE_HEADERS).forEach(
([category, label]) => {
SORTING_ORDERS.forEach((order) => {
it(`${order} by ${label}`, () => {
checkSorting(
data,
category,
label,
order,
'Description',
'description',
RULES_ENABLED,
null
);
});
_.zip(
['description', 'created_at', 'impacted', 'total_risk'],
TABLE_HEADERS
).forEach(([category, label]) => {
SORTING_ORDERS.forEach((order) => {
it(`${order} by ${label}`, () => {
checkSorting(
data,
category,
label,
order,
'Description',
'description',
RULES_ENABLED,
null
);
});
}
);
});
});
});

describe('filtering', () => {
Expand Down
36 changes: 36 additions & 0 deletions src/Components/ClusterRules/ClusterRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,36 @@ const ClusterRules = ({ cluster }) => {
</div>
),
},
value.impacted
? {
title: (
<div key={key}>
<DateFormat
extraTitle={`${intl.formatMessage(
messages.impacted
)}: `}
date={value.impacted}
type="relative"
tooltipProps={{ position: TooltipPosition.bottom }}
/>
</div>
),
}
: {
title: (
<Tooltip
key={key}
content={
<span>
{intl.formatMessage(messages.impacted) + ': '}
{intl.formatMessage(messages.nA)}
</span>
}
>
<span>{intl.formatMessage(messages.nA)}</span>
</Tooltip>
),
},
{
title: (
<div key={key} style={{ verticalAlign: 'top' }}>
Expand Down Expand Up @@ -244,6 +274,12 @@ const ClusterRules = ({ cluster }) => {
sortingRows = [...rows].sort((firstItem, secondItem) => {
const fst = firstItem[0].rule[CLUSTER_RULES_COLUMNS_KEYS[index]];
const snd = secondItem[0].rule[CLUSTER_RULES_COLUMNS_KEYS[index]];
if (index === 3) {
Fewwy marked this conversation as resolved.
Show resolved Hide resolved
//sorting for the impacted column
const firstDate = new Date(firstItem[0].rule.impacted || 0);
const secondDate = new Date(secondItem[0].rule.impacted || 0);
return firstDate > secondDate ? d : secondDate > firstDate ? -d : 0;
Fewwy marked this conversation as resolved.
Show resolved Hide resolved
}
return fst > snd ? d : snd > fst ? -d : 0;
});
} else if (firstRule) {
Expand Down