feat: rename request by double clicking its name on tabs (#3057)

Co-authored-by: Liyas Thomas <liyascthomas@gmail.com>
This commit is contained in:
Anwarul Islam
2023-05-25 02:18:19 +06:00
committed by GitHub
parent ddaec1b9ac
commit c910a0314a
3 changed files with 29 additions and 12 deletions

View File

@@ -42,9 +42,9 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch } from "vue"
import { useI18n } from "@composables/i18n" import { useI18n } from "@composables/i18n"
import { useToast } from "@composables/toast" import { useToast } from "@composables/toast"
import { useVModel } from "@vueuse/core"
const toast = useToast() const toast = useToast()
const t = useI18n() const t = useI18n()
@@ -53,28 +53,22 @@ const props = withDefaults(
defineProps<{ defineProps<{
show: boolean show: boolean
loadingState: boolean loadingState: boolean
editingRequestName: string modelValue?: string
}>(), }>(),
{ {
show: false, show: false,
loadingState: false, loadingState: false,
editingRequestName: "", modelValue: "",
} }
) )
const emit = defineEmits<{ const emit = defineEmits<{
(e: "submit", name: string): void (e: "submit", name: string): void
(e: "hide-modal"): void (e: "hide-modal"): void
(e: "update:modelValue", value: string): void
}>() }>()
const name = ref("") const name = useVModel(props, "modelValue")
watch(
() => props.editingRequestName,
(newName) => {
name.value = newName
}
)
const editRequest = () => { const editRequest = () => {
if (name.value.trim() === "") { if (name.value.trim() === "") {

View File

@@ -126,7 +126,7 @@
/> />
<CollectionsEditRequest <CollectionsEditRequest
:show="showModalEditRequest" :show="showModalEditRequest"
:editing-request-name="editingRequest ? editingRequest.name : ''" v-bind:model-value="editingRequest ? editingRequest.name : ''"
:loading-state="modalLoadingState" :loading-state="modalLoadingState"
@submit="updateEditingRequest" @submit="updateEditingRequest"
@hide-modal="displayModalEditRequest(false)" @hide-modal="displayModalEditRequest(false)"

View File

@@ -23,6 +23,7 @@
v-tippy="{ theme: 'tooltip', delay: [500, 20] }" v-tippy="{ theme: 'tooltip', delay: [500, 20] }"
:title="tab.document.request.name" :title="tab.document.request.name"
class="truncate px-2" class="truncate px-2"
@dblclick="openReqRenameModal()"
> >
<span <span
class="font-semibold text-tiny" class="font-semibold text-tiny"
@@ -61,6 +62,12 @@
<HttpSidebar /> <HttpSidebar />
</template> </template>
</AppPaneLayout> </AppPaneLayout>
<CollectionsEditRequest
:show="showRenamingReqNameModal"
v-model="reqName"
@submit="renameReqName"
@hide-modal="showRenamingReqNameModal = false"
/>
<HoppSmartConfirmModal <HoppSmartConfirmModal
:show="confirmingCloseForTabID !== null" :show="confirmingCloseForTabID !== null"
:confirm="t('modal.close_unsaved_tab')" :confirm="t('modal.close_unsaved_tab')"
@@ -116,6 +123,8 @@ import { oauthRedirect } from "~/helpers/oauth"
const savingRequest = ref(false) const savingRequest = ref(false)
const confirmingCloseForTabID = ref<string | null>(null) const confirmingCloseForTabID = ref<string | null>(null)
const showRenamingReqNameModal = ref(false)
const reqName = ref<string>("")
const t = useI18n() const t = useI18n()
const toast = useToast() const toast = useToast()
@@ -166,6 +175,20 @@ const removeTab = (tabID: string) => {
} }
} }
const openReqRenameModal = () => {
showRenamingReqNameModal.value = true
reqName.value = currentActiveTab.value.document.request.name
}
const renameReqName = () => {
const tab = getTabRef(currentTabID.value)
if (tab.value) {
tab.value.document.request.name = reqName.value
updateTab(tab.value)
}
showRenamingReqNameModal.value = false
}
/** /**
* This function is closed when the confirm tab is closed by some means (even saving triggers close) * This function is closed when the confirm tab is closed by some means (even saving triggers close)
*/ */