Skip to content

Commit 1e55ac4

Browse files
PR changes
1 parent 29dfd6e commit 1e55ac4

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

src/components/ControlPlane/FluxList.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { FluxKustomization } from '../../lib/api/types/flux/listKustomization';
1010
import { useTranslation } from 'react-i18next';
1111
import { timeAgo } from '../../utils/i18n/timeAgo.ts';
1212
import { ResourceStatusCell } from '../Shared/ResourceStatusCell.tsx';
13-
import { shortenCommitHash } from '../../lib/api/types/shared/helpers.ts';
1413

1514
export default function FluxList() {
1615
const {
@@ -30,27 +29,22 @@ export default function FluxList() {
3029
cell: {
3130
value: T | null; // null for grouping rows
3231
row: {
33-
original?: FluxRows; // missing for grouping rows
32+
original?: FluxRow; // missing for grouping rows
3433
};
3534
};
3635
}
3736

38-
type FluxRows = {
37+
type FluxRow = {
3938
name: string;
4039
created: string;
4140
status: boolean;
4241
statusUptadeTime?: string;
4342
};
4443

45-
if (repoErr) {
46-
return (
47-
<IllustratedError error={repoErr} title={t('FluxList.noFluxError')} />
48-
);
49-
}
50-
if (kustomizationErr) {
44+
if (repoErr || kustomizationErr) {
5145
return (
5246
<IllustratedError
53-
error={kustomizationErr}
47+
error={repoErr || kustomizationErr}
5448
title={t('FluxList.noFluxError')}
5549
/>
5650
);
@@ -64,7 +58,7 @@ export default function FluxList() {
6458
{
6559
Header: t('FluxList.tableStatusHeader'),
6660
accessor: 'status',
67-
Cell: (cellData: CellData<FluxRows['status']>) =>
61+
Cell: (cellData: CellData<FluxRow['status']>) =>
6862
cellData.cell.row.original?.status != null ? (
6963
<ResourceStatusCell
7064
value={cellData.cell.row.original?.status}
@@ -94,7 +88,7 @@ export default function FluxList() {
9488
{
9589
Header: t('FluxList.tableStatusHeader'),
9690
accessor: 'status',
97-
Cell: (cellData: CellData<FluxRows['status']>) =>
91+
Cell: (cellData: CellData<FluxRow['status']>) =>
9892
cellData.cell.row.original?.status != null ? (
9993
<ResourceStatusCell
10094
value={cellData.cell.row.original?.status}
@@ -112,7 +106,19 @@ export default function FluxList() {
112106
},
113107
];
114108

115-
const gitReposRows: FluxRows[] =
109+
function shortenCommitHash(commitHash: string): string {
110+
//example hash: master@sha1:b3396adb98a6a0f5eeedd1a600beaf5e954a1f28
111+
const match = commitHash.match(/^([a-zA-Z0-9-_]+)@sha1:([a-f0-9]{40})/);
112+
113+
if (match && match[2]) {
114+
return `${match[1]}@${match[2].slice(0, 7)}`;
115+
}
116+
117+
//example output : master@b3396ad
118+
return commitHash;
119+
}
120+
121+
const gitReposRows: FluxRow[] =
116122
gitReposData?.items?.map((item) => {
117123
return {
118124
name: item.metadata.name,
@@ -126,7 +132,7 @@ export default function FluxList() {
126132
};
127133
}) ?? [];
128134

129-
const kustomizationsRows: FluxRows[] =
135+
const kustomizationsRows: FluxRow[] =
130136
kustmizationData?.items?.map((item) => {
131137
return {
132138
name: item.metadata.name,

src/lib/api/types/shared/helpers.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)