Card.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div class="flex flex-col group">
  3. <div class="flex items-center">
  4. <span
  5. class="
  6. cursor-pointer
  7. flex flex-1
  8. min-w-0
  9. py-2
  10. pr-2
  11. pl-4
  12. transition
  13. group-hover:text-secondaryDark
  14. "
  15. data-testid="restore_history_entry"
  16. @click="useEntry"
  17. >
  18. <span class="truncate">
  19. {{ entry.request.url }}
  20. </span>
  21. </span>
  22. <ButtonSecondary
  23. v-tippy="{ theme: 'tooltip' }"
  24. svg="trash"
  25. color="red"
  26. :title="$t('action.remove')"
  27. class="hidden group-hover:inline-flex"
  28. data-testid="delete_history_entry"
  29. @click.native="$emit('delete-entry')"
  30. />
  31. <ButtonSecondary
  32. v-tippy="{ theme: 'tooltip' }"
  33. :title="expand ? $t('hide.more') : $t('show.more')"
  34. :svg="expand ? 'minimize-2' : 'maximize-2'"
  35. class="hidden group-hover:inline-flex"
  36. @click.native="expand = !expand"
  37. />
  38. <ButtonSecondary
  39. v-tippy="{ theme: 'tooltip' }"
  40. :title="!entry.star ? $t('add.star') : $t('remove.star')"
  41. :svg="entry.star ? 'star-solid' : 'star'"
  42. color="yellow"
  43. :class="{ 'group-hover:inline-flex hidden': !entry.star }"
  44. data-testid="star_button"
  45. @click.native="$emit('toggle-star')"
  46. />
  47. </div>
  48. <div class="flex flex-col">
  49. <span
  50. v-for="(line, index) in query"
  51. :key="`line-${index}`"
  52. class="cursor-pointer text-secondaryLight px-4 whitespace-pre truncate"
  53. data-testid="restore_history_entry"
  54. @click="useEntry"
  55. >{{ line }}</span
  56. >
  57. </div>
  58. </div>
  59. </template>
  60. <script lang="ts">
  61. import {
  62. computed,
  63. defineComponent,
  64. PropType,
  65. ref,
  66. } from "@nuxtjs/composition-api"
  67. import { makeGQLRequest } from "~/helpers/types/HoppGQLRequest"
  68. import { setGQLSession } from "~/newstore/GQLSession"
  69. import { GQLHistoryEntry } from "~/newstore/history"
  70. export default defineComponent({
  71. props: {
  72. entry: { type: Object as PropType<GQLHistoryEntry>, default: () => {} },
  73. showMore: Boolean,
  74. },
  75. setup(props) {
  76. const expand = ref(false)
  77. const query = computed(() =>
  78. expand.value
  79. ? (props.entry.request.query.split("\n") as string[])
  80. : (props.entry.request.query
  81. .split("\n")
  82. .slice(0, 2)
  83. .concat(["..."]) as string[])
  84. )
  85. const useEntry = () => {
  86. setGQLSession({
  87. request: makeGQLRequest({
  88. name: props.entry.request.name,
  89. url: props.entry.request.url,
  90. headers: props.entry.request.headers,
  91. query: props.entry.request.query,
  92. variables: props.entry.request.variables,
  93. }),
  94. schema: "",
  95. response: props.entry.response,
  96. })
  97. }
  98. return {
  99. expand,
  100. query,
  101. useEntry,
  102. }
  103. },
  104. })
  105. </script>