create-expo-updates-server 0.3.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 (191) hide show
  1. package/README.md +4 -2
  2. package/dist/template/Dockerfile +4 -6
  3. package/dist/template/README.md +5 -10
  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 +382 -248
  18. package/dist/template/app/updates/devices/page.tsx +187 -145
  19. package/dist/template/app/updates/embedded/page.tsx +80 -34
  20. package/dist/template/app/updates/emergency-redirects/page.tsx +138 -71
  21. package/dist/template/app/updates/layout.tsx +2 -1
  22. package/dist/template/app/updates/page.tsx +385 -274
  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 -95
  26. package/dist/template/components/admin/confirm-action.tsx +123 -0
  27. package/dist/template/components/admin/language-switcher.tsx +27 -16
  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/dialog.tsx +13 -4
  39. package/dist/template/components/ui/empty.tsx +103 -0
  40. package/dist/template/components/ui/field.tsx +248 -0
  41. package/dist/template/components/ui/input-group.tsx +170 -0
  42. package/dist/template/components/ui/input.tsx +1 -1
  43. package/dist/template/components/ui/native-select.tsx +1 -1
  44. package/dist/template/components/ui/radio-group.tsx +41 -0
  45. package/dist/template/components/ui/sheet.tsx +6 -2
  46. package/dist/template/components/ui/sidebar.tsx +62 -17
  47. package/dist/template/components/ui/status-tones.ts +15 -0
  48. package/dist/template/components/ui/table.tsx +1 -1
  49. package/dist/template/components/ui/textarea.tsx +1 -1
  50. package/dist/template/docs/admin-ui.md +22 -24
  51. package/dist/template/docs/device-targeting.md +6 -12
  52. package/dist/template/docs/doctor.md +2 -2
  53. package/dist/template/docs/expo-app-setup.md +9 -27
  54. package/dist/template/docs/getting-started.md +3 -4
  55. package/dist/template/docs/getting-started.ru.md +11 -544
  56. package/dist/template/docs/index.md +1 -1
  57. package/dist/template/docs/installation-telemetry.md +6 -12
  58. package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +5 -0
  59. package/dist/template/docs/migrations/2026-11-25-device-favorites.sql +53 -0
  60. package/dist/template/docs/migrations/2026-11-25-download-on-postpone.sql +5 -0
  61. package/dist/template/docs/migrations/2026-11-25-public-distribution-history.sql +283 -0
  62. package/dist/template/docs/migrations/schema.sql +349 -0
  63. package/dist/template/docs/npm-installer.md +3 -3
  64. package/dist/template/docs/operations-guide.md +9 -7
  65. package/dist/template/docs/ota-client-lifecycle.md +30 -68
  66. package/dist/template/docs/ota-emergency-recovery.md +34 -57
  67. package/dist/template/docs/ota-update-policy.md +9 -20
  68. package/dist/template/docs/ru/admin-ui.md +33 -0
  69. package/dist/template/docs/ru/device-targeting.md +59 -0
  70. package/dist/template/docs/ru/doctor.md +98 -0
  71. package/dist/template/docs/ru/expo-app-setup.md +497 -0
  72. package/dist/template/docs/ru/getting-started.md +391 -0
  73. package/dist/template/docs/ru/index.md +50 -0
  74. package/dist/template/docs/ru/installation-telemetry.md +125 -0
  75. package/dist/template/docs/ru/npm-installer.md +71 -0
  76. package/dist/template/docs/ru/operations-guide.md +322 -0
  77. package/dist/template/docs/ru/ota-client-lifecycle.md +162 -0
  78. package/dist/template/docs/ru/ota-emergency-recovery.md +108 -0
  79. package/dist/template/docs/ru/ota-update-policy.md +69 -0
  80. package/dist/template/docs/ru/publishing-npm-installer.md +49 -0
  81. package/dist/template/docs/ru/supabase-setup.md +120 -0
  82. package/dist/template/docs/uk/admin-ui.md +33 -0
  83. package/dist/template/docs/uk/device-targeting.md +59 -0
  84. package/dist/template/docs/uk/doctor.md +98 -0
  85. package/dist/template/docs/uk/expo-app-setup.md +497 -0
  86. package/dist/template/docs/uk/getting-started.md +391 -0
  87. package/dist/template/docs/uk/index.md +50 -0
  88. package/dist/template/docs/uk/installation-telemetry.md +125 -0
  89. package/dist/template/docs/uk/npm-installer.md +71 -0
  90. package/dist/template/docs/uk/operations-guide.md +322 -0
  91. package/dist/template/docs/uk/ota-client-lifecycle.md +162 -0
  92. package/dist/template/docs/uk/ota-emergency-recovery.md +108 -0
  93. package/dist/template/docs/uk/ota-update-policy.md +69 -0
  94. package/dist/template/docs/uk/publishing-npm-installer.md +49 -0
  95. package/dist/template/docs/uk/supabase-setup.md +120 -0
  96. package/dist/template/lib/audience-ids.ts +4 -0
  97. package/dist/template/package-lock.json +46 -0
  98. package/dist/template/package.json +4 -1
  99. package/dist/template/scripts/configure-expo-app.mjs +3 -3
  100. package/dist/template/scripts/create-access-token.mjs +1 -1
  101. package/dist/template/scripts/lib/doctor.mjs +10 -7
  102. package/dist/template/scripts/lib/doctor.test.mjs +7 -5
  103. package/dist/template/scripts/lib/embedded-update-registrar.test.ts +22 -7
  104. package/dist/template/scripts/lib/expo-app-configurator.mjs +25 -22
  105. package/dist/template/scripts/lib/expo-app-configurator.test.ts +37 -2
  106. package/dist/template/scripts/lib/ota-client-configurator.mjs +152 -55
  107. package/dist/template/scripts/lib/ota-client-configurator.test.ts +60 -20
  108. package/dist/template/scripts/lib/ota-client-package.mjs +25 -0
  109. package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +90 -32
  110. package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +49 -6
  111. package/dist/template/scripts/tests/device-analytics-migrations.mjs +12 -1
  112. package/dist/template/scripts/tests/device-targeting-activation.mjs +2 -3
  113. package/dist/template/scripts/tests/e2e/client-lifecycle.mjs +161 -0
  114. package/dist/template/scripts/tests/e2e/client-lifecycle.scenario.jsx +465 -0
  115. package/dist/template/scripts/tests/e2e/client-vitest.mts +18 -0
  116. package/dist/template/scripts/tests/e2e/console.mjs +86 -0
  117. package/dist/template/scripts/tests/e2e/delivery.mjs +296 -0
  118. package/dist/template/scripts/tests/e2e/device-favorites.mjs +309 -0
  119. package/dist/template/scripts/tests/e2e/installations.mjs +132 -0
  120. package/dist/template/scripts/tests/e2e/policy.mjs +253 -0
  121. package/dist/template/scripts/tests/e2e/registrar-token.mjs +59 -0
  122. package/dist/template/scripts/tests/e2e/release-matrix.mjs +307 -0
  123. package/dist/template/scripts/tests/e2e/releases.mjs +162 -0
  124. package/dist/template/scripts/tests/e2e/run.mjs +224 -0
  125. package/dist/template/scripts/tests/manifest-identity.sql +7 -5
  126. package/dist/template/scripts/tests/public-distribution-history.mjs +102 -0
  127. package/dist/template/src/client/admin-api.ts +45 -10
  128. package/dist/template/src/client/admin-types.ts +35 -1
  129. package/dist/template/src/client/devices/analytics.tsx +169 -219
  130. package/dist/template/src/client/devices/cohorts.tsx +181 -0
  131. package/dist/template/src/client/devices/device-name.tsx +37 -21
  132. package/dist/template/src/client/devices/favorite-targets.tsx +381 -0
  133. package/dist/template/src/client/devices/registry.tsx +265 -233
  134. package/dist/template/src/client/devices/use-devices-report.test.tsx +98 -0
  135. package/dist/template/src/client/devices/use-devices-report.ts +53 -82
  136. package/dist/template/src/client/devices/version-adoption-chart.tsx +48 -38
  137. package/dist/template/src/client/distribution-control.tsx +98 -53
  138. package/dist/template/src/client/distribution-history.tsx +353 -0
  139. package/dist/template/src/client/guard-action-catalog.tsx +183 -0
  140. package/dist/template/src/client/guard-action-combobox.test.ts +16 -22
  141. package/dist/template/src/client/guard-action-combobox.tsx +134 -234
  142. package/dist/template/src/client/guard-action-options.ts +4 -6
  143. package/dist/template/src/client/i18n/en.json +335 -2
  144. package/dist/template/src/client/i18n/language-switching.test.tsx +233 -0
  145. package/dist/template/src/client/i18n/messages.test.ts +102 -19
  146. package/dist/template/src/client/i18n/messages.ts +31 -16
  147. package/dist/template/src/client/i18n/provider.tsx +6 -3
  148. package/dist/template/src/client/i18n/ru.json +619 -0
  149. package/dist/template/src/client/i18n/uk.json +619 -0
  150. package/dist/template/src/client/i18n/use-formatters.ts +5 -0
  151. package/dist/template/src/client/logout-button.tsx +3 -3
  152. package/dist/template/src/client/policy-draft.ts +138 -0
  153. package/dist/template/src/client/update-audience-editor.tsx +597 -199
  154. package/dist/template/src/client/update-policy-editor.test.ts +101 -29
  155. package/dist/template/src/client/update-policy-editor.tsx +466 -307
  156. package/dist/template/src/client/use-filtered-results.ts +55 -0
  157. package/dist/template/src/server/controllers/manifest.test.ts +23 -3
  158. package/dist/template/src/server/controllers/manifest.ts +15 -1
  159. package/dist/template/src/server/devices/audience.ts +9 -5
  160. package/dist/template/src/server/lib/admin-audience-activation.test.ts +37 -90
  161. package/dist/template/src/server/lib/admin-release-history.test.ts +138 -0
  162. package/dist/template/src/server/lib/admin-updates.ts +160 -534
  163. package/dist/template/src/server/lib/distribution-history.ts +97 -0
  164. package/dist/template/src/server/lib/supabase.js +24 -0
  165. package/dist/template/src/server/lib/supabase.test.ts +38 -1
  166. package/dist/template/src/server/lib/update-policy.test.ts +20 -0
  167. package/dist/template/src/server/lib/update-policy.ts +23 -10
  168. package/dist/template/src/server/manifest/manifest-repository.ts +11 -3
  169. package/dist/template/src/server/manifest/manifest-values.test.ts +2 -0
  170. package/dist/template/src/server/manifest/manifest-values.ts +21 -13
  171. package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +7 -30
  172. package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +2 -1
  173. package/dist/template/tsconfig.json +2 -2
  174. package/dist/template-manifest.json +571 -271
  175. package/package.json +1 -1
  176. package/dist/template/scripts/lib/device-identity.test.ts +0 -29
  177. package/dist/template/scripts/lib/ota-client.test.ts +0 -55
  178. package/dist/template/scripts/lib/ota-update-controller.test.ts +0 -232
  179. package/dist/template/scripts/lib/ota-updates-ui.test.tsx +0 -154
  180. package/dist/template/scripts/tests/ota-client-types.mjs +0 -69
  181. package/dist/template/templates/expo-app/ota-client/README.md +0 -73
  182. package/dist/template/templates/expo-app/ota-client/controller.ts +0 -107
  183. package/dist/template/templates/expo-app/ota-client/device-identity.ts +0 -48
  184. package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +0 -61
  185. package/dist/template/templates/expo-app/ota-client/index.ts +0 -16
  186. package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +0 -97
  187. package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +0 -293
  188. package/dist/template/templates/expo-app/ota-client/runtime.ts +0 -153
  189. package/dist/template/templates/expo-app/ota-client/types.ts +0 -85
  190. package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +0 -25
  191. package/dist/template/templates/expo-app/ota-client/ui/ota-updates.tsx +0 -196
