|
3 | 3 | */
|
4 | 4 | import { useEffect, useMemo, useRef, useState } from 'react'
|
5 | 5 |
|
6 |
| -import { |
7 |
| - abortPreviousRequests, |
8 |
| - GenericInfoCardListingProps, |
9 |
| - getIsRequestAborted, |
10 |
| - useAsync, |
11 |
| -} from '@devtron-labs/devtron-fe-common-lib' |
| 6 | +import { abortPreviousRequests, getIsRequestAborted, useAsync } from '@devtron-labs/devtron-fe-common-lib' |
12 | 7 |
|
13 | 8 | import { getJobs } from '@Components/Jobs/Service'
|
14 | 9 | import { APP_TYPE } from '@Config/constants'
|
15 |
| -import { getAppIconWithBackground } from '@Config/utils' |
16 | 10 | import { getAppListMin } from '@Services/service'
|
17 | 11 |
|
| 12 | +import { getDevtronAppList } from '../service' |
18 | 13 | import { DevtronAppCloneListProps, DevtronListResponse } from './types'
|
19 | 14 |
|
20 | 15 | export const useDevtronCloneList = ({ handleCloneAppClick, isJobView }: DevtronAppCloneListProps) => {
|
@@ -53,11 +48,11 @@ export const useDevtronCloneList = ({ handleCloneAppClick, isJobView }: DevtronA
|
53 | 48 | },
|
54 | 49 | [],
|
55 | 50 | )
|
56 |
| - let totalCount = 0 |
57 | 51 |
|
58 |
| - if (listResponse?.type === APP_TYPE.JOB) { |
59 |
| - totalCount = listResponse.data.result.jobCount |
60 |
| - } |
| 52 | + const { list, totalCount } = useMemo(() => { |
| 53 | + if (!listResponse) return { list: [], totalCount: 0 } |
| 54 | + return getDevtronAppList({ listResponse, handleCloneAppClick }) |
| 55 | + }, [isListLoading, listResponse, handleCloneAppClick]) |
61 | 56 |
|
62 | 57 | const loadMoreData = async () => {
|
63 | 58 | if (isLoadingMore || !listResponse) return
|
@@ -101,43 +96,6 @@ export const useDevtronCloneList = ({ handleCloneAppClick, isJobView }: DevtronA
|
101 | 96 | }
|
102 | 97 | }
|
103 | 98 |
|
104 |
| - const list = useMemo(() => { |
105 |
| - if (isListLoading || !listResponse) return [] |
106 |
| - |
107 |
| - if (listResponse.type === APP_TYPE.JOB) { |
108 |
| - const jobContainers = listResponse.data.result?.jobContainers ?? [] |
109 |
| - |
110 |
| - totalCount = listResponse.data.result.jobCount |
111 |
| - |
112 |
| - return jobContainers.map<GenericInfoCardListingProps['list'][number]>((job) => { |
113 |
| - const { jobId, jobName, description } = job |
114 |
| - |
115 |
| - return { |
116 |
| - id: String(jobId), |
117 |
| - title: jobName, |
118 |
| - description: description.description, |
119 |
| - author: description.createdBy, |
120 |
| - Icon: getAppIconWithBackground(APP_TYPE.JOB, 40), |
121 |
| - onClick: () => handleCloneAppClick({ appId: jobId, appName: jobName }), |
122 |
| - } |
123 |
| - }) |
124 |
| - } |
125 |
| - const apps = listResponse.data.result ?? [] |
126 |
| - |
127 |
| - return apps.map<GenericInfoCardListingProps['list'][number]>((app) => { |
128 |
| - const { id, name, createdBy, description } = app |
129 |
| - |
130 |
| - return { |
131 |
| - id: String(id), |
132 |
| - title: name, |
133 |
| - Icon: getAppIconWithBackground(APP_TYPE.DEVTRON_APPS, 40), |
134 |
| - onClick: () => handleCloneAppClick({ appId: id, appName: name }), |
135 |
| - author: createdBy, |
136 |
| - description, |
137 |
| - } |
138 |
| - }) |
139 |
| - }, [isListLoading, listResponse]) |
140 |
| - |
141 | 99 | return {
|
142 | 100 | isListLoading: isListLoading ?? getIsRequestAborted(listError),
|
143 | 101 | list,
|
|
0 commit comments