From b02853c9a475fac85a812d72e73e0bcfc94a6667 Mon Sep 17 00:00:00 2001 From: karthik Date: Wed, 25 Oct 2023 11:30:17 +0530 Subject: [PATCH] fix(secret-list): fix secret list page error when secret is missing status field --- .../Secrets/__tests___/secret-utils.spec.ts | 18 ++++++++++++++++++ src/components/Secrets/utils/secret-utils.ts | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/components/Secrets/__tests___/secret-utils.spec.ts b/src/components/Secrets/__tests___/secret-utils.spec.ts index 5cc0bab44..db71e9bb8 100644 --- a/src/components/Secrets/__tests___/secret-utils.spec.ts +++ b/src/components/Secrets/__tests___/secret-utils.spec.ts @@ -160,6 +160,24 @@ describe('getSecretRowData', () => { }); }); + it('should not throw error when the status field is missing in the newly created secret', () => { + const injectedSecret = sampleRemoteSecrets[RemoteSecretStatusReason.Injected]; + + const secretWithoutStatus = { + ...injectedSecret, + status: undefined, + }; + + expect(getSecretRowData(secretWithoutStatus, ['development'])).toEqual({ + secretFor: 'Build', + secretLabels: '-', + secretName: 'test-secret-two', + secretStatus: '-', + secretTarget: 'development', + secretType: 'Key/value', + }); + }); + it('should return the labels data for the given secret', () => { const injectedSecret = sampleRemoteSecrets[RemoteSecretStatusReason.Injected]; diff --git a/src/components/Secrets/utils/secret-utils.ts b/src/components/Secrets/utils/secret-utils.ts index 3084fd5ce..ea9efb3b2 100644 --- a/src/components/Secrets/utils/secret-utils.ts +++ b/src/components/Secrets/utils/secret-utils.ts @@ -213,7 +213,8 @@ export const statusFromConditions = ( export const getSecretRowData = (obj: RemoteSecretKind, environmentNames: string[]): any => { const type = typeToLabel(obj?.spec?.secret?.type); - const keys = obj?.status.secret?.keys; + + const keys = obj?.status?.secret?.keys; const secretName = obj?.spec?.secret?.name || '-'; const secretFor = obj?.metadata?.labels?.[SecretByUILabel] ?? SecretFor.Deployment; const secretTarget =