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

fix: add pagination for child node expansion #232

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Changes from all commits
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
63 changes: 53 additions & 10 deletions src/components/Executions/Tables/NodeExecutionChildren.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Typography } from '@material-ui/core';
import { Button, Typography } from '@material-ui/core';
import { Theme, makeStyles } from '@material-ui/core/styles';
import * as classnames from 'classnames';
import { getCacheKey } from 'components/Cache/utils';
import { useTheme } from 'components/Theme/useTheme';
Expand All @@ -15,12 +16,24 @@ export interface NodeExecutionChildrenProps {
level: number;
}

const PAGE_SIZE = 50;

const useStyles = makeStyles((theme: Theme) => ({
loadMoreContainer: {
display: 'flex',
justifyContent: 'center',
marginTop: theme.spacing(1),
marginBottom: theme.spacing(1)
}
}));

/** Renders a nested list of row items for children of a NodeExecution */
export const NodeExecutionChildren: React.FC<NodeExecutionChildrenProps> = ({
abortMetadata,
childGroups,
level
}) => {
const styles = useStyles();
const showNames = childGroups.length > 1;
const tableStyles = useExecutionTableStyles();
const theme = useTheme();
Expand All @@ -31,18 +44,45 @@ export const NodeExecutionChildren: React.FC<NodeExecutionChildrenProps> = ({
theme.spacing
)}px`
};
const [loadedNodes, setLoadedNodes] = React.useState(
new Array(childGroups.length).fill(PAGE_SIZE)
);

const loadMoreRows = React.useCallback(
(which: number) => () => {
const newLoadedNodes = [...loadedNodes];
newLoadedNodes[which] += PAGE_SIZE;
setLoadedNodes(newLoadedNodes);
},
[loadedNodes]
);

const loadMoreButton = (which: number) => (
<div className={styles.loadMoreContainer}>
<Button
onClick={loadMoreRows(which)}
size="small"
variant="outlined"
>
Load More
</Button>
</div>
);

return (
<>
{childGroups.map(({ name, nodeExecutions }, groupIndex) => {
const rows = nodeExecutions.map((nodeExecution, index) => (
<NodeExecutionRow
abortMetadata={abortMetadata}
key={getCacheKey(nodeExecution.id)}
index={index}
execution={nodeExecution}
level={level}
/>
));
const rows = nodeExecutions
.slice(0, loadedNodes[groupIndex])
.map((nodeExecution, index) => (
<NodeExecutionRow
abortMetadata={abortMetadata}
key={getCacheKey(nodeExecution.id)}
index={index}
execution={nodeExecution}
level={level}
/>
));
const key = `group-${name}`;
return showNames ? (
<div key={key} role="list">
Expand All @@ -63,10 +103,13 @@ export const NodeExecutionChildren: React.FC<NodeExecutionChildrenProps> = ({
</Typography>
</div>
<div>{rows}</div>
{loadMoreButton(groupIndex)}
</div>
) : (
<div key={key} role="list">
{rows}
{nodeExecutions.length > loadedNodes[groupIndex] &&
loadMoreButton(groupIndex)}
</div>
);
})}
Expand Down