Card.vue 2.5 KB

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