Skip to content

Commit 917d7b1

Browse files
author
Golan Hallel
authored
Merge pull request #228 from kube-HPC/fix-batch-output
fix infinity scroll in job by limit more
2 parents bfc6c0a + ed3de2f commit 917d7b1

File tree

11 files changed

+326
-19
lines changed

11 files changed

+326
-19
lines changed

src/Routes/Tables/Jobs/GraphTab/Details.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useCallback, useMemo, useState } from 'react';
2+
import { removeNullUndefined } from 'utils';
23
import PropTypes from 'prop-types';
34
// import { useSelector } from 'react-redux';
45
import styled from 'styled-components';
@@ -125,7 +126,7 @@ const Details = ({ node, jobId, isDisabledBtnRunDebug }) => {
125126
<Tabs.TabPane tab="Algorithm Details" key="algorithms-tab">
126127
<OverflowContainer>
127128
<JsonSwitch
128-
obj={algorithmDetails}
129+
obj={removeNullUndefined(algorithmDetails)}
129130
jobId={jobId}
130131
typeDefaultView="Table"
131132
/>

src/Routes/Tables/Jobs/index.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import React, { useMemo } from 'react';
22
import { Route } from 'react-router-dom';
33
import styled from 'styled-components';
44
import useQueryHook from 'hooks/useQuery';
5-
import { Table } from 'components';
5+
import { WTable } from 'components';
66
import { Card } from 'components/common';
77
import { Collapse } from 'react-collapse';
88
import { Divider, Empty, BackTop, Button } from 'antd';
99
import { ArrowUpOutlined } from '@ant-design/icons';
10-
import useJobsFunctions from './useJobsFunctions';
10+
import useJobsFunctionsLimit from './useJobsFunctionsLimit';
1111
import GridView from './GridView';
1212
import OverviewDrawer from './OverviewDrawer';
1313
import QueryForm from './QueryTable/QueryForm';
@@ -33,13 +33,12 @@ const JobsTable = () => {
3333
mergedParams,
3434
dataSourceGraph,
3535
debouncedZoomChanged,
36-
onFetchMore,
3736
isGraphLoad,
3837
isTableLoad,
3938
onRow,
4039
columns,
4140
_dataSource,
42-
} = useJobsFunctions();
41+
} = useJobsFunctionsLimit();
4342