@@ -0,0 +1,156 @@
1
+ // @vitest-environment jsdom
2
+ import { act } from "react";
3
+ import { createRoot, type Root } from "react-dom/client";
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5
+ import { AdminRoleContext } from "@/components/admin/admin-role";
6
+ import UpdatesPage from "./page";
7
+ import UpdateDetailsPage from "./[encodedKey]/page";
8
+
9
+ const api = vi.hoisted(() => ({
10
+ getDistributionHistory: vi.fn(),
11
+ getUpdates: vi.fn(),
12
+ getUpdate: vi.fn(),
13
+ }));
14
+ vi.mock("@/src/client/admin-api", () => api);
15
+ vi.mock("next/navigation", () => ({
16
+ useParams: () => ({ encodedKey: "draft" }),
17
+ useRouter: () => ({ replace: vi.fn() }),
18
+ }));
19
+ vi.mock("@/src/client/update-policy-editor", () => ({ default: () => null }));
20
+ vi.mock("@/src/client/distribution-control", () => ({
21
+ default: () => null,
22
+ DistributionControlBanner: () => null,
23
+ useDistributionControlState: () => ({
24
+ loading: false,
25
+ error: "",
26
+ state: { blocked: false },
27
+ }),
28
+ }));
29
+
30
+ const draft = {
31
+ key: "draft",
32
+ encodedKey: "draft",
33
+ updateId: "878b4c0b-7ef8-45db-9726-63c3418cfea7",
34
+ comment: "First iOS release",
35
+ runtimeVersion: "1.0",
36
+ platform: "ios",
37
+ channel: "preview",
38
+ status: "disabled",
39
+ isNewestInScope: true,
40
+ channelLatest: null,
41
+ policyEditable: true,
42
+ audienceMode: "all",
43
+ policyVersion: 1,
44
+ createdAt: "2026-11-20T12:00:00Z",
45
+ };
46
+ const result = {
47
+ items: [draft],
48
+ total: 1,
49
+ page: 1,
50
+ totalPages: 1,
51
+ filters: { channels: ["preview"], runtimes: ["1.0"] },
52
+ rollbackLockByScope: [],
53
+ };
54
+ let root: Root;
55
+ let host: HTMLDivElement;
56
+
57
+ beforeEach(() => {
58
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
59
+ host = document.createElement("div");
60
+ document.body.append(host);
61
+ root = createRoot(host);
62
+ api.getDistributionHistory.mockResolvedValue({ canWrite: true, scopes: [] });
63
+ api.getUpdates.mockResolvedValue(result);
64
+ api.getUpdate.mockResolvedValue(draft);
65
+ vi.stubGlobal(
66
+ "fetch",
67
+ vi.fn(
68
+ async () =>
69
+ new Response(
70
+ JSON.stringify({
71
+ audience_mode: "all",
72
+ audience_installation_ids: [],
73
+ audience_device_ids: [],
74
+ audience_version: 1,
75
+ }),
76
+ ),
77
+ ),
78
+ );
79
+ });
80
+ afterEach(async () => {
81
+ await act(async () => root.unmount());
82
+ host.remove();
83
+ vi.useRealTimers();
84
+ vi.unstubAllGlobals();
85
+ vi.clearAllMocks();
86
+ });
87
+
88
+ describe("release workflows", () => {
89
+ it("applies filters to the API, retains the last history on error and resets empty results", async () => {
90
+ await act(async () => root.render(<UpdatesPage />));
91
+ expect(host.textContent).toContain(draft.comment);
92
+ const search = host.querySelector<HTMLInputElement>("input[type=search]")!;
93
+ vi.useFakeTimers();
94
+ const typeSearch = (value: string) => act(async () => {
95
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call(search, value);
96
+ search.dispatchEvent(new Event("input", { bubbles: true }));
97
+ });
98
+ const initialSignal = api.getUpdates.mock.lastCall![1] as AbortSignal;
99
+ await typeSearch("Fi");
100
+ await typeSearch("First");
101
+ expect(initialSignal.aborted).toBe(true);
102
+ await act(async () => vi.advanceTimersByTimeAsync(299));
103
+ expect(api.getUpdates).toHaveBeenCalledTimes(1);
104
+ api.getUpdates.mockRejectedValueOnce(new Error("Temporary outage"));
105
+ await act(async () => vi.advanceTimersByTimeAsync(1));
106
+ expect(api.getUpdates).toHaveBeenLastCalledWith(
107
+ expect.objectContaining({ page: 1, q: "First" }),
108
+ expect.any(AbortSignal),
109
+ );
110
+ expect(host.querySelector("[role=alert]")?.textContent).toContain(
111
+ "Showing the previous results.",
112
+ );
113
+ expect(host.textContent).toContain(draft.comment);
114
+ api.getUpdates.mockResolvedValueOnce({ ...result, items: [], total: 0 });
115
+ await act(async () =>
116
+ host.querySelector<HTMLButtonElement>("[role=alert] button")!.click(),
117
+ );
118
+ expect(host.textContent).toContain("No matching releases");
119
+ const reset = [...host.querySelectorAll("button")].find(
120
+ (b) => b.textContent === "Reset",
121
+ )!;
122
+ await act(async () => reset.click());
123
+ expect(api.getUpdates).toHaveBeenLastCalledWith(
124
+ expect.objectContaining({ page: 1, q: "" }),
125
+ expect.any(AbortSignal),
126
+ );
127
+ expect(host.textContent).toContain(draft.comment);
128
+ });
129
+
130
+ it("exposes first-draft activation before a channel pointer exists and keeps viewer controls read-only", async () => {
131
+ const render = (role: string) =>
132
+ root.render(
133
+ <AdminRoleContext.Provider value={role}>
134
+ <UpdateDetailsPage />
135
+ </AdminRoleContext.Provider>,
136
+ );
137
+ await act(async () => render("operator"));
138
+ const buttons = () =>
139
+ [...host.querySelectorAll("button")].map((button) => button.textContent);
140
+ expect(buttons()).toContain("Activate");
141
+ expect(buttons()).toContain("Save audience");
142
+ expect(
143
+ host.querySelector("[role=tab][aria-selected=true]")?.textContent,
144
+ ).toBe("Audience");
145
+ expect(host.querySelector('textarea[aria-label="JSON editor"]')).toBeNull();
146
+
147
+ await act(async () => render("viewer"));
148
+ expect(buttons()).not.toContain("Activate");
149
+ expect(buttons()).not.toContain("Save audience");
150
+ const scopeChoices = host.querySelectorAll<HTMLButtonElement>(
151
+ '[role="radiogroup"][aria-label="Who can receive this OTA"] [role="radio"]',
152
+ );
153
+ expect(scopeChoices).toHaveLength(2);
154
+ expect([...scopeChoices].every((choice) => choice.disabled)).toBe(true);
155
+ });
156
+ });
@@ -0,0 +1,5 @@
1
+ "use client";
2
+
3
+ import { createContext } from "react";
4
+
5
+ export const AdminRoleContext = createContext("viewer");
@@ -1,24 +1,35 @@
1
1
  "use client";
