All files / src/components AdminFlowsPanel.vue

100% Statements 16/16
100% Branches 26/26
100% Functions 5/5
100% Lines 14/14

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  15x 2x   2x                                                                 2x                 7x     2x                                           1x                                   13x 13x 13x       13x 1x           1x     13x    
<template>
  <div class="admin-flows-panel">
    <p class="text-muted">{{ t('admin.flowsDirectoryDescription') }}</p>
 
    <div class="mb-3">
      <label for="admin-flows-search" class="visually-hidden">{{ t('common.search') }}</label>
      <input
        id="admin-flows-search"
        :value="searchQuery"
        type="search"
        class="form-control"
        :placeholder="t('admin.searchFlowsPlaceholder')"
        @input="onSearchInput"
      />
    </div>
 
    <ErrorAlert
      v-if="adminStore.platformFlows.error"
      :title="t('common.error')"
      :message="adminStore.platformFlows.error"
    />
    <LoadingSpinner v-if="adminStore.platformFlows.loading" />
 
    <template v-else-if="!adminStore.platformFlows.error">
      <div v-if="adminStore.platformFlows.truncated" class="alert alert-warning">
        {{ t('admin.searchTruncated') }}
      </div>
 
      <p v-if="adminStore.platformFlows.items.length === 0" class="text-muted">
        <!-- A search reads a bounded number of candidates per request, so an empty page
             with a cursor means "nothing yet", not "nothing" -->
        {{
          adminStore.platformFlows.nextCursor ? t('admin.noMatchesYet') : t('admin.noFlowsFound')
        }}
      </p>
 
      <div v-else class="table-responsive">
        <table class="table table-hover align-middle">
          <thead>
            <tr>
              <th>{{ t('admin.colFlow') }}</th>
              <th>{{ t('admin.colOwner') }}</th>
              <th>{{ t('admin.colCreated') }}</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="flow in adminStore.platformFlows.items" :key="flow.id">
              <td>
                <strong>{{ flow.name }}</strong>
                <div class="text-muted small">{{ flow.slug }}</div>
              </td>
              <td>
                <template v-if="flow.ownerName || flow.ownerEmail">
                  {{ flow.ownerName || flow.ownerEmail }}
                  <div v-if="flow.ownerName && flow.ownerEmail" class="text-muted small">
                    {{ flow.ownerEmail }}
                  </div>
                </template>
                <span v-else class="text-muted">—</span>
              </td>
              <td>{{ formatDate(flow.createdAt) || '—' }}</td>
            </tr>
          </tbody>
        </table>
      </div>
 
      <button
        v-if="adminStore.platformFlows.nextCursor"
        type="button"
        class="btn btn-outline-secondary"
        :disabled="adminStore.platformFlows.loadingMore"
        @click="adminStore.platformFlows.loadMore()"
      >
        {{ t('admin.loadMore') }}
      </button>
    </template>
  </div>
</template>
 
<script setup lang="ts">
// @implements UC-ADMIN-006.1
import { onMounted } from 'vue'
import { useAdminStore } from '@/stores/admin'
import { useUILanguage } from '@/composables/useUILanguage'
import { useDateFormat } from '@/composables/useDateFormat'
import { useDebouncedSearch } from '@/composables/useDebouncedSearch'
import LoadingSpinner from '@/components/LoadingSpinner.vue'
import ErrorAlert from '@/components/ErrorAlert.vue'
 
const adminStore = useAdminStore()
const { t } = useUILanguage()
const { formatDate } = useDateFormat()
 
// Unlike the Credits picker there is no minimum length: clearing the box goes
// back to the unfiltered list.
const { searchQuery, scheduleSearch } = useDebouncedSearch(
  (query) => adminStore.platformFlows.load(query),
  300,
  { auto: false }
)
 
function onSearchInput(event: Event) {
  scheduleSearch((event.target as HTMLInputElement).value)
}
 
onMounted(() => adminStore.platformFlows.load())
</script>