From b601a2f55f04a15316c3b2d9634f6bbb8c3947a1 Mon Sep 17 00:00:00 2001 From: Joel Jacob Stephen <70131076+JoelJacobStephen@users.noreply.github.com> Date: Mon, 3 Jun 2024 14:31:44 +0530 Subject: [PATCH] fix(sh-admin): saving changes to server configurations post a failed attempt will require a page reload in dashboard (#4081) * fix: resolved an issue with server restart component * refactor: early return if any mutation fails when initiating server restart * fix: ensure further attempts go through after a failed reset configs action --------- Co-authored-by: jamesgeorge007 --- .../hoppscotch-sh-admin/src/components.d.ts | 6 ---- .../src/components/settings/Reset.vue | 6 +++- .../src/components/settings/ServerRestart.vue | 30 ++++++++++++++----- .../src/pages/settings.vue | 1 + 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/packages/hoppscotch-sh-admin/src/components.d.ts b/packages/hoppscotch-sh-admin/src/components.d.ts index eaaf88bfe..d26357c81 100644 --- a/packages/hoppscotch-sh-admin/src/components.d.ts +++ b/packages/hoppscotch-sh-admin/src/components.d.ts @@ -17,7 +17,6 @@ declare module '@vue/runtime-core' { HoppButtonPrimary: typeof import('@hoppscotch/ui')['HoppButtonPrimary'] HoppButtonSecondary: typeof import('@hoppscotch/ui')['HoppButtonSecondary'] HoppSmartAnchor: typeof import('@hoppscotch/ui')['HoppSmartAnchor'] - HoppSmartAutoComplete: typeof import('@hoppscotch/ui')['HoppSmartAutoComplete'] HoppSmartConfirmModal: typeof import('@hoppscotch/ui')['HoppSmartConfirmModal'] HoppSmartInput: typeof import('@hoppscotch/ui')['HoppSmartInput'] HoppSmartItem: typeof import('@hoppscotch/ui')['HoppSmartItem'] @@ -26,14 +25,9 @@ declare module '@vue/runtime-core' { HoppSmartPicture: typeof import('@hoppscotch/ui')['HoppSmartPicture'] HoppSmartSpinner: typeof import('@hoppscotch/ui')['HoppSmartSpinner'] HoppSmartTab: typeof import('@hoppscotch/ui')['HoppSmartTab'] - HoppSmartTable: typeof import('@hoppscotch/ui')['HoppSmartTable'] HoppSmartTabs: typeof import('@hoppscotch/ui')['HoppSmartTabs'] HoppSmartToggle: typeof import('@hoppscotch/ui')['HoppSmartToggle'] - IconLucideArrowLeft: typeof import('~icons/lucide/arrow-left')['default'] - IconLucideChevronDown: typeof import('~icons/lucide/chevron-down')['default'] IconLucideInbox: typeof import('~icons/lucide/inbox')['default'] - IconLucideSearch: typeof import('~icons/lucide/search')['default'] - IconLucideUser: typeof import('~icons/lucide/user')['default'] SettingsAuthProvider: typeof import('./components/settings/AuthProvider.vue')['default'] SettingsConfigurations: typeof import('./components/settings/Configurations.vue')['default'] SettingsDataSharing: typeof import('./components/settings/DataSharing.vue')['default'] diff --git a/packages/hoppscotch-sh-admin/src/components/settings/Reset.vue b/packages/hoppscotch-sh-admin/src/components/settings/Reset.vue index ddfa35380..cc6e2b1b0 100644 --- a/packages/hoppscotch-sh-admin/src/components/settings/Reset.vue +++ b/packages/hoppscotch-sh-admin/src/components/settings/Reset.vue @@ -24,7 +24,11 @@ - + (); + // Mutations to update or reset server configurations and audit logs const resetInfraConfigsMutation = useMutation(ResetInfraConfigsDocument); const updateInfraConfigsMutation = useMutation(UpdateInfraConfigsDocument); @@ -73,28 +77,40 @@ const startCountdown = () => { }, 1000); }; +const triggerComponentUnMount = () => emit('mutationFailure'); + // Call relevant mutations on component mount and initiate server restart onMounted(async () => { - let success = true; - if (props.reset) { - success = await resetInfraConfigs(resetInfraConfigsMutation); - if (!success) return; + const resetInfraConfigsResult = await resetInfraConfigs( + resetInfraConfigsMutation + ); + + if (!resetInfraConfigsResult) { + return triggerComponentUnMount(); + } } else { const infraResult = await updateInfraConfigs(updateInfraConfigsMutation); - if (!infraResult) return; + if (!infraResult) { + return triggerComponentUnMount(); + } const authResult = await updateAuthProvider( updateAllowedAuthProviderMutation ); - if (!authResult) return; + + if (!authResult) { + return triggerComponentUnMount(); + } const dataSharingResult = await updateDataSharingConfigs( toggleDataSharingMutation ); - if (!dataSharingResult) return; + if (!dataSharingResult) { + return triggerComponentUnMount(); + } } restart.value = true; diff --git a/packages/hoppscotch-sh-admin/src/pages/settings.vue b/packages/hoppscotch-sh-admin/src/pages/settings.vue index 23cddb6e7..783935414 100644 --- a/packages/hoppscotch-sh-admin/src/pages/settings.vue +++ b/packages/hoppscotch-sh-admin/src/pages/settings.vue @@ -37,6 +37,7 @@