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.
- package/README.md +4 -2
- package/dist/template/Dockerfile +4 -6
- package/dist/template/README.md +5 -10
- 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 +382 -248
- package/dist/template/app/updates/devices/page.tsx +187 -145
- package/dist/template/app/updates/embedded/page.tsx +80 -34
- package/dist/template/app/updates/emergency-redirects/page.tsx +138 -71
- package/dist/template/app/updates/layout.tsx +2 -1
- package/dist/template/app/updates/page.tsx +385 -274
- 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 -95
- package/dist/template/components/admin/confirm-action.tsx +123 -0
- package/dist/template/components/admin/language-switcher.tsx +27 -16
- 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/dialog.tsx +13 -4
- 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/sheet.tsx +6 -2
- package/dist/template/components/ui/sidebar.tsx +62 -17
- 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 +22 -24
- package/dist/template/docs/device-targeting.md +6 -12
- 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/getting-started.ru.md +11 -544
- package/dist/template/docs/index.md +1 -1
- package/dist/template/docs/installation-telemetry.md +6 -12
- 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 +9 -7
- package/dist/template/docs/ota-client-lifecycle.md +30 -68
- package/dist/template/docs/ota-emergency-recovery.md +34 -57
- package/dist/template/docs/ota-update-policy.md +9 -20
- package/dist/template/docs/ru/admin-ui.md +33 -0
- package/dist/template/docs/ru/device-targeting.md +59 -0
- package/dist/template/docs/ru/doctor.md +98 -0
- package/dist/template/docs/ru/expo-app-setup.md +497 -0
- package/dist/template/docs/ru/getting-started.md +391 -0
- package/dist/template/docs/ru/index.md +50 -0
- package/dist/template/docs/ru/installation-telemetry.md +125 -0
- package/dist/template/docs/ru/npm-installer.md +71 -0
- package/dist/template/docs/ru/operations-guide.md +322 -0
- package/dist/template/docs/ru/ota-client-lifecycle.md +162 -0
- package/dist/template/docs/ru/ota-emergency-recovery.md +108 -0
- package/dist/template/docs/ru/ota-update-policy.md +69 -0
- package/dist/template/docs/ru/publishing-npm-installer.md +49 -0
- package/dist/template/docs/ru/supabase-setup.md +120 -0
- package/dist/template/docs/uk/admin-ui.md +33 -0
- package/dist/template/docs/uk/device-targeting.md +59 -0
- package/dist/template/docs/uk/doctor.md +98 -0
- package/dist/template/docs/uk/expo-app-setup.md +497 -0
- package/dist/template/docs/uk/getting-started.md +391 -0
- package/dist/template/docs/uk/index.md +50 -0
- package/dist/template/docs/uk/installation-telemetry.md +125 -0
- package/dist/template/docs/uk/npm-installer.md +71 -0
- package/dist/template/docs/uk/operations-guide.md +322 -0
- package/dist/template/docs/uk/ota-client-lifecycle.md +162 -0
- package/dist/template/docs/uk/ota-emergency-recovery.md +108 -0
- package/dist/template/docs/uk/ota-update-policy.md +69 -0
- package/dist/template/docs/uk/publishing-npm-installer.md +49 -0
- package/dist/template/docs/uk/supabase-setup.md +120 -0
- package/dist/template/lib/audience-ids.ts +4 -0
- package/dist/template/package-lock.json +46 -0
- package/dist/template/package.json +4 -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 +169 -219
- package/dist/template/src/client/devices/cohorts.tsx +181 -0
- package/dist/template/src/client/devices/device-name.tsx +37 -21
- package/dist/template/src/client/devices/favorite-targets.tsx +381 -0
- package/dist/template/src/client/devices/registry.tsx +265 -233
- 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 +48 -38
- package/dist/template/src/client/distribution-control.tsx +98 -53
- 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 +134 -234
- package/dist/template/src/client/guard-action-options.ts +4 -6
- package/dist/template/src/client/i18n/en.json +335 -2
- package/dist/template/src/client/i18n/language-switching.test.tsx +233 -0
- package/dist/template/src/client/i18n/messages.test.ts +102 -19
- package/dist/template/src/client/i18n/messages.ts +31 -16
- package/dist/template/src/client/i18n/provider.tsx +6 -3
- package/dist/template/src/client/i18n/ru.json +619 -0
- package/dist/template/src/client/i18n/uk.json +619 -0
- package/dist/template/src/client/i18n/use-formatters.ts +5 -0
- 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 -199
- package/dist/template/src/client/update-policy-editor.test.ts +101 -29
- package/dist/template/src/client/update-policy-editor.tsx +466 -307
- 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 +571 -271
- 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
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useConfirmAction } from "@/components/admin/confirm-action";
|
|
3
|
+
import type { TranslationMessage } from "@/src/client/i18n/messages";
|
|
2
4
|
import { useI18n } from "@/src/client/i18n/provider";
|
|
3
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";
|
|
4
9
|
import { Textarea } from "@/components/ui/textarea";
|
|
5
10
|
|
|
11
|
+
import { statusTones } from "@/components/ui/status-tones";
|
|
12
|
+
import { cn } from "@/lib/utils";
|
|
6
13
|
import { Button } from "@/components/ui/button";
|
|
7
14
|
import { Badge } from "@/components/ui/badge";
|
|
8
15
|
import { Card } from "@/components/ui/card";
|
|
@@ -17,7 +24,6 @@ import type { DistributionControlResponse } from "./admin-types";
|
|
|
17
24
|
import { useCallback, useEffect, useState } from "react";
|
|
18
25
|
|
|
19
26
|
export function useDistributionControlState() {
|
|
20
|
-
const { t } = useI18n();
|
|
21
27
|
const [state, setState] = useState<DistributionControlResponse | null>(null);
|
|
22
28
|
const [loading, setLoading] = useState(true);
|
|
23
29
|
const [error, setError] = useState("");
|
|
@@ -46,11 +52,14 @@ export function useDistributionControlState() {
|
|
|
46
52
|
return () => window.clearTimeout(timeoutId);
|
|
47
53
|
}, [refresh]);
|
|
48
54
|
|
|
49
|
-
return { state, setState, loading, error
|
|
55
|
+
return { state, setState, loading, error, setError, refresh };
|
|
50
56
|
}
|
|
51
57
|
|
|
52
|
-
function formatChangedBy(
|
|
53
|
-
|
|
58
|
+
function formatChangedBy(
|
|
59
|
+
state: DistributionControlResponse,
|
|
60
|
+
t: ReturnType<typeof useI18n>["t"],
|
|
61
|
+
): string {
|
|
62
|
+
const role = state.changedBy.role ? ` (${t(state.changedBy.role)})` : "";
|
|
54
63
|
return `${state.changedBy.label}${role}`;
|
|
55
64
|
}
|
|
56
65
|
|
|
@@ -66,48 +75,64 @@ export function DistributionControlBanner({
|
|
|
66
75
|
const { t, formatLocale } = useI18n();
|
|
67
76
|
if (loading) {
|
|
68
77
|
return (
|
|
69
|
-
<
|
|
70
|
-
|
|
71
|
-
|
|
78
|
+
<Skeleton className="h-12" role="status">
|
|
79
|
+
<span className="sr-only">
|
|
80
|
+
{t("Проверка глобального статуса OTA…")}
|
|
81
|
+
</span>
|
|
82
|
+
</Skeleton>
|
|
72
83
|
);
|
|
73
84
|
}
|
|
74
|
-
|
|
75
85
|
if (error || !state) {
|
|
76
86
|
return (
|
|
77
|
-
<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
<Alert variant="destructive">
|
|
88
|
+
<ShieldAlert />
|
|
89
|
+
<AlertTitle>
|
|
90
|
+
{t(
|
|
91
|
+
"Глобальный статус OTA недоступен. Распространяющие действия отключены до восстановления связи.",
|
|
92
|
+
)}
|
|
93
|
+
</AlertTitle>
|
|
94
|
+
{error && <AlertDescription>{t(error)}</AlertDescription>}
|
|
95
|
+
</Alert>
|
|
83
96
|
);
|
|
84
97
|
}
|
|
85
|
-
|
|
86
98
|
if (!state.blocked) {
|
|
87
99
|
return null;
|
|
88
100
|
}
|
|
89
101
|
|
|
90
102
|
return (
|
|
91
|
-
<
|
|
92
|
-
<
|
|
93
|
-
<
|
|
94
|
-
<
|
|
95
|
-
{
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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>
|
|
99
114
|
);
|
|
100
115
|
}
|
|
101
116
|
|
|
102
|
-
export default function DistributionControl(
|
|
117
|
+
export default function DistributionControl({
|
|
118
|
+
onAvailabilityChange,
|
|
119
|
+
}: {
|
|
120
|
+
onAvailabilityChange?: (blocked: boolean) => void;
|
|
121
|
+
}) {
|
|
122
|
+
const confirmAction = useConfirmAction();
|
|
103
123
|
const { t, formatLocale } = useI18n();
|
|
104
|
-
const { state, setState, loading, error,
|
|
124
|
+
const { state, setState, loading, error, refresh } =
|
|
105
125
|
useDistributionControlState();
|
|
126
|
+
const [actionError, setActionError] = useState("");
|
|
106
127
|
const [reason, setReason] = useState("");
|
|
107
128
|
const [saving, setSaving] = useState(false);
|
|
108
|
-
const [message, setMessage] = useState("");
|
|
129
|
+
const [message, setMessage] = useState<TranslationMessage>("");
|
|
109
130
|
const [expanded, setExpanded] = useState(false);
|
|
110
131
|
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
onAvailabilityChange?.(loading || !!error || !state || state.blocked);
|
|
134
|
+
}, [loading, error, state, onAvailabilityChange]);
|
|
135
|
+
|
|
111
136
|
const changeState = async (blocked: boolean) => {
|
|
112
137
|
if (!state) {
|
|
113
138
|
return;
|
|
@@ -115,23 +140,25 @@ export default function DistributionControl() {
|
|
|
115
140
|
|
|
116
141
|
const normalizedReason = reason.trim();
|
|
117
142
|
if (blocked && !normalizedReason) {
|
|
118
|
-
|
|
143
|
+
setActionError("Укажите причину аварийной блокировки.");
|
|
119
144
|
return;
|
|
120
145
|
}
|
|
121
146
|
|
|
122
|
-
const confirmed =
|
|
147
|
+
const confirmed = await confirmAction(
|
|
148
|
+
blocked ? t("Остановить все OTA") : t("Возобновить OTA"),
|
|
123
149
|
blocked
|
|
124
150
|
? t(
|
|
125
151
|
"Немедленно остановить выдачу manifest и всех OTA assets для всех клиентов?",
|
|
126
152
|
)
|
|
127
153
|
: t("Возобновить глобальное OTA-распространение?"),
|
|
154
|
+
blocked,
|
|
128
155
|
);
|
|
129
156
|
if (!confirmed) {
|
|
130
157
|
return;
|
|
131
158
|
}
|
|
132
159
|
|
|
133
160
|
setSaving(true);
|
|
134
|
-
|
|
161
|
+
setActionError("");
|
|
135
162
|
setMessage("");
|
|
136
163
|
try {
|
|
137
164
|
const updated = await setDistributionControl({
|
|
@@ -143,17 +170,17 @@ export default function DistributionControl() {
|
|
|
143
170
|
setReason("");
|
|
144
171
|
setMessage(
|
|
145
172
|
blocked
|
|
146
|
-
?
|
|
147
|
-
:
|
|
173
|
+
? "OTA-распространение остановлено."
|
|
174
|
+
: "OTA-распространение возобновлено.",
|
|
148
175
|
);
|
|
149
176
|
} catch (saveError: unknown) {
|
|
150
177
|
if (saveError instanceof AdminApiError && saveError.status === 409) {
|
|
151
178
|
await refresh();
|
|
152
|
-
|
|
179
|
+
setActionError(
|
|
153
180
|
"Состояние уже изменил другой оператор. Данные обновлены; проверьте их и повторите действие.",
|
|
154
181
|
);
|
|
155
182
|
} else {
|
|
156
|
-
|
|
183
|
+
setActionError(
|
|
157
184
|
saveError instanceof Error
|
|
158
185
|
? saveError.message
|
|
159
186
|
: "Не удалось изменить глобальный статус OTA",
|
|
@@ -165,11 +192,16 @@ export default function DistributionControl() {
|
|
|
165
192
|
};
|
|
166
193
|
|
|
167
194
|
return (
|
|
168
|
-
<Card
|
|
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
|
+
>
|
|
169
201
|
<div className="flex flex-wrap items-center justify-between gap-4 p-4">
|
|
170
202
|
<div className="flex items-start gap-3">
|
|
171
203
|
<div
|
|
172
|
-
className={`flex size-9 shrink-0 items-center justify-center rounded-lg ${state?.blocked || error ?
|
|
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"}`}
|
|
173
205
|
>
|
|
174
206
|
{loading ? (
|
|
175
207
|
<RefreshCw className="size-4 animate-spin" />
|
|
@@ -185,11 +217,12 @@ export default function DistributionControl() {
|
|
|
185
217
|
{t("Распространение OTA")}
|
|
186
218
|
</h2>
|
|
187
219
|
<Badge
|
|
188
|
-
variant=
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
220
|
+
variant={
|
|
221
|
+
loading
|
|
222
|
+
? "neutral"
|
|
223
|
+
: state?.blocked || error || !state
|
|
224
|
+
? "destructive"
|
|
225
|
+
: "positive"
|
|
193
226
|
}
|
|
194
227
|
>
|
|
195
228
|
{loading
|
|
@@ -222,33 +255,42 @@ export default function DistributionControl() {
|
|
|
222
255
|
/>
|
|
223
256
|
</Button>
|
|
224
257
|
) : state ? (
|
|
225
|
-
<Badge variant="
|
|
258
|
+
<Badge variant="neutral">{t("Read only · updates:write")}</Badge>
|
|
226
259
|
) : null}
|
|
227
260
|
</div>
|
|
228
261
|
{expanded && state?.canWrite && (
|
|
229
262
|
<div
|
|
230
263
|
id="distribution-controls"
|
|
231
|
-
className=
|
|
264
|
+
className={cn(
|
|
265
|
+
"space-y-3 border-t p-4",
|
|
266
|
+
state.blocked ? "bg-muted/20" : statusTones.destructive,
|
|
267
|
+
)}
|
|
232
268
|
>
|
|
233
269
|
<p className="text-xs text-muted-foreground">
|
|
234
270
|
{t("Изменено: ")}
|
|
235
271
|
{new Date(state.changedAt).toLocaleString(formatLocale)} ·{" "}
|
|
236
|
-
{formatChangedBy(state)} · version {state.version}
|
|
272
|
+
{formatChangedBy(state, t)} {t(" · version {0}", [state.version])}
|
|
237
273
|
</p>
|
|
238
274
|
{!state.blocked && (
|
|
239
|
-
<
|
|
240
|
-
|
|
275
|
+
<Field>
|
|
276
|
+
<FieldLabel htmlFor="stop-reason">
|
|
277
|
+
{t("Причина остановки")}
|
|
278
|
+
</FieldLabel>
|
|
241
279
|
<Textarea
|
|
280
|
+
id="stop-reason"
|
|
242
281
|
value={reason}
|
|
243
|
-
onChange={(event) =>
|
|
282
|
+
onChange={(event) => {
|
|
283
|
+
setReason(event.target.value);
|
|
284
|
+
setActionError("");
|
|
285
|
+
}}
|
|
244
286
|
maxLength={500}
|
|
245
287
|
aria-label={t("Причина аварийной блокировки OTA")}
|
|
246
288
|
placeholder={t(
|
|
247
289
|
"Обязательная причина остановки (до 500 символов)",
|
|
248
290
|
)}
|
|
249
|
-
className="
|
|
291
|
+
className="min-h-20 max-w-2xl bg-background text-foreground"
|
|
250
292
|
/>
|
|
251
|
-
</
|
|
293
|
+
</Field>
|
|
252
294
|
)}
|
|
253
295
|
<Button
|
|
254
296
|
variant={state.blocked ? "default" : "destructive"}
|
|
@@ -264,20 +306,23 @@ export default function DistributionControl() {
|
|
|
264
306
|
</Button>
|
|
265
307
|
</div>
|
|
266
308
|
)}
|
|
267
|
-
{error && (
|
|
309
|
+
{(error || actionError) && (
|
|
268
310
|
<p
|
|
269
311
|
role="alert"
|
|
270
|
-
className="border-t
|
|
312
|
+
className={cn("border-t px-4 py-3 text-sm", statusTones.destructive)}
|
|
271
313
|
>
|
|
272
|
-
{t(error)}
|
|
314
|
+
{t(error || actionError)}
|
|
273
315
|
</p>
|
|
274
316
|
)}
|
|
275
317
|
{message && (
|
|
276
318
|
<p
|
|
277
319
|
role="status"
|
|
278
|
-
className=
|
|
320
|
+
className={cn(
|
|
321
|
+
"border-t px-4 py-3 text-sm",
|
|
322
|
+
state?.blocked ? statusTones.destructive : statusTones.positive,
|
|
323
|
+
)}
|
|
279
324
|
>
|
|
280
|
-
{message}
|
|
325
|
+
{t(message)}
|
|
281
326
|
</p>
|
|
282
327
|
)}
|
|
283
328
|
</Card>
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import Link from "next/link";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
import {
|
|
6
|
+
ArrowUpRight,
|
|
7
|
+
ChevronLeft,
|
|
8
|
+
ChevronRight,
|
|
9
|
+
CircleOff,
|
|
10
|
+
History,
|
|
11
|
+
Layers,
|
|
12
|
+
RotateCcw,
|
|
13
|
+
Search,
|
|
14
|
+
} from "lucide-react";
|
|
15
|
+
import { useConfirmAction } from "@/components/admin/confirm-action";
|
|
16
|
+
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
17
|
+
import { ChannelBadge, PlatformBadge } from "@/components/admin/release-badges";
|
|
18
|
+
import { Button } from "@/components/ui/button";
|
|
19
|
+
import {
|
|
20
|
+
Card,
|
|
21
|
+
CardDescription,
|
|
22
|
+
CardHeader,
|
|
23
|
+
CardTitle,
|
|
24
|
+
} from "@/components/ui/card";
|
|
25
|
+
import {
|
|
26
|
+
Empty,
|
|
27
|
+
EmptyDescription,
|
|
28
|
+
EmptyHeader,
|
|
29
|
+
EmptyMedia,
|
|
30
|
+
EmptyTitle,
|
|
31
|
+
} from "@/components/ui/empty";
|
|
32
|
+
import {
|
|
33
|
+
InputGroup,
|
|
34
|
+
InputGroupAddon,
|
|
35
|
+
InputGroupInput,
|
|
36
|
+
} from "@/components/ui/input-group";
|
|
37
|
+
import { Skeleton } from "@/components/ui/skeleton";
|
|
38
|
+
import {
|
|
39
|
+
AdminApiError,
|
|
40
|
+
getDistributionHistory,
|
|
41
|
+
restorePreviousRelease,
|
|
42
|
+
} from "./admin-api";
|
|
43
|
+
import type {
|
|
44
|
+
DistributionHistoryRelease,
|
|
45
|
+
DistributionHistoryResponse,
|
|
46
|
+
DistributionHistoryScope,
|
|
47
|
+
} from "./admin-types";
|
|
48
|
+
import type { TranslationMessage } from "./i18n/messages";
|
|
49
|
+
import { useI18n } from "./i18n/provider";
|
|
50
|
+
import { useFormatters } from "./i18n/use-formatters";
|
|
51
|
+
|
|
52
|
+
function ReleaseLink({ release }: { release: DistributionHistoryRelease }) {
|
|
53
|
+
const { t } = useI18n();
|
|
54
|
+
const { fullDate } = useFormatters();
|
|
55
|
+
return (
|
|
56
|
+
<div className="min-w-0">
|
|
57
|
+
<Link
|
|
58
|
+
href={"/updates/" + release.encodedKey}
|
|
59
|
+
className="inline-flex max-w-full items-baseline gap-1.5 rounded-sm text-sm font-medium hover:text-primary hover:underline focus-visible:outline-ring"
|
|
60
|
+
>
|
|
61
|
+
<span className="truncate">
|
|
62
|
+
{release.comment || release.appVersion || release.updateId}
|
|
63
|
+
</span>
|
|
64
|
+
<ArrowUpRight
|
|
65
|
+
aria-hidden="true"
|
|
66
|
+
className="size-3 shrink-0 self-center text-muted-foreground"
|
|
67
|
+
/>
|
|
68
|
+
</Link>
|
|
69
|
+
<div className="mt-0.5 flex flex-wrap items-center gap-x-2 text-xs tabular-nums text-muted-foreground">
|
|
70
|
+
{release.appVersion && <span>v{release.appVersion}</span>}
|
|
71
|
+
<code>{release.updateId.slice(0, 8)}</code>
|
|
72
|
+
{release.activatedAt && (
|
|
73
|
+
<time dateTime={release.activatedAt} title={t("Activated at")}>
|
|
74
|
+
{fullDate(release.activatedAt)}
|
|
75
|
+
</time>
|
|
76
|
+
)}
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const pageSize = 5;
|
|
83
|
+
export default function DistributionHistory({
|
|
84
|
+
revision,
|
|
85
|
+
blocked,
|
|
86
|
+
onRestored,
|
|
87
|
+
}: {
|
|
88
|
+
revision: number;
|
|
89
|
+
blocked: boolean;
|
|
90
|
+
onRestored: () => void;
|
|
91
|
+
}) {
|
|
92
|
+
const { t } = useI18n();
|
|
93
|
+
const confirm = useConfirmAction();
|
|
94
|
+
const [data, setData] = useState<DistributionHistoryResponse | null>(null);
|
|
95
|
+
const [filter, setFilter] = useState("");
|
|
96
|
+
const [page, setPage] = useState(0);
|
|
97
|
+
const [loadError, setLoadError] = useState("");
|
|
98
|
+
const [actionError, setActionError] = useState("");
|
|
99
|
+
const [notice, setNotice] = useState<TranslationMessage>("");
|
|
100
|
+
const [busy, setBusy] = useState(false);
|
|
101
|
+
const [retry, setRetry] = useState(0);
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
const controller = new AbortController();
|
|
104
|
+
getDistributionHistory(controller.signal)
|
|
105
|
+
.then((value) => {
|
|
106
|
+
if (!controller.signal.aborted) {
|
|
107
|
+
setData(value);
|
|
108
|
+
setLoadError("");
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
.catch((err: Error) => {
|
|
112
|
+
if (!controller.signal.aborted)
|
|
113
|
+
setLoadError(err.message || "Unable to load delivery history.");
|
|
114
|
+
});
|
|
115
|
+
return () => controller.abort();
|
|
116
|
+
}, [revision, retry]);
|
|
117
|
+
|
|
118
|
+
async function restore(scope: DistributionHistoryScope) {
|
|
119
|
+
const target = scope.previous;
|
|
120
|
+
if (!target || blocked || busy) return;
|
|
121
|
+
const scopeName = [
|
|
122
|
+
scope.channel,
|
|
123
|
+
scope.platform,
|
|
124
|
+
scope.runtimeVersion,
|
|
125
|
+
].join(" / ");
|
|
126
|
+
if (
|
|
127
|
+
!(await confirm(
|
|
128
|
+
t("Restore release"),
|
|
129
|
+
t("Resume public delivery of {0} in {1}?", [
|
|
130
|
+
target.comment || target.updateId,
|
|
131
|
+
scopeName,
|
|
132
|
+
]),
|
|
133
|
+
true,
|
|
134
|
+
))
|
|
135
|
+
)
|
|
136
|
+
return;
|
|
137
|
+
setBusy(true);
|
|
138
|
+
setActionError("");
|
|
139
|
+
setNotice("");
|
|
140
|
+
try {
|
|
141
|
+
await restorePreviousRelease(target.updateId, scope.revision);
|
|
142
|
+
setNotice({
|
|
143
|
+
key: "Restored {0} in {1}.",
|
|
144
|
+
values: [target.appVersion || target.updateId.slice(0, 8), scopeName],
|
|
145
|
+
});
|
|
146
|
+
onRestored();
|
|
147
|
+
} catch (err) {
|
|
148
|
+
setActionError(
|
|
149
|
+
err instanceof AdminApiError && err.status === 409
|
|
150
|
+
? "Delivery changed. Review the refreshed scope before restoring."
|
|
151
|
+
: err instanceof Error
|
|
152
|
+
? err.message
|
|
153
|
+
: "Could not restore release.",
|
|
154
|
+
);
|
|
155
|
+
setRetry((n) => n + 1);
|
|
156
|
+
} finally {
|
|
157
|
+
setBusy(false);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const query = filter.trim().toLowerCase();
|
|
162
|
+
const scopes = (data?.scopes || []).filter((scope) =>
|
|
163
|
+
[scope.channel, scope.runtimeVersion, scope.platform].some((v) =>
|
|
164
|
+
v.toLowerCase().includes(query),
|
|
165
|
+
),
|
|
166
|
+
);
|
|
167
|
+
const pages = Math.ceil(scopes.length / pageSize);
|
|
168
|
+
const visiblePage = Math.min(page, Math.max(0, pages - 1));
|
|
169
|
+
return (
|
|
170
|
+
<Card
|
|
171
|
+
aria-labelledby="public-distribution"
|
|
172
|
+
className="min-w-0 gap-0 overflow-hidden py-0"
|
|
173
|
+
>
|
|
174
|
+
<CardHeader className="flex flex-wrap items-center justify-between gap-3 px-4 py-4 sm:px-5">
|
|
175
|
+
<div className="space-y-1">
|
|
176
|
+
<CardTitle
|
|
177
|
+
id="public-distribution"
|
|
178
|
+
className="flex items-center gap-2 text-base"
|
|
179
|
+
>
|
|
180
|
+
<History className="size-4 text-primary" aria-hidden="true" />
|
|
181
|
+
{t("Public delivery")}
|
|
182
|
+
</CardTitle>
|
|
183
|
+
<CardDescription>
|
|
184
|
+
{t(
|
|
185
|
+
"Current and previous releases served to all devices in each scope.",
|
|
186
|
+
)}
|
|
187
|
+
</CardDescription>
|
|
188
|
+
</div>
|
|
189
|
+
{(data?.scopes.length ?? 0) > 0 && (
|
|
190
|
+
<InputGroup className="w-full sm:w-52">
|
|
191
|
+
<InputGroupAddon>
|
|
192
|
+
<Search />
|
|
193
|
+
</InputGroupAddon>
|
|
194
|
+
<InputGroupInput
|
|
195
|
+
aria-label={t("Find a delivery scope")}
|
|
196
|
+
placeholder={t("Find a delivery scope")}
|
|
197
|
+
value={filter}
|
|
198
|
+
onChange={(e) => {
|
|
199
|
+
setFilter(e.target.value);
|
|
200
|
+
setPage(0);
|
|
201
|
+
}}
|
|
202
|
+
/>
|
|
203
|
+
</InputGroup>
|
|
204
|
+
)}
|
|
205
|
+
</CardHeader>
|
|
206
|
+
{loadError && (
|
|
207
|
+
<Alert variant="destructive" className="rounded-none">
|
|
208
|
+
<AlertDescription>
|
|
209
|
+
{t(loadError)}
|
|
210
|
+
<Button
|
|
211
|
+
size="sm"
|
|
212
|
+
variant="outline"
|
|
213
|
+
onClick={() => setRetry((n) => n + 1)}
|
|
214
|
+
>
|
|
215
|
+
{t("Retry")}
|
|
216
|
+
</Button>
|
|
217
|
+
</AlertDescription>
|
|
218
|
+
</Alert>
|
|
219
|
+
)}
|
|
220
|
+
{actionError && (
|
|
221
|
+
<Alert variant="destructive" className="rounded-none">
|
|
222
|
+
<AlertDescription>{t(actionError)}</AlertDescription>
|
|
223
|
+
</Alert>
|
|
224
|
+
)}
|
|
225
|
+
{notice && (
|
|
226
|
+
<p role="status" className="border-t px-5 py-2 text-sm">
|
|
227
|
+
{t(notice)}
|
|
228
|
+
</p>
|
|
229
|
+
)}
|
|
230
|
+
{!data && !loadError && <Skeleton className="mx-5 mb-4 h-16" />}
|
|
231
|
+
{data && !scopes.length && (
|
|
232
|
+
<Empty className="gap-2 rounded-none border-t border-solid p-4 md:p-5">
|
|
233
|
+
<EmptyHeader>
|
|
234
|
+
<EmptyMedia variant="icon">
|
|
235
|
+
<Layers />
|
|
236
|
+
</EmptyMedia>
|
|
237
|
+
<EmptyTitle className="text-sm">
|
|
238
|
+
{t(
|
|
239
|
+
query ? "No matching scopes" : "No public release history yet",
|
|
240
|
+
)}
|
|
241
|
+
</EmptyTitle>
|
|
242
|
+
<EmptyDescription>
|
|
243
|
+
{t(
|
|
244
|
+
query
|
|
245
|
+
? "Try another runtime, channel or platform."
|
|
246
|
+
: "Manually activate a release for all devices to start its history.",
|
|
247
|
+
)}
|
|
248
|
+
</EmptyDescription>
|
|
249
|
+
</EmptyHeader>
|
|
250
|
+
</Empty>
|
|
251
|
+
)}
|
|
252
|
+
{scopes.length > 0 && (
|
|
253
|
+
<div>
|
|
254
|
+
<div
|
|
255
|
+
aria-hidden="true"
|
|
256
|
+
className="hidden grid-cols-[1fr_1.15fr_1.15fr_auto] gap-4 border-y bg-muted/45 px-5 py-2 text-xs font-medium text-muted-foreground lg:grid"
|
|
257
|
+
>
|
|
258
|
+
<span>{t("Delivery scope")}</span>
|
|
259
|
+
<span>{t("Currently serving")}</span>
|
|
260
|
+
<span>{t("Previous public release")}</span>
|
|
261
|
+
<span className="w-24" />
|
|
262
|
+
</div>
|
|
263
|
+
{scopes
|
|
264
|
+
.slice(visiblePage * pageSize, (visiblePage + 1) * pageSize)
|
|
265
|
+
.map((scope) => (
|
|
266
|
+
<section
|
|
267
|
+
key={JSON.stringify([
|
|
268
|
+
scope.runtimeVersion,
|
|
269
|
+
scope.platform,
|
|
270
|
+
scope.channel,
|
|
271
|
+
])}
|
|
272
|
+
aria-label={[
|
|
273
|
+
scope.channel,
|
|
274
|
+
scope.platform,
|
|
275
|
+
scope.runtimeVersion,
|
|
276
|
+
].join(" / ")}
|
|
277
|
+
className="grid min-w-0 gap-3 border-t px-4 py-3.5 sm:px-5 lg:grid-cols-[1fr_1.15fr_1.15fr_auto] lg:items-center lg:gap-4 lg:first-of-type:border-t-0"
|
|
278
|
+
>
|
|
279
|
+
<div className="min-w-0">
|
|
280
|
+
<ChannelBadge channel={scope.channel} />
|
|
281
|
+
<div className="mt-1 flex items-center gap-2 text-xs text-muted-foreground">
|
|
282
|
+
<PlatformBadge platform={scope.platform} />
|
|
283
|
+
{t("Runtime {0}", [scope.runtimeVersion])}
|
|
284
|
+
</div>
|
|
285
|
+
</div>
|
|
286
|
+
<div className="min-w-0">
|
|
287
|
+
<div className="mb-1 text-xs text-muted-foreground lg:sr-only">
|
|
288
|
+
{t("Currently serving")}
|
|
289
|
+
</div>
|
|
290
|
+
{scope.current ? (
|
|
291
|
+
<ReleaseLink release={scope.current} />
|
|
292
|
+
) : (
|
|
293
|
+
<span className="inline-flex items-center gap-1.5 text-sm text-muted-foreground">
|
|
294
|
+
<CircleOff className="size-3.5" />
|
|
295
|
+
{t("No active release")}
|
|
296
|
+
</span>
|
|
297
|
+
)}
|
|
298
|
+
</div>
|
|
299
|
+
<div className="min-w-0">
|
|
300
|
+
<div className="mb-1 text-xs text-muted-foreground lg:sr-only">
|
|
301
|
+
{t("Previous public release")}
|
|
302
|
+
</div>
|
|
303
|
+
{scope.previous ? (
|
|
304
|
+
<ReleaseLink release={scope.previous} />
|
|
305
|
+
) : (
|
|
306
|
+
<span className="text-sm text-muted-foreground">
|
|
307
|
+
{t("No previous release")}
|
|
308
|
+
</span>
|
|
309
|
+
)}
|
|
310
|
+
</div>
|
|
311
|
+
<div className="lg:min-w-24 lg:text-right">
|
|
312
|
+
{scope.previous && data?.canWrite && (
|
|
313
|
+
<Button
|
|
314
|
+
variant="destructive"
|
|
315
|
+
size="sm"
|
|
316
|
+
disabled={blocked || busy || !!loadError}
|
|
317
|
+
onClick={() => void restore(scope)}
|
|
318
|
+
>
|
|
319
|
+
<RotateCcw />
|
|
320
|
+
{t("Restore")}
|
|
321
|
+
</Button>
|
|
322
|
+
)}
|
|
323
|
+
</div>
|
|
324
|
+
</section>
|
|
325
|
+
))}
|
|
326
|
+
{pages > 1 && (
|
|
327
|
+
<div className="flex items-center justify-end gap-3 border-t px-4 py-2 text-xs text-muted-foreground">
|
|
328
|
+
<span>{t("Page {0} of {1}", [visiblePage + 1, pages])}</span>
|
|
329
|
+
<Button
|
|
330
|
+
variant="outline"
|
|
331
|
+
size="icon"
|
|
332
|
+
disabled={!visiblePage}
|
|
333
|
+
aria-label={t("Назад")}
|
|
334
|
+
onClick={() => setPage(visiblePage - 1)}
|
|
335
|
+
>
|
|
336
|
+
<ChevronLeft />
|
|
337
|
+
</Button>
|
|
338
|
+
<Button
|
|
339
|
+
variant="outline"
|
|
340
|
+
size="icon"
|
|
341
|
+
disabled={visiblePage + 1 >= pages}
|
|
342
|
+
aria-label={t("Вперёд")}
|
|
343
|
+
onClick={() => setPage(visiblePage + 1)}
|
|
344
|
+
>
|
|
345
|
+
<ChevronRight />
|
|
346
|
+
</Button>
|
|
347
|
+
</div>
|
|
348
|
+
)}
|
|
349
|
+
</div>
|
|
350
|
+
)}
|
|
351
|
+
</Card>
|
|
352
|
+
);
|
|
353
|
+
}
|