-
Notifications
You must be signed in to change notification settings - Fork 11
Add the Table Component #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 1 commit
7503c1e
cad734b
53f4f92
797de98
9eec770
9aa39d8
e578bb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { storiesOf } from '@storybook/react'; | ||
import React from 'react'; | ||
import { ThemedBackground } from '../../../utils/storybook'; | ||
import { BasicTable } from '../BasicTable'; | ||
import { | ||
tableHead, | ||
tableData, | ||
pageCount, | ||
paginationData, | ||
onChangePage, | ||
} from './data'; | ||
|
||
storiesOf('Table/Basic Table', module) | ||
// Litmus Portal | ||
.add('Litmus Portal', () => ( | ||
<ThemedBackground platform="litmus-portal"> | ||
<BasicTable | ||
tableData={tableData} | ||
tableHead={tableHead} | ||
pageCount={pageCount} | ||
paginationData={paginationData} | ||
onChangePage={onChangePage} | ||
/> | ||
</ThemedBackground> | ||
)) | ||
|
||
// Kubera Chaos | ||
.add('Kubera Chaos', () => ( | ||
<ThemedBackground platform="kubera-chaos"> | ||
<BasicTable | ||
tableData={tableData} | ||
tableHead={tableHead} | ||
pageCount={pageCount} | ||
paginationData={paginationData} | ||
onChangePage={onChangePage} | ||
/> | ||
</ThemedBackground> | ||
)) | ||
|
||
// Kubera Propel | ||
.add('Kubera Propel', () => ( | ||
<ThemedBackground platform="kubera-propel"> | ||
<BasicTable | ||
tableData={tableData} | ||
tableHead={tableHead} | ||
pageCount={pageCount} | ||
paginationData={paginationData} | ||
onChangePage={onChangePage} | ||
/>{' '} | ||
</ThemedBackground> | ||
)) | ||
|
||
// Kubera Portal | ||
.add('Kubera Portal', () => ( | ||
<ThemedBackground platform="kubera-portal"> | ||
<BasicTable | ||
tableData={tableData} | ||
tableHead={tableHead} | ||
pageCount={pageCount} | ||
paginationData={paginationData} | ||
onChangePage={onChangePage} | ||
/> | ||
</ThemedBackground> | ||
)) | ||
|
||
// Kubera Core | ||
.add('Kubera Core', () => ( | ||
<ThemedBackground platform="kubera-core"> | ||
<BasicTable | ||
tableData={tableData} | ||
tableHead={tableHead} | ||
pageCount={pageCount} | ||
paginationData={paginationData} | ||
onChangePage={onChangePage} | ||
/> | ||
</ThemedBackground> | ||
)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { | ||
Table, | ||
TableBody, | ||
TableContainer, | ||
TableHead, | ||
TableProps, | ||
TablePagination, | ||
Paper, | ||
} from '@material-ui/core'; | ||
import React from 'react'; | ||
import { useStyles } from './style'; | ||
|
||
interface PaginationData { | ||
pageNo: number; | ||
rowsPerPage: number; | ||
} | ||
|
||
interface BasicTableProps extends TableProps { | ||
|
||
tableHead: React.ReactNode; | ||
tableData: React.ReactNode; | ||
paginationData: PaginationData; | ||
pageCount: number; | ||
onChangePage: (_: any, page: number) => any; | ||
onChangeRowsPerPage?: ( | ||
event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement> | ||
) => void; | ||
} | ||
|
||
const BasicTable: React.FC<BasicTableProps> = ({ | ||
tableHead, | ||
tableData, | ||
paginationData, | ||
pageCount, | ||
onChangePage, | ||
onChangeRowsPerPage, | ||
}) => { | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<Paper className={classes.root} data-testid="table"> | ||
<TableContainer className={classes.tableMain}> | ||
<Table stickyHeader> | ||
<TableHead className={classes.tableHead}>{tableHead}</TableHead> | ||
<TableBody>{tableData}</TableBody> | ||
</Table> | ||
</TableContainer> | ||
<TablePagination | ||
rowsPerPageOptions={[5, 10, 25]} | ||
component="div" | ||
count={pageCount} | ||
rowsPerPage={paginationData.rowsPerPage} | ||
page={paginationData.pageNo} | ||
onChangePage={onChangePage} | ||
onChangeRowsPerPage={onChangeRowsPerPage} | ||
/> | ||
</Paper> | ||
); | ||
}; | ||
|
||
export { BasicTable }; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { KuberaThemeProvider } from '../../../../theme'; | ||
import { BasicTable } from '../BasicTable'; | ||
import { | ||
tableHead, | ||
tableData, | ||
pageCount, | ||
paginationData, | ||
onChangePage, | ||
} from '../data'; | ||
|
||
describe('Basic Table Component', () => { | ||
it('Renders', () => { | ||
const { getByTestId } = render( | ||
<KuberaThemeProvider platform="kubera-chaos"> | ||
<BasicTable | ||
tableData={tableData} | ||
tableHead={tableHead} | ||
pageCount={pageCount} | ||
paginationData={paginationData} | ||
onChangePage={onChangePage} | ||
/> | ||
</KuberaThemeProvider> | ||
); | ||
|
||
expect(getByTestId('table')).toBeTruthy(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { TableCell, TableRow, Typography } from '@material-ui/core'; | ||
|
||
import React from 'react'; | ||
|
||
const tableHead = ( | ||
<TableRow> | ||
<TableCell>Status</TableCell> | ||
<TableCell>Workflow Name</TableCell> | ||
<TableCell>Target Cluster</TableCell> | ||
<TableCell>Reliability Details</TableCell> | ||
<TableCell># of Steps</TableCell> | ||
<TableCell>Last Run</TableCell> | ||
<TableCell /> | ||
</TableRow> | ||
); | ||
|
||
const tableData = ( | ||
<TableRow> | ||
<TableCell colSpan={7}> | ||
<Typography align="center">No records available</Typography> | ||
</TableCell> | ||
</TableRow> | ||
); | ||
|
||
const pageCount = 0; | ||
|
||
const paginationData = { | ||
pageNo: 0, | ||
rowsPerPage: 5, | ||
}; | ||
|
||
const onChangePage = (_: any, page: number) => { | ||
console.log(page); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's required, since I need to use |
||
}; | ||
|
||
export { tableHead, tableData, pageCount, paginationData, onChangePage }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './BasicTable'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { makeStyles, Theme } from '@material-ui/core'; | ||
|
||
const useStyles = makeStyles((theme: Theme) => ({ | ||
root: { | ||
backgroundColor: theme.palette.background.default, | ||
}, | ||
tableMain: { | ||
marginTop: theme.spacing(4.25), | ||
backgroundColor: theme.palette.background.default, | ||
height: '29.219rem', | ||
'&::-webkit-scrollbar': { | ||
width: '0.2em', | ||
}, | ||
'&::-webkit-scrollbar-track': { | ||
webkitBoxShadow: `inset 0 0 6px ${theme.palette.border.main}`, | ||
|
||
}, | ||
'&::-webkit-scrollbar-thumb': { | ||
backgroundColor: theme.palette.secondary.dark, | ||
}, | ||
}, | ||
tableHead: { | ||
'& p': { | ||
fontWeight: 'bold', | ||
fontSize: '0.8125rem', | ||
}, | ||
'& th': { | ||
fontWeight: 'bold', | ||
fontSize: '0.8125rem', | ||
backgroundColor: theme.palette.background.default, | ||
}, | ||
}, | ||
})); | ||
|
||
export { useStyles }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './BasicTable'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some extra brackets
{' '}
can be removed if not required.