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

Re-add checks filtering into the new Checks UI #1231

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
43 changes: 27 additions & 16 deletions assets/js/components/ExecutionResults/ExecutionResults.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import Table from '@components/Table';

import ReactMarkdown from 'react-markdown';
Expand Down Expand Up @@ -89,6 +89,8 @@ function ExecutionResults({
onLastExecutionUpdate = () => {},
onStartExecution = () => {},
}) {
const [predicates, setPredicates] = useState([]);

const hosts = hostnames.map((item) => item.id);

if (catalogLoading) {
Expand Down Expand Up @@ -121,22 +123,30 @@ function ExecutionResults({
);
}

const tableData = getCheckResults(executionData).map(
({
check_id: checkID,
result,
expectation_results: expectationResults,
agents_check_results: agentsCheckResults,
}) => ({
checkID,
result,
clusterName,
executionState: executionData?.status,
description: getCheckDescription(catalog, checkID),
expectationResults,
agentsCheckResults: addHostnameToTargets(agentsCheckResults, hostnames),
const tableData = getCheckResults(executionData)
.filter((check) => {
if (predicates.length === 0) {
return true;
}

return predicates.some((predicate) => predicate(check));
})
);
.map(
({
check_id: checkID,
result,
expectation_results: expectationResults,
agents_check_results: agentsCheckResults,
}) => ({
checkID,
result,
clusterName,
executionState: executionData?.status,
description: getCheckDescription(catalog, checkID),
expectationResults,
agentsCheckResults: addHostnameToTargets(agentsCheckResults, hostnames),
})
);

return (
<>
Expand All @@ -145,6 +155,7 @@ function ExecutionResults({
clusterName={clusterName}
cloudProvider={cloudProvider}
clusterScenario={clusterScenario}
onFilterChange={(newPredicates) => setPredicates(newPredicates)}
/>
<ResultsContainer
catalogError={false}
Expand Down
85 changes: 85 additions & 0 deletions assets/js/components/ExecutionResults/ExecutionResults.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,89 @@ describe('ExecutionResults', () => {
const svgText = screen.getByText('Select Checks now');
expect(svgText).toBeInTheDocument();
});

it("should render ExecutionResults with successfully filtered 'passing' results", async () => {
const {
clusterID,
hostnames,
checks: [checkID1, checkID2],
loading,
catalog,
error,
executionLoading,
executionData,
executionError,
executionStarted,
} = prepareStateData('passing');

renderWithRouter(
<ExecutionResults
clusterID={clusterID}
clusterName="test-cluster"
clusterScenario="hana_scale_up"
cloudProvider="azure"
hostnames={hostnames}
catalogLoading={loading}
catalog={catalog}
executionStarted={executionStarted}
catalogError={error}
executionLoading={executionLoading}
executionData={executionData}
executionError={executionError}
/>,
{ route: `/clusters/${clusterID}/executions/last?health=passing` }
);

expect(screen.getAllByText('test-cluster')).toHaveLength(2);
expect(screen.getByText('HANA scale-up')).toBeTruthy();
expect(screen.getByText('Azure')).toBeTruthy();
expect(screen.getByText(hostnames[0].hostname)).toBeTruthy();
expect(screen.getByText(hostnames[1].hostname)).toBeTruthy();
expect(screen.getAllByText(checkID1)).toHaveLength(1);
expect(screen.queryByText(checkID2)).toBeNull();
});

it("should render ExecutionResults with successfully filtered 'passing' and 'critical' results", async () => {
const {
clusterID,
hostnames,
checks: [checkID1, checkID2],
loading,
catalog,
executionStarted,
error,
executionLoading,
executionData,
executionError,
} = prepareStateData('passing');

renderWithRouter(
<ExecutionResults
clusterID={clusterID}
clusterName="test-cluster"
clusterScenario="hana_scale_up"
cloudProvider="azure"
hostnames={hostnames}
catalogLoading={loading}
catalog={catalog}
executionStarted={executionStarted}
catalogError={error}
executionLoading={executionLoading}
executionData={executionData}
executionError={executionError}
/>,
{
route: `/clusters/${clusterID}/executions/last?health=passing&health=critical
`,
}
);

expect(screen.getAllByText('test-cluster')).toHaveLength(2);
expect(screen.getByText('HANA scale-up')).toBeTruthy();
expect(screen.getByText('Azure')).toBeTruthy();
expect(screen.getAllByText(hostnames[0].hostname)).toHaveLength(2);
expect(screen.getAllByText(hostnames[1].hostname)).toHaveLength(2);
expect(screen.getAllByText(checkID1)).toHaveLength(1);
expect(screen.getAllByText(checkID2)).toHaveLength(1);
});
});