From 64f0a9db0244c1dcaa9912e75cd41d6c5a071f7b Mon Sep 17 00:00:00 2001 From: Hrishav Date: Wed, 27 Sep 2023 14:52:35 +0530 Subject: [PATCH] fix: Fixed issues with refetch on ChaosHub, Environment and Probe screens (#4182) * fix: Fixed issues with refetch of various screens Signed-off-by: Hrishav * fix: Updated no token state management Signed-off-by: Hrishav --------- Signed-off-by: Hrishav --- .../graphql/server/pkg/gitops/service.go | 2 +- .../web/src/context/AppStoreContext.tsx | 12 +++--- .../AddHubModalWizard/AddHubModalWizard.tsx | 1 + .../controllers/Environments/Environment.tsx | 9 ++-- chaoscenter/web/src/strings/strings.en.yaml | 2 + chaoscenter/web/src/strings/types.ts | 2 + .../web/src/views/ChaosHubs/AddHubModal.tsx | 41 +++++++------------ .../ChaosProbes/ChaosProbesTableMenu.tsx | 5 ++- .../EnvironmentList/EnvironmentsList.tsx | 6 +-- ...sInfrastructureStepWizardConfiguration.tsx | 3 +- 10 files changed, 43 insertions(+), 40 deletions(-) diff --git a/chaoscenter/graphql/server/pkg/gitops/service.go b/chaoscenter/graphql/server/pkg/gitops/service.go index 84d6a55b05a..77d073aa5f9 100644 --- a/chaoscenter/graphql/server/pkg/gitops/service.go +++ b/chaoscenter/graphql/server/pkg/gitops/service.go @@ -79,7 +79,7 @@ func (g *gitOpsService) GitOpsNotificationHandler(ctx context.Context, infra cha if config == nil { return "Gitops Disabled", nil } - query := bson.D{{"infra_id", infra.InfraID}, {"experiment_id", experimentID}, {"isRemoved", false}} + query := bson.D{{"infra_id", infra.InfraID}, {"experiment_id", experimentID}, {"is_removed", false}} experiments, err := g.chaosExperimentOps.GetExperiments(query) if err != nil { logrus.Error("Could not get experiment :", err) diff --git a/chaoscenter/web/src/context/AppStoreContext.tsx b/chaoscenter/web/src/context/AppStoreContext.tsx index 13754c9ddda..c5464acd618 100644 --- a/chaoscenter/web/src/context/AppStoreContext.tsx +++ b/chaoscenter/web/src/context/AppStoreContext.tsx @@ -39,16 +39,18 @@ export function useAppStore(): AppStoreContextProps { export const AppStoreProvider: React.FC = ({ children }) => { const userDetails = getUserDetails(); - const tokenDecode: DecodedTokenType = jwtDecode(userDetails.accessToken); + const tokenDecode: DecodedTokenType | undefined = userDetails.accessToken + ? jwtDecode(userDetails.accessToken) + : undefined; const [appStore, setAppStore] = React.useState({ projectID: userDetails.projectID, projectRole: userDetails.projectRole, currentUserInfo: { - ID: tokenDecode.uid, - username: tokenDecode.username, - userRole: tokenDecode.role + ID: tokenDecode?.uid ?? '', + username: tokenDecode?.username ?? '', + userRole: tokenDecode?.role ?? '' }, - renderUrl: `/account/${tokenDecode.uid}`, + renderUrl: `/account/${tokenDecode?.uid}`, matchPath: '/account/:accountID', updateAppStore: () => void 0 }); diff --git a/chaoscenter/web/src/controllers/AddHubModalWizard/AddHubModalWizard.tsx b/chaoscenter/web/src/controllers/AddHubModalWizard/AddHubModalWizard.tsx index 66d7871f8b3..6f961f58431 100644 --- a/chaoscenter/web/src/controllers/AddHubModalWizard/AddHubModalWizard.tsx +++ b/chaoscenter/web/src/controllers/AddHubModalWizard/AddHubModalWizard.tsx @@ -20,6 +20,7 @@ export default function AddHubModalWizardController({ const [addChaosHubMutation, { loading: addChaosHubMutationLoading, error: addHubMutationError }] = addChaosHub({ onCompleted: () => { listChaosHubRefetch(); + hideDarkModal(); }, onError: err => showError(err.message) }); diff --git a/chaoscenter/web/src/controllers/Environments/Environment.tsx b/chaoscenter/web/src/controllers/Environments/Environment.tsx index 2e8a0114396..1bf5d2517ca 100644 --- a/chaoscenter/web/src/controllers/Environments/Environment.tsx +++ b/chaoscenter/web/src/controllers/Environments/Environment.tsx @@ -37,19 +37,22 @@ const EnvironmentController: React.FC = () => { const [deleteEnvironmentMutation] = deleteEnvironment({ onCompleted: () => { refetchEnvironments(); - } + }, + onError: err => showError(err.message) }); const [createEnvironmentMutation] = createEnvironment({ onCompleted: () => { refetchEnvironments(); - } + }, + onError: err => showError(err.message) }); const [updateEnvironmentMutation] = updateEnvironment({ onCompleted: () => { refetchEnvironments(); - } + }, + onError: err => showError(err.message) }); const environments = envData?.listEnvironments.environments; diff --git a/chaoscenter/web/src/strings/strings.en.yaml b/chaoscenter/web/src/strings/strings.en.yaml index 77586cacbc5..56e55fe1d3c 100644 --- a/chaoscenter/web/src/strings/strings.en.yaml +++ b/chaoscenter/web/src/strings/strings.en.yaml @@ -521,6 +521,7 @@ lastModified: Last Modified lastResilienceScore: Last Resilience Score lastRun: Last Run lastSyncedAt: Last Synced at +lastUpdatedBy: Last Updated By latestRun: Latest Run latestRunFallbackText: No Experiment Runs found launchExperiment: Launch Experiment @@ -598,6 +599,7 @@ needAttention: Needs Attention newChaosExperiment: New Chaos Experiment newChaosHub: New ChaosHub newChaosInfrastructure: Enable Chaos +newEnvironment: New Environment newExperiment: New Experiment newMember: New Member newPassword: New Password diff --git a/chaoscenter/web/src/strings/types.ts b/chaoscenter/web/src/strings/types.ts index b921ca172a2..f81b534acf3 100644 --- a/chaoscenter/web/src/strings/types.ts +++ b/chaoscenter/web/src/strings/types.ts @@ -430,6 +430,7 @@ export interface StringsMap { 'lastResilienceScore': unknown 'lastRun': unknown 'lastSyncedAt': unknown + 'lastUpdatedBy': unknown 'latestRun': unknown 'latestRunFallbackText': unknown 'launchExperiment': unknown @@ -499,6 +500,7 @@ export interface StringsMap { 'newChaosExperiment': unknown 'newChaosHub': unknown 'newChaosInfrastructure': unknown + 'newEnvironment': unknown 'newExperiment': unknown 'newMember': unknown 'newPassword': unknown diff --git a/chaoscenter/web/src/views/ChaosHubs/AddHubModal.tsx b/chaoscenter/web/src/views/ChaosHubs/AddHubModal.tsx index d2cc14b13f1..eaddafcf587 100644 --- a/chaoscenter/web/src/views/ChaosHubs/AddHubModal.tsx +++ b/chaoscenter/web/src/views/ChaosHubs/AddHubModal.tsx @@ -1,11 +1,10 @@ import React from 'react'; import { Dialog } from '@blueprintjs/core'; -import { ButtonVariation } from '@harnessio/uicore'; +import { ButtonVariation, useToggleOpen } from '@harnessio/uicore'; import type { ApolloQueryResult } from '@apollo/client'; import AddHubModalWizardController from '@controllers/AddHubModalWizard'; import type { ListChaosHubRequest, ListChaosHubResponse } from '@api/core'; import { useStrings } from '@strings'; -import { ParentComponentErrorWrapper } from '@errors'; import RbacButton from '@components/RbacButton'; import { PermissionGroup } from '@models'; import css from './ChaosHubs.module.scss'; @@ -19,33 +18,23 @@ interface AddHubModalProviderProps { function AddHubModal({ listChaosHubRefetch, disabled }: AddHubModalProviderProps): React.ReactElement { const { getString } = useStrings(); - const [isAddChaosHubModalOpen, setIsAddChaosHubModalOpen] = React.useState(false); + const { isOpen, open, close } = useToggleOpen(); return ( <> - - { - setIsAddChaosHubModalOpen(true); - }} - disabled={disabled} - permission={PermissionGroup.EDITOR} - /> - - setIsAddChaosHubModalOpen(false)} - className={css.modalWithHelpPanel} - > - setIsAddChaosHubModalOpen(false)} - listChaosHubRefetch={listChaosHubRefetch} - /> - + open()} + disabled={disabled} + permission={PermissionGroup.EDITOR} + /> + {isOpen && ( + close()} className={css.modalWithHelpPanel}> + close()} listChaosHubRefetch={listChaosHubRefetch} /> + + )} ); } diff --git a/chaoscenter/web/src/views/ChaosProbes/ChaosProbesTableMenu.tsx b/chaoscenter/web/src/views/ChaosProbes/ChaosProbesTableMenu.tsx index 58a43d02edc..41dd2aceee8 100644 --- a/chaoscenter/web/src/views/ChaosProbes/ChaosProbesTableMenu.tsx +++ b/chaoscenter/web/src/views/ChaosProbes/ChaosProbesTableMenu.tsx @@ -37,7 +37,10 @@ export const MenuCell = ({ row: { original: data }, refetchProbes }: MenuCellPro } = useToggleOpen(); const [deleteProbeMutation] = deleteProbe({ - onError: error => showError(error.message) + onError: error => showError(error.message), + onCompleted: () => { + refetchProbes?.(); + } }); // diff --git a/chaoscenter/web/src/views/Environments/EnvironmentList/EnvironmentsList.tsx b/chaoscenter/web/src/views/Environments/EnvironmentList/EnvironmentsList.tsx index 13124d84bf4..3e8ea79f0f6 100644 --- a/chaoscenter/web/src/views/Environments/EnvironmentList/EnvironmentsList.tsx +++ b/chaoscenter/web/src/views/Environments/EnvironmentList/EnvironmentsList.tsx @@ -60,14 +60,14 @@ export default function EnvironmentListView({ Cell: EnvironmentName }, { - Header: 'TYPE', + Header: getString('type').toUpperCase(), id: 'type', accessor: 'type', width: '30%', Cell: EnvironmentTypes }, { - Header: 'LAST UPDATED BY', + Header: getString('lastUpdatedBy').toUpperCase(), id: 'modifiedBy', width: '30%', Cell: LastUpdatedBy @@ -95,7 +95,7 @@ export default function EnvironmentListView({ data-testid="add-environment" icon="plus" iconProps={{ size: 10 }} - text="New Environment" + text={getString('newEnvironment')} permission={PermissionGroup.EDITOR} onClick={() => open()} /> diff --git a/chaoscenter/web/src/views/KubernetesChaosInfrastructureCreationModal/KubernetesChaosInfrastructureStepWizardConfiguration.tsx b/chaoscenter/web/src/views/KubernetesChaosInfrastructureCreationModal/KubernetesChaosInfrastructureStepWizardConfiguration.tsx index 987386fb19d..152c738f57d 100644 --- a/chaoscenter/web/src/views/KubernetesChaosInfrastructureCreationModal/KubernetesChaosInfrastructureStepWizardConfiguration.tsx +++ b/chaoscenter/web/src/views/KubernetesChaosInfrastructureCreationModal/KubernetesChaosInfrastructureStepWizardConfiguration.tsx @@ -202,11 +202,12 @@ function AdvancedChaosInfrastructureConfig({ className={css.addRowButton} /> - {tolerationEntities.map((_, index) => ( + {tolerationEntities.map((toleration, index) => (