feat: added support for loaders / spinners in table component. (#15683)

* feat: added loader/spinner support for table

* added empty data state in table

* updated no data UI for table

Co-authored-by: Ankita Kinger <ankita@appsmith.com>
This commit is contained in:
Sangeeth Sivan 2022-08-16 16:48:12 +05:30 committed by GitHub
parent 50014eef78
commit 5e2e701220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,9 @@ import styled from "styled-components";
import { ReactComponent as DownArrow } from "assets/icons/ads/down_arrow.svg"; import { ReactComponent as DownArrow } from "assets/icons/ads/down_arrow.svg";
import { ReactComponent as UpperArrow } from "assets/icons/ads/upper_arrow.svg"; import { ReactComponent as UpperArrow } from "assets/icons/ads/upper_arrow.svg";
import { Classes } from "./common"; import { Classes } from "./common";
import Spinner from "./Spinner";
import { IconSize } from "./Icon";
import EmptyDataState from "components/utils/EmptyDataState";
const Styles = styled.div` const Styles = styled.div`
table { table {
@ -45,11 +48,6 @@ const Styles = styled.div`
tbody { tbody {
tr { tr {
td:first-child {
color: ${(props) => props.theme.colors.table.rowTitle};
font-weight: ${(props) => props.theme.fontWeights[1]};
}
td { td {
padding: ${(props) => props.theme.spaces[4]}px padding: ${(props) => props.theme.spaces[4]}px
${(props) => props.theme.spaces[9]}px; ${(props) => props.theme.spaces[9]}px;
@ -60,6 +58,19 @@ const Styles = styled.div`
props.theme.typography.p1.letterSpacing}px; props.theme.typography.p1.letterSpacing}px;
font-weight: normal; font-weight: normal;
border-bottom: 1px solid ${(props) => props.theme.colors.table.border}; border-bottom: 1px solid ${(props) => props.theme.colors.table.border};
&:first-child {
color: ${(props) => props.theme.colors.table.rowTitle};
font-weight: ${(props) => props.theme.fontWeights[1]};
}
&.no-border {
border: none;
.no-data-title {
color: ${(props) => props.theme.colors.table.rowData};
}
}
} }
&:hover { &:hover {
@ -69,11 +80,16 @@ const Styles = styled.div`
fill: ${(props) => props.theme.colors.table.hover.rowTitle}; fill: ${(props) => props.theme.colors.table.hover.rowTitle};
} }
} }
td:first-child {
color: ${(props) => props.theme.colors.table.hover.rowTitle};
}
td { td {
color: ${(props) => props.theme.colors.table.hover.rowData}; color: ${(props) => props.theme.colors.table.hover.rowData};
&:first-child {
color: ${(props) => props.theme.colors.table.hover.rowTitle};
}
&.no-border {
background-color: var(--appsmith-color-black-0);
}
} }
} }
} }
@ -84,13 +100,31 @@ const Styles = styled.div`
const HiddenArrow = styled(DownArrow)` const HiddenArrow = styled(DownArrow)`
visibility: hidden; visibility: hidden;
`; `;
const CentralizedWrapper = styled.div`
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 250px;
`;
export interface TableProps { export interface TableProps {
data: any[]; data: any[];
columns: any[]; columns: any[];
isLoading?: boolean;
loaderComponent?: JSX.Element;
noDataComponent?: JSX.Element;
} }
function Table(props: TableProps) { function Table(props: TableProps) {
const { columns, data } = props; const {
columns,
data,
isLoading = false,
loaderComponent,
noDataComponent,
} = props;
const { const {
getTableBodyProps, getTableBodyProps,
@ -127,24 +161,46 @@ function Table(props: TableProps) {
))} ))}
</thead> </thead>
<tbody {...getTableBodyProps()}> <tbody {...getTableBodyProps()}>
{rows.map((row, index) => { {isLoading ? (
prepareRow(row); <tr>
return ( <td className="no-border" colSpan={columns?.length}>
<tr {...row.getRowProps()} key={index}> <CentralizedWrapper>
{row.cells.map((cell, index) => { {loaderComponent ? (
return ( loaderComponent
<td ) : (
{...cell.getCellProps()} <Spinner size={IconSize.XXL} />
data-colindex={index} )}
key={index} </CentralizedWrapper>
> </td>
{cell.render("Cell")} </tr>
</td> ) : rows.length > 0 ? (
); rows.map((row, index) => {
})} prepareRow(row);
</tr> return (
); <tr {...row.getRowProps()} key={index}>
})} {row.cells.map((cell, index) => {
return (
<td
{...cell.getCellProps()}
data-colindex={index}
key={index}
>
{cell.render("Cell")}
</td>
);
})}
</tr>
);
})
) : (
<tr>
<td className="no-border" colSpan={columns?.length}>
<CentralizedWrapper>
{noDataComponent ? noDataComponent : <EmptyDataState />}
</CentralizedWrapper>
</td>
</tr>
)}
</tbody> </tbody>
</table> </table>
</Styles> </Styles>