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.
- package/README.md +4 -2
- package/dist/template/Dockerfile +4 -6
- package/dist/template/README.md +4 -9
- package/dist/template/app/api/admin/device-favorites/route.test.ts +125 -0
- package/dist/template/app/api/admin/device-favorites/route.ts +91 -0
- package/dist/template/app/api/admin/distribution-history/restore/route.ts +39 -0
- package/dist/template/app/api/admin/distribution-history/route.test.ts +55 -0
- package/dist/template/app/api/admin/distribution-history/route.ts +24 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +2 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +2 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +2 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +2 -1
- package/dist/template/app/api/admin/updates/route.test.ts +21 -0
- package/dist/template/app/api/admin/updates/route.ts +12 -1
- package/dist/template/app/globals.css +65 -68
- package/dist/template/app/login/page.tsx +66 -42
- package/dist/template/app/updates/[encodedKey]/page.tsx +375 -263
- package/dist/template/app/updates/devices/page.tsx +188 -152
- package/dist/template/app/updates/embedded/page.tsx +63 -29
- package/dist/template/app/updates/emergency-redirects/page.tsx +93 -58
- package/dist/template/app/updates/layout.tsx +2 -1
- package/dist/template/app/updates/page.tsx +381 -283
- package/dist/template/app/updates/releases.test.tsx +156 -0
- package/dist/template/components/admin/admin-role.ts +5 -0
- package/dist/template/components/admin/admin-shell.tsx +166 -101
- package/dist/template/components/admin/confirm-action.tsx +123 -0
- package/dist/template/components/admin/language-switcher.tsx +25 -17
- package/dist/template/components/admin/release-badges.test.tsx +50 -0
- package/dist/template/components/admin/release-badges.tsx +101 -0
- package/dist/template/components/ui/alert.tsx +10 -3
- package/dist/template/components/ui/avatar.tsx +108 -0
- package/dist/template/components/ui/badge.tsx +2 -2
- package/dist/template/components/ui/breadcrumb.tsx +108 -0
- package/dist/template/components/ui/button.tsx +5 -5
- package/dist/template/components/ui/card.tsx +2 -2
- package/dist/template/components/ui/chart.tsx +1 -1
- package/dist/template/components/ui/collapsible.tsx +7 -0
- package/dist/template/components/ui/empty.tsx +103 -0
- package/dist/template/components/ui/field.tsx +248 -0
- package/dist/template/components/ui/input-group.tsx +170 -0
- package/dist/template/components/ui/input.tsx +1 -1
- package/dist/template/components/ui/native-select.tsx +1 -1
- package/dist/template/components/ui/radio-group.tsx +41 -0
- package/dist/template/components/ui/status-tones.ts +15 -0
- package/dist/template/components/ui/table.tsx +1 -1
- package/dist/template/components/ui/textarea.tsx +1 -1
- package/dist/template/docs/admin-ui.md +7 -3
- package/dist/template/docs/device-targeting.md +2 -7
- package/dist/template/docs/doctor.md +2 -2
- package/dist/template/docs/expo-app-setup.md +9 -27
- package/dist/template/docs/getting-started.md +3 -4
- package/dist/template/docs/installation-telemetry.md +2 -8
- package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +5 -0
- package/dist/template/docs/migrations/2026-11-25-device-favorites.sql +53 -0
- package/dist/template/docs/migrations/2026-11-25-download-on-postpone.sql +5 -0
- package/dist/template/docs/migrations/2026-11-25-public-distribution-history.sql +283 -0
- package/dist/template/docs/migrations/schema.sql +349 -0
- package/dist/template/docs/npm-installer.md +3 -3
- package/dist/template/docs/operations-guide.md +8 -6
- package/dist/template/docs/ota-client-lifecycle.md +30 -68
- package/dist/template/docs/ota-update-policy.md +9 -20
- package/dist/template/docs/ru/admin-ui.md +7 -3
- package/dist/template/docs/ru/device-targeting.md +2 -2
- package/dist/template/docs/ru/doctor.md +2 -2
- package/dist/template/docs/ru/expo-app-setup.md +9 -9
- package/dist/template/docs/ru/getting-started.md +3 -3
- package/dist/template/docs/ru/installation-telemetry.md +2 -2
- package/dist/template/docs/ru/npm-installer.md +3 -3
- package/dist/template/docs/ru/operations-guide.md +8 -3
- package/dist/template/docs/ru/ota-client-lifecycle.md +30 -35
- package/dist/template/docs/ru/ota-update-policy.md +9 -7
- package/dist/template/docs/ru/publishing-npm-installer.md +2 -2
- package/dist/template/docs/uk/admin-ui.md +7 -3
- package/dist/template/docs/uk/device-targeting.md +2 -2
- package/dist/template/docs/uk/doctor.md +2 -2
- package/dist/template/docs/uk/expo-app-setup.md +9 -9
- package/dist/template/docs/uk/getting-started.md +3 -3
- package/dist/template/docs/uk/installation-telemetry.md +2 -2
- package/dist/template/docs/uk/npm-installer.md +3 -3
- package/dist/template/docs/uk/operations-guide.md +8 -3
- package/dist/template/docs/uk/ota-client-lifecycle.md +30 -35
- package/dist/template/docs/uk/ota-update-policy.md +9 -7
- package/dist/template/docs/uk/publishing-npm-installer.md +2 -2
- package/dist/template/lib/audience-ids.ts +4 -0
- package/dist/template/package-lock.json +46 -0
- package/dist/template/package.json +3 -1
- package/dist/template/scripts/configure-expo-app.mjs +3 -3
- package/dist/template/scripts/create-access-token.mjs +1 -1
- package/dist/template/scripts/lib/doctor.mjs +10 -7
- package/dist/template/scripts/lib/doctor.test.mjs +7 -5
- package/dist/template/scripts/lib/embedded-update-registrar.test.ts +22 -7
- package/dist/template/scripts/lib/expo-app-configurator.mjs +25 -22
- package/dist/template/scripts/lib/expo-app-configurator.test.ts +37 -2
- package/dist/template/scripts/lib/ota-client-configurator.mjs +152 -55
- package/dist/template/scripts/lib/ota-client-configurator.test.ts +60 -20
- package/dist/template/scripts/lib/ota-client-package.mjs +25 -0
- package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +90 -32
- package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +49 -6
- package/dist/template/scripts/tests/device-analytics-migrations.mjs +12 -1
- package/dist/template/scripts/tests/device-targeting-activation.mjs +2 -3
- package/dist/template/scripts/tests/e2e/client-lifecycle.mjs +161 -0
- package/dist/template/scripts/tests/e2e/client-lifecycle.scenario.jsx +465 -0
- package/dist/template/scripts/tests/e2e/client-vitest.mts +18 -0
- package/dist/template/scripts/tests/e2e/console.mjs +86 -0
- package/dist/template/scripts/tests/e2e/delivery.mjs +296 -0
- package/dist/template/scripts/tests/e2e/device-favorites.mjs +309 -0
- package/dist/template/scripts/tests/e2e/installations.mjs +132 -0
- package/dist/template/scripts/tests/e2e/policy.mjs +253 -0
- package/dist/template/scripts/tests/e2e/registrar-token.mjs +59 -0
- package/dist/template/scripts/tests/e2e/release-matrix.mjs +307 -0
- package/dist/template/scripts/tests/e2e/releases.mjs +162 -0
- package/dist/template/scripts/tests/e2e/run.mjs +224 -0
- package/dist/template/scripts/tests/manifest-identity.sql +7 -5
- package/dist/template/scripts/tests/public-distribution-history.mjs +102 -0
- package/dist/template/src/client/admin-api.ts +45 -10
- package/dist/template/src/client/admin-types.ts +35 -1
- package/dist/template/src/client/devices/analytics.tsx +168 -231
- package/dist/template/src/client/devices/cohorts.tsx +181 -0
- package/dist/template/src/client/devices/device-name.tsx +37 -23
- package/dist/template/src/client/devices/favorite-targets.tsx +381 -0
- package/dist/template/src/client/devices/registry.tsx +258 -245
- package/dist/template/src/client/devices/use-devices-report.test.tsx +98 -0
- package/dist/template/src/client/devices/use-devices-report.ts +53 -82
- package/dist/template/src/client/devices/version-adoption-chart.tsx +47 -49
- package/dist/template/src/client/distribution-control.tsx +89 -57
- package/dist/template/src/client/distribution-history.tsx +353 -0
- package/dist/template/src/client/guard-action-catalog.tsx +183 -0
- package/dist/template/src/client/guard-action-combobox.test.ts +16 -22
- package/dist/template/src/client/guard-action-combobox.tsx +133 -239
- package/dist/template/src/client/guard-action-options.ts +4 -6
- package/dist/template/src/client/i18n/en.json +133 -2
- package/dist/template/src/client/i18n/language-switching.test.tsx +12 -3
- package/dist/template/src/client/i18n/ru.json +133 -2
- package/dist/template/src/client/i18n/uk.json +133 -2
- package/dist/template/src/client/logout-button.tsx +3 -3
- package/dist/template/src/client/policy-draft.ts +138 -0
- package/dist/template/src/client/update-audience-editor.tsx +597 -206
- package/dist/template/src/client/update-policy-editor.test.ts +101 -29
- package/dist/template/src/client/update-policy-editor.tsx +454 -320
- package/dist/template/src/client/use-filtered-results.ts +55 -0
- package/dist/template/src/server/controllers/manifest.test.ts +23 -3
- package/dist/template/src/server/controllers/manifest.ts +15 -1
- package/dist/template/src/server/devices/audience.ts +9 -5
- package/dist/template/src/server/lib/admin-audience-activation.test.ts +37 -90
- package/dist/template/src/server/lib/admin-release-history.test.ts +138 -0
- package/dist/template/src/server/lib/admin-updates.ts +160 -534
- package/dist/template/src/server/lib/distribution-history.ts +97 -0
- package/dist/template/src/server/lib/supabase.js +24 -0
- package/dist/template/src/server/lib/supabase.test.ts +38 -1
- package/dist/template/src/server/lib/update-policy.test.ts +20 -0
- package/dist/template/src/server/lib/update-policy.ts +23 -10
- package/dist/template/src/server/manifest/manifest-repository.ts +11 -3
- package/dist/template/src/server/manifest/manifest-values.test.ts +2 -0
- package/dist/template/src/server/manifest/manifest-values.ts +21 -13
- package/dist/template/templates/expo-app/scripts/ota-publish/api/database-client.mjs +7 -30
- package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +2 -1
- package/dist/template/tsconfig.json +2 -2
- package/dist/template-manifest.json +446 -301
- package/package.json +1 -1
- package/dist/template/scripts/lib/device-identity.test.ts +0 -29
- package/dist/template/scripts/lib/ota-client.test.ts +0 -55
- package/dist/template/scripts/lib/ota-update-controller.test.ts +0 -232
- package/dist/template/scripts/lib/ota-updates-ui.test.tsx +0 -154
- package/dist/template/scripts/tests/ota-client-types.mjs +0 -69
- package/dist/template/templates/expo-app/ota-client/README.md +0 -73
- package/dist/template/templates/expo-app/ota-client/controller.ts +0 -107
- package/dist/template/templates/expo-app/ota-client/device-identity.ts +0 -48
- package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +0 -61
- package/dist/template/templates/expo-app/ota-client/index.ts +0 -16
- package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.ts +0 -97
- package/dist/template/templates/expo-app/ota-client/model/update-controller.ts +0 -293
- package/dist/template/templates/expo-app/ota-client/runtime.ts +0 -153
- package/dist/template/templates/expo-app/ota-client/types.ts +0 -85
- package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.tsx +0 -25
- 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
|
+
});
|
|
@@ -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
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
<
|
|
55
|
-
{
|
|
56
|
-
<
|
|
57
|
-
<
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
</
|
|
112
|
+
</nav>
|
|
113
|
+
);
|
|
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>
|
|
78
129
|
);
|
|
79
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,88 +156,92 @@ export function AdminShell({
|
|
|
101
156
|
}
|
|
102
157
|
}
|
|
103
158
|
return (
|
|
104
|
-
<SidebarProvider
|
|
105
|
-
style={{ "--sidebar-width": "14rem" } as CSSProperties}
|
|
106
|
-
>
|
|
159
|
+
<SidebarProvider style={{ "--sidebar-width": "15.5rem" } as CSSProperties}>
|
|
107
160
|
<a
|
|
108
161
|
href="#main-content"
|
|
109
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"
|
|
110
163
|
>
|
|
111
164
|
{t("К содержимому")}
|
|
112
165
|
</a>
|
|
113
|
-
<Sidebar collapsible="offcanvas">
|
|
114
|
-
<SidebarHeader className="h-
|
|
115
|
-
<
|
|
116
|
-
href="/updates/devices"
|
|
117
|
-
className="flex items-center gap-3 font-semibold text-foreground"
|
|
118
|
-
>
|
|
119
|
-
<span className="flex size-9 items-center justify-center rounded-xl bg-primary text-primary-foreground">
|
|
120
|
-
<Activity className="size-5" />
|
|
121
|
-
</span>
|
|
122
|
-
<span>
|
|
123
|
-
OTA Console
|
|
124
|
-
<span className="block text-[10px] font-medium uppercase tracking-[.18em] text-muted-foreground">
|
|
125
|
-
{t("Release workspace")}
|
|
126
|
-
</span>
|
|
127
|
-
</span>
|
|
128
|
-
</Link>
|
|
166
|
+
<Sidebar collapsible="offcanvas" variant="sidebar">
|
|
167
|
+
<SidebarHeader className="h-14 justify-center border-b px-5">
|
|
168
|
+
<ConsoleBrand />
|
|
129
169
|
</SidebarHeader>
|
|
130
|
-
<SidebarContent className="
|
|
131
|
-
<
|
|
132
|
-
<SidebarGroupLabel>{t("Управление")}</SidebarGroupLabel>
|
|
133
|
-
<SidebarGroupContent>
|
|
134
|
-
<Navigation />
|
|
135
|
-
</SidebarGroupContent>
|
|
136
|
-
</SidebarGroup>
|
|
170
|
+
<SidebarContent className="px-1 pt-3">
|
|
171
|
+
<Navigation current={current} />
|
|
137
172
|
</SidebarContent>
|
|
138
|
-
<SidebarFooter className="gap-
|
|
173
|
+
<SidebarFooter className="gap-2 border-t p-4">
|
|
139
174
|
<div className="flex items-center gap-3">
|
|
140
|
-
<
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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">
|
|
144
181
|
<p className="truncate text-sm font-medium text-foreground">
|
|
145
182
|
{session.username}
|
|
146
183
|
</p>
|
|
147
|
-
<p className="text-xs text-muted-foreground">
|
|
148
|
-
{t(session.role)}
|
|
149
|
-
</p>
|
|
184
|
+
<p className="text-xs text-muted-foreground">{t(session.role)}</p>
|
|
150
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>
|
|
151
196
|
</div>
|
|
152
197
|
{error && (
|
|
153
198
|
<p role="alert" className="text-xs text-destructive">
|
|
154
199
|
{t(error)}
|
|
155
200
|
</p>
|
|
156
201
|
)}
|
|
157
|
-
<Button
|
|
158
|
-
variant="ghost"
|
|
159
|
-
className="justify-start"
|
|
160
|
-
disabled={busy}
|
|
161
|
-
onClick={logout}
|
|
162
|
-
>
|
|
163
|
-
<LogOut />
|
|
164
|
-
{busy ? t("Выход…") : t("Выйти")}
|
|
165
|
-
</Button>
|
|
166
202
|
</SidebarFooter>
|
|
167
203
|
</Sidebar>
|
|
168
|
-
<SidebarInset className="min-w-0
|
|
169
|
-
<header className="flex h-
|
|
170
|
-
<div className="flex items-center gap-
|
|
171
|
-
<SidebarTrigger
|
|
172
|
-
|
|
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">
|
|
207
|
+
<SidebarTrigger aria-label={t("Открыть или скрыть навигацию")} />
|
|
208
|
+
<Separator
|
|
209
|
+
orientation="vertical"
|
|
210
|
+
className="mx-1 data-[orientation=vertical]:h-4"
|
|
173
211
|
/>
|
|
174
|
-
<
|
|
175
|
-
|
|
176
|
-
|
|
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>
|
|
177
239
|
</div>
|
|
178
|
-
<div className="flex items-center gap-
|
|
240
|
+
<div className="flex shrink-0 items-center gap-1">
|
|
179
241
|
<LanguageSwitcher />
|
|
180
|
-
<Badge variant="outline" className="hidden sm:inline-flex">
|
|
181
|
-
Expo OTA
|
|
182
|
-
</Badge>
|
|
183
242
|
<Button
|
|
184
243
|
variant="ghost"
|
|
185
|
-
size="icon"
|
|
244
|
+
size="icon-sm"
|
|
186
245
|
aria-label={t("Переключить светлую и тёмную тему")}
|
|
187
246
|
onClick={() =>
|
|
188
247
|
setTheme(resolvedTheme === "dark" ? "light" : "dark")
|
|
@@ -193,8 +252,14 @@ export function AdminShell({
|
|
|
193
252
|
</Button>
|
|
194
253
|
</div>
|
|
195
254
|
</header>
|
|
196
|
-
<div
|
|
197
|
-
|
|
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>
|
|
198
263
|
</div>
|
|
199
264
|
</SidebarInset>
|
|
200
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
|
+
}
|