@sentio/ui-dashboard 0.3.0 → 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,
@@ -5298,7 +5301,6 @@ var TimeSeriesChart = (0, import_react20.forwardRef)(
5298
5301
  }
5299
5302
  return _noLegend;
5300
5303
  }, [_noLegend, chartType, series?.length]);
5301
- console.log("options", options);
5302
5304
  return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
5303
5305
  "div",
5304
5306
  {
@@ -5832,7 +5834,7 @@ var operators = {
5832
5834
  "<=": "less or equal"
5833
5835
  };
5834
5836
  var renderTreeLine = (index, isLast) => {
5835
- 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: [
5836
5838
  /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
5837
5839
  "div",
5838
5840
  {
@@ -5873,16 +5875,16 @@ function ValueStringMapping({ rules, onChange }) {
5873
5875
  })
5874
5876
  );
5875
5877
  }
5876
- 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: [
5877
5879
  (rules || []).map((rule, index) => {
5878
5880
  const isLast = index === (rules || []).length - 1;
5879
5881
  return /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(
5880
5882
  "div",
5881
5883
  {
5882
- className: "text-text-foreground flex h-10 items-center py-1",
5884
+ className: "text-text-foreground flex h-8 items-center",
5883
5885
  children: [
5884
5886
  renderTreeLine(index, isLast),
5885
- /* @__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" }),
5886
5888
  /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
5887
5889
  "select",
5888
5890
  {
@@ -5911,7 +5913,7 @@ function ValueStringMapping({ rules, onChange }) {
5911
5913
  }
5912
5914
  }
5913
5915
  ),
5914
- /* @__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" }),
5915
5917
  /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
5916
5918
  "input",
5917
5919
  {
@@ -5930,16 +5932,10 @@ function ValueStringMapping({ rules, onChange }) {
5930
5932
  "button",
5931
5933
  {
5932
5934
  type: "button",
5933
- className: "mx-2",
5935
+ className: "text-text-foreground-disabled hover:text-primary-600 mx-2 cursor-pointer",
5934
5936
  "aria-label": "remove",
5935
5937
  onClick: () => removeRule(index),
5936
- children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
5937
- import_lu7.LuTrash2,
5938
- {
5939
- className: "icon text-text-foreground-disabled",
5940
- "aria-hidden": "true"
5941
- }
5942
- )
5938
+ children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_lu7.LuTrash2, { className: "icon", "aria-hidden": "true" })
5943
5939
  }
5944
5940
  )
5945
5941
  ]
@@ -5947,18 +5943,16 @@ function ValueStringMapping({ rules, onChange }) {
5947
5943
  index
5948
5944
  );
5949
5945
  }),
5950
- /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(
5946
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
5951
5947
  import_ui_core21.Button,
5952
5948
  {
5953
5949
  type: "button",
5954
5950
  role: "secondary",
5955
- className: "mt-1 w-fit flex-none",
5951
+ className: "w-fit flex-none py-1.5!",
5956
5952
  "aria-label": "remove",
5957
5953
  onClick: addRule,
5958
- children: [
5959
- /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_lu7.LuPlus, { className: (0, import_ui_core21.classNames)("h-4 w-4"), "aria-hidden": "true" }),
5960
- "Add Formatting Rule"
5961
- ]
5954
+ icon: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_lu7.LuPlus, {}),
5955
+ children: "Add Formatting Rule"
5962
5956
  }
5963
5957
  )
5964
5958
  ] });
@@ -6608,6 +6602,224 @@ function ScatterControls({
6608
6602
  }
6609
6603
  );
6610
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
+ }
6611
6823
  // Annotate the CommonJS export names for ESM import in node:
6612
6824
  0 && (module.exports = {
6613
6825
  AggregateInput,
@@ -6646,6 +6858,7 @@ function ScatterControls({
6646
6858
  ScatterControls,
6647
6859
  ScatterIcon,
6648
6860
  SystemLabels,
6861
+ TableControls,
6649
6862
  TableIcon,
6650
6863
  TimeSeriesChart,
6651
6864
  ValueControls,
@@ -6658,8 +6871,10 @@ function ScatterControls({
6658
6871
  defaultDataConfig,
6659
6872
  defaultPieConfig,
6660
6873
  defaultScatterConfig,
6874
+ defaultTableConfig,
6661
6875
  defaultValueConfig,
6662
6876
  defaultValueControlsConfig,
6877
+ getDefaultValueConfig,
6663
6878
  isAggrOrRollupFunction,
6664
6879
  sentioColors,
6665
6880
  sentioTheme,