4443
return (
4544
<>
@@ -60,26 +59,19 @@ const JobsTable = () => {
6059
<Divider />
6160
</Collapse>
6261

63-
<Table
62+
<WTable
6463
id="jobsTable"
65-
fetchMore={onFetchMore}
66-
loading={isTableLoad && isGraphLoad}
64+
loading={isTableLoad || isGraphLoad}
6765
onRow={onRow}
6866
rowKey={rowKey}
6967
expandIcon={false}
7068
columns={columns}
7169
dataSource={_dataSource}
7270
pagination={false}
73-
isInfinity
74-
heightScroll={filterToggeled ? '58vh' : '88vh'}
71+
scroll={{ y: filterToggeled ? '50vh' : '80vh' }}
7572
locale={localeEmpty}
76-
rowClassName={record => {
77-
if (record.status.status === 'active') {
78-
return 'active-row';
79-
}
80-
return null;
81-
}}
8273
/>
74+
8375
<BackTop target={BackToTop}>
8476
<Button
8577
style={{ opacity: '0.5' }}
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
import { useCallback, useEffect, useMemo, useState } from 'react';
2+
import { useDebouncedCallback } from 'use-debounce';
3+
import { useJobs, usePolling } from 'hooks';
4+
import { useQuery, useReactiveVar } from '@apollo/client';
5+
import {
6+
filterToggeledVar,
7+
instanceFiltersVar,
8+
metaVar,
9+
// isPinActiveJobVar,
10+
} from 'cache';
11+
import { JOB_QUERY, JOB_QUERY_GRAPH } from 'graphql/queries';
12+
13+
import usePath from './usePath';
14+
15+
export { default as jobColumns } from './jobColumns';
16+
17+
const topTableScroll = () => {
18+
const el = document.querySelector('.ant-table-body');
19+
if (el) el.scrollTop = 0;
20+
};
21+
22+
const numberLimitJobs = 100;
23+
const useJobsFunctionsLimit = () => {
24+
const instanceFilters = useReactiveVar(instanceFiltersVar);
25+
const filterToggeled = useReactiveVar(filterToggeledVar);
26+
const metaMode = useReactiveVar(metaVar);
27+
const [dataSourceGraph, setDataSourceGraph] = useState([]);
28+
const [zoomedChangedDate, setZoomedChangedDate] = useState(Date.now());
29+
const [isTableLoad, setIsTableLoad] = useState(true);
30+
const [isGraphLoad, setIsGraphLoad] = useState(true);
31+
const [limitGetJobs, setLimitGetJobs] = useState(numberLimitJobs);
32+
const [changeDs, setChangeDs] = useState(0);
33+
const [isGetMore, setIsGetMore] = useState(true);
34+
const { goTo } = usePath();
35+
const { columns } = useJobs();
36+
37+
const mergedParams = useMemo(() => {
38+
const iJobs = instanceFilters.jobs;
39+
40+
const items = {
41+
algorithmName: iJobs?.algorithmName || undefined,
42+
pipelineName: iJobs?.pipelineName || undefined,
43+
pipelineStatus: iJobs?.pipelineStatus || undefined,
44+
datesRange: {
45+
from: iJobs?.datesRange?.from || null,
46+
to: iJobs?.datesRange?.to || null,
47+
},
48+
};
49+
50+
if (
51+
metaMode?.experimentName != null &&
52+
metaMode?.experimentName !== 'show-all'
53+
) {
54+
items.experimentName = metaMode.experimentName;
55+
}
56+
57+
return items;
58+
}, [
59+
instanceFilters.jobs,
60+
instanceFilters.jobs.algorithmName,
61+
instanceFilters.jobs.pipelineName,
62+
instanceFilters.jobs.pipelineStatus,
63+
instanceFilters.jobs?.datesRange?.from,
64+
instanceFilters.jobs?.datesRange?.to,
65+
metaMode?.experimentName,
66+
]);
67+
68+
// all limit Jobs
69+
const queryAllJobs = useQuery(JOB_QUERY, {
70+
notifyOnNetworkStatusChange: true,
71+
// fetchPolicy: 'no-cache',
72+
variables: {
73+
limit: limitGetJobs,
74+
...mergedParams,
75+
},
76+
77+
onCompleted: () => {
78+
setIsTableLoad(false);
79+
setChangeDs(!changeDs);
80+
setIsGetMore(true);
81+
},
82+
});
83+
usePolling(queryAllJobs, 2000);
84+
// all Jobs to Graph
85+
const queryGraph = useQuery(JOB_QUERY_GRAPH, {
86+
// notifyOnNetworkStatusChange: true,
87+
88+
displayName: 'JOB_QUERY_GRAPH',
89+
variables: {
90+
limit: 100000,
91+
...mergedParams,
92+
},
93+
onCompleted: resGraph => {
94+
if (resGraph && resGraph?.jobsAggregated?.jobs) {
95+
setDataSourceGraph(resGraph.jobsAggregated.jobs);
96+
} else {
97+
setDataSourceGraph([]);
98+
}
99+
100+
setIsGraphLoad(false);
101+
},
102+
});
103+
104+
const onFetchMore = () => {
105+
setLimitGetJobs(previousState => previousState + numberLimitJobs);
106+
};
107+
108+
const onZoomChanged = useCallback(
109+
data => {
110+
let datesRange = null;
111+
if (data.min) {
112+
datesRange = {
113+
from: new Date(data.min).toISOString(),
114+
to: new Date(data.max).toISOString(),
115+
};
116+
}
117+
118+
setZoomedChangedDate(Date.now());
119+
const stateInstanceFilter = { ...instanceFiltersVar() };
120+
stateInstanceFilter.jobs = { ...mergedParams, datesRange };
121+
122+
instanceFiltersVar(stateInstanceFilter);
123+
setIsTableLoad(true);
124+
setIsGraphLoad(true);
125+
126+
topTableScroll();
127+
128+
setLimitGetJobs(numberLimitJobs);
129+
queryAllJobs.refetch();
130+
queryGraph.refetch();
131+
},
132+
[mergedParams, queryAllJobs, queryGraph]
133+
);
134+
const debouncedZoomChanged = useDebouncedCallback(onZoomChanged, 1000);
135+
136+
const onQuerySubmit = useCallback(
137+
values => {
138+
let datesRange = null;
139+
const { time, ...other } = values;
140+
141+
time
142+
? (datesRange = {
143+
from: time[0]?.toISOString(),
144+
to: time[1]?.toISOString(),
145+
})
146+
: null;
147+
148+
Object.values(other).forEach((element, index) => {
149+
element === '' ? (other[Object.keys(other)[index]] = undefined) : null;
150+
});
151+
const stateInstanceFilter = { ...instanceFiltersVar() };
152+
stateInstanceFilter.jobs = { ...other, datesRange };
153+
154+
instanceFiltersVar(stateInstanceFilter);
155+
156+
topTableScroll();
157+
setIsTableLoad(true);
158+
setIsGraphLoad(true);
159+
setLimitGetJobs(numberLimitJobs);
160+
queryAllJobs.refetch();
161+
queryGraph.refetch();
162+
},
163+
[queryGraph]
164+
);
165+
166+
useEffect(() => {
167+
setLimitGetJobs(numberLimitJobs);
168+
queryAllJobs.refetch();
169+
queryGraph.refetch();
170+
}, [mergedParams]);
171+
172+
const onRow = useCallback(
173+
job => ({
174+
onDoubleClick: () => goTo.overview({ nextJobId: job.key }),
175+
}),
176+
[goTo]
177+
);
178+
179+
const _dataSource = useMemo(() => {
180+
if (queryAllJobs && queryAllJobs.data) {
181+
const dsAllJobs = [
182+
...queryAllJobs.data.jobsAggregated.jobs.filter(
183+
x => x.status.status !== 'pending'
184+
),
185+
];
186+
187+
return dsAllJobs;
188+
}
189+
190+
return [];
191+
}, [changeDs]);
192+
193+
useEffect(() => {
194+
const tableContent = document.querySelector('#jobsTable .ant-table-body');
195+
tableContent.addEventListener('scroll', event => {
196+
const maxScroll = event.target.scrollHeight - event.target.clientHeight;
197+
198+
const currentScroll = event.target.scrollTop;
199+
200+
if (isGetMore && currentScroll > maxScroll - 10) {
201+
setIsTableLoad(true);
202+
setIsGetMore(false);
203+
onFetchMore();
204+
}
205+
});
206+
}, []);
207+
208+
return {
209+
zoomedChangedDate,
210+
filterToggeled,
211+
onQuerySubmit,
212+
mergedParams,
213+
dataSourceGraph,
214+
debouncedZoomChanged,
215+
isGraphLoad,
216+
isTableLoad,
217+
onRow,
218+
columns,
219+
_dataSource,
220+
setLimitGetJobs,
221+
};
222+
};
223+
224+
export default useJobsFunctionsLimit;

src/Routes/Tables/QueueOrderJobs/OrderPaging.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class OrderPaging extends React.PureComponent {
6060
defaultValue={numberRowToView}
6161
onChange={onChangeNumberRow}
6262
/>
63+
6364
<Button
6465
type="text"
6566
disabled={!HasNext > 0}

src/Routes/Tables/QueueOrderJobs/useQueueOrderJobs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const useQueueOrderJobs = () => {
5454
TypeTable.QUEUE
5555
);
5656

57-
return dataKeys;
57+
return { ...res.data.managedList, returnList: dataKeys };
5858
} catch (error) {
5959
console.error(error);
6060
}
@@ -127,12 +127,12 @@ const useQueueOrderJobs = () => {
127127
},
128128
});
129129

130-
const dataKey = addToObjectKeyIndexId(
130+
const dataKeys = addToObjectKeyIndexId(
131131
res.data.preferedList.returnList,
132132
TypeTable.PREFERRED
133133
);
134134

135-
return dataKey;
135+
return { ...res.data.preferedList, returnList: dataKeys };
136136
} catch (error) {
137137
console.error(error);
138138
}

0 commit comments

Comments
 (0)