Skip to content

Commit

Permalink
fix(ClusterRules): Open rows memorization (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fewwy authored May 9, 2022
1 parent 3d8f9de commit 83f754e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/Components/ClusterRules/ClusterRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const ClusterRules = ({ cluster }) => {
const { isError, isUninitialized, isFetching, isSuccess, data, error } =
cluster;
const reports = data?.report?.data || [];

const [filteredRows, setFilteredRows] = useState([]);
const [displayedRows, setDisplayedRows] = useState([]);
const [isAllExpanded, setIsAllExpanded] = useState(false);
Expand Down Expand Up @@ -119,13 +118,19 @@ const ClusterRules = ({ cluster }) => {
setDisplayedRows(collapseRows);
};

const buildFilteredRows = (allRows, filters) =>
allRows
const buildFilteredRows = (allRows, filters) => {
const expandedRowsSet = new Set(
displayedRows
.filter((ruleExpanded) => ruleExpanded?.isOpen)
.map((object) => object?.rule?.rule_id)
);

return allRows
.filter((rule) => passFilters(rule, filters))
.map((value, key) => [
{
rule: value,
isOpen: isAllExpanded,
isOpen: isAllExpanded || expandedRowsSet?.has(value?.rule_id),
cells: [
{
title: (
Expand Down Expand Up @@ -194,6 +199,7 @@ const ClusterRules = ({ cluster }) => {
],
},
]);
};

const buildDisplayedRows = (rows, index, direction) => {
let sortingRows = [...rows];
Expand Down Expand Up @@ -227,6 +233,7 @@ const ClusterRules = ({ cluster }) => {
};

const onSort = (_e, index, direction) => {
setExpandFirst(false);
setFirstRule('');
return updateFilters({
...filters,
Expand Down
12 changes: 11 additions & 1 deletion src/Components/ClusterRules/ClusterRules.spec.ct.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe('cluster rules table', () => {
});

describe('defaults', () => {
it('only first item expanded', () => {
it('only one row is expanded', () => {
cy.get('#expanded-content1').should('have.length', 1);
cy.get(EXPANDABLES).should('have.length', 1);
});
Expand All @@ -207,6 +207,16 @@ describe('cluster rules table', () => {
cy.get(EXPANDABLES).should('have.length', 0);
});

it('expand one row then sort', () => {
cy.get(ROOT).find('#expandable-toggle2').click();
cy.get(ROOT)
.find('th[data-label=Description]')
.find('button')
.click()
.click();
cy.get(EXPANDABLES).should('have.length', 2);
});

describe('sorting', () => {
// all tables must preserve original ordering
_.zip(['description', 'created_at', 'total_risk'], TABLE_HEADERS).forEach(
Expand Down

0 comments on commit 83f754e

Please sign in to comment.