-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom DataTableSkeleton component to support display of filters
If a consumer of the Table component provides a value for the `filters` prop, they should reasonably be able to expect that those filters will be displayed regardless of the loading state of the rest of the table. Update the loading state to use a custom DataTableSkeleton component based on the Carbon DataTableSkeleton, but with some minor changes: - only display the description skeleton if the table uses a description - remove support for zebra striping as this is not used in the Dashboard - include support for different row sizes directly in the skeleton component instead of relying on consumers to provide custom classnames to control this - if the table has `filters`, render them in the table skeleton toolbar - ensure the filters are left-aligned, replacing the toolbar button skeleton which is present by default and right-aligned
- Loading branch information
1 parent
7b8f7bc
commit 755db6d
Showing
6 changed files
with
141 additions
and
13 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
packages/components/src/components/DataTableSkeleton/DataTableSkeleton.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
Copyright 2024 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { usePrefix } from '@carbon/react'; | ||
import { classNames } from '@tektoncd/dashboard-utils'; | ||
|
||
export default function DataTableSkeleton({ | ||
filters, | ||
headers, | ||
rowCount = 5, | ||
columnCount = 5, | ||
compact = false, | ||
className, | ||
showDescription, | ||
showHeader = true, | ||
showToolbar = true, | ||
size, | ||
...rest | ||
}) { | ||
const prefix = usePrefix(); | ||
|
||
const dataTableSkeletonClasses = classNames(className, { | ||
[`${prefix}--skeleton`]: true, | ||
[`${prefix}--data-table`]: true, | ||
[`${prefix}--data-table--compact`]: compact, | ||
[`${prefix}--data-table--${size}`]: true | ||
}); | ||
|
||
const rows = Array(rowCount); | ||
const columnsArray = Array.from({ length: columnCount }, (_, index) => index); | ||
for (let i = 0; i < rowCount; i += 1) { | ||
rows[i] = ( | ||
<tr key={i}> | ||
{columnsArray.map(j => ( | ||
<td key={j}> | ||
<span /> | ||
</td> | ||
))} | ||
</tr> | ||
); | ||
} | ||
|
||
return ( | ||
<div className={`${prefix}--skeleton ${prefix}--data-table-container`}> | ||
{showHeader ? ( | ||
<div className={`${prefix}--data-table-header`}> | ||
<div className={`${prefix}--data-table-header__title`} /> | ||
{showDescription && ( | ||
<div className={`${prefix}--data-table-header__description`} /> | ||
)} | ||
</div> | ||
) : null} | ||
{showToolbar ? ( | ||
<section | ||
aria-label="data table toolbar" | ||
className={`${prefix}--table-toolbar`} | ||
> | ||
<div className={`${prefix}--toolbar-content`}> | ||
{filters || ( | ||
<span | ||
className={`${prefix}--skeleton ${prefix}--btn ${prefix}--btn--sm`} | ||
/> | ||
)} | ||
</div> | ||
</section> | ||
) : null} | ||
<table className={dataTableSkeletonClasses} {...rest}> | ||
<thead> | ||
<tr> | ||
{columnsArray.map(i => ( | ||
<th key={i}> | ||
{headers ? ( | ||
<div className={`${prefix}--table-header-label`}> | ||
{headers[i]?.header} | ||
</div> | ||
) : ( | ||
<span /> | ||
)} | ||
</th> | ||
))} | ||
</tr> | ||
</thead> | ||
<tbody>{rows}</tbody> | ||
</table> | ||
</div> | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/components/src/components/DataTableSkeleton/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
Copyright 2024 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
/* istanbul ignore file */ | ||
|
||
export { default } from './DataTableSkeleton'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters