Skip to content

Commit

Permalink
fix(tableSkeleton): allow table with zero rows (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Sep 10, 2020
1 parent ef0333a commit 00c001b
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,134 @@ exports[`TableSkeleton Component should allow variations in table layout: column
/>
`;

exports[`TableSkeleton Component should allow variations in table layout: no table header and zero rows 1`] = `
<Table
ariaLabel="t(curiosity-inventory.tableSkeletonAriaLabel)"
borders={false}
className="curiosity-skeleton-table curiosity-skeleton-table__hidden-rows lorem-ipsum-class"
columnHeaders={
Array [
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
]
}
isHeader={false}
rows={
Array [
Object {
"cells": Array [
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
],
},
]
}
summary={null}
t={[Function]}
variant="compact"
/>
`;

exports[`TableSkeleton Component should allow variations in table layout: table header and zero rows 1`] = `
<Table
ariaLabel="t(curiosity-inventory.tableSkeletonAriaLabel)"
borders={false}
className="curiosity-skeleton-table curiosity-skeleton-table__hidden-rows lorem-ipsum-class"
columnHeaders={
Array [
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
]
}
isHeader={true}
rows={
Array [
Object {
"cells": Array [
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
<Skeleton
isDark={false}
size="md"
/>,
],
},
]
}
summary={null}
t={[Function]}
variant="compact"
/>
`;

exports[`TableSkeleton Component should render a non-connected component: non-connected 1`] = `
<Table
ariaLabel="t(curiosity-inventory.tableSkeletonAriaLabel)"
Expand Down
10 changes: 10 additions & 0 deletions src/components/table/__tests__/tableSkeleton.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,15 @@ describe('TableSkeleton Component', () => {
variant: TableVariant.compact
});
expect(component).toMatchSnapshot('className and variant');

component.setProps({
rowCount: 0
});
expect(component).toMatchSnapshot('no table header and zero rows');

component.setProps({
isHeader: true
});
expect(component).toMatchSnapshot('table header and zero rows');
});
});
7 changes: 5 additions & 2 deletions src/components/table/tableSkeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ import { translate } from '../i18n/i18n';
*/
const TableSkeleton = ({ className, borders, colCount, isHeader, rowCount, t, variant }) => {
const updatedColumnHeaders = [...new Array(colCount)].map(() => <Skeleton size={SkeletonSize.md} />);
const updatedRowCount = rowCount || 1;

const updatedRows = [...new Array(rowCount)].map(() => ({
const updatedRows = [...new Array(updatedRowCount)].map(() => ({
cells: [...new Array(colCount)].map(() => <Skeleton size={SkeletonSize.md} />)
}));

return (
<Table
ariaLabel={t('curiosity-inventory.tableSkeletonAriaLabel')}
borders={borders}
className={`curiosity-skeleton-table ${className || ''}`}
className={`curiosity-skeleton-table${(!rowCount && ' curiosity-skeleton-table__hidden-rows') || ''} ${
className || ''
}`}
columnHeaders={updatedColumnHeaders}
isHeader={isHeader}
rows={updatedRows}
Expand Down
8 changes: 8 additions & 0 deletions src/styles/_skeleton.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@
height: 200px;
}
}

.curiosity-skeleton-table {
&.curiosity-skeleton-table__hidden-rows {
tbody {
display: none
}
}
}
}

0 comments on commit 00c001b

Please sign in to comment.