All files / src/components AdminReportContent.vue

100% Statements 39/39
100% Branches 35/35
100% Functions 7/7
100% Lines 35/35

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127  43x 3x               3x       3x                   3x 3x               3x 3x 3x 3x 3x           3x   27x                                 29x           29x 29x 29x 29x   29x 2x 2x       5x 3x       29x 29x 29x 25x       4x 2x               29x 29x 29x 26x 24x   2x                                        
<template>
  <div class="admin-report-content">
    <span class="badge bg-secondary me-2 report-type">
      {{ t(`report.admin.types.${item.targetType}`) }}
    </span>
 
    <template v-if="item.targetType === 'comment'">
      <span v-if="item.snapshot.packVersion" class="text-muted small">
        {{ t('store.versionLabel').replace('{version}', String(item.snapshot.packVersion)) }}
      </span>
      <blockquote class="report-quote mb-1 mt-2">{{ item.snapshot.body }}</blockquote>
    </template>
 
    <template v-else-if="item.targetType === 'pack'">
      <strong class="report-pack-name">{{ packName }}</strong>
      <span v-if="item.snapshot.version" class="text-muted small ms-2">
        {{ t('store.versionLabel').replace('{version}', String(item.snapshot.version)) }}
      </span>
    </template>
 
    <template v-else-if="item.targetType === 'conversation'">
      <span v-if="item.snapshot.status === 'pending'" class="badge bg-warning text-dark">
        {{ t('report.admin.messageRequest') }}
      </span>
      <details class="mt-2 report-messages">
        <summary class="small">
          {{
            t('report.admin.latestMessages').replace(
              '{count}',
              String(item.snapshot.messages?.length ?? 0)
            )
          }}
        </summary>
        <ul class="list-unstyled small mb-0 mt-1">
          <li v-for="(message, index) in item.snapshot.messages ?? []" :key="index" class="mb-1">
            <span class="fw-semibold">{{ senderLabel(message.senderId) }}</span>
            <span class="text-muted ms-1">{{ formatDateTime(message.createdAt) }}</span>
            <div class="report-message-body">{{ message.body }}</div>
          </li>
        </ul>
      </details>
    </template>
 
    <div class="text-muted small mt-1 report-target-ids">{{ targetIds }}</div>
    <router-link v-if="targetLink" :to="targetLink" target="_blank" class="small report-open">
      <font-awesome-icon icon="fa-solid fa-up-right-from-square" class="me-1" />
      {{ t('report.admin.open') }}
    </router-link>
  </div>
</template>
 
<script setup lang="ts">
// @implements UC-REPORT-004.1, UC-REPORT-010.1
import { computed } from 'vue'
import type { RouteLocationNamedRaw } from 'vue-router'
import type { AdminContentReport, AdminReportUser } from '@/stores/admin'
import { useUILanguage } from '@/composables/useUILanguage'
import { useLanguage } from '@/composables/useLanguage'
import { useDateFormat } from '@/composables/useDateFormat'
import { useFlowLink } from '@/composables/useFlowLink'
 
// What was reported, as the report kept it: on the Reports and the Appeals tabs
const props = defineProps<{
  item: Pick<AdminContentReport, 'targetType' | 'target' | 'snapshot'>
  // Who may have written in a reported conversation: the reported user, the reporter
  people: (AdminReportUser | null)[]
}>()
 
const { t } = useUILanguage()
const { getTranslation } = useLanguage()
const { formatDateTime } = useDateFormat()
const { flowLink } = useFlowLink()
 
const packName = computed(() => {
  const name = props.item.snapshot.name
  return (name && getTranslation(name)) || '—'
})
 
function senderLabel(senderId: string): string {
  const sender = props.people.find((user) => user?.id === senderId)
  return sender?.name || (sender?.nickname ? `@${sender.nickname}` : '') || senderId
}
 
// The ids an admin needs to find the content and take it down
const targetIds = computed(() => {
  const { target, targetType } = props.item
  if (targetType === 'comment') {
    return target.packId
      ? `pack ${target.packId} · comment ${target.commentId}`
      : `entity ${target.entityId} · item ${target.itemId} · comment ${target.commentId}`
  }
  if (targetType === 'pack') return `pack ${target.packId}`
  return `conversation ${target.conversationId}`
})
 
/**
 * Where the reported content lives, opened in a new tab so the list keeps its
 * place: an item's comments panel, or the pack over the Store. A conversation
 * has no link: only its two participants may open it.
 */
const targetLink = computed((): RouteLocationNamedRaw | null => {
  const { target, targetType } = props.item
  if (target.packId) return flowLink('store', {}, { pack: target.packId })
  if (targetType === 'comment' && target.entityId && target.itemId) {
    return flowLink('entity-items', { entityId: target.entityId }, { comments: target.itemId })
  }
  return null
})
</script>
 
<style scoped>
.report-quote,
.report-message-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
 
.report-quote {
  padding-left: 0.75rem;
  border-left: 3px solid var(--bw-border, rgba(0, 0, 0, 0.15));
}
 
.admin-report-content {
  min-width: 18rem;
}
</style>