Environment.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div
  3. class="flex items-stretch group"
  4. @contextmenu.prevent="$refs.options.tippy().show()"
  5. >
  6. <span
  7. class="cursor-pointer flex px-4 items-center justify-center"
  8. @click="$emit('edit-environment')"
  9. >
  10. <SmartIcon class="svg-icons" name="layers" />
  11. </span>
  12. <span
  13. class="cursor-pointer flex flex-1 min-w-0 py-2 pr-2 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 ref="options" interactive trigger="click" theme="popover" arrow>
  22. <template #trigger>
  23. <ButtonSecondary
  24. v-tippy="{ theme: 'tooltip' }"
  25. :title="$t('action.more')"
  26. svg="more-vertical"
  27. />
  28. </template>
  29. <SmartItem
  30. svg="edit"
  31. :label="`${$t('action.edit')}`"
  32. @click.native="
  33. () => {
  34. $emit('edit-environment')
  35. $refs.options.tippy().hide()
  36. }
  37. "
  38. />
  39. <SmartItem
  40. svg="copy"
  41. :label="`${$t('action.duplicate')}`"
  42. @click.native="
  43. () => {
  44. duplicateEnvironment()
  45. $refs.options.tippy().hide()
  46. }
  47. "
  48. />
  49. <SmartItem
  50. v-if="!(environmentIndex === 'Global')"
  51. svg="trash-2"
  52. color="red"
  53. :label="`${$t('action.delete')}`"
  54. @click.native="
  55. () => {
  56. confirmRemove = true
  57. $refs.options.tippy().hide()
  58. }
  59. "
  60. />
  61. </tippy>
  62. </span>
  63. <SmartConfirmModal
  64. :show="confirmRemove"
  65. :title="`${$t('confirm.remove_environment')}`"
  66. @hide-modal="confirmRemove = false"
  67. @resolve="removeEnvironment"
  68. />
  69. </div>
  70. </template>
  71. <script lang="ts">
  72. import { defineComponent, PropType } from "@nuxtjs/composition-api"
  73. import {
  74. deleteEnvironment,
  75. duplicateEnvironment,
  76. createEnvironment,
  77. setEnvironmentVariables,
  78. getGlobalVariables,
  79. environmentsStore,
  80. } from "~/newstore/environments"
  81. export default defineComponent({
  82. props: {
  83. environment: { type: Object, default: () => {} },
  84. environmentIndex: {
  85. type: [Number, String] as PropType<number | "Global">,
  86. default: null,
  87. },
  88. },
  89. data() {
  90. return {
  91. confirmRemove: false,
  92. }
  93. },
  94. methods: {
  95. removeEnvironment() {
  96. if (this.environmentIndex !== "Global")
  97. deleteEnvironment(this.environmentIndex)
  98. this.$toast.success(`${this.$t("state.deleted")}`)
  99. },
  100. duplicateEnvironment() {
  101. if (this.environmentIndex === "Global") {
  102. createEnvironment(`Global - ${this.$t("action.duplicate")}`)
  103. setEnvironmentVariables(
  104. environmentsStore.value.environments.length - 1,
  105. getGlobalVariables().reduce((gVars, gVar) => {
  106. gVars.push({ key: gVar.key, value: gVar.value })
  107. return gVars
  108. }, [])
  109. )
  110. } else duplicateEnvironment(this.environmentIndex)
  111. },
  112. },
  113. })
  114. </script>