Skip to content

Commit 8a2479e

Browse files
Fixed SNC errors in helm and insights plugin
1 parent 4dd9a7c commit 8a2479e

37 files changed

+245
-202
lines changed

frontend/packages/helm-plugin/src/actions/creators.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export const getHelmDeleteAction = (
2525
onSubmit: () => {
2626
return coFetchJSON.delete(
2727
`/api/helm/release/async?name=${releaseName}&ns=${namespace}&version=${releaseVersion}`,
28-
null,
29-
null,
28+
undefined,
29+
undefined,
3030
-1,
3131
);
3232
},
@@ -66,16 +66,16 @@ export const editChartRepository = (
6666
cta: {
6767
href:
6868
hcr.kind === ProjectHelmChartRepositoryModel.kind
69-
? `/helm-repositories/ns/${hcr.metadata.namespace}/${
70-
hcr.metadata.name
69+
? `/helm-repositories/ns/${hcr.metadata?.namespace}/${
70+
hcr.metadata?.name
7171
}/form?kind=${referenceFor(hcr)}`
72-
: `/k8s/cluster/helmchartrepositories/${hcr.metadata.name}/form?kind=${referenceFor(hcr)}`,
72+
: `/k8s/cluster/helmchartrepositories/${hcr.metadata?.name}/form?kind=${referenceFor(hcr)}`,
7373
},
7474
accessReview: {
7575
group: model.apiGroup,
7676
resource: model.plural,
77-
name: hcr.metadata.name,
78-
namespace: hcr.metadata.namespace,
77+
name: hcr.metadata?.name,
78+
namespace: hcr.metadata?.namespace,
7979
verb: 'update',
8080
},
8181
});

frontend/packages/helm-plugin/src/actions/providers.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ export const useHelmActionProviderForTopology = (element: GraphElement) => {
5656
if (nodeType !== TYPE_HELM_RELEASE) return undefined;
5757
const releaseName = element.getLabel();
5858
if (!resource?.metadata) return null;
59-
const {
60-
namespace,
61-
labels: { version },
62-
} = resource.metadata;
59+
const { namespace, labels: { version } = {} } = resource.metadata;
6360
return {
6461
release: {
6562
name: releaseName,
@@ -72,7 +69,7 @@ export const useHelmActionProviderForTopology = (element: GraphElement) => {
7269
actionOrigin: 'topology',
7370
};
7471
}, [data, element, resource]);
75-
const result = useHelmActionProvider(scope);
72+
const result = useHelmActionProvider(scope as HelmActionsScope);
7673
return result;
7774
};
7875

frontend/packages/helm-plugin/src/catalog/providers/useHelmCharts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const useHelmCharts: ExtensionHook<CatalogItem[]> = ({
6969
const normalizedHelmCharts: CatalogItem[] = React.useMemo(
7070
() =>
7171
normalizeHelmCharts(
72-
helmCharts,
72+
helmCharts || {},
7373
[...chartRepositories?.hcrs?.data, ...chartRepositories?.phcrs?.data],
7474
namespace,
7575
t,

frontend/packages/helm-plugin/src/catalog/utils/catalog-utils.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const normalizeHelmCharts = (
3434
chartEntries,
3535
(normalizedCharts, charts, key) => {
3636
const chartRepoName = key.split('--').pop();
37-
const chartRepositoryTitle = getChartRepositoryTitle(chartRepositories, chartRepoName);
37+
const chartRepositoryTitle = getChartRepositoryTitle(chartRepositories, chartRepoName || '');
3838

3939
charts.forEach((chart: HelmChartMetaData) => {
4040
const { name, created, version, appVersion, description, keywords, annotations } = chart;
@@ -47,7 +47,7 @@ export const normalizeHelmCharts = (
4747
const imgUrl = chart.icon || getImageForIconClass('icon-helm');
4848
const chartURL = chart.urls[0];
4949
const encodedChartURL = encodeURIComponent(chartURL);
50-
const encodedChartRepoName = encodeURIComponent(chartRepoName);
50+
const encodedChartRepoName = encodeURIComponent(chartRepoName || '');
5151
const encodedChartName = encodeURIComponent(name);
5252
const encodedChartIndexKey = encodeURIComponent(key);
5353
const href = `/catalog/helm-install?chartName=${encodedChartName}&chartRepoName=${encodedChartRepoName}&chartURL=${encodedChartURL}&preselected-ns=${activeNamespace}&indexEntry=${encodedChartIndexKey}`;
@@ -70,7 +70,7 @@ export const normalizeHelmCharts = (
7070
</>
7171
) : null;
7272

73-
const maintainers = chart.maintainers?.length > 0 && (
73+
const maintainers = chart.maintainers?.length && chart.maintainers?.length > 0 && (
7474
<>
7575
{chart.maintainers?.map((maintainer, index) => (
7676
// eslint-disable-next-line react/no-array-index-key
@@ -156,7 +156,7 @@ export const normalizeHelmCharts = (
156156
providerType: translatedProviderType,
157157
},
158158
icon: {
159-
class: null,
159+
class: undefined,
160160
url: imgUrl,
161161
},
162162
cta: {

frontend/packages/helm-plugin/src/components/details-page/HelmReleaseDetails.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,25 @@ export const LoadedHelmReleaseDetails: React.FC<LoadedHelmReleaseDetailsProps> =
4949
if (helmRelease.loadError) {
5050
return <StatusBox loadError={helmRelease.loadError} />;
5151
}
52-
if (helmRelease.loaded && secrets.loadError) {
52+
if (helmRelease.loaded && secrets?.loadError) {
5353
return <StatusBox loadError={secrets.loadError} />;
5454
}
55-
if (!helmRelease.loaded || !secrets.loaded) {
55+
if (!helmRelease.loaded || !secrets?.loaded) {
5656
return <LoadingBox />;
5757
}
58-
if (!helmRelease.data || _.isEmpty(secrets.data)) {
58+
if (!helmRelease.data || _.isEmpty(secrets?.data)) {
5959
return <ErrorPage404 />;
6060
}
6161

62-
const sortedSecrets = _.orderBy(secrets.data, (o) => Number(o.metadata.labels.version), 'desc');
62+
const sortedSecrets = _.orderBy(
63+
secrets?.data,
64+
(o) => Number(o.metadata?.labels?.version),
65+
'desc',
66+
);
6367

6468
const releaseName = helmRelease.data?.name;
6569
const latestReleaseSecret = sortedSecrets[0];
66-
const latestSecretName = latestReleaseSecret?.metadata.name;
70+
const latestSecretName = latestReleaseSecret?.metadata?.name;
6771
const latestSecretStatus = latestReleaseSecret?.metadata?.labels?.status;
6872

6973
const title = (
@@ -74,8 +78,8 @@ export const LoadedHelmReleaseDetails: React.FC<LoadedHelmReleaseDetailsProps> =
7478
style={{ verticalAlign: 'middle', marginLeft: 'var(--pf-t--global--spacer--md)' }}
7579
>
7680
<Status
77-
status={releaseStatus(latestSecretStatus)}
78-
title={HelmReleaseStatusLabels[latestSecretStatus]}
81+
status={releaseStatus(latestSecretStatus || '')}
82+
title={HelmReleaseStatusLabels[latestSecretStatus || '']}
7983
/>
8084
</Badge>
8185
</>
@@ -173,7 +177,7 @@ const HelmReleaseDetails: React.FC<HelmReleaseDetailsProps> = () => {
173177

174178
const getHelmRelease = async () => {
175179
try {
176-
const helmRelease = await fetchHelmRelease(namespace, helmReleaseName);
180+
const helmRelease = await fetchHelmRelease(namespace || '', helmReleaseName || '');
177181
if (mounted) {
178182
setHelmReleaseData(helmRelease);
179183
}
@@ -213,7 +217,12 @@ const HelmReleaseDetails: React.FC<HelmReleaseDetailsProps> = () => {
213217
data: secrets,
214218
};
215219

216-
return <LoadedHelmReleaseDetails helmRelease={helmRelease} secrets={secretsFirehoseResult} />;
220+
return (
221+
<LoadedHelmReleaseDetails
222+
helmRelease={helmRelease as LoadedHelmReleaseDetailsProps['helmRelease']}
223+
secrets={secretsFirehoseResult}
224+
/>
225+
);
217226
};
218227

219228
export default HelmReleaseDetails;

frontend/packages/helm-plugin/src/components/details-page/history/HelmReleaseHistory.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ const HelmReleaseHistory: React.FC<HelmReleaseHistoryProps> = ({
2828
const helmReleaseName = params.name;
2929
const [revisionsLoaded, setRevisionsLoaded] = React.useState<boolean>(false);
3030
const [loadError, setLoadError] = React.useState<string>();
31-
const [revisions, setRevisions] = React.useState([]);
31+
const [revisions, setRevisions] = React.useState<HelmRelease[]>([]);
3232
const memoizedObj = useDeepCompareMemoize(obj);
3333
const { t } = useTranslation();
3434

3535
React.useEffect(() => {
3636
let destroyed = false;
37-
fetchHelmReleaseHistory(helmReleaseName, namespace)
37+
fetchHelmReleaseHistory(helmReleaseName || '', namespace || '')
3838
.then((items) => {
3939
if (!destroyed) {
40-
setLoadError(null);
40+
setLoadError(undefined);
4141
setRevisionsLoaded(true);
42-
setRevisions(items);
42+
setRevisions(items as HelmRelease[]);
4343
}
4444
})
4545
.catch((err) => {

frontend/packages/helm-plugin/src/components/details-page/overview/HelmChartSummary.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ const HelmChartSummary: React.FC<HelmChartSummaryProps> = ({ obj, helmRelease })
2828
info: { last_deployed: updated },
2929
} = helmRelease;
3030

31-
const {
32-
metadata: {
33-
labels: { version: revision },
34-
},
35-
} = obj;
31+
const revision = obj?.metadata?.labels?.version;
3632

3733
return (
3834
<DescriptionList>

frontend/packages/helm-plugin/src/components/details-page/overview/HelmReleaseOverview.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ const HelmReleaseOverview: React.FC<HelmReleaseOverviewProps> = ({ obj, customDa
2020
<SectionHeading text={t('helm-plugin~Helm Release details')} />
2121
<Grid hasGutter>
2222
<GridItem sm={6}>
23-
<ResourceSummary resource={obj} customPathName={'metadata.labels.name'} />
23+
<ResourceSummary
24+
resource={obj as K8sResourceKind}
25+
customPathName={'metadata.labels.name'}
26+
/>
2427
</GridItem>
2528
<GridItem sm={6}>
2629
<HelmChartSummary helmRelease={customData} obj={obj} />

frontend/packages/helm-plugin/src/components/details-page/resources/HelmReleaseResources.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const HelmReleaseResources: React.FC<HelmReleaseResourcesProps> = ({ customData
2929
return {
3030
...(model.namespaced ? { namespace } : {}),
3131
kind: model.crd ? referenceForModel(model) : model.kind,
32-
name: resource.metadata.name,
33-
prop: `${resource.metadata.name}-${resource.kind.toLowerCase()}`,
32+
name: resource.metadata?.name,
33+
prop: `${resource.metadata?.name}-${resource.kind?.toLowerCase()}`,
3434
isList: false,
3535
optional: true,
3636
};

frontend/packages/helm-plugin/src/components/details-page/resources/HelmReleaseResourcesRow.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ export const HelmReleaseResourceStatus: React.FC<HelmReleaseResourceStatusProps>
2020
const kind = referenceFor(resource);
2121
return resource.status?.replicas ? (
2222
<Link
23-
to={`${resourcePath(kind, resource.metadata.name, resource.metadata.namespace)}/pods`}
23+
to={`${resourcePath(kind, resource.metadata?.name, resource.metadata?.namespace)}/pods`}
2424
title={t('helm-plugin~Pods')}
2525
>
26-
{resource.status.replicas || 0} of {resource.spec.replicas} pods
26+
{resource.status?.replicas || 0} of {resource.spec?.replicas} pods
2727
</Link>
2828
) : (
2929
<Status status={_.get(resource.status, 'phase', 'Created')} />
@@ -37,16 +37,16 @@ const HelmReleaseResourcesRow: React.FC<RowFunctionArgs<K8sResourceKind>> = ({ o
3737
<TableData className={tableColumnClasses.name}>
3838
<ResourceLink
3939
kind={kind}
40-
name={resource.metadata.name}
41-
namespace={resource.metadata.namespace}
40+
name={resource.metadata?.name}
41+
namespace={resource.metadata?.namespace}
4242
/>
4343
</TableData>
4444
<TableData className={tableColumnClasses.type}>{resource.kind}</TableData>
4545
<TableData className={tableColumnClasses.status}>
4646
<HelmReleaseResourceStatus resource={resource} />
4747
</TableData>
4848
<TableData className={tableColumnClasses.created}>
49-
<Timestamp timestamp={resource.metadata.creationTimestamp} />
49+
<Timestamp timestamp={resource.metadata?.creationTimestamp || ''} />
5050
</TableData>
5151
</>
5252
);

0 commit comments

Comments
 (0)