lhcb-ntuple-wizard-test 2.0.0 → 2.0.2
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/App.d.ts +12 -0
- package/dist/App.js +22 -0
- package/dist/components/ConfigFilesUploadingAlert.d.ts +1 -0
- package/dist/components/ConfigFilesUploadingAlert.js +5 -0
- package/dist/components/DatasetEventTypeBadge.d.ts +5 -0
- package/dist/components/DatasetEventTypeBadge.js +23 -0
- package/dist/components/DatasetInfo.d.ts +5 -0
- package/dist/components/DatasetInfo.js +21 -0
- package/dist/components/DecayLatex.d.ts +7 -0
- package/dist/components/DecayLatex.js +103 -0
- package/dist/components/DecayList.d.ts +8 -0
- package/dist/components/DecayList.js +37 -0
- package/dist/components/DecayListItem.d.ts +11 -0
- package/dist/components/DecayListItem.js +23 -0
- package/dist/components/DecayTagBadge.d.ts +5 -0
- package/dist/components/DecayTagBadge.js +21 -0
- package/dist/components/DecayTreeCard.d.ts +7 -0
- package/dist/components/DecayTreeCard.js +43 -0
- package/dist/components/DecayTreeCardHeader.d.ts +7 -0
- package/dist/components/DecayTreeCardHeader.js +5 -0
- package/dist/components/DecayTreeGraph.d.ts +9 -0
- package/dist/components/DecayTreeGraph.js +89 -0
- package/dist/components/DeleteButton.d.ts +9 -0
- package/dist/components/DeleteButton.js +19 -0
- package/dist/components/DttNameInput.d.ts +9 -0
- package/dist/components/DttNameInput.js +73 -0
- package/dist/components/LineTableRow.d.ts +9 -0
- package/dist/components/LineTableRow.js +123 -0
- package/dist/components/LoadingIndicator.d.ts +6 -0
- package/dist/components/LoadingIndicator.js +5 -0
- package/dist/components/NtupleWizard.d.ts +26 -0
- package/dist/components/NtupleWizard.js +33 -0
- package/dist/components/NumStrippingLinesBadge.d.ts +8 -0
- package/dist/components/NumStrippingLinesBadge.js +10 -0
- package/dist/components/ParticleDropdown.d.ts +8 -0
- package/dist/components/ParticleDropdown.js +33 -0
- package/dist/components/ParticleTagBadge.d.ts +9 -0
- package/dist/components/ParticleTagBadge.js +22 -0
- package/dist/components/ParticleTagFilters.d.ts +6 -0
- package/dist/components/ParticleTagFilters.js +51 -0
- package/dist/components/PolarityBadge.d.ts +5 -0
- package/dist/components/PolarityBadge.js +15 -0
- package/dist/components/StrippingLineBadge.d.ts +7 -0
- package/dist/components/StrippingLineBadge.js +29 -0
- package/dist/components/StrippingLineInfo.d.ts +8 -0
- package/dist/components/StrippingLineInfo.js +17 -0
- package/dist/components/SubmitRequestButton.d.ts +10 -0
- package/dist/components/SubmitRequestButton.js +31 -0
- package/dist/components/TagDropdown.d.ts +12 -0
- package/dist/components/TagDropdown.js +31 -0
- package/dist/components/TupleToolDocsAccordion.d.ts +5 -0
- package/dist/components/TupleToolDocsAccordion.js +14 -0
- package/dist/components/TupleToolDropdown.d.ts +21 -0
- package/dist/components/TupleToolDropdown.js +29 -0
- package/dist/components/TupleToolGroup.d.ts +6 -0
- package/dist/components/TupleToolGroup.js +22 -0
- package/dist/components/TupleToolLabel.d.ts +6 -0
- package/dist/components/TupleToolLabel.js +20 -0
- package/dist/components/TupleToolList.d.ts +7 -0
- package/dist/components/TupleToolList.js +38 -0
- package/dist/components/YearBadge.d.ts +5 -0
- package/dist/components/YearBadge.js +15 -0
- package/dist/components/modals/AddTupleToolModal.d.ts +7 -0
- package/dist/components/modals/AddTupleToolModal.js +32 -0
- package/dist/components/modals/ConfigureTupleToolModal.d.ts +8 -0
- package/dist/components/modals/ConfigureTupleToolModal.js +43 -0
- package/dist/components/modals/ReasonForRequestModal.d.ts +8 -0
- package/dist/components/modals/ReasonForRequestModal.js +49 -0
- package/dist/components/modals/UploadDttConfigModal.d.ts +7 -0
- package/dist/components/modals/UploadDttConfigModal.js +35 -0
- package/dist/components/modals/UploadProdConfigModal.d.ts +5 -0
- package/dist/components/modals/UploadProdConfigModal.js +27 -0
- package/dist/components/tupleToolParams/BoolParamInput.d.ts +16 -0
- package/dist/components/tupleToolParams/BoolParamInput.js +15 -0
- package/dist/components/tupleToolParams/DictParamInput.d.ts +14 -0
- package/dist/components/tupleToolParams/DictParamInput.js +31 -0
- package/dist/components/tupleToolParams/ListParamInput.d.ts +14 -0
- package/dist/components/tupleToolParams/ListParamInput.js +46 -0
- package/dist/components/tupleToolParams/NumParamInput.d.ts +18 -0
- package/dist/components/tupleToolParams/NumParamInput.js +25 -0
- package/dist/components/tupleToolParams/StrParamInput.d.ts +19 -0
- package/dist/components/tupleToolParams/StrParamInput.js +22 -0
- package/dist/config.d.ts +78 -0
- package/dist/config.js +72 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +11 -0
- package/dist/models/bkPath.d.ts +11 -0
- package/dist/models/bkPath.js +40 -0
- package/dist/models/blobFile.d.ts +12 -0
- package/dist/models/blobFile.js +1 -0
- package/dist/models/decayData.d.ts +15 -0
- package/dist/models/decayData.js +1 -0
- package/dist/models/dropdownOption.d.ts +5 -0
- package/dist/models/dropdownOption.js +1 -0
- package/dist/models/dtt.d.ts +108 -0
- package/dist/models/dtt.js +149 -0
- package/dist/models/jobConfig.d.ts +7 -0
- package/dist/models/jobConfig.js +1 -0
- package/dist/models/particle.d.ts +12 -0
- package/dist/models/particle.js +1 -0
- package/dist/models/particleTag.d.ts +4 -0
- package/dist/models/particleTag.js +1 -0
- package/dist/models/rowData.d.ts +15 -0
- package/dist/models/rowData.js +1 -0
- package/dist/models/strippingLine.d.ts +5 -0
- package/dist/models/strippingLine.js +1 -0
- package/dist/models/strippingLineOption.d.ts +6 -0
- package/dist/models/strippingLineOption.js +1 -0
- package/dist/models/tupleTool.d.ts +8 -0
- package/dist/models/tupleTool.js +18 -0
- package/dist/models/tupleTreeGraphData.d.ts +20 -0
- package/dist/models/tupleTreeGraphData.js +1 -0
- package/dist/models/yamlFile.d.ts +11 -0
- package/dist/models/yamlFile.js +78 -0
- package/dist/pages/DecaySearchPage.d.ts +5 -0
- package/dist/pages/DecaySearchPage.js +197 -0
- package/dist/pages/DecayTreeConfigPage.d.ts +5 -0
- package/dist/pages/DecayTreeConfigPage.js +63 -0
- package/dist/pages/LinesTablePage.d.ts +14 -0
- package/dist/pages/LinesTablePage.js +125 -0
- package/dist/providers/DttProvider.d.ts +24 -0
- package/dist/providers/DttProvider.js +77 -0
- package/dist/providers/MetadataProvider.d.ts +87 -0
- package/dist/providers/MetadataProvider.js +50 -0
- package/dist/providers/ProductionConfigProvider.d.ts +14 -0
- package/dist/providers/ProductionConfigProvider.js +76 -0
- package/dist/providers/RequestProvider.d.ts +15 -0
- package/dist/providers/RequestProvider.js +35 -0
- package/dist/providers/RowsProvider.d.ts +14 -0
- package/dist/providers/RowsProvider.js +31 -0
- package/dist/utils/mathjaxUtils.d.ts +12 -0
- package/dist/utils/mathjaxUtils.js +24 -0
- package/dist/utils/utils.d.ts +31 -0
- package/dist/utils/utils.js +80 -0
- package/package.json +3 -2
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*****************************************************************************\
|
|
2
|
+
* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration *
|
|
3
|
+
* *
|
|
4
|
+
* This software is distributed under the terms of the GNU General Public *
|
|
5
|
+
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
|
|
6
|
+
* *
|
|
7
|
+
* In applying this licence, CERN does not waive the privileges and immunities *
|
|
8
|
+
* granted to it by virtue of its status as an Intergovernmental Organization *
|
|
9
|
+
* or submit itself to any jurisdiction. *
|
|
10
|
+
\*****************************************************************************/
|
|
11
|
+
import { ReactNode } from "react";
|
|
12
|
+
import { Particle } from "../models/particle.js";
|
|
13
|
+
import { DecayData } from "../models/decayData";
|
|
14
|
+
import { ToolMetadata } from "../models/dtt.js";
|
|
15
|
+
export type TagHint = DecayTagHint | ParticleTagHint;
|
|
16
|
+
export interface DecayTagHint {
|
|
17
|
+
description: string;
|
|
18
|
+
hide: boolean;
|
|
19
|
+
warn: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface ParticleTagHint {
|
|
22
|
+
description: string;
|
|
23
|
+
group: string;
|
|
24
|
+
hide: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface ApplicationInfo {
|
|
27
|
+
Analysis: string;
|
|
28
|
+
DaVinci: string;
|
|
29
|
+
Phys: string;
|
|
30
|
+
}
|
|
31
|
+
interface StrippingInfo {
|
|
32
|
+
full_decays: string[];
|
|
33
|
+
output: string;
|
|
34
|
+
prescale: number;
|
|
35
|
+
stream: string[];
|
|
36
|
+
url: {
|
|
37
|
+
[key: string]: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface MetadataContext {
|
|
41
|
+
dataset: string[];
|
|
42
|
+
decays: {
|
|
43
|
+
[key: string]: DecayData;
|
|
44
|
+
};
|
|
45
|
+
embedding: {
|
|
46
|
+
[key: string]: string;
|
|
47
|
+
};
|
|
48
|
+
kgdoc: {
|
|
49
|
+
[key: string]: object;
|
|
50
|
+
};
|
|
51
|
+
lokiVariables: {
|
|
52
|
+
applicationInfo: ApplicationInfo;
|
|
53
|
+
lokiVariables: object;
|
|
54
|
+
};
|
|
55
|
+
particleProperties: {
|
|
56
|
+
[key: string]: Particle;
|
|
57
|
+
};
|
|
58
|
+
stripping: {
|
|
59
|
+
[key: string]: {
|
|
60
|
+
[key: string]: StrippingInfo;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
strippingHints: {
|
|
64
|
+
[key: string]: {
|
|
65
|
+
davinci: string;
|
|
66
|
+
description: string;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
tupleTools: {
|
|
70
|
+
applicationInfo: ApplicationInfo;
|
|
71
|
+
tupleTools: ToolMetadata;
|
|
72
|
+
};
|
|
73
|
+
userHints: {
|
|
74
|
+
decayTags: {
|
|
75
|
+
[key: string]: DecayTagHint;
|
|
76
|
+
};
|
|
77
|
+
particleTags: {
|
|
78
|
+
[key: string]: ParticleTagHint;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
interface Props {
|
|
83
|
+
children: ReactNode;
|
|
84
|
+
}
|
|
85
|
+
export declare function MetadataProvider({ children }: Props): import("react/jsx-runtime").JSX.Element;
|
|
86
|
+
export declare const useMetadata: () => MetadataContext | null;
|
|
87
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/*****************************************************************************\
|
|
3
|
+
* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration *
|
|
4
|
+
* *
|
|
5
|
+
* This software is distributed under the terms of the GNU General Public *
|
|
6
|
+
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
|
|
7
|
+
* *
|
|
8
|
+
* In applying this licence, CERN does not waive the privileges and immunities *
|
|
9
|
+
* granted to it by virtue of its status as an Intergovernmental Organization *
|
|
10
|
+
* or submit itself to any jurisdiction. *
|
|
11
|
+
\*****************************************************************************/
|
|
12
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
13
|
+
import { config } from "../config.js";
|
|
14
|
+
import pako from "pako";
|
|
15
|
+
const MetadataContextType = createContext(null);
|
|
16
|
+
export function MetadataProvider({ children }) {
|
|
17
|
+
const [error, setError] = useState(null);
|
|
18
|
+
const [metadata, setMetadata] = useState(null);
|
|
19
|
+
async function loadDict(path) {
|
|
20
|
+
const response = await fetch(`${config.metadata_baseurl}${path}.json.gz`);
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
console.error(response);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const data = await response.arrayBuffer();
|
|
26
|
+
const unzipped = pako.inflate(new Uint8Array(data));
|
|
27
|
+
const decoded = new TextDecoder("utf-8").decode(unzipped);
|
|
28
|
+
return JSON.parse(decoded);
|
|
29
|
+
}
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const metadataContextKeys = Object.keys(config.metadata_files);
|
|
32
|
+
// Load all metadata files
|
|
33
|
+
const promises = metadataContextKeys.map(async (key) => [key, await loadDict(config.metadata_files[key])]);
|
|
34
|
+
// Build the context object
|
|
35
|
+
Promise.all(promises)
|
|
36
|
+
.then((entries) => {
|
|
37
|
+
setMetadata(Object.fromEntries(entries));
|
|
38
|
+
})
|
|
39
|
+
.catch(setError);
|
|
40
|
+
}, []);
|
|
41
|
+
if (error) {
|
|
42
|
+
return _jsxs("h1", { children: ["Oops: ", `${error}`] });
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return _jsx(MetadataContextType.Provider, { value: metadata, children: children });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export const useMetadata = () => {
|
|
49
|
+
return useContext(MetadataContextType);
|
|
50
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { BlobFile } from "../models/blobFile";
|
|
3
|
+
import { RowData } from "../models/rowData";
|
|
4
|
+
import { MetadataContext } from "./MetadataProvider";
|
|
5
|
+
export interface ProductionConfigApi {
|
|
6
|
+
parseProductionFiles(this: void, files: (BlobFile | File)[], metadata: MetadataContext): Promise<{
|
|
7
|
+
rows: RowData[];
|
|
8
|
+
emails: string[];
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
11
|
+
export declare function ProductionConfigProvider({ children }: {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare function useProductionConfig(): ProductionConfigApi;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useMemo } from "react";
|
|
3
|
+
import yaml from "js-yaml";
|
|
4
|
+
import Dtt from "../models/dtt";
|
|
5
|
+
const ProductionConfigContext = createContext(null);
|
|
6
|
+
export function ProductionConfigProvider({ children }) {
|
|
7
|
+
const parseInput = useCallback((decay) => (input) => {
|
|
8
|
+
const [, , stream, , lineName] = input.split("/");
|
|
9
|
+
const line = `Stripping${lineName}`;
|
|
10
|
+
return {
|
|
11
|
+
stream,
|
|
12
|
+
line,
|
|
13
|
+
versions: decay.lines[`${stream}/${line}`],
|
|
14
|
+
};
|
|
15
|
+
}, []);
|
|
16
|
+
const applyInfoYaml = useCallback((config, rows, emails) => {
|
|
17
|
+
const defaults = config.defaults;
|
|
18
|
+
if (defaults?.inform?.[0]) {
|
|
19
|
+
emails.push(defaults.inform[0]);
|
|
20
|
+
}
|
|
21
|
+
rows.forEach((row) => {
|
|
22
|
+
if (!row.dtt?.config.name)
|
|
23
|
+
return;
|
|
24
|
+
const dttName = row.dtt.config.name.split("/")[1];
|
|
25
|
+
Object.entries(config).forEach(([key, jobConfig]) => {
|
|
26
|
+
if (key === "defaults")
|
|
27
|
+
return;
|
|
28
|
+
const job = jobConfig;
|
|
29
|
+
if (!job.options)
|
|
30
|
+
return;
|
|
31
|
+
if (job.options.some((opt) => opt.split(".")[0] === dttName)) {
|
|
32
|
+
row.paths.push(job.input.bk_query);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}, []);
|
|
37
|
+
const parseProductionFiles = useCallback(async (files, metadata) => {
|
|
38
|
+
const rows = [];
|
|
39
|
+
const emails = [];
|
|
40
|
+
const sorted = [...files].sort((a, b) => (a.name === "info.yaml" ? 1 : b.name === "info.yaml" ? -1 : 0));
|
|
41
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
42
|
+
const file = sorted[i];
|
|
43
|
+
const blob = file.blob ?? file;
|
|
44
|
+
const text = await blob.text();
|
|
45
|
+
if (file.name === "info.yaml") {
|
|
46
|
+
const config = yaml.load(text);
|
|
47
|
+
applyInfoYaml(config, rows, emails);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const config = yaml.load(text);
|
|
51
|
+
const decay = Object.values(metadata.decays).find((d) => d.descriptors.template === config.descriptorTemplate);
|
|
52
|
+
if (!decay || !config.inputs)
|
|
53
|
+
continue;
|
|
54
|
+
rows.push({
|
|
55
|
+
id: i,
|
|
56
|
+
decay,
|
|
57
|
+
lines: config.inputs.map(parseInput(decay)),
|
|
58
|
+
paths: [],
|
|
59
|
+
pathOptions: [],
|
|
60
|
+
dtt: new Dtt(config, {}),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return { rows, emails };
|
|
64
|
+
}, [applyInfoYaml, parseInput]);
|
|
65
|
+
const api = useMemo(() => ({
|
|
66
|
+
parseProductionFiles,
|
|
67
|
+
}), [parseProductionFiles]);
|
|
68
|
+
return _jsx(ProductionConfigContext.Provider, { value: api, children: children });
|
|
69
|
+
}
|
|
70
|
+
export function useProductionConfig() {
|
|
71
|
+
const ctx = useContext(ProductionConfigContext);
|
|
72
|
+
if (!ctx) {
|
|
73
|
+
throw new Error("useProductionConfig must be used within ProductionConfigProvider");
|
|
74
|
+
}
|
|
75
|
+
return ctx;
|
|
76
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
interface RequestContextType {
|
|
3
|
+
productionName: string;
|
|
4
|
+
setProductionName: (name: string) => void;
|
|
5
|
+
contactEmails: string[];
|
|
6
|
+
setContactEmails: (emails: string[]) => void;
|
|
7
|
+
reasonForRequest: string;
|
|
8
|
+
setReasonForRequest: (reason: string) => void;
|
|
9
|
+
}
|
|
10
|
+
interface RequestProviderProps {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export declare const RequestProvider: ({ children }: RequestProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare const useRequest: () => RequestContextType;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useState } from "react";
|
|
3
|
+
const RequestContext = createContext(null);
|
|
4
|
+
export const RequestProvider = ({ children }) => {
|
|
5
|
+
const [productionName, setProductionName] = useState(localStorage.getItem("name") || "");
|
|
6
|
+
const [contactEmails, setContactEmails] = useState((localStorage.getItem("email") || "").split(/,/).filter((s) => s));
|
|
7
|
+
const [reasonForRequest, setReasonForRequest] = useState(localStorage.getItem("reasonForRequest") || "");
|
|
8
|
+
const updateProductionName = (newProductionName) => {
|
|
9
|
+
setProductionName(newProductionName);
|
|
10
|
+
localStorage.setItem("name", newProductionName);
|
|
11
|
+
};
|
|
12
|
+
const updateContactEmails = (newContactEmails) => {
|
|
13
|
+
setContactEmails(newContactEmails);
|
|
14
|
+
localStorage.setItem("email", newContactEmails.join(","));
|
|
15
|
+
};
|
|
16
|
+
const updateReasonForRequest = (newReasonForRequest) => {
|
|
17
|
+
setReasonForRequest(newReasonForRequest);
|
|
18
|
+
localStorage.setItem("reasonForRequest", newReasonForRequest);
|
|
19
|
+
};
|
|
20
|
+
return (_jsx(RequestContext.Provider, { value: {
|
|
21
|
+
productionName,
|
|
22
|
+
setProductionName: updateProductionName,
|
|
23
|
+
contactEmails,
|
|
24
|
+
setContactEmails: updateContactEmails,
|
|
25
|
+
reasonForRequest,
|
|
26
|
+
setReasonForRequest: updateReasonForRequest,
|
|
27
|
+
}, children: children }));
|
|
28
|
+
};
|
|
29
|
+
export const useRequest = () => {
|
|
30
|
+
const ctx = useContext(RequestContext);
|
|
31
|
+
if (!ctx) {
|
|
32
|
+
throw new Error("useRequest must be used within a RequestProvider");
|
|
33
|
+
}
|
|
34
|
+
return ctx;
|
|
35
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Dispatch, ReactNode, SetStateAction } from "react";
|
|
2
|
+
import { RowData } from "../models/rowData.js";
|
|
3
|
+
import { YamlFile } from "../models/yamlFile";
|
|
4
|
+
interface RowsContextType {
|
|
5
|
+
rows: RowData[];
|
|
6
|
+
setRows: Dispatch<SetStateAction<RowData[]>>;
|
|
7
|
+
generateAllFiles: () => YamlFile[];
|
|
8
|
+
}
|
|
9
|
+
interface Props {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export declare const RowsProvider: ({ children }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare const useRows: () => RowsContextType;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
3
|
+
import Dtt from "../models/dtt";
|
|
4
|
+
import { useMetadata } from "./MetadataProvider";
|
|
5
|
+
import { YamlFile } from "../models/yamlFile";
|
|
6
|
+
const RowsContext = createContext(undefined);
|
|
7
|
+
export const RowsProvider = ({ children }) => {
|
|
8
|
+
const metadata = useMetadata();
|
|
9
|
+
const storedRows = JSON.parse(localStorage.getItem("rows") || "[]");
|
|
10
|
+
const [rows, setRows] = useState(storedRows.map((row) => ({ ...row, dtt: row.dtt?.config ? new Dtt(row.dtt.config, {}) : null })));
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
localStorage.setItem("rows", JSON.stringify(rows));
|
|
13
|
+
}, [rows]);
|
|
14
|
+
const generateAllFiles = () => {
|
|
15
|
+
if (!metadata) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
return [
|
|
19
|
+
...rows.filter((row) => row.dtt).map((row) => YamlFile.fromDtt(row.dtt)),
|
|
20
|
+
YamlFile.createInfoYaml(rows, metadata),
|
|
21
|
+
];
|
|
22
|
+
};
|
|
23
|
+
return _jsx(RowsContext.Provider, { value: { rows, setRows, generateAllFiles }, children: children });
|
|
24
|
+
};
|
|
25
|
+
export const useRows = () => {
|
|
26
|
+
const context = useContext(RowsContext);
|
|
27
|
+
if (!context) {
|
|
28
|
+
throw new Error("useRows must be used within a RowsProvider");
|
|
29
|
+
}
|
|
30
|
+
return context;
|
|
31
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*****************************************************************************\
|
|
2
|
+
* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration *
|
|
3
|
+
* *
|
|
4
|
+
* This software is distributed under the terms of the GNU General Public *
|
|
5
|
+
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
|
|
6
|
+
* *
|
|
7
|
+
* In applying this licence, CERN does not waive the privileges and immunities *
|
|
8
|
+
* granted to it by virtue of its status as an Intergovernmental Organization *
|
|
9
|
+
* or submit itself to any jurisdiction. *
|
|
10
|
+
\*****************************************************************************/
|
|
11
|
+
import "@mathjax/src/cjs/input/tex/ams/AmsConfiguration.js";
|
|
12
|
+
export declare function tex2svg(inputTeX: string): SVGElement;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*****************************************************************************\
|
|
2
|
+
* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration *
|
|
3
|
+
* *
|
|
4
|
+
* This software is distributed under the terms of the GNU General Public *
|
|
5
|
+
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
|
|
6
|
+
* *
|
|
7
|
+
* In applying this licence, CERN does not waive the privileges and immunities *
|
|
8
|
+
* granted to it by virtue of its status as an Intergovernmental Organization *
|
|
9
|
+
* or submit itself to any jurisdiction. *
|
|
10
|
+
\*****************************************************************************/
|
|
11
|
+
import { mathjax } from "@mathjax/src/cjs/mathjax.js";
|
|
12
|
+
import { TeX } from "@mathjax/src/cjs/input/tex.js";
|
|
13
|
+
import { SVG } from "@mathjax/src/cjs/output/svg.js";
|
|
14
|
+
import { browserAdaptor } from "@mathjax/src/cjs/adaptors/browserAdaptor.js";
|
|
15
|
+
import { RegisterHTMLHandler } from "@mathjax/src/cjs/handlers/html.js";
|
|
16
|
+
import "@mathjax/src/cjs/input/tex/ams/AmsConfiguration.js";
|
|
17
|
+
RegisterHTMLHandler(browserAdaptor());
|
|
18
|
+
const mathDoc = mathjax.document("", {
|
|
19
|
+
InputJax: new TeX({ packages: ["base", "ams"] }),
|
|
20
|
+
OutputJax: new SVG({ fontCache: "none" }),
|
|
21
|
+
});
|
|
22
|
+
export function tex2svg(inputTeX) {
|
|
23
|
+
return mathDoc.convert(inputTeX);
|
|
24
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { YamlFile } from "../models/yamlFile";
|
|
2
|
+
/**
|
|
3
|
+
* Sanitizes a user-provided filename to prevent path traversal (Zip Slip)
|
|
4
|
+
* and unsafe filesystem characters.
|
|
5
|
+
*
|
|
6
|
+
* Guarantees the result is a single filename, not a path.
|
|
7
|
+
*
|
|
8
|
+
* - Strips directory separators (/ and \)
|
|
9
|
+
* - Removes path traversal sequences (..)
|
|
10
|
+
* - Removes leading dots
|
|
11
|
+
* - Allowlists safe characters
|
|
12
|
+
*
|
|
13
|
+
* @param input - Potentially unsafe filename
|
|
14
|
+
* @param fallback - Filename to use if sanitization results in an empty string
|
|
15
|
+
* @returns A safe filename
|
|
16
|
+
*/
|
|
17
|
+
export declare function sanitizeFilename(input: string, fallback?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Downloads a text string with the given filename.
|
|
20
|
+
*
|
|
21
|
+
* @param yamlFile - The YamlFile object to download
|
|
22
|
+
* @param type - The MIME type of the file (default: text/plain)
|
|
23
|
+
*/
|
|
24
|
+
export declare function downloadText(yamlFile: YamlFile, type?: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Downloads a ZIP archive containing multiple text files.
|
|
27
|
+
*
|
|
28
|
+
* @param files - An array of [filename, content] pairs
|
|
29
|
+
* @param name - The desired archive filename
|
|
30
|
+
*/
|
|
31
|
+
export declare function downloadZip(files: YamlFile[], name?: string): Promise<void>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*****************************************************************************\
|
|
2
|
+
* (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration *
|
|
3
|
+
* *
|
|
4
|
+
* This software is distributed under the terms of the GNU General Public *
|
|
5
|
+
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
|
|
6
|
+
* *
|
|
7
|
+
* In applying this licence, CERN does not waive the privileges and immunities *
|
|
8
|
+
* granted to it by virtue of its status as an Intergovernmental Organization *
|
|
9
|
+
* or submit itself to any jurisdiction. *
|
|
10
|
+
\*****************************************************************************/
|
|
11
|
+
import JsZip from "jszip";
|
|
12
|
+
/**
|
|
13
|
+
* Sanitizes a user-provided filename to prevent path traversal (Zip Slip)
|
|
14
|
+
* and unsafe filesystem characters.
|
|
15
|
+
*
|
|
16
|
+
* Guarantees the result is a single filename, not a path.
|
|
17
|
+
*
|
|
18
|
+
* - Strips directory separators (/ and \)
|
|
19
|
+
* - Removes path traversal sequences (..)
|
|
20
|
+
* - Removes leading dots
|
|
21
|
+
* - Allowlists safe characters
|
|
22
|
+
*
|
|
23
|
+
* @param input - Potentially unsafe filename
|
|
24
|
+
* @param fallback - Filename to use if sanitization results in an empty string
|
|
25
|
+
* @returns A safe filename
|
|
26
|
+
*/
|
|
27
|
+
export function sanitizeFilename(input, fallback = "file") {
|
|
28
|
+
// Get the last path segment
|
|
29
|
+
const basename = input.split(/[/\\]/).pop() ?? "";
|
|
30
|
+
const noTraversal = basename.replace(/\.\./g, "");
|
|
31
|
+
const noLeadingDots = noTraversal.replace(/^\.+/, "");
|
|
32
|
+
const sanitized = noLeadingDots.replace(/[^a-zA-Z0-9._-]/g, "");
|
|
33
|
+
return sanitized.length > 0 ? sanitized : fallback;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Downloads a Blob object with the given filename.
|
|
37
|
+
*
|
|
38
|
+
* @param blob - The Blob object to download
|
|
39
|
+
* @param name - The desired filename
|
|
40
|
+
*/
|
|
41
|
+
function downloadBlob(blob, name) {
|
|
42
|
+
const safeName = sanitizeFilename(name);
|
|
43
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
44
|
+
const link = document.createElement("a");
|
|
45
|
+
link.href = blobUrl;
|
|
46
|
+
link.download = safeName;
|
|
47
|
+
document.body.appendChild(link);
|
|
48
|
+
link.dispatchEvent(new MouseEvent("click", {
|
|
49
|
+
bubbles: true,
|
|
50
|
+
cancelable: true,
|
|
51
|
+
view: window,
|
|
52
|
+
}));
|
|
53
|
+
document.body.removeChild(link);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Downloads a text string with the given filename.
|
|
57
|
+
*
|
|
58
|
+
* @param yamlFile - The YamlFile object to download
|
|
59
|
+
* @param type - The MIME type of the file (default: text/plain)
|
|
60
|
+
*/
|
|
61
|
+
export function downloadText(yamlFile, type = "text/plain") {
|
|
62
|
+
const blob = new Blob([yamlFile.content], { type: type });
|
|
63
|
+
downloadBlob(blob, yamlFile.name);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Downloads a ZIP archive containing multiple text files.
|
|
67
|
+
*
|
|
68
|
+
* @param files - An array of [filename, content] pairs
|
|
69
|
+
* @param name - The desired archive filename
|
|
70
|
+
*/
|
|
71
|
+
export async function downloadZip(files, name = "archive.zip") {
|
|
72
|
+
const zip = JsZip();
|
|
73
|
+
const safeZipName = sanitizeFilename(name, "archive.zip");
|
|
74
|
+
for (const file of files) {
|
|
75
|
+
const blob = new Blob([file.content], { type: "text/plain" });
|
|
76
|
+
zip.file(file.name, blob);
|
|
77
|
+
}
|
|
78
|
+
const blob = await zip.generateAsync({ type: "blob" });
|
|
79
|
+
downloadBlob(blob, safeZipName);
|
|
80
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lhcb-ntuple-wizard-test",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "An application to access large-scale open data from LHCb",
|
|
5
5
|
"url": "https://gitlab.cern.ch/lhcb-dpa/wp6-analysis-preservation-and-open-data/lhcb-ntuple-wizard-frontend/issues",
|
|
6
6
|
"private": false,
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"start": "vite --open",
|
|
46
|
-
"build": "tsc"
|
|
46
|
+
"build": "tsc",
|
|
47
|
+
"prepublishOnly": "npm run build"
|
|
47
48
|
},
|
|
48
49
|
"browserslist": {
|
|
49
50
|
"production": [
|