@burdenoff/microfe-export 2026.1123.1 → 2026.1124.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/export/ExportRoutes.js +23 -22
- package/dist/export/ExportRoutes.js.map +1 -1
- package/dist/export/hooks/useExportQueries.d.ts +89 -1
- package/dist/export/hooks/useExportQueries.js +167 -127
- package/dist/export/hooks/useExportQueries.js.map +1 -1
- package/dist/export/workspace-v2/DownloadCells.d.ts +29 -0
- package/dist/export/workspace-v2/DownloadCells.js +105 -0
- package/dist/export/workspace-v2/DownloadCells.js.map +1 -0
- package/dist/export/workspace-v2/DownloadsList.d.ts +13 -0
- package/dist/export/workspace-v2/DownloadsList.js +208 -0
- package/dist/export/workspace-v2/DownloadsList.js.map +1 -0
- package/dist/export/workspace-v2/DownloadsPage.d.ts +1 -0
- package/dist/export/workspace-v2/DownloadsPage.js +114 -0
- package/dist/export/workspace-v2/DownloadsPage.js.map +1 -0
- package/dist/export/workspace-v2/ExportV2Routes.d.ts +1 -0
- package/dist/export/workspace-v2/ExportV2Routes.js +68 -0
- package/dist/export/workspace-v2/ExportV2Routes.js.map +1 -0
- package/dist/export/workspace-v2/NewDownloadDialog.d.ts +10 -0
- package/dist/export/workspace-v2/NewDownloadDialog.js +432 -0
- package/dist/export/workspace-v2/NewDownloadDialog.js.map +1 -0
- package/dist/export/workspace-v2/SetupsList.d.ts +13 -0
- package/dist/export/workspace-v2/SetupsList.js +132 -0
- package/dist/export/workspace-v2/SetupsList.js.map +1 -0
- package/dist/export/workspace-v2/downloadsModel.d.ts +108 -0
- package/dist/export/workspace-v2/downloadsModel.js +138 -0
- package/dist/export/workspace-v2/downloadsModel.js.map +1 -0
- package/dist/export/workspace-v2/newDownloadModel.d.ts +48 -0
- package/dist/export/workspace-v2/newDownloadModel.js +76 -0
- package/dist/export/workspace-v2/newDownloadModel.js.map +1 -0
- package/dist/export/workspace-v2/useDownloadActions.d.ts +20 -0
- package/dist/export/workspace-v2/useDownloadActions.js +127 -0
- package/dist/export/workspace-v2/useDownloadActions.js.map +1 -0
- package/dist/export/workspace-v2/useDownloadsData.d.ts +57 -0
- package/dist/export/workspace-v2/useDownloadsData.js +186 -0
- package/dist/export/workspace-v2/useDownloadsData.js.map +1 -0
- package/dist/export/workspace-v2/useDownloadsPage.d.ts +22 -0
- package/dist/export/workspace-v2/useDownloadsPage.js +45 -0
- package/dist/export/workspace-v2/useDownloadsPage.js.map +1 -0
- package/dist/export/workspace-v2/useExportAccess.d.ts +21 -0
- package/dist/export/workspace-v2/useExportAccess.js +16 -0
- package/dist/export/workspace-v2/useExportAccess.js.map +1 -0
- package/dist/export/workspace-v2/useListClock.d.ts +4 -0
- package/dist/export/workspace-v2/useListClock.js +20 -0
- package/dist/export/workspace-v2/useListClock.js.map +1 -0
- package/dist/export/workspace-v2/useOfferedKinds.d.ts +19 -0
- package/dist/export/workspace-v2/useOfferedKinds.js +30 -0
- package/dist/export/workspace-v2/useOfferedKinds.js.map +1 -0
- package/dist/export/workspace-v2/useOnceAtATime.d.ts +7 -0
- package/dist/export/workspace-v2/useOnceAtATime.js +17 -0
- package/dist/export/workspace-v2/useOnceAtATime.js.map +1 -0
- package/dist/generated/global-types.d.ts +9901 -584
- package/dist/generated/wspace-operations.js +9 -11
- package/dist/generated/wspace-operations.js.map +1 -1
- package/dist/generated/wspace-types.d.ts +195315 -42067
- package/dist/generated/wspace-types.js +5 -1
- package/dist/generated/wspace-types.js.map +1 -1
- package/dist/translations/en.d.ts +190 -0
- package/dist/translations/en.js +191 -1
- package/dist/translations/en.js.map +1 -1
- package/package.json +11 -3
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { SUPPORTED_FORMATS as e } from "../utils/newDownloadForm.js";
|
|
2
|
+
// src/export/workspace-v2/newDownloadModel.ts
|
|
3
|
+
var t = {
|
|
4
|
+
scope: "INDIVIDUAL",
|
|
5
|
+
entityTypes: [],
|
|
6
|
+
format: "CSV",
|
|
7
|
+
period: "all",
|
|
8
|
+
name: "",
|
|
9
|
+
nameEdited: !1,
|
|
10
|
+
save: !1,
|
|
11
|
+
setupName: "",
|
|
12
|
+
setupId: void 0
|
|
13
|
+
};
|
|
14
|
+
function n(n, r) {
|
|
15
|
+
let i = n.format?.toUpperCase();
|
|
16
|
+
return {
|
|
17
|
+
...t,
|
|
18
|
+
entityTypes: (n.entityTypes ?? []).filter(r),
|
|
19
|
+
format: e.find((e) => e === i) ?? t.format,
|
|
20
|
+
name: n.name,
|
|
21
|
+
nameEdited: !0,
|
|
22
|
+
setupId: n.id
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function r(e, t) {
|
|
26
|
+
let n = new Set(e), r = new Set(t);
|
|
27
|
+
return t.length > 0 && t.every((e) => n.has(e)) ? e.filter((e) => !r.has(e)) : [...e, ...t.filter((e) => !n.has(e))];
|
|
28
|
+
}
|
|
29
|
+
function i(e, t) {
|
|
30
|
+
let n = new Set(e), r = t.filter((e) => n.has(e)).length;
|
|
31
|
+
return r === 0 ? !1 : r === t.length || "indeterminate";
|
|
32
|
+
}
|
|
33
|
+
var a = 864e5;
|
|
34
|
+
function o(e, t = Date.now()) {
|
|
35
|
+
return e === "all" ? null : (/* @__PURE__ */ new Date(t - Number(e) * a)).toISOString();
|
|
36
|
+
}
|
|
37
|
+
function s(e) {
|
|
38
|
+
return e.entityTypes.length === 0 ? "noKinds" : e.name.trim() ? e.save && !(e.setupName.trim() || e.name.trim()) ? "noSetupName" : null : "noName";
|
|
39
|
+
}
|
|
40
|
+
function c(e, t, n = e.setupId, r = Date.now()) {
|
|
41
|
+
return {
|
|
42
|
+
name: e.name.trim(),
|
|
43
|
+
entityTypes: e.entityTypes,
|
|
44
|
+
format: e.format,
|
|
45
|
+
exportScope: e.scope,
|
|
46
|
+
organizationId: e.scope === "ORG_ADMIN" ? t : void 0,
|
|
47
|
+
templateId: n,
|
|
48
|
+
dateRangeStart: o(e.period, r),
|
|
49
|
+
dateRangeEnd: null
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function l(e) {
|
|
53
|
+
return {
|
|
54
|
+
name: e.setupName.trim() || e.name.trim(),
|
|
55
|
+
entityTypes: e.entityTypes,
|
|
56
|
+
format: e.format
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function u(e, t) {
|
|
60
|
+
return e.entityTypes.some(t);
|
|
61
|
+
}
|
|
62
|
+
function d(n, r, i) {
|
|
63
|
+
let a = n.format?.toUpperCase();
|
|
64
|
+
return {
|
|
65
|
+
name: r,
|
|
66
|
+
entityTypes: n.entityTypes.filter(i),
|
|
67
|
+
format: e.find((e) => e === a) ?? t.format,
|
|
68
|
+
exportScope: "INDIVIDUAL",
|
|
69
|
+
templateId: n.id,
|
|
70
|
+
dateRangeStart: null,
|
|
71
|
+
dateRangeEnd: null
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export { t as EMPTY_DRAFT, u as canRunSetup, n as draftFromSetup, s as draftProblem, i as groupState, c as jobInput, o as periodStart, d as runSetupInput, l as setupInput, r as toggleKinds };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=newDownloadModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"newDownloadModel.js","names":["EMPTY_DRAFT","draftFromSetup","format","setup","isOffered","SUPPORTED_FORMATS","f","toggleKinds","picked","chosen","group","kinds","kind","groupState","on","DAY_MS","periodStart","period","now","draftProblem","draft","jobInput","organizationId","setupId","setupInput","canRunSetup","runSetupInput"],"sources":["../../../src/export/workspace-v2/newDownloadModel.ts"],"sourcesContent":["/**\n * What \"New download\" collects (BOFF-15822) and the export service calls it\n * becomes: `createExportJob`, and with \"Save as a setup\" first\n * `createExportTemplate` (the job then names the setup it came from).\n *\n * The service keeps no schedule and no \"whose data\" on a setup, so a setup is\n * the kinds of data and the file type; the period, the name and whose data\n * are chosen each time.\n */\nimport type {\n CreateExportJobInput,\n CreateExportTemplateInput,\n} from \"../hooks/useExportQueries\";\nimport type { ExportFormat, ExportScope, ExportTemplate } from \"../types\";\nimport { SUPPORTED_FORMATS } from \"../utils/newDownloadForm\";\n\n/** How far back the data goes: everything, or the last 30 or 90 days. */\nexport const PERIODS = [\"all\", \"30\", \"90\"] as const;\nexport type Period = (typeof PERIODS)[number];\n\nexport interface NewDownloadDraft {\n scope: ExportScope;\n entityTypes: string[];\n format: ExportFormat;\n period: Period;\n /** The download's name; suggested from the kinds until the person edits it. */\n name: string;\n nameEdited: boolean;\n /** \"Save as a setup\", and the setup's name. */\n save: boolean;\n setupName: string;\n /** The saved setup this download starts from, if any. */\n setupId?: string;\n}\n\nexport const EMPTY_DRAFT: NewDownloadDraft = {\n scope: \"INDIVIDUAL\",\n entityTypes: [],\n format: \"CSV\",\n period: \"all\",\n name: \"\",\n nameEdited: false,\n save: false,\n setupName: \"\",\n setupId: undefined,\n};\n\n/**\n * A draft filled in from a saved setup: its kinds (only the ones offered\n * here), its file type when the service still writes it, and its name.\n */\nexport function draftFromSetup(\n setup: ExportTemplate,\n isOffered: (entityType: string) => boolean,\n): NewDownloadDraft {\n const format = setup.format?.toUpperCase();\n return {\n ...EMPTY_DRAFT,\n entityTypes: (setup.entityTypes ?? []).filter(isOffered),\n format: SUPPORTED_FORMATS.find((f) => f === format) ?? EMPTY_DRAFT.format,\n name: setup.name,\n nameEdited: true,\n setupId: setup.id,\n };\n}\n\n/** A group's kinds on or off together: on unless all of them are on already. */\nexport function toggleKinds(\n chosen: readonly string[],\n kinds: readonly string[],\n): string[] {\n const picked = new Set(chosen);\n const group = new Set(kinds);\n const all = kinds.length > 0 && kinds.every((kind) => picked.has(kind));\n if (all) return chosen.filter((kind) => !group.has(kind));\n return [...chosen, ...kinds.filter((kind) => !picked.has(kind))];\n}\n\n/** How much of a group is chosen: a checkbox's checked, unchecked or mixed. */\nexport function groupState(\n chosen: readonly string[],\n kinds: readonly string[],\n): boolean | \"indeterminate\" {\n const picked = new Set(chosen);\n const on = kinds.filter((kind) => picked.has(kind)).length;\n if (on === 0) return false;\n return on === kinds.length ? true : \"indeterminate\";\n}\n\nconst DAY_MS = 24 * 60 * 60 * 1000;\n\n/** The first moment a period covers, or null for all time. */\nexport function periodStart(period: Period, now = Date.now()): string | null {\n if (period === \"all\") return null;\n return new Date(now - Number(period) * DAY_MS).toISOString();\n}\n\n/** Why a draft cannot start yet, or null when it can. */\nexport type DraftProblem = \"noKinds\" | \"noName\" | \"noSetupName\";\n\nexport function draftProblem(draft: NewDownloadDraft): DraftProblem | null {\n if (draft.entityTypes.length === 0) return \"noKinds\";\n if (!draft.name.trim()) return \"noName\";\n if (draft.save && !(draft.setupName.trim() || draft.name.trim()))\n return \"noSetupName\";\n return null;\n}\n\n/** The `createExportJob` input for a draft (and the setup it was saved as). */\nexport function jobInput(\n draft: NewDownloadDraft,\n organizationId: string | undefined,\n setupId: string | undefined = draft.setupId,\n now = Date.now(),\n): CreateExportJobInput {\n return {\n name: draft.name.trim(),\n entityTypes: draft.entityTypes,\n format: draft.format,\n exportScope: draft.scope,\n organizationId: draft.scope === \"ORG_ADMIN\" ? organizationId : undefined,\n templateId: setupId,\n dateRangeStart: periodStart(draft.period, now),\n dateRangeEnd: null,\n };\n}\n\n/** The `createExportTemplate` input for \"Save as a setup\". */\nexport function setupInput(draft: NewDownloadDraft): CreateExportTemplateInput {\n return {\n name: draft.setupName.trim() || draft.name.trim(),\n entityTypes: draft.entityTypes,\n format: draft.format,\n };\n}\n\n/**\n * Whether \"Run now\" has something to download here: a setup is workspace-wide,\n * so it can hold another product's kinds of data, or a switched-off module's.\n */\nexport function canRunSetup(\n setup: ExportTemplate,\n isOffered: (entityType: string) => boolean,\n): boolean {\n return setup.entityTypes.some(isOffered);\n}\n\n/**\n * \"Run now\" on a saved setup: just this person's data, the setup's kinds\n * that are offered here (as New download does), and its file type.\n */\nexport function runSetupInput(\n setup: ExportTemplate,\n name: string,\n isOffered: (entityType: string) => boolean,\n): CreateExportJobInput {\n const format = setup.format?.toUpperCase();\n return {\n name,\n entityTypes: setup.entityTypes.filter(isOffered),\n format: SUPPORTED_FORMATS.find((f) => f === format) ?? EMPTY_DRAFT.format,\n exportScope: \"INDIVIDUAL\",\n templateId: setup.id,\n dateRangeStart: null,\n dateRangeEnd: null,\n };\n}\n"],"mappings":";;AAmCA,IAAaA,IAAgC;CAC3C,OAAO;CACP,aAAa,CAAC;CACd,QAAQ;CACR,QAAQ;CACR,MAAM;CACN,YAAY;CACZ,MAAM;CACN,WAAW;CACX,SAAS,KAAA;AACX;AAMA,SAAgBC,EACd,GACA,GACkB;CAClB,IAAMC,IAASC,EAAM,QAAQ,YAAY;CACzC,OAAO;EACL,GAAGH;EACH,cAAcG,EAAM,eAAe,CAAC,EAAA,CAAG,OAAOC,CAAS;EACvD,QAAQC,EAAkB,MAAM,MAAMC,MAAMJ,CAAM,KAAKF,EAAY;EACnE,MAAMG,EAAM;EACZ,YAAY;EACZ,SAASA,EAAM;CACjB;AACF;AAGA,SAAgBI,EACd,GACA,GACU;CACV,IAAMC,IAAS,IAAI,IAAIC,CAAM,GACvBC,IAAQ,IAAI,IAAIC,CAAK;CAG3B,OAFYA,EAAM,SAAS,KAAKA,EAAM,OAAO,MAASH,EAAO,IAAII,CAAI,CAAC,IACtDH,EAAO,QAAQ,MAAS,CAACC,EAAM,IAAIE,CAAI,CAAC,IACjD,CAAC,GAAGH,GAAQ,GAAGE,EAAM,QAAQ,MAAS,CAACH,EAAO,IAAII,CAAI,CAAC,CAAC;AACjE;AAGA,SAAgBC,EACd,GACA,GAC2B;CAC3B,IAAML,IAAS,IAAI,IAAIC,CAAM,GACvBK,IAAKH,EAAM,QAAQ,MAASH,EAAO,IAAII,CAAI,CAAC,CAAC,CAAC;CAEpD,OADIE,MAAO,IAAU,KACdA,MAAOH,EAAM,UAAgB;AACtC;AAEA,IAAMI,IAAS;AAGf,SAAgBC,EAAY,GAAgB,IAAM,KAAK,IAAI,GAAkB;CAE3E,OADIC,MAAW,QAAc,wBACtB,IAAI,KAAKC,IAAM,OAAOD,CAAM,IAAIF,CAAM,EAAA,CAAE,YAAY;AAC7D;AAKA,SAAgBI,EAAa,GAA8C;CAKzE,OAJIC,EAAM,YAAY,WAAW,IAAU,YACtCA,EAAM,KAAK,KAAK,IACjBA,EAAM,QAAQ,EAAEA,EAAM,UAAU,KAAK,KAAKA,EAAM,KAAK,KAAK,KACrD,gBACF,OAHwB;AAIjC;AAGA,SAAgBC,EACd,GACA,GACA,IAA8BD,EAAM,SACpC,IAAM,KAAK,IAAI,GACO;CACtB,OAAO;EACL,MAAMA,EAAM,KAAK,KAAK;EACtB,aAAaA,EAAM;EACnB,QAAQA,EAAM;EACd,aAAaA,EAAM;EACnB,gBAAgBA,EAAM,UAAU,cAAcE,IAAiB,KAAA;EAC/D,YAAYC;EACZ,gBAAgBP,EAAYI,EAAM,QAAQF,CAAG;EAC7C,cAAc;CAChB;AACF;AAGA,SAAgBM,EAAW,GAAoD;CAC7E,OAAO;EACL,MAAMJ,EAAM,UAAU,KAAK,KAAKA,EAAM,KAAK,KAAK;EAChD,aAAaA,EAAM;EACnB,QAAQA,EAAM;CAChB;AACF;AAMA,SAAgBK,EACd,GACA,GACS;CACT,OAAOtB,EAAM,YAAY,KAAKC,CAAS;AACzC;AAMA,SAAgBsB,EACd,GACA,GACA,GACsB;CACtB,IAAMxB,IAASC,EAAM,QAAQ,YAAY;CACzC,OAAO;EACL;EACA,aAAaA,EAAM,YAAY,OAAOC,CAAS;EAC/C,QAAQC,EAAkB,MAAM,MAAMC,MAAMJ,CAAM,KAAKF,EAAY;EACnE,aAAa;EACb,YAAYG,EAAM;EAClB,gBAAgB;EAChB,cAAc;CAChB;AACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ExportJob, ExportTemplate } from '../types';
|
|
2
|
+
export interface DownloadActions {
|
|
3
|
+
/** Follows the download's link, checked again now: an expired one is said, not followed. */
|
|
4
|
+
download: (job: ExportJob) => void;
|
|
5
|
+
cancel: (job: ExportJob) => Promise<void>;
|
|
6
|
+
/** Try again (failed) or Make again (expired, cancelled). */
|
|
7
|
+
again: (job: ExportJob) => Promise<void>;
|
|
8
|
+
remove: (job: ExportJob) => Promise<void>;
|
|
9
|
+
saveAsSetup: (job: ExportJob) => Promise<void>;
|
|
10
|
+
runSetup: (setup: ExportTemplate) => Promise<void>;
|
|
11
|
+
removeSetup: (setup: ExportTemplate) => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare function useDownloadActions(input: {
|
|
14
|
+
refreshDownloads: () => void;
|
|
15
|
+
refreshSetups: () => void;
|
|
16
|
+
showDownloads: () => void;
|
|
17
|
+
showSetups: () => void;
|
|
18
|
+
/** The kinds of data offered here: Run now sends only those. */
|
|
19
|
+
isOffered: (entityType: string) => boolean;
|
|
20
|
+
}): DownloadActions;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useCancelExportJob as e, useCreateExportJob as t, useCreateExportTemplate as n, useDeleteExportJob as r, useDeleteExportTemplate as i, useRetryExportJob as a } from "../hooks/useExportQueries.js";
|
|
2
|
+
import { useTr as o } from "../hooks/useTr.js";
|
|
3
|
+
import { exportArchiveDownload as s } from "../utils/exportAuthority.js";
|
|
4
|
+
import { suggestedDownloadName as c } from "../utils/newDownloadForm.js";
|
|
5
|
+
import { runSetupInput as l } from "./newDownloadModel.js";
|
|
6
|
+
import { useConfirm as u, useNotify as d } from "@burdenoff/fe-libs/ui";
|
|
7
|
+
// src/export/workspace-v2/useDownloadActions.ts
|
|
8
|
+
function f(f) {
|
|
9
|
+
let p = o(), m = d(), h = u(), { cancelJob: g } = e(), { retryJob: _ } = a(), { deleteJob: v } = r(), { createJob: y } = t(), { createTemplate: b } = n(), { deleteTemplate: x } = i(), S = (e, t) => m({
|
|
10
|
+
tone: "error",
|
|
11
|
+
title: e,
|
|
12
|
+
description: t instanceof Error && t.message ? t.message : void 0,
|
|
13
|
+
urgent: !0
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
download: (e) => {
|
|
17
|
+
let t = s(e, Date.now());
|
|
18
|
+
t ? window.location.assign(t) : (m({
|
|
19
|
+
tone: "error",
|
|
20
|
+
title: p("export.v2.download.expired", "The link to “{{name}}” had expired", { name: e.name }),
|
|
21
|
+
description: p("export.v2.download.expiredHelp", "The list is updating. Try again in a moment.")
|
|
22
|
+
}), f.refreshDownloads());
|
|
23
|
+
},
|
|
24
|
+
cancel: async (e) => {
|
|
25
|
+
if (await h({
|
|
26
|
+
title: p("export.v2.cancel.title", "Stop preparing “{{name}}”?", { name: e.name }),
|
|
27
|
+
description: p("export.v2.cancel.description", "What it has packed so far is dropped. You can make it again later."),
|
|
28
|
+
confirmLabel: p("export.v2.cancel.confirm", "Stop it"),
|
|
29
|
+
cancelLabel: p("export.v2.cancel.keep", "Keep preparing")
|
|
30
|
+
})) try {
|
|
31
|
+
await g(e.id), m({
|
|
32
|
+
tone: "success",
|
|
33
|
+
title: p("export.v2.cancel.done", "Stopped “{{name}}”", { name: e.name })
|
|
34
|
+
});
|
|
35
|
+
} catch (e) {
|
|
36
|
+
S(p("export.v2.cancel.failed", "Couldn’t stop the download"), e);
|
|
37
|
+
} finally {
|
|
38
|
+
f.refreshDownloads();
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
again: async (e) => {
|
|
42
|
+
try {
|
|
43
|
+
await _(e.id), m({
|
|
44
|
+
tone: "success",
|
|
45
|
+
title: p("export.v2.again.done", "Started “{{name}}” again", { name: e.name })
|
|
46
|
+
});
|
|
47
|
+
} catch (e) {
|
|
48
|
+
S(p("export.v2.again.failed", "Couldn’t start it again"), e);
|
|
49
|
+
} finally {
|
|
50
|
+
f.refreshDownloads();
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
remove: async (e) => {
|
|
54
|
+
if (await h({
|
|
55
|
+
title: p("export.v2.delete.title", "Delete “{{name}}”?", { name: e.name }),
|
|
56
|
+
description: p("export.v2.delete.description", "The file goes for good. Your data stays where it is."),
|
|
57
|
+
tone: "danger",
|
|
58
|
+
confirmLabel: p("export.v2.delete.confirm", "Delete download")
|
|
59
|
+
})) try {
|
|
60
|
+
await v(e.id), m({ title: p("export.v2.delete.done", "Deleted “{{name}}”", { name: e.name }) });
|
|
61
|
+
} catch (e) {
|
|
62
|
+
S(p("export.v2.delete.failed", "Couldn’t delete the download"), e);
|
|
63
|
+
} finally {
|
|
64
|
+
f.refreshDownloads();
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
saveAsSetup: async (e) => {
|
|
68
|
+
try {
|
|
69
|
+
await b({
|
|
70
|
+
name: e.name,
|
|
71
|
+
entityTypes: e.entityTypes,
|
|
72
|
+
format: e.format
|
|
73
|
+
}), m({
|
|
74
|
+
tone: "success",
|
|
75
|
+
title: p("export.v2.saveSetup.done", "Saved “{{name}}” as a setup", { name: e.name }),
|
|
76
|
+
action: {
|
|
77
|
+
label: p("export.v2.saveSetup.see", "See setups"),
|
|
78
|
+
onClick: f.showSetups
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
} catch (e) {
|
|
82
|
+
S(p("export.v2.saveSetup.failed", "Couldn’t save the setup"), e);
|
|
83
|
+
} finally {
|
|
84
|
+
f.refreshSetups();
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
runSetup: async (e) => {
|
|
88
|
+
let t = l(e, c(e.name), f.isOffered);
|
|
89
|
+
if (t.entityTypes.length === 0) m({
|
|
90
|
+
tone: "error",
|
|
91
|
+
title: p("export.v2.run.nothingHere", "Nothing in “{{name}}” can be downloaded here", { name: e.name })
|
|
92
|
+
});
|
|
93
|
+
else try {
|
|
94
|
+
await y(t), m({
|
|
95
|
+
tone: "success",
|
|
96
|
+
title: p("export.v2.run.done", "Started “{{name}}”", { name: e.name }),
|
|
97
|
+
description: p("export.v2.run.description", "It shows up in Downloads when it’s ready."),
|
|
98
|
+
action: {
|
|
99
|
+
label: p("export.v2.run.see", "See downloads"),
|
|
100
|
+
onClick: f.showDownloads
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
} catch (t) {
|
|
104
|
+
S(p("export.v2.run.failed", "Couldn’t start “{{name}}”", { name: e.name }), t);
|
|
105
|
+
} finally {
|
|
106
|
+
f.refreshDownloads();
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
removeSetup: async (e) => {
|
|
110
|
+
if (await h({
|
|
111
|
+
title: p("export.v2.deleteSetup.title", "Delete the setup “{{name}}”?", { name: e.name }),
|
|
112
|
+
description: p("export.v2.deleteSetup.description", "Downloads made from it stay in Downloads."),
|
|
113
|
+
tone: "danger",
|
|
114
|
+
confirmLabel: p("export.v2.deleteSetup.confirm", "Delete setup")
|
|
115
|
+
})) try {
|
|
116
|
+
await x(e.id), m({ title: p("export.v2.deleteSetup.done", "Deleted “{{name}}”", { name: e.name }) });
|
|
117
|
+
} catch (e) {
|
|
118
|
+
S(p("export.v2.deleteSetup.failed", "Couldn’t delete the setup"), e);
|
|
119
|
+
} finally {
|
|
120
|
+
f.refreshSetups();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export { f as useDownloadActions };
|
|
126
|
+
|
|
127
|
+
//# sourceMappingURL=useDownloadActions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDownloadActions.js","names":["useDownloadActions","tr","useTr","notify","useNotify","confirm","useConfirm","useCancelExportJob","useRetryExportJob","useDeleteExportJob","useCreateExportJob","useCreateExportTemplate","useDeleteExportTemplate","failed","error","url","exportArchiveDownload","job","input","cancelJob","retryJob","deleteJob","createTemplate","runSetupInput","setup","suggestedDownloadName","createJob","deleteTemplate"],"sources":["../../../src/export/workspace-v2/useDownloadActions.ts"],"sourcesContent":["/**\n * What the rows of \"Download your data\" do (BOFF-15822), with the export\n * service's own calls. Anything that removes or stops something asks first\n * (the page's own confirm, BOFF-15689); every outcome is said in a toast, and\n * the lists ask again afterwards.\n */\nimport { useConfirm, useNotify } from \"@burdenoff/fe-libs/ui\";\nimport {\n useCancelExportJob,\n useCreateExportJob,\n useCreateExportTemplate,\n useDeleteExportJob,\n useDeleteExportTemplate,\n useRetryExportJob,\n} from \"../hooks/useExportQueries\";\nimport { useTr } from \"../hooks/useTr\";\nimport type { ExportJob, ExportTemplate } from \"../types\";\nimport { exportArchiveDownload } from \"../utils/exportAuthority\";\nimport { suggestedDownloadName } from \"../utils/newDownloadForm\";\nimport { runSetupInput } from \"./newDownloadModel\";\n\nexport interface DownloadActions {\n /** Follows the download's link, checked again now: an expired one is said, not followed. */\n download: (job: ExportJob) => void;\n cancel: (job: ExportJob) => Promise<void>;\n /** Try again (failed) or Make again (expired, cancelled). */\n again: (job: ExportJob) => Promise<void>;\n remove: (job: ExportJob) => Promise<void>;\n saveAsSetup: (job: ExportJob) => Promise<void>;\n runSetup: (setup: ExportTemplate) => Promise<void>;\n removeSetup: (setup: ExportTemplate) => Promise<void>;\n}\n\nexport function useDownloadActions(input: {\n refreshDownloads: () => void;\n refreshSetups: () => void;\n showDownloads: () => void;\n showSetups: () => void;\n /** The kinds of data offered here: Run now sends only those. */\n isOffered: (entityType: string) => boolean;\n}): DownloadActions {\n const tr = useTr();\n const notify = useNotify();\n const confirm = useConfirm();\n const { cancelJob } = useCancelExportJob();\n const { retryJob } = useRetryExportJob();\n const { deleteJob } = useDeleteExportJob();\n const { createJob } = useCreateExportJob();\n const { createTemplate } = useCreateExportTemplate();\n const { deleteTemplate } = useDeleteExportTemplate();\n\n const failed = (title: string, error: unknown) =>\n notify({\n tone: \"error\",\n title,\n description:\n error instanceof Error && error.message ? error.message : undefined,\n urgent: true,\n });\n\n return {\n download: (job) => {\n const url = exportArchiveDownload(job, Date.now());\n if (url) {\n window.location.assign(url);\n return;\n }\n // The service signs a fresh link each time the list is read (or the\n // download has expired, and its row then offers Make again).\n notify({\n tone: \"error\",\n title: tr(\n \"export.v2.download.expired\",\n \"The link to “{{name}}” had expired\",\n { name: job.name },\n ),\n description: tr(\n \"export.v2.download.expiredHelp\",\n \"The list is updating. Try again in a moment.\",\n ),\n });\n input.refreshDownloads();\n },\n\n cancel: async (job) => {\n const yes = await confirm({\n title: tr(\"export.v2.cancel.title\", \"Stop preparing “{{name}}”?\", {\n name: job.name,\n }),\n description: tr(\n \"export.v2.cancel.description\",\n \"What it has packed so far is dropped. You can make it again later.\",\n ),\n confirmLabel: tr(\"export.v2.cancel.confirm\", \"Stop it\"),\n cancelLabel: tr(\"export.v2.cancel.keep\", \"Keep preparing\"),\n });\n if (!yes) return;\n try {\n await cancelJob(job.id);\n notify({\n tone: \"success\",\n title: tr(\"export.v2.cancel.done\", \"Stopped “{{name}}”\", {\n name: job.name,\n }),\n });\n } catch (error) {\n failed(\n tr(\"export.v2.cancel.failed\", \"Couldn’t stop the download\"),\n error,\n );\n } finally {\n input.refreshDownloads();\n }\n },\n\n again: async (job) => {\n try {\n await retryJob(job.id);\n notify({\n tone: \"success\",\n title: tr(\"export.v2.again.done\", \"Started “{{name}}” again\", {\n name: job.name,\n }),\n });\n } catch (error) {\n failed(tr(\"export.v2.again.failed\", \"Couldn’t start it again\"), error);\n } finally {\n input.refreshDownloads();\n }\n },\n\n remove: async (job) => {\n const yes = await confirm({\n title: tr(\"export.v2.delete.title\", \"Delete “{{name}}”?\", {\n name: job.name,\n }),\n description: tr(\n \"export.v2.delete.description\",\n \"The file goes for good. Your data stays where it is.\",\n ),\n tone: \"danger\",\n confirmLabel: tr(\"export.v2.delete.confirm\", \"Delete download\"),\n });\n if (!yes) return;\n try {\n await deleteJob(job.id);\n notify({\n title: tr(\"export.v2.delete.done\", \"Deleted “{{name}}”\", {\n name: job.name,\n }),\n });\n } catch (error) {\n failed(\n tr(\"export.v2.delete.failed\", \"Couldn’t delete the download\"),\n error,\n );\n } finally {\n input.refreshDownloads();\n }\n },\n\n saveAsSetup: async (job) => {\n try {\n await createTemplate({\n name: job.name,\n entityTypes: job.entityTypes,\n format: job.format,\n });\n notify({\n tone: \"success\",\n title: tr(\"export.v2.saveSetup.done\", \"Saved “{{name}}” as a setup\", {\n name: job.name,\n }),\n action: {\n label: tr(\"export.v2.saveSetup.see\", \"See setups\"),\n onClick: input.showSetups,\n },\n });\n } catch (error) {\n failed(\n tr(\"export.v2.saveSetup.failed\", \"Couldn’t save the setup\"),\n error,\n );\n } finally {\n input.refreshSetups();\n }\n },\n\n runSetup: async (setup) => {\n const job = runSetupInput(\n setup,\n suggestedDownloadName(setup.name),\n input.isOffered,\n );\n // Run now is locked for such a setup; never send an empty download.\n if (job.entityTypes.length === 0) {\n notify({\n tone: \"error\",\n title: tr(\n \"export.v2.run.nothingHere\",\n \"Nothing in “{{name}}” can be downloaded here\",\n { name: setup.name },\n ),\n });\n return;\n }\n try {\n await createJob(job);\n notify({\n tone: \"success\",\n title: tr(\"export.v2.run.done\", \"Started “{{name}}”\", {\n name: setup.name,\n }),\n description: tr(\n \"export.v2.run.description\",\n \"It shows up in Downloads when it’s ready.\",\n ),\n action: {\n label: tr(\"export.v2.run.see\", \"See downloads\"),\n onClick: input.showDownloads,\n },\n });\n } catch (error) {\n failed(\n tr(\"export.v2.run.failed\", \"Couldn’t start “{{name}}”\", {\n name: setup.name,\n }),\n error,\n );\n } finally {\n input.refreshDownloads();\n }\n },\n\n removeSetup: async (setup) => {\n const yes = await confirm({\n title: tr(\n \"export.v2.deleteSetup.title\",\n \"Delete the setup “{{name}}”?\",\n { name: setup.name },\n ),\n description: tr(\n \"export.v2.deleteSetup.description\",\n \"Downloads made from it stay in Downloads.\",\n ),\n tone: \"danger\",\n confirmLabel: tr(\"export.v2.deleteSetup.confirm\", \"Delete setup\"),\n });\n if (!yes) return;\n try {\n await deleteTemplate(setup.id);\n notify({\n title: tr(\"export.v2.deleteSetup.done\", \"Deleted “{{name}}”\", {\n name: setup.name,\n }),\n });\n } catch (error) {\n failed(\n tr(\"export.v2.deleteSetup.failed\", \"Couldn’t delete the setup\"),\n error,\n );\n } finally {\n input.refreshSetups();\n }\n },\n };\n}\n"],"mappings":";;;;;;;AAiCA,SAAgBA,EAAmB,GAOf;CAClB,IAAMC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,EAAM,KAAK,CACrB;GACF,CAAC;QAGH,IAAI;IAEF,AADA,MAAME,EAAUT,CAAG,GACnBd,EAAO;KACL,MAAM;KACN,OAAOF,EAAG,sBAAsB,sBAAsB,EACpD,MAAMuB,EAAM,KACd,CAAC;KACD,aAAavB,EACX,6BACA,2CACF;KACA,QAAQ;MACN,OAAOA,EAAG,qBAAqB,eAAe;MAC9C,SAASiB,EAAM;KACjB;IACF,CAAC;GACH,SAASJ,GAAO;IACd,EACEb,EAAG,wBAAwB,6BAA6B,EACtD,MAAMuB,EAAM,KACd,CAAC,GACDV,CACF;GACF,UAAU;IACR,EAAM,iBAAiB;GACzB;EACF;EAEA,aAAa,OAAO,MAAU;GAc5B,IAAK,MAbaT,EAAQ;IACxB,OAAOJ,EACL,+BACA,gCACA,EAAE,MAAMuB,EAAM,KAAK,CACrB;IACA,aAAavB,EACX,qCACA,2CACF;IACA,MAAM;IACN,cAAcA,EAAG,iCAAiC,cAAc;GAClE,CAAC,GAED,IAAI;IAEF,AADA,MAAM0B,EAAeH,EAAM,EAAE,GAC7BrB,EAAO,EACL,OAAOF,EAAG,8BAA8B,sBAAsB,EAC5D,MAAMuB,EAAM,KACd,CAAC,EACH,CAAC;GACH,SAASV,GAAO;IACd,EACEb,EAAG,gCAAgC,2BAA2B,GAC9Da,CACF;GACF,UAAU;IACR,EAAM,cAAc;GACtB;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ExportJob, ExportJobStatus, ExportTemplate } from '../types';
|
|
2
|
+
/** How often a preparing download's progress is read again. */
|
|
3
|
+
export declare const PREPARING_POLL_MS = 5000;
|
|
4
|
+
export interface DownloadsListQuery {
|
|
5
|
+
statuses?: ExportJobStatus[];
|
|
6
|
+
entityTypes?: string[];
|
|
7
|
+
search?: string;
|
|
8
|
+
sort?: string;
|
|
9
|
+
/** 1-based. */
|
|
10
|
+
page: number;
|
|
11
|
+
pageSize: number;
|
|
12
|
+
}
|
|
13
|
+
export interface DownloadsList {
|
|
14
|
+
/** The downloads on this page. */
|
|
15
|
+
jobs: ExportJob[];
|
|
16
|
+
/** Every download that matches, from the service; undefined until it answers. */
|
|
17
|
+
total: number | undefined;
|
|
18
|
+
/** Nothing to show yet: the first load, or a later window on its way. */
|
|
19
|
+
loading: boolean;
|
|
20
|
+
error: Error | null;
|
|
21
|
+
/** Asks again (after a change, or "Try again"). */
|
|
22
|
+
refresh: () => void;
|
|
23
|
+
}
|
|
24
|
+
export declare function useDownloadsList(query: DownloadsListQuery): DownloadsList;
|
|
25
|
+
/**
|
|
26
|
+
* Reads these downloads again every 5 seconds, one by one, while they
|
|
27
|
+
* prepare. Each answer lands on the cached download (by its id), so its row
|
|
28
|
+
* updates where it is.
|
|
29
|
+
*/
|
|
30
|
+
export declare function usePollJobs(jobIds: readonly string[], workspaceId: string | undefined,
|
|
31
|
+
/** Called when one of them is no longer preparing. */
|
|
32
|
+
onFinished?: () => void): void;
|
|
33
|
+
/** The most saved setups the service gives at once. */
|
|
34
|
+
export declare const SETUPS_LIMIT = 100;
|
|
35
|
+
export interface SavedSetups {
|
|
36
|
+
setups: ExportTemplate[];
|
|
37
|
+
/** Every saved setup there is, from the service; undefined until it answers. */
|
|
38
|
+
total: number | undefined;
|
|
39
|
+
loading: boolean;
|
|
40
|
+
error: Error | null;
|
|
41
|
+
refresh: () => void;
|
|
42
|
+
}
|
|
43
|
+
export declare function useSavedSetups(): SavedSetups;
|
|
44
|
+
export interface SetupById {
|
|
45
|
+
setup: ExportTemplate | null;
|
|
46
|
+
/** The service answered: with the setup, or that it has none by that id. */
|
|
47
|
+
answered: boolean;
|
|
48
|
+
/** Asking failed for another reason (the service, the network): Try again. */
|
|
49
|
+
error: Error | null;
|
|
50
|
+
retry: () => void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* One saved setup by its id, for New download started from a setup the list
|
|
54
|
+
* doesn't hold (past its first 100: an old link, or the setup's own page).
|
|
55
|
+
* Without an id, nothing is asked and there is nothing to wait for.
|
|
56
|
+
*/
|
|
57
|
+
export declare function useSetupById(setupId: string | undefined): SetupById;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { GetExportJobDocument as e, GetExportTemplateDocument as t, ListExportJobsDocument as n, ListExportTemplatesDocument as r } from "../../generated/wspace-operations.js";
|
|
2
|
+
import { ExportJobStatus as i } from "../../generated/wspace-types.js";
|
|
3
|
+
import { mapJob as a, mapTemplate as o } from "../hooks/useExportQueries.js";
|
|
4
|
+
import { useExport as s } from "../providers/ExportProvider.js";
|
|
5
|
+
import { isInProgress as c } from "../utils/downloadStatus.js";
|
|
6
|
+
import { preparingPoll as l, sortInput as u } from "./downloadsModel.js";
|
|
7
|
+
import { useEffect as d, useMemo as f, useRef as p, useState as m } from "react";
|
|
8
|
+
import { CombinedGraphQLErrors as h, NetworkStatus as g } from "@apollo/client";
|
|
9
|
+
import { useApolloClient as _, useQuery as v } from "@apollo/client/react";
|
|
10
|
+
// src/export/workspace-v2/useDownloadsData.ts
|
|
11
|
+
var y = {
|
|
12
|
+
CANCELLED: i.Cancelled,
|
|
13
|
+
COMPLETED: i.Completed,
|
|
14
|
+
CREATED: i.Created,
|
|
15
|
+
DELETED: i.Deleted,
|
|
16
|
+
EXPIRED: i.Expired,
|
|
17
|
+
FAILED: i.Failed,
|
|
18
|
+
QUEUED: i.Queued,
|
|
19
|
+
RUNNING: i.Running
|
|
20
|
+
}, b = 5e3;
|
|
21
|
+
function x(e, t) {
|
|
22
|
+
if (!t) return e;
|
|
23
|
+
let n = new Set(e.listExportJobs.edges.map((e) => e.node.id)), r = {
|
|
24
|
+
...t.listExportJobs,
|
|
25
|
+
edges: [...e.listExportJobs.edges, ...t.listExportJobs.edges.filter((e) => !n.has(e.node.id))]
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
...e,
|
|
29
|
+
listExportJobs: r
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function S(e, t) {
|
|
33
|
+
let n = e.statuses?.join(",") ?? "", r = e.entityTypes?.join(",") ?? "", i = e.search?.trim() ?? "", a = u(e.sort);
|
|
34
|
+
return f(() => ({
|
|
35
|
+
filter: {
|
|
36
|
+
status: n ? n.split(",").map((e) => y[e]) : void 0,
|
|
37
|
+
entityTypes: r ? r.split(",") : void 0,
|
|
38
|
+
search: i || void 0
|
|
39
|
+
},
|
|
40
|
+
pagination: {
|
|
41
|
+
first: 100,
|
|
42
|
+
sortBy: a.sortBy,
|
|
43
|
+
sortDirection: a.sortDirection
|
|
44
|
+
},
|
|
45
|
+
context: { workspaceId: t }
|
|
46
|
+
}), [
|
|
47
|
+
a.sortBy,
|
|
48
|
+
a.sortDirection,
|
|
49
|
+
i,
|
|
50
|
+
n,
|
|
51
|
+
r,
|
|
52
|
+
t
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
function C(e) {
|
|
56
|
+
let { connection: t, loadedCount: n, needed: r, growing: i, variables: a, fetchMore: o } = e, s = t?.pageInfo.endCursor ?? null, c = !!(t?.pageInfo.hasNextPage && s), l = `${JSON.stringify(a)}|${s ?? ""}`, [u, f] = m(null), p = u?.key === l;
|
|
57
|
+
return d(() => {
|
|
58
|
+
c && s && !i && !p && (n >= r || o({
|
|
59
|
+
variables: { pagination: {
|
|
60
|
+
...a.pagination,
|
|
61
|
+
after: s
|
|
62
|
+
} },
|
|
63
|
+
updateQuery: (e, { fetchMoreResult: t }) => x(e, t)
|
|
64
|
+
}).catch((e) => {
|
|
65
|
+
f({
|
|
66
|
+
key: l,
|
|
67
|
+
error: e instanceof Error ? e : Error(String(e))
|
|
68
|
+
});
|
|
69
|
+
}));
|
|
70
|
+
}, [
|
|
71
|
+
s,
|
|
72
|
+
p,
|
|
73
|
+
o,
|
|
74
|
+
i,
|
|
75
|
+
l,
|
|
76
|
+
n,
|
|
77
|
+
c,
|
|
78
|
+
r,
|
|
79
|
+
a
|
|
80
|
+
]), {
|
|
81
|
+
failure: p ? u.error : null,
|
|
82
|
+
clear: () => f(null)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function w(e) {
|
|
86
|
+
let { workspaceId: t } = s(), r = S(e, t), i = v(n, {
|
|
87
|
+
variables: r,
|
|
88
|
+
skip: !t,
|
|
89
|
+
notifyOnNetworkStatusChange: !0
|
|
90
|
+
}), { data: o, error: c, fetchMore: u, refetch: p, startPolling: m, stopPolling: h } = i, _ = o?.listExportJobs, y = f(() => _?.edges.map((e) => a(e.node)) ?? [], [_]), x = e.page * e.pageSize, w = i.networkStatus === g.fetchMore, E = C({
|
|
91
|
+
connection: _,
|
|
92
|
+
loadedCount: y.length,
|
|
93
|
+
needed: x,
|
|
94
|
+
growing: w,
|
|
95
|
+
variables: r,
|
|
96
|
+
fetchMore: u
|
|
97
|
+
}), D = () => {
|
|
98
|
+
E.clear(), p().catch(() => void 0);
|
|
99
|
+
}, O = f(() => l(y, e.page, e.pageSize), [
|
|
100
|
+
y,
|
|
101
|
+
e.page,
|
|
102
|
+
e.pageSize
|
|
103
|
+
]);
|
|
104
|
+
d(() => {
|
|
105
|
+
if (O.list) return m(b), () => h();
|
|
106
|
+
}, [
|
|
107
|
+
O.list,
|
|
108
|
+
m,
|
|
109
|
+
h
|
|
110
|
+
]), T(O.jobIds, t, r.filter?.status ? D : void 0);
|
|
111
|
+
let k = (e.page - 1) * e.pageSize, A = y.slice(k, k + e.pageSize), j = y.length < x ? E.failure : null, M = A.length === 0 && y.length < x && (w || !!_?.pageInfo.hasNextPage);
|
|
112
|
+
return {
|
|
113
|
+
jobs: A,
|
|
114
|
+
total: _?.totalCount,
|
|
115
|
+
loading: i.loading && !_ || !j && M,
|
|
116
|
+
error: c ?? j,
|
|
117
|
+
refresh: D
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function T(t, n, r) {
|
|
121
|
+
let i = _(), o = t.join(","), s = p(r);
|
|
122
|
+
d(() => {
|
|
123
|
+
s.current = r;
|
|
124
|
+
}, [r]), d(() => {
|
|
125
|
+
if (!o || !n) return;
|
|
126
|
+
let t = o.split(","), r = setInterval(() => {
|
|
127
|
+
for (let r of t) i.query({
|
|
128
|
+
query: e,
|
|
129
|
+
variables: {
|
|
130
|
+
id: r,
|
|
131
|
+
context: { workspaceId: n }
|
|
132
|
+
},
|
|
133
|
+
fetchPolicy: "network-only"
|
|
134
|
+
}).then(({ data: e }) => {
|
|
135
|
+
let t = e?.getExportJob;
|
|
136
|
+
t && !c(a(t).status) && s.current?.();
|
|
137
|
+
}).catch(() => {});
|
|
138
|
+
}, b);
|
|
139
|
+
return () => clearInterval(r);
|
|
140
|
+
}, [
|
|
141
|
+
i,
|
|
142
|
+
o,
|
|
143
|
+
n
|
|
144
|
+
]);
|
|
145
|
+
}
|
|
146
|
+
function E() {
|
|
147
|
+
let { workspaceId: e } = s(), { data: t, loading: n, error: i, refetch: a } = v(r, {
|
|
148
|
+
variables: {
|
|
149
|
+
context: { workspaceId: e },
|
|
150
|
+
pagination: { first: 100 }
|
|
151
|
+
},
|
|
152
|
+
skip: !e
|
|
153
|
+
}), c = t?.listExportTemplates;
|
|
154
|
+
return {
|
|
155
|
+
setups: f(() => c?.edges.map((e) => o(e.node)) ?? [], [c]),
|
|
156
|
+
total: c?.totalCount,
|
|
157
|
+
loading: n && !c,
|
|
158
|
+
error: i ?? null,
|
|
159
|
+
refresh: () => {
|
|
160
|
+
a().catch(() => void 0);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function D(e) {
|
|
165
|
+
return h.is(e) && e.errors.some((e) => e.extensions?.code === "NOT_FOUND");
|
|
166
|
+
}
|
|
167
|
+
function O(e) {
|
|
168
|
+
let { workspaceId: n } = s(), r = !!(e && n), { data: i, error: a, refetch: c } = v(t, {
|
|
169
|
+
variables: {
|
|
170
|
+
id: e ?? "",
|
|
171
|
+
context: { workspaceId: n }
|
|
172
|
+
},
|
|
173
|
+
skip: !r
|
|
174
|
+
}), l = D(a);
|
|
175
|
+
return {
|
|
176
|
+
setup: i?.getExportTemplate ? o(i.getExportTemplate) : null,
|
|
177
|
+
answered: !r || i !== void 0 || l,
|
|
178
|
+
error: a && !l ? a : null,
|
|
179
|
+
retry: () => {
|
|
180
|
+
c().catch(() => void 0);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
export { b as PREPARING_POLL_MS, w as useDownloadsList, T as usePollJobs, E as useSavedSetups, O as useSetupById };
|
|
185
|
+
|
|
186
|
+
//# sourceMappingURL=useDownloadsData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDownloadsData.js","names":["GqlExportJobStatus","GQL_STATUS","ExportJobStatus","PREPARING_POLL_MS","appendWindow","next","previous","seen","edge","merged","useListVariables","statusesKey","query","typesKey","search","order","sortInput","useMemo","status","workspaceId","useWindowGrowth","input","endCursor","connection","more","key","variables","failed","setFailed","useState","failedHere","useEffect","loadedCount","needed","fetchMore","fetchMoreResult","reason","growing","useDownloadsList","useExport","result","useQuery","ListExportJobsDocument","data","loaded","mapJob","NetworkStatus","growth","refresh","refetch","poll","preparingPoll","startPolling","stopPolling","usePollJobs","start","jobs","pageFailure","waiting","error","client","useApolloClient","jobIds","finished","useRef","onFinished","ids","timer","id","GetExportJobDocument","job","isInProgress","useSavedSetups","ListExportTemplatesDocument","mapTemplate","loading","isNotFound","CombinedGraphQLErrors","entry","useSetupById","asked","setupId","GetExportTemplateDocument","notFound"],"sources":["../../../src/export/workspace-v2/useDownloadsData.ts"],"sourcesContent":["/**\n * The data of the redesigned \"Download your data\" (BOFF-15822).\n *\n * - `useDownloadsList`: the downloads, filtered, searched and sorted by the\n * export service, as the shared pager's numbered pages. The service pages by\n * cursor (at most 100 at a time), so the list asks for windows of 100 and\n * grows them on one cached list as the person pages on: with 20 a page,\n * page 6 asks for the second window once, and going back is instant. While\n * a download is preparing, its progress is read again every 5 seconds\n * (`preparingPoll`).\n * - `useSavedSetups`: the workspace's saved setups (export templates), up to\n * the service's 100 at a time; `useSetupById` asks for one past those.\n */\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { CombinedGraphQLErrors, NetworkStatus } from \"@apollo/client\";\nimport { useApolloClient, useQuery } from \"@apollo/client/react\";\nimport {\n GetExportJobDocument,\n GetExportTemplateDocument,\n ListExportJobsDocument,\n ListExportTemplatesDocument,\n type GetExportJobQuery,\n type GetExportJobQueryVariables,\n type GetExportTemplateQuery,\n type GetExportTemplateQueryVariables,\n type ListExportJobsQuery,\n type ListExportJobsQueryVariables,\n type ListExportTemplatesQuery,\n type ListExportTemplatesQueryVariables,\n} from \"../../generated/wspace-operations\";\nimport { ExportJobStatus as GqlExportJobStatus } from \"../../generated/wspace-types\";\nimport { mapJob, mapTemplate } from \"../hooks/useExportQueries\";\nimport { useExport } from \"../providers/ExportProvider\";\nimport type { ExportJob, ExportJobStatus, ExportTemplate } from \"../types\";\nimport { isInProgress } from \"../utils/downloadStatus\";\nimport { WINDOW_SIZE, preparingPoll, sortInput } from \"./downloadsModel\";\n\n/** The service's enum value for each status. */\nconst GQL_STATUS: Readonly<Record<ExportJobStatus, GqlExportJobStatus>> = {\n CANCELLED: GqlExportJobStatus.Cancelled,\n COMPLETED: GqlExportJobStatus.Completed,\n CREATED: GqlExportJobStatus.Created,\n DELETED: GqlExportJobStatus.Deleted,\n EXPIRED: GqlExportJobStatus.Expired,\n FAILED: GqlExportJobStatus.Failed,\n QUEUED: GqlExportJobStatus.Queued,\n RUNNING: GqlExportJobStatus.Running,\n};\n\n/** How often a preparing download's progress is read again. */\nexport const PREPARING_POLL_MS = 5000;\n\nexport interface DownloadsListQuery {\n statuses?: ExportJobStatus[];\n entityTypes?: string[];\n search?: string;\n sort?: string;\n /** 1-based. */\n page: number;\n pageSize: number;\n}\n\nexport interface DownloadsList {\n /** The downloads on this page. */\n jobs: ExportJob[];\n /** Every download that matches, from the service; undefined until it answers. */\n total: number | undefined;\n /** Nothing to show yet: the first load, or a later window on its way. */\n loading: boolean;\n error: Error | null;\n /** Asks again (after a change, or \"Try again\"). */\n refresh: () => void;\n}\n\ntype Connection = ListExportJobsQuery[\"listExportJobs\"];\n\n/** Appends a further window to the list loaded so far. */\nfunction appendWindow(\n previous: ListExportJobsQuery,\n next: ListExportJobsQuery | undefined,\n): ListExportJobsQuery {\n if (!next) return previous;\n const seen = new Set(\n previous.listExportJobs.edges.map((edge) => edge.node.id),\n );\n const merged: Connection = {\n ...next.listExportJobs,\n edges: [\n ...previous.listExportJobs.edges,\n ...next.listExportJobs.edges.filter((edge) => !seen.has(edge.node.id)),\n ],\n };\n return { ...previous, listExportJobs: merged };\n}\n\n/** The list query's variables: the filters, search and order, one window at a time. */\nfunction useListVariables(\n query: DownloadsListQuery,\n workspaceId: string | undefined,\n): ListExportJobsQueryVariables {\n const statusesKey = query.statuses?.join(\",\") ?? \"\";\n const typesKey = query.entityTypes?.join(\",\") ?? \"\";\n const search = query.search?.trim() ?? \"\";\n const order = sortInput(query.sort);\n return useMemo<ListExportJobsQueryVariables>(\n () => ({\n filter: {\n // The key is the statuses joined (a stable memo dependency while\n // callers pass fresh arrays); splitting it gives those statuses back.\n status: statusesKey\n ? statusesKey\n .split(\",\")\n .map((status) => GQL_STATUS[status as ExportJobStatus])\n : undefined,\n entityTypes: typesKey ? typesKey.split(\",\") : undefined,\n search: search || undefined,\n },\n pagination: {\n first: WINDOW_SIZE,\n sortBy: order.sortBy,\n sortDirection: order.sortDirection,\n },\n context: { workspaceId },\n }),\n [\n order.sortBy,\n order.sortDirection,\n search,\n statusesKey,\n typesKey,\n workspaceId,\n ],\n );\n}\n\ntype FetchMore = ReturnType<\n typeof useQuery<ListExportJobsQuery, ListExportJobsQueryVariables>\n>[\"fetchMore\"];\n\n/**\n * Asks for the next window until a page's downloads are here, or the list\n * ends. A window that failed is asked for again only by `clear` (Try again),\n * never by itself: a failing service would otherwise be asked in a loop.\n */\nfunction useWindowGrowth(input: {\n connection: ListExportJobsQuery[\"listExportJobs\"] | undefined;\n loadedCount: number;\n needed: number;\n growing: boolean;\n variables: ListExportJobsQueryVariables;\n fetchMore: FetchMore;\n}): { failure: Error | null; clear: () => void } {\n const { connection, loadedCount, needed, growing, variables, fetchMore } =\n input;\n const endCursor = connection?.pageInfo.endCursor ?? null;\n const more = Boolean(connection?.pageInfo.hasNextPage && endCursor);\n const key = `${JSON.stringify(variables)}|${endCursor ?? \"\"}`;\n const [failed, setFailed] = useState<{ key: string; error: Error } | null>(\n null,\n );\n const failedHere = failed?.key === key;\n useEffect(() => {\n if (!more || !endCursor || growing || failedHere) return;\n if (loadedCount >= needed) return;\n void fetchMore({\n variables: {\n pagination: { ...variables.pagination, after: endCursor },\n },\n updateQuery: (previous, { fetchMoreResult }) =>\n appendWindow(previous, fetchMoreResult),\n }).catch((reason: unknown) => {\n setFailed({\n key,\n error: reason instanceof Error ? reason : new Error(String(reason)),\n });\n });\n }, [\n endCursor,\n failedHere,\n fetchMore,\n growing,\n key,\n loadedCount,\n more,\n needed,\n variables,\n ]);\n return {\n failure: failedHere ? failed.error : null,\n clear: () => setFailed(null),\n };\n}\n\nexport function useDownloadsList(query: DownloadsListQuery): DownloadsList {\n const { workspaceId } = useExport();\n const variables = useListVariables(query, workspaceId);\n const result = useQuery<ListExportJobsQuery, ListExportJobsQueryVariables>(\n ListExportJobsDocument,\n {\n variables,\n skip: !workspaceId,\n notifyOnNetworkStatusChange: true,\n },\n );\n const { data, error, fetchMore, refetch, startPolling, stopPolling } = result;\n const connection = data?.listExportJobs;\n const loaded = useMemo(\n () => connection?.edges.map((edge) => mapJob(edge.node)) ?? [],\n [connection],\n );\n const needed = query.page * query.pageSize;\n const growing = result.networkStatus === NetworkStatus.fetchMore;\n const growth = useWindowGrowth({\n connection,\n loadedCount: loaded.length,\n needed,\n growing,\n variables,\n fetchMore,\n });\n const refresh = () => {\n growth.clear();\n void refetch().catch(() => undefined);\n };\n\n // Progress: while something prepares, the first window is asked again; on\n // a later page, its preparing downloads are read again one by one. Under a\n // Status filter, one that finished no longer belongs to the list: the list\n // is read again.\n const poll = useMemo(\n () => preparingPoll(loaded, query.page, query.pageSize),\n [loaded, query.page, query.pageSize],\n );\n useEffect(() => {\n if (!poll.list) return undefined;\n startPolling(PREPARING_POLL_MS);\n return () => stopPolling();\n }, [poll.list, startPolling, stopPolling]);\n usePollJobs(\n poll.jobIds,\n workspaceId,\n variables.filter?.status ? refresh : undefined,\n );\n\n const start = (query.page - 1) * query.pageSize;\n const jobs = loaded.slice(start, start + query.pageSize);\n // The window this page needs failed: its error, not an endless skeleton.\n const pageFailure = loaded.length < needed ? growth.failure : null;\n const waiting =\n jobs.length === 0 &&\n loaded.length < needed &&\n (growing || Boolean(connection?.pageInfo.hasNextPage));\n return {\n jobs,\n total: connection?.totalCount,\n loading: (result.loading && !connection) || (!pageFailure && waiting),\n error: error ?? pageFailure,\n refresh,\n };\n}\n\n/**\n * Reads these downloads again every 5 seconds, one by one, while they\n * prepare. Each answer lands on the cached download (by its id), so its row\n * updates where it is.\n */\nexport function usePollJobs(\n jobIds: readonly string[],\n workspaceId: string | undefined,\n /** Called when one of them is no longer preparing. */\n onFinished?: () => void,\n): void {\n const client = useApolloClient();\n // A stable dependency while callers pass fresh arrays.\n const key = jobIds.join(\",\");\n // The newest callback, without restarting the timer when it changes.\n const finished = useRef(onFinished);\n useEffect(() => {\n finished.current = onFinished;\n }, [onFinished]);\n useEffect(() => {\n if (!key || !workspaceId) return undefined;\n const ids = key.split(\",\");\n const timer = setInterval(() => {\n for (const id of ids) {\n void client\n .query<GetExportJobQuery, GetExportJobQueryVariables>({\n query: GetExportJobDocument,\n variables: { id, context: { workspaceId } },\n fetchPolicy: \"network-only\",\n })\n .then(({ data }) => {\n const job = data?.getExportJob;\n if (job && !isInProgress(mapJob(job).status)) {\n finished.current?.();\n }\n })\n .catch(() => {\n // The row keeps what it showed; the next turn asks again.\n });\n }\n }, PREPARING_POLL_MS);\n return () => clearInterval(timer);\n }, [client, key, workspaceId]);\n}\n\n/** The most saved setups the service gives at once. */\nexport const SETUPS_LIMIT = 100;\n\nexport interface SavedSetups {\n setups: ExportTemplate[];\n /** Every saved setup there is, from the service; undefined until it answers. */\n total: number | undefined;\n loading: boolean;\n error: Error | null;\n refresh: () => void;\n}\n\nexport function useSavedSetups(): SavedSetups {\n const { workspaceId } = useExport();\n const { data, loading, error, refetch } = useQuery<\n ListExportTemplatesQuery,\n ListExportTemplatesQueryVariables\n >(ListExportTemplatesDocument, {\n variables: {\n context: { workspaceId },\n pagination: { first: SETUPS_LIMIT },\n },\n skip: !workspaceId,\n });\n const connection = data?.listExportTemplates;\n const setups = useMemo(\n () => connection?.edges.map((edge) => mapTemplate(edge.node)) ?? [],\n [connection],\n );\n return {\n setups,\n total: connection?.totalCount,\n loading: loading && !connection,\n error: error ?? null,\n refresh: () => {\n void refetch().catch(() => undefined);\n },\n };\n}\n\nexport interface SetupById {\n setup: ExportTemplate | null;\n /** The service answered: with the setup, or that it has none by that id. */\n answered: boolean;\n /** Asking failed for another reason (the service, the network): Try again. */\n error: Error | null;\n retry: () => void;\n}\n\n/** The service says it has nothing by that id (NOT_FOUND). */\nfunction isNotFound(error: unknown): boolean {\n return (\n CombinedGraphQLErrors.is(error) &&\n error.errors.some((entry) => entry.extensions?.code === \"NOT_FOUND\")\n );\n}\n\n/**\n * One saved setup by its id, for New download started from a setup the list\n * doesn't hold (past its first 100: an old link, or the setup's own page).\n * Without an id, nothing is asked and there is nothing to wait for.\n */\nexport function useSetupById(setupId: string | undefined): SetupById {\n const { workspaceId } = useExport();\n const asked = Boolean(setupId && workspaceId);\n const { data, error, refetch } = useQuery<\n GetExportTemplateQuery,\n GetExportTemplateQueryVariables\n >(GetExportTemplateDocument, {\n variables: { id: setupId ?? \"\", context: { workspaceId } },\n skip: !asked,\n });\n const notFound = isNotFound(error);\n return {\n setup: data?.getExportTemplate ? mapTemplate(data.getExportTemplate) : null,\n // A refusal for another reason is not \"it's gone\": the dialog offers\n // Try again instead of starting without the setup.\n answered: !asked || data !== undefined || notFound,\n error: error && !notFound ? error : null,\n retry: () => {\n void refetch().catch(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AU,CAACqC,KAASrC,MAAS,KAAA,KAAawC;EAC1C,OAAOxB,KAAS,CAACwB,IAAWxB,IAAQ;EACpC,aAAa;GACX,EAAa,CAAC,CAAC,YAAY,KAAA,CAAS;EACtC;CACF;AACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ListState } from '@burdenoff/fe-libs/ui';
|
|
2
|
+
export type DownloadsTab = "downloads" | "setups";
|
|
3
|
+
export interface DownloadsPageState {
|
|
4
|
+
tab: DownloadsTab;
|
|
5
|
+
setTab: (tab: DownloadsTab) => void;
|
|
6
|
+
/** The Downloads list's search, filters, sort and page. */
|
|
7
|
+
list: ListState;
|
|
8
|
+
/** The Saved setups list's page (its own `s_` parameters). */
|
|
9
|
+
setupsList: ListState;
|
|
10
|
+
dialogOpen: boolean;
|
|
11
|
+
/** New download starts from this saved setup. */
|
|
12
|
+
dialogSetupId: string | null;
|
|
13
|
+
openNew: (setupId?: string) => void;
|
|
14
|
+
closeNew: () => void;
|
|
15
|
+
/** A download started: close New download and show the Downloads tab, in one change. */
|
|
16
|
+
finishNew: () => void;
|
|
17
|
+
/** A download's own page (its parts and progress). */
|
|
18
|
+
openDetails: (jobId: string) => void;
|
|
19
|
+
/** A saved setup's own page (to edit it). */
|
|
20
|
+
openSetup: (setupId: string) => void;
|
|
21
|
+
}
|
|
22
|
+
export declare function useDownloadsPage(): DownloadsPageState;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useExport as e } from "../providers/ExportProvider.js";
|
|
2
|
+
import { joinPath as t } from "../utils/paths.js";
|
|
3
|
+
import { CONTAINS_FILTER as n, SETUPS_TAB as r, SETUP_PARAM as i, SORT_VALUES as a, STATUS_FILTER as o } from "./downloadsModel.js";
|
|
4
|
+
import { useCallback as s } from "react";
|
|
5
|
+
import { useSearchParams as c } from "react-router";
|
|
6
|
+
import { useListState as l } from "@burdenoff/fe-libs/ui";
|
|
7
|
+
// src/export/workspace-v2/useDownloadsPage.ts
|
|
8
|
+
var u = [o, n];
|
|
9
|
+
function d() {
|
|
10
|
+
let { basePath: n = "/", navigate: o } = e(), [d, f] = c(), p = l({
|
|
11
|
+
filters: u,
|
|
12
|
+
sorts: a,
|
|
13
|
+
url: [d, f]
|
|
14
|
+
}), m = l({
|
|
15
|
+
urlPrefix: "s_",
|
|
16
|
+
url: [d, f]
|
|
17
|
+
}), h = d.get("tab") === "setups" ? "setups" : "downloads", g = s((e) => f((t) => {
|
|
18
|
+
let n = new URLSearchParams(t);
|
|
19
|
+
return e(n), n;
|
|
20
|
+
}, { replace: !0 }), [f]);
|
|
21
|
+
return {
|
|
22
|
+
tab: h,
|
|
23
|
+
setTab: (e) => g((t) => {
|
|
24
|
+
e === "setups" ? t.set("tab", r) : t.delete("tab");
|
|
25
|
+
}),
|
|
26
|
+
list: p,
|
|
27
|
+
setupsList: m,
|
|
28
|
+
dialogOpen: d.get("dialog") === "new",
|
|
29
|
+
dialogSetupId: d.get(i),
|
|
30
|
+
openNew: (e) => g((t) => {
|
|
31
|
+
t.set("dialog", "new"), e ? t.set(i, e) : t.delete(i);
|
|
32
|
+
}),
|
|
33
|
+
closeNew: () => g((e) => {
|
|
34
|
+
e.delete("dialog"), e.delete(i);
|
|
35
|
+
}),
|
|
36
|
+
finishNew: () => g((e) => {
|
|
37
|
+
e.delete("dialog"), e.delete(i), e.delete("tab");
|
|
38
|
+
}),
|
|
39
|
+
openDetails: (e) => o?.(t(n, e)),
|
|
40
|
+
openSetup: (e) => o?.(t(n, `templates/${e}`))
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export { d as useDownloadsPage };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=useDownloadsPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDownloadsPage.js","names":["LIST_FILTERS","STATUS_FILTER","CONTAINS_FILTER","useDownloadsPage","useExport","params","setParams","useSearchParams","list","useListState","SORT_VALUES","setupsList","tab","update","useCallback","next","current","change","search","SETUPS_TAB","SETUP_PARAM","setupId","navigate","joinPath","basePath","jobId"],"sources":["../../../src/export/workspace-v2/useDownloadsPage.ts"],"sourcesContent":["/**\n * The state of \"Download your data\" (BOFF-15822), all of it in the address so\n * a link, a reload or Back opens the same view: the tab (`?tab=setups`), New\n * download (`?dialog=new`, `&setup=<id>` to start from a saved setup), and the\n * Downloads list's search, filters, sort and page.\n */\nimport { useCallback } from \"react\";\nimport { useSearchParams } from \"react-router\";\nimport { useListState, type ListState } from \"@burdenoff/fe-libs/ui\";\nimport { useExport } from \"../providers/ExportProvider\";\nimport { joinPath } from \"../utils/paths\";\nimport {\n CONTAINS_FILTER,\n NEW_DIALOG,\n SETUPS_TAB,\n SETUP_PARAM,\n SORT_VALUES,\n STATUS_FILTER,\n} from \"./downloadsModel\";\n\nexport type DownloadsTab = \"downloads\" | \"setups\";\n\nconst LIST_FILTERS = [STATUS_FILTER, CONTAINS_FILTER];\n\nexport interface DownloadsPageState {\n tab: DownloadsTab;\n setTab: (tab: DownloadsTab) => void;\n /** The Downloads list's search, filters, sort and page. */\n list: ListState;\n /** The Saved setups list's page (its own `s_` parameters). */\n setupsList: ListState;\n dialogOpen: boolean;\n /** New download starts from this saved setup. */\n dialogSetupId: string | null;\n openNew: (setupId?: string) => void;\n closeNew: () => void;\n /** A download started: close New download and show the Downloads tab, in one change. */\n finishNew: () => void;\n /** A download's own page (its parts and progress). */\n openDetails: (jobId: string) => void;\n /** A saved setup's own page (to edit it). */\n openSetup: (setupId: string) => void;\n}\n\nexport function useDownloadsPage(): DownloadsPageState {\n const { basePath = \"/\", navigate } = useExport();\n const [params, setParams] = useSearchParams();\n // The pager moves a page past the end back to the last one (ListPager).\n const list = useListState({\n filters: LIST_FILTERS,\n sorts: SORT_VALUES,\n url: [params, setParams],\n });\n const setupsList = useListState({\n urlPrefix: \"s_\",\n url: [params, setParams],\n });\n const tab: DownloadsTab =\n params.get(\"tab\") === SETUPS_TAB ? \"setups\" : \"downloads\";\n\n const update = useCallback(\n (change: (next: URLSearchParams) => void) =>\n setParams(\n (current) => {\n const next = new URLSearchParams(current);\n change(next);\n return next;\n },\n { replace: true },\n ),\n [setParams],\n );\n\n return {\n tab,\n setTab: (next) =>\n update((search) => {\n if (next === \"setups\") search.set(\"tab\", SETUPS_TAB);\n else search.delete(\"tab\");\n }),\n list,\n setupsList,\n dialogOpen: params.get(\"dialog\") === NEW_DIALOG,\n dialogSetupId: params.get(SETUP_PARAM),\n openNew: (setupId) =>\n update((search) => {\n search.set(\"dialog\", NEW_DIALOG);\n if (setupId) search.set(SETUP_PARAM, setupId);\n else search.delete(SETUP_PARAM);\n }),\n closeNew: () =>\n update((search) => {\n search.delete(\"dialog\");\n search.delete(SETUP_PARAM);\n }),\n finishNew: () =>\n update((search) => {\n search.delete(\"dialog\");\n search.delete(SETUP_PARAM);\n search.delete(\"tab\");\n }),\n openDetails: (jobId) => navigate?.(joinPath(basePath, jobId)),\n openSetup: (setupId) =>\n navigate?.(joinPath(basePath, `templates/${setupId}`)),\n };\n}\n"],"mappings":";;;;;;;AAsBA,IAAMA,IAAe,CAACC,GAAeC,CAAe;AAsBpD,SAAgBC,IAAuC;CACrD,IAAM,EAAE,cAAW,KAAK,gBAAaC,EAAU,GACzC,CAACC,GAAQC,KAAaC,EAAgB,GAEtCC,IAAOC,EAAa;EACxB,SAAST;EACT,OAAOU;EACP,KAAK,CAACL,GAAQC,CAAS;CACzB,CAAC,GACKK,IAAaF,EAAa;EAC9B,WAAW;EACX,KAAK,CAACJ,GAAQC,CAAS;CACzB,CAAC,GACKM,IACJP,EAAO,IAAI,KAAK,MAAA,WAAmB,WAAW,aAE1CQ,IAASC,GACZ,MACCR,GACG,MAAY;EACX,IAAMS,IAAO,IAAI,gBAAgBC,CAAO;EAExC,OADAC,EAAOF,CAAI,GACJA;CACT,GACA,EAAE,SAAS,GAAK,CAClB,GACF,CAACT,CAAS,CACZ;CAEA,OAAO;EACL;EACA,SAAS,MACPO,GAAQ,MAAW;GACjB,AAAIE,MAAS,W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