@malloy-publisher/sdk 0.10.7 → 0.11.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/dist/{RenderedResult-BlYdT4lz.cjs.js → RenderedResult-C2r3Zkwl.cjs.js} +1 -1
- package/dist/{RenderedResult-B_sW7neX.es.js → RenderedResult-r3dg2xOJ.es.js} +2 -2
- package/dist/ServerProvider-CFHqDHFO.cjs.js +1 -0
- package/dist/{ServerProvider-BN399NH6.es.js → ServerProvider-DdGjhDhY.es.js} +2077 -1604
- package/dist/builder/index.cjs.js +1 -1
- package/dist/builder/index.es.js +3 -3
- package/dist/client/api.d.ts +673 -165
- package/dist/client/configuration.d.ts +1 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.es.js +101 -92
- package/dist/components/Materializations/Materializations.d.ts +8 -1
- package/dist/components/Package/Package.d.ts +15 -1
- package/dist/components/Package/VersionSwitch.d.ts +51 -0
- package/dist/components/Package/index.d.ts +2 -0
- package/dist/components/Package/usePackageVersions.d.ts +48 -0
- package/dist/components/ServerProvider.d.ts +2 -1
- package/dist/hooks/useDimensionFiltersQuery.d.ts +2 -0
- package/dist/index.cjs.js +14 -14
- package/dist/index.es.js +8290 -7677
- package/dist/{useCompiledDocument-xJRD5DRP.es.js → useCompiledDocument-Bc0HuUtz.es.js} +3 -3
- package/dist/{useCompiledDocument-CyPOSStA.cjs.js → useCompiledDocument-QgySwHGA.cjs.js} +2 -2
- package/dist/utils/dataAppEmbed.d.ts +6 -1
- package/package.json +1 -1
- package/src/components/DataAppViewer/DataAppViewer.tsx +18 -5
- package/src/components/DocumentStorage/DocumentStorage.contract.spec.tsx +2 -0
- package/src/components/Environment/Packages.tsx +12 -5
- package/src/components/Environment/Packages.versions.spec.tsx +62 -0
- package/src/components/Materializations/Materializations.tsx +26 -6
- package/src/components/Materializations/Materializations.versions.spec.tsx +101 -0
- package/src/components/Package/Package.agents.spec.tsx +2 -0
- package/src/components/Package/Package.artifacts.spec.tsx +35 -0
- package/src/components/Package/Package.create.spec.tsx +37 -1
- package/src/components/Package/Package.notebooks.spec.tsx +2 -0
- package/src/components/Package/Package.spec.tsx +23 -11
- package/src/components/Package/Package.tsx +111 -20
- package/src/components/Package/VersionSwitch.spec.tsx +668 -0
- package/src/components/Package/VersionSwitch.tsx +779 -0
- package/src/components/Package/index.ts +7 -0
- package/src/components/Package/usePackageVersions.spec.tsx +78 -0
- package/src/components/Package/usePackageVersions.ts +146 -0
- package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
- package/src/components/ReportBuilder/ReportEditor.authoritative.spec.tsx +5 -1
- package/src/components/ServerProvider.tsx +2 -0
- package/src/hooks/useDimensionFiltersFromSpec.ts +1 -0
- package/src/hooks/useDimensionFiltersQuery.ts +5 -1
- package/src/utils/dataAppEmbed.spec.ts +27 -0
- package/src/utils/dataAppEmbed.ts +11 -3
- package/src/utils/formatting.spec.ts +25 -0
- package/src/utils/formatting.ts +2 -1
- package/test/serverProvider.tsx +15 -0
- package/dist/ServerProvider-e2369oom.cjs.js +0 -1
|
@@ -0,0 +1,779 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import ArchiveOutlinedIcon from "@mui/icons-material/ArchiveOutlined";
|
|
5
|
+
import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
|
|
6
|
+
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
|
|
7
|
+
import MoreHorizIcon from "@mui/icons-material/MoreHoriz";
|
|
8
|
+
import PushPinOutlinedIcon from "@mui/icons-material/PushPinOutlined";
|
|
9
|
+
import UnarchiveOutlinedIcon from "@mui/icons-material/UnarchiveOutlined";
|
|
10
|
+
import {
|
|
11
|
+
Alert,
|
|
12
|
+
Box,
|
|
13
|
+
Button,
|
|
14
|
+
Chip,
|
|
15
|
+
Divider,
|
|
16
|
+
IconButton,
|
|
17
|
+
ListItemIcon,
|
|
18
|
+
ListItemText,
|
|
19
|
+
Menu,
|
|
20
|
+
MenuItem,
|
|
21
|
+
Snackbar,
|
|
22
|
+
Stack,
|
|
23
|
+
Tooltip,
|
|
24
|
+
Typography,
|
|
25
|
+
alpha,
|
|
26
|
+
} from "@mui/material";
|
|
27
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
28
|
+
import React, { useRef, useState } from "react";
|
|
29
|
+
import type { PackageVersion } from "../../client";
|
|
30
|
+
import { AppDialog } from "../AppDialog";
|
|
31
|
+
import { useServer } from "../ServerProvider";
|
|
32
|
+
import {
|
|
33
|
+
useFetchPackageVersions,
|
|
34
|
+
useInvalidatePackage,
|
|
35
|
+
} from "./usePackageVersions";
|
|
36
|
+
|
|
37
|
+
/** The server's own words for a refusal, when it sent any. */
|
|
38
|
+
const errorDetail = (error: unknown): string => {
|
|
39
|
+
const message = (error as { response?: { data?: { message?: unknown } } })
|
|
40
|
+
?.response?.data?.message;
|
|
41
|
+
if (typeof message === "string" && message !== "") return message;
|
|
42
|
+
return error instanceof Error ? error.message : "Unknown error";
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const publishedOn = (iso: string): string => {
|
|
46
|
+
const date = new Date(iso);
|
|
47
|
+
return Number.isNaN(date.getTime())
|
|
48
|
+
? ""
|
|
49
|
+
: date.toLocaleDateString("en-US", {
|
|
50
|
+
month: "short",
|
|
51
|
+
day: "numeric",
|
|
52
|
+
year: "numeric",
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const isArchived = (version: PackageVersion) =>
|
|
57
|
+
version.archiveStatus === "archive";
|
|
58
|
+
|
|
59
|
+
/** What archiving or deleting a version drops, said in both dialogs. */
|
|
60
|
+
const TABLES_DROPPED =
|
|
61
|
+
"Tables built for this version alone (under scope: version) are dropped.";
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Why the server would refuse to archive or delete `version`, given all of
|
|
65
|
+
* the package's versions; undefined when it would not. These mirror the
|
|
66
|
+
* server's checks, so the menu says why up front instead of answering a
|
|
67
|
+
* click with a 409. A package that has versions always keeps one in service,
|
|
68
|
+
* so its `latest` and its last version in service cannot be archived, and
|
|
69
|
+
* while other versions remain they cannot be deleted either. Deleting the
|
|
70
|
+
* only version is allowed: it deletes the package.
|
|
71
|
+
*/
|
|
72
|
+
export function versionRefusals(
|
|
73
|
+
version: PackageVersion,
|
|
74
|
+
versions: PackageVersion[],
|
|
75
|
+
): { archive?: string; delete?: string } {
|
|
76
|
+
const lastInService =
|
|
77
|
+
!isArchived(version) &&
|
|
78
|
+
versions.filter((other) => !isArchived(other)).length <= 1;
|
|
79
|
+
const onlyVersion = versions.length <= 1;
|
|
80
|
+
return {
|
|
81
|
+
archive: version.latest
|
|
82
|
+
? "The latest version can't be archived"
|
|
83
|
+
: lastInService
|
|
84
|
+
? "The last version in service can't be archived"
|
|
85
|
+
: undefined,
|
|
86
|
+
delete: onlyVersion
|
|
87
|
+
? undefined
|
|
88
|
+
: version.latest
|
|
89
|
+
? "Pin another version as latest first"
|
|
90
|
+
: lastInService
|
|
91
|
+
? "The last version in service; delete the archived versions first"
|
|
92
|
+
: undefined,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface VersionSwitchProps {
|
|
97
|
+
environmentName: string;
|
|
98
|
+
packageName: string;
|
|
99
|
+
/** The package's versions, highest first. */
|
|
100
|
+
versions: PackageVersion[];
|
|
101
|
+
/** The version on screen; absent means the package's `latest`. */
|
|
102
|
+
selectedVersionId?: string;
|
|
103
|
+
/** Open another version. */
|
|
104
|
+
onSelectVersion: (versionId: string, event?: React.MouseEvent) => void;
|
|
105
|
+
/**
|
|
106
|
+
* Show another version in place of the one on screen, which was archived
|
|
107
|
+
* or deleted: a version's id, or undefined for the package's `latest`.
|
|
108
|
+
* Replaces the address rather than adding to history, so Back does not
|
|
109
|
+
* return to a version that is gone. Absent, the switch opens the version
|
|
110
|
+
* by id with `onSelectVersion`.
|
|
111
|
+
*/
|
|
112
|
+
onReplaceVersion?: (versionId: string | undefined) => void;
|
|
113
|
+
/**
|
|
114
|
+
* Called after the package's only version was deleted, which deletes the
|
|
115
|
+
* package. Absent, the switch stays where it is.
|
|
116
|
+
*/
|
|
117
|
+
onPackageDeleted?: () => void;
|
|
118
|
+
/** Offer Pin as latest, Archive, Unarchive and Delete. False on a frozen server. */
|
|
119
|
+
canManage: boolean;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The package title's version switch: `v1.2.0 ▾`, a menu of every version
|
|
124
|
+
* (highest first, the one on screen marked), and on each row a ⋯ menu that
|
|
125
|
+
* pins `latest` there, archives or unarchives it, or deletes it.
|
|
126
|
+
*
|
|
127
|
+
* A version is state, never a page: picking one changes what the package page
|
|
128
|
+
* shows, and its ⋯ changes the version itself. Archived versions are listed
|
|
129
|
+
* (they can be unarchived or deleted) but cannot be opened; the server
|
|
130
|
+
* answers 410 for them.
|
|
131
|
+
*/
|
|
132
|
+
export function VersionSwitch({
|
|
133
|
+
environmentName,
|
|
134
|
+
packageName,
|
|
135
|
+
versions,
|
|
136
|
+
selectedVersionId,
|
|
137
|
+
onSelectVersion,
|
|
138
|
+
onReplaceVersion,
|
|
139
|
+
onPackageDeleted,
|
|
140
|
+
canManage,
|
|
141
|
+
}: VersionSwitchProps) {
|
|
142
|
+
const { apiClients } = useServer();
|
|
143
|
+
const queryClient = useQueryClient();
|
|
144
|
+
const invalidatePackage = useInvalidatePackage(environmentName, packageName);
|
|
145
|
+
const fetchVersions = useFetchPackageVersions(environmentName, packageName);
|
|
146
|
+
const [listAnchor, setListAnchor] = useState<HTMLElement | null>(null);
|
|
147
|
+
const [actionsFor, setActionsFor] = useState<{
|
|
148
|
+
version: PackageVersion;
|
|
149
|
+
anchor: HTMLElement;
|
|
150
|
+
} | null>(null);
|
|
151
|
+
const [pinning, setPinning] = useState<PackageVersion | null>(null);
|
|
152
|
+
const [archiving, setArchiving] = useState<PackageVersion | null>(null);
|
|
153
|
+
// The version to delete, with the package's versions read as its dialog
|
|
154
|
+
// opened (absent while that read is under way): whether the delete takes
|
|
155
|
+
// the package with it is decided from that read, never from a list
|
|
156
|
+
// another tab may have changed.
|
|
157
|
+
const [deleting, setDeleting] = useState<{
|
|
158
|
+
version: PackageVersion;
|
|
159
|
+
versions?: PackageVersion[];
|
|
160
|
+
} | null>(null);
|
|
161
|
+
const [failure, setFailure] = useState<string | null>(null);
|
|
162
|
+
const pinCancelRef = useRef<HTMLButtonElement>(null);
|
|
163
|
+
const archiveCancelRef = useRef<HTMLButtonElement>(null);
|
|
164
|
+
const deleteCancelRef = useRef<HTMLButtonElement>(null);
|
|
165
|
+
// Each row's ⋯, so the keyboard opens a row's actions where the mouse does.
|
|
166
|
+
const moreButtons = useRef(new Map<string, HTMLElement>());
|
|
167
|
+
|
|
168
|
+
const latest = versions.find((version) => version.latest)?.id;
|
|
169
|
+
const shown = selectedVersionId ?? latest;
|
|
170
|
+
|
|
171
|
+
// The environment's package list shows each package's latest version, so
|
|
172
|
+
// it is refreshed with the package.
|
|
173
|
+
const refresh = () =>
|
|
174
|
+
Promise.all([
|
|
175
|
+
invalidatePackage(),
|
|
176
|
+
queryClient.invalidateQueries({
|
|
177
|
+
queryKey: ["packages", environmentName],
|
|
178
|
+
}),
|
|
179
|
+
]);
|
|
180
|
+
|
|
181
|
+
// The version on screen was archived or deleted: show the package's
|
|
182
|
+
// latest, or with no latest the highest version still in service, by the
|
|
183
|
+
// versions as they are now (`after`, else read afresh). A listing that
|
|
184
|
+
// fails leaves the page where it is.
|
|
185
|
+
const leaveVersion = async (gone: string, after?: PackageVersion[]) => {
|
|
186
|
+
const now = after ?? (await fetchVersions().catch(() => undefined));
|
|
187
|
+
if (now === undefined) return;
|
|
188
|
+
const latestAfter = now.find((version) => version.latest)?.id;
|
|
189
|
+
const next =
|
|
190
|
+
latestAfter ??
|
|
191
|
+
now.find((version) => version.id !== gone && !isArchived(version))?.id;
|
|
192
|
+
if (next === undefined) return;
|
|
193
|
+
if (onReplaceVersion) {
|
|
194
|
+
onReplaceVersion(next === latestAfter ? undefined : next);
|
|
195
|
+
} else {
|
|
196
|
+
onSelectVersion(next);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// A refusal means the list on screen was out of date, so it is read again
|
|
201
|
+
// as it is after a success.
|
|
202
|
+
const setLatest = useMutation({
|
|
203
|
+
mutationFn: (version: string) =>
|
|
204
|
+
apiClients.versions.setPackageLatestVersion(
|
|
205
|
+
environmentName,
|
|
206
|
+
packageName,
|
|
207
|
+
{ version },
|
|
208
|
+
),
|
|
209
|
+
onSuccess: async () => {
|
|
210
|
+
setPinning(null);
|
|
211
|
+
await refresh();
|
|
212
|
+
},
|
|
213
|
+
onError: () => void refresh(),
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
const changeArchive = useMutation({
|
|
217
|
+
mutationFn: ({
|
|
218
|
+
id,
|
|
219
|
+
archiveStatus,
|
|
220
|
+
}: {
|
|
221
|
+
id: string;
|
|
222
|
+
archiveStatus: "archive" | "unarchive";
|
|
223
|
+
}) =>
|
|
224
|
+
apiClients.versions.updatePackageVersion(
|
|
225
|
+
environmentName,
|
|
226
|
+
packageName,
|
|
227
|
+
id,
|
|
228
|
+
{ archiveStatus },
|
|
229
|
+
),
|
|
230
|
+
onSuccess: async (_response, { id, archiveStatus }) => {
|
|
231
|
+
setArchiving(null);
|
|
232
|
+
if (archiveStatus === "archive" && id === shown) {
|
|
233
|
+
await leaveVersion(id);
|
|
234
|
+
}
|
|
235
|
+
await refresh();
|
|
236
|
+
},
|
|
237
|
+
onError: (error, { id, archiveStatus }) => {
|
|
238
|
+
// An archive is confirmed in a dialog, which shows its refusal.
|
|
239
|
+
if (archiveStatus === "unarchive") {
|
|
240
|
+
setFailure(`Couldn't unarchive v${id}: ${errorDetail(error)}`);
|
|
241
|
+
}
|
|
242
|
+
void refresh();
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
const updating = changeArchive.isPending
|
|
246
|
+
? changeArchive.variables?.id
|
|
247
|
+
: undefined;
|
|
248
|
+
|
|
249
|
+
const deleteVersion = useMutation({
|
|
250
|
+
// `read`: the package's versions the dialog was confirmed against.
|
|
251
|
+
mutationFn: ({ id }: { id: string; read: PackageVersion[] }) =>
|
|
252
|
+
apiClients.versions.deletePackageVersion(
|
|
253
|
+
environmentName,
|
|
254
|
+
packageName,
|
|
255
|
+
id,
|
|
256
|
+
),
|
|
257
|
+
onSuccess: async (_response, { id, read }) => {
|
|
258
|
+
setDeleting(null);
|
|
259
|
+
// What is left decides what happened, not the list the dialog read:
|
|
260
|
+
// a package with no versions left (its listing answers 404, read as
|
|
261
|
+
// none) went with the version. Only when that cannot be read does the
|
|
262
|
+
// dialog's read stand in, so a deleted package never leaves the page
|
|
263
|
+
// on its dead route.
|
|
264
|
+
const after = await fetchVersions().catch(() => undefined);
|
|
265
|
+
const left = after ?? read.filter((version) => version.id !== id);
|
|
266
|
+
if (left.length === 0) {
|
|
267
|
+
await queryClient.invalidateQueries({
|
|
268
|
+
queryKey: ["packages", environmentName],
|
|
269
|
+
});
|
|
270
|
+
onPackageDeleted?.();
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (id === shown) await leaveVersion(id, left);
|
|
274
|
+
await refresh();
|
|
275
|
+
},
|
|
276
|
+
onError: () => void refresh(),
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
const closeActions = () => setActionsFor(null);
|
|
280
|
+
const refusals = actionsFor
|
|
281
|
+
? versionRefusals(actionsFor.version, versions)
|
|
282
|
+
: {};
|
|
283
|
+
const allRefused =
|
|
284
|
+
actionsFor !== null &&
|
|
285
|
+
!isArchived(actionsFor.version) &&
|
|
286
|
+
actionsFor.version.latest &&
|
|
287
|
+
refusals.archive !== undefined &&
|
|
288
|
+
refusals.delete !== undefined;
|
|
289
|
+
// The dialog is open and its read of the versions is under way.
|
|
290
|
+
const checkingDelete = deleting !== null && deleting.versions === undefined;
|
|
291
|
+
const deletesPackage =
|
|
292
|
+
deleting?.versions !== undefined && deleting.versions.length <= 1;
|
|
293
|
+
// What the server would refuse, by the list read as the dialog opened.
|
|
294
|
+
const deleteRefusal =
|
|
295
|
+
deleting?.versions !== undefined
|
|
296
|
+
? versionRefusals(deleting.version, deleting.versions).delete
|
|
297
|
+
: undefined;
|
|
298
|
+
|
|
299
|
+
// Read the versions afresh, then confirm against that read.
|
|
300
|
+
const chooseDelete = async (chosen: PackageVersion) => {
|
|
301
|
+
closeActions();
|
|
302
|
+
setListAnchor(null);
|
|
303
|
+
deleteVersion.reset();
|
|
304
|
+
// Open at once, saying it is checking, so the click visibly did something.
|
|
305
|
+
setDeleting({ version: chosen });
|
|
306
|
+
// Only into the dialog this call opened: one cancelled meanwhile stays shut.
|
|
307
|
+
const settle = (
|
|
308
|
+
next: { version: PackageVersion; versions: PackageVersion[] } | null,
|
|
309
|
+
) =>
|
|
310
|
+
setDeleting((open) =>
|
|
311
|
+
open !== null &&
|
|
312
|
+
open.version.id === chosen.id &&
|
|
313
|
+
open.versions === undefined
|
|
314
|
+
? next
|
|
315
|
+
: open,
|
|
316
|
+
);
|
|
317
|
+
let fresh: PackageVersion[];
|
|
318
|
+
try {
|
|
319
|
+
fresh = await fetchVersions();
|
|
320
|
+
} catch (error) {
|
|
321
|
+
settle(null);
|
|
322
|
+
setFailure(
|
|
323
|
+
`Couldn't check v${chosen.id} before deleting it: ${errorDetail(error)}`,
|
|
324
|
+
);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const current = fresh.find((version) => version.id === chosen.id);
|
|
328
|
+
if (current === undefined) {
|
|
329
|
+
settle(null);
|
|
330
|
+
setFailure(`v${chosen.id} is no longer a version of ${packageName}.`);
|
|
331
|
+
void refresh();
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
settle({ version: current, versions: fresh });
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
// A row's ⋯ menu, anchored at its ⋯ as a click there anchors it.
|
|
338
|
+
const openActions = (version: PackageVersion, fallback: HTMLElement) => {
|
|
339
|
+
if (!canManage || updating === version.id) return;
|
|
340
|
+
setActionsFor({
|
|
341
|
+
version,
|
|
342
|
+
anchor: moreButtons.current.get(version.id) ?? fallback,
|
|
343
|
+
});
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// From the keyboard: ArrowRight, Shift+F10 or the menu key.
|
|
347
|
+
const openActionsByKey = (
|
|
348
|
+
event: React.KeyboardEvent<HTMLElement>,
|
|
349
|
+
version: PackageVersion,
|
|
350
|
+
) => {
|
|
351
|
+
const opens =
|
|
352
|
+
event.key === "ArrowRight" ||
|
|
353
|
+
event.key === "ContextMenu" ||
|
|
354
|
+
(event.key === "F10" && event.shiftKey);
|
|
355
|
+
if (!canManage || !opens) return;
|
|
356
|
+
event.preventDefault();
|
|
357
|
+
event.stopPropagation();
|
|
358
|
+
openActions(version, event.currentTarget);
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const deleteItem = actionsFor && (
|
|
362
|
+
<MenuItem
|
|
363
|
+
key="delete"
|
|
364
|
+
disabled={refusals.delete !== undefined}
|
|
365
|
+
onClick={() => void chooseDelete(actionsFor.version)}
|
|
366
|
+
>
|
|
367
|
+
<ListItemIcon>
|
|
368
|
+
<DeleteOutlineIcon fontSize="small" />
|
|
369
|
+
</ListItemIcon>
|
|
370
|
+
<ListItemText primary="Delete version" secondary={refusals.delete} />
|
|
371
|
+
</MenuItem>
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
return (
|
|
375
|
+
<>
|
|
376
|
+
<Button
|
|
377
|
+
size="small"
|
|
378
|
+
variant="outlined"
|
|
379
|
+
endIcon={<KeyboardArrowDownIcon />}
|
|
380
|
+
// Holds the visible text, so a speech user can say what they see.
|
|
381
|
+
aria-label={
|
|
382
|
+
shown ? `Version v${shown}, change version` : "Select a version"
|
|
383
|
+
}
|
|
384
|
+
aria-haspopup="menu"
|
|
385
|
+
onClick={(event) => setListAnchor(event.currentTarget)}
|
|
386
|
+
sx={{
|
|
387
|
+
borderRadius: 999,
|
|
388
|
+
textTransform: "none",
|
|
389
|
+
fontWeight: 500,
|
|
390
|
+
px: 1.5,
|
|
391
|
+
minWidth: 0,
|
|
392
|
+
whiteSpace: "nowrap",
|
|
393
|
+
}}
|
|
394
|
+
>
|
|
395
|
+
{shown ? `v${shown}` : "Select a version"}
|
|
396
|
+
</Button>
|
|
397
|
+
|
|
398
|
+
<Menu
|
|
399
|
+
anchorEl={listAnchor}
|
|
400
|
+
open={listAnchor !== null}
|
|
401
|
+
onClose={() => setListAnchor(null)}
|
|
402
|
+
slotProps={{
|
|
403
|
+
paper: {
|
|
404
|
+
sx: { minWidth: 320, maxWidth: 400, mt: 1, borderRadius: 3 },
|
|
405
|
+
},
|
|
406
|
+
// A row marked disabled stays reachable by keyboard, so what
|
|
407
|
+
// it says is read too.
|
|
408
|
+
list: {
|
|
409
|
+
"aria-label": `Versions of ${packageName}`,
|
|
410
|
+
disabledItemsFocusable: true,
|
|
411
|
+
},
|
|
412
|
+
}}
|
|
413
|
+
>
|
|
414
|
+
{versions.map((version) => {
|
|
415
|
+
const active = version.id === shown;
|
|
416
|
+
const archived = isArchived(version);
|
|
417
|
+
const details = [
|
|
418
|
+
archived ? "Archived" : undefined,
|
|
419
|
+
publishedOn(version.createdAt),
|
|
420
|
+
version.gitCommitSha
|
|
421
|
+
? version.gitCommitSha.slice(0, 7)
|
|
422
|
+
: undefined,
|
|
423
|
+
]
|
|
424
|
+
.filter(Boolean)
|
|
425
|
+
.join(" · ");
|
|
426
|
+
return (
|
|
427
|
+
<MenuItem
|
|
428
|
+
key={version.id}
|
|
429
|
+
aria-current={active ? "true" : undefined}
|
|
430
|
+
// An archived version is listed but does not open (the
|
|
431
|
+
// server answers 410): choosing it offers its actions
|
|
432
|
+
// instead. With none to offer, it is marked disabled; it
|
|
433
|
+
// is not otherwise, since that would disable its ⋯ too.
|
|
434
|
+
aria-disabled={archived && !canManage ? "true" : undefined}
|
|
435
|
+
aria-haspopup={canManage ? "menu" : undefined}
|
|
436
|
+
data-testid="version-row"
|
|
437
|
+
onKeyDown={(event) => openActionsByKey(event, version)}
|
|
438
|
+
onClick={(event) => {
|
|
439
|
+
if (archived) {
|
|
440
|
+
openActions(version, event.currentTarget);
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (active) return;
|
|
444
|
+
setListAnchor(null);
|
|
445
|
+
onSelectVersion(version.id, event);
|
|
446
|
+
}}
|
|
447
|
+
sx={(theme) => ({
|
|
448
|
+
gap: 1,
|
|
449
|
+
borderLeft: "3px solid",
|
|
450
|
+
borderLeftColor: active
|
|
451
|
+
? theme.palette.primary.main
|
|
452
|
+
: "transparent",
|
|
453
|
+
backgroundColor: active
|
|
454
|
+
? alpha(theme.palette.primary.main, 0.04)
|
|
455
|
+
: undefined,
|
|
456
|
+
cursor:
|
|
457
|
+
active || (archived && !canManage)
|
|
458
|
+
? "default"
|
|
459
|
+
: "pointer",
|
|
460
|
+
})}
|
|
461
|
+
>
|
|
462
|
+
<ListItemText
|
|
463
|
+
primary={version.id}
|
|
464
|
+
secondary={details}
|
|
465
|
+
sx={{ opacity: archived ? 0.6 : 1 }}
|
|
466
|
+
slotProps={{
|
|
467
|
+
primary: { sx: { fontWeight: active ? 600 : 400 } },
|
|
468
|
+
}}
|
|
469
|
+
/>
|
|
470
|
+
{version.latest && (
|
|
471
|
+
<Chip
|
|
472
|
+
size="small"
|
|
473
|
+
label="Latest"
|
|
474
|
+
color="info"
|
|
475
|
+
variant="outlined"
|
|
476
|
+
sx={{ height: 20, fontSize: 11, fontWeight: 600 }}
|
|
477
|
+
/>
|
|
478
|
+
)}
|
|
479
|
+
{canManage && (
|
|
480
|
+
<Tooltip
|
|
481
|
+
title={
|
|
482
|
+
updating === version.id
|
|
483
|
+
? "Updating this version…"
|
|
484
|
+
: ""
|
|
485
|
+
}
|
|
486
|
+
>
|
|
487
|
+
<span>
|
|
488
|
+
<IconButton
|
|
489
|
+
ref={(element: HTMLButtonElement | null) => {
|
|
490
|
+
if (element) {
|
|
491
|
+
moreButtons.current.set(
|
|
492
|
+
version.id,
|
|
493
|
+
element,
|
|
494
|
+
);
|
|
495
|
+
} else {
|
|
496
|
+
moreButtons.current.delete(version.id);
|
|
497
|
+
}
|
|
498
|
+
}}
|
|
499
|
+
size="small"
|
|
500
|
+
aria-label={`More actions for version ${version.id}`}
|
|
501
|
+
aria-haspopup="menu"
|
|
502
|
+
disabled={updating === version.id}
|
|
503
|
+
onClick={(event) => {
|
|
504
|
+
event.stopPropagation();
|
|
505
|
+
setActionsFor({
|
|
506
|
+
version,
|
|
507
|
+
anchor: event.currentTarget,
|
|
508
|
+
});
|
|
509
|
+
}}
|
|
510
|
+
>
|
|
511
|
+
<MoreHorizIcon fontSize="small" />
|
|
512
|
+
</IconButton>
|
|
513
|
+
</span>
|
|
514
|
+
</Tooltip>
|
|
515
|
+
)}
|
|
516
|
+
</MenuItem>
|
|
517
|
+
);
|
|
518
|
+
})}
|
|
519
|
+
</Menu>
|
|
520
|
+
|
|
521
|
+
<Menu
|
|
522
|
+
anchorEl={actionsFor?.anchor ?? null}
|
|
523
|
+
open={actionsFor !== null}
|
|
524
|
+
onClose={closeActions}
|
|
525
|
+
slotProps={{
|
|
526
|
+
list: {
|
|
527
|
+
"aria-label": actionsFor
|
|
528
|
+
? `Actions for version ${actionsFor.version.id}`
|
|
529
|
+
: undefined,
|
|
530
|
+
// A refused action is focusable, so its reason is read.
|
|
531
|
+
disabledItemsFocusable: true,
|
|
532
|
+
// Latest refuses every action, and the menu then focuses
|
|
533
|
+
// no item: focus the list, so the arrow keys reach them.
|
|
534
|
+
autoFocus: allRefused,
|
|
535
|
+
},
|
|
536
|
+
}}
|
|
537
|
+
>
|
|
538
|
+
{actionsFor && isArchived(actionsFor.version)
|
|
539
|
+
? [
|
|
540
|
+
<MenuItem
|
|
541
|
+
key="unarchive"
|
|
542
|
+
onClick={() => {
|
|
543
|
+
const { id } = actionsFor.version;
|
|
544
|
+
closeActions();
|
|
545
|
+
changeArchive.mutate({
|
|
546
|
+
id,
|
|
547
|
+
archiveStatus: "unarchive",
|
|
548
|
+
});
|
|
549
|
+
}}
|
|
550
|
+
>
|
|
551
|
+
<ListItemIcon>
|
|
552
|
+
<UnarchiveOutlinedIcon fontSize="small" />
|
|
553
|
+
</ListItemIcon>
|
|
554
|
+
<ListItemText primary="Unarchive" />
|
|
555
|
+
</MenuItem>,
|
|
556
|
+
<Divider key="divider" />,
|
|
557
|
+
deleteItem,
|
|
558
|
+
]
|
|
559
|
+
: actionsFor && [
|
|
560
|
+
<MenuItem
|
|
561
|
+
key="pin-latest"
|
|
562
|
+
disabled={actionsFor.version.latest}
|
|
563
|
+
onClick={() => {
|
|
564
|
+
setPinning(actionsFor.version);
|
|
565
|
+
setLatest.reset();
|
|
566
|
+
closeActions();
|
|
567
|
+
setListAnchor(null);
|
|
568
|
+
}}
|
|
569
|
+
>
|
|
570
|
+
<ListItemIcon>
|
|
571
|
+
<PushPinOutlinedIcon fontSize="small" />
|
|
572
|
+
</ListItemIcon>
|
|
573
|
+
<ListItemText
|
|
574
|
+
primary="Pin as latest"
|
|
575
|
+
secondary={
|
|
576
|
+
actionsFor.version.latest
|
|
577
|
+
? "Already the latest version"
|
|
578
|
+
: undefined
|
|
579
|
+
}
|
|
580
|
+
/>
|
|
581
|
+
</MenuItem>,
|
|
582
|
+
<MenuItem
|
|
583
|
+
key="archive"
|
|
584
|
+
disabled={refusals.archive !== undefined}
|
|
585
|
+
onClick={() => {
|
|
586
|
+
setArchiving(actionsFor.version);
|
|
587
|
+
changeArchive.reset();
|
|
588
|
+
closeActions();
|
|
589
|
+
setListAnchor(null);
|
|
590
|
+
}}
|
|
591
|
+
>
|
|
592
|
+
<ListItemIcon>
|
|
593
|
+
<ArchiveOutlinedIcon fontSize="small" />
|
|
594
|
+
</ListItemIcon>
|
|
595
|
+
<ListItemText
|
|
596
|
+
primary="Archive"
|
|
597
|
+
secondary={refusals.archive}
|
|
598
|
+
/>
|
|
599
|
+
</MenuItem>,
|
|
600
|
+
<Divider key="divider" />,
|
|
601
|
+
deleteItem,
|
|
602
|
+
]}
|
|
603
|
+
</Menu>
|
|
604
|
+
|
|
605
|
+
<AppDialog
|
|
606
|
+
open={pinning !== null}
|
|
607
|
+
onClose={() => {
|
|
608
|
+
if (!setLatest.isPending) setPinning(null);
|
|
609
|
+
}}
|
|
610
|
+
title={pinning ? `Pin v${pinning.id} as latest` : ""}
|
|
611
|
+
description={
|
|
612
|
+
pinning
|
|
613
|
+
? `Requests that name no version will be served from v${pinning.id}.`
|
|
614
|
+
: undefined
|
|
615
|
+
}
|
|
616
|
+
initialFocus={pinCancelRef}
|
|
617
|
+
actions={
|
|
618
|
+
<>
|
|
619
|
+
<Button
|
|
620
|
+
ref={pinCancelRef}
|
|
621
|
+
disabled={setLatest.isPending}
|
|
622
|
+
onClick={() => setPinning(null)}
|
|
623
|
+
>
|
|
624
|
+
Cancel
|
|
625
|
+
</Button>
|
|
626
|
+
<Button
|
|
627
|
+
variant="contained"
|
|
628
|
+
loading={setLatest.isPending}
|
|
629
|
+
onClick={() => pinning && setLatest.mutate(pinning.id)}
|
|
630
|
+
>
|
|
631
|
+
Pin as latest
|
|
632
|
+
</Button>
|
|
633
|
+
</>
|
|
634
|
+
}
|
|
635
|
+
>
|
|
636
|
+
<Stack spacing={1.5}>
|
|
637
|
+
{latest && pinning && latest !== pinning.id && (
|
|
638
|
+
<Typography variant="body2" color="text.secondary">
|
|
639
|
+
{`The latest version is v${latest} now. Links and requests that name a version keep answering as before.`}
|
|
640
|
+
</Typography>
|
|
641
|
+
)}
|
|
642
|
+
{setLatest.isError && pinning && (
|
|
643
|
+
<Alert severity="error" role="alert">
|
|
644
|
+
{`Couldn't pin v${pinning.id} as latest: ${errorDetail(setLatest.error)}`}
|
|
645
|
+
</Alert>
|
|
646
|
+
)}
|
|
647
|
+
</Stack>
|
|
648
|
+
</AppDialog>
|
|
649
|
+
|
|
650
|
+
<AppDialog
|
|
651
|
+
open={archiving !== null}
|
|
652
|
+
onClose={() => {
|
|
653
|
+
if (!changeArchive.isPending) setArchiving(null);
|
|
654
|
+
}}
|
|
655
|
+
title={archiving ? `Archive v${archiving.id}` : ""}
|
|
656
|
+
description={
|
|
657
|
+
archiving
|
|
658
|
+
? `v${archiving.id} stops being served and is unloaded. Its files stay, so it can be unarchived.`
|
|
659
|
+
: undefined
|
|
660
|
+
}
|
|
661
|
+
initialFocus={archiveCancelRef}
|
|
662
|
+
actions={
|
|
663
|
+
<>
|
|
664
|
+
<Button
|
|
665
|
+
ref={archiveCancelRef}
|
|
666
|
+
disabled={changeArchive.isPending}
|
|
667
|
+
onClick={() => setArchiving(null)}
|
|
668
|
+
>
|
|
669
|
+
Cancel
|
|
670
|
+
</Button>
|
|
671
|
+
<Button
|
|
672
|
+
variant="contained"
|
|
673
|
+
loading={changeArchive.isPending}
|
|
674
|
+
onClick={() =>
|
|
675
|
+
archiving &&
|
|
676
|
+
changeArchive.mutate({
|
|
677
|
+
id: archiving.id,
|
|
678
|
+
archiveStatus: "archive",
|
|
679
|
+
})
|
|
680
|
+
}
|
|
681
|
+
>
|
|
682
|
+
Archive
|
|
683
|
+
</Button>
|
|
684
|
+
</>
|
|
685
|
+
}
|
|
686
|
+
>
|
|
687
|
+
<Stack spacing={1.5}>
|
|
688
|
+
<Typography variant="body2" color="text.secondary">
|
|
689
|
+
{`${TABLES_DROPPED} Its scheduled builds stop, and once unarchived it serves live until it is built again.`}
|
|
690
|
+
</Typography>
|
|
691
|
+
{changeArchive.isError && archiving && (
|
|
692
|
+
<Alert severity="error" role="alert">
|
|
693
|
+
{`Couldn't archive v${archiving.id}: ${errorDetail(changeArchive.error)}`}
|
|
694
|
+
</Alert>
|
|
695
|
+
)}
|
|
696
|
+
</Stack>
|
|
697
|
+
</AppDialog>
|
|
698
|
+
|
|
699
|
+
<AppDialog
|
|
700
|
+
open={deleting !== null}
|
|
701
|
+
onClose={() => {
|
|
702
|
+
if (!deleteVersion.isPending) setDeleting(null);
|
|
703
|
+
}}
|
|
704
|
+
title={deleting ? `Delete v${deleting.version.id}` : ""}
|
|
705
|
+
initialFocus={deleteCancelRef}
|
|
706
|
+
actions={
|
|
707
|
+
<>
|
|
708
|
+
<Button
|
|
709
|
+
ref={deleteCancelRef}
|
|
710
|
+
disabled={deleteVersion.isPending}
|
|
711
|
+
onClick={() => setDeleting(null)}
|
|
712
|
+
>
|
|
713
|
+
Cancel
|
|
714
|
+
</Button>
|
|
715
|
+
<Button
|
|
716
|
+
variant="contained"
|
|
717
|
+
color="error"
|
|
718
|
+
loading={deleteVersion.isPending}
|
|
719
|
+
// While the dialog reads the versions it says so in
|
|
720
|
+
// its text; Delete waits for that read.
|
|
721
|
+
disabled={checkingDelete || deleteRefusal !== undefined}
|
|
722
|
+
onClick={() =>
|
|
723
|
+
deleting?.versions &&
|
|
724
|
+
deleteVersion.mutate({
|
|
725
|
+
id: deleting.version.id,
|
|
726
|
+
read: deleting.versions,
|
|
727
|
+
})
|
|
728
|
+
}
|
|
729
|
+
>
|
|
730
|
+
{deletesPackage ? "Delete package" : "Delete version"}
|
|
731
|
+
</Button>
|
|
732
|
+
</>
|
|
733
|
+
}
|
|
734
|
+
>
|
|
735
|
+
<Stack spacing={1.5}>
|
|
736
|
+
{checkingDelete && deleting && (
|
|
737
|
+
<Typography variant="body2">
|
|
738
|
+
{`Checking ${packageName}'s versions before deleting v${deleting.version.id}…`}
|
|
739
|
+
</Typography>
|
|
740
|
+
)}
|
|
741
|
+
{deleting && !checkingDelete && (
|
|
742
|
+
<Typography variant="body2">
|
|
743
|
+
{deletesPackage
|
|
744
|
+
? `v${deleting.version.id} is the only version of ${packageName}, so deleting it deletes the package. ${TABLES_DROPPED} This cannot be undone.`
|
|
745
|
+
: `v${deleting.version.id} stops being served and its files are removed. ${TABLES_DROPPED} Links that name it stop working, and this cannot be undone.`}
|
|
746
|
+
</Typography>
|
|
747
|
+
)}
|
|
748
|
+
{deleteRefusal !== undefined && deleting && (
|
|
749
|
+
<Alert severity="warning" role="alert">
|
|
750
|
+
{`v${deleting.version.id} can't be deleted now: ${deleteRefusal}.`}
|
|
751
|
+
</Alert>
|
|
752
|
+
)}
|
|
753
|
+
{deleteVersion.isError && deleting && (
|
|
754
|
+
<Alert severity="error" role="alert">
|
|
755
|
+
{`Couldn't delete v${deleting.version.id}: ${errorDetail(deleteVersion.error)}`}
|
|
756
|
+
</Alert>
|
|
757
|
+
)}
|
|
758
|
+
</Stack>
|
|
759
|
+
</AppDialog>
|
|
760
|
+
|
|
761
|
+
<Snackbar
|
|
762
|
+
open={failure !== null}
|
|
763
|
+
autoHideDuration={8000}
|
|
764
|
+
onClose={() => setFailure(null)}
|
|
765
|
+
anchorOrigin={{ vertical: "bottom", horizontal: "center" }}
|
|
766
|
+
>
|
|
767
|
+
<Box>
|
|
768
|
+
<Alert
|
|
769
|
+
severity="error"
|
|
770
|
+
variant="filled"
|
|
771
|
+
onClose={() => setFailure(null)}
|
|
772
|
+
>
|
|
773
|
+
{failure}
|
|
774
|
+
</Alert>
|
|
775
|
+
</Box>
|
|
776
|
+
</Snackbar>
|
|
777
|
+
</>
|
|
778
|
+
);
|
|
779
|
+
}
|