index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <AppSection :label="$t('environment.title')">
  3. <div
  4. class="
  5. bg-primary
  6. rounded-t
  7. flex flex-col
  8. top-sidebarPrimaryStickyFold
  9. z-10
  10. sticky
  11. "
  12. >
  13. <tippy ref="options" interactive trigger="click" theme="popover" arrow>
  14. <template #trigger>
  15. <span
  16. v-tippy="{ theme: 'tooltip' }"
  17. :title="$t('environment.select')"
  18. class="
  19. bg-transparent
  20. border-b border-dividerLight
  21. flex-1
  22. select-wrapper
  23. "
  24. >
  25. <ButtonSecondary
  26. v-if="selectedEnvironmentIndex !== -1"
  27. :label="environments[selectedEnvironmentIndex].name"
  28. class="rounded-none flex-1 pr-8"
  29. />
  30. <ButtonSecondary
  31. v-else
  32. :label="$t('environment.no_environment')"
  33. class="rounded-none flex-1 pr-8"
  34. />
  35. </span>
  36. </template>
  37. <SmartItem
  38. :label="$t('environment.no_environment')"
  39. :info-icon="selectedEnvironmentIndex === -1 ? 'done' : ''"
  40. :active-info-icon="selectedEnvironmentIndex === -1"
  41. @click.native="
  42. selectedEnvironmentIndex = -1
  43. $refs.options.tippy().hide()
  44. "
  45. />
  46. <SmartItem
  47. v-for="(gen, index) in environments"
  48. :key="`gen-${index}`"
  49. :label="gen.name"
  50. :info-icon="index === selectedEnvironmentIndex ? 'done' : ''"
  51. :active-info-icon="index === selectedEnvironmentIndex"
  52. @click.native="
  53. selectedEnvironmentIndex = index
  54. $refs.options.tippy().hide()
  55. "
  56. />
  57. </tippy>
  58. <div class="border-b border-dividerLight flex flex-1 justify-between">
  59. <ButtonSecondary
  60. svg="plus"
  61. :label="$t('action.new')"
  62. class="!rounded-none"
  63. @click.native="displayModalAdd(true)"
  64. />
  65. <div class="flex">
  66. <ButtonSecondary
  67. v-tippy="{ theme: 'tooltip' }"
  68. to="https://docs.hoppscotch.io/features/environments"
  69. blank
  70. :title="$t('app.wiki')"
  71. svg="help-circle"
  72. />
  73. <ButtonSecondary
  74. v-tippy="{ theme: 'tooltip' }"
  75. svg="archive"
  76. :title="$t('modal.import_export')"
  77. @click.native="displayModalImportExport(true)"
  78. />
  79. </div>
  80. </div>
  81. </div>
  82. <EnvironmentsAdd
  83. :show="showModalAdd"
  84. @hide-modal="displayModalAdd(false)"
  85. />
  86. <EnvironmentsEdit
  87. :show="showModalEdit"
  88. :editing-environment-index="editingEnvironmentIndex"
  89. @hide-modal="displayModalEdit(false)"
  90. />
  91. <EnvironmentsImportExport
  92. :show="showModalImportExport"
  93. @hide-modal="displayModalImportExport(false)"
  94. />
  95. <div class="flex flex-col">
  96. <EnvironmentsEnvironment
  97. environment-index="Global"
  98. :environment="globalEnvironment"
  99. class="border-b border-dashed border-dividerLight"
  100. @edit-environment="editEnvironment('Global')"
  101. />
  102. <EnvironmentsEnvironment
  103. v-for="(environment, index) in environments"
  104. :key="`environment-${index}`"
  105. :environment-index="index"
  106. :environment="environment"
  107. @edit-environment="editEnvironment(index)"
  108. />
  109. </div>
  110. <div
  111. v-if="environments.length === 0"
  112. class="flex flex-col text-secondaryLight p-4 items-center justify-center"
  113. >
  114. <span class="text-center pb-4">
  115. {{ $t("empty.environments") }}
  116. </span>
  117. <ButtonSecondary
  118. :label="$t('add.new')"
  119. filled
  120. @click.native="displayModalAdd(true)"
  121. />
  122. </div>
  123. </AppSection>
  124. </template>
  125. <script lang="ts">
  126. import { computed, defineComponent } from "@nuxtjs/composition-api"
  127. import { useReadonlyStream, useStream } from "~/helpers/utils/composables"
  128. import {
  129. environments$,
  130. setCurrentEnvironment,
  131. selectedEnvIndex$,
  132. globalEnv$,
  133. } from "~/newstore/environments"
  134. export default defineComponent({
  135. setup() {
  136. const globalEnv = useReadonlyStream(globalEnv$, [])
  137. const globalEnvironment = computed(() => ({
  138. name: "Global",
  139. variables: globalEnv.value,
  140. }))
  141. return {
  142. environments: useReadonlyStream(environments$, []),
  143. globalEnvironment,
  144. selectedEnvironmentIndex: useStream(
  145. selectedEnvIndex$,
  146. -1,
  147. setCurrentEnvironment
  148. ),
  149. }
  150. },
  151. data() {
  152. return {
  153. showModalImportExport: false,
  154. showModalAdd: false,
  155. showModalEdit: false,
  156. editingEnvironmentIndex: undefined as number | "Global" | undefined,
  157. }
  158. },
  159. methods: {
  160. displayModalAdd(shouldDisplay: boolean) {
  161. this.showModalAdd = shouldDisplay
  162. },
  163. displayModalEdit(shouldDisplay: boolean) {
  164. this.showModalEdit = shouldDisplay
  165. if (!shouldDisplay) this.resetSelectedData()
  166. },
  167. displayModalImportExport(shouldDisplay: boolean) {
  168. this.showModalImportExport = shouldDisplay
  169. },
  170. editEnvironment(environmentIndex: number | "Global") {
  171. this.$data.editingEnvironmentIndex = environmentIndex
  172. this.displayModalEdit(true)
  173. },
  174. resetSelectedData() {
  175. this.$data.editingEnvironmentIndex = undefined
  176. },
  177. },
  178. })
  179. </script>