Skip to content

Commit ffb1516

Browse files
authored
Merge pull request #3380 from frappe/version-16-hotfix
chore: merge 'version-16-hotfix' into 'version-16'
2 parents 38dcc21 + 4854f6c commit ffb1516

91 files changed

Lines changed: 12206 additions & 1778 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎e2e/batch_creation.spec.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ test.describe("Batch Creation", () => {
243243
.or(page.getByRole("tab"))
244244
.filter({ hasText: "Dashboard" })
245245
.click();
246-
// Exact: the empty dashboard also offers "Enroll Students".
247-
await button(page, /^Enroll$/).click();
246+
// A batch with no students shows only the empty state's Enroll students;
247+
// the header's Enroll appears once the dashboard has data.
248+
await button(page, /^Enroll students$/i).click();
248249
// The Enroll Students dialog picks students with a MultiSelect, the same
249250
// trigger + content-body search as the Instructors field above. Typing
250251
// the unique email narrows the results to the student made above.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<template>
2+
<div ref="bounds" class="w-full">
3+
<div
4+
v-if="height"
5+
dir="ltr"
6+
class="mx-auto overflow-hidden rounded shadow-sm"
7+
:style="{
8+
width: `${page.width * scale}px`,
9+
height: `${height * scale}px`,
10+
}"
11+
>
12+
<iframe
13+
sandbox=""
14+
class="origin-top-left border-0"
15+
:title="__('Preview of the report')"
16+
:srcdoc="reportDocument(html, page)"
17+
:style="{
18+
width: `${page.width}px`,
19+
height: `${height}px`,
20+
transform: `scale(${scale})`,
21+
}"
22+
/>
23+
</div>
24+
</div>
25+
</template>
26+
27+
<script setup lang="ts">
28+
import { computed, ref, useTemplateRef, watch } from 'vue'
29+
import { useElementSize } from '@vueuse/core'
30+
import { measureReport, reportDocument } from '@/utils/dashboard/export'
31+
import type { ReportPage } from '@/utils/dashboard/export'
32+
33+
const props = defineProps<{
34+
html: string
35+
page: ReportPage
36+
}>()
37+
38+
const { width: available } = useElementSize(useTemplateRef('bounds'))
39+
const height = ref<number>(0)
40+
const scale = computed<number>(() =>
41+
Math.min(1, available.value / props.page.width)
42+
)
43+
44+
// The frame that shows the report has no same origin, so it cannot be asked how
45+
// tall the report came out; a throwaway one that can be asked measures it first.
46+
watch(
47+
() => [props.html, props.page] as const,
48+
async ([html, page], _previous, onCleanup) => {
49+
let stale = false
50+
onCleanup(() => (stale = true))
51+
const measured = await measureReport(html, page)
52+
if (!stale) height.value = measured.height
53+
},
54+
{ immediate: true }
55+
)
56+
</script>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<template>
2+
<div class="w-max">
3+
<table
4+
class="table-fixed border-collapse bg-surface-base text-xs text-ink-gray-8"
5+
>
6+
<thead>
7+
<tr class="bg-surface-gray-2 text-ink-gray-6">
8+
<th scope="col" :class="[HEADING, 'w-9']">
9+
<span class="sr-only">{{ __('Row') }}</span>
10+
</th>
11+
<th
12+
v-for="letter in letters"
13+
:key="letter"
14+
scope="col"
15+
:class="[HEADING, 'w-32']"
16+
>
17+
{{ letter }}
18+
</th>
19+
</tr>
20+
</thead>
21+
<tbody>
22+
<tr v-for="(row, rowIndex) in sheet.rows" :key="rowIndex">
23+
<th
24+
scope="row"
25+
:class="[HEADING, 'bg-surface-gray-2 text-ink-gray-6']"
26+
>
27+
{{ rowIndex + 1 }}
28+
</th>
29+
<td
30+
v-for="cell in cells(row, rowIndex)"
31+
:key="cell.key"
32+
:colspan="cell.span"
33+
class="h-6 max-w-0 truncate border border-outline-gray-1 px-1.5"
34+
:class="{
35+
'font-semibold': rowIndex === 0,
36+
'text-end tabular-nums rtl:text-start':
37+
typeof cell.value === 'number',
38+
}"
39+
:title="String(cell.value ?? '')"
40+
>
41+
{{ cell.value }}
42+
</td>
43+
</tr>
44+
</tbody>
45+
</table>
46+
<p v-if="hiddenRows" class="mt-3 text-p-sm text-ink-gray-6">
47+
{{ __('And {0} more rows in the file.').format(String(hiddenRows)) }}
48+
</p>
49+
</div>
50+
</template>
51+
52+
<script setup lang="ts">
53+
import { computed } from 'vue'
54+
import type { AnalyticsPreviewSheet } from '@/types'
55+
56+
const props = defineProps<{
57+
sheet: AnalyticsPreviewSheet
58+
hiddenRows: number
59+
}>()
60+
61+
const HEADING =
62+
'h-6 border border-outline-gray-1 px-1.5 text-center font-normal tabular-nums'
63+
64+
const letters = computed<string[]>(() =>
65+
Array.from({ length: props.sheet.columns }, (_, column) =>
66+
String.fromCharCode(65 + column)
67+
)
68+
)
69+
70+
// Above the student table a row is shorter than the sheet. A spreadsheet lets
71+
// text in its last cell run over the empty ones beside it; a number stays in its
72+
// own, with the empty ones after it.
73+
function cells(row: AnalyticsPreviewSheet['rows'][number], rowIndex: number) {
74+
const { columns, header_row } = props.sheet
75+
if (rowIndex >= header_row)
76+
return row.map((value, key) => ({ key, value, span: 1 }))
77+
const filled = row.map((value, key) => ({ key, value, span: 1 }))
78+
const last = filled[filled.length - 1]
79+
if (typeof last?.value === 'string') last.span = columns - last.key
80+
else
81+
filled.push({
82+
key: filled.length,
83+
value: '',
84+
span: columns - filled.length,
85+
})
86+
return filled
87+
}
88+
</script>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template>
2+
<div v-if="first" class="flex items-center gap-2.5" aria-hidden="true">
3+
<Skeleton class="size-6 shrink-0 rounded-full" />
4+
<Skeleton class="h-2 w-28 rounded-full" />
5+
</div>
6+
<Skeleton v-else-if="!blank" class="h-2 w-12 rounded-full" />
7+
</template>
8+
<script setup lang="ts">
9+
import { Skeleton } from 'frappe-ui'
10+
11+
defineProps<{ first: boolean; blank?: boolean }>()
12+
</script>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<template>
2+
<EmptyStateLayout
3+
name="students"
4+
icon="lucide-users"
5+
:title="__('No students yet')"
6+
:description="description"
7+
>
8+
<Button
9+
variant="subtle"
10+
:label="__('Enroll students')"
11+
@click="emit('enroll')"
12+
>
13+
<template #prefix>
14+
<span class="lucide-plus size-4" />
15+
</template>
16+
</Button>
17+
</EmptyStateLayout>
18+
</template>
19+
<script setup lang="ts">
20+
import { Button } from 'frappe-ui'
21+
import EmptyStateLayout from '@/components/Layouts/EmptyStateLayout.vue'
22+
23+
defineProps<{
24+
description: string
25+
}>()
26+
27+
const emit = defineEmits<{
28+
enroll: []
29+
}>()
30+
</script>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<template>
2+
<div
3+
data-slot="dashboard-kpis"
4+
class="grid shrink-0 grid-cols-2 gap-5 md:grid-cols-4 lg:grid-cols-2 min-[1400px]:grid-cols-4"
5+
>
6+
<component
7+
:is="kpi.select ? 'button' : 'div'"
8+
v-for="kpi in kpis"
9+
:key="kpi.key"
10+
data-slot="dashboard-kpi"
11+
class="flex min-w-0 rounded-4 text-start"
12+
:class="kpi.select && cardClass(kpi.select.pressed)"
13+
:type="kpi.select ? 'button' : undefined"
14+
:aria-pressed="kpi.select ? kpi.select.pressed : undefined"
15+
:title="kpi.select?.label"
16+
@click="kpi.select?.onSelect()"
17+
>
18+
<NumberCard
19+
:title="kpi.title"
20+
:value="kpi.value"
21+
:color="kpi.color"
22+
:suffix="kpi.suffix"
23+
:target="kpi.target"
24+
:format="kpi.format"
25+
:loading="loading"
26+
:delta="kpi.delta || null"
27+
:delta-suffix="kpi.deltaSuffix"
28+
:delta-format="kpi.deltaFormat"
29+
:delta-caption="kpi.delta ? lastMonth : kpi.fallbackCaption"
30+
:negative-is-better="kpi.negativeIsBetter"
31+
:sparkline="kpi.sparkline"
32+
>
33+
<template v-if="$slots[`empty-${kpi.key}`]" #empty>
34+
<slot :name="`empty-${kpi.key}`" :kpi="kpi" />
35+
</template>
36+
</NumberCard>
37+
</component>
38+
</div>
39+
</template>
40+
<script setup lang="ts">
41+
import { NumberCard } from 'frappe-ui/charts'
42+
import { computed } from 'vue'
43+
import type { DashboardKpi } from '@/types'
44+
45+
defineProps<{
46+
kpis: DashboardKpi[]
47+
loading: boolean
48+
}>()
49+
50+
const lastMonth = computed<string>(() => __('vs last month'))
51+
52+
// A pressed card takes the focus look of a text input.
53+
const FOCUSED = '[&>*]:!border-outline-gray-4 [&>*]:shadow-sm'
54+
55+
const cardClass = (pressed: boolean): string[] => [
56+
'cursor-pointer touch-manipulation outline-none',
57+
'focus-visible:[&>*]:!border-outline-gray-4 focus-visible:[&>*]:shadow-sm',
58+
'[@media(hover:hover)]:hover:[&>*]:!border-outline-gray-3',
59+
pressed ? FOCUSED : '',
60+
]
61+
</script>

0 commit comments

Comments
 (0)