Environment.vue 3.0 KB

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