@sentio/ui-dashboard 0.3.1 → 0.3.4

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 CHANGED
@@ -66,6 +66,7 @@ __export(index_exports, {
66
66
  ScatterControls: () => ScatterControls,
67
67
  ScatterIcon: () => ScatterIcon_default,
68
68
  SystemLabels: () => SystemLabels,
69
+ TableControls: () => TableControls,
69
70
  TableIcon: () => TableIcon_default,
70
71
  TimeSeriesChart: () => TimeSeriesChart,
71
72
  ValueControls: () => ValueControls,
@@ -78,8 +79,10 @@ __export(index_exports, {
78
79
  defaultDataConfig: () => defaultConfig5,
79
80
  defaultPieConfig: () => defaultConfig,
80
81
  defaultScatterConfig: () => defaultConfig6,
82
+ defaultTableConfig: () => defaultConfig7,
81
83
  defaultValueConfig: () => defaultConfig3,
82
84
  defaultValueControlsConfig: () => defaultConfig4,
85
+ getDefaultValueConfig: () => getDefaultValueConfig,
83
86
  isAggrOrRollupFunction: () => isAggrOrRollupFunction,
84
87
  sentioColors: () => sentioColors,
85
88
  sentioTheme: () => sentioTheme,
@@ -5831,7 +5834,7 @@ var operators = {
5831
5834
  "<=": "less or equal"
5832
5835
  };
5833
5836
  var renderTreeLine = (index, isLast) => {
5834
- return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: "mr-2 flex h-12 w-3 flex-col items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("div", { className: "flex h-full w-full items-center", children: [
5837
+ return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: "mr-2 flex w-3 flex-col items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("div", { className: "flex h-full w-full items-center", children: [
5835
5838
  /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
5836
5839
  "div",
5837
5840
  {
@@ -5872,16 +5875,16 @@ function ValueStringMapping({ rules, onChange }) {
5872
5875
  })
5873
5876
  );
5874
5877
  }
5875
- return /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("div", { className: "flex w-full flex-col rounded-md py-2", children: [
5878
+ return /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("div", { className: "flex w-full flex-col gap-2 rounded-md", children: [
5876
5879
  (rules || []).map((rule, index) => {
5877
5880
  const isLast = index === (rules || []).length - 1;
5878
5881
  return /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(
5879
5882
  "div",
5880
5883
  {
5881
- className: "text-text-foreground flex h-10 items-center py-1",
5884
+ className: "text-text-foreground flex h-8 items-center",
5882
5885
  children: [
5883
5886
  renderTreeLine(index, isLast),
5884
- /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("span", { className: "sm:text-ilabel inline-flex h-full items-center pr-3 font-medium", children: "If value is" }),
5887
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("span", { className: "sm:text-ilabel inline-flex h-full items-center pr-2 font-medium", children: "If value is" }),
5885
5888
  /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
5886
5889
  "select",
5887
5890
  {
@@ -5910,7 +5913,7 @@ function ValueStringMapping({ rules, onChange }) {
5910
5913
  }
5911
5914
  }
5912
5915
  ),
5913
- /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("span", { className: "sm:text-ilabel inline-flex h-full items-center rounded-none px-3 font-medium", children: ", then show" }),
5916
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("span", { className: "sm:text-ilabel inline-flex h-full items-center rounded-none px-2 font-medium", children: ", then show" }),
5914
5917
  /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
5915
5918
  "input",
5916
5919
  {
@@ -5929,16 +5932,10 @@ function ValueStringMapping({ rules, onChange }) {
5929
5932
  "button",
5930
5933
  {
5931
5934
  type: "button",
5932
- className: "mx-2",
5935
+ className: "text-text-foreground-disabled hover:text-primary-600 mx-2 cursor-pointer",
5933
5936
  "aria-label": "remove",
5934
5937
  onClick: () => removeRule(index),
5935
- children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
5936
- import_lu7.LuTrash2,
5937
- {
5938
- className: "icon text-text-foreground-disabled",
5939
- "aria-hidden": "true"
5940
- }
5941
- )
5938
+ children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_lu7.LuTrash2, { className: "icon", "aria-hidden": "true" })
5942
5939
  }
5943
5940
  )
5944
5941
  ]
@@ -5946,18 +5943,16 @@ function ValueStringMapping({ rules, onChange }) {
5946
5943
  index
5947
5944
  );
5948
5945
  }),
5949
- /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(
5946
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
5950
5947
  import_ui_core21.Button,
5951
5948
  {
5952
5949
  type: "button",
5953
5950
  role: "secondary",
5954
- className: "mt-1 w-fit flex-none",
5951
+ className: "w-fit flex-none py-1.5!",
5955
5952
  "aria-label": "remove",
5956
5953
  onClick: addRule,
5957
- children: [
5958
- /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_lu7.LuPlus, { className: (0, import_ui_core21.classNames)("h-4 w-4"), "aria-hidden": "true" }),
5959
- "Add Formatting Rule"
5960
- ]
5954
+ icon: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_lu7.LuPlus, {}),
5955
+ children: "Add Formatting Rule"
5961
5956
  }
5962
5957
  )
5963
5958
  ] });
@@ -6607,6 +6602,224 @@ function ScatterControls({
6607
6602
  }
6608
6603
  );
6609
6604
  }
6605
+
6606
+ // src/charts/options/TableControls.tsx
6607
+ var import_react24 = require("react");
6608
+ var import_immer14 = require("immer");
6609
+ var import_lodash13 = require("lodash");
6610
+ var import_ui_core27 = require("@sentio/ui-core");
6611
+
6612
+ // src/charts/table-utils.ts
6613
+ var import_lodash12 = require("lodash");
6614
+ var TEMPLATE_TOKEN = /{{([\s\S]+?)}}/g;
6615
+ function sanitizeLabels(labels) {
6616
+ const result = {};
6617
+ for (const k in labels) {
6618
+ switch (k) {
6619
+ case "contract_name":
6620
+ result["contract"] = labels[k];
6621
+ break;
6622
+ case "contract_address":
6623
+ result["address"] = labels[k];
6624
+ break;
6625
+ }
6626
+ result[k] = labels[k];
6627
+ }
6628
+ return result;
6629
+ }
6630
+ function aliasTemplate(alias, labels) {
6631
+ if (alias) {
6632
+ try {
6633
+ const safe = sanitizeLabels(labels);
6634
+ return alias.replace(TEMPLATE_TOKEN, (_, m1) => {
6635
+ const value = safe[m1.trim()];
6636
+ return value == null ? `` : value;
6637
+ });
6638
+ } catch (e) {
6639
+ return alias;
6640
+ }
6641
+ }
6642
+ }
6643
+ function escapeColumnId(id) {
6644
+ return id.replace(/[\W_.]+/g, "_");
6645
+ }
6646
+ function getColumnNameId(labels, alias, displayName) {
6647
+ const s = aliasTemplate(alias, labels) || (0, import_lodash12.startCase)(displayName);
6648
+ return { columnName: s, columnId: escapeColumnId(s) };
6649
+ }
6650
+
6651
+ // src/charts/options/TableControls.tsx
6652
+ var import_jsx_runtime39 = require("react/jsx-runtime");
6653
+ var defaultConfig7 = {
6654
+ calculation: "LAST",
6655
+ sortColumns: [],
6656
+ showColumns: void 0,
6657
+ columnWidths: {},
6658
+ columnOrders: [],
6659
+ showPlainData: false,
6660
+ calculations: {},
6661
+ valueConfigs: {}
6662
+ };
6663
+ function getDefaultValueConfig(type) {
6664
+ switch (type) {
6665
+ case "NUMBER":
6666
+ return {
6667
+ ...defaultConfig4,
6668
+ valueFormatter: "NumberFormatter"
6669
+ };
6670
+ case "TIME":
6671
+ return {
6672
+ ...defaultConfig4,
6673
+ valueFormatter: "DateFormatter"
6674
+ };
6675
+ default:
6676
+ return {
6677
+ ...defaultConfig4,
6678
+ valueFormatter: "StringFormatter"
6679
+ };
6680
+ }
6681
+ }
6682
+ var CalculationItems3 = [
6683
+ { label: "All", value: "ALL" },
6684
+ { label: "Last", value: "LAST" },
6685
+ { label: "First", value: "FIRST" },
6686
+ { label: "Total", value: "TOTAL" },
6687
+ { label: "Mean", value: "MEAN" },
6688
+ { label: "Max", value: "MAX" },
6689
+ { label: "Min", value: "MIN" }
6690
+ ];
6691
+ function TableControls({ config, defaultOpen, onChange, data }) {
6692
+ config = (0, import_lodash13.defaults)({}, config, defaultConfig7);
6693
+ function onCalculationChange(col, cal) {
6694
+ config && onChange(
6695
+ (0, import_immer14.produce)(config, (draft) => {
6696
+ if (col === "") {
6697
+ delete draft.calculations;
6698
+ draft.calculation = cal;
6699
+ } else {
6700
+ draft.calculations = draft.calculations || {};
6701
+ draft.calculations[col] = cal;
6702
+ }
6703
+ })
6704
+ );
6705
+ }
6706
+ function onValueConfigChange(col, valueConfig) {
6707
+ config && onChange(
6708
+ (0, import_immer14.produce)(config, (draft) => {
6709
+ draft.valueConfigs = draft.valueConfigs || {};
6710
+ draft.valueConfigs[col] = valueConfig;
6711
+ })
6712
+ );
6713
+ }
6714
+ function onMapSeriesAsColumnsChange(checked) {
6715
+ config && onChange((0, import_immer14.produce)(config, (draft) => void (draft.showPlainData = checked)));
6716
+ }
6717
+ const calculations = (0, import_react24.useMemo)(() => {
6718
+ if (!config?.showPlainData) {
6719
+ return CalculationItems3.filter((item) => item.value !== "ALL");
6720
+ }
6721
+ return CalculationItems3;
6722
+ }, [config?.showPlainData]);
6723
+ const isSql = data?.result !== void 0;
6724
+ const columns = (0, import_react24.useMemo)(() => {
6725
+ if (config?.showPlainData) {
6726
+ return [];
6727
+ }
6728
+ const map = {};
6729
+ if (isSql) {
6730
+ const results = data?.result;
6731
+ if (results) {
6732
+ for (const [name, type] of Object.entries(results?.columnTypes || {})) {
6733
+ map[name] = {
6734
+ name,
6735
+ type
6736
+ };
6737
+ }
6738
+ }
6739
+ } else {
6740
+ const results = data?.results;
6741
+ for (const r of results || []) {
6742
+ for (const s of r?.matrix?.samples || []) {
6743
+ const { columnId, columnName } = getColumnNameId(
6744
+ s?.metric?.labels || {},
6745
+ r.alias,
6746
+ s.metric?.displayName
6747
+ );
6748
+ map[columnId] = {
6749
+ name: columnName
6750
+ };
6751
+ }
6752
+ }
6753
+ }
6754
+ return Object.keys(map).sort().map((k) => ({ columnId: k, column: map[k] }));
6755
+ }, [data, config]);
6756
+ return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(
6757
+ import_ui_core27.DisclosurePanel,
6758
+ {
6759
+ title: "Table Options",
6760
+ defaultOpen,
6761
+ containerClassName: "w-full bg-default-bg",
6762
+ children: [
6763
+ !isSql && /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "min-h-8 flex items-center", children: [
6764
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "w-48 px-2", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6765
+ import_ui_core27.Checkbox,
6766
+ {
6767
+ checked: config?.showPlainData,
6768
+ onChange: onMapSeriesAsColumnsChange,
6769
+ label: "Show plain data"
6770
+ }
6771
+ ) }),
6772
+ config?.showPlainData && /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "flex", children: [
6773
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { className: "border-main sm:text-icontent inline-flex items-center rounded-l-md border border-r-0 bg-gray-50 px-3", children: "Calculation" }),
6774
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6775
+ "select",
6776
+ {
6777
+ value: config.calculation,
6778
+ className: "border-main text-text-foreground sm:text-icontent focus:border-primary-600 hover:border-primary-600 inline-flex items-center rounded-r-md border pl-4 pr-7 focus:ring-0",
6779
+ onChange: (e) => {
6780
+ onCalculationChange("", e.target.value);
6781
+ },
6782
+ children: calculations.map((d) => {
6783
+ return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("option", { value: d.value, children: d.label }, d.value);
6784
+ })
6785
+ }
6786
+ )
6787
+ ] }),
6788
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", {})
6789
+ ] }),
6790
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "divide-border-color flex flex-col gap-2 divide-y", children: columns.map(({ columnId, column }) => /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "flex items-start pb-2", children: [
6791
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("h4", { className: "text-text-foreground text-icontent leading-7.5 w-48 px-2 font-medium", children: column.name }),
6792
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "flex flex-1 flex-wrap items-start gap-2 rounded-md", children: [
6793
+ !isSql && /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "flex", children: [
6794
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { className: "sm:text-ilabel border-main inline-flex items-center rounded-l-md border border-r-0 bg-gray-50 px-3", children: "Calculation" }),
6795
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6796
+ "select",
6797
+ {
6798
+ value: config?.calculations && config?.calculations[columnId] || "LAST",
6799
+ className: "border-main text-text-foreground sm:text-icontent focus:border-primary-600 hover:border-primary-600 inline-flex items-center rounded-r-md border pl-4 pr-7 focus:ring-0",
6800
+ onChange: (e) => onCalculationChange(
6801
+ columnId,
6802
+ e.target.value
6803
+ ),
6804
+ children: calculations.map((d) => {
6805
+ return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("option", { value: d.value, children: d.label }, d.value);
6806
+ })
6807
+ }
6808
+ )
6809
+ ] }),
6810
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6811
+ ValueOptions,
6812
+ {
6813
+ onChange: (cfg) => onValueConfigChange(columnId, cfg),
6814
+ config: config?.valueConfigs && config.valueConfigs[columnId] || getDefaultValueConfig(column.type)
6815
+ }
6816
+ )
6817
+ ] })
6818
+ ] }, columnId)) })
6819
+ ]
6820
+ }
6821
+ );
6822
+ }
6610
6823
  // Annotate the CommonJS export names for ESM import in node:
6611
6824
  0 && (module.exports = {
6612
6825
  AggregateInput,
@@ -6645,6 +6858,7 @@ function ScatterControls({
6645
6858
  ScatterControls,
6646
6859
  ScatterIcon,
6647
6860
  SystemLabels,
6861
+ TableControls,
6648
6862
  TableIcon,
6649
6863
  TimeSeriesChart,
6650
6864
  ValueControls,
@@ -6657,8 +6871,10 @@ function ScatterControls({
6657
6871
  defaultDataConfig,
6658
6872
  defaultPieConfig,
6659
6873
  defaultScatterConfig,
6874
+ defaultTableConfig,
6660
6875
  defaultValueConfig,
6661
6876
  defaultValueControlsConfig,
6877
+ getDefaultValueConfig,
6662
6878
  isAggrOrRollupFunction,
6663
6879
  sentioColors,
6664
6880
  sentioTheme,