create-expo-updates-server 0.4.0 → 0.6.0

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.
Files changed (175) hide show
  1. package/README.md +4 -2
  2. package/dist/template/Dockerfile +4 -6
  3. package/dist/template/README.md +4 -9
  4. package/dist/template/app/api/admin/device-favorites/route.test.ts +125 -0
  5. package/dist/template/app/api/admin/device-favorites/route.ts +91 -0
  6. package/dist/template/app/api/admin/distribution-history/restore/route.ts +39 -0
  7. package/dist/template/app/api/admin/distribution-history/route.test.ts +55 -0
  8. package/dist/template/app/api/admin/distribution-history/route.ts +24 -0
  9. package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +2 -1
  10. package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +2 -1
  11. package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +2 -1
  12. package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +2 -1
  13. package/dist/template/app/api/admin/updates/route.test.ts +21 -0
  14. package/dist/template/app/api/admin/updates/route.ts +12 -1
  15. package/dist/template/app/globals.css +65 -68
  16. package/dist/template/app/login/page.tsx +66 -42
  17. package/dist/template/app/updates/[encodedKey]/page.tsx +375 -263
  18. package/dist/template/app/updates/devices/page.tsx +188 -152
  19. package/dist/template/app/updates/embedded/page.tsx +63 -29
  20. package/dist/template/app/updates/emergency-redirects/page.tsx +93 -58
  21. package/dist/template/app/updates/layout.tsx +2 -1
  22. package/dist/template/app/updates/page.tsx +381 -283
  23. package/dist/template/app/updates/releases.test.tsx +156 -0
  24. package/dist/template/components/admin/admin-role.ts +5 -0
  25. package/dist/template/components/admin/admin-shell.tsx +166 -101
  26. package/dist/template/components/admin/confirm-action.tsx +123 -0
  27. package/dist/template/components/admin/language-switcher.tsx +25 -17
  28. package/dist/template/components/admin/release-badges.test.tsx +50 -0
  29. package/dist/template/components/admin/release-badges.tsx +101 -0
  30. package/dist/template/components/ui/alert.tsx +10 -3
  31. package/dist/template/components/ui/avatar.tsx +108 -0
  32. package/dist/template/components/ui/badge.tsx +2 -2
  33. package/dist/template/components/ui/breadcrumb.tsx +108 -0
  34. package/dist/template/components/ui/button.tsx +5 -5
  35. package/dist/template/components/ui/card.tsx +2 -2
  36. package/dist/template/components/ui/chart.tsx +1 -1
  37. package/dist/template/components/ui/collapsible.tsx +7 -0
  38. package/dist/template/components/ui/empty.tsx +103 -0
  39. package/dist/template/components/ui/field.tsx +248 -0
  40. package/dist/template/components/ui/input-group.tsx +170 -0
  41. package/dist/template/components/ui/input.tsx +1 -1
  42. package/dist/template/components/ui/native-select.tsx +1 -1
  43. package/dist/template/components/ui/radio-group.tsx +41 -0
  44. package/dist/template/components/ui/status-tones.ts +15 -0
  45. package/dist/template/components/ui/table.tsx +1 -1
  46. package/dist/template/components/ui/textarea.tsx +1 -1
  47. package/dist/template/docs/admin-ui.md +7 -3
  48. package/dist/template/docs/device-targeting.md +2 -7
  49. package/dist/template/docs/doctor.md +2 -2
  50. package/dist/template/docs/expo-app-setup.md +9 -27
  51. package/dist/template/docs/getting-started.md +3 -4
  52. package/dist/template/docs/installation-telemetry.md +2 -8
  53. package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +5 -0
  54. package/dist/template/docs/migrations/2026-11-25-device-favorites.sql +53 -0
  55. package/dist/template/docs/migrations/2026-11-25-download-on-postpone.sql +5 -0
  56. package/dist/template/docs/migrations/2026-11-25-public-distribution-history.sql +283 -0
  57. package/dist/template/docs/migrations/schema.sql +349 -0
  58. package/dist/template/docs/npm-installer.md +3 -3
  59. package/dist/template/docs/operations-guide.md +8 -6
  60. package/dist/template/docs/ota-client-lifecycle.md +30 -68
  61. package/dist/template/docs/ota-update-policy.md +9 -20
  62. package/dist/template/docs/ru/admin-ui.md +7 -3
  63. package/dist/template/docs/ru/device-targeting.md +2 -2
  64. package/dist/template/docs/ru/doctor.md +2 -2
  65. package/dist/template/docs/ru/expo-app-setup.md +9 -9
  66. package/dist/template/docs/ru/getting-started.md +3 -3
  67. package/dist/template/docs/ru/installation-telemetry.md +2 -2
  68. package/dist/template/docs/ru/npm-installer.md +3 -3
  69. package/dist/template/docs/ru/operations-guide.md +8 -3
  70. package/dist/template/docs/ru/ota-client-lifecycle.md +30 -35
  71. package/dist/template/docs/ru/ota-update-policy.md +9 -7
  72. package/dist/template/docs/ru/publishing-npm-installer.md +2 -2
  73. package/dist/template/docs/uk/admin-ui.md +7 -3
  74. package/dist/template/docs/uk/device-targeting.md +2 -2
  75. package/dist/template/docs/uk/doctor.md +2 -2
  76. package/dist/template/docs/uk/expo-app-setup.md +9 -9
  77. package/dist/template/docs/uk/getting-started.md +3 -3
  78. package/dist/template/docs/uk/installation-telemetry.md +2 -2
  79. package/dist/template/docs/uk/npm-installer.md +3 -3
  80. package/dist/template/docs/uk/operations-guide.md +8 -3
  81. package/dist/template/docs/uk/ota-client-lifecycle.md +30 -35
  82. package/dist/template/docs/uk/ota-update-policy.md +9 -7
  83. package/dist/template/docs/uk/publishing-npm-installer.md +2 -2
  84. package/dist/template/lib/audience-ids.ts +4 -0
  85. package/dist/template/package-lock.json +46 -0
  86. package/dist/template/package.json +3 -1
  87. package/dist/template/scripts/configure-expo-app.mjs +3 -3
  88. package/dist/template/scripts/create-access-token.mjs +1 -1
  89. package/dist/template/scripts/lib/doctor.mjs +10 -7
  90. package/dist/template/scripts/lib/doctor.test.mjs +7 -5
  91. package/dist/template/scripts/lib/embedded-update-registrar.test.ts +22 -7
  92. package/dist/template/scripts/lib/expo-app-configurator.mjs +25 -22
  93. package/dist/template/scripts/lib/expo-app-configurator.test.ts +37 -2
  94. package/dist/template/scripts/lib/ota-client-configurator.mjs +152 -55
  95. package/dist/template/scripts/lib/ota-client-configurator.test.ts +60 -20
  96. package/dist/template/scripts/lib/ota-client-package.mjs +25 -0
  97. package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +90 -32
  98. package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +49 -6
  99. package/dist/template/scripts/tests/device-analytics-migrations.mjs +12 -1
  100. package/dist/template/scripts/tests/device-targeting-activation.mjs +2 -3
  101. package/dist/template/scripts/tests/e2e/client-lifecycle.mjs +161 -0
  102. package/dist/template/scripts/tests/e2e/client-lifecycle.scenario.jsx +465 -0
  103. package/dist/template/scripts/tests/e2e/client-vitest.mts +18 -0
  104. package/dist/template/scripts/tests/e2e/console.mjs +86 -0
  105. package/dist/template/scripts/tests/e2e/delivery.mjs +296 -0
  106. package/dist/template/scripts/tests/e2e/device-favorites.mjs +309 -0
  107. package/dist/template/scripts/tests/e2e/installations.mjs +132 -0
  108. package/dist/template/scripts/tests/e2e/policy.mjs +253 -0
  109. package/dist/template/scripts/tests/e2e/registrar-token.mjs +59 -0
  110. package/dist/template/scripts/tests/e2e/release-matrix.mjs +307 -0
  111. package/dist/template/scripts/tests/e2e/releases.mjs +162 -0
  112. package/dist/template/scripts/tests/e2e/run.mjs +224 -0
  113. package/dist/template/scripts/tests/manifest-identity.sql +7 -5
  114. package/dist/template/scripts/tests/public-distribution-history.mjs +102 -0
  115. package/dist/template/src/client/admin-api.ts +45 -10
  116. package/dist/template/src/client/admin-types.ts +35 -1
  117. package/dist/template/src/client/devices/analytics.tsx +168 -231
  118. package/dist/template/src/client/devices/cohorts.tsx +181 -0
  119. package/dist/template/src/client/devices/device-name.tsx +37 -23
  120. package/dist/template/src/client/devices/favorite-targets.tsx +381 -0
  121. package/dist/template/src/client/devices/registry.tsx +258 -245
  122. package/dist/template/src/client/devices/use-devices-report.test.tsx +98 -0
  123. package/dist/template/src/client/devices/use-devices-report.ts +53 -82
  124. package/dist/template/src/client/devices/version-adoption-chart.tsx +47 -49
  125. package/dist/template/src/client/distribution-control.tsx +89 -57
  126. package/dist/template/src/client/distribution-history.tsx +353 -0
  127. package/dist/template/src/client/guard-action-catalog.tsx +183 -0
  128. package/dist/template/src/client/guard-action-combobox.test.ts +16 -22
  129. package/dist/template/src/client/guard-action-combobox.tsx +133 -239
  130. package/dist/template/src/client/guard-action-options.ts +4 -6
  131. package/dist/template/src/client/i18n/en.json +133 -2
  132. package/dist/template/src/client/i18n/language-switching.test.tsx +12 -3
  133. package/dist/template/src/client/i18n/ru.json +133 -2
  134. package/dist/template/src/client/i18n/uk.json +133 -2
  135. package/dist/template/src/client/logout-button.tsx +3 -3
  136. package/dist/template/src/client/policy-draft.ts +138 -0
  137. package/dist/template/src/client/update-audience-editor.tsx +597 -206
  138. package/dist/template/src/client/update-policy-editor.test.ts +101 -29
  139. package/dist/template/src/client/update-policy-editor.tsx +454 -320
  140. package/dist/template/src/client/use-filtered-results.ts +55 -0
  141. package/dist/template/src/server/controllers/manifest.test.ts +23 -3
  142. package/dist/template/src/server/controllers/manifest.ts +15 -1
  143. package/dist/template/src/server/devices/audience.ts +9 -5
  144. package/dist/template/src/server/lib/admin-audience-activation.test.ts +37 -90
  145. package/dist/template/src/server/lib/admin-release-history.test.ts +138 -0
  146. package/dist/template/src/server/lib/admin-updates.ts +160 -534
  147. package/dist/template/src/server/lib/distribution-history.ts +97 -0
  148. package/dist/template/src/server/lib/supabase.js +24 -0
  149. package/dist/template/src/server/lib/supabase.test.ts +38 -1
  150. package/dist/template/src/server/lib/update-policy.test.ts +20 -0
  151. package/dist/template/src/server/lib/update-policy.ts +23 -10
  152. package/dist/template/src/server/manifest/manifest-repository.ts +11 -3
  153. package/dist/template/src/server/manifest/manifest-values.test.ts +2 -0
  154. package/dist/template/src/server/manifest/manifest-values.ts +21 -13
  155. package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +7 -30
  156. package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +2 -1
  157. package/dist/template/tsconfig.json +2 -2
  158. package/dist/template-manifest.json +446 -301
  159. package/package.json +1 -1
  160. package/dist/template/scripts/lib/device-identity.test.ts +0 -29
  161. package/dist/template/scripts/lib/ota-client.test.ts +0 -55
  162. package/dist/template/scripts/lib/ota-update-controller.test.ts +0 -232
  163. package/dist/template/scripts/lib/ota-updates-ui.test.tsx +0 -154
  164. package/dist/template/scripts/tests/ota-client-types.mjs +0 -69
  165. package/dist/template/templates/expo-app/ota-client/README.md +0 -73
  166. package/dist/template/templates/expo-app/ota-client/controller.ts +0 -107
  167. package/dist/template/templates/expo-app/ota-client/device-identity.ts +0 -48
  168. package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +0 -61
  169. package/dist/template/templates/expo-app/ota-client/index.ts +0 -16
  170. package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +0 -97
  171. package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +0 -293
  172. package/dist/template/templates/expo-app/ota-client/runtime.ts +0 -153
  173. package/dist/template/templates/expo-app/ota-client/types.ts +0 -85
  174. package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +0 -25
  175. package/dist/template/templates/expo-app/ota-client/ui/ota-updates.tsx +0 -196
