Card.vue 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <div class="flex flex-col group">
  3. <div class="flex items-center">
  4. <span
  5. class="flex flex-1 min-w-0 py-2 pl-4 pr-2 cursor-pointer 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. <tippy
  13. v-if="entry.updatedOn"
  14. theme="tooltip"
  15. :delay="[500, 20]"
  16. :content="`${new Date(entry.updatedOn).toLocaleString()}`"
  17. />
  18. </span>
  19. <ButtonSecondary
  20. v-tippy="{ theme: 'tooltip' }"
  21. svg="trash"
  22. color="red"
  23. :title="$t('action.remove')"
  24. class="hidden group-hover:inline-flex"
  25. data-testid="delete_history_entry"
  26. @click.native="$emit('delete-entry')"
  27. />
  28. <ButtonSecondary
  29. v-tippy="{ theme: 'tooltip' }"
  30. :title="expand ? $t('hide.more') : $t('show.more')"
  31. :svg="expand ? 'minimize-2' : 'maximize-2'"
  32. class="hidden group-hover:inline-flex"
  33. @click.native="expand = !expand"
  34. />
  35. <ButtonSecondary
  36. v-tippy="{ theme: 'tooltip' }"
  37. :title="!entry.star ? $t('add.star') : $t('remove.star')"
  38. :svg="entry.star ? 'star-solid' : 'star'"
  39. color="yellow"
  40. :class="{ 'group-hover:inline-flex hidden': !entry.star }"
  41. data-testid="star_button"
  42. @click.native="$emit('toggle-star')"
  43. />
  44. </div>
  45. <div class="flex flex-col text-tiny">
  46. <span
  47. v-for="(line, index) in query"
  48. :key="`line-${index}`"
  49. class="px-4 font-mono truncate whitespace-pre cursor-pointer text-secondaryLight"
  50. data-testid="restore_history_entry"
  51. @click="useEntry"
  52. >{{ line }}</span
  53. >
  54. </div>
  55. </div>
  56. </template>
  57. <script setup lang="ts">
  58. import { computed, ref } from "@nuxtjs/composition-api"
  59. import { makeGQLRequest } from "@hoppscotch/data"
  60. import { cloneDeep } from "lodash"
  61. import { setGQLSession } from "~/newstore/GQLSession"
  62. import { GQLHistoryEntry } from "~/newstore/history"
  63. const props = defineProps<{
  64. entry: GQLHistoryEntry
  65. showMore: Boolean
  66. }>()
  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: cloneDeep(
  79. makeGQLRequest({
  80. name: props.entry.request.name,
  81. url: props.entry.request.url,
  82. headers: props.entry.request.headers,
  83. query: props.entry.request.query,
  84. variables: props.entry.request.variables,
  85. auth: props.entry.request.auth,
  86. })
  87. ),
  88. schema: "",
  89. response: props.entry.response,
  90. })
  91. }
  92. </script>