@nuxtseo/pro-indexing 0.0.0-stage → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,204 @@
1
+ <script setup lang="ts">
2
+ import type { IndexingStackBucket, IndexingWindow } from '@gscdump/sdk/indexing'
3
+ import type { UiStatProps } from '@nuxtseo/design-system/app/shared/stat'
4
+ import type { IndexingPortfolioEntry } from '../../shared/portfolio'
5
+ import { indexingWindowNote } from '@gscdump/sdk/indexing'
6
+ import { DISPLAY_LOCALE, formatNumber } from '@nuxtseo/design-system/app/composables/formatting'
7
+ import { computed } from 'vue'
8
+ import { UiAlert, UiButton, UiEmptyState, UiStat, UiStats, UiTopEntityStackChart } from '#components'
9
+ import { portfolioFetchState } from '../../shared/portfolio'
10
+ import { buildPortfolioOverview } from '../../shared/portfolio-overview'
11
+ import { useIndexingSource } from '../composables/useIndexingSource'
12
+ import { useProIndexingCopy } from '../composables/useProIndexingCopy'
13
+
14
+ // Portfolio Overview: the tiles and the not-indexed stack over one Portfolio
15
+ // scope. The per-Site rows stay in the site's own Site list, which reads the
16
+ // same model (`buildPortfolioOverview`). The Sitemap problems tile needs the
17
+ // `sitemapProblems` capability.
18
+
19
+ const { entries, window } = defineProps<{
20
+ entries: readonly IndexingPortfolioEntry[]
21
+ window: IndexingWindow
22
+ }>()
23
+
24
+ const emit = defineEmits<{
25
+ /** Retry the indexing reads of the failed Sites, by Site id. */
26
+ retry: [siteIds: string[]]
27
+ }>()
28
+
29
+ const copy = useProIndexingCopy()
30
+ const source = useIndexingSource()
31
+ const sitemapRead = source?.sitemapProblems?.() ?? null
32
+
33
+ const fetchState = computed(() => portfolioFetchState(entries, copy.common))
34
+ const model = computed(() => buildPortfolioOverview(entries, window))
35
+ const hasGsc = computed(() => entries.some(entry => entry.site.dataId !== null))
36
+ const windowNote = computed(() => indexingWindowNote(window, entries.map(entry => entry.trend)))
37
+
38
+ type RateHealth = 'ok' | 'warning' | 'error'
39
+ function rateHealth(percent: number): RateHealth {
40
+ if (percent >= 80)
41
+ return 'ok'
42
+ return percent >= 50 ? 'warning' : 'error'
43
+ }
44
+ const rateTextClass: Record<RateHealth, string> = { ok: 'text-default', warning: 'text-warning', error: 'text-error' }
45
+
46
+ // The rollup counts only this scope's linked Sites. A failed read is unknown, never zero.
47
+ const sitemapError = computed(() => sitemapRead?.error.value ?? null)
48
+ const sitemapProblemCount = computed(() => {
49
+ if (!sitemapRead || sitemapError.value)
50
+ return null
51
+ const problems = sitemapRead.data.value
52
+ const unreachable = new Set(problems?.unreachable ?? [])
53
+ const errors = new Set(problems?.errors ?? [])
54
+ return entries.filter(entry => entry.site.dataId !== null && (unreachable.has(entry.site.id) || errors.has(entry.site.id))).length
55
+ })
56
+
57
+ const hasNotIndexedStack = computed(() => model.value.stack.series.length > 1)
58
+
59
+ // The stack carries each Site's last known value forward, so this total does
60
+ // not dip on a day one Site skipped.
61
+ const notIndexedSparkline = computed(() => {
62
+ const { buckets, series } = model.value.stack
63
+ return buckets.map((bucket, i) => ({ x: bucket.end, value: series.reduce((sum, entry) => sum + (entry.values[i] ?? 0), 0) }))
64
+ })
65
+
66
+ // A partial total has no sparkline: the series sums only the Sites that loaded,
67
+ // or starts after the window does. The tile shows the note in that band instead.
68
+ const tileNote = computed(() => fetchState.value.partialTotalsNote ?? windowNote.value)
69
+ function statSparkline(points: { x: string, value: number }[]) {
70
+ return points.length > 1 && !tileNote.value ? points : undefined
71
+ }
72
+
73
+ const loading = computed(() => fetchState.value.isPending && !fetchState.value.hasCoverage)
74
+
75
+ const stats = computed<UiStatProps[]>(() => {
76
+ const { indexed, notIndexed, crawlErrors, trend, indexedChange } = model.value
77
+ const out: UiStatProps[] = [
78
+ {
79
+ title: copy.overview.indexedTitle,
80
+ icon: 'check-circle',
81
+ tooltip: copy.overview.indexedTooltip,
82
+ value: indexed ? `${indexed.percent.toFixed(0)}%` : null,
83
+ valueClass: indexed ? rateTextClass[rateHealth(indexed.percent)] : undefined,
84
+ trend: indexedChange,
85
+ trendSuffix: copy.overview.trendSuffix,
86
+ sparkline: statSparkline(trend.map(point => ({ x: point.date, value: point.indexedPercent }))),
87
+ loading: loading.value,
88
+ },
89
+ {
90
+ title: copy.overview.notIndexedTitle,
91
+ icon: 'caution',
92
+ tooltip: copy.overview.notIndexedTooltip,
93
+ value: notIndexed == null ? null : formatNumber(notIndexed),
94
+ sparkline: statSparkline(notIndexedSparkline.value),
95
+ loading: loading.value,
96
+ },
97
+ {
98
+ title: copy.overview.crawlErrorsTitle,
99
+ icon: 'warning',
100
+ tooltip: copy.overview.crawlErrorsTooltip,
101
+ value: crawlErrors == null ? null : formatNumber(crawlErrors),
102
+ valueClass: crawlErrors ? 'text-warning' : undefined,
103
+ sparkline: statSparkline(trend.map(point => ({ x: point.date, value: point.errors }))),
104
+ loading: loading.value,
105
+ },
106
+ ]
107
+ if (sitemapRead) {
108
+ out.push({
109
+ title: copy.overview.sitemapProblemsTitle,
110
+ icon: 'file-search',
111
+ tooltip: sitemapError.value ? copy.overview.sitemapProblemsFailedTooltip : copy.overview.sitemapProblemsTooltip,
112
+ value: sitemapProblemCount.value,
113
+ valueClass: sitemapProblemCount.value ? 'text-warning' : undefined,
114
+ loading: sitemapRead.status.value === 'pending' || sitemapRead.status.value === 'idle',
115
+ })
116
+ }
117
+ return out
118
+ })
119
+
120
+ const stackDateFormat = new Intl.DateTimeFormat(DISPLAY_LOCALE, { month: 'short', day: 'numeric', timeZone: 'UTC' })
121
+ function stackBucketLabel(bucket: IndexingStackBucket): string {
122
+ const date = new Date(`${bucket.start}T00:00:00Z`)
123
+ return Number.isNaN(date.getTime()) ? bucket.start : stackDateFormat.format(date)
124
+ }
125
+
126
+ const showCollecting = computed(() => hasGsc.value && !fetchState.value.hasCoverage && !fetchState.value.isPending && !fetchState.value.failed.length)
127
+ const showFigures = computed(() => entries.length > 0 && (fetchState.value.hasCoverage || fetchState.value.isPending))
128
+ // With nothing to show the section renders no element, so it adds no gap to
129
+ // the parent stack.
130
+ const visible = computed(() => fetchState.value.failed.length > 0 || showCollecting.value || showFigures.value)
131
+
132
+ function retryFailed() {
133
+ emit('retry', fetchState.value.failed.map(entry => entry.site.id))
134
+ }
135
+ </script>
136
+
137
+ <template>
138
+ <div v-if="visible" class="space-y-4" data-pro-indexing-section="portfolio-overview">
139
+ <UiAlert
140
+ v-if="fetchState.failed.length"
141
+ status="error"
142
+ icon="caution"
143
+ :title="copy.common.failedTitle"
144
+ :description="fetchState.errorDescription ?? undefined"
145
+ >
146
+ <template #action>
147
+ <UiButton purpose="secondary" size="xs" class="min-h-11 sm:min-h-7" @click="retryFailed">
148
+ {{ copy.common.retry }}
149
+ </UiButton>
150
+ </template>
151
+ </UiAlert>
152
+
153
+ <UiEmptyState
154
+ v-if="showCollecting"
155
+ icon="file-search"
156
+ :title="copy.common.collectingTitle"
157
+ :description="copy.common.collectingBody"
158
+ />
159
+
160
+ <template v-else-if="showFigures">
161
+ <UiStats :data="stats" variant="cards">
162
+ <template #default="{ item }">
163
+ <UiStat v-bind="item" card :trend-colored="item.trendColored ?? true">
164
+ <!-- UiStat has no error state, so a failed Sitemap read says so here
165
+ and offers the retry. A failed read is unknown, never zero. -->
166
+ <template v-if="item.title === copy.overview.sitemapProblemsTitle && sitemapError" #info>
167
+ <span class="relative z-10 flex flex-wrap items-center gap-x-2 gap-y-1">
168
+ <span class="text-xs text-error">{{ copy.overview.sitemapProblemsFailed }}</span>
169
+ <UiButton purpose="secondary" size="xs" class="min-h-11 sm:min-h-7" @click="sitemapRead?.refresh()">
170
+ {{ copy.common.retry }}
171
+ </UiButton>
172
+ </span>
173
+ </template>
174
+ <!-- The partial tiles drop their sparkline, so this note never sits on it. -->
175
+ <template v-else-if="item.title !== copy.overview.sitemapProblemsTitle && tileNote" #info>
176
+ <span class="relative z-10 text-xs text-muted">{{ tileNote }}</span>
177
+ </template>
178
+ </UiStat>
179
+ </template>
180
+ </UiStats>
181
+
182
+ <div v-if="hasNotIndexedStack || (fetchState.isPending && entries.length > 1)" class="min-w-0 space-y-1.5">
183
+ <div class="flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1">
184
+ <p class="text-xs text-muted">
185
+ {{ copy.overview.stackTitle }}
186
+ </p>
187
+ <p v-if="windowNote" class="text-xs text-muted">
188
+ {{ windowNote }}
189
+ </p>
190
+ </div>
191
+ <UiTopEntityStackChart
192
+ :buckets="model.stack.buckets"
193
+ :series="model.stack.series"
194
+ scale="absolute"
195
+ :loading="!hasNotIndexedStack"
196
+ :height="200"
197
+ :legend-slots="6"
198
+ :format="formatNumber"
199
+ :x-format="stackBucketLabel"
200
+ />
201
+ </div>
202
+ </template>
203
+ </div>
204
+ </template>
@@ -0,0 +1,123 @@
1
+ <script setup lang="ts">
2
+ import type { IndexingWindowReading } from '@gscdump/sdk/indexing'
3
+ import type { IndexingPortfolioEntry } from '../../shared/portfolio'
4
+ import { getSiteIndexingIssues } from '@gscdump/sdk/indexing'
5
+ import { formatGroupedNumber, formatNumber } from '@nuxtseo/design-system/app/composables/formatting'
6
+ import { fillCopy } from '@nuxtseo/pro-shell/shared/copy'
7
+ import { computed } from 'vue'
8
+ import { NuxtLink, UiAlert, UiButton, UiSkeleton, UiTableShell, UiTableTd, UiTableTh } from '#components'
9
+ import { hasCoverageObservation } from '../../shared/portfolio'
10
+ import { indexingIssueQuery } from '../../shared/routes'
11
+ import { useProIndexingCopy } from '../composables/useProIndexingCopy'
12
+ import { useProIndexingRoute } from '../composables/useProIndexingRoute'
13
+
14
+ // One Site's issue breakdown at the window end: the Portfolio Overview row
15
+ // detail. Each row links to the Site's URLs list filtered to that issue.
16
+
17
+ const { entry, reading } = defineProps<{
18
+ entry: IndexingPortfolioEntry
19
+ /** The Site's reading at the window end, from `buildPortfolioOverview`. */
20
+ reading: IndexingWindowReading | null
21
+ }>()
22
+
23
+ const emit = defineEmits<{ retry: [siteId: string] }>()
24
+
25
+ const copy = useProIndexingCopy()
26
+ const route = useProIndexingRoute()
27
+
28
+ const issues = computed(() => getSiteIndexingIssues(reading?.point))
29
+ const loading = computed(() => entry.read._tag === 'loading' || (!reading && entry.read._tag === 'idle'))
30
+
31
+ // An empty breakdown has three causes and only one of them is a clean bill.
32
+ const emptyReason = computed(() => {
33
+ if (!reading?.point || !hasCoverageObservation(reading))
34
+ return copy.siteIssues.emptyNoObservation
35
+ const unindexed = Math.max(0, reading.totalUrls - reading.indexed)
36
+ if (unindexed === 0)
37
+ return copy.siteIssues.emptyAllIndexed
38
+ return fillCopy(unindexed === 1 ? copy.siteIssues.emptyUnattributedOne : copy.siteIssues.emptyUnattributedMany, { count: formatGroupedNumber(unindexed) })
39
+ })
40
+ const hasUnexplainedUrls = computed(() => !!reading && reading.totalUrls - reading.indexed > 0)
41
+ const reportTo = computed(() => route.site('siteIndexing', entry.site.ref))
42
+
43
+ function issueTo(filter: { key: 'issue' | 'facet', value: string }) {
44
+ return route.site('siteIndexingUrls', entry.site.ref, indexingIssueQuery(filter))
45
+ }
46
+ </script>
47
+
48
+ <template>
49
+ <UiAlert
50
+ v-if="entry.read._tag === 'failed'"
51
+ status="error"
52
+ icon="caution"
53
+ :title="copy.common.failedTitle"
54
+ :description="fillCopy(copy.siteIssues.failedBody, { site: entry.site.label })"
55
+ data-pro-indexing-section="site-issues"
56
+ >
57
+ <template #action>
58
+ <UiButton purpose="secondary" size="xs" class="min-h-11 sm:min-h-7" @click="emit('retry', entry.site.id)">
59
+ {{ copy.common.retry }}
60
+ </UiButton>
61
+ </template>
62
+ </UiAlert>
63
+ <div v-else-if="loading" class="space-y-2" aria-busy="true" data-pro-indexing-section="site-issues">
64
+ <UiSkeleton v-for="i in 3" :key="i" type="block" class="h-8 w-full" />
65
+ </div>
66
+ <UiTableShell
67
+ v-else-if="issues.length"
68
+ size="xs"
69
+ bordered
70
+ row-hover
71
+ :label="fillCopy(copy.siteIssues.tableLabel, { site: entry.site.label })"
72
+ data-pro-indexing-section="site-issues"
73
+ >
74
+ <template #head>
75
+ <UiTableTh>{{ copy.siteIssues.issue }}</UiTableTh>
76
+ <UiTableTh numeric>
77
+ {{ copy.siteIssues.count }}
78
+ </UiTableTh>
79
+ <UiTableTh align="right">
80
+ <span class="sr-only">{{ copy.siteIssues.action }}</span>
81
+ </UiTableTh>
82
+ </template>
83
+ <tr v-for="iss in issues" :key="iss.id">
84
+ <UiTableTd size="xs" row-header class="text-muted">
85
+ {{ iss.label }}
86
+ </UiTableTd>
87
+ <UiTableTd
88
+ size="xs"
89
+ numeric
90
+ :class="iss.count > 0 ? 'text-warning font-medium' : 'text-dimmed'"
91
+ >
92
+ {{ formatNumber(iss.count) }}
93
+ </UiTableTd>
94
+ <UiTableTd size="xs" align="right">
95
+ <UiButton
96
+ v-if="issueTo(iss.filter)"
97
+ :to="issueTo(iss.filter)!"
98
+ purpose="secondary"
99
+ size="xs"
100
+ trailing-icon="next"
101
+ class="min-h-11 sm:min-h-7"
102
+ :aria-label="fillCopy(copy.common.fixIssuesLabel, { issue: iss.label.toLowerCase(), site: entry.site.label })"
103
+ >
104
+ {{ copy.common.fixIssues }}
105
+ </UiButton>
106
+ </UiTableTd>
107
+ </tr>
108
+ </UiTableShell>
109
+ <!-- Empty is not one state: fully indexed, not yet synced, and "unindexed
110
+ with no attributed reason" are different answers and only the last one
111
+ is worth opening the site report for. -->
112
+ <p v-else class="text-xs text-dimmed px-1 max-w-2xl" data-pro-indexing-section="site-issues">
113
+ {{ emptyReason }}
114
+ <NuxtLink
115
+ v-if="hasUnexplainedUrls && reportTo"
116
+ :to="reportTo"
117
+ class="text-primary hover:underline"
118
+ @click.stop
119
+ >
120
+ {{ copy.siteIssues.openReport }}
121
+ </NuxtLink>
122
+ </p>
123
+ </template>