@@ -3,15 +3,16 @@ import { useFormatters } from "@/src/client/i18n/use-formatters";
3
3
  import { useI18n } from "@/src/client/i18n/provider";
4
4
 
5
5
  import { DeviceName } from "./device-name";
6
- import { useRef, useState } from "react";
7
- import {
8
- Copy,
9
- Check,
10
- ChevronLeft,
11
- ChevronRight,
12
- Search,
13
- } from "lucide-react";
6
+ import { AdminRoleContext } from "@/components/admin/admin-role";
7
+ import { BookmarkTarget, useFavoriteTargets } from "./favorite-targets";
8
+ import { useContext, useRef, useState } from "react";
9
+ import { Copy, Check, ChevronLeft, ChevronRight, Search } from "lucide-react";
14
10
  import { Button } from "@/components/ui/button";
11
+ import {
12
+ PlatformBadge,
13
+ ChannelBadge,
14
+ launchKindTone,
15
+ } from "@/components/admin/release-badges";
15
16
  import { Badge } from "@/components/ui/badge";
16
17
  import {
17
18
  Card,
@@ -20,12 +21,6 @@ import {
20
21
  CardDescription,
21
22
  CardContent,
22
23
  } from "@/components/ui/card";
23
- import {
24
- Tabs,
25
- TabsList,
26
- TabsTrigger,
27
- TabsContent,
28
- } from "@/components/ui/tabs";
29
24
  import {
30
25
  Table,
31
26
  TableHeader,
@@ -45,7 +40,7 @@ import type {
45
40
  DeviceInstallation,
46
41
  DevicesReport,
47
42
  } from "@/src/server/devices/report-types";
48
- import { useKindNames, percent } from "./analytics";
43
+ import { useKindNames } from "./analytics";
49
44
  function CopyValue({ value }: { value: string }) {
50
45
  const { t } = useI18n();
51
46
  const [state, setState] = useState<"idle" | "copied" | "failed">("idle");
@@ -98,13 +93,22 @@ export function Registry({
98
93
  const kindNames = useKindNames();
99
94
  const { number, fullDate, calendarDate } = useFormatters();
100
95
  const [selected, setSelected] = useState<DeviceInstallation | null>(null);
96
+ const role = useContext(AdminRoleContext);
97
+ const canBookmark = role === "admin" || role === "operator";
98
+ const personal = useFavoriteTargets(
99
+ selected?.platform ?? "",
100
+ !!selected && canBookmark,
101
+ 0,
102
+ );
101
103
  return (
102
104
  <>
103
105
  <Card className="min-w-0 shadow-none">
104
106
  <CardHeader>
105
107
  <div className="flex flex-wrap items-center gap-3">
106
- <CardTitle>{t("Реестр установок")}</CardTitle>
107
- <Badge variant="secondary">{number(report.total)}</Badge>
108
+ <CardTitle>
109
+ <h2>{t("Реестр установок")}</h2>
110
+ </CardTitle>
111
+ <Badge variant="info">{number(report.total)}</Badge>
108
112
  </div>
109
113
  <CardDescription>
110
114
  {t(
@@ -112,233 +116,136 @@ export function Registry({
112
116
  )}
113
117
  </CardDescription>
114
118
  </CardHeader>
115
- <CardContent>
116
- <Tabs defaultValue="devices">
117
- <TabsList className="mb-4">
118
- <TabsTrigger value="devices">{t("Установки")}</TabsTrigger>
119
- <TabsTrigger value="versions">
120
- {t("Все версии · ")}
121
- {report.versions.length}
122
- </TabsTrigger>
123
- </TabsList>
124
- <TabsContent value="devices">
125
- <Table>
126
- <TableHeader>
127
- <TableRow>
128
- <TableHead>{t("Установка")}</TableHead>
129
- <TableHead>{t("Платформа / канал")}</TableHead>
130
- <TableHead>{t("Версия")}</TableHead>
131
- <TableHead>{t("Запуск")}</TableHead>
132
- <TableHead>{t("Последняя связь · UTC")}</TableHead>
133
- </TableRow>
134
- </TableHeader>
135
- <TableBody>
136
- {report.devices.map((d) => (
137
- <TableRow key={`${d.platform}:${d.installation_id}`}>
138
- <TableCell>
139
- <Button
140
- variant="link"
141
- className="h-auto p-0 font-mono text-xs"
142
- title={d.installation_id}
143
- onClick={(event) => {
144
- opener.current = event.currentTarget;
145
- setSelected(d);
146
- }}
147
- aria-label={t("Детали установки {0}", [
148
- d.installation_id,
149
- ])}
150
- >
151
- {d.installation_id.slice(0, 8)}…
152
- {d.installation_id.slice(-4)}
153
- </Button>
154
- <p className="mt-1 text-xs text-muted-foreground">
155
- {t("С ")}
156
- {calendarDate(d.first_seen_at)}
157
- </p>
158
- </TableCell>
159
- <TableCell>
160
- <span className="capitalize">{d.platform}</span>
161
- <p className="mt-1 text-xs text-muted-foreground">
162
- {d.channel}
163
- </p>
164
- </TableCell>
165
- <TableCell>
166
- <p
167
- className="max-w-56 truncate text-sm"
168
- title={
169
- d.update_label ||
170
- d.resolved_update_id ||
171
- kindNames[d.launch_kind]
172
- }
173
- >
174
- {d.update_label ||
175
- d.resolved_update_id?.slice(0, 8) ||
176
- kindNames[d.launch_kind]}
177
- </p>
178
- <p
179
- className="mt-1 text-xs text-muted-foreground"
180
- title={d.runtime_version}
181
- >
182
- {d.runtime_version}
183
- </p>
184
- <p className="mt-1 text-xs text-muted-foreground">
185
- {t("Native")} {d.native_version || "—"} (
186
- {d.native_build || "—"})
187
- </p>
188
- </TableCell>
189
- <TableCell>
190
- <Badge
191
- variant={
192
- d.launch_kind === "ota"
193
- ? "default"
194
- : "secondary"
195
- }
196
- >
197
- {kindNames[d.launch_kind]}
198
- </Badge>
199
- {d.emergency_launch && (
200
- <Badge
201
- variant="destructive"
202
- className="mt-1 block w-fit"
203
- >
204
- {t("Emergency")}
205
- </Badge>
206
- )}
207
- </TableCell>
208
- <TableCell className="text-xs tabular-nums">
209
- {fullDate(d.last_seen_at).replace(" UTC", "")}
210
- </TableCell>
211
- </TableRow>
212
- ))}
213
- </TableBody>
214
- </Table>
215
- {!report.devices.length && (
216
- <div className="flex flex-col items-center gap-2 py-12 text-center">
217
- <Search className="size-6 text-muted-foreground" />
218
- <p className="text-sm font-medium">
219
- {t("Установки не найдены")}
220
- </p>
221
- <p className="max-w-sm text-xs leading-5 text-muted-foreground">
222
- {t(
223
- "Измените фильтры или дождитесь heartbeat от приложения с подключённой телеметрией.",
119
+ <CardContent className="min-w-0 px-4 sm:px-6">
120
+ <Table aria-label={t("Реестр установок")}>
121
+ <TableHeader>
122
+ <TableRow>
123
+ <TableHead>{t("Установка")}</TableHead>
124
+ <TableHead>{t("Платформа / канал")}</TableHead>
125
+ <TableHead>{t("Версия")}</TableHead>
126
+ <TableHead>{t("Запуск")}</TableHead>
127
+ <TableHead>{t("Последняя связь · UTC")}</TableHead>
128
+ </TableRow>
129
+ </TableHeader>
130
+ <TableBody>
131
+ {report.devices.map((d) => (
132
+ <TableRow key={`${d.platform}:${d.installation_id}`}>
133
+ <TableCell>
134
+ <Button
135
+ variant="link"
136
+ className="h-auto p-0 font-mono text-xs"
137
+ title={d.installation_id}
138
+ onClick={(event) => {
139
+ opener.current = event.currentTarget;
140
+ setSelected(d);
141
+ }}
142
+ aria-label={t("Детали установки {0}", [
143
+ d.installation_id,
144
+ ])}
145
+ >
146
+ {d.installation_id.slice(0, 8)}…
147
+ {d.installation_id.slice(-4)}
148
+ </Button>
149
+ <p className="mt-1 text-xs text-muted-foreground">
150
+ {t("С ")}
151
+ {calendarDate(d.first_seen_at)}
152
+ </p>
153
+ </TableCell>
154
+ <TableCell>
155
+ <div className="flex max-w-52 flex-wrap items-center gap-1">
156
+ <PlatformBadge platform={d.platform} />
157
+ <ChannelBadge channel={d.channel} />
158
+ </div>
159
+ </TableCell>
160
+ <TableCell>
161
+ <p
162
+ className="max-w-56 truncate text-sm"
163
+ title={
164
+ d.update_label ||
165
+ d.resolved_update_id ||
166
+ kindNames[d.launch_kind]
167
+ }
168
+ >
169
+ {d.update_label ||
170
+ d.resolved_update_id?.slice(0, 8) ||
171
+ kindNames[d.launch_kind]}
172
+ </p>
173
+ <p
174
+ className="mt-1 text-xs text-muted-foreground"
175
+ title={d.runtime_version}
176
+ >
177
+ {d.runtime_version}
178
+ </p>
179
+ <p className="mt-1 text-xs text-muted-foreground">
180
+ {t("Native")} {d.native_version || "—"} (
181
+ {d.native_build || "—"})
182
+ </p>
183
+ </TableCell>
184
+ <TableCell>
185
+ <Badge variant={launchKindTone[d.launch_kind]}>
186
+ {kindNames[d.launch_kind]}
187
+ </Badge>
188
+ {d.emergency_launch && (
189
+ <Badge variant="destructive" className="mt-1 block w-fit">
190
+ {t("Emergency")}
191
+ </Badge>
224
192
  )}
225
- </p>
226
- </div>
227
- )}
228
- <div className="mt-4 flex flex-wrap items-center justify-between gap-3 border-t pt-4">
229
- <p className="text-xs text-muted-foreground">
230
- {report.total
231
- ? t("{0}–{1} из {2}", [
232
- number(report.offset + 1),
233
- number(
234
- Math.min(
235
- report.offset + report.pageSize,
236
- report.total,
237
- ),
238
- ),
239
- number(report.total),
240
- ])
241
- : t("0 установок")}
242
- </p>
243
- <div className="flex gap-2">
244
- <Button
245
- size="sm"
246
- variant="outline"
247
- disabled={loading || report.offset === 0}
248
- onClick={() =>
249
- paginate(Math.max(0, report.offset - report.pageSize))
250
- }
251
- >
252
- <ChevronLeft />
253
- {t("Назад")}
254
- </Button>
255
- <Button
256
- size="sm"
257
- variant="outline"
258
- disabled={
259
- loading ||
260
- report.offset + report.pageSize >= report.total
261
- }
262
- onClick={() =>
263
- paginate(report.offset + report.pageSize)
264
- }
265
- >
266
- {t("Далее")}
267
- <ChevronRight />
268
- </Button>
269
- </div>
270
- </div>
271
- </TabsContent>
272
- <TabsContent value="versions">
273
- <Table>
274
- <TableHeader>
275
- <TableRow>
276
- <TableHead>{t("Версия / ID")}</TableHead>
277
- <TableHead>{t("Платформа / канал")}</TableHead>
278
- <TableHead>{t("Runtime / native")}</TableHead>
279
- <TableHead>{t("Запуск")}</TableHead>
280
- <TableHead className="text-right">
281
- {t("Установки")}
282
- </TableHead>
283
- <TableHead className="text-right">
284
- {t("Доля")}
285
- </TableHead>
286
- </TableRow>
287
- </TableHeader>
288
- <TableBody>
289
- {report.versions.map((v, i) => (
290
- <TableRow key={i}>
291
- <TableCell>
292
- <p
293
- className="max-w-56 truncate font-medium"
294
- title={v.update_label || undefined}
295
- >
296
- {v.update_label || kindNames[v.launch_kind]}
297
- </p>
298
- {v.update_id && (
299
- <code
300
- className="mt-1 block text-xs text-muted-foreground"
301
- title={v.update_id}
302
- >
303
- {v.update_id}
304
- </code>
305
- )}
306
- </TableCell>
307
- <TableCell>
308
- {v.platform}
309
- <p className="text-xs text-muted-foreground">
310
- {v.channel}
311
- </p>
312
- </TableCell>
313
- <TableCell>
314
- {v.runtime_version}
315
- <p className="text-xs text-muted-foreground">
316
- {v.native_version || "—"} ({v.native_build || "—"}
317
- )
318
- </p>
319
- </TableCell>
320
- <TableCell>
321
- <Badge variant="secondary">
322
- {kindNames[v.launch_kind]}
323
- </Badge>
324
- </TableCell>
325
- <TableCell className="text-right tabular-nums">
326
- {number(v.installations)}
327
- </TableCell>
328
- <TableCell className="text-right tabular-nums">
329
- {percent(v.installations, report.total)}
330
- </TableCell>
331
- </TableRow>
332
- ))}
333
- </TableBody>
334
- </Table>
335
- {!report.versions.length && (
336
- <p className="py-8 text-center text-sm text-muted-foreground">
337
- {t("Нет версий в выбранной выборке.")}
338
- </p>
339
- )}
340
- </TabsContent>
341
- </Tabs>
193
+ </TableCell>
194
+ <TableCell className="text-xs tabular-nums">
195
+ {fullDate(d.last_seen_at).replace(" UTC", "")}
196
+ </TableCell>
197
+ </TableRow>
198
+ ))}
199
+ </TableBody>
200
+ </Table>
201
+ {!report.devices.length && (
202
+ <div className="flex flex-col items-center gap-2 py-12 text-center">
203
+ <Search className="size-6 text-muted-foreground" />
204
+ <p className="text-sm font-medium">{t("Установки не найдены")}</p>
205
+ <p className="max-w-sm text-xs leading-5 text-muted-foreground">
206
+ {t(
207
+ "Измените фильтры или дождитесь heartbeat от приложения с подключённой телеметрией.",
208
+ )}
209
+ </p>
210
+ </div>
211
+ )}
212
+ <div className="mt-4 flex flex-wrap items-center justify-between gap-3 border-t pt-4">
213
+ <p className="text-xs text-muted-foreground">
214
+ {report.total
215
+ ? t("{0}–{1} из {2}", [
216
+ number(report.offset + 1),
217
+ number(
218
+ Math.min(report.offset + report.pageSize, report.total),
219
+ ),
220
+ number(report.total),
221
+ ])
222
+ : t("0 установок")}
223
+ </p>
224
+ <div className="flex gap-2">
225
+ <Button
226
+ size="sm"
227
+ variant="outline"
228
+ disabled={loading || report.offset === 0}
229
+ onClick={() =>
230
+ paginate(Math.max(0, report.offset - report.pageSize))
231
+ }
232
+ >
233
+ <ChevronLeft />
234
+ {t("Назад")}
235
+ </Button>
236
+ <Button
237
+ size="sm"
238
+ variant="outline"
239
+ disabled={
240
+ loading || report.offset + report.pageSize >= report.total
241
+ }
242
+ onClick={() => paginate(report.offset + report.pageSize)}
243
+ >
244
+ {t("Далее")}
245
+ <ChevronRight />
246
+ </Button>
247
+ </div>
248
+ </div>
342
249
  </CardContent>
343
250
  </Card>
344
251
  <Sheet
@@ -362,6 +269,24 @@ export function Registry({
362
269
  )}
363
270
  </SheetDescription>
364
271
  </SheetHeader>
272
+ {selected && canBookmark && (
273
+ <div className="mx-4 space-y-2 sm:mx-6">
274
+ {personal.error && (
275
+ <p role="alert" className="text-sm text-destructive">
276
+ {t(personal.error)}
277
+ </p>
278
+ )}
279
+ <BookmarkTarget
280
+ platform={selected.platform}
281
+ deviceId={selected.device_id ?? null}
282
+ installationId={selected.installation_id}
283
+ displayName={null}
284
+ showLabel
285
+ favorites={personal.favorites ?? []}
286
+ onChanged={personal.refresh}
287
+ />
288
+ </div>
289
+ )}
365
290
  {selected?.device_id && (
366
291
  <DeviceName
367
292
  key={selected.device_id}
@@ -370,7 +295,7 @@ export function Registry({
370
295
  />
371
296
  )}
372
297
  {selected && (
373
- <dl className="space-y-5 px-6 pb-8">
298
+ <dl className="divide-y px-4 pb-6 sm:px-6">
374
299
  {[
375
300
  [t("Installation ID"), selected.installation_id],
376
301
  [t("Device ID"), selected.device_id || "—"],
@@ -396,7 +321,10 @@ export function Registry({
396
321
  fullDate(selected.observed_at),
397
322
  ],
398
323
  ].map(([label, value]) => (
399
- <div key={label}>
324
+ <div
325
+ key={label}
326
+ className="grid items-start gap-1.5 py-3 sm:grid-cols-[9rem_1fr]"
327
+ >
400
328
  <dt className="mb-1 text-xs font-medium text-muted-foreground">
401
329
  {label}
402
330
  </dt>
@@ -416,3 +344,88 @@ export function Registry({
416
344
  </>
417
345
  );
418
346
  }
347
+
348
+ export function VersionTable({ report }: { report: DevicesReport }) {
349
+ const { t } = useI18n();
350
+ const kindNames = useKindNames();
351
+ const { number, share } = useFormatters();
352
+ return (
353
+ <Card className="min-w-0 gap-4 shadow-none">
354
+ <CardHeader>
355
+ <CardTitle>
356
+ <h2>
357
+ {t("Все версии · ")}
358
+ {number(report.versions.length)}
359
+ </h2>
360
+ </CardTitle>
361
+ <CardDescription>
362
+ {t("Shares across all installations in the selected period.")}
363
+ </CardDescription>
364
+ </CardHeader>
365
+ <CardContent className="min-w-0 px-4 sm:px-6">
366
+ <Table>
367
+ <TableHeader>
368
+ <TableRow>
369
+ <TableHead>{t("Версия / ID")}</TableHead>
370
+ <TableHead>{t("Платформа / канал")}</TableHead>
371
+ <TableHead>{t("Runtime / native")}</TableHead>
372
+ <TableHead>{t("Запуск")}</TableHead>
373
+ <TableHead className="text-right">{t("Установки")}</TableHead>
374
+ <TableHead className="text-right">{t("Доля")}</TableHead>
375
+ </TableRow>
376
+ </TableHeader>
377
+ <TableBody>
378
+ {report.versions.map((v, i) => (
379
+ <TableRow key={i}>
380
+ <TableCell>
381
+ <p
382
+ className="max-w-56 truncate font-medium"
383
+ title={v.update_label || undefined}
384
+ >
385
+ {v.update_label || kindNames[v.launch_kind]}
386
+ </p>
387
+ {v.update_id && (
388
+ <code
389
+ className="mt-1 block text-xs text-muted-foreground"
390
+ title={v.update_id}
391
+ >
392
+ {v.update_id}
393
+ </code>
394
+ )}
395
+ </TableCell>
396
+ <TableCell>
397
+ <div className="flex max-w-52 flex-wrap items-center gap-1">
398
+ <PlatformBadge platform={v.platform} />
399
+ <ChannelBadge channel={v.channel} />
400
+ </div>
401
+ </TableCell>
402
+ <TableCell>
403
+ {v.runtime_version}
404
+ <p className="text-xs text-muted-foreground">
405
+ {v.native_version || "—"} ({v.native_build || "—"})
406
+ </p>
407
+ </TableCell>
408
+ <TableCell>
409
+ <Badge variant={launchKindTone[v.launch_kind]}>
410
+ {kindNames[v.launch_kind]}
411
+ </Badge>
412
+ </TableCell>
413
+ <TableCell className="text-right tabular-nums">
414
+ {number(v.installations)}
415
+ </TableCell>
416
+ <TableCell className="text-right tabular-nums">
417
+ {share(v.installations, report.total)}
418
+ </TableCell>
419
+ </TableRow>
420
+ ))}
421
+ </TableBody>
422
+ </Table>
423
+ {!report.versions.length && (
424
+ <p className="py-8 text-center text-sm text-muted-foreground">
425
+ {t("Нет версий в выбранной выборке.")}
426
+ </p>
427
+ )}
428
+ </CardContent>
429
+ </Card>
430
+ );
431
+ }
@@ -0,0 +1,98 @@
1
+ // @vitest-environment jsdom
2
+ import { act, useLayoutEffect } from "react";
3
+ import { createRoot, type Root } from "react-dom/client";
4
+ import { afterEach, beforeEach, expect, it, vi } from "vitest";
5
+ import { useDevicesReport } from "./use-devices-report";
6
+
7
+ let root: Root;
8
+ let state: ReturnType<typeof useDevicesReport>;
9
+ const fetchReport = vi.fn<typeof fetch>();
10
+ const response = (total: number, offset = 0) =>
11
+ Response.json({
12
+ total,
13
+ offset,
14
+ pageSize: 20,
15
+ options: { channels: [], runtimes: [] },
16
+ });
17
+
18
+ function Screen() {
19
+ const result = useDevicesReport();
20
+ useLayoutEffect(() => {
21
+ state = result;
22
+ });
23
+ return null;
24
+ }
25
+
26
+ beforeEach(async () => {
27
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
28
+ vi.useFakeTimers();
29
+ fetchReport.mockReset().mockImplementation(async () => response(24));
30
+ vi.stubGlobal("fetch", fetchReport);
31
+ root = createRoot(document.createElement("div"));
32
+ await act(async () => root.render(<Screen />));
33
+ });
34
+ afterEach(async () => {
35
+ await act(async () => root.unmount());
36
+ vi.useRealTimers();
37
+ vi.unstubAllGlobals();
38
+ });
39
+
40
+ it("debounces typing, cancels pending searches on select/reset, and starts filtering at the first page", async () => {
41
+ await act(async () => state.paginate(20));
42
+ await act(async () => state.update("search", "a"));
43
+ await act(async () => state.update("search", "ab"));
44
+ expect(fetchReport).toHaveBeenCalledTimes(2);
45
+ await act(async () => state.update("platform", "ios"));
46
+ const params = new URL(
47
+ String(fetchReport.mock.lastCall![0]),
48
+ "http://localhost",
49
+ ).searchParams;
50
+ expect(Object.fromEntries(params)).toEqual({
51
+ days: "7",
52
+ offset: "0",
53
+ search: "ab",
54
+ platform: "ios",
55
+ });
56
+ await act(async () => state.update("search", "abc"));
57
+ await act(async () => state.reset());
58
+ await act(async () => vi.advanceTimersByTimeAsync(500));
59
+ expect(fetchReport).toHaveBeenCalledTimes(4);
60
+ expect(String(fetchReport.mock.lastCall![0])).not.toContain("search=");
61
+ });
62
+
63
+ it("keeps the last success through errors and ignores late responses from aborted requests", async () => {
64
+ let resolveLate!: (value: Response) => void;
65
+ fetchReport.mockImplementationOnce(
66
+ () =>
67
+ new Promise((resolve) => {
68
+ resolveLate = resolve;
69
+ }),
70
+ );
71
+ await act(async () => state.update("days", "1"));
72
+ const signal = fetchReport.mock.lastCall![1]!.signal!;
73
+ await act(async () => state.update("search", "a"));
74
+ expect(signal.aborted).toBe(true);
75
+ fetchReport.mockResolvedValueOnce(
76
+ Response.json({ error: "Temporary outage" }, { status: 503 }),
77
+ );
78
+ await act(async () => vi.advanceTimersByTimeAsync(300));
79
+ expect(state.error).toBe("Temporary outage");
80
+ await act(async () => resolveLate(response(900)));
81
+ expect(state.report?.total).toBe(24);
82
+ expect(state.error).toBe("Temporary outage");
83
+ fetchReport.mockResolvedValueOnce(response(2));
84
+ await act(async () => state.refresh());
85
+ expect(state.report?.total).toBe(2);
86
+ expect(state.error).toBe("");
87
+ });
88
+
89
+ it("retrieves the last available page when a refresh shrinks the registry", async () => {
90
+ fetchReport
91
+ .mockResolvedValueOnce(response(23, 40))
92
+ .mockResolvedValueOnce(response(23, 20));
93
+ await act(async () => state.paginate(40));
94
+ expect(String(fetchReport.mock.lastCall![0])).toContain("offset=20");
95
+ expect(state.report?.offset).toBe(20);
96
+ await act(async () => state.refresh());
97
+ expect(String(fetchReport.mock.lastCall![0])).toContain("offset=20");
98
+ });