index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. :alt="$t('empty.environments')"
  114. />
  115. <span class="text-center pb-4">
  116. {{ $t("empty.environments") }}
  117. </span>
  118. <ButtonSecondary
  119. :label="`${$t('add.new')}`"
  120. filled
  121. class="mb-4"
  122. @click.native="displayModalAdd(true)"
  123. />
  124. </div>
  125. </AppSection>
  126. </template>
  127. <script lang="ts">
  128. import { computed, defineComponent } from "@nuxtjs/composition-api"
  129. import { useReadonlyStream, useStream } from "~/helpers/utils/composables"
  130. import {
  131. environments$,
  132. setCurrentEnvironment,
  133. selectedEnvIndex$,
  134. globalEnv$,
  135. } from "~/newstore/environments"
  136. export default defineComponent({
  137. setup() {
  138. const globalEnv = useReadonlyStream(globalEnv$, [])
  139. const globalEnvironment = computed(() => ({
  140. name: "Global",
  141. variables: globalEnv.value,
  142. }))
  143. return {
  144. environments: useReadonlyStream(environments$, []),
  145. globalEnvironment,
  146. selectedEnvironmentIndex: useStream(
  147. selectedEnvIndex$,
  148. -1,
  149. setCurrentEnvironment
  150. ),
  151. }
  152. },
  153. data() {
  154. return {
  155. showModalImportExport: false,
  156. showModalAdd: false,
  157. showModalEdit: false,
  158. editingEnvironmentIndex: undefined as number | "Global" | undefined,
  159. }
  160. },
  161. methods: {
  162. displayModalAdd(shouldDisplay: boolean) {
  163. this.showModalAdd = shouldDisplay
  164. },
  165. displayModalEdit(shouldDisplay: boolean) {
  166. this.showModalEdit = shouldDisplay
  167. if (!shouldDisplay) this.resetSelectedData()
  168. },
  169. displayModalImportExport(shouldDisplay: boolean) {
  170. this.showModalImportExport = shouldDisplay
  171. },
  172. editEnvironment(environmentIndex: number | "Global") {
  173. this.$data.editingEnvironmentIndex = environmentIndex
  174. this.displayModalEdit(true)
  175. },
  176. resetSelectedData() {
  177. this.$data.editingEnvironmentIndex = undefined
  178. },
  179. },
  180. })
  181. </script>