lhcb-ntuple-wizard-test 0.0.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.
Files changed (41) hide show
  1. package/COPYING +674 -0
  2. package/README.md +79 -0
  3. package/dist/components/App.js +99 -0
  4. package/dist/components/ConfigDict.js +103 -0
  5. package/dist/components/ConfigList.js +94 -0
  6. package/dist/components/ConfigNode.js +323 -0
  7. package/dist/components/ConfigValue.js +85 -0
  8. package/dist/components/Dataset.js +67 -0
  9. package/dist/components/Decay.js +51 -0
  10. package/dist/components/DecayItem.js +101 -0
  11. package/dist/components/DecayTag.js +50 -0
  12. package/dist/components/DecayTree.js +452 -0
  13. package/dist/components/DecaysList.js +108 -0
  14. package/dist/components/DeleteButton.js +56 -0
  15. package/dist/components/DescriptorsSearch.js +351 -0
  16. package/dist/components/EventTypeBadge.js +42 -0
  17. package/dist/components/ItemSearch.js +119 -0
  18. package/dist/components/LinesTable.js +1111 -0
  19. package/dist/components/NtupleWizard.js +141 -0
  20. package/dist/components/ParticleTag.js +52 -0
  21. package/dist/components/PolarityBadge.js +35 -0
  22. package/dist/components/SearchItem.js +100 -0
  23. package/dist/components/SelectParticle.js +61 -0
  24. package/dist/components/SelectTag.js +66 -0
  25. package/dist/components/SelectTool.js +59 -0
  26. package/dist/components/SelectVariables.js +105 -0
  27. package/dist/components/StrippingBadge.js +62 -0
  28. package/dist/components/StrippingLine.js +48 -0
  29. package/dist/components/TupleTool.js +46 -0
  30. package/dist/components/VariablesSearch.js +127 -0
  31. package/dist/components/YearBadge.js +35 -0
  32. package/dist/config.json +70 -0
  33. package/dist/contexts/MetadataContext.js +134 -0
  34. package/dist/index.js +18 -0
  35. package/dist/lib/BKPath.js +58 -0
  36. package/dist/lib/DTTConfig.js +174 -0
  37. package/dist/lib/analysisHelpers.js +30 -0
  38. package/dist/lib/mathjax.js +35 -0
  39. package/dist/lib/utils.js +191 -0
  40. package/dist/style/DecaysList.css +15 -0
  41. package/package.json +66 -0
