@sentio/ui-dashboard 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1074 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ AggregateInput: () => AggregateInput,
34
+ ArgumentInput: () => ArgumentInput,
35
+ ArgumentType: () => ArgumentType,
36
+ EventsFunctionCategories: () => EventsFunctionCategories,
37
+ EventsFunctionMap: () => EventsFunctionMap,
38
+ FunctionInput: () => FunctionInput,
39
+ FunctionMap: () => FunctionMap,
40
+ FunctionsCategories: () => FunctionsCategories,
41
+ FunctionsPanel: () => FunctionsPanel,
42
+ LabelSearchProvider: () => LabelSearchProvider,
43
+ LabelsInput: () => LabelsInput,
44
+ SystemLabels: () => SystemLabels,
45
+ isAggrOrRollupFunction: () => isAggrOrRollupFunction,
46
+ sortMetricByName: () => sortMetricByName,
47
+ useLabelSearch: () => useLabelSearch,
48
+ useLabelSearchContext: () => useLabelSearchContext
49
+ });
50
+ module.exports = __toCommonJS(index_exports);
51
+
52
+ // src/timeseries/AggregateInput.tsx
53
+ var import_react = require("react");
54
+ var import_lodash = require("lodash");
55
+ var import_immer = require("immer");
56
+ var import_ui_core = require("@sentio/ui-core");
57
+
58
+ // src/timeseries/labels.ts
59
+ var import_chain = require("@sentio/chain");
60
+ var SystemLabels = [
61
+ {
62
+ field: "contract_name",
63
+ name: "contract",
64
+ getValues(metric) {
65
+ return (metric.contractName || []).map((name) => ({
66
+ value: name,
67
+ display: name
68
+ }));
69
+ }
70
+ },
71
+ {
72
+ field: "contract_address",
73
+ name: "address",
74
+ getValues(metric) {
75
+ return (metric.contractAddress || []).map((name) => ({
76
+ value: name,
77
+ display: name
78
+ }));
79
+ }
80
+ },
81
+ {
82
+ field: "chain",
83
+ name: "chain",
84
+ getValues(metric) {
85
+ return (metric.chainId || []).map((chainId) => {
86
+ return { value: chainId, display: (0, import_chain.getChainName)(chainId) };
87
+ });
88
+ }
89
+ }
90
+ ];
91
+ function sortMetricByName(a, b) {
92
+ const aIsSystem = a.startsWith("system.");
93
+ const bIsSystem = b.startsWith("system.");
94
+ if (aIsSystem && !bIsSystem) {
95
+ return 1;
96
+ }
97
+ if (!aIsSystem && bIsSystem) {
98
+ return -1;
99
+ }
100
+ return a.localeCompare(b);
101
+ }
102
+
103
+ // src/timeseries/AggregateInput.tsx
104
+ var import_jsx_runtime = require("react/jsx-runtime");
105
+ var AggregateAggregateOps = [
106
+ "AVG",
107
+ "SUM",
108
+ "MIN",
109
+ "MAX",
110
+ "COUNT"
111
+ ];
112
+ function AggregateInput({ metric, value, onChange }) {
113
+ const { labels, selectedLabels } = (0, import_react.useMemo)(() => {
114
+ const labels2 = [];
115
+ for (const sl of SystemLabels) {
116
+ labels2.push({ label: sl.name, value: sl.field });
117
+ }
118
+ Object.keys(metric?.labels || {}).forEach((l) => {
119
+ labels2.push({ label: l, value: l });
120
+ });
121
+ const selectedLabels2 = [];
122
+ for (const l of value?.aggregate?.grouping || []) {
123
+ const label = labels2.find((lb) => lb.value === l);
124
+ if (label) {
125
+ selectedLabels2.push(label);
126
+ }
127
+ }
128
+ return { labels: labels2, selectedLabels: selectedLabels2 };
129
+ }, [metric, value]);
130
+ const onSelectLabel = (labels2) => {
131
+ onChange(
132
+ (0, import_immer.produce)(value, (draft) => {
133
+ draft.aggregate = draft.aggregate || {};
134
+ draft.aggregate.grouping = labels2.map((l) => l.value);
135
+ })
136
+ );
137
+ };
138
+ const onSelectFunc = (f) => {
139
+ onChange(
140
+ (0, import_immer.produce)(value, (draft) => {
141
+ if (f == "none") {
142
+ delete draft.aggregate;
143
+ } else {
144
+ const aggr = draft.aggregate || {};
145
+ aggr.op = f;
146
+ draft.aggregate = aggr;
147
+ }
148
+ })
149
+ );
150
+ };
151
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "min-h-8 flex grow items-center justify-stretch", children: [
152
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
153
+ "select",
154
+ {
155
+ value: value.aggregate?.op || "",
156
+ className: "sm:text-ilabel border-main text-text-foreground inline-flex h-8 items-center rounded-l-md border border-r-0 bg-gray-50 py-1 pl-4 pr-7 focus:border-0 focus:ring-inset",
157
+ onChange: (e) => onSelectFunc(e.target.value),
158
+ "aria-label": "aggregate",
159
+ children: [
160
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "none", children: "No aggregate" }, ""),
161
+ AggregateAggregateOps.map((key) => {
162
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("option", { value: key, children: [
163
+ (0, import_lodash.capitalize)(key),
164
+ " by"
165
+ ] }, key);
166
+ })
167
+ ]
168
+ }
169
+ ),
170
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
171
+ import_ui_core.NewMultipleSelect,
172
+ {
173
+ disabled: !value.aggregate,
174
+ className: "border-main flex h-8 grow overflow-hidden rounded-r-md border",
175
+ options: labels || [],
176
+ value: selectedLabels,
177
+ onChange: onSelectLabel,
178
+ displayFn: (l) => l.label,
179
+ unSelectedText: "(everything)",
180
+ optionsClassName: "min-w-[200px]"
181
+ }
182
+ )
183
+ ] });
184
+ }
185
+
186
+ // src/timeseries/ArgumentInput.tsx
187
+ var import_ui_core2 = require("@sentio/ui-core");
188
+
189
+ // src/timeseries/functions.ts
190
+ var ArgumentType = /* @__PURE__ */ ((ArgumentType2) => {
191
+ ArgumentType2[ArgumentType2["String"] = 0] = "String";
192
+ ArgumentType2[ArgumentType2["Integer"] = 1] = "Integer";
193
+ ArgumentType2[ArgumentType2["Double"] = 2] = "Double";
194
+ ArgumentType2[ArgumentType2["Bool"] = 3] = "Bool";
195
+ ArgumentType2[ArgumentType2["Duration"] = 4] = "Duration";
196
+ return ArgumentType2;
197
+ })(ArgumentType || {});
198
+ var abs = {
199
+ name: "abs",
200
+ description: "Returns the absolute value.",
201
+ arguments: []
202
+ };
203
+ var ceil = {
204
+ name: "ceil",
205
+ description: "Returns the smallest integer greater than or equal to a number.",
206
+ arguments: []
207
+ };
208
+ var floor = {
209
+ name: "floor",
210
+ description: "Returns the largest integer less than or equal to a number.",
211
+ arguments: []
212
+ };
213
+ var round = {
214
+ name: "round",
215
+ description: "Returns the value of a number rounded to the nearest integer.",
216
+ arguments: []
217
+ };
218
+ var log2 = {
219
+ name: "log2",
220
+ description: "Returns the base 2 logarithm.",
221
+ arguments: []
222
+ };
223
+ var log10 = {
224
+ name: "log10",
225
+ description: "Returns the base 10 logarithm.",
226
+ arguments: []
227
+ };
228
+ var ln = {
229
+ name: "ln",
230
+ description: "Returns the natural logarithm.",
231
+ arguments: []
232
+ };
233
+ var aggregations = ["avg", "count", "last", "max", "min", "sum", "delta"];
234
+ var aggregationDescriptions = {
235
+ avg: "Calculates the sum of all values in the specified interval.",
236
+ count: "Calculates the number of values in the specified interval.",
237
+ last: "Calculates the last value in the specified interval.",
238
+ max: "Calculates the maximum of all values in the specified interval.",
239
+ min: "Calculates the minimum of all values in the specified interval.",
240
+ sum: "Calculates the sum of all values in the specified interval.",
241
+ delta: "Calculates the difference between the first and last value in the specified interval."
242
+ };
243
+ var aggregateOverTimeFunctions = aggregations.map(
244
+ (method) => ({
245
+ name: `${method}_over_time`,
246
+ description: aggregationDescriptions[method],
247
+ arguments: [
248
+ {
249
+ name: "interval",
250
+ type: 4 /* Duration */
251
+ }
252
+ ],
253
+ defaultArguments: [{ durationValue: { value: 1, unit: "m" } }]
254
+ })
255
+ );
256
+ var rollupDescriptions = {
257
+ avg: "Roll up the metric by its average value over the specified time period.",
258
+ count: "Roll up the metric by its count value over the specified time period.",
259
+ last: "Roll up the metric by its last value over the specified time period.",
260
+ max: "Roll up the metric by its maximum value over the specified time period.",
261
+ min: "Roll up the metric by its minimum value over the specified time period.",
262
+ sum: "Roll up the metric by its sum value over the specified time period.",
263
+ delta: "Roll up the metric by its delta value over the specified time period."
264
+ };
265
+ var rollupFunctions = aggregations.map(
266
+ (method) => ({
267
+ name: `rollup_${method}`,
268
+ description: rollupDescriptions[method],
269
+ arguments: [
270
+ {
271
+ name: "interval",
272
+ type: 4 /* Duration */
273
+ }
274
+ ],
275
+ defaultArguments: [{ durationValue: { value: 1, unit: "m" } }]
276
+ })
277
+ );
278
+ var rate = {
279
+ name: "rate",
280
+ description: "Calculates the per-second average rate of increase of the time series.",
281
+ arguments: [
282
+ {
283
+ name: "interval",
284
+ type: 4 /* Duration */
285
+ }
286
+ ],
287
+ defaultArguments: [{ durationValue: { value: 1, unit: "m" } }]
288
+ };
289
+ var irate = {
290
+ name: "irate",
291
+ description: "Calculates the per-second instant rate of increase of the time series.",
292
+ arguments: [
293
+ {
294
+ name: "interval",
295
+ type: 4 /* Duration */
296
+ }
297
+ ],
298
+ defaultArguments: [{ durationValue: { value: 1, unit: "m" } }]
299
+ };
300
+ var delta = {
301
+ name: "delta",
302
+ description: "Calculates the difference between the first and last value of each time series.",
303
+ arguments: [
304
+ {
305
+ name: "interval",
306
+ type: 4 /* Duration */
307
+ }
308
+ ],
309
+ defaultArguments: [{ durationValue: { value: 1, unit: "m" } }],
310
+ deprecated: true
311
+ };
312
+ var moving_delta = {
313
+ name: "moving_delta",
314
+ description: "Calculates the difference between the first and last value of each time series. (continuously)",
315
+ arguments: [
316
+ {
317
+ name: "interval",
318
+ type: 4 /* Duration */
319
+ }
320
+ ],
321
+ defaultArguments: [{ durationValue: { value: 1, unit: "m" } }],
322
+ deprecated: true
323
+ };
324
+ var topk = {
325
+ name: "topk",
326
+ description: "Returns the top k elements by sample value.",
327
+ arguments: [
328
+ {
329
+ name: "k",
330
+ type: 1 /* Integer */
331
+ }
332
+ ],
333
+ defaultArguments: [{ intValue: 1 }]
334
+ };
335
+ var bottomk = {
336
+ name: "bottomk",
337
+ description: "Returns the bottom k elements by sample value.",
338
+ arguments: [
339
+ {
340
+ name: "k",
341
+ type: 1 /* Integer */
342
+ }
343
+ ],
344
+ defaultArguments: [{ intValue: 1 }]
345
+ };
346
+ var timestamp = {
347
+ name: "timestamp",
348
+ description: "Returns the timestamp of each of the samples of the given vector as the number of seconds since January 1, 1970 UTC.",
349
+ arguments: []
350
+ };
351
+ var day_of_week = {
352
+ name: "day_of_week",
353
+ description: "Returns the day of the week for each of the given times. (needs timestamp)",
354
+ arguments: []
355
+ };
356
+ var day_of_month = {
357
+ name: "day_of_month",
358
+ description: "Returns the day of the month for each of the given times. (needs timestamp)",
359
+ arguments: []
360
+ };
361
+ var day_of_year = {
362
+ name: "day_of_year",
363
+ description: "Returns the day of the year for each of the given times. (needs timestamp)",
364
+ arguments: []
365
+ };
366
+ var month = {
367
+ name: "month",
368
+ description: "Returns the month of the given time. Returned values are from 1 to 12, where 1 means January etc. (needs timestamp)",
369
+ arguments: []
370
+ };
371
+ var year = {
372
+ name: "year",
373
+ description: "Returns the year of the given time. (needs timestamp)",
374
+ arguments: []
375
+ };
376
+ var hour = {
377
+ name: "hour",
378
+ description: "Returns the hour of the given time. Returned values are from 0 to 23. (needs timestamp)",
379
+ arguments: []
380
+ };
381
+ var minute = {
382
+ name: "minute",
383
+ description: "Returns the minute of the given time. Returned values are from 0 to 59. (needs timestamp)",
384
+ arguments: []
385
+ };
386
+ var before = {
387
+ name: "before",
388
+ displayName: "shift earlier",
389
+ description: "Shifts the vector back in time by the specified duration.",
390
+ arguments: [
391
+ {
392
+ name: "duration",
393
+ type: 4 /* Duration */
394
+ }
395
+ ],
396
+ defaultArguments: [{ durationValue: { value: 1, unit: "h" } }]
397
+ };
398
+ var after = {
399
+ name: "after",
400
+ displayName: "shift later",
401
+ description: "Shifts the vector forward in time by the specified duration.",
402
+ arguments: [
403
+ {
404
+ name: "duration",
405
+ type: 4 /* Duration */
406
+ }
407
+ ],
408
+ defaultArguments: [{ durationValue: { value: 1, unit: "h" } }]
409
+ };
410
+ var FunctionsCategories = {
411
+ Math: [abs, ceil, floor, round, log2, log10, ln],
412
+ Rollup: rollupFunctions,
413
+ "Aggregate Over Time": aggregateOverTimeFunctions,
414
+ Rate: [rate, irate, delta, moving_delta],
415
+ Rank: [topk, bottomk],
416
+ Time: [
417
+ timestamp,
418
+ day_of_year,
419
+ day_of_month,
420
+ day_of_week,
421
+ year,
422
+ month,
423
+ hour,
424
+ minute
425
+ ],
426
+ TimeShift: [before, after]
427
+ };
428
+ var FunctionMap = Object.values(
429
+ FunctionsCategories
430
+ ).reduce(
431
+ (acc, funcs) => {
432
+ funcs.forEach((f) => {
433
+ acc[f.name] = f;
434
+ });
435
+ return acc;
436
+ },
437
+ {}
438
+ );
439
+ function isAggrOrRollupFunction(name) {
440
+ const f = FunctionMap[name];
441
+ return f && (f.name.startsWith("rollup_") || f.name.endsWith("_over_time"));
442
+ }
443
+ var eventsDelta = {
444
+ name: "delta",
445
+ description: "Calculates the difference between the first and last value of each time series.",
446
+ arguments: [
447
+ {
448
+ name: "interval",
449
+ type: 4 /* Duration */
450
+ }
451
+ ],
452
+ defaultArguments: [{ durationValue: { value: 1, unit: "m" } }]
453
+ };
454
+ var EventsFunctionCategories = {
455
+ Rank: [topk, bottomk],
456
+ Delta: [eventsDelta]
457
+ };
458
+ var EventsFunctionMap = Object.values(
459
+ EventsFunctionCategories
460
+ ).reduce(
461
+ (acc, funcs) => {
462
+ funcs.forEach((f) => {
463
+ acc[f.name] = f;
464
+ });
465
+ return acc;
466
+ },
467
+ {}
468
+ );
469
+
470
+ // src/timeseries/ArgumentInput.tsx
471
+ var import_jsx_runtime2 = require("react/jsx-runtime");
472
+ function ArgumentInput({ className, argument, value, onChange }) {
473
+ switch (argument.type) {
474
+ case 0 /* String */:
475
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
476
+ "input",
477
+ {
478
+ type: "text",
479
+ className: (0, import_ui_core2.classNames)(
480
+ className,
481
+ "hover:border-primary-600 focus:border-primary-600 focus:ring-3 focus:ring-primary-600/30 border border-transparent"
482
+ ),
483
+ value: value?.stringValue,
484
+ onChange: (v) => onChange && onChange({ stringValue: v.target.value })
485
+ }
486
+ );
487
+ case 2 /* Double */:
488
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
489
+ "input",
490
+ {
491
+ type: "number",
492
+ className: (0, import_ui_core2.classNames)(
493
+ className,
494
+ "hover:border-primary-600 focus:border-primary-600 focus:ring-3 focus:ring-primary-600/30 border border-transparent"
495
+ ),
496
+ value: value?.doubleValue,
497
+ step: "any",
498
+ onChange: (v) => onChange && onChange({ doubleValue: parseFloat(v.target.value) })
499
+ }
500
+ );
501
+ case 1 /* Integer */:
502
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
503
+ "input",
504
+ {
505
+ step: "1",
506
+ type: "number",
507
+ className: (0, import_ui_core2.classNames)(
508
+ className,
509
+ "hover:border-primary-600 focus:border-primary-600 focus:ring-3 focus:ring-primary-600/30 border border-transparent"
510
+ ),
511
+ value: value?.intValue,
512
+ onChange: (v) => onChange && onChange({ intValue: parseInt(v.target.value) })
513
+ }
514
+ );
515
+ case 3 /* Bool */:
516
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
517
+ "input",
518
+ {
519
+ type: "checkbox",
520
+ className: (0, import_ui_core2.classNames)(
521
+ className,
522
+ "hover:border-primary-600 focus:border-primary-600 focus:ring-3 focus:ring-primary-600/30 border border-transparent"
523
+ ),
524
+ checked: value?.boolValue,
525
+ onChange: (e) => onChange && onChange({ boolValue: e.target.value == "true" })
526
+ }
527
+ );
528
+ case 4 /* Duration */:
529
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
530
+ import_ui_core2.DurationInput,
531
+ {
532
+ className: "rounded-none! border-transparent! hover:border-primary-600! focus-within:border-primary-600!",
533
+ inputClassName: (0, import_ui_core2.classNames)(className),
534
+ value: value?.durationValue,
535
+ onChange: (e) => onChange && onChange({ durationValue: e }),
536
+ enableDays: true
537
+ }
538
+ );
539
+ }
540
+ }
541
+
542
+ // src/timeseries/FunctionInput.tsx
543
+ var import_react4 = require("@headlessui/react");
544
+ var import_lu = require("react-icons/lu");
545
+ var import_react5 = require("@floating-ui/react");
546
+ var import_immer2 = require("immer");
547
+ var import_isEqual = __toESM(require("lodash/isEqual"));
548
+ var import_ui_core4 = require("@sentio/ui-core");
549
+
550
+ // src/timeseries/FunctionsPanel.tsx
551
+ var import_react2 = require("@headlessui/react");
552
+ var import_react3 = require("react");
553
+ var import_ui_core3 = require("@sentio/ui-core");
554
+ var import_bi = require("react-icons/bi");
555
+ var import_jsx_runtime3 = require("react/jsx-runtime");
556
+ function FunctionsPanel({
557
+ onClick,
558
+ functionCategories = FunctionsCategories,
559
+ defaultFunc
560
+ }) {
561
+ const ulRef = (0, import_react3.useRef)(null);
562
+ const [selectedIdx, setSelectedIdx] = (0, import_react3.useState)(0);
563
+ (0, import_react3.useEffect)(() => {
564
+ if (!defaultFunc) return;
565
+ let targetIndex = 0;
566
+ Object.keys(functionCategories).forEach((category, idx) => {
567
+ const func = functionCategories[category].find(
568
+ (f) => f.name === defaultFunc
569
+ );
570
+ if (func) {
571
+ targetIndex = idx;
572
+ }
573
+ });
574
+ setSelectedIdx(targetIndex);
575
+ setTimeout(() => {
576
+ const target = ulRef.current?.querySelector(
577
+ `li[data-name="${defaultFunc}"]`
578
+ );
579
+ if (target) {
580
+ target.scrollIntoView({ block: "center" });
581
+ }
582
+ }, 0);
583
+ }, [defaultFunc]);
584
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "bg-default-bg flex h-full overflow-hidden rounded-md", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react2.Tab.Group, { vertical: true, selectedIndex: selectedIdx, onChange: setSelectedIdx, children: [
585
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
586
+ import_react2.Tab.List,
587
+ {
588
+ as: "ul",
589
+ className: "native-scroller border-main flex w-44 shrink-0 flex-col flex-nowrap divide-y divide-gray-200 overflow-auto border-r",
590
+ children: Object.keys(functionCategories).map((category, idx) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react2.Tab, { as: import_react3.Fragment, children: ({ selected }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
591
+ "li",
592
+ {
593
+ onMouseOver: () => setSelectedIdx(idx),
594
+ className: (0, import_ui_core3.classNames)(
595
+ selected ? "bg-primary-500 hover:bg-primary-600" : "bg-default-bg hover:bg-gray-50",
596
+ selected ? "text-white" : "text-foreground",
597
+ "flex cursor-pointer items-center justify-between p-2 text-sm font-medium"
598
+ ),
599
+ children: [
600
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
601
+ "p",
602
+ {
603
+ className: (0, import_ui_core3.classNames)(
604
+ "text-ilabel flex-1 truncate font-medium"
605
+ ),
606
+ children: category
607
+ }
608
+ ),
609
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
610
+ import_bi.BiCaretRight,
611
+ {
612
+ className: (0, import_ui_core3.classNames)("h-3 w-3 shrink-0 self-center")
613
+ }
614
+ )
615
+ ]
616
+ }
617
+ ) }, category))
618
+ }
619
+ ),
620
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react2.Tab.Panels, { className: "flex-1", children: Object.keys(functionCategories).map((category) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
621
+ import_react2.Tab.Panel,
622
+ {
623
+ as: "ul",
624
+ className: "h-full divide-y overflow-y-auto",
625
+ ref: ulRef,
626
+ children: functionCategories[category].filter((f) => !f.deprecated).map((func) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
627
+ "li",
628
+ {
629
+ className: (0, import_ui_core3.classNames)(
630
+ "group cursor-pointer space-y-1 px-2 py-1.5",
631
+ func.name === defaultFunc ? "bg-primary-600 dark:bg-primary-600 text-white" : "hover:bg-sentio-gray-100 dark:hover:bg-sentio-gray-400 text-text-foreground dark:hover:text-white"
632
+ ),
633
+ onClick: () => onClick(func),
634
+ "data-name": func.name,
635
+ children: [
636
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "flex items-center justify-between", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-ilabel truncate font-medium", children: func.displayName || func.name }) }),
637
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "flex", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
638
+ "div",
639
+ {
640
+ className: (0, import_ui_core3.classNames)(
641
+ "text-icontent flex items-center",
642
+ func.name === defaultFunc ? "text-white/80" : "text-text-foreground-secondary"
643
+ ),
644
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { children: func.description })
645
+ }
646
+ ) })
647
+ ]
648
+ },
649
+ func.name
650
+ ))
651
+ },
652
+ category
653
+ )) })
654
+ ] }) });
655
+ }
656
+
657
+ // src/timeseries/FunctionInput.tsx
658
+ var import_jsx_runtime4 = require("react/jsx-runtime");
659
+ function FunctionInput({ value, onChange }) {
660
+ const { x, y, refs, strategy } = (0, import_react5.useFloating)({
661
+ middleware: [(0, import_react5.autoPlacement)()]
662
+ });
663
+ const onSelectFunc = (f) => {
664
+ onChange(
665
+ (0, import_immer2.produce)(value, (draft) => {
666
+ draft.functions = draft.functions || [];
667
+ draft.functions.push({
668
+ name: f.name,
669
+ arguments: f.defaultArguments || []
670
+ });
671
+ })
672
+ );
673
+ };
674
+ const remove = (f) => {
675
+ const idx = (value.functions || []).indexOf(f);
676
+ if (idx >= 0) {
677
+ onChange(
678
+ (0, import_immer2.produce)(value, (draft) => {
679
+ draft.functions = draft.functions || [];
680
+ draft.functions.splice(idx, 1);
681
+ })
682
+ );
683
+ }
684
+ };
685
+ function changeArgument(fidx, aidx, v) {
686
+ onChange(
687
+ (0, import_immer2.produce)(value, (draft) => {
688
+ draft.functions = draft.functions || [];
689
+ const f = draft.functions[fidx];
690
+ if (f) {
691
+ f.arguments = f.arguments || [];
692
+ f.arguments[aidx] = v;
693
+ }
694
+ })
695
+ );
696
+ }
697
+ function changeFunction(fidx, f) {
698
+ onChange(
699
+ (0, import_immer2.produce)(value, (draft) => {
700
+ draft.functions = draft.functions || [];
701
+ const preFunc = draft.functions[fidx];
702
+ let resetArg = true;
703
+ if (preFunc.arguments?.length === f.defaultArguments?.length) {
704
+ const firstArg = preFunc.arguments?.[0];
705
+ const firstDefaultArg = f.defaultArguments?.[0];
706
+ if (firstArg && firstDefaultArg) {
707
+ resetArg = (0, import_isEqual.default)(
708
+ Object.keys(firstArg),
709
+ Object.keys(firstDefaultArg)
710
+ ) ? false : true;
711
+ }
712
+ }
713
+ draft.functions[fidx] = {
714
+ name: f.name,
715
+ arguments: resetArg ? f.defaultArguments || [] : preFunc.arguments
716
+ };
717
+ })
718
+ );
719
+ }
720
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
721
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
722
+ Functions,
723
+ {
724
+ functions: value.functions || [],
725
+ onRemove: remove,
726
+ onChangeArgument: changeArgument,
727
+ onChangeFunction: changeFunction
728
+ }
729
+ ),
730
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "inline-flex items-center", children: [
731
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "h-0.5 w-2.5 self-center bg-gray-300" }),
732
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react4.Popover, { className: "relative", children: ({ open }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
733
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
734
+ import_react4.Popover.Button,
735
+ {
736
+ ref: refs.setReference,
737
+ "aria-label": "Add function",
738
+ className: (0, import_ui_core4.classNames)(
739
+ "text-ilabel focus:border-primary-600 focus:ring-primary-600/30 focus:ring-3 relative -ml-px inline-flex h-8 items-center space-x-2 rounded-md",
740
+ "border-main hover:border-primary-600 border px-4 font-normal",
741
+ open ? "text-primary-600 ring-1" : "text-text-foreground-secondary hover:text-text-foreground"
742
+ ),
743
+ children: [
744
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "flex text-sm", children: "f(x)" }),
745
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui_core4.HelpIcon, { text: "Add functions to query." })
746
+ ]
747
+ }
748
+ ),
749
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
750
+ import_react4.Popover.Panel,
751
+ {
752
+ className: "shadow-xs border-main z-10 mt-3 h-56 w-96 rounded-md border px-2 sm:px-0 lg:max-w-3xl",
753
+ ref: refs.setFloating,
754
+ style: {
755
+ position: strategy,
756
+ top: y ?? 0,
757
+ left: x ?? 0
758
+ },
759
+ children: ({ close }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
760
+ FunctionsPanel,
761
+ {
762
+ onClick: (f) => {
763
+ onSelectFunc(f);
764
+ close();
765
+ }
766
+ }
767
+ )
768
+ }
769
+ )
770
+ ] }) })
771
+ ] })
772
+ ] });
773
+ }
774
+ function Functions({
775
+ functions,
776
+ onRemove,
777
+ onChangeArgument,
778
+ onChangeFunction
779
+ }) {
780
+ if (functions.length == 0) {
781
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, {});
782
+ }
783
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: functions.map((f, fi) => {
784
+ const def = FunctionMap[f.name];
785
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "inline-flex items-center", children: [
786
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "h-0.5 w-2.5 self-center bg-gray-300" }),
787
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
788
+ "div",
789
+ {
790
+ className: (0, import_ui_core4.classNames)(
791
+ "text-ilabel focus:outline-hidden text-text-foreground-secondary relative inline-flex items-center pl-2 font-normal",
792
+ "border-main rounded-md border",
793
+ "h-8"
794
+ ),
795
+ children: [
796
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
797
+ import_ui_core4.PopoverButton,
798
+ {
799
+ containerClassName: "h-full border-r border-light pr-2 inline-flex items-center bg-gray-50",
800
+ content: ({ close }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "z-10 h-56 w-96 px-2 sm:px-0 lg:max-w-3xl", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
801
+ FunctionsPanel,
802
+ {
803
+ onClick: (f2) => {
804
+ onChangeFunction?.(fi, f2);
805
+ close();
806
+ },
807
+ defaultFunc: f.name
808
+ }
809
+ ) }),
810
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "hover:text-primary-600 text-text-foreground inline-flex cursor-pointer flex-nowrap items-center gap-1", children: [
811
+ def.displayName || f.name,
812
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_lu.LuChevronDown, { className: "h-4 w-4" })
813
+ ] })
814
+ }
815
+ ),
816
+ def.arguments.map((arg, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
817
+ ArgumentInput,
818
+ {
819
+ className: "sm:text-ilabel block w-full pl-4",
820
+ argument: arg,
821
+ value: f.arguments && f.arguments[i],
822
+ onChange: (v) => onChangeArgument(fi, i, v)
823
+ },
824
+ "arg_" + i
825
+ )),
826
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
827
+ "button",
828
+ {
829
+ type: "button",
830
+ className: "text-text-foreground-disabled hover:text-text-foreground hover:bg-hover h-full rounded-r-md px-2",
831
+ "aria-label": "remove function",
832
+ onClick: () => onRemove(f),
833
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_lu.LuX, { className: "h-3.5 w-3.5", "aria-hidden": "true" })
834
+ }
835
+ )
836
+ ]
837
+ }
838
+ )
839
+ ] }, f.name);
840
+ }) });
841
+ }
842
+
843
+ // src/timeseries/LabelsInput.tsx
844
+ var import_react7 = require("react");
845
+ var import_immer3 = require("immer");
846
+ var import_lodash2 = require("lodash");
847
+ var import_lu2 = require("react-icons/lu");
848
+ var import_vsc = require("react-icons/vsc");
849
+ var import_ui_core5 = require("@sentio/ui-core");
850
+
851
+ // src/timeseries/LabelSearchContext.tsx
852
+ var import_react6 = require("react");
853
+ var import_jsx_runtime5 = require("react/jsx-runtime");
854
+ var LabelSearchContext = (0, import_react6.createContext)(
855
+ void 0
856
+ );
857
+ function LabelSearchProvider({ children }) {
858
+ const [labelSearchQuery, setLabelSearchQuery] = (0, import_react6.useState)("");
859
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
860
+ LabelSearchContext.Provider,
861
+ {
862
+ value: { labelSearchQuery, setLabelSearchQuery },
863
+ children
864
+ }
865
+ );
866
+ }
867
+ function useLabelSearchContext() {
868
+ return (0, import_react6.useContext)(LabelSearchContext);
869
+ }
870
+ function useLabelSearch(defaultQuery) {
871
+ const context = useLabelSearchContext();
872
+ const [localQuery, setLocalQuery] = (0, import_react6.useState)(defaultQuery || "");
873
+ if (context) {
874
+ return context;
875
+ }
876
+ return {
877
+ labelSearchQuery: localQuery,
878
+ setLabelSearchQuery: setLocalQuery
879
+ };
880
+ }
881
+
882
+ // src/timeseries/LabelsInput.tsx
883
+ var import_jsx_runtime6 = require("react/jsx-runtime");
884
+ function LabelsInput({
885
+ value,
886
+ metric,
887
+ variables,
888
+ onChange,
889
+ small,
890
+ useRegex
891
+ }) {
892
+ const [input, setInput] = (0, import_react7.useState)("");
893
+ const onSelectLabel = (labels) => {
894
+ const selector = {};
895
+ labels.forEach((label) => {
896
+ selector[label.key] = label.value;
897
+ });
898
+ onChange(
899
+ (0, import_immer3.produce)(value, (draft) => {
900
+ draft.labelSelector = selector;
901
+ })
902
+ );
903
+ };
904
+ const { setLabelSearchQuery } = useLabelSearch();
905
+ const labelSelectors = (0, import_react7.useMemo)(() => {
906
+ const result = [];
907
+ if (metric) {
908
+ Object.entries(variables || {}).forEach(([name, variable]) => {
909
+ const varname = `$${name}`;
910
+ const labelSelector = {
911
+ display: variable.field == name ? varname : `${variable.field}: ${varname}`,
912
+ key: variable.field,
913
+ value: `${varname}`
914
+ };
915
+ if (metric.labels && metric.labels[variable.field]) {
916
+ result.push(labelSelector);
917
+ } else if (variable?.field && SystemLabels.map((l) => l.name).includes(variable?.field)) {
918
+ result.push(labelSelector);
919
+ }
920
+ });
921
+ for (const sl of SystemLabels) {
922
+ sl.getValues(metric).forEach(({ value: value2, display }) => {
923
+ result.push({
924
+ display: `${sl.name}: ${display}`,
925
+ key: sl.field,
926
+ value: value2
927
+ });
928
+ });
929
+ }
930
+ let inputLabel = "";
931
+ let inputValue = "";
932
+ if (input.includes(":")) {
933
+ ;
934
+ [inputLabel, inputValue] = input.split(":");
935
+ inputLabel = inputLabel.trim();
936
+ inputValue = inputValue.trim();
937
+ } else {
938
+ inputValue = input.trim();
939
+ }
940
+ Object.entries(metric?.labels || {}).forEach(([key, values]) => {
941
+ ;
942
+ (values.values || []).forEach((value2) => {
943
+ result.push({
944
+ display: `${key}:${value2}`,
945
+ key,
946
+ value: value2
947
+ });
948
+ });
949
+ if (!useRegex || inputValue && key.includes(inputLabel) === false || !inputValue) {
950
+ return;
951
+ }
952
+ result.push({
953
+ display: `${key}: <contains> ${inputValue}`,
954
+ key,
955
+ value: JSON.stringify({
956
+ operator: "contains",
957
+ value: inputValue,
958
+ ignoreCase: true
959
+ })
960
+ });
961
+ });
962
+ }
963
+ return (0, import_lodash2.sortedUniqBy)(
964
+ (0, import_lodash2.sortBy)(result, (r) => r.display),
965
+ (r) => r.display
966
+ );
967
+ }, [metric, variables, input, useRegex]);
968
+ const selectedLabels = (0, import_react7.useMemo)(() => {
969
+ const selector = value?.labelSelector || {};
970
+ return Object.entries(selector).map(([key, value2]) => {
971
+ return labelSelectors.find((ls) => ls.key == key && ls.value == value2) || {
972
+ display: `${key}:${value2}`,
973
+ key,
974
+ value: value2
975
+ };
976
+ });
977
+ }, [value?.labelSelector, labelSelectors]);
978
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
979
+ import_ui_core5.NewMultipleSelect,
980
+ {
981
+ input,
982
+ onInputChange: setInput,
983
+ className: (0, import_ui_core5.classNames)(
984
+ "border-main flex grow overflow-auto rounded-r-md border",
985
+ small ? "min-h-6" : "min-h-8"
986
+ ),
987
+ options: labelSelectors,
988
+ value: selectedLabels,
989
+ onChange: onSelectLabel,
990
+ displayFn: (o) => {
991
+ const { display, value: value2 } = o;
992
+ const isRegex = /^\{.*\}$/.test(value2);
993
+ if (isRegex) {
994
+ const valueObj = JSON.parse(value2);
995
+ return `${o.key}:<${valueObj?.opertaor ?? "contains"}> ${valueObj?.value ?? value2}`;
996
+ }
997
+ return display;
998
+ },
999
+ disabled: !value.query,
1000
+ unSelectedText: "(everywhere)",
1001
+ maxInputSize: 30,
1002
+ displayIcon: (o) => {
1003
+ const isRegex = /^\{.*\}$/.test(o.value);
1004
+ return isRegex ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_vsc.VscRegex, { className: "mr-1 inline-block h-3 w-3 align-top" }) : null;
1005
+ },
1006
+ renderOption: (v, _active, selected) => {
1007
+ const text = v.display;
1008
+ const isRegex = /^\{.*\}$/.test(v.value);
1009
+ const title = `${text} ${isRegex ? " (case-sensitive regex matcher)" : ""}`;
1010
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
1011
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1012
+ "span",
1013
+ {
1014
+ title,
1015
+ className: (0, import_ui_core5.classNames)(
1016
+ "block truncate",
1017
+ selected && "font-medium"
1018
+ ),
1019
+ children: [
1020
+ isRegex && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_vsc.VscRegex, { className: "mr-1 inline-block h-3 w-3 align-top" }),
1021
+ text
1022
+ ]
1023
+ }
1024
+ ),
1025
+ selected && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1026
+ "span",
1027
+ {
1028
+ className: (0, import_ui_core5.classNames)(
1029
+ "absolute inset-y-0 right-0 flex items-center pr-4"
1030
+ ),
1031
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lu2.LuCheck, { className: "h-4 w-4", "aria-hidden": "true" })
1032
+ }
1033
+ )
1034
+ ] });
1035
+ },
1036
+ filterFn: (option, input2) => {
1037
+ const { display, value: value2 } = option;
1038
+ const isRegex = /^\{.*\}$/.test(value2);
1039
+ if (isRegex) {
1040
+ return true;
1041
+ }
1042
+ return display.toLowerCase().includes(input2.toLowerCase());
1043
+ },
1044
+ validateFn: (option) => {
1045
+ const isRegex = /^\{.*\}$/.test(option.value);
1046
+ if (isRegex) {
1047
+ return true;
1048
+ }
1049
+ return labelSelectors.some((o) => (0, import_lodash2.isEqual)(o, option));
1050
+ },
1051
+ onFilterTextChange: setLabelSearchQuery
1052
+ }
1053
+ );
1054
+ }
1055
+ // Annotate the CommonJS export names for ESM import in node:
1056
+ 0 && (module.exports = {
1057
+ AggregateInput,
1058
+ ArgumentInput,
1059
+ ArgumentType,
1060
+ EventsFunctionCategories,
1061
+ EventsFunctionMap,
1062
+ FunctionInput,
1063
+ FunctionMap,
1064
+ FunctionsCategories,
1065
+ FunctionsPanel,
1066
+ LabelSearchProvider,
1067
+ LabelsInput,
1068
+ SystemLabels,
1069
+ isAggrOrRollupFunction,
1070
+ sortMetricByName,
1071
+ useLabelSearch,
1072
+ useLabelSearchContext
1073
+ });
1074
+ //# sourceMappingURL=index.js.map