create-expo-updates-server 0.4.0 → 0.6.1

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 +303 -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 +25 -3
  142. package/dist/template/src/server/controllers/manifest.ts +1 -2
  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 +2 -2
  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 +445 -300
  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
@@ -1,7 +1,6 @@
1
1
  "use client";
2
- import { useI18n } from "@/src/client/i18n/provider";
3
2
 
4
- import { useEffect, useState } from "react";
3
+ import { useFilteredResults } from "@/src/client/use-filtered-results";
5
4
  import type { DevicesReport } from "@/src/server/devices/report-types";
6
5
  export type Filters = {
7
6
  days: string;
@@ -19,90 +18,62 @@ export const defaultFilters: Filters = {
19
18
  launchKind: "",
20
19
  search: "",
21
20
  };
22
- export function useDevicesReport() {
23
- const { t } = useI18n();
24
- const [filters, setFilters] = useState(defaultFilters);
25
- const [applied, setApplied] = useState(defaultFilters);
26
- const [offset, setOffset] = useState(0);
27
- const [revision, setRevision] = useState(0);
28
- const [report, setReport] = useState<DevicesReport | null>(null);
29
- const [error, setError] = useState("");
30
- const [loading, setLoading] = useState(true);
31
- useEffect(() => {
32
- const controller = new AbortController();
33
- const params = new URLSearchParams({ offset: String(offset) });
34
- Object.entries(applied).forEach(([key, value]) => {
35
- if (value.trim()) params.set(key, value.trim());
36
- });
37
- fetch(`/api/admin/devices?${params}`, {
38
- signal: controller.signal,
21
+ const initialQuery = { ...defaultFilters, offset: 0 };
22
+
23
+ async function loadReport(
24
+ query: typeof initialQuery,
25
+ signal: AbortSignal,
26
+ ): Promise<DevicesReport> {
27
+ if (!/^[a-f0-9-]{0,36}$/i.test(query.search.trim()))
28
+ throw new Error("Часть UUID: цифры, буквы a–f и дефисы");
29
+
30
+ const params = new URLSearchParams();
31
+ for (const [key, value] of Object.entries(query)) {
32
+ if (String(value).trim()) params.set(key, String(value).trim());
33
+ }
34
+ for (;;) {
35
+ signal.throwIfAborted();
36
+ const response = await fetch(`/api/admin/devices?${params}`, {
37
+ signal,
39
38
  cache: "no-store",
40
- })
41
- .then(async (response) => {
42
- const data = await response.json();
43
- if (!response.ok)
44
- throw new Error(data.error || "Не удалось загрузить статистику");
45
- return data as DevicesReport;
46
- })
47
- .then((data) => {
48
- if (!controller.signal.aborted) {
49
- if (data.offset > 0 && data.offset >= data.total) {
50
- setOffset(
51
- Math.max(
52
- 0,
53
- Math.floor((data.total - 1) / data.pageSize) * data.pageSize,
54
- ),
55
- );
56
- return;
57
- }
58
- setReport(data);
59
- setError("");
60
- setLoading(false);
61
- }
62
- })
63
- .catch((e) => {
64
- if (!controller.signal.aborted) {
65
- setError(e.message);
66
- setLoading(false);
67
- }
68
- });
69
- return () => controller.abort();
70
- }, [applied, offset, revision]);
71
- const refresh = () => {
72
- setLoading(true);
73
- setError("");
74
- setRevision((n) => n + 1);
75
- };
76
- const apply = () => {
77
- setLoading(true);
78
- setError("");
79
- setApplied({ ...filters });
80
- setOffset(0);
81
- };
82
- const reset = () => {
83
- setFilters(defaultFilters);
84
- setApplied({ ...defaultFilters });
85
- setOffset(0);
86
- setLoading(true);
87
- setError("");
88
- };
89
- const paginate = (next: number) => {
90
- setLoading(true);
91
- setError("");
92
- setOffset(next);
93
- setRevision((n) => n + 1);
94
- };
39
+ });
40
+ const data = await response.json();
41
+ if (!response.ok)
42
+ throw new Error(data.error || "Не удалось загрузить статистику");
43
+ const report: DevicesReport = data;
44
+ if (report.offset === 0 || report.offset < report.total) return report;
45
+ // A concurrent removal can make the requested registry page disappear.
46
+ const lastOffset = Math.max(
47
+ 0,
48
+ Math.floor((report.total - 1) / report.pageSize) * report.pageSize,
49
+ );
50
+ params.set("offset", String(lastOffset));
51
+ }
52
+ }
53
+
54
+ export function useDevicesReport() {
55
+ const { query, success, error, loading, request } = useFilteredResults(
56
+ initialQuery,
57
+ loadReport,
58
+ );
59
+ const { offset, ...filters } = query;
60
+ const report = success?.data ?? null;
95
61
  return {
96
62
  filters,
97
- setFilters,
98
- applied,
99
63
  report,
100
- error: t(error),
64
+ error,
101
65
  loading,
102
- offset,
103
- apply,
104
- reset,
105
- refresh,
106
- paginate,
66
+ update: (key: keyof Filters, value: string) =>
67
+ request(
68
+ { ...query, [key]: value, offset: 0 },
69
+ key === "search" && Boolean(value.trim()),
70
+ ),
71
+ reset: () => request(initialQuery),
72
+ refresh: () =>
73
+ request({
74
+ ...query,
75
+ offset: success?.query === query && report ? report.offset : offset,
76
+ }),
77
+ paginate: (offset: number) => request({ ...query, offset }),
107
78
  };
108
79
  }
@@ -2,14 +2,18 @@
2
2
  import { useFormatters } from "@/src/client/i18n/use-formatters";
3
3
  import { useI18n } from "@/src/client/i18n/provider";
4
4
 
5
+ import {
6
+ Collapsible,
7
+ CollapsibleTrigger,
8
+ CollapsibleContent,
9
+ } from "@/components/ui/collapsible";
5
10
  import { useState } from "react";
11
+ import { ChevronDown, ChevronUp, BarChart3, Layers } from "lucide-react";
6
12
  import {
7
- ChevronDown,
8
- ChevronUp,
9
- BarChart3,
10
- Layers,
11
- GitBranch,
12
- } from "lucide-react";
13
+ PlatformBadge,
14
+ ChannelBadge,
15
+ launchKindTone,
16
+ } from "@/components/admin/release-badges";
13
17
  import { Badge } from "@/components/ui/badge";
14
18
  import { Button } from "@/components/ui/button";
15
19
  import {
@@ -46,21 +50,15 @@ function ScopeChart({ scope }: { scope: VersionScope }) {
46
50
  : scope.versions.slice(0, PREVIEW_ROWS);
47
51
  return (
48
52
  <section
49
- className="min-w-0 rounded-lg border p-4"
53
+ className="@container min-w-0 rounded-lg border bg-background/35 p-3 sm:p-4"
50
54
  aria-label={t("Канал {0}, {1}", [scope.channel, scope.platform])}
51
55
  >
52
56
  <header className="mb-4 flex flex-wrap items-center justify-between gap-3">
53
57
  <div className="flex min-w-0 flex-wrap items-center gap-2">
54
- <GitBranch className="size-4 shrink-0 text-muted-foreground" />
55
- <span className="text-xs text-muted-foreground">
56
- {t("Канал")}
57
- </span>
58
- <h4 className="break-all text-sm font-semibold">
59
- {scope.channel}
58
+ <h4 className="min-w-0 max-w-full">
59
+ <ChannelBadge channel={scope.channel} />
60
60
  </h4>
61
- <Badge variant="outline">
62
- {scope.platform === "ios" ? "iOS" : "Android"}
63
- </Badge>
61
+ <PlatformBadge platform={scope.platform} />
64
62
  </div>
65
63
  <span className="text-xs text-muted-foreground">
66
64
  {t("Активных установок:")}{" "}
@@ -69,7 +67,7 @@ function ScopeChart({ scope }: { scope: VersionScope }) {
69
67
  </strong>
70
68
  </span>
71
69
  </header>
72
- <div className="hidden grid-cols-[minmax(0,18rem)_minmax(0,1fr)_8rem] gap-5 border-b pb-3 text-xs text-muted-foreground md:grid">
70
+ <div className="hidden grid-cols-[minmax(0,1fr)_minmax(4rem,1.4fr)_6.5rem] gap-5 border-b pb-3 text-xs text-muted-foreground @min-[32rem]:grid">
73
71
  <span>{t("Версия приложения / OTA")}</span>
74
72
  <div className="flex justify-between">
75
73
  <span>0%</span>
@@ -84,7 +82,7 @@ function ScopeChart({ scope }: { scope: VersionScope }) {
84
82
  {visible.map((version) => (
85
83
  <li
86
84
  key={version.key}
87
- className="grid min-w-0 gap-x-5 gap-y-3 border-b py-4 last:border-b-0 md:grid-cols-[minmax(0,18rem)_minmax(0,1fr)_8rem] md:items-center"
85
+ className="grid min-w-0 grid-cols-[minmax(0,1fr)_auto] gap-x-4 gap-y-2.5 border-b py-3 last:border-b-0 @min-[32rem]:grid-cols-[minmax(0,1fr)_minmax(4rem,1.4fr)_6.5rem] @min-[32rem]:items-center"
88
86
  >
89
87
  <div className="min-w-0">
90
88
  <div className="flex flex-wrap items-center gap-2">
@@ -92,32 +90,38 @@ function ScopeChart({ scope }: { scope: VersionScope }) {
92
90
  {version.appVersion || t("Версия не указана")}
93
91
  </p>
94
92
  <Badge
95
- variant="secondary"
96
- className="font-mono text-[10px]"
93
+ variant={launchKindTone[version.kind]}
94
+ className="font-mono text-[11px]"
97
95
  title={version.updateId || undefined}
98
96
  >
99
97
  {kindLabels[version.kind]}
100
- {version.updateId
101
- ? ` ${version.updateId.slice(0, 8)}`
102
- : ""}
98
+ {version.updateId ? ` ${version.updateId.slice(0, 8)}` : ""}
103
99
  </Badge>
104
100
  </div>
105
101
  <p className="mt-1 break-words text-xs leading-5 text-muted-foreground">
106
102
  {t("Native:")} {version.nativeBuilds.join(", ")}
107
103
  </p>
108
104
  {version.updateId && (
109
- <details className="mt-1 text-xs text-muted-foreground">
110
- <summary className="w-fit cursor-pointer">
111
- {t("Полный ID")}
112
- </summary>
113
- <code className="mt-1 block break-all select-all">
114
- {version.updateId}
115
- </code>
116
- </details>
105
+ <Collapsible className="group/id mt-1 text-xs text-muted-foreground">
106
+ <CollapsibleTrigger asChild>
107
+ <Button size="xs" variant="ghost" className="-ml-1 px-1">
108
+ <ChevronDown
109
+ className="size-3 group-data-[state=open]/id:rotate-180"
110
+ aria-hidden="true"
111
+ />
112
+ {t("Полный ID")}
113
+ </Button>
114
+ </CollapsibleTrigger>
115
+ <CollapsibleContent>
116
+ <code className="mt-1 block break-all select-all">
117
+ {version.updateId}
118
+ </code>
119
+ </CollapsibleContent>
120
+ </Collapsible>
117
121
  )}
118
122
  </div>
119
123
  <div
120
- className="flex h-8 items-center overflow-hidden rounded-md bg-muted/70"
124
+ className="col-span-2 row-start-2 flex h-3 items-center @min-[32rem]:col-span-1 @min-[32rem]:col-start-2 @min-[32rem]:row-start-1 overflow-hidden rounded-sm bg-muted"
121
125
  role="img"
122
126
  aria-label={t(
123
127
  "{0}, {1} {2}: {3} установок, {4} внутри канала {5}, {6}",
@@ -133,7 +137,7 @@ function ScopeChart({ scope }: { scope: VersionScope }) {
133
137
  )}
134
138
  >
135
139
  <div
136
- className="h-full rounded-md"
140
+ className="h-full rounded-sm"
137
141
  style={{
138
142
  width: `${scope.total ? (version.installations / scope.total) * 100 : 0}%`,
139
143
  minWidth: version.installations ? 2 : 0,
@@ -141,8 +145,8 @@ function ScopeChart({ scope }: { scope: VersionScope }) {
141
145
  }}
142
146
  />
143
147
  </div>
144
- <div className="flex items-baseline justify-end gap-2 tabular-nums">
145
- <strong className="text-xl font-semibold">
148
+ <div className="col-start-2 row-start-1 flex flex-wrap items-baseline justify-end gap-x-2 tabular-nums @min-[32rem]:col-start-3">
149
+ <strong className="text-base font-semibold">
146
150
  {number(version.installations)}
147
151
  </strong>
148
152
  <span className="text-sm text-muted-foreground">
@@ -157,8 +161,7 @@ function ScopeChart({ scope }: { scope: VersionScope }) {
157
161
  <p className="text-xs text-muted-foreground">
158
162
  {t("Показано ")}
159
163
  {visible.length} {t(" из ")}
160
- {scope.versions.length}{" "}
161
- {t(" версий. Доли учитывают весь блок.")}
164
+ {scope.versions.length} {t(" версий. Доли учитывают весь блок.")}
162
165
  </p>
163
166
  <Button
164
167
  variant="outline"
@@ -176,11 +179,7 @@ function ScopeChart({ scope }: { scope: VersionScope }) {
176
179
  </section>
177
180
  );
178
181
  }
179
- export function VersionAdoptionChart({
180
- report,
181
- }: {
182
- report: DevicesReport;
183
- }) {
182
+ export function VersionAdoptionChart({ report }: { report: DevicesReport }) {
184
183
  const kindLabels = useKindLabels();
185
184
  const { number } = useFormatters();
186
185
  const { t } = useI18n();
@@ -197,9 +196,9 @@ export function VersionAdoptionChart({
197
196
  <CardHeader>
198
197
  <div className="flex flex-wrap items-center justify-between gap-3">
199
198
  <CardTitle id="version-adoption-title">
200
- {t("Активные установки по версиям")}
199
+ <h2>{t("Активные установки по версиям")}</h2>
201
200
  </CardTitle>
202
- <Badge variant="secondary">
201
+ <Badge variant="info">
203
202
  {t("Всего: ")}
204
203
  {number(report.total)}
205
204
  </Badge>
@@ -212,7 +211,7 @@ export function VersionAdoptionChart({
212
211
  )}
213
212
  </CardDescription>
214
213
  </CardHeader>
215
- <CardContent>
214
+ <CardContent className="min-w-0 px-4 sm:px-6">
216
215
  {runtimes.length ? (
217
216
  <>
218
217
  <div className="mb-5 flex flex-wrap gap-x-5 gap-y-2 text-xs text-muted-foreground">
@@ -221,15 +220,14 @@ export function VersionAdoptionChart({
221
220
  <i
222
221
  className="size-2 rounded-full"
223
222
  style={{
224
- background:
225
- kindColors[kind as keyof typeof kindColors],
223
+ background: kindColors[kind as keyof typeof kindColors],
226
224
  }}
227
225
  />
228
226
  {label}
229
227
  </span>
230
228
  ))}
231
229
  </div>
232
- <div className="space-y-7">
230
+ <div className="space-y-6">
233
231
  {runtimes.map((runtime) => (
234
232
  <section
235
233
  key={runtime.runtime}
@@ -245,7 +243,7 @@ export function VersionAdoptionChart({
245
243
  {runtime.runtime}
246
244
  </span>
247
245
  </h3>
248
- <Badge variant="secondary">
246
+ <Badge variant="info">
249
247
  {t("Установок: ")}
250
248
  {number(runtime.total)}
251
249
  </Badge>
@@ -1,18 +1,19 @@
1
1
  "use client";
2
+ import { useConfirmAction } from "@/components/admin/confirm-action";
2
3
  import type { TranslationMessage } from "@/src/client/i18n/messages";
3
4
  import { useI18n } from "@/src/client/i18n/provider";
4
5
 
6
+ import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert";
7
+ import { Field, FieldLabel } from "@/components/ui/field";
8
+ import { Skeleton } from "@/components/ui/skeleton";
5
9
  import { Textarea } from "@/components/ui/textarea";
6
10
 
11
+ import { statusTones } from "@/components/ui/status-tones";
12
+ import { cn } from "@/lib/utils";
7
13
  import { Button } from "@/components/ui/button";
8
14
  import { Badge } from "@/components/ui/badge";
9
15
  import { Card } from "@/components/ui/card";
10
- import {
11
- ShieldCheck,
12
- ShieldAlert,
13
- ChevronDown,
14
- RefreshCw,
15
- } from "lucide-react";
16
+ import { ShieldCheck, ShieldAlert, ChevronDown, RefreshCw } from "lucide-react";
16
17
 
17
18
  import {
18
19
  AdminApiError,
@@ -23,9 +24,7 @@ import type { DistributionControlResponse } from "./admin-types";
23
24
  import { useCallback, useEffect, useState } from "react";
24
25
 
25
26
  export function useDistributionControlState() {
26
- const [state, setState] = useState<DistributionControlResponse | null>(
27
- null,
28
- );
27
+ const [state, setState] = useState<DistributionControlResponse | null>(null);
29
28
  const [loading, setLoading] = useState(true);
30
29
  const [error, setError] = useState("");
31
30
 
@@ -76,50 +75,64 @@ export function DistributionControlBanner({
76
75
  const { t, formatLocale } = useI18n();
77
76
  if (loading) {
78
77
  return (
79
- <section className="rounded-lg border bg-muted/30 p-4 text-sm text-muted-foreground">
80
- {t("Проверка глобального статуса OTA…")}
81
- </section>
78
+ <Skeleton className="h-12" role="status">
79
+ <span className="sr-only">
80
+ {t("Проверка глобального статуса OTA…")}
81
+ </span>
82
+ </Skeleton>
82
83
  );
83
84
  }
84
-
85
85
  if (error || !state) {
86
86
  return (
87
- <section className="rounded-lg border border-destructive/25 bg-destructive/5 p-4 text-sm text-destructive">
88
- {t(
89
- "Глобальный статус OTA недоступен. Распространяющие действия отключены до восстановления связи.",
90
- )}
91
- {error ? <p className="mt-1 text-xs">{t(error)}</p> : null}
92
- </section>
87
+ <Alert variant="destructive">
88
+ <ShieldAlert />
89
+ <AlertTitle>
90
+ {t(
91
+ "Глобальный статус OTA недоступен. Распространяющие действия отключены до восстановления связи.",
92
+ )}
93
+ </AlertTitle>
94
+ {error && <AlertDescription>{t(error)}</AlertDescription>}
95
+ </Alert>
93
96
  );
94
97
  }
95
-
96
98
  if (!state.blocked) {
97
99
  return null;
98
100
  }
99
101
 
100
102
  return (
101
- <section className="rounded-lg border border-destructive/25 bg-destructive/5 p-4 text-destructive">
102
- <p className="font-semibold">
103
- {t("Распространение OTA остановлено")}
104
- </p>
105
- <p className="mt-1 text-sm">{state.reason}</p>
106
- <p className="mt-2 text-xs">
107
- {new Date(state.changedAt).toLocaleString(formatLocale)} ·{" "}
108
- {formatChangedBy(state, t)}
109
- </p>
110
- </section>
103
+ <Alert variant="destructive">
104
+ <ShieldAlert />
105
+ <AlertTitle>{t("Распространение OTA остановлено")}</AlertTitle>
106
+ <AlertDescription>
107
+ <p>{state.reason}</p>
108
+ <p>
109
+ {new Date(state.changedAt).toLocaleString(formatLocale)} ·{" "}
110
+ {formatChangedBy(state, t)}
111
+ </p>
112
+ </AlertDescription>
113
+ </Alert>
111
114
  );
112
115
  }
113
116
 
114
- export default function DistributionControl() {
117
+ export default function DistributionControl({
118
+ onAvailabilityChange,
119
+ }: {
120
+ onAvailabilityChange?: (blocked: boolean) => void;
121
+ }) {
122
+ const confirmAction = useConfirmAction();
115
123
  const { t, formatLocale } = useI18n();
116
- const { state, setState, loading, error, setError, refresh } =
124
+ const { state, setState, loading, error, refresh } =
117
125
  useDistributionControlState();
126
+ const [actionError, setActionError] = useState("");
118
127
  const [reason, setReason] = useState("");
119
128
  const [saving, setSaving] = useState(false);
120
129
  const [message, setMessage] = useState<TranslationMessage>("");
121
130
  const [expanded, setExpanded] = useState(false);
122
131
 
132
+ useEffect(() => {
133
+ onAvailabilityChange?.(loading || !!error || !state || state.blocked);
134
+ }, [loading, error, state, onAvailabilityChange]);
135
+
123
136
  const changeState = async (blocked: boolean) => {
124
137
  if (!state) {
125
138
  return;
@@ -127,23 +140,25 @@ export default function DistributionControl() {
127
140
 
128
141
  const normalizedReason = reason.trim();
129
142
  if (blocked && !normalizedReason) {
130
- setError("Укажите причину аварийной блокировки.");
143
+ setActionError("Укажите причину аварийной блокировки.");
131
144
  return;
132
145
  }
133
146
 
134
- const confirmed = window.confirm(
147
+ const confirmed = await confirmAction(
148
+ blocked ? t("Остановить все OTA") : t("Возобновить OTA"),
135
149
  blocked
136
150
  ? t(
137
151
  "Немедленно остановить выдачу manifest и всех OTA assets для всех клиентов?",
138
152
  )
139
153
  : t("Возобновить глобальное OTA-распространение?"),
154
+ blocked,
140
155
  );
141
156
  if (!confirmed) {
142
157
  return;
143
158
  }
144
159
 
145
160
  setSaving(true);
146
- setError("");
161
+ setActionError("");
147
162
  setMessage("");
148
163
  try {
149
164
  const updated = await setDistributionControl({
@@ -161,11 +176,11 @@ export default function DistributionControl() {
161
176
  } catch (saveError: unknown) {
162
177
  if (saveError instanceof AdminApiError && saveError.status === 409) {
163
178
  await refresh();
164
- setError(
179
+ setActionError(
165
180
  "Состояние уже изменил другой оператор. Данные обновлены; проверьте их и повторите действие.",
166
181
  );
167
182
  } else {
168
- setError(
183
+ setActionError(
169
184
  saveError instanceof Error
170
185
  ? saveError.message
171
186
  : "Не удалось изменить глобальный статус OTA",
@@ -177,11 +192,16 @@ export default function DistributionControl() {
177
192
  };
178
193
 
179
194
  return (
180
- <Card className="gap-0 overflow-hidden py-0 shadow-none">
195
+ <Card
196
+ className={cn(
197
+ "gap-0 overflow-hidden py-0 shadow-none",
198
+ (state?.blocked || error) && "border-l-4 border-l-destructive",
199
+ )}
200
+ >
181
201
  <div className="flex flex-wrap items-center justify-between gap-4 p-4">
182
202
  <div className="flex items-start gap-3">
183
203
  <div
184
- className={`flex size-9 shrink-0 items-center justify-center rounded-lg ${state?.blocked || error ? "bg-destructive/10 text-destructive" : "bg-muted text-muted-foreground"}`}
204
+ className={`flex size-9 shrink-0 items-center justify-center rounded-lg ${state?.blocked || error ? statusTones.destructive : state && !loading ? statusTones.positive : "bg-muted text-muted-foreground"}`}
185
205
  >
186
206
  {loading ? (
187
207
  <RefreshCw className="size-4 animate-spin" />
@@ -197,11 +217,12 @@ export default function DistributionControl() {
197
217
  {t("Распространение OTA")}
198
218
  </h2>
199
219
  <Badge
200
- variant="secondary"
201
- className={
202
- state?.blocked || error
203
- ? "bg-destructive/10 text-destructive"
204
- : ""
220
+ variant={
221
+ loading
222
+ ? "neutral"
223
+ : state?.blocked || error || !state
224
+ ? "destructive"
225
+ : "positive"
205
226
  }
206
227
  >
207
228
  {loading
@@ -234,34 +255,42 @@ export default function DistributionControl() {
234
255
  />
235
256
  </Button>
236
257
  ) : state ? (
237
- <Badge variant="outline">{t("Read only · updates:write")}</Badge>
258
+ <Badge variant="neutral">{t("Read only · updates:write")}</Badge>
238
259
  ) : null}
239
260
  </div>
240
261
  {expanded && state?.canWrite && (
241
262
  <div
242
263
  id="distribution-controls"
243
- className="space-y-3 border-t bg-muted/20 p-4"
264
+ className={cn(
265
+ "space-y-3 border-t p-4",
266
+ state.blocked ? "bg-muted/20" : statusTones.destructive,
267
+ )}
244
268
  >
245
269
  <p className="text-xs text-muted-foreground">
246
270
  {t("Изменено: ")}
247
271
  {new Date(state.changedAt).toLocaleString(formatLocale)} ·{" "}
248
- {formatChangedBy(state, t)}{" "}
249
- {t(" · version {0}", [state.version])}
272
+ {formatChangedBy(state, t)} {t(" · version {0}", [state.version])}
250
273
  </p>
251
274
  {!state.blocked && (
252
- <label className="block space-y-2 text-sm font-medium">
253
- {t("Причина остановки")}
275
+ <Field>
276
+ <FieldLabel htmlFor="stop-reason">
277
+ {t("Причина остановки")}
278
+ </FieldLabel>
254
279
  <Textarea
280
+ id="stop-reason"
255
281
  value={reason}
256
- onChange={(event) => setReason(event.target.value)}
282
+ onChange={(event) => {
283
+ setReason(event.target.value);
284
+ setActionError("");
285
+ }}
257
286
  maxLength={500}
258
287
  aria-label={t("Причина аварийной блокировки OTA")}
259
288
  placeholder={t(
260
289
  "Обязательная причина остановки (до 500 символов)",
261
290
  )}
262
- className="block min-h-20 w-full max-w-2xl rounded-md border border-input bg-background p-3 text-sm font-normal outline-none focus-visible:ring-2 focus-visible:ring-ring"
291
+ className="min-h-20 max-w-2xl bg-background text-foreground"
263
292
  />
264
- </label>
293
+ </Field>
265
294
  )}
266
295
  <Button
267
296
  variant={state.blocked ? "default" : "destructive"}
@@ -277,18 +306,21 @@ export default function DistributionControl() {
277
306
  </Button>
278
307
  </div>
279
308
  )}
280
- {error && (
309
+ {(error || actionError) && (
281
310
  <p
282
311
  role="alert"
283
- className="border-t bg-destructive/5 px-4 py-3 text-sm text-destructive"
312
+ className={cn("border-t px-4 py-3 text-sm", statusTones.destructive)}
284
313
  >
285
- {t(error)}
314
+ {t(error || actionError)}
286
315
  </p>
287
316
  )}
288
317
  {message && (
289
318
  <p
290
319
  role="status"
291
- className="border-t px-4 py-3 text-sm text-emerald-700 dark:text-emerald-400"
320
+ className={cn(
321
+ "border-t px-4 py-3 text-sm",
322
+ state?.blocked ? statusTones.destructive : statusTones.positive,
323
+ )}
292
324
  >
293
325
  {t(message)}
294
326
  </p>