Skip to content

Commit 700f888

Browse files
Merge pull request #1036 from anwesha-palit-redhat/feat/SRVKP-9709
SRVKP-9709: Replaces the repositories list built on VirtualizedTable andListPageFilter with ConsoleDataView
2 parents 9da4653 + 7f8ba75 commit 700f888

6 files changed

Lines changed: 188 additions & 385 deletions

File tree

locales/en/plugin__pipelines-console-plugin.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@
326326
"No PipelineRuns found": "No PipelineRuns found",
327327
"No Projects found": "No Projects found",
328328
"No Properties found": "No Properties found",
329-
"No Repositories found": "No Repositories found",
330329
"No requester": "No requester",
331330
"No results": "No results",
332331
"No results found": "No results found",

src/components/hooks/useTektonResult.ts

Lines changed: 5 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,12 @@
1-
import {
2-
K8sResourceCommon,
3-
Selector,
4-
useFlag,
5-
} from '@openshift-console/dynamic-plugin-sdk';
6-
import { uniqBy } from 'lodash';
1+
import { Selector, useFlag } from '@openshift-console/dynamic-plugin-sdk';
72
import { useEffect, useState } from 'react';
8-
import {
9-
FLAG_PIPELINE_TEKTON_RESULT_INSTALLED,
10-
RepositoryFields,
11-
RepositoryLabels,
12-
TektonResourceLabel,
13-
} from '../../consts';
14-
import {
15-
FLAGS,
16-
PipelineRunKind,
17-
RecordsList,
18-
TaskRunKind,
19-
TektonResultsOptions,
20-
} from '../../types';
21-
import {
22-
getPipelineRuns,
23-
getTaskRunLog,
24-
getTaskRuns,
25-
} from '../utils/tekton-results';
26-
import { usePipelineRuns, useTaskRuns } from './useTaskRuns';
3+
import { RepositoryFields, RepositoryLabels } from '../../consts';
4+
import { FLAGS, PipelineRunKind } from '../../types';
5+
import { getTaskRunLog } from '../utils/tekton-results';
6+
import { usePipelineRuns } from './useTaskRuns';
277

288
export type GetNextPage = () => void | undefined;
299

