Skip to content

Commit

Permalink
Apply comment suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
EMaksy committed May 14, 2023
1 parent 745f48c commit 935e2fa
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
20 changes: 10 additions & 10 deletions assets/js/components/ExecutionResults/ExecutionResults.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { useState } from 'react';
import Table from '@components/Table';
import Accordion from '@components/Accordion';
import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
import Modal from '@components/Modal';
import { getHostID } from '@state/selectors/cluster';
import PremiumPill from '@components/PremiumPill';
import Accordion from '@components/Accordion';
import HealthIcon from '@components/Health';

import Modal from '@components/Modal';
import PremiumPill from '@components/PremiumPill';
import Table from '@components/Table';
import {
getCatalogCategoryList,
getCheckResults,
Expand Down Expand Up @@ -62,7 +61,7 @@ const resultsTableConfig = {
title: 'Result',
key: 'result',
fontSize: 'text-base',
className: 'bg-gray-50 border-b w-1/6 h-auto text-base',
className: 'bg-gray-50 border-b w-1/6 h-auto',
render: (_, { result }) => <HealthIcon health={result} />,
},
],
Expand Down Expand Up @@ -151,6 +150,10 @@ function ExecutionResults({
},
})
);
const filterAndSortData = (data, item) =>
data
.filter((obj) => obj.category === item)
.sort((a, b) => a.description.localeCompare(b.description));

return (
<ExecutionContainer
Expand Down Expand Up @@ -188,9 +191,7 @@ function ExecutionResults({
>
<Table
config={resultsTableConfig}
data={tableData
.filter((obj) => obj.category === item)
.sort((a, b) => a.description.localeCompare(b.description))}
data={filterAndSortData(tableData, item)}
withPadding={false}
/>
</Accordion>
Expand All @@ -212,5 +213,4 @@ function ExecutionResults({
</ExecutionContainer>
);
}

export default ExecutionResults;
2 changes: 1 addition & 1 deletion assets/js/components/ExecutionResults/checksUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const isPremium = (catalog, checkID) => {
};

export const getCatalogCategoryList = (catalog, checksResults = []) => {
if (catalog.length === 0) {
if (!catalog || catalog.length === 0 || !checksResults) {
return [];
}
return [
Expand Down
28 changes: 15 additions & 13 deletions assets/js/components/ExecutionResults/checksUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,35 @@ describe('checksUtils', () => {
});

it('getCatalogCategoryList should return a sorted category list where it is matching', () => {
const fakerListID = [
const IDs = [
faker.datatype.number(),
faker.datatype.number(),
faker.datatype.number(),
];
const execution = [
{ check_id: fakerListID[0] },
{ check_id: fakerListID[1] },
{ check_id: fakerListID[2] },
const checksResults = [
{ check_id: IDs[0] },
{ check_id: IDs[1] },
{ check_id: IDs[2] },
];
const catalog = [
{ id: fakerListID[0], group: 'Category C' },
{ id: fakerListID[1], group: 'Category A' },
{ id: fakerListID[2], group: 'Category B' },
{ id: IDs[0], group: 'Category C' },
{ id: IDs[1], group: 'Category A' },
{ id: IDs[2], group: 'Category B' },
];
const expected = ['Category A', 'Category B', 'Category C'];
expect(getCatalogCategoryList(catalog, execution)).toEqual(expected);
expect(getCatalogCategoryList(catalog, checksResults)).toEqual(expected);
});

it('getCatalogCategoryList should return an empty array if checksResults is not provided', () => {
const fakerListID = [faker.datatype.number(), faker.datatype.number()];
const IDs = [faker.datatype.number(), faker.datatype.number()];
const catalog = [
{ id: fakerListID[0], group: faker.lorem.word() },
{ id: fakerListID[1], group: faker.lorem.word() },
{ id: IDs[0], group: faker.lorem.word() },
{ id: IDs[1], group: faker.lorem.word() },
];
const expected = [];
expect(getCatalogCategoryList(catalog, undefined)).toEqual(expected);
[[], undefined, null].forEach((item) => {
expect(getCatalogCategoryList(catalog, item)).toEqual(expected);
});
});

it('getDescription should return a check description', () => {
Expand Down
8 changes: 3 additions & 5 deletions assets/js/components/Table/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,9 @@ function Table({
</div>
<div className="">
<div
className={
withPadding
? '-mx-4 sm:-mx-8 px-4 sm:px-8 pt-4'
: '-mx-4 sm:-mx-8 px-4 sm:px-8 '
}
className={classNames('-mx-4 sm:-mx-8 px-4 sm:px-8', {
'pt-4': withPadding,
})}
>
<div className="min-w-fit shadow rounded-lg">
<table className="min-w-full leading-normal table-fixed">
Expand Down

0 comments on commit 935e2fa

Please sign in to comment.