Environment.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <div
  3. class="flex items-stretch group"
  4. @contextmenu.prevent="options.tippy().show()"
  5. >
  6. <span
  7. class="flex items-center justify-center px-4 cursor-pointer"
  8. @click="$emit('edit-environment')"
  9. >
  10. <SmartIcon class="svg-icons" name="layers" />
  11. </span>
  12. <span
  13. class="flex flex-1 min-w-0 py-2 pr-2 cursor-pointer transition group-hover:text-secondaryDark"
  14. @click="$emit('edit-environment')"
  15. >
  16. <span class="truncate">
  17. {{ environment.name }}
  18. </span>
  19. </span>
  20. <span>
  21. <tippy
  22. ref="options"
  23. interactive
  24. trigger="click"
  25. theme="popover"
  26. arrow
  27. :on-shown="() => tippyActions.focus()"
  28. >
  29. <template #trigger>
  30. <ButtonSecondary
  31. v-tippy="{ theme: 'tooltip' }"
  32. :title="$t('action.more')"
  33. svg="more-vertical"
  34. />
  35. </template>
  36. <div
  37. ref="tippyActions"
  38. class="flex flex-col focus:outline-none"
  39. tabindex="0"
  40. role="menu"
  41. @keyup.e="edit.$el.click()"
  42. @keyup.d="duplicate.$el.click()"
  43. @keyup.delete="
  44. !(environmentIndex === 'Global') ? deleteAction.$el.click() : null
  45. "
  46. @keyup.escape="options.tippy().hide()"
  47. >
  48. <SmartItem
  49. ref="edit"
  50. svg="edit"
  51. :label="`${$t('action.edit')}`"
  52. :shortcut="['E']"
  53. @click.native="
  54. () => {
  55. $emit('edit-environment')
  56. options.tippy().hide()
  57. }
  58. "
  59. />
  60. <SmartItem
  61. ref="duplicate"
  62. svg="copy"
  63. :label="`${$t('action.duplicate')}`"
  64. :shortcut="['D']"
  65. @click.native="
  66. () => {
  67. duplicateEnvironment()
  68. options.tippy().hide()
  69. }
  70. "
  71. />
  72. <SmartItem
  73. v-if="!(environmentIndex === 'Global')"
  74. ref="deleteAction"
  75. svg="trash-2"
  76. :label="`${$t('action.delete')}`"
  77. :shortcut="['⌫']"
  78. @click.native="
  79. () => {
  80. confirmRemove = true
  81. options.tippy().hide()
  82. }
  83. "
  84. />
  85. </div>
  86. </tippy>
  87. </span>
  88. <SmartConfirmModal
  89. :show="confirmRemove"
  90. :title="`${$t('confirm.remove_environment')}`"
  91. @hide-modal="confirmRemove = false"
  92. @resolve="removeEnvironment"
  93. />
  94. </div>
  95. </template>
  96. <script lang="ts">
  97. import { defineComponent, PropType, ref } from "@nuxtjs/composition-api"
  98. import {
  99. deleteEnvironment,
  100. duplicateEnvironment,
  101. createEnvironment,
  102. setEnvironmentVariables,
  103. getGlobalVariables,
  104. environmentsStore,
  105. } from "~/newstore/environments"
  106. export default defineComponent({
  107. props: {
  108. environment: { type: Object, default: () => {} },
  109. environmentIndex: {
  110. type: [Number, String] as PropType<number | "Global">,
  111. default: null,
  112. },
  113. },
  114. setup() {
  115. return {
  116. tippyActions: ref<any | null>(null),
  117. options: ref<any | null>(null),
  118. edit: ref<any | null>(null),
  119. duplicate: ref<any | null>(null),
  120. deleteAction: ref<any | null>(null),
  121. }
  122. },
  123. data() {
  124. return {
  125. confirmRemove: false,
  126. }
  127. },
  128. methods: {
  129. removeEnvironment() {
  130. if (this.environmentIndex !== "Global")
  131. deleteEnvironment(this.environmentIndex)
  132. this.$toast.success(`${this.$t("state.deleted")}`)
  133. },
  134. duplicateEnvironment() {
  135. if (this.environmentIndex === "Global") {
  136. createEnvironment(`Global - ${this.$t("action.duplicate")}`)
  137. setEnvironmentVariables(
  138. environmentsStore.value.environments.length - 1,
  139. getGlobalVariables().reduce((gVars, gVar) => {
  140. gVars.push({ key: gVar.key, value: gVar.value })
  141. return gVars
  142. }, [])
  143. )
  144. } else duplicateEnvironment(this.environmentIndex)
  145. },
  146. },
  147. })
  148. </script>