30-
const useTRRuns = <Kind extends K8sResourceCommon>(
31-
getRuns: (
32-
namespace: string,
33-
options?: TektonResultsOptions,
34-
nextPageToken?: string,
35-
cacheKey?: string,
36-
isDevConsoleProxyAvailable?: boolean,
37-
) => Promise<[Kind[], RecordsList, boolean?]>,
38-
namespace: string,
39-
options?: TektonResultsOptions,
40-
cacheKey?: string,
41-
): [Kind[], boolean, unknown, GetNextPage] => {
42-
const isDevConsoleProxyAvailable = useFlag(FLAGS.DEVCONSOLE_PROXY);
43-
const [nextPageToken, setNextPageToken] = useState<string>(null);
44-
const [localCacheKey, setLocalCacheKey] = useState(cacheKey);
45-
46-
if (cacheKey !== localCacheKey) {
47-
// force update local cache key
48-
setLocalCacheKey(cacheKey);
49-
}
50-
51-
const [result, setResult] = useState<[Kind[], boolean, unknown, GetNextPage]>(
52-
[[], false, undefined, undefined],
53-
);
54-
55-
// reset token if namespace or options change
56-
useEffect(() => {
57-
setNextPageToken(null);
58-
}, [namespace, options, cacheKey]);
59-
60-
// eslint-disable-next-line consistent-return
61-
useEffect(() => {
62-
let disposed = false;
63-
(async () => {
64-
try {
65-
const tkPipelineRuns = await getRuns(
66-
namespace,
67-
options,
68-
nextPageToken,
69-
localCacheKey,
70-
isDevConsoleProxyAvailable,
71-
);
72-
if (!disposed) {
73-
const token = tkPipelineRuns[1].nextPageToken;
74-
const callInflight = !!tkPipelineRuns?.[2];
75-
const loaded = !callInflight;
76-
if (!callInflight) {
77-
setResult((cur) => [
78-
nextPageToken
79-
? [...cur[0], ...tkPipelineRuns[0]]
80-
: tkPipelineRuns[0],
81-
loaded,
82-
undefined,
83-
token
84-
? (() => {
85-
// ensure we can only call this once
86-
let executed = false;
87-
return () => {
88-
if (!disposed && !executed) {
89-
executed = true;
90-
// trigger the update
91-
setNextPageToken(token);
92-
return true;
93-
}
94-
return false;
95-
};
96-
})()
97-
: undefined,
98-
]);
99-
}
100-
}
101-
} catch (e) {
102-
if (!disposed) {
103-
if (nextPageToken) {
104-
setResult((cur) => [cur[0], cur[1], e, undefined]);
105-
} else {
106-
setResult([[], false, e, undefined]);
107-
}
108-
}
109-
}
110-
})();
111-
return () => {
112-
disposed = true;
113-
};
114-
}, [namespace, options, nextPageToken, localCacheKey, getRuns]);
115-
return result;
116-
};
117-
118-
export const useTRPipelineRuns = (
119-
namespace: string,
120-
options?: TektonResultsOptions,
121-
cacheKey?: string,
122-
): [PipelineRunKind[], boolean, unknown, GetNextPage] =>
123-
useTRRuns<PipelineRunKind>(getPipelineRuns, namespace, options, cacheKey);
124-
125-
export const useTRTaskRuns = (
126-
namespace: string,
127-
options?: TektonResultsOptions,
128-
cacheKey?: string,
129-
): [TaskRunKind[], boolean, unknown, GetNextPage] =>
130-
useTRRuns<TaskRunKind>(getTaskRuns, namespace, options, cacheKey);
131-
13210
export const useGetPipelineRuns = (
13311
ns: string,
13412
options?: { name: string; kind: string },
@@ -161,56 +39,6 @@ export const useGetPipelineRuns = (
16139
);
16240
};
16341

