api-client/components/collections/graphql/Request.vue

175 lines
4.3 KiB
Vue
Raw Normal View History

2021-03-18 14:55:12 +00:00
<template>
2021-07-08 18:12:15 +00:00
<div class="flex flex-col" :class="[{ 'bg-primaryLight': dragging }]">
2021-03-18 14:55:12 +00:00
<div
2021-07-08 18:12:15 +00:00
class="flex items-center group"
2021-03-18 14:55:12 +00:00
draggable="true"
@dragstart="dragStart"
@dragover.stop
@dragleave="dragging = false"
@dragend="dragging = false"
>
2021-07-08 18:12:15 +00:00
<span
class="
2021-07-17 17:40:28 +00:00
cursor-pointer
2021-07-08 18:12:15 +00:00
flex
2021-07-17 17:40:28 +00:00
font-mono font-bold
mx-2
2021-07-08 18:12:15 +00:00
w-12
2021-07-17 17:40:28 +00:00
justify-center
items-center
2021-07-08 18:12:15 +00:00
truncate
"
@click="!doc ? selectRequest() : {}"
>
<i class="material-icons" :class="{ 'text-green-400': isSelected }">
{{ isSelected ? "check_circle" : "description" }}
</i>
</span>
<span
class="
cursor-pointer
2021-07-17 17:40:28 +00:00
flex
font-semibold
flex-1
min-w-0
py-2
2021-07-17 17:40:28 +00:00
pr-2
2021-07-08 18:12:15 +00:00
transition
2021-07-17 17:40:28 +00:00
group-hover:text-secondaryDark
2021-07-08 18:12:15 +00:00
"
@click="!doc ? selectRequest() : {}"
>
<span class="truncate"> {{ request.name }} </span>
</span>
2021-07-09 07:39:52 +00:00
<ButtonSecondary
2021-07-10 13:15:39 +00:00
v-if="!savingMode"
2021-07-09 07:39:52 +00:00
v-tippy="{ theme: 'tooltip' }"
icon="replay"
:title="$t('restore')"
class="group-hover:inline-flex hidden"
@click.native="!doc ? selectRequest() : {}"
/>
2021-07-08 07:30:41 +00:00
<tippy
ref="options"
interactive
tabindex="-1"
trigger="click"
theme="popover"
arrow
>
2021-07-02 16:30:08 +00:00
<template #trigger>
2021-07-08 07:30:41 +00:00
<ButtonSecondary
2021-07-02 16:30:08 +00:00
v-tippy="{ theme: 'tooltip' }"
:title="$t('more')"
2021-07-03 13:14:58 +00:00
icon="more_vert"
/>
2021-03-18 14:55:12 +00:00
</template>
2021-07-05 16:52:15 +00:00
<SmartItem
icon="edit"
:label="$t('edit')"
@click.native="
$emit('edit-request', {
request,
requestIndex,
folderPath,
})
$refs.options.tippy().hide()
"
/>
<SmartItem
icon="delete"
color="red"
2021-07-05 16:52:15 +00:00
:label="$t('delete')"
@click.native="
confirmRemove = true
$refs.options.tippy().hide()
"
/>
2021-07-02 16:30:08 +00:00
</tippy>
2021-03-18 14:55:12 +00:00
</div>
<SmartConfirmModal
:show="confirmRemove"
:title="$t('are_you_sure_remove_request')"
@hide-modal="confirmRemove = false"
@resolve="removeRequest"
/>
</div>
</template>
<script lang="ts">
import Vue from "vue"
import { removeGraphqlRequest } from "~/newstore/collections"
2021-03-18 14:55:12 +00:00
export default Vue.extend({
2021-03-18 14:55:12 +00:00
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 },
2021-05-18 16:09:55 +00:00
request: { type: Object, default: () => {} },
folderPath: { type: String, default: null },
2021-05-18 16:09:55 +00:00
requestIndex: { type: Number, default: null },
2021-03-18 14:55:12 +00:00
doc: Boolean,
},
data() {
return {
dragging: false,
confirmRemove: false,
}
},
computed: {
isSelected(): boolean {
2021-05-30 02:43:05 +00:00
return (
this.picked &&
this.picked.pickedType === "gql-my-request" &&
this.picked.folderPath === this.folderPath &&
this.picked.requestIndex === this.requestIndex
2021-05-30 02:43:05 +00:00
)
},
},
2021-03-18 14:55:12 +00:00
methods: {
pick() {
2021-05-30 02:43:05 +00:00
this.$emit("select", {
picked: {
pickedType: "gql-my-request",
folderPath: this.folderPath,
2021-05-30 02:43:05 +00:00
requestIndex: this.requestIndex,
},
})
},
2021-03-18 14:55:12 +00:00
selectRequest() {
if (this.savingMode) {
this.pick()
return
}
2021-05-18 16:09:55 +00:00
this.$store.commit("postwoman/selectGraphqlRequest", {
request: this.request,
})
2021-03-18 14:55:12 +00:00
},
dragStart({ dataTransfer }: any) {
2021-03-18 14:55:12 +00:00
this.dragging = !this.dragging
dataTransfer.setData("folderPath", this.folderPath)
dataTransfer.setData("requestIndex", this.requestIndex)
2021-03-18 14:55:12 +00:00
},
removeRequest() {
// Cancel pick if the picked request is deleted
2021-06-16 13:43:07 +00:00
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.error(this.$t("deleted").toString(), {
2021-03-18 14:55:12 +00:00
icon: "delete",
})
},
},
})
2021-03-18 14:55:12 +00:00
</script>