Environment.vue 3.1 KB

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