2
- import { LanguageSwitcher } from "@/components/admin/language-switcher";
3
- import { useI18n } from "@/src/client/i18n/provider";
4
2
 
5
3
  import Link from "next/link";
6
4
  import { usePathname, useRouter } from "next/navigation";
7
5
  import { useTheme } from "next-themes";
8
6
  import { useState, type CSSProperties } from "react";
9
7
  import {
10
- Activity,
11
- ArrowUpToLine,
12
8
  Boxes,
13
- ShieldAlert,
14
- Smartphone,
9
+ ChartNoAxesColumnIncreasing,
10
+ Layers3,
15
11
  LogOut,
16
12
  Moon,
13
+ RadioTower,
14
+ ShieldAlert,
17
15
  Sun,
16
+ type LucideIcon,
18
17
  } from "lucide-react";
19
18
  import { adminLogout } from "@/src/client/admin-api";
19
+ import { useI18n } from "@/src/client/i18n/provider";
20
+ import { LanguageSwitcher } from "@/components/admin/language-switcher";
21
+ import { AdminRoleContext } from "@/components/admin/admin-role";
22
+ import { Avatar, AvatarFallback } from "@/components/ui/avatar";
23
+ import {
24
+ Breadcrumb,
25
+ BreadcrumbList,
26
+ BreadcrumbItem,
27
+ BreadcrumbPage,
28
+ BreadcrumbLink,
29
+ BreadcrumbSeparator,
30
+ } from "@/components/ui/breadcrumb";
31
+ import { Separator } from "@/components/ui/separator";
20
32
  import { Button } from "@/components/ui/button";
