|
| 1 | +<template> |
| 2 | + <section |
| 3 | + class="flex min-w-0 shrink-0 grow flex-col bg-surface-gray-1 md:min-h-0 md:flex-1 md:shrink" |
| 4 | + :aria-label="__('Preview')" |
| 5 | + > |
| 6 | + <header class="shrink-0 pb-3 pe-14 ps-6 pt-6" aria-live="polite"> |
| 7 | + <h3 class="text-base font-semibold text-ink-gray-8"> |
| 8 | + {{ __('Preview') }} |
| 9 | + </h3> |
| 10 | + <p class="mt-1 min-h-5 text-p-sm text-ink-gray-6"> |
| 11 | + {{ summary }} |
| 12 | + </p> |
| 13 | + </header> |
| 14 | + <div |
| 15 | + v-if="showsContent" |
| 16 | + class="min-h-0 flex-1 overflow-auto overscroll-contain px-6 pb-6 [scrollbar-gutter:stable]" |
| 17 | + tabindex="0" |
| 18 | + :aria-label="__('Preview of the export')" |
| 19 | + role="group" |
| 20 | + > |
| 21 | + <AnalyticsSheetPreview |
| 22 | + v-if="preview?.sheet" |
| 23 | + :sheet="preview.sheet" |
| 24 | + :hidden-rows="preview.students - preview.shown" |
| 25 | + /> |
| 26 | + <AnalyticsReportFrame |
| 27 | + v-else-if="preview?.html" |
| 28 | + :html="preview.html" |
| 29 | + :page="reportPage(format)" |
| 30 | + /> |
| 31 | + </div> |
| 32 | + <div |
| 33 | + v-else-if="loading" |
| 34 | + class="flex min-h-64 flex-1 flex-col gap-3 px-6 pb-6" |
| 35 | + role="status" |
| 36 | + :aria-label="__('Loading preview')" |
| 37 | + > |
| 38 | + <div |
| 39 | + v-for="row in 8" |
| 40 | + :key="row" |
| 41 | + class="flex items-center gap-4" |
| 42 | + aria-hidden="true" |
| 43 | + > |
| 44 | + <Skeleton class="h-2 w-6 shrink-0 rounded-full" /> |
| 45 | + <Skeleton |
| 46 | + class="h-2 rounded-full" |
| 47 | + :class="row === 1 ? 'w-40' : 'w-32'" |
| 48 | + /> |
| 49 | + <Skeleton class="h-2 w-24 rounded-full" /> |
| 50 | + <Skeleton class="h-2 w-16 rounded-full" /> |
| 51 | + </div> |
| 52 | + </div> |
| 53 | + <LoadError |
| 54 | + v-else-if="error" |
| 55 | + compact |
| 56 | + :error="failure ?? { name: 'Error' }" |
| 57 | + @retry="emit('retry')" |
| 58 | + /> |
| 59 | + <EmptyStateLayout |
| 60 | + v-else-if="preview" |
| 61 | + name="Students" |
| 62 | + width="lg" |
| 63 | + icon="lucide-users" |
| 64 | + :title="__('No students in this time frame')" |
| 65 | + :description="__('Pick a wider time frame to have something to export.')" |
| 66 | + /> |
| 67 | + <EmptyStateLayout |
| 68 | + v-else |
| 69 | + name="Preview" |
| 70 | + width="lg" |
| 71 | + icon="lucide-calendar" |
| 72 | + :title="__('Pick a date range')" |
| 73 | + :description=" |
| 74 | + __('Choose both days, in order, to see what the export will hold.') |
| 75 | + " |
| 76 | + /> |
| 77 | + </section> |
| 78 | +</template> |
| 79 | + |
| 80 | +<script setup lang="ts"> |
| 81 | +import { computed } from 'vue' |
| 82 | +import { Skeleton } from 'frappe-ui' |
| 83 | +import AnalyticsReportFrame from '@/components/Dashboard/AnalyticsReportFrame.vue' |
| 84 | +import AnalyticsSheetPreview from '@/components/Dashboard/AnalyticsSheetPreview.vue' |
| 85 | +import EmptyStateLayout from '@/components/Layouts/EmptyStateLayout.vue' |
| 86 | +import LoadError from '@/components/LoadError.vue' |
| 87 | +import { reportPage } from '@/utils/dashboard/export' |
| 88 | +import type { AnalyticsFormat, AnalyticsPreview } from '@/types' |
| 89 | +
|
| 90 | +const props = defineProps<{ |
| 91 | + format: AnalyticsFormat |
| 92 | + preview: AnalyticsPreview | null |
| 93 | + loading: boolean |
| 94 | + error: string |
| 95 | + failure?: { name?: string; status?: number; exc_type?: string } | null |
| 96 | +}>() |
| 97 | +
|
| 98 | +const emit = defineEmits<{ |
| 99 | + retry: [] |
| 100 | +}>() |
| 101 | +
|
| 102 | +const showsContent = computed<boolean>(() => Boolean(props.preview?.students)) |
| 103 | +
|
| 104 | +const summary = computed<string>(() => { |
| 105 | + if (!props.preview) return '' |
| 106 | + const { students, shown } = props.preview |
| 107 | + const count = |
| 108 | + students === 1 |
| 109 | + ? __('1 student in this export.') |
| 110 | + : __('{0} students in this export.').format(String(students)) |
| 111 | + if (shown === students) return count |
| 112 | + const cap = |
| 113 | + props.format === 'png' |
| 114 | + ? __('The image stops at {0}.').format(String(shown)) |
| 115 | + : __('Showing the first {0}, the file has them all.').format( |
| 116 | + String(shown) |
| 117 | + ) |
| 118 | + return `${count} ${cap}` |
| 119 | +}) |
| 120 | +</script> |
0 commit comments