forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui/tasks): add pagination on tasks listing page (datahub-project…
- Loading branch information
1 parent
f9dbe98
commit d7cd1fc
Showing
5 changed files
with
168 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 47 additions & 6 deletions
53
datahub-web-react/src/app/entity/shared/tabs/Entity/DataFlowJobsTab.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,60 @@ | ||
import React from 'react'; | ||
import { useBaseEntity } from '../../EntityContext'; | ||
import React, { useState } from 'react'; | ||
import { EntityType } from '../../../../../types.generated'; | ||
import { EntityList } from './components/EntityList'; | ||
import { useEntityRegistry } from '../../../../useEntityRegistry'; | ||
import { useGetDataFlowChildJobsQuery } from '../../../../../graphql/dataFlow.generated'; | ||
import { SearchCfg } from '../../../../../conf'; | ||
|
||
export const DataFlowJobsTab = () => { | ||
const entity = useBaseEntity() as any; | ||
const dataFlow = entity && entity.dataFlow; | ||
interface Props { | ||
properties?: { | ||
urn: string; | ||
}; | ||
} | ||
|
||
export const DataFlowJobsTab = ({ properties = { urn: '' } }: Props) => { | ||
const [page, setPage] = useState(1); | ||
const [numResultsPerPage, setNumResultsPerPage] = useState(SearchCfg.RESULTS_PER_PAGE); | ||
|
||
const start: number = (page - 1) * numResultsPerPage; | ||
|
||
const { data, loading, error } = useGetDataFlowChildJobsQuery({ | ||
variables: { | ||
urn: properties.urn, | ||
start, | ||
count: numResultsPerPage, | ||
}, | ||
}); | ||
|
||
const onChangePage = (newPage: number) => { | ||
setPage(newPage); | ||
}; | ||
|
||
const dataFlow = data && data?.dataFlow; | ||
const dataJobs = dataFlow?.childJobs?.relationships.map((relationship) => relationship.entity); | ||
const entityRegistry = useEntityRegistry(); | ||
const totalJobs = dataFlow?.childJobs?.total || 0; | ||
const pageSize = data?.dataFlow?.childJobs?.count || 0; | ||
const pageStart = data?.dataFlow?.childJobs?.start || 0; | ||
const lastResultIndex = pageStart + pageSize > totalJobs ? totalJobs : pageStart + pageSize; | ||
const title = `Contains ${totalJobs} ${ | ||
totalJobs === 1 | ||
? entityRegistry.getEntityName(EntityType.DataJob) | ||
: entityRegistry.getCollectionName(EntityType.DataJob) | ||
}`; | ||
return <EntityList title={title} type={EntityType.DataJob} entities={dataJobs || []} />; | ||
return ( | ||
<EntityList | ||
title={title} | ||
type={EntityType.DataJob} | ||
entities={dataJobs || []} | ||
showPagination | ||
loading={loading} | ||
error={error} | ||
totalAssets={totalJobs} | ||
page={page} | ||
pageSize={numResultsPerPage} | ||
lastResultIndex={lastResultIndex} | ||
onChangePage={onChangePage} | ||
setNumResultsPerPage={setNumResultsPerPage} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters