Skip to content

Commit 23e9e94

Browse files
authored
feat(ui/ingestion): add pagination on ingestion executions (#10269)
1 parent f8ede9b commit 23e9e94

File tree

2 files changed

+85
-15
lines changed

2 files changed

+85
-15
lines changed

datahub-web-react/src/app/ingest/source/executions/IngestionExecutionTable.tsx

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,58 @@
11
import React from 'react';
2-
import { Empty } from 'antd';
2+
import { Empty, Pagination, Typography } from 'antd';
3+
import styled from 'styled-components';
34
import { StyledTable } from '../../../entity/shared/components/styled/StyledTable';
45
import { ExecutionRequest } from '../../../../types.generated';
56
import { ButtonsColumn, SourceColumn, StatusColumn, TimeColumn } from './IngestionExecutionTableColumns';
67
import { SUCCESS } from '../utils';
78
import { formatDuration } from '../../../shared/formatDuration';
9+
import { SearchCfg } from '../../../../conf';
10+
11+
const PaginationInfoContainer = styled.span`
12+
padding: 8px;
13+
padding-left: 16px;
14+
border-top: 1px solid;
15+
border-color: ${(props) => props.theme.styles['border-color-base']};
16+
display: flex;
17+
justify-content: space-between;
18+
align-items: center;
19+
`;
20+
21+
const StyledPagination = styled(Pagination)`
22+
margin: 0px;
23+
padding: 0px;
24+
`;
25+
26+
const PaginationInfo = styled(Typography.Text)`
27+
padding: 0px;
28+
`;
829

930
interface Props {
1031
executionRequests: ExecutionRequest[];
1132
setFocusExecutionUrn: (urn: string) => void;
1233
handleViewDetails: (urn: string) => void;
1334
handleCancelExecution: (urn: string) => void;
1435
handleRollbackExecution: (runId: string) => void;
36+
onChangePage: (number: any) => void;
37+
setNumResultsPerPage: (number: any) => void;
38+
totalExecution?: number | null;
39+
page?: any;
40+
pageSize?: any;
41+
lastResultIndex?: any;
1542
}
1643

1744
export default function IngestionExecutionTable({
1845
executionRequests,
46+
onChangePage,
1947
setFocusExecutionUrn,
2048
handleViewDetails,
2149
handleCancelExecution,
2250
handleRollbackExecution,
51+
setNumResultsPerPage,
52+
totalExecution,
53+
pageSize,
54+
lastResultIndex,
55+
page,
2356
}: Props) {
2457
const tableColumns = [
2558
{
@@ -69,7 +102,8 @@ export default function IngestionExecutionTable({
69102
},
70103
];
71104

72-
const mostRecentSuccessfulExecution = executionRequests.find((execution) => execution.result?.status === SUCCESS);
105+
const mostRecentSuccessfulExecution =
106+
page === 1 && executionRequests.find((execution) => execution.result?.status === SUCCESS);
73107

74108
const tableData = executionRequests.map((execution) => ({
75109
urn: execution.urn,
@@ -79,18 +113,38 @@ export default function IngestionExecutionTable({
79113
executedAt: execution.result?.startTimeMs,
80114
duration: execution.result?.durationMs,
81115
status: execution.result?.status,
82-
showRollback: execution.urn === mostRecentSuccessfulExecution?.urn,
116+
showRollback: mostRecentSuccessfulExecution && execution?.urn === mostRecentSuccessfulExecution?.urn,
83117
}));
84118

85119
return (
86-
<StyledTable
87-
columns={tableColumns}
88-
dataSource={tableData}
89-
rowKey="id"
90-
locale={{
91-
emptyText: <Empty description="No Executions found!" image={Empty.PRESENTED_IMAGE_SIMPLE} />,
92-
}}
93-
pagination={false}
94-
/>
120+
<>
121+
<StyledTable
122+
columns={tableColumns}
123+
dataSource={tableData}
124+
rowKey="id"
125+
locale={{
126+
emptyText: <Empty description="No Executions found!" image={Empty.PRESENTED_IMAGE_SIMPLE} />,
127+
}}
128+
pagination={false}
129+
/>
130+
<PaginationInfoContainer>
131+
<PaginationInfo>
132+
<b>
133+
{lastResultIndex > 0 ? (page - 1) * pageSize + 1 : 0} - {lastResultIndex}
134+
</b>{' '}
135+
of <b>{totalExecution}</b>
136+
</PaginationInfo>
137+
<StyledPagination
138+
current={page}
139+
pageSize={pageSize}
140+
total={totalExecution as any}
141+
showLessItems
142+
onChange={onChangePage}
143+
showSizeChanger={(totalExecution as any) > SearchCfg.RESULTS_PER_PAGE}
144+
onShowSizeChange={(_currNum, newNum) => setNumResultsPerPage(newNum)}
145+
pageSizeOptions={['10', '20', '50', '100']}
146+
/>
147+
</PaginationInfoContainer>
148+
</>
95149
);
96150
}

datahub-web-react/src/app/ingest/source/executions/IngestionSourceExecutionList.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import IngestionExecutionTable from './IngestionExecutionTable';
1212
import { ExecutionRequest } from '../../../../types.generated';
1313
import { ROLLING_BACK, RUNNING } from '../utils';
1414
import useRefreshIngestionData from './useRefreshIngestionData';
15+
import { SearchCfg } from '../../../../conf';
1516

1617
const ListContainer = styled.div`
1718
margin-left: 28px;
@@ -30,18 +31,23 @@ type Props = {
3031

3132
export const IngestionSourceExecutionList = ({ urn, isExpanded, lastRefresh, onRefresh }: Props) => {
3233
const [focusExecutionUrn, setFocusExecutionUrn] = useState<undefined | string>(undefined);
34+
const [page, setPage] = useState(1);
35+
const [numResultsPerPage, setNumResultsPerPage] = useState(SearchCfg.RESULTS_PER_PAGE);
3336

34-
const start = 0;
35-
const count = 10; // Load 10 items at a time.
37+
const start: number = (page - 1) * numResultsPerPage;
3638

3739
const { loading, data, error, refetch } = useGetIngestionSourceQuery({
3840
variables: {
3941
urn,
4042
runStart: start,
41-
runCount: count,
43+
runCount: numResultsPerPage,
4244
},
4345
});
4446

47+
const onChangePage = (newPage: number) => {
48+
setPage(newPage);
49+
};
50+
4551
function hasActiveExecution() {
4652
return !!data?.ingestionSource?.executions?.executionRequests.find((request) =>
4753
isExecutionRequestActive(request as ExecutionRequest),
@@ -139,6 +145,10 @@ export const IngestionSourceExecutionList = ({ urn, isExpanded, lastRefresh, onR
139145
}
140146

141147
const executionRequests = (data?.ingestionSource?.executions?.executionRequests as ExecutionRequest[]) || [];
148+
const totalExecution = data?.ingestionSource?.executions?.total || 0;
149+
const pageSize = data?.ingestionSource?.executions?.count || 0;
150+
const pageStart = data?.ingestionSource?.executions?.start || 0;
151+
const lastResultIndex = pageStart + pageSize > totalExecution ? totalExecution : pageStart + pageSize;
142152

143153
return (
144154
<ListContainer>
@@ -147,11 +157,17 @@ export const IngestionSourceExecutionList = ({ urn, isExpanded, lastRefresh, onR
147157
<Message type="error" content="Failed to load ingestion executions! An unexpected error occurred." />
148158
)}
149159
<IngestionExecutionTable
160+
onChangePage={onChangePage}
150161
executionRequests={executionRequests}
162+
totalExecution={totalExecution}
163+
page={page}
164+
pageSize={numResultsPerPage}
165+
lastResultIndex={lastResultIndex}
151166
setFocusExecutionUrn={setFocusExecutionUrn}
152167
handleCancelExecution={handleCancelExecution}
153168
handleViewDetails={handleViewDetails}
154169
handleRollbackExecution={handleRollbackExecution}
170+
setNumResultsPerPage={setNumResultsPerPage}
155171
/>
156172
{focusExecutionUrn && (
157173
<ExecutionDetailsModal

0 commit comments

Comments
 (0)