All files / src/components/matches MatchActionsSheet.vue

100% Statements 93/93
53.84% Branches 7/13
33.33% Functions 1/3
100% Lines 93/93

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 1191x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x   1x 1x 3x 3x 3x 3x 3x 3x   3x 1x   1x   1x 1x 1x 1x 1x   1x 1x   1x 1x 1x 1x   1x 1x   1x 1x 1x 1x 1x 1x 1x       1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x       1x       1x 1x 4x 1x   1x 4x 4x 4x 1x   1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x   1x 3x 3x 1x    
<template>
  <ModalOverlay
    align="end"
    max-width="max-w-md"
    :label="`Options for ${fixture}`"
    close-label="Close options"
    @close="$emit('close')"
  >
    <div class="p-4" data-testid="match-actions-sheet">
      <!-- Which match this is about. A sheet raised by a press has no visible
           tie back to the row underneath it, so it restates the fixture. -->
      <p class="text-sm font-semibold text-fg pr-10">{{ fixture }}</p>
      <p class="text-xs text-fg-muted mt-0.5">{{ subtitle }}</p>
 
      <div class="mt-4 space-y-1">
        <button
          type="button"
          class="w-full text-left px-3 py-2.5 rounded-lg text-sm font-medium text-fg hover:bg-surface-alt"
          data-testid="sheet-view-match"
          @click="$emit('view', match)"
        >
          View match
        </button>
        <button
          v-if="canEdit"
          type="button"
          class="w-full text-left px-3 py-2.5 rounded-lg text-sm font-medium text-fg hover:bg-surface-alt"
          data-testid="sheet-edit-match"
          @click="$emit('edit', match)"
        >
          Edit match
        </button>
      </div>
 
      <!-- Forensics. Off the row because they answer "where did this record
           come from", which is an admin's question about the data, not a
           reader's question about the match. -->
      <dl
        v-if="isAdmin"
        class="mt-4 pt-3 border-t border-line grid grid-cols-[auto,1fr] gap-x-3 gap-y-1.5 text-xs"
        data-testid="sheet-forensics"
      >
        <dt class="text-fg-muted">Competition</dt>
        <dd class="text-fg">{{ match.match_type_name || 'League' }}</dd>
 
        <dt class="text-fg-muted">Match ID</dt>
        <dd class="text-fg font-mono" data-testid="sheet-match-id">
          {{ match.match_id || '—' }}
        </dd>
 
        <dt class="text-fg-muted">Source</dt>
        <dd class="text-fg" data-testid="sheet-source">{{ sourceLabel }}</dd>
 
        <template v-if="match.updated_at">
          <dt class="text-fg-muted">Updated</dt>
          <dd class="text-fg">{{ updatedLabel }}</dd>
        </template>
      </dl>
    </div>
  </ModalOverlay>
</template>
 
<script setup>
import { computed } from 'vue';
import ModalOverlay from '../ui/ModalOverlay.vue';
import { formatDayHeading } from '../../utils/matchGrouping';
 
/**
 * Everything the compact match row stopped showing (SB-1101).
 *
 * Reached by long-pressing a row, or by the row's "⋯" button — the button
 * exists because a long press is invisible to a keyboard, a switch and a
 * screen reader, and undiscoverable even for a sighted user with a thumb.
 */
const props = defineProps({
  match: { type: Object, required: true },
  canEdit: { type: Boolean, default: false },
  isAdmin: { type: Boolean, default: false },
});
 
defineEmits(['close', 'view', 'edit']);
 
const fixture = computed(
  () =>
    `${props.match.away_team_name || 'TBD'} @ ${props.match.home_team_name || 'TBD'}`
);
 
const subtitle = computed(() => {
  const parts = [formatDayHeading(props.match.match_date)];
  if (props.match.age_group_name) parts.push(props.match.age_group_name);
  return parts.join(' · ');
});
 
const SOURCES = {
  manual: 'Manually entered',
  'match-scraper': 'Scraped from the official source',
  'match-scraper-agent': 'Scraped by the agent',
  'modular11-backfill': 'Backfilled from Modular11',
  import: 'Imported from backup',
};
 
/**
 * An unrecognised source shows the stored value rather than "Unknown source".
 * This row exists to answer "where did this record come from", and the raw
 * string answers it; the old wording hid it — and hid it for most of the
 * table, because `match-scraper-agent` and `modular11-backfill` were never in
 * this map.
 */
const sourceLabel = computed(() => {
  const source = props.match.source || 'manual';
  return SOURCES[source] || source;
});
 
const updatedLabel = computed(() => {
  const d = new Date(props.match.updated_at);
  return Number.isNaN(d.getTime()) ? '—' : d.toLocaleString();
});
</script>