2020-02-23 16:38:15 +00:00
|
|
|
<template>
|
2021-12-11 02:33:39 +00:00
|
|
|
<div
|
|
|
|
|
class="flex items-stretch group"
|
2022-10-07 16:35:39 +00:00
|
|
|
@contextmenu.prevent="options!.tippy.show()"
|
2021-12-11 02:33:39 +00:00
|
|
|
>
|
2021-07-08 08:06:37 +00:00
|
|
|
<span
|
2022-11-03 04:43:06 +00:00
|
|
|
v-if="environmentIndex === 'Global'"
|
|
|
|
|
class="flex items-center justify-center px-4 cursor-pointer"
|
|
|
|
|
@click="emit('edit-environment')"
|
|
|
|
|
>
|
|
|
|
|
<icon-lucide-globe class="svg-icons" />
|
|
|
|
|
</span>
|
|
|
|
|
<span
|
|
|
|
|
v-else
|
2021-12-31 14:35:39 +00:00
|
|
|
class="flex items-center justify-center px-4 cursor-pointer"
|
2022-04-17 16:59:32 +00:00
|
|
|
@click="emit('edit-environment')"
|
2021-07-08 08:06:37 +00:00
|
|
|
>
|
2022-09-29 05:25:21 +00:00
|
|
|
<icon-lucide-layers class="svg-icons" />
|
2021-07-08 08:06:37 +00:00
|
|
|
</span>
|
|
|
|
|
<span
|
2022-01-31 14:14:40 +00:00
|
|
|
class="flex flex-1 min-w-0 py-2 pr-2 cursor-pointer transition group-hover:text-secondaryDark"
|
2022-04-17 16:59:32 +00:00
|
|
|
@click="emit('edit-environment')"
|
2021-07-08 08:06:37 +00:00
|
|
|
>
|
|
|
|
|
<span class="truncate">
|
|
|
|
|
{{ environment.name }}
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
2021-08-02 04:30:50 +00:00
|
|
|
<span>
|
2021-12-19 18:52:31 +00:00
|
|
|
<tippy
|
|
|
|
|
ref="options"
|
|
|
|
|
interactive
|
|
|
|
|
trigger="click"
|
|
|
|
|
theme="popover"
|
2022-10-07 16:35:39 +00:00
|
|
|
:on-shown="() => tippyActions!.focus()"
|
2021-12-19 18:52:31 +00:00
|
|
|
>
|
2022-09-29 05:25:21 +00:00
|
|
|
<ButtonSecondary
|
|
|
|
|
v-tippy="{ theme: 'tooltip' }"
|
|
|
|
|
:title="t('action.more')"
|
|
|
|
|
:icon="IconMoreVertical"
|
|
|
|
|
/>
|
|
|
|
|
<template #content="{ hide }">
|
|
|
|
|
<div
|
|
|
|
|
ref="tippyActions"
|
|
|
|
|
class="flex flex-col focus:outline-none"
|
|
|
|
|
tabindex="0"
|
2022-10-07 16:35:39 +00:00
|
|
|
role="menu"
|
|
|
|
|
@keyup.e="edit!.$el.click()"
|
|
|
|
|
@keyup.d="duplicate!.$el.click()"
|
2022-09-29 05:25:21 +00:00
|
|
|
@keyup.delete="
|
2022-10-07 16:35:39 +00:00
|
|
|
!(environmentIndex === 'Global')
|
|
|
|
|
? deleteAction!.$el.click()
|
|
|
|
|
: null
|
2021-12-19 18:52:31 +00:00
|
|
|
"
|
2022-09-29 05:25:21 +00:00
|
|
|
@keyup.escape="hide()"
|
|
|
|
|
>
|
|
|
|
|
<SmartItem
|
|
|
|
|
ref="edit"
|
|
|
|
|
:icon="IconEdit"
|
|
|
|
|
:label="`${t('action.edit')}`"
|
|
|
|
|
:shortcut="['E']"
|
|
|
|
|
@click="
|
|
|
|
|
() => {
|
|
|
|
|
emit('edit-environment')
|
|
|
|
|
hide()
|
|
|
|
|
}
|
|
|
|
|
"
|
|
|
|
|
/>
|
|
|
|
|
<SmartItem
|
|
|
|
|
ref="duplicate"
|
|
|
|
|
:icon="IconCopy"
|
|
|
|
|
:label="`${t('action.duplicate')}`"
|
|
|
|
|
:shortcut="['D']"
|
|
|
|
|
@click="
|
|
|
|
|
() => {
|
|
|
|
|
duplicateEnvironments()
|
|
|
|
|
hide()
|
|
|
|
|
}
|
|
|
|
|
"
|
|
|
|
|
/>
|
|
|
|
|
<SmartItem
|
2022-11-03 04:43:06 +00:00
|
|
|
v-if="environmentIndex !== 'Global'"
|
2022-09-29 05:25:21 +00:00
|
|
|
ref="deleteAction"
|
|
|
|
|
:icon="IconTrash2"
|
|
|
|
|
:label="`${t('action.delete')}`"
|
|
|
|
|
:shortcut="['⌫']"
|
|
|
|
|
@click="
|
|
|
|
|
() => {
|
|
|
|
|
confirmRemove = true
|
|
|
|
|
hide()
|
|
|
|
|
}
|
|
|
|
|
"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2021-08-02 04:30:50 +00:00
|
|
|
</tippy>
|
|
|
|
|
</span>
|
2021-03-01 03:58:14 +00:00
|
|
|
<SmartConfirmModal
|
2020-12-14 05:05:14 +00:00
|
|
|
:show="confirmRemove"
|
2022-04-17 16:59:32 +00:00
|
|
|
:title="`${t('confirm.remove_environment')}`"
|
2020-12-14 05:05:14 +00:00
|
|
|
@hide-modal="confirmRemove = false"
|
|
|
|
|
@resolve="removeEnvironment"
|
|
|
|
|
/>
|
2020-02-23 16:38:15 +00:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2022-04-17 16:59:32 +00:00
|
|
|
<script setup lang="ts">
|
2022-09-29 05:25:21 +00:00
|
|
|
import IconMoreVertical from "~icons/lucide/more-vertical"
|
|
|
|
|
import IconEdit from "~icons/lucide/edit"
|
|
|
|
|
import IconCopy from "~icons/lucide/copy"
|
|
|
|
|
import IconTrash2 from "~icons/lucide/trash-2"
|
|
|
|
|
import { ref } from "vue"
|
2022-04-17 16:59:32 +00:00
|
|
|
import { Environment } from "@hoppscotch/data"
|
2022-09-29 05:25:21 +00:00
|
|
|
import { cloneDeep } from "lodash-es"
|
2021-10-03 13:08:36 +00:00
|
|
|
import {
|
|
|
|
|
deleteEnvironment,
|
|
|
|
|
duplicateEnvironment,
|
2021-11-02 00:46:16 +00:00
|
|
|
createEnvironment,
|
|
|
|
|
setEnvironmentVariables,
|
|
|
|
|
getGlobalVariables,
|
|
|
|
|
environmentsStore,
|
2021-10-03 13:08:36 +00:00
|
|
|
} from "~/newstore/environments"
|
2022-09-29 05:25:21 +00:00
|
|
|
import { useI18n } from "@composables/i18n"
|
|
|
|
|
import { useToast } from "@composables/toast"
|
2022-10-07 16:35:39 +00:00
|
|
|
import { TippyComponent } from "vue-tippy"
|
2023-01-28 02:57:00 +00:00
|
|
|
import SmartItem from "@hoppscotch/ui/src/components/smart/Item.vue"
|
2020-06-07 17:56:13 +00:00
|
|
|
|
2022-04-17 16:59:32 +00:00
|
|
|
const t = useI18n()
|
|
|
|
|
const toast = useToast()
|
|
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
environment: Environment
|
|
|
|
|
environmentIndex: number | "Global" | null
|
|
|
|
|
}>()
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
(e: "edit-environment"): void
|
|
|
|
|
}>()
|
|
|
|
|
|
|
|
|
|
const confirmRemove = ref(false)
|
|
|
|
|
|
2022-10-07 16:35:39 +00:00
|
|
|
const tippyActions = ref<TippyComponent | null>(null)
|
|
|
|
|
const options = ref<TippyComponent | null>(null)
|
2023-01-28 02:57:00 +00:00
|
|
|
const edit = ref<typeof SmartItem>()
|
|
|
|
|
const duplicate = ref<typeof SmartItem>()
|
|
|
|
|
const deleteAction = ref<typeof SmartItem>()
|
2022-04-17 16:59:32 +00:00
|
|
|
|
|
|
|
|
const removeEnvironment = () => {
|
|
|
|
|
if (props.environmentIndex === null) return
|
|
|
|
|
if (props.environmentIndex !== "Global")
|
|
|
|
|
deleteEnvironment(props.environmentIndex)
|
|
|
|
|
toast.success(`${t("state.deleted")}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const duplicateEnvironments = () => {
|
|
|
|
|
if (props.environmentIndex === null) return
|
|
|
|
|
if (props.environmentIndex === "Global") {
|
|
|
|
|
createEnvironment(`Global - ${t("action.duplicate")}`)
|
|
|
|
|
setEnvironmentVariables(
|
|
|
|
|
environmentsStore.value.environments.length - 1,
|
|
|
|
|
cloneDeep(getGlobalVariables())
|
|
|
|
|
)
|
|
|
|
|
} else duplicateEnvironment(props.environmentIndex)
|
|
|
|
|
}
|
2020-02-23 16:38:15 +00:00
|
|
|
</script>
|