@nuxtseo/pro-search 0.0.0-stage → 0.1.11

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.
package/README.md CHANGED
@@ -1,3 +1,8 @@
1
- # Temporary Holding Version
1
+ # Pro Search
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Install `@nuxtseo/pro-search` with its design system peer. Add the package to the host Nuxt config's `extends`.
4
+
5
+ - Use `SearchConsoleTrend.vue` from `@nuxtseo/pro-search/components/` for daily Search Console metrics and comparison overlays. Pass the current and previous series and the requested date range. A host can provide a connection link and a classified read failure.
6
+ - Use `RankedSearchTable.vue` and `RankedSearchRow.vue` from `@nuxtseo/pro-search/components/` for the ranked Search Console cards. Pass Top, Rising, and Falling rows. The row slot supplies the label and any host links or query variants.
7
+ - Use `BingSearchPerformance.vue` from the same path for the Bing traffic chart and ranked Pages and Keywords. Pass the traffic response and the current breakdown response. Bind `entityKind` and `page` and handle `retry` to drive the host reads. Use `BING_PERFORMANCE_PAGE_SIZE` when requesting breakdown rows.
8
+ - Import labels, icons, and Webmaster Tools tabs from `@nuxtseo/pro-search/shared/navigation`. The host owns its routes, access checks, and data reads.
@@ -0,0 +1,201 @@
1
+ <script setup lang="ts">
2
+ import type { BingDataV1 } from '@gscdump/contracts/v1/http'
3
+ import type { BingEntityKind } from '../../shared/bing-performance'
4
+ import { gscMetricColors } from '@nuxtseo/design-system/app/composables/dataVizColors'
5
+ import { computed, ref, watch } from 'vue'
6
+ import { UiAlert, UiDataTableSection, UiEmptyState, UiIcon, UiLineChart, UiMetricStat, UiMetricToggle, UiRelativeTime, UiSectionHeader, UiTableMetricCell, UiTablePathCell, UiTableShell, UiTableTd, UiTableTh, UiTogglePill } from '#components'
7
+ import { BING_PERFORMANCE_PAGE_SIZE, bingTrafficTotals, formatBingCtr, formatBingNumber, formatBingReportingDay } from '../../shared/bing-performance'
8
+
9
+ const { data, startDate, endDate, entities, pending, error, view } = defineProps<{
10
+ data: Extract<BingDataV1, { dataset: 'traffic' }> | null
11
+ startDate: string
12
+ endDate: string
13
+ entities: BingDataV1 | null
14
+ pending: boolean
15
+ error: boolean
16
+ view?: 'overview' | 'queries' | 'pages'
17
+ }>()
18
+ const emit = defineEmits<{ retry: [] }>()
19
+ const entityKind = defineModel<BingEntityKind>('entityKind', { required: true })
20
+ const page = defineModel<number>('page', { required: true })
21
+
22
+ const metrics = ref(['clicks', 'impressions'])
23
+ const metricOptions = [
24
+ { key: 'clicks', label: 'Clicks', color: 'blue' },
25
+ { key: 'impressions', label: 'Impressions', color: 'purple' },
26
+ ] as const
27
+ // The chips are the chart legend, so each line draws in its chip's identity colour.
28
+ const chartSeries = computed(() => metricOptions
29
+ .filter(option => metrics.value.includes(option.key))
30
+ .map(option => ({ key: option.key, label: option.label, color: gscMetricColors[option.key].color })))
31
+ const totals = computed(() => bingTrafficTotals(data?.rows ?? []))
32
+ const lastCollection = computed(() => {
33
+ const sync = (view === 'pages' || view === 'queries' ? entities : data)?.sync
34
+ return sync && sync._tag !== 'missing' ? sync.observedAt : null
35
+ })
36
+ const unavailable = computed(() => data?.sync._tag === 'unavailable' || entities?.sync._tag === 'unavailable')
37
+ const entityTitle = computed(() => {
38
+ if (entityKind.value === 'pages')
39
+ return 'Top Pages'
40
+ return view === 'queries' ? 'Top Queries' : 'Top Keywords'
41
+ })
42
+
43
+ interface EntityRow extends Record<string, unknown> {
44
+ key: string
45
+ label: string
46
+ date: string
47
+ url: string | null
48
+ clicks: number
49
+ impressions: number
50
+ averagePosition: number | null
51
+ }
52
+
53
+ const entityOptions = [
54
+ { label: 'Pages', value: 'pages' as const },
55
+ { label: 'Keywords', value: 'keywords' as const },
56
+ ]
57
+ const visibleRows = computed<EntityRow[]>(() => {
58
+ const result = entities
59
+ if (result?.dataset !== entityKind.value)
60
+ return []
61
+ if (result.dataset === 'pages')
62
+ return result.rows.map(row => ({ key: `${row.date}:${row.page}`, date: row.date, label: row.page, url: row.page, clicks: row.clicks, impressions: row.impressions, averagePosition: row.averageImpressionPosition }))
63
+ if (result?.dataset === 'keywords')
64
+ return result.rows.map(row => ({ key: `${row.date}:${row.keyword}`, date: row.date, label: row.keyword, url: null, clicks: row.clicks, impressions: row.impressions, averagePosition: row.averageImpressionPosition }))
65
+ return []
66
+ })
67
+ const totalRows = computed(() => entities?.pagination.total ?? 0)
68
+ watch(entityKind, () => { page.value = 1 })
69
+ watch(() => entities, (result) => {
70
+ if (result && result.dataset === entityKind.value)
71
+ page.value = Math.min(page.value, Math.max(1, Math.ceil(result.pagination.total / BING_PERFORMANCE_PAGE_SIZE)))
72
+ })
73
+
74
+ function rowCtr(row: EntityRow): string {
75
+ return formatBingCtr(row.impressions === 0 ? 0 : row.clicks / row.impressions)
76
+ }
77
+ </script>
78
+
79
+ <template>
80
+ <div class="flex flex-col gap-6" data-testid="bing-search-performance">
81
+ <UiAlert
82
+ v-if="unavailable"
83
+ status="warning"
84
+ title="Some Bing data is delayed"
85
+ description="The last successful collection stays visible while the next daily sync retries."
86
+ />
87
+
88
+ <template v-if="data && (!view || view === 'overview')">
89
+ <div role="group" aria-label="Bing Search Performance filters" class="flex min-w-0 flex-col gap-2">
90
+ <span class="inline-flex items-center gap-1.5 text-xs text-muted">
91
+ <UiIcon name="calendar" class="size-3.5 shrink-0 text-dimmed" aria-hidden="true" />
92
+ {{ startDate }} to {{ endDate }}
93
+ </span>
94
+ <UiMetricToggle v-if="data.rows.length" v-model="metrics" :options="[...metricOptions]" chip :colors="gscMetricColors" />
95
+ </div>
96
+
97
+ <div class="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
98
+ <UiSectionHeader
99
+ title="Bing Search Performance"
100
+ tooltip="Bing reports total traffic across its search surfaces. It does not provide a separate Chat source."
101
+ />
102
+ <div v-if="lastCollection" class="text-xs text-muted">
103
+ Collected <UiRelativeTime :date="lastCollection" />
104
+ </div>
105
+ </div>
106
+
107
+ <UiEmptyState v-if="!data.rows.length && !unavailable" icon="search" title="No Bing traffic in this date range" :description="view ? undefined : 'Pages and Keywords can still have data below.'" />
108
+
109
+ <div v-if="data.rows.length" class="flex flex-wrap gap-x-6 gap-y-3 rounded-xl border border-default bg-elevated/30 px-4 py-3">
110
+ <UiMetricStat :value="formatBingNumber(totals.clicks)" label="clicks" />
111
+ <UiMetricStat :value="formatBingNumber(totals.impressions)" label="impressions" />
112
+ <UiMetricStat :value="formatBingCtr(totals.ctr)" label="CTR" />
113
+ </div>
114
+
115
+ <div v-if="data.rows.length" class="rounded-xl border border-default bg-default p-4">
116
+ <h3 class="mb-3 text-sm font-strong text-highlighted">
117
+ Traffic over time
118
+ </h3>
119
+ <UiLineChart
120
+ :data="data.rows"
121
+ x-key="date"
122
+ :series="chartSeries"
123
+ :height="220"
124
+ :x-format="value => formatBingReportingDay(String(value))"
125
+ :y-format="value => formatBingNumber(value)"
126
+ />
127
+ </div>
128
+ </template>
129
+
130
+ <template v-if="view !== 'overview'">
131
+ <div class="flex items-center justify-between gap-3">
132
+ <UiSectionHeader
133
+ :title="entityTitle"
134
+ tooltip="Bing updates its top Pages and Keywords data weekly."
135
+ />
136
+ <UiTogglePill v-if="!view" v-model="entityKind" :options="entityOptions" label="Bing breakdown" />
137
+ <div v-else-if="lastCollection" class="text-xs text-muted">
138
+ Collected <UiRelativeTime :date="lastCollection" />
139
+ </div>
140
+ </div>
141
+
142
+ <UiDataTableSection
143
+ v-model:page="page"
144
+ :rows="visibleRows"
145
+ :total="totalRows"
146
+ :pending="pending"
147
+ :error="error ? 'Bing data could not be loaded. Retry the request.' : undefined"
148
+ :searchable="false"
149
+ :columns="[]"
150
+ :page-size="BING_PERFORMANCE_PAGE_SIZE"
151
+ item-label="rows"
152
+ :label="entityTitle"
153
+ @retry="emit('retry')"
154
+ >
155
+ <template #body>
156
+ <UiTableShell bordered row-hover size="xs" :label="entityTitle">
157
+ <template #head>
158
+ <UiTableTh>
159
+ {{ entityKind === 'pages' ? 'Page' : view === 'queries' ? 'Query' : 'Keyword' }}
160
+ </UiTableTh>
161
+ <UiTableTh>Date</UiTableTh>
162
+ <UiTableTh numeric>
163
+ Clicks
164
+ </UiTableTh>
165
+ <UiTableTh numeric>
166
+ Impressions
167
+ </UiTableTh>
168
+ <UiTableTh numeric visible-from="md">
169
+ CTR
170
+ </UiTableTh>
171
+ <UiTableTh numeric visible-from="lg">
172
+ Avg position
173
+ </UiTableTh>
174
+ </template>
175
+ <tr v-for="row in visibleRows" :key="row.key">
176
+ <UiTableTd row-header class="max-w-0 w-full">
177
+ <UiTablePathCell v-if="row.url" :url="row.url" />
178
+ <span v-else class="block truncate font-sans text-xs text-default" :title="row.label">{{ row.label }}</span>
179
+ </UiTableTd>
180
+ <UiTableTd class="whitespace-nowrap">
181
+ {{ row.date }}
182
+ </UiTableTd>
183
+ <UiTableTd numeric>
184
+ <UiTableMetricCell :value="row.clicks" :display="formatBingNumber(row.clicks)" />
185
+ </UiTableTd>
186
+ <UiTableTd numeric>
187
+ <UiTableMetricCell :value="row.impressions" :display="formatBingNumber(row.impressions)" muted />
188
+ </UiTableTd>
189
+ <UiTableTd numeric visible-from="md">
190
+ <UiTableMetricCell :value="row.impressions ? row.clicks / row.impressions : 0" :display="rowCtr(row)" muted />
191
+ </UiTableTd>
192
+ <UiTableTd numeric visible-from="lg">
193
+ <UiTableMetricCell :value="row.averagePosition" :display="row.averagePosition == null ? null : row.averagePosition.toFixed(1)" muted />
194
+ </UiTableTd>
195
+ </tr>
196
+ </UiTableShell>
197
+ </template>
198
+ </UiDataTableSection>
199
+ </template>
200
+ </div>
201
+ </template>
@@ -0,0 +1,46 @@
1
+ <script setup lang="ts">
2
+ import type { GscTrendDisplay } from './search-trend'
3
+ import { formatNumber } from '@nuxtseo/design-system/app/composables/formatting'
4
+ import { UiFavicon, UiSparkline } from '#components'
5
+
6
+ const { siteDomain, clicks, comparison, barPct, barClass, sparkColor, sparkline } = defineProps<{
7
+ siteDomain?: string
8
+ clicks: number
9
+ comparison: GscTrendDisplay
10
+ barPct: number
11
+ barClass: string
12
+ sparkColor: string
13
+ sparkline: number[]
14
+ }>()
15
+ </script>
16
+
17
+ <template>
18
+ <div class="relative flex min-w-0 items-center gap-2 py-1.5 px-1.5 rounded-md overflow-hidden cursor-default">
19
+ <div
20
+ class="absolute inset-y-0 left-0 rounded-md motion-reduce:transition-none transition-[width] duration-300"
21
+ :class="barClass"
22
+ :style="{ width: `${barPct}%` }"
23
+ />
24
+ <UiFavicon v-if="siteDomain" :domain="siteDomain" :size="14" class="relative rounded-sm shrink-0" />
25
+
26
+ <div class="relative flex min-w-0 flex-1 items-center gap-2">
27
+ <slot />
28
+ </div>
29
+
30
+ <UiSparkline
31
+ v-if="sparkline.length > 1"
32
+ :data="sparkline"
33
+ :color="sparkColor"
34
+ :width="40"
35
+ :height="14"
36
+ class="relative hidden shrink-0 @min-[19rem]:block"
37
+ />
38
+ <span class="relative shrink-0 text-xs font-medium tabular-nums text-default">{{ formatNumber(clicks) }}</span>
39
+ <span
40
+ class="relative w-16 shrink-0 truncate text-right text-mini font-medium text-muted"
41
+ :title="comparison._tag === 'none' ? undefined : comparison.title"
42
+ >
43
+ {{ comparison._tag === 'none' ? '' : comparison.label }}
44
+ </span>
45
+ </div>
46
+ </template>
@@ -0,0 +1,94 @@
1
+ <script setup lang="ts" generic="Row extends RankedSearchRow">
2
+ import type { RankedSearchRow } from '../../shared/ranked-search'
3
+ import { UiMetricLabel, UiSeverityDot, UiSkeleton } from '#components'
4
+
5
+ type EntitySort = 'top' | 'rising' | 'falling'
6
+
7
+ const { entityPlural, top = [], rising = [], falling = [], loading = false, pending = [], failed = [] } = defineProps<{
8
+ entityPlural: 'queries' | 'pages' | 'countries'
9
+ top?: Row[]
10
+ rising?: Row[]
11
+ falling?: Row[]
12
+ loading?: boolean
13
+ pending?: readonly EntitySort[]
14
+ failed?: readonly EntitySort[]
15
+ }>()
16
+
17
+ defineSlots<{
18
+ row: (props: { row: Row, barPct: number, barClass: string, sparkColor: string }) => unknown
19
+ }>()
20
+
21
+ interface SetMeta { value: EntitySort, label: string, barClass: string, sparkColor: string }
22
+ const SETS: SetMeta[] = [
23
+ { value: 'top', label: 'Top by clicks', barClass: 'bg-info/8', sparkColor: 'blue' },
24
+ { value: 'rising', label: 'Rising', barClass: 'bg-success/5', sparkColor: 'green' },
25
+ { value: 'falling', label: 'Falling', barClass: 'bg-error/8', sparkColor: 'red' },
26
+ ]
27
+
28
+ function rowsFor(s: EntitySort): Row[] {
29
+ return s === 'top' ? top : s === 'rising' ? rising : falling
30
+ }
31
+ function visibleRows(s: EntitySort): Row[] {
32
+ return rowsFor(s).slice(0, 3)
33
+ }
34
+ // Top ranks by clicks; the movers rank by |%Δ|.
35
+ function basis(s: EntitySort, row: Row): number {
36
+ return s === 'top' ? row.clicks : Math.abs(row.clicksChangePercent ?? 0)
37
+ }
38
+ function maxBasis(s: EntitySort): number {
39
+ return Math.max(...rowsFor(s).map(r => basis(s, r)), 1)
40
+ }
41
+ function barPct(s: EntitySort, row: Row): number {
42
+ return (basis(s, row) / maxBasis(s)) * 100
43
+ }
44
+ function emptyLabel(s: EntitySort): string {
45
+ return s === 'top' ? `No ${entityPlural} yet` : s === 'rising' ? `No rising ${entityPlural}` : `No declining ${entityPlural}`
46
+ }
47
+ function isPending(s: EntitySort): boolean {
48
+ return loading || pending.includes(s)
49
+ }
50
+ function rowKey(row: Row, i: number): string {
51
+ return `${row.siteDomain}:${row.keyword ?? row.label ?? ''}:${i}`
52
+ }
53
+ </script>
54
+
55
+ <template>
56
+ <div class="@container grid min-w-0 grid-cols-1 gap-3">
57
+ <template v-for="set in SETS" :key="set.value">
58
+ <div v-if="isPending(set.value)" class="min-w-0">
59
+ <!-- `block` keeps the caller's box: the self-sizing `text` type writes an
60
+ inline pixel width that beat `w-20`/`w-full`, so every placeholder came
61
+ out ~200px wide regardless of the row it stood in for. -->
62
+ <UiSkeleton type="block" class="mb-2 h-3 w-20" />
63
+ <div class="space-y-px">
64
+ <UiSkeleton v-for="j in 3" :key="j" type="block" class="h-7 w-full" />
65
+ </div>
66
+ </div>
67
+ <section v-else class="min-w-0">
68
+ <UiMetricLabel :label="set.label" class="mb-2" />
69
+ <span
70
+ v-if="failed.includes(set.value)"
71
+ class="ml-2 inline-flex items-center gap-1 text-xs text-muted"
72
+ title="Couldn't load. Reload to try again."
73
+ >
74
+ <UiSeverityDot severity="warning" />
75
+ Couldn't load
76
+ </span>
77
+ <div v-if="visibleRows(set.value).length" class="space-y-px">
78
+ <template v-for="(row, i) in visibleRows(set.value)" :key="rowKey(row, i)">
79
+ <slot
80
+ name="row"
81
+ :row="row"
82
+ :bar-pct="barPct(set.value, row)"
83
+ :bar-class="set.barClass"
84
+ :spark-color="set.sparkColor"
85
+ />
86
+ </template>
87
+ </div>
88
+ <p v-else-if="!failed.includes(set.value)" class="py-2 text-xs text-dimmed">
89
+ {{ emptyLabel(set.value) }}
90
+ </p>
91
+ </section>
92
+ </template>
93
+ </div>
94
+ </template>