2
0

index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <AppSection :label="`${$t('environment.title')}`">
  3. <div class="bg-primary rounded-t flex flex-col top-0 z-10 sticky">
  4. <tippy ref="options" interactive trigger="click" theme="popover" arrow>
  5. <template #trigger>
  6. <span
  7. v-tippy="{ theme: 'tooltip' }"
  8. :title="`${$t('environment.select')}`"
  9. class="
  10. bg-transparent
  11. border-b border-dividerLight
  12. flex-1
  13. select-wrapper
  14. "
  15. >
  16. <ButtonSecondary
  17. v-if="selectedEnvironmentIndex !== -1"
  18. :label="environments[selectedEnvironmentIndex].name"
  19. class="rounded-none flex-1 pr-8"
  20. />
  21. <ButtonSecondary
  22. v-else
  23. :label="`${$t('environment.no_environment')}`"
  24. class="rounded-none flex-1 pr-8"
  25. />
  26. </span>
  27. </template>
  28. <SmartItem
  29. :label="`${$t('environment.no_environment')}`"
  30. :info-icon="selectedEnvironmentIndex === -1 ? 'done' : ''"
  31. :active-info-icon="selectedEnvironmentIndex === -1"
  32. @click.native="
  33. () => {
  34. selectedEnvironmentIndex = -1
  35. $refs.options.tippy().hide()
  36. }
  37. "
  38. />
  39. <SmartItem
  40. v-for="(gen, index) in environments"
  41. :key="`gen-${index}`"
  42. :label="gen.name"
  43. :info-icon="index === selectedEnvironmentIndex ? 'done' : ''"
  44. :active-info-icon="index === selectedEnvironmentIndex"
  45. @click.native="
  46. () => {
  47. selectedEnvironmentIndex = index
  48. $refs.options.tippy().hide()
  49. }
  50. "
  51. />
  52. </tippy>
  53. <div class="border-b border-dividerLight flex flex-1 justify-between">
  54. <ButtonSecondary
  55. svg="plus"
  56. :label="`${$t('action.new')}`"
  57. class="!rounded-none"
  58. @click.native="displayModalAdd(true)"
  59. />
  60. <div class="flex">
  61. <ButtonSecondary
  62. v-tippy="{ theme: 'tooltip' }"
  63. to="https://docs.hoppscotch.io/features/environments"
  64. blank
  65. :title="$t('app.wiki')"
  66. svg="help-circle"
  67. />
  68. <ButtonSecondary
  69. v-tippy="{ theme: 'tooltip' }"
  70. svg="archive"
  71. :title="$t('modal.import_export')"
  72. @click.native="displayModalImportExport(true)"
  73. />
  74. </div>
  75. </div>
  76. </div>
  77. <EnvironmentsAdd
  78. :show="showModalAdd"
  79. @hide-modal="displayModalAdd(false)"
  80. />
  81. <EnvironmentsEdit
  82. :show="showModalEdit"
  83. :editing-environment-index="editingEnvironmentIndex"
  84. @hide-modal="displayModalEdit(false)"
  85. />
  86. <EnvironmentsImportExport
  87. :show="showModalImportExport"
  88. @hide-modal="displayModalImportExport(false)"
  89. />
  90. <div class="flex flex-col">
  91. <EnvironmentsEnvironment
  92. environment-index="Global"
  93. :environment="globalEnvironment"
  94. class="border-b border-dashed border-dividerLight"
  95. @edit-environment="editEnvironment('Global')"
  96. />
  97. <EnvironmentsEnvironment
  98. v-for="(environment, index) in environments"
  99. :key="`environment-${index}`"
  100. :environment-index="index"
  101. :environment="environment"
  102. @edit-environment="editEnvironment(index)"
  103. />
  104. </div>
  105. <div
  106. v-if="environments.length === 0"
  107. class="flex flex-col text-secondaryLight p-4 items-center justify-center"
  108. >
  109. <img
  110. :src="`/images/states/${$colorMode.value}/blockchain.svg`"
  111. loading="lazy"
  112. class="flex-col my-4 object-contain object-center h-16 w-16 inline-flex"
  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>