Environment.vue 3.1 KB

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