Card.vue 2.4 KB

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