From 2b9a33488145a2bd80dbb8fe6ded1b23f6abf8e0 Mon Sep 17 00:00:00 2001 From: Nivedin <53208152+nivedin@users.noreply.github.com> Date: Wed, 29 Jan 2025 14:30:01 +0530 Subject: [PATCH] chore: add warning prompt for same response name (#4699) Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com> --- packages/hoppscotch-common/locales/en.json | 1 + .../src/components/http/Response.vue | 15 +++++- .../src/components/http/SaveResponseName.vue | 48 ++++++++++++++++--- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/packages/hoppscotch-common/locales/en.json b/packages/hoppscotch-common/locales/en.json index dfa0960a..7454f233 100644 --- a/packages/hoppscotch-common/locales/en.json +++ b/packages/hoppscotch-common/locales/en.json @@ -736,6 +736,7 @@ "preview_html": "Preview HTML", "raw": "Raw", "renamed": "Response renamed", + "same_name_inspector_warning": "Response name already exists for this request, if saved it will overwrite the existing response", "size": "Size", "status": "Status", "time": "Time", diff --git a/packages/hoppscotch-common/src/components/http/Response.vue b/packages/hoppscotch-common/src/components/http/Response.vue index 5caf62d7..96d52c96 100644 --- a/packages/hoppscotch-common/src/components/http/Response.vue +++ b/packages/hoppscotch-common/src/components/http/Response.vue @@ -9,7 +9,8 @@ /> { + return responseName.value + ? responseName.value in doc.value.request.responses + : false +}) + const loading = computed(() => doc.value.response?.type === "loading") const saveAsExample = () => { showSaveResponseName.value = true + + responseName.value = doc.value.request.name } const onSaveAsExample = () => { @@ -124,8 +133,10 @@ const onSaveAsExample = () => { editRESTRequest(saveCtx.folderPath, saveCtx.requestIndex, req) toast.success(`${t("response.saved")}`) + responseName.value = "" } catch (e) { console.error(e) + responseName.value = "" } } else { runMutation(UpdateRequestDocument, { @@ -137,10 +148,12 @@ const onSaveAsExample = () => { })().then((result) => { if (E.isLeft(result)) { toast.error(`${t("profile.no_permission")}`) + responseName.value = "" } else { doc.value.isDirty = false toast.success(`${t("request.saved")}`) + responseName.value = "" } }) } diff --git a/packages/hoppscotch-common/src/components/http/SaveResponseName.vue b/packages/hoppscotch-common/src/components/http/SaveResponseName.vue index 431be738..b818c71c 100644 --- a/packages/hoppscotch-common/src/components/http/SaveResponseName.vue +++ b/packages/hoppscotch-common/src/components/http/SaveResponseName.vue @@ -12,9 +12,14 @@ class="flex-grow" placeholder=" " :label="t('action.label')" - input-styles="floating-input" + input-styles="floating-input !border-0" + styles="border border-divider rounded" @submit="editRequest" - /> + > + +