index.vue 5.4 KB

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