Co-authored-by: Rishabh Agarwal <rishabh2001agarwal@gmail.com> Co-authored-by: Rishabh Agarwal <45998880+RishabhAgarwal-2001@users.noreply.github.com> Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
219 lines
6.4 KiB
Vue
219 lines
6.4 KiB
Vue
<template>
|
|
<div class="flex flex-col" :class="[{ 'bg-primaryLight': dragging }]">
|
|
<div
|
|
class="flex items-stretch group"
|
|
draggable="true"
|
|
@dragstart="dragStart"
|
|
@dragover.stop
|
|
@dragleave="dragging = false"
|
|
@dragend="dragging = false"
|
|
@contextmenu.prevent="options.tippy().show()"
|
|
>
|
|
<span
|
|
class="flex items-center justify-center w-16 px-2 truncate cursor-pointer"
|
|
@click="!doc ? selectRequest() : {}"
|
|
>
|
|
<SmartIcon
|
|
class="svg-icons"
|
|
:class="{ 'text-accent': isSelected }"
|
|
:name="isSelected ? 'check-circle' : 'file'"
|
|
/>
|
|
</span>
|
|
<span
|
|
class="flex flex-1 min-w-0 py-2 pr-2 cursor-pointer transition group-hover:text-secondaryDark"
|
|
@click="!doc ? selectRequest() : {}"
|
|
>
|
|
<span class="truncate" :class="{ 'text-accent': isSelected }">
|
|
{{ request.name }}
|
|
</span>
|
|
</span>
|
|
<div class="flex">
|
|
<ButtonSecondary
|
|
v-if="!savingMode"
|
|
v-tippy="{ theme: 'tooltip' }"
|
|
svg="rotate-ccw"
|
|
:title="$t('action.restore')"
|
|
class="hidden group-hover:inline-flex"
|
|
@click.native="!doc ? selectRequest() : {}"
|
|
/>
|
|
<span>
|
|
<tippy
|
|
ref="options"
|
|
interactive
|
|
trigger="click"
|
|
theme="popover"
|
|
arrow
|
|
:on-shown="() => tippyActions.focus()"
|
|
>
|
|
<template #trigger>
|
|
<ButtonSecondary
|
|
v-tippy="{ theme: 'tooltip' }"
|
|
:title="$t('action.more')"
|
|
svg="more-vertical"
|
|
/>
|
|
</template>
|
|
<div
|
|
ref="tippyActions"
|
|
class="flex flex-col focus:outline-none"
|
|
tabindex="0"
|
|
role="menu"
|
|
@keyup.e="edit.$el.click()"
|
|
@keyup.d="duplicate.$el.click()"
|
|
@keyup.delete="deleteAction.$el.click()"
|
|
@keyup.escape="options.tippy().hide()"
|
|
>
|
|
<SmartItem
|
|
ref="edit"
|
|
svg="edit"
|
|
:label="`${$t('action.edit')}`"
|
|
:shortcut="['E']"
|
|
@click.native="
|
|
() => {
|
|
$emit('edit-request', {
|
|
request,
|
|
requestIndex,
|
|
folderPath,
|
|
})
|
|
options.tippy().hide()
|
|
}
|
|
"
|
|
/>
|
|
<SmartItem
|
|
ref="duplicate"
|
|
svg="copy"
|
|
:label="`${$t('action.duplicate')}`"
|
|
:shortcut="['D']"
|
|
@click.native="
|
|
() => {
|
|
$emit('duplicate-request', {
|
|
request,
|
|
requestIndex,
|
|
folderPath,
|
|
})
|
|
options.tippy().hide()
|
|
}
|
|
"
|
|
/>
|
|
<SmartItem
|
|
ref="deleteAction"
|
|
svg="trash-2"
|
|
:label="`${$t('action.delete')}`"
|
|
:shortcut="['⌫']"
|
|
@click.native="
|
|
() => {
|
|
confirmRemove = true
|
|
options.tippy().hide()
|
|
}
|
|
"
|
|
/>
|
|
</div>
|
|
</tippy>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<SmartConfirmModal
|
|
:show="confirmRemove"
|
|
:title="`${$t('confirm.remove_request')}`"
|
|
@hide-modal="confirmRemove = false"
|
|
@resolve="removeRequest"
|
|
/>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import { defineComponent, PropType, ref } from "@nuxtjs/composition-api"
|
|
import { HoppGQLRequest, makeGQLRequest } from "@hoppscotch/data"
|
|
import { cloneDeep } from "lodash"
|
|
import { removeGraphqlRequest } from "~/newstore/collections"
|
|
import { setGQLSession } from "~/newstore/GQLSession"
|
|
|
|
export default defineComponent({
|
|
props: {
|
|
// Whether the object is selected (show the tick mark)
|
|
picked: { type: Object, default: null },
|
|
// Whether the request is being saved (activate 'select' event)
|
|
savingMode: { type: Boolean, default: false },
|
|
request: { type: Object as PropType<HoppGQLRequest>, default: () => {} },
|
|
folderPath: { type: String, default: null },
|
|
requestIndex: { type: Number, default: null },
|
|
doc: Boolean,
|
|
},
|
|
setup() {
|
|
return {
|
|
tippyActions: ref<any | null>(null),
|
|
options: ref<any | null>(null),
|
|
edit: ref<any | null>(null),
|
|
duplicate: ref<any | null>(null),
|
|
deleteAction: ref<any | null>(null),
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
dragging: false,
|
|
confirmRemove: false,
|
|
}
|
|
},
|
|
computed: {
|
|
isSelected(): boolean {
|
|
return (
|
|
this.picked &&
|
|
this.picked.pickedType === "gql-my-request" &&
|
|
this.picked.folderPath === this.folderPath &&
|
|
this.picked.requestIndex === this.requestIndex
|
|
)
|
|
},
|
|
},
|
|
methods: {
|
|
pick() {
|
|
this.$emit("select", {
|
|
picked: {
|
|
pickedType: "gql-my-request",
|
|
folderPath: this.folderPath,
|
|
requestIndex: this.requestIndex,
|
|
},
|
|
})
|
|
},
|
|
selectRequest() {
|
|
if (this.savingMode) {
|
|
this.pick()
|
|
} else {
|
|
setGQLSession({
|
|
request: cloneDeep(
|
|
makeGQLRequest({
|
|
name: this.$props.request.name,
|
|
url: this.$props.request.url,
|
|
query: this.$props.request.query,
|
|
headers: this.$props.request.headers,
|
|
variables: this.$props.request.variables,
|
|
auth: this.$props.request.auth,
|
|
})
|
|
),
|
|
schema: "",
|
|
response: "",
|
|
})
|
|
}
|
|
},
|
|
dragStart({ dataTransfer }: any) {
|
|
this.dragging = !this.dragging
|
|
|
|
dataTransfer.setData("folderPath", this.folderPath)
|
|
dataTransfer.setData("requestIndex", this.requestIndex)
|
|
},
|
|
removeRequest() {
|
|
// Cancel pick if the picked request is deleted
|
|
if (
|
|
this.picked &&
|
|
this.picked.pickedType === "gql-my-request" &&
|
|
this.picked.folderPath === this.folderPath &&
|
|
this.picked.requestIndex === this.requestIndex
|
|
) {
|
|
this.$emit("select", { picked: null })
|
|
}
|
|
|
|
removeGraphqlRequest(this.folderPath, this.requestIndex)
|
|
this.$toast.success(`${this.$t("state.deleted")}`)
|
|
},
|
|
},
|
|
})
|
|
</script>
|