Skip to content

Commit

Permalink
fix: Fixed issues with refetch on ChaosHub, Environment and Probe scr…
Browse files Browse the repository at this point in the history
…eens (#4182)

* fix: Fixed issues with refetch of various screens

Signed-off-by: Hrishav <hrishav.kumar@harness.io>

* fix: Updated no token state management

Signed-off-by: Hrishav <hrishav.kumar@harness.io>

---------

Signed-off-by: Hrishav <hrishav.kumar@harness.io>
  • Loading branch information
hrishavjha authored Sep 27, 2023
1 parent 6141ddd commit 64f0a9d
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 40 deletions.
2 changes: 1 addition & 1 deletion chaoscenter/graphql/server/pkg/gitops/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions chaoscenter/web/src/context/AppStoreContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ export function useAppStore(): AppStoreContextProps {

export const AppStoreProvider: React.FC<AppStoreContextProps> = ({ 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<AppStoreContextProps>({
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
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function AddHubModalWizardController({
const [addChaosHubMutation, { loading: addChaosHubMutationLoading, error: addHubMutationError }] = addChaosHub({
onCompleted: () => {
listChaosHubRefetch();
hideDarkModal();
},
onError: err => showError(err.message)
});
Expand Down
9 changes: 6 additions & 3 deletions chaoscenter/web/src/controllers/Environments/Environment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions chaoscenter/web/src/strings/strings.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions chaoscenter/web/src/strings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ export interface StringsMap {
'lastResilienceScore': unknown
'lastRun': unknown
'lastSyncedAt': unknown
'lastUpdatedBy': unknown
'latestRun': unknown
'latestRunFallbackText': unknown
'launchExperiment': unknown
Expand Down Expand Up @@ -499,6 +500,7 @@ export interface StringsMap {
'newChaosExperiment': unknown
'newChaosHub': unknown
'newChaosInfrastructure': unknown
'newEnvironment': unknown
'newExperiment': unknown
'newMember': unknown
'newPassword': unknown
Expand Down
41 changes: 15 additions & 26 deletions chaoscenter/web/src/views/ChaosHubs/AddHubModal.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
<>
<ParentComponentErrorWrapper>
<RbacButton
variation={ButtonVariation.PRIMARY}
text={getString('newChaosHub')}
icon="plus"
onClick={() => {
setIsAddChaosHubModalOpen(true);
}}
disabled={disabled}
permission={PermissionGroup.EDITOR}
/>
</ParentComponentErrorWrapper>
<Dialog
isOpen={isAddChaosHubModalOpen}
enforceFocus={false}
onClose={() => setIsAddChaosHubModalOpen(false)}
className={css.modalWithHelpPanel}
>
<AddHubModalWizardController
hideDarkModal={() => setIsAddChaosHubModalOpen(false)}
listChaosHubRefetch={listChaosHubRefetch}
/>
</Dialog>
<RbacButton
variation={ButtonVariation.PRIMARY}
text={getString('newChaosHub')}
icon="plus"
onClick={() => open()}
disabled={disabled}
permission={PermissionGroup.EDITOR}
/>
{isOpen && (
<Dialog isOpen={isOpen} enforceFocus={false} onClose={() => close()} className={css.modalWithHelpPanel}>
<AddHubModalWizardController hideDarkModal={() => close()} listChaosHubRefetch={listChaosHubRefetch} />
</Dialog>
)}
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?.();
}
});

// <!-- confirmation dialog boxes -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,12 @@ function AdvancedChaosInfrastructureConfig({
className={css.addRowButton}
/>
</Layout.Horizontal>
{tolerationEntities.map((_, index) => (
{tolerationEntities.map((toleration, index) => (
<Layout.Horizontal key={index} className={css.keyValueContainer}>
<FormInput.Text
inputGroup={{ type: 'number' }}
className={css.textCss}
disabled={toleration.effect === 'NoSchedule' || toleration.effect === ''}
name={`${'tolerationValues'}[${index}].tolerationSeconds`}
placeholder={getString('tolerationSeconds')}
/>
Expand Down

0 comments on commit 64f0a9d

Please sign in to comment.