Skip to content

Commit 9260744

Browse files
committed
chore: sort cluster list in service
1 parent 7289677 commit 9260744

File tree

5 files changed

+53
-40
lines changed

5 files changed

+53
-40
lines changed

src/Pages/GlobalConfigurations/ClustersAndEnvironments/ClusterList.components.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,17 @@ export const DeleteCluster = ({ clusterList, reloadClusterList, handleClose }: E
285285
/>
286286
)
287287
}
288+
289+
export const ClusterEnvLoader = () => (
290+
<>
291+
{Array.from({ length: 3 }).map((_, idx) => (
292+
// eslint-disable-next-line react/no-array-index-key
293+
<div key={idx} className="px-20 py-8 dc__grid environment-row dc__align-items-center">
294+
{Array.from({ length: 5 }).map((_, index) => (
295+
// eslint-disable-next-line react/no-array-index-key
296+
<span key={index} className="shimmer" />
297+
))}
298+
</div>
299+
))}
300+
</>
301+
)

src/Pages/GlobalConfigurations/ClustersAndEnvironments/ClusterList.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ import {
6666
EnvListSortableKeys,
6767
} from './cluster.type'
6868
import { parseClusterEnvSearchParams } from './cluster.util'
69-
import { AddEnvironment, ClusterListCellComponent, DeleteCluster, EditCluster } from './ClusterList.components'
69+
import {
70+
AddEnvironment,
71+
ClusterEnvLoader,
72+
ClusterListCellComponent,
73+
DeleteCluster,
74+
EditCluster,
75+
} from './ClusterList.components'
7076
import { ALL_CLUSTER_VALUE } from './constants'
7177
import EnvironmentList from './EnvironmentList'
7278

@@ -270,13 +276,7 @@ const ClusterList = () => {
270276

271277
const renderList = () => {
272278
if (isClusterEnvListLoading) {
273-
return Array.from({ length: 3 }).map(() => (
274-
<div className="px-20 py-8 dc__grid cluster-row dc__align-items-center">
275-
{Array.from({ length: 5 }).map(() => (
276-
<span className="shimmer" />
277-
))}
278-
</div>
279-
))
279+
return <ClusterEnvLoader />
280280
}
281281

282282
if (clusterListError || envListError) {

src/Pages/GlobalConfigurations/ClustersAndEnvironments/EnvironmentList.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
} from './cluster.type'
3636
import { environmentNameComparator, getSelectParsedCategory } from './cluster.util'
3737
import { ClusterEnvironmentDrawer } from './ClusterEnvironmentDrawer'
38+
import { ClusterEnvLoader } from './ClusterList.components'
3839
import { ADD_ENVIRONMENT_FORM_LOCAL_STORAGE_KEY } from './constants'
3940

4041
import './cluster.scss'
@@ -129,13 +130,7 @@ const ClustersEnvironmentsList = ({
129130

130131
const renderNamespaceEnvList = () => {
131132
if (namespaceListLoading) {
132-
return Array.from({ length: 3 }).map(() => (
133-
<div className="px-20 py-8 dc__grid environment-row dc__align-items-center">
134-
{Array.from({ length: 5 }).map(() => (
135-
<span className="shimmer" />
136-
))}
137-
</div>
138-
))
133+
return <ClusterEnvLoader />
139134
}
140135

141136
if (namespaceListError) {
@@ -405,7 +400,6 @@ const EnvironmentList = ({
405400
<SortableTableHeaderCell title="DESCRIPTION" isSortable={false} />
406401
</div>
407402
{clusterList
408-
.sort((a, b) => stringComparatorBySortOrder(a.clusterName, b.clusterName))
409403
.filter(({ clusterId }) => !filterClusterId || filterClusterId === String(clusterId))
410404
.map(({ clusterId, clusterName, isProd, isVirtualCluster }) => (
411405
<ClustersEnvironmentsList

src/Pages/GlobalConfigurations/ClustersAndEnvironments/cluster.scss

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@
6565
}
6666
}
6767

68-
.cluster-list-row {
69-
display: grid;
70-
grid-template-columns: 24px minmax(278px, 346px) 120px 130px 190px minmax(80px, 90px);
71-
grid-column-gap: 16px;
72-
}
73-
7468
.saved-cluster-list-row {
7569
display: grid;
7670
grid-template-columns: 300px 100px 1fr;

src/Pages/GlobalConfigurations/ClustersAndEnvironments/cluster.service.ts

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { get, getUrlWithSearchParams, post, put, trash } from '@devtron-labs/devtron-fe-common-lib'
17+
import {
18+
get,
19+
getUrlWithSearchParams,
20+
post,
21+
put,
22+
stringComparatorBySortOrder,
23+
trash,
24+
} from '@devtron-labs/devtron-fe-common-lib'
1825

1926
import { Routes } from '@Config/constants'
2027

@@ -46,23 +53,27 @@ export const getClusterList = async (clusterIds?: number[]): Promise<Cluster[]>
4653
const url = getUrlWithSearchParams(Routes.CLUSTER, { clusterId: clusterIds?.join() })
4754
const { result } = await get<ClusterDTO[]>(url)
4855

49-
// eslint-disable-next-line camelcase
50-
return (result ?? []).map(({ id, server_url, cluster_name, prometheus_url, category, ...res }) => ({
51-
...res,
52-
clusterId: id,
53-
// eslint-disable-next-line camelcase
54-
serverUrl: server_url,
55-
// eslint-disable-next-line camelcase
56-
clusterName: cluster_name,
57-
// eslint-disable-next-line camelcase
58-
prometheusUrl: prometheus_url,
59-
category: category?.name
60-
? {
61-
label: category.name,
62-
value: category.id,
63-
}
64-
: null,
65-
}))
56+
return (
57+
(result ?? [])
58+
// eslint-disable-next-line camelcase
59+
.map(({ id, server_url, cluster_name, prometheus_url, category, ...res }) => ({
60+
...res,
61+
clusterId: id,
62+
// eslint-disable-next-line camelcase
63+
serverUrl: server_url,
64+
// eslint-disable-next-line camelcase
65+
clusterName: cluster_name,
66+
// eslint-disable-next-line camelcase
67+
prometheusUrl: prometheus_url,
68+
category: category?.name
69+
? {
70+
label: category.name,
71+
value: category.id,
72+
}
73+
: null,
74+
}))
75+
.sort((a, b) => stringComparatorBySortOrder(a.clusterName, b.clusterName))
76+
)
6677
}
6778

6879
export function getCluster(id: number) {

0 commit comments

Comments
 (0)