@@ -0,0 +1,351 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _lodash = _interopRequireDefault(require("lodash.memoize"));
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _react = _interopRequireDefault(require("react"));
10
+ var _reactBootstrap = require("react-bootstrap");
11
+ var _reactRouterDom = require("react-router-dom");
12
+ var _reactSelect = _interopRequireDefault(require("react-select"));
13
+ var _MetadataContext = _interopRequireDefault(require("../contexts/MetadataContext"));
14
+ var _DecaysList = _interopRequireDefault(require("./DecaysList"));
15
+ var _SelectParticle = _interopRequireDefault(require("./SelectParticle"));
16
+ var _SelectTag = _interopRequireDefault(require("./SelectTag"));
17
+ var _jsxRuntime = require("react/jsx-runtime");
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
20
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
21
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*****************************************************************************\
22
+ * (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration *
23
+ * *
24
+ * This software is distributed under the terms of the GNU General Public *
25
+ * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
26
+ * *
27
+ * In applying this licence, CERN does not waive the privileges and immunities *
28
+ * granted to it by virtue of its status as an Intergovernmental Organization *
29
+ * or submit itself to any jurisdiction. *
30
+ \*****************************************************************************/
31
+ class DescriptorsSearch extends _react.default.Component {
32
+ constructor() {
33
+ super(...arguments);
34
+ _defineProperty(this, "state", {
35
+ selectedContains: [],
36
+ selectedHead: null,
37
+ selectedHeadTags: [],
38
+ selectedDecays: this.props.rows.map(row => row.decay),
39
+ selectedTags: null,
40
+ selectedLine: null,
41
+ chargeConjugateContains: true,
42
+ chargeConjugateHeads: true,
43
+ containsMatchType: "all",
44
+ headMatchType: "exactly",
45
+ tagMatchType: "none",
46
+ headTagMatchType: "all",
47
+ onlySelected: false
48
+ });
49
+ _defineProperty(this, "updateState", key => contents => {
50
+ this.setState({
51
+ [key]: contents
52
+ });
53
+ });
54
+ _defineProperty(this, "toggleState", key => () => {
55
+ this.setState({
56
+ [key]: !this.state[key]
57
+ });
58
+ });
59
+ _defineProperty(this, "callbackFunction", childData => {
60
+ this.setState({
61
+ selectedDecays: childData
62
+ });
63
+ });
64
+ _defineProperty(this, "createRow", (decay, id) => {
65
+ return Object({
66
+ id: id,
67
+ decay: decay,
68
+ lines: [],
69
+ paths: [],
70
+ // Currently-selected paths
71
+ pathOptions: [],
72
+ // Keep a history of valid paths
73
+ dtt: false
74
+ });
75
+ });
76
+ _defineProperty(this, "sendData", () => {
77
+ const selectedDecays = this.state.selectedDecays;
78
+ const selectedDecayDescriptors = selectedDecays.map(decay => decay.descriptors.plain);
79
+ // Loop through rows and remove any not-selected decays
80
+ let rows = [...this.props.rows].filter(row => selectedDecayDescriptors.includes(row.decay.descriptors.plain));
81
+ const existingDecayDescriptors = rows.map(row => row.decay.descriptors.plain);
82
+ // Loop through selected decays and add any new rows
83
+ const newDecays = selectedDecays.filter(decay => !existingDecayDescriptors.includes(decay.descriptors.plain));
84
+ newDecays.forEach(decay => {
85
+ const rowIDs = rows.map(row => row.id);
86
+ let newRowID = 0;
87
+ while (rowIDs.includes(newRowID)) {
88
+ newRowID += 1;
89
+ }
90
+ rows.push(this.createRow(decay, newRowID));
91
+ });
92
+ this.props.parentCallback(rows.map(row => ({
93
+ ...row,
94
+ dtt: {
95
+ config: row.dtt
96
+ }
97
+ }))); // callback expects row.dtt to be a DTTConfig
98
+ });
99
+ _defineProperty(this, "allStrippingLines", (0, _lodash.default)(() => {
100
+ const allLines = [].concat(...Object.values(this.context.metadata.stripping).map(stream => Object.keys(stream)));
101
+ const uniqueLines = new Set(allLines);
102
+ return [...uniqueLines];
103
+ }));
104
+ _defineProperty(this, "filterDecays", selectedTags => {
105
+ // XXX: selectedTags is passed as an arg because it's the only one with a non-empty default value.
106
+ // the value depends on async-loaded metadata, and I don't know how to put it in the state.
107
+ // TODO: can probably do some refactoring in here (cf variableMatch)
108
+ let newDecays = Object.values(this.context.metadata.decays);
109
+ if (this.state.selectedContains) {
110
+ newDecays = newDecays.filter(decay => {
111
+ const conditions = this.state.selectedContains.map(element => {
112
+ const particle = element.value;
113
+ const antiparticle = this.context.metadata.particleProperties[particle]["antiparticle"];
114
+ return decay.descriptors.plain.includes(particle) || this.state.chargeConjugateContains && decay.descriptors.plain.includes(antiparticle);
115
+ });
116
+ return DescriptorsSearch.variableMatch(this.state.containsMatchType, conditions);
117
+ });
118
+ }
119
+ if (this.state.headMatchType === "exactly") {
120
+ if (this.state.selectedHead) {
121
+ const particle = this.state.selectedHead.value;
122
+ const antiparticle = this.context.metadata.particleProperties[particle]["antiparticle"];
123
+ newDecays = newDecays.filter(decay => {
124
+ const head = decay.descriptors.list[0];
125
+ return head === particle || this.state.chargeConjugateHeads && head === antiparticle;
126
+ });
127
+ }
128
+ } else if (this.state.headMatchType === "category") {
129
+ if (this.state.selectedHeadTags) {
130
+ newDecays = newDecays.filter(decay => {
131
+ const conditions = this.state.selectedHeadTags.map(element => {
132
+ const tag = element.value;
133
+ const head = this.context.metadata.particleProperties[decay.descriptors.list[0]];
134
+ return head.tags.includes(tag);
135
+ });
136
+ return DescriptorsSearch.variableMatch(this.state.headTagMatchType, conditions);
137
+ });
138
+ }
139
+ }
140
+ if (this.state.onlySelected) {
141
+ newDecays = newDecays.filter(decay => this.state.selectedDecays.map(selectedDecay => selectedDecay.descriptors.plain).includes(decay.descriptors.plain));
142
+ }
143
+ if (selectedTags) {
144
+ newDecays = newDecays.filter(decay => {
145
+ const conditions = selectedTags.map(element => {
146
+ const tag = element.value;
147
+ return decay.tags.includes(tag);
148
+ });
149
+ return DescriptorsSearch.variableMatch(this.state.tagMatchType, conditions);
150
+ });
151
+ }
152
+ if (this.state.selectedLine) {
153
+ const line = this.state.selectedLine.value;
154
+ newDecays = newDecays.filter(decay => {
155
+ const decayStreamLines = Object.keys(decay.lines);
156
+ const decayLines = new Set(decayStreamLines.map(streamLine => streamLine.split("/")[1]));
157
+ return decayLines.has(line);
158
+ });
159
+ }
160
+ return newDecays;
161
+ });
162
+ _defineProperty(this, "getDecayList", () => {
163
+ const strippingSelectedTags = this.state.selectedTags !== null // If a value has been chosen by the user...
164
+ ? this.state.selectedTags // ... then set according to the state.
165
+ : this.context.loaded.userHints // Otherwise, if the metadata is loaded, set the default value...
166
+ ? _SelectTag.default.createOptions(this.context.metadata.userHints.decayTags, tag => tag.hide) : []; // ... or empty if not loaded yet
167
+ const filteredDecays = this.context.loaded.decays ? this.filterDecays(strippingSelectedTags) : [];
168
+ const strippingDecayList = /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
169
+ children: this.context.loaded.decays ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_DecaysList.default, {
170
+ decays: filteredDecays,
171
+ selectedDecays: this.state.selectedDecays,
172
+ parentCallback: this.callbackFunction
173
+ }, JSON.stringify(filteredDecays)) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Alert, {
174
+ variant: "warning",
175
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Spinner, {
176
+ size: "sm",
177
+ animation: "border"
178
+ }), " Loading decays..."]
179
+ })
180
+ });
181
+ return strippingDecayList;
182
+ });
183
+ _defineProperty(this, "getExtraInputs", () => {
184
+ const strippingSelectedTags = this.state.selectedTags !== null // If a value has been chosen by the user...
185
+ ? this.state.selectedTags // ... then set according to the state.
186
+ : this.context.loaded.userHints // Otherwise, if the metadata is loaded, set the default value...
187
+ ? _SelectTag.default.createOptions(this.context.metadata.userHints.decayTags, tag => tag.hide) : []; // ... or empty if not loaded yet
188
+ const strippingExtraInput = /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
189
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.InputGroup, {
190
+ size: "sm",
191
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.DropdownButton, {
192
+ title: "Tags (" + this.state.tagMatchType + " of):",
193
+ variant: "outline-secondary",
194
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DescriptorsSearch.DropdownMatchTypes, {
195
+ parent: this,
196
+ stateItem: "tagMatchType",
197
+ options: ["any", "all", "none"]
198
+ })
199
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectTag.default, {
200
+ isMulti: true,
201
+ type: "decayTags",
202
+ placeholder: "Decay tags",
203
+ value: strippingSelectedTags,
204
+ onChange: this.updateState("selectedTags"),
205
+ closeMenuOnSelect: false
206
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
207
+ className: "react-select form-control p-0",
208
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactSelect.default, {
209
+ placeholder: "Stripping line",
210
+ isClearable: true,
211
+ options: this.context.loaded.stripping ? this.allStrippingLines().map(line => Object({
212
+ value: line,
213
+ label: line
214
+ })) : [],
215
+ onChange: this.updateState("selectedLine"),
216
+ isLoading: !this.context.loaded.stripping
217
+ })
218
+ })]
219
+ })
220
+ });
221
+ return strippingExtraInput;
222
+ });
223
+ }
224
+ static DropdownMatchTypes(props) {
225
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
226
+ children: props.options.map(option => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Dropdown.Item, {
227
+ active: props.parent.state[props.stateItem] === option,
228
+ onClick: () => props.parent.setState({
229
+ [props.stateItem]: option
230
+ }),
231
+ children: option
232
+ }, option))
233
+ });
234
+ }
235
+ static DropdownChargeConjugate(props) {
236
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
237
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Dropdown.Item, {
238
+ active: props.parent.state[props.stateItem],
239
+ onClick: () => props.parent.setState({
240
+ [props.stateItem]: true
241
+ }),
242
+ children: "Include antiparticles"
243
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Dropdown.Item, {
244
+ active: !props.parent.state[props.stateItem],
245
+ onClick: () => props.parent.setState({
246
+ [props.stateItem]: false
247
+ }),
248
+ children: "Exclude antiparticles"
249
+ })]
250
+ });
251
+ }
252
+ render() {
253
+ const nSelected = this.state.selectedDecays.length;
254
+ const {
255
+ basePath
256
+ } = this.props;
257
+ const decayList = this.getDecayList();
258
+ const extraInputs = this.getExtraInputs();
259
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
260
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
261
+ children: "Decay search"
262
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.InputGroup, {
263
+ size: "sm",
264
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.DropdownButton, {
265
+ title: "Head (" + (this.state.headMatchType === "exactly" ? this.state.headMatchType : this.state.headTagMatchType + " of") + "):",
266
+ variant: "outline-secondary",
267
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(DescriptorsSearch.DropdownMatchTypes, {
268
+ parent: this,
269
+ stateItem: "headMatchType",
270
+ options: ["exactly", "category"]
271
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Dropdown.Divider, {}), this.state.headMatchType === "exactly" ? /*#__PURE__*/(0, _jsxRuntime.jsx)(DescriptorsSearch.DropdownChargeConjugate, {
272
+ parent: this,
273
+ stateItem: "chargeConjugateHeads"
274
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(DescriptorsSearch.DropdownMatchTypes, {
275
+ parent: this,
276
+ stateItem: "headTagMatchType",
277
+ options: ["any", "all", "none"]
278
+ })]
279
+ }), this.state.headMatchType === "exactly" ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectParticle.default, {
280
+ isClearable: true,
281
+ onlyHeads: true,
282
+ placeholder: "Decay head",
283
+ onChange: this.updateState("selectedHead")
284
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectTag.default, {
285
+ isMulti: true,
286
+ type: "particleTags",
287
+ placeholder: "Decay head",
288
+ filter: tag => !tag.hide,
289
+ onChange: this.updateState("selectedHeadTags")
290
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.DropdownButton, {
291
+ title: "Contains (" + this.state.containsMatchType + " of):",
292
+ variant: "outline-secondary",
293
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(DescriptorsSearch.DropdownMatchTypes, {
294
+ parent: this,
295
+ stateItem: "containsMatchType",
296
+ options: ["any", "all", "none"]
297
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Dropdown.Divider, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(DescriptorsSearch.DropdownChargeConjugate, {
298
+ parent: this,
299
+ stateItem: "chargeConjugateContains"
300
+ })]
301
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectParticle.default, {
302
+ isMulti: true,
303
+ onlyKnown: true,
304
+ placeholder: "Particles in decay...",
305
+ onChange: this.updateState("selectedContains"),
306
+ closeMenuOnSelect: false
307
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.InputGroup.Text, {
308
+ children: "Show only selected:"
309
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.InputGroup.Checkbox, {
310
+ onChange: this.toggleState("onlySelected")
311
+ })]
312
+ }), extraInputs, decayList, /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.Link, {
313
+ to: basePath,
314
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.OverlayTrigger, {
315
+ overlay: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Tooltip, {
316
+ children: "Return to production configuration"
317
+ }),
318
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Button, {
319
+ variant: "success",
320
+ type: "submit",
321
+ onClick: this.sendData,
322
+ children: ["Select ", /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Badge, {
323
+ pill: true,
324
+ bg: "secondary",
325
+ children: nSelected
326
+ })]
327
+ })
328
+ })
329
+ })]
330
+ });
331
+ }
332
+ }
333
+ _defineProperty(DescriptorsSearch, "contextType", _MetadataContext.default);
334
+ _defineProperty(DescriptorsSearch, "variableMatch", (type, conditions) => {
335
+ if (type === "all") {
336
+ return conditions.every(x => x);
337
+ } else if (type === "any") {
338
+ return conditions.some(x => x);
339
+ } else if (type === "none") {
340
+ return !conditions.some(x => x);
341
+ } else {
342
+ console.error("Unrecognised match type: " + type);
343
+ return true;
344
+ }
345
+ });
346
+ DescriptorsSearch.propTypes = {
347
+ rows: _propTypes.default.arrayOf(_propTypes.default.object),
348
+ parentCallback: _propTypes.default.func,
349
+ basePath: _propTypes.default.string.isRequired
350
+ };
351
+ var _default = exports.default = DescriptorsSearch;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _reactBootstrap = require("react-bootstrap");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ /*****************************************************************************\
13
+ * (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration *
14
+ * *
15
+ * This software is distributed under the terms of the GNU General Public *
16
+ * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
17
+ * *
18
+ * In applying this licence, CERN does not waive the privileges and immunities *
19
+ * granted to it by virtue of its status as an Intergovernmental Organization *
20
+ * or submit itself to any jurisdiction. *
21
+ \*****************************************************************************/
22
+
23
+ class EventTypeBadge extends _react.default.Component {
24
+ render() {
25
+ const content = "" + this.props.eventType === "90000000" ? "Data" : "" + this.props.eventType;
26
+ const linkProps = content === "Data" ? {} : {
27
+ as: "a",
28
+ href: "http://lhcbdoc.web.cern.ch/lhcbdoc/decfiles/",
29
+ target: "_blank"
30
+ };
31
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Badge, {
32
+ pill: true,
33
+ ...linkProps,
34
+ bg: "primary",
35
+ children: content
36
+ });
37
+ }
38
+ }
39
+ EventTypeBadge.propTypes = {
40
+ eventType: _propTypes.default.string
41
+ };
42
+ var _default = exports.default = EventTypeBadge;
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _Tooltip = _interopRequireDefault(require("react-bootstrap/Tooltip"));
10
+ var _OverlayTrigger = _interopRequireDefault(require("react-bootstrap/OverlayTrigger"));
11
+ var _jsxRuntime = require("react/jsx-runtime");
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
15
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*****************************************************************************\
16
+ * (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration *
17
+ * *
18
+ * This software is distributed under the terms of the GNU General Public *
19
+ * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
20
+ * *
21
+ * In applying this licence, CERN does not waive the privileges and immunities *
22
+ * granted to it by virtue of its status as an Intergovernmental Organization *
23
+ * or submit itself to any jurisdiction. *
24
+ \*****************************************************************************/
25
+ const {
26
+ search
27
+ } = window.location;
28
+ const query = new URLSearchParams(search).get("s");
29
+ //const [searchQuery, setSearchQuery] = useState(query || '')
30
+
31
+ function compare(a, b) {
32
+ return Object.keys(a)[0] > Object.keys(b)[0] ? 1 : Object.keys(a)[0] < Object.keys(b)[0] ? -1 : 0;
33
+ }
34
+ class ItemSearch extends _react.default.Component {
35
+ constructor() {
36
+ super(...arguments);
37
+ _defineProperty(this, "state", {
38
+ items: this.props.data,
39
+ label: this.props.label,
40
+ searchQuery: query || ""
41
+ });
42
+ }
43
+ filterItems(variables, query) {
44
+ /*
45
+ const nInclOptions = variables.filter(
46
+ variable => !Object.keys(variable)[0].toLowerCase().includes(query.toLowerCase())
47
+ );
48
+ */
49
+ const inclOptions = variables.filter(variable => Object.keys(variable)[0].toLowerCase().includes(query.toLowerCase()) && Object.keys(variable)[0].toLowerCase() !== query.toLowerCase());
50
+ const matchedOptions = variables.filter(variable => Object.keys(variable)[0].toLowerCase() === query.toLowerCase());
51
+ const orderedNewOptions = matchedOptions.sort(compare);
52
+ //this.setState({
53
+ return orderedNewOptions.concat(inclOptions);
54
+ //});
55
+ /* if (!query) {
56
+ return variables;
57
+ }
58
+ return variables.filter((variable) => {
59
+ const name = Object.keys(variable)[0].toLowerCase();
60
+ return name.includes(query.toLowerCase());
61
+ });*/
62
+ }
63
+ render() {
64
+ //const {decay} = this.props
65
+ const filteredItems = this.filterItems(this.state.items, this.state.searchQuery);
66
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
67
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("form", {
68
+ action: "/",
69
+ method: "get",
70
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
71
+ htmlFor: "header-search",
72
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
73
+ className: "visually-hidden",
74
+ children: "Search item"
75
+ })
76
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
77
+ value: this.state.searchQuery,
78
+ onInput: e => this.setState({
79
+ searchQuery: e.target.value
80
+ }),
81
+ type: "text",
82
+ id: "header-search",
83
+ placeholder: this.state.label,
84
+ name: "s"
85
+ })]
86
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
87
+ className: "scroll",
88
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
89
+ children: filteredItems.map((variable, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_OverlayTrigger.default, {
90
+ placement: "top",
91
+ delay: {
92
+ hide: 450,
93
+ show: 300
94
+ },
95
+ overlay: props => /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
96
+ ...props,
97
+ children: Object.values(variable)[0]
98
+ }),
99
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
100
+ children: Object.keys(variable)[0]
101
+ })
102
+ }, index))
103
+ })
104
+ })]
105
+ });
106
+ }
107
+ }
108
+ ItemSearch.propTypes = {
109
+ data: _propTypes.default.arrayOf(_propTypes.default.object),
110
+ label: _propTypes.default.string
111
+ };
112
+ var _default = exports.default = ItemSearch;
113
+ /* <div>
114
+ <ul>
115
+ {filteredVariables.map(variable => (
116
+ <li key={Object.keys(variable)[0]}>{Object.keys(variable)[0]}</li>
117
+ ))}
118
+ </ul>
119
+ </div> */