Card.vue 2.8 KB

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