Skip to content

Commit

Permalink
fix(RHINENG-11976): Fix table loading states (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
xmicha82 authored Dec 17, 2024
1 parent 04b36fb commit 503cffc
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 326 deletions.
2 changes: 1 addition & 1 deletion cypress/utils/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ function checkSorting(
}
});
} else {
cy.get(header).find('button').click();
cy.get(header)
.find('button')
.click()
.click() // TODO dblclick fails for unknown reason in RecsListTable when sorting by Clusters
.then(() => {
if (validateURL) {
Expand Down
45 changes: 23 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"postinstall": "ts-patch install"
},
"dependencies": {
"@patternfly/react-component-groups": "^5.4.0",
"@patternfly/react-core": "^5.4.8",
"@patternfly/react-icons": "^5.4.2",
"@patternfly/react-table": "^5.4.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,14 @@ describe('non-empty successful affected clusters table', () => {
});

it('renders table header', () => {
cy.get('[data-ouia-component-id=SkeletonTable-tr-0]').should('not.exist');
checkTableHeaders(TABLE_HEADERS);
});

it('rows show cluster names instead uuids when available', () => {
const names = _.map(data, 'name');
// Wait for skeleton to disappear
cy.get('[data-ouia-component-id=loading-skeleton]').should('not.exist');
cy.get('[data-ouia-component-id=SkeletonTable-tr-0]').should('not.exist');
cy.get(`td[data-label="Name"]`)
.then(($els) => {
return _.map(Cypress.$.makeArray($els), 'innerText');
Expand All @@ -178,7 +179,7 @@ describe('non-empty successful affected clusters table', () => {
});

it('names of rows are links', () => {
cy.get('[data-ouia-component-id=loading-skeleton]').should('not.exist');
cy.get('[data-ouia-component-id=SkeletonTable-tr-0]').should('not.exist');
cy.get(TABLE)
.find(TABLE_ROW)
.each(($el, index) => {
Expand Down Expand Up @@ -641,6 +642,7 @@ describe('empty successful affected clusters table', () => {
});

it('renders table headers', () => {
cy.get('[data-ouia-component-id=SkeletonTable-tr-0]').should('not.exist');
checkTableHeaders(TABLE_HEADERS);
});
});
Expand Down
116 changes: 61 additions & 55 deletions src/Components/AffectedClustersTable/AffectedClustersTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
AFFECTED_CLUSTERS_VERSION_CELL,
FILTER_CATEGORIES,
} from '../../AppConstants';
import Loading from '../Loading/Loading';
import {
AFFECTED_CLUSTERS_INITIAL_STATE,
resetFilters,
Expand All @@ -45,6 +44,7 @@ import {
addFilterParam as _addFilterParam,
} from '../Common/Tables';
import { BASE_PATH } from '../../Routes';
import { SkeletonTable } from '@patternfly/react-component-groups';

const AffectedClustersTable = ({ query, rule, afterDisableFn }) => {
const intl = useIntl();
Expand Down Expand Up @@ -97,7 +97,7 @@ const AffectedClustersTable = ({ query, rule, afterDisableFn }) => {
type: conditionalFilterType.text,
filterValues: {
id: 'name-filter',
key: 'name-filter',
// key: 'name-filter',
onChange: (event, value) => addFilterParam('text', value),
value: filters.text,
},
Expand All @@ -108,7 +108,7 @@ const AffectedClustersTable = ({ query, rule, afterDisableFn }) => {
type: conditionalFilterType.checkbox,
filterValues: {
id: 'version-filter',
key: 'version-filter',
// key: 'version-filter',
onChange: (event, value) => addFilterParam('version', value),
value: filters.version,
items: uniqBy(
Expand Down Expand Up @@ -384,59 +384,65 @@ const AffectedClustersTable = ({ query, rule, afterDisableFn }) => {
],
}}
/>
<Table
aria-label="Table of affected clusters"
ouiaId="clusters"
ouiaSafe={!loadingState}
variant="compact"
cells={AFFECTED_CLUSTERS_COLUMNS}
rows={
errorState || loadingState || noMatch || noInput ? (
[
{
fullWidth: true,
cells: [
{
props: {
colSpan: AFFECTED_CLUSTERS_COLUMNS.length + 1,
{loadingState ? (
<SkeletonTable
columns={AFFECTED_CLUSTERS_COLUMNS.map((c) => c.title)}
isSelectable
variant="compact"
/>
) : (
<Table
aria-label="Table of affected clusters"
ouiaId="clusters"
ouiaSafe={!loadingState}
variant="compact"
cells={AFFECTED_CLUSTERS_COLUMNS}
rows={
errorState || loadingState || noMatch || noInput ? (
[
{
fullWidth: true,
cells: [
{
props: {
colSpan: AFFECTED_CLUSTERS_COLUMNS.length + 1,
},
title: errorState ? (
<ErrorState />
) : noInput ? (
<NoAffectedClusters />
) : (
<NoMatchingClusters />
),
},
title: errorState ? (
<ErrorState />
) : loadingState ? (
<Loading />
) : noInput ? (
<NoAffectedClusters />
) : (
<NoMatchingClusters />
),
},
],
},
]
) : successState ? (
displayedRows
) : (
<ErrorState />
)
}
sortBy={{
index: filters.sortIndex,
direction: filters.sortDirection,
}}
onSort={onSort}
canSelectAll={false}
onSelect={displayedRows?.length > 0 ? onSelect : undefined}
actions={[
{
title: 'Disable recommendation for cluster',
onClick: (event, rowIndex) =>
handleModalToggle(true, filteredRows[rowIndex].id),
},
]}
>
<TableHeader />
<TableBody />
</Table>
],
},
]
) : successState ? (
displayedRows
) : (
<ErrorState />
)
}
sortBy={{
index: filters.sortIndex,
direction: filters.sortDirection,
}}
onSort={onSort}
canSelectAll={false}
onSelect={displayedRows?.length > 0 ? onSelect : undefined}
actions={[
{
title: 'Disable recommendation for cluster',
onClick: (event, rowIndex) =>
handleModalToggle(true, filteredRows[rowIndex].id),
},
]}
>
<TableHeader />
<TableBody />
</Table>
)}
<Pagination
variant={PaginationVariant.bottom}
itemCount={filteredRows.length}
Expand Down
10 changes: 4 additions & 6 deletions src/Components/ClusterRules/ClusterRules.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,8 @@ describe('cluster rules table', () => {

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

Expand Down Expand Up @@ -413,7 +410,8 @@ describe('cluster rules table testing the first query parameter', () => {
if (order === 'ascending') {
cy.get(header).find('button').click();
} else {
cy.get(header).find('button').click().click();
cy.get(header).find('button').click();
cy.get(header).find('button').click();
}
let sortedDescriptions = _.map(
_.orderBy(
Expand Down
Loading

0 comments on commit 503cffc

Please sign in to comment.