164-
export const useGetTaskRuns = (
165-
ns: string,
166-
pipelineRunName?: string,
167-
): [TaskRunKind[], boolean, unknown, GetNextPage] => {
168-
let selector: Selector;
169-
const isTektonResultEnabled = useFlag(FLAG_PIPELINE_TEKTON_RESULT_INSTALLED);
170-
171-
if (pipelineRunName) {
172-
selector = {
173-
matchLabels: {
174-
[TektonResourceLabel.pipelinerun]: pipelineRunName,
175-
},
176-
};
177-
}
178-
const [
179-
k8sTaskRuns,
180-
k8sTaskRunsK8sLoaded,
181-
k8sTaskRunsTrLoaded,
182-
k8sTaskRunsLoadError,
183-
] = useTaskRuns(ns, pipelineRunName);
184-
185-
/* this needs decoupling */
186-
187-
const k8sTaskRunsLoaded = k8sTaskRunsK8sLoaded && k8sTaskRunsTrLoaded;
188-
const [
189-
resultTaskRuns,
190-
resultTaskRunsLoaded,
191-
resultTaskRunsLoadError,
192-
getNextPage,
193-
] = isTektonResultEnabled
194-
? useTRTaskRuns(
195-
ns,
196-
pipelineRunName && {
197-
selector,
198-
},
199-
)
200-
: [[], true, undefined, undefined];
201-
202-
const mergedTaskRuns =
203-
resultTaskRunsLoaded || k8sTaskRunsLoaded
204-
? uniqBy([...k8sTaskRuns, ...resultTaskRuns], (r) => r.metadata.uid)
205-
: [];
206-
return [
207-
mergedTaskRuns,
208-
resultTaskRunsLoaded || k8sTaskRunsLoaded,
209-
k8sTaskRunsLoadError || resultTaskRunsLoadError,
210-
getNextPage,
211-
];
212-
};
213-
21442
export const useTRTaskRunLog = (
21543
namespace: string,
21644
taskRunName: string,

src/components/repositories-list/RepositoriesList.tsx

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import {
22
ListPageBody,
3-
VirtualizedTable,
43
getGroupVersionKindForModel,
4+
useFlag,
55
useK8sWatchResource,
6-
useListPageFilter,
76
} from '@openshift-console/dynamic-plugin-sdk';
87
import type { FC } from 'react';
98
import { PipelineRunModel, RepositoryModel } from '../../models';
109
import { PipelineRunKind, RepositoryKind } from '../../types';
1110
import useRepositoriesColumns from './useRepositoriesColumns';
12-
import RepositoriesRow from './RepositoriesRow';
13-
import { useGetTaskRuns } from '../hooks/useTektonResult';
11+
import { getRepositoriesListDataViewRows } from './RepositoriesRow';
1412
import { useParams } from 'react-router';
1513
import { useTranslation } from 'react-i18next';
16-
import { ListPageFilter } from '../list-pages/ListPageFilter';
14+
import { ConsoleDataView } from '@openshift-console/dynamic-plugin-sdk-internal';
15+
import { useDataViewFilter } from '../hooks/useDataViewFilter';
16+
import { DataViewFilterToolbar } from '../common/DataViewFilterToolbar';
17+
import { useTaskRuns } from '../hooks/useTaskRuns';
18+
import { FLAG_PIPELINE_TEKTON_RESULT_INSTALLED } from '../../consts';
1719

1820
type RepositoriesListProps = {
1921
namespace?: string;
@@ -43,35 +45,39 @@ const RepositoriesList: FC<RepositoriesListProps> = ({
4345
namespace,
4446
optional: true,
4547
});
46-
const [taskRuns, taskRunsLoaded] = useGetTaskRuns(namespace);
47-
const [staticData, filteredData, onFilterChange] =
48-
useListPageFilter(repositories);
48+
const [taskRuns, k8sLoaded, resultsLoaded] = useTaskRuns(namespace);
49+
const isTektonResultEnabled = useFlag(FLAG_PIPELINE_TEKTON_RESULT_INSTALLED);
50+
51+
const { filterValues, onFilterChange, onClearAll, filteredData } =
52+
useDataViewFilter<RepositoryKind>({
53+
data: repositories || [],
54+
});
4955

5056
return (
5157
<ListPageBody>
52-
<ListPageFilter
53-
data={staticData}
54-
onFilterChange={onFilterChange}
55-
loaded={repositoriesLoaded}
56-
hideNameLabelFilters={hideTextFilter}
57-
/>
58-
<VirtualizedTable
59-
EmptyMsg={() => (
60-
<div className="cp-text-align-center" id="no-resource-msg">
61-
{t('No Repositories found')}
62-
</div>
63-
)}
58+
{!hideTextFilter && (
59+
<DataViewFilterToolbar
60+
filterValues={filterValues}
61+
onFilterChange={onFilterChange}
62+
onClearAll={onClearAll}
63+
/>
64+
)}
65+
<ConsoleDataView<RepositoryKind>
66+
label={t('Repositories')}
6467
columns={columns}
6568
data={filteredData}
6669
loaded={repositoriesLoaded && pipelineRunsLoaded}
6770
loadError={repositoriesLoadError}
68-
Row={RepositoriesRow}
69-
rowData={{
71+
getDataViewRows={getRepositoriesListDataViewRows}
72+
hideColumnManagement
73+
hideNameLabelFilters
74+
customRowData={{
7075
taskRuns,
7176
pipelineRuns,
72-
taskRunsLoaded,
77+
taskRunsLoaded: isTektonResultEnabled
78+
? k8sLoaded && resultsLoaded
79+
: k8sLoaded,
7380
}}
74-
unfilteredData={staticData}
7581
/>
7682
</ListPageBody>
7783
);

0 commit comments

Comments
 (0)