21
- import { Badge } from "@/components/ui/badge";
22
33
  import {
23
34
  Sidebar,
24
35
  SidebarContent,
@@ -35,48 +46,89 @@ import {
35
46
  SidebarTrigger,
36
47
  useSidebar,
37
48
  } from "@/components/ui/sidebar";
38
- function Navigation() {
39
- const { t } = useI18n();
40
- const navigation = [
41
- { href: "/updates/devices", label: t("Установки"), icon: Smartphone },
42
- { href: "/updates", label: t("OTA-обновления"), icon: ArrowUpToLine },
43
- { href: "/updates/embedded", label: t("Embedded-сборки"), icon: Boxes },
44
- {
45
- href: "/updates/emergency-redirects",
46
- label: t("Аварийные маршруты"),
47
- icon: ShieldAlert,
48
- },
49
- ];
50
49
 
51
- const path = usePathname();
50
+ type Destination = { href: string; label: string; icon: LucideIcon };
51
+ const releases = { href: "/updates", label: "Публикации", icon: Layers3 };
52
+ const groups = [
53
+ {
54
+ label: "Release workspace",
55
+ links: [
56
+ releases,
57
+ { href: "/updates/embedded", label: "Embedded-сборки", icon: Boxes },
58
+ {
59
+ href: "/updates/emergency-redirects",
60
+ label: "Аварийные маршруты",
61
+ icon: ShieldAlert,
62
+ },
63
+ ],
64
+ },
65
+ {
66
+ label: "Analytics",
67
+ links: [
68
+ {
69
+ href: "/updates/devices",
70
+ label: "Установки",
71
+ icon: ChartNoAxesColumnIncreasing,
72
+ },
73
+ ],
74
+ },
75
+ ];
76
+ const destinations: Destination[] = groups.flatMap((group) => group.links);
77
+
78
+ function Navigation({ current }: { current: Destination }) {
79
+ const { t } = useI18n();
52
80
  const { setOpenMobile } = useSidebar();
53
81
  return (
54
- <SidebarMenu>
55
- {navigation.map(({ href, label, icon: Icon }) => (
56
- <SidebarMenuItem key={href}>
57
- <SidebarMenuButton
58
- asChild
59
- isActive={
60
- href === "/updates"
61
- ? path === href ||
62
- !navigation
63
- .slice(0, 1)
64
- .concat(navigation.slice(2))
65
- .some((n) => path.startsWith(n.href))
66
- : path.startsWith(href)
67
- }
68
- tooltip={label}
69
- >
70
- <Link href={href} onClick={() => setOpenMobile(false)}>
71
- <Icon aria-hidden="true" />
72
- <span>{label}</span>
73
- </Link>
74
- </SidebarMenuButton>
75
- </SidebarMenuItem>
82
+ <nav aria-label={t("Навигация")}>
83
+ {groups.map((group) => (
84
+ <SidebarGroup key={group.label} className="mb-2 px-2">
85
+ <SidebarGroupLabel className="h-8 text-xs font-medium text-muted-foreground">
86
+ {t(group.label)}
87
+ </SidebarGroupLabel>
88
+ <SidebarGroupContent>
89
+ <SidebarMenu>
90
+ {group.links.map(({ href, label, icon: Icon }) => (
91
+ <SidebarMenuItem key={href}>
92
+ <SidebarMenuButton
93
+ asChild
94
+ isActive={href === current.href}
95
+ className="min-h-9 gap-2.5 px-3 hover:bg-muted data-[active=true]:bg-sidebar-accent"
96
+ >
97
+ <Link
98
+ href={href}
99
+ aria-current={href === current.href ? "page" : undefined}
100
+ onClick={() => setOpenMobile(false)}
101
+ >
102
+ <Icon aria-hidden="true" />
103
+ <span>{t(label)}</span>
104
+ </Link>
105
+ </SidebarMenuButton>
106
+ </SidebarMenuItem>
107
+ ))}
108
+ </SidebarMenu>
109
+ </SidebarGroupContent>
110
+ </SidebarGroup>
76
111
  ))}
77
- </SidebarMenu>
112
+ </nav>
78
113
  );
79
114
  }
115
+
116
+ function ConsoleBrand() {
117
+ const { setOpenMobile } = useSidebar();
118
+ return (
119
+ <Link
120
+ href="/updates"
121
+ onClick={() => setOpenMobile(false)}
122
+ className="flex w-fit items-center gap-3 rounded-md font-semibold tracking-tight text-foreground"
123
+ >
124
+ <span className="grid size-8 place-items-center rounded-md border border-input bg-card text-foreground">
125
+ <RadioTower className="size-5" aria-hidden="true" />
126
+ </span>
127
+ OTA Console
128
+ </Link>
129
+ );
130
+ }
131
+
80
132
  export function AdminShell({
81
133
  children,
82
134
  session,
@@ -87,10 +139,13 @@ export function AdminShell({
87
139
  const { t } = useI18n();
88
140
  const { resolvedTheme, setTheme } = useTheme();
89
141
  const router = useRouter();
142
+ const path = usePathname();
143
+ const current = destinations.find(({ href }) => path === href) ?? releases;
90
144
  const [busy, setBusy] = useState(false);
91
145
  const [error, setError] = useState("");
92
146
  async function logout() {
93
147
  setBusy(true);
148
+ setError("");
94
149
  try {
95
150
  await adminLogout();
96
151
  router.replace("/login");
@@ -101,82 +156,92 @@ export function AdminShell({
101
156
  }
102
157
  }
103
158
  return (
104
- <SidebarProvider style={{ "--sidebar-width": "14rem" } as CSSProperties}>
159
+ <SidebarProvider style={{ "--sidebar-width": "15.5rem" } as CSSProperties}>
105
160
  <a
106
161
  href="#main-content"
107
162
  className="sr-only focus:not-sr-only focus:fixed focus:left-4 focus:top-4 focus:z-50 focus:rounded focus:bg-card focus:p-3"
108
163
  >
109
164
  {t("К содержимому")}
110
165
  </a>
111
- <Sidebar collapsible="offcanvas">
112
- <SidebarHeader className="h-20 justify-center border-b px-5">
113
- <Link
114
- href="/updates/devices"
115
- className="flex items-center gap-3 font-semibold text-foreground"
116
- >
117
- <span className="flex size-9 items-center justify-center rounded-xl bg-primary text-primary-foreground">
118
- <Activity className="size-5" />
119
- </span>
120
- <span>
121
- OTA Console
122
- <span className="block text-[10px] font-medium uppercase tracking-[.18em] text-muted-foreground">
123
- Release workspace
124
- </span>
125
- </span>
126
- </Link>
166
+ <Sidebar collapsible="offcanvas" variant="sidebar">
167
+ <SidebarHeader className="h-14 justify-center border-b px-5">
168
+ <ConsoleBrand />
127
169
  </SidebarHeader>
128
- <SidebarContent className="p-2">
129
- <SidebarGroup>
130
- <SidebarGroupLabel>{t("Управление")}</SidebarGroupLabel>
131
- <SidebarGroupContent>
132
- <Navigation />
133
- </SidebarGroupContent>
134
- </SidebarGroup>
170
+ <SidebarContent className="px-1 pt-3">
171
+ <Navigation current={current} />
135
172
  </SidebarContent>
136
- <SidebarFooter className="gap-3 border-t p-4">
173
+ <SidebarFooter className="gap-2 border-t p-4">
137
174
  <div className="flex items-center gap-3">
138
- <span className="flex size-9 shrink-0 items-center justify-center rounded-full bg-muted text-sm font-semibold uppercase">
139
- {session.username.slice(0, 2)}
140
- </span>
141
- <div className="min-w-0">
175
+ <Avatar aria-hidden="true">
176
+ <AvatarFallback className="bg-secondary text-xs font-semibold uppercase">
177
+ {session.username.slice(0, 2)}
178
+ </AvatarFallback>
179
+ </Avatar>
180
+ <div className="min-w-0 flex-1">
142
181
  <p className="truncate text-sm font-medium text-foreground">
143
182
  {session.username}
144
183
  </p>
145
- <p className="text-xs text-muted-foreground">{session.role}</p>
184
+ <p className="text-xs text-muted-foreground">{t(session.role)}</p>
146
185
  </div>
186
+ <Button
187
+ variant="ghost"
188
+ size="icon"
189
+ disabled={busy}
190
+ onClick={logout}
191
+ title={t("Выйти")}
192
+ aria-label={busy ? t("Выход…") : t("Выйти")}
193
+ >
194
+ <LogOut />
195
+ </Button>
147
196
  </div>
148
197
  {error && (
149
198
  <p role="alert" className="text-xs text-destructive">
150
199
  {t(error)}
151
200
  </p>
152
201
  )}
153
- <Button
154
- variant="ghost"
155
- className="justify-start"
156
- disabled={busy}
157
- onClick={logout}
158
- >
159
- <LogOut />
160
- {busy ? t("Выход…") : t("Выйти")}
161
- </Button>
162
202
  </SidebarFooter>
163
203
  </Sidebar>
164
- <SidebarInset className="min-w-0 bg-background">
165
- <header className="flex h-16 shrink-0 items-center justify-between gap-4 border-b bg-card/80 px-4 md:px-8">
166
- <div className="flex items-center gap-3">
204
+ <SidebarInset className="min-w-0">
205
+ <header className="sticky top-0 z-20 flex min-h-14 items-center bg-sidebar justify-between gap-2 border-b px-3 sm:px-6 lg:px-8">
206
+ <div className="flex min-w-0 items-center gap-2 text-sm">
167
207
  <SidebarTrigger aria-label={t("Открыть или скрыть навигацию")} />
168
- <span className="text-sm text-muted-foreground">
169
- {t("Управление обновлениями")}
170
- </span>
208
+ <Separator
209
+ orientation="vertical"
210
+ className="mx-1 data-[orientation=vertical]:h-4"
211
+ />
212
+ <Breadcrumb>
213
+ <BreadcrumbList>
214
+ <BreadcrumbItem className="hidden sm:inline-flex">
215
+ <BreadcrumbLink asChild>
216
+ <Link href="/updates">OTA Console</Link>
217
+ </BreadcrumbLink>
218
+ </BreadcrumbItem>
219
+ <BreadcrumbSeparator className="hidden sm:inline-flex" />
220
+ <BreadcrumbItem>
221
+ {path === current.href ? (
222
+ <BreadcrumbPage>{t(current.label)}</BreadcrumbPage>
223
+ ) : (
224
+ <BreadcrumbLink asChild>
225
+ <Link href={current.href}>{t(current.label)}</Link>
226
+ </BreadcrumbLink>
227
+ )}
228
+ </BreadcrumbItem>
229
+ {path !== current.href && (
230
+ <>
231
+ <BreadcrumbSeparator />
232
+ <BreadcrumbItem>
233
+ <BreadcrumbPage>{t("Release")}</BreadcrumbPage>
234
+ </BreadcrumbItem>
235
+ </>
236
+ )}
237
+ </BreadcrumbList>
238
+ </Breadcrumb>
171
239
  </div>
172
- <div className="flex items-center gap-2">
240
+ <div className="flex shrink-0 items-center gap-1">
173
241
  <LanguageSwitcher />
174
- <Badge variant="outline" className="hidden sm:inline-flex">
175
- Expo OTA
176
- </Badge>
177
242
  <Button
178
243
  variant="ghost"
179
- size="icon"
244
+ size="icon-sm"
180
245
  aria-label={t("Переключить светлую и тёмную тему")}
181
246
  onClick={() =>
182
247
  setTheme(resolvedTheme === "dark" ? "light" : "dark")
@@ -187,8 +252,14 @@ export function AdminShell({
187
252
  </Button>
188
253
  </div>
189
254
  </header>
190
- <div id="main-content" className="min-w-0 flex-1">
191
- {children}
255
+ <div
256
+ id="main-content"
257
+ tabIndex={-1}
258
+ className="min-w-0 flex-1 outline-none"
259
+ >
260
+ <AdminRoleContext.Provider value={session.role}>
261
+ {children}
262
+ </AdminRoleContext.Provider>
192
263
  </div>
193
264
  </SidebarInset>
194
265
  </SidebarProvider>
@@ -0,0 +1,123 @@
1
+ "use client";
2
+
3
+ import {
4
+ createContext,
5
+ useContext,
6
+ useEffect,
7
+ useRef,
8
+ useState,
9
+ type ReactNode,
10
+ } from "react";
11
+ import { usePathname } from "next/navigation";
12
+ import { TriangleAlert } from "lucide-react";
13
+ import { statusTones } from "@/components/ui/status-tones";
14
+ import { Button } from "@/components/ui/button";
15
+ import {
16
+ Dialog,
17
+ DialogContent,
18
+ DialogDescription,
19
+ DialogFooter,
20
+ DialogHeader,
21
+ DialogTitle,
22
+ } from "@/components/ui/dialog";
23
+ import { useI18n } from "@/src/client/i18n/provider";
24
+
25
+ type Confirm = (
26
+ action: string,
27
+ description: string,
28
+ destructive?: boolean,
29
+ ) => Promise<boolean>;
30
+ const ConfirmContext = createContext<Confirm>(async () => false);
31
+
32
+ export const useConfirmAction = () => useContext(ConfirmContext);
33
+
34
+ export function ConfirmActionProvider({ children }: { children: ReactNode }) {
35
+ const path = usePathname();
36
+ return <PageConfirmations key={path}>{children}</PageConfirmations>;
37
+ }
38
+
39
+ function PageConfirmations({ children }: { children: ReactNode }) {
40
+ const { t } = useI18n();
41
+ const [prompt, setPrompt] = useState<{
42
+ action: string;
43
+ description: string;
44
+ destructive: boolean;
45
+ } | null>(null);
46
+ const pending = useRef<((value: boolean) => void) | null>(null);
47
+ const trigger = useRef<HTMLElement | null>(null);
48
+ const cancel = useRef<HTMLButtonElement>(null);
49
+
50
+ useEffect(() => () => pending.current?.(false), []);
51
+
52
+ const confirm: Confirm = (action, description, destructive = false) => {
53
+ if (pending.current) return Promise.resolve(false);
54
+ trigger.current =
55
+ document.activeElement instanceof HTMLElement
56
+ ? document.activeElement
57
+ : null;
58
+ setPrompt({ action, description, destructive });
59
+ return new Promise<boolean>((resolve) => {
60
+ pending.current = resolve;
61
+ });
62
+ };
63
+
64
+ function finish(accepted: boolean) {
65
+ const resolve = pending.current;
66
+ pending.current = null;
67
+ setPrompt(null);
68
+ resolve?.(accepted);
69
+ }
70
+
71
+ return (
72
+ <ConfirmContext.Provider value={confirm}>
73
+ {children}
74
+ <Dialog
75
+ open={Boolean(prompt)}
76
+ onOpenChange={(open) => {
77
+ if (!open) finish(false);
78
+ }}
79
+ >
80
+ <DialogContent
81
+ showCloseButton={false}
82
+ onOpenAutoFocus={(event) => {
83
+ event.preventDefault();
84
+ cancel.current?.focus();
85
+ }}
86
+ onCloseAutoFocus={(event) => {
87
+ event.preventDefault();
88
+ trigger.current?.focus();
89
+ }}
90
+ >
91
+ <DialogHeader>
92
+ {prompt?.destructive && (
93
+ <span
94
+ className={`mb-1 inline-flex size-10 items-center justify-center self-center rounded-lg border sm:self-start ${statusTones.destructive}`}
95
+ >
96
+ <TriangleAlert className="size-5" aria-hidden="true" />
97
+ </span>
98
+ )}
99
+ <DialogTitle>{prompt?.action}</DialogTitle>
100
+ <DialogDescription className="break-words">
101
+ {prompt?.description}
102
+ </DialogDescription>
103
+ </DialogHeader>
104
+ <DialogFooter>
105
+ <Button
106
+ ref={cancel}
107
+ variant="outline"
108
+ onClick={() => finish(false)}
109
+ >
110
+ {t("Отменить")}
111
+ </Button>
112
+ <Button
113
+ variant={prompt?.destructive ? "destructive" : "default"}
114
+ onClick={() => finish(true)}
115
+ >
116
+ {prompt?.action}
117
+ </Button>
118
+ </DialogFooter>
119
+ </DialogContent>
120
+ </Dialog>
121
+ </ConfirmContext.Provider>
122
+ );
123
+ }
@@ -1,25 +1,36 @@
1
1
  "use client";
2
2
 
3
+ import { Languages } from "lucide-react";
4
+ import { NativeSelect } from "@/components/ui/native-select";
3
5
  import { useI18n } from "@/src/client/i18n/provider";
4
6
  import { resolveLocale } from "@/src/client/i18n/messages";
5
7
 
6
8
  export function LanguageSwitcher() {
7
- const { locale, setLocale } = useI18n();
8
- const label = locale === "en" ? "Interface language" : "Язык интерфейса";
9
+ const { locale, setLocale, t } = useI18n();
10
+ const label = t("Interface language");
9
11
  return (
10
- <select
11
- aria-label={label}
12
- title={label}
13
- value={locale}
14
- onChange={(event) => setLocale(resolveLocale(event.target.value))}
15
- className="h-9 rounded-md border border-input bg-background px-2 text-sm text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
16
- >
17
- <option value="en" lang="en">
18
- English
19
- </option>
20
- <option value="ru" lang="ru">
21
- Русский
22
- </option>
23
- </select>
12
+ <div className="relative">
13
+ <Languages
14
+ aria-hidden="true"
15
+ className="pointer-events-none absolute left-2.5 top-1/2 z-10 size-4 -translate-y-1/2 text-muted-foreground"
16
+ />
17
+ <NativeSelect
18
+ aria-label={label}
19
+ title={label}
20
+ value={locale}
21
+ onChange={(event) => setLocale(resolveLocale(event.target.value))}
22
+ className="border-transparent bg-transparent pl-8 hover:border-input"
23
+ >
24
+ <option value="en" lang="en">
25
+ English
26
+ </option>
27
+ <option value="ru" lang="ru">
28
+ Русский
29
+ </option>
30
+ <option value="uk" lang="uk">
31
+ Українська
32
+ </option>
33
+ </NativeSelect>
34
+ </div>
24
35
  );
25
36
  }