Card.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div class="flex items-stretch group">
  3. <span
  4. v-tippy="{ theme: 'tooltip', delay: [500, 20] }"
  5. class="flex items-center justify-center w-16 px-2 truncate cursor-pointer"
  6. :class="entryStatus.className"
  7. data-testid="restore_history_entry"
  8. :title="`${duration}`"
  9. @click="$emit('use-entry')"
  10. >
  11. {{ entry.request.method }}
  12. </span>
  13. <span
  14. class="flex flex-1 min-w-0 py-2 pr-2 cursor-pointer transition group-hover:text-secondaryDark"
  15. data-testid="restore_history_entry"
  16. @click="$emit('use-entry')"
  17. >
  18. <span class="truncate">
  19. {{ entry.request.endpoint }}
  20. </span>
  21. <tippy
  22. v-if="entry.updatedOn"
  23. theme="tooltip"
  24. :delay="[500, 20]"
  25. :content="`${new Date(entry.updatedOn).toLocaleString()}`"
  26. />
  27. </span>
  28. <ButtonSecondary
  29. v-tippy="{ theme: 'tooltip' }"
  30. svg="trash"
  31. color="red"
  32. :title="$t('action.remove')"
  33. class="hidden group-hover:inline-flex"
  34. data-testid="delete_history_entry"
  35. @click.native="$emit('delete-entry')"
  36. />
  37. <ButtonSecondary
  38. v-tippy="{ theme: 'tooltip' }"
  39. :title="!entry.star ? $t('add.star') : $t('remove.star')"
  40. :class="{ 'group-hover:inline-flex hidden': !entry.star }"
  41. :svg="entry.star ? 'star-solid' : 'star'"
  42. color="yellow"
  43. data-testid="star_button"
  44. @click.native="$emit('toggle-star')"
  45. />
  46. </div>
  47. </template>
  48. <script setup lang="ts">
  49. import { computed } from "@nuxtjs/composition-api"
  50. import findStatusGroup from "~/helpers/findStatusGroup"
  51. import { useI18n } from "~/helpers/utils/composables"
  52. import { RESTHistoryEntry } from "~/newstore/history"
  53. const props = defineProps<{
  54. entry: RESTHistoryEntry
  55. showMore: Boolean
  56. }>()
  57. const t = useI18n()
  58. const duration = computed(() => {
  59. if (props.entry.responseMeta.duration) {
  60. const responseDuration = props.entry.responseMeta.duration
  61. if (!responseDuration) return ""
  62. return responseDuration > 0
  63. ? `${t("request.duration")}: ${responseDuration}ms`
  64. : t("error.no_duration")
  65. } else return t("error.no_duration")
  66. })
  67. const entryStatus = computed(() => {
  68. const foundStatusGroup = findStatusGroup(props.entry.responseMeta.statusCode)
  69. return (
  70. foundStatusGroup || {
  71. className: "",
  72. }
  73. )
  74. })
  75. </script>