Card.vue 2.4 KB

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