Skip to content
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

Add the Table Component #48

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions src/core/Table/BasicTable/BasicTable.stories.tsx
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}
/>{' '}
Copy link
Contributor

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.

</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>
));
60 changes: 60 additions & 0 deletions src/core/Table/BasicTable/BasicTable.tsx
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can get the TableProps from another file as base.ts, have a look as done in other components.

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 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there other variations coming up for the table component?
if not we can export it just as a table. Let wait for others to reviews this.

29 changes: 29 additions & 0 deletions src/core/Table/BasicTable/__tests__/BasicTable.test.tsx
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();
});
});
35 changes: 35 additions & 0 deletions src/core/Table/BasicTable/data.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { TableCell, TableRow, Typography } from '@material-ui/core';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the typography which is available in Kubera-UI?

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is console.log() really required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's required, since I need to use page and can't have an empty function. Otherwise linting errors/warnings occurs.

};

export { tableHead, tableData, pageCount, paginationData, onChangePage };
1 change: 1 addition & 0 deletions src/core/Table/BasicTable/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './BasicTable';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as it's only one table component, we can export the Table instead.

34 changes: 34 additions & 0 deletions src/core/Table/BasicTable/style.ts
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}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we convert px to rem and use where required.

},
'&::-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 };
1 change: 1 addition & 0 deletions src/core/Table/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './BasicTable';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this has only one table component then we can just use as ./Table

Copy link
Contributor

@AVRahul AVRahul Oct 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I guess you need to export globally the Table component at src/core/index.ts something like export * from './Table'; in order to get the table exported for npm.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@S-ayanide @arkajyotiMukherjee should we have this Table as a core or lab component?