@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.mjs CHANGED
@@ -5801,7 +5801,7 @@ var operators = {
5801
5801
  "<=": "less or equal"
5802
5802
  };
5803
5803
  var renderTreeLine = (index, isLast) => {
5804
- return /* @__PURE__ */ jsx33("div", { className: "mr-2 flex h-12 w-3 flex-col items-center justify-center", children: /* @__PURE__ */ jsxs23("div", { className: "flex h-full w-full items-center", children: [
5804
+ return /* @__PURE__ */ jsx33("div", { className: "mr-2 flex w-3 flex-col items-center justify-center", children: /* @__PURE__ */ jsxs23("div", { className: "flex h-full w-full items-center", children: [
5805
5805
  /* @__PURE__ */ jsx33(
5806
5806
  "div",
5807
5807
  {
@@ -5842,16 +5842,16 @@ function ValueStringMapping({ rules, onChange }) {
5842
5842
  })
5843
5843
  );
5844
5844
  }
5845
- return /* @__PURE__ */ jsxs23("div", { className: "flex w-full flex-col rounded-md py-2", children: [
5845
+ return /* @__PURE__ */ jsxs23("div", { className: "flex w-full flex-col gap-2 rounded-md", children: [
5846
5846
  (rules || []).map((rule, index) => {
5847
5847
  const isLast = index === (rules || []).length - 1;
5848
5848
  return /* @__PURE__ */ jsxs23(
5849
5849
  "div",
5850
5850
  {
5851
- className: "text-text-foreground flex h-10 items-center py-1",
5851
+ className: "text-text-foreground flex h-8 items-center",
5852
5852
  children: [
5853
5853
  renderTreeLine(index, isLast),
5854
- /* @__PURE__ */ jsx33("span", { className: "sm:text-ilabel inline-flex h-full items-center pr-3 font-medium", children: "If value is" }),
5854
+ /* @__PURE__ */ jsx33("span", { className: "sm:text-ilabel inline-flex h-full items-center pr-2 font-medium", children: "If value is" }),
5855
5855
  /* @__PURE__ */ jsx33(
5856
5856
  "select",
5857
5857
  {
@@ -5880,7 +5880,7 @@ function ValueStringMapping({ rules, onChange }) {
5880
5880
  }
5881
5881
  }
5882
5882
  ),
5883
- /* @__PURE__ */ jsx33("span", { className: "sm:text-ilabel inline-flex h-full items-center rounded-none px-3 font-medium", children: ", then show" }),
5883
+ /* @__PURE__ */ jsx33("span", { className: "sm:text-ilabel inline-flex h-full items-center rounded-none px-2 font-medium", children: ", then show" }),
5884
5884
  /* @__PURE__ */ jsx33(
5885
5885
  "input",
5886
5886
  {
@@ -5899,16 +5899,10 @@ function ValueStringMapping({ rules, onChange }) {
5899
5899
  "button",
5900
5900
  {
5901
5901
  type: "button",
5902
- className: "mx-2",
5902
+ className: "text-text-foreground-disabled hover:text-primary-600 mx-2 cursor-pointer",
5903
5903
  "aria-label": "remove",
5904
5904
  onClick: () => removeRule(index),
5905
- children: /* @__PURE__ */ jsx33(
5906
- LuTrash2,
5907
- {
5908
- className: "icon text-text-foreground-disabled",
5909
- "aria-hidden": "true"
5910
- }
5911
- )
5905
+ children: /* @__PURE__ */ jsx33(LuTrash2, { className: "icon", "aria-hidden": "true" })
5912
5906
  }
5913
5907
  )
5914
5908
  ]
@@ -5916,18 +5910,16 @@ function ValueStringMapping({ rules, onChange }) {
5916
5910
  index
5917
5911
  );
5918
5912
  }),
5919
- /* @__PURE__ */ jsxs23(
5913
+ /* @__PURE__ */ jsx33(
5920
5914
  Button3,
5921
5915
  {
5922
5916
  type: "button",
5923
5917
  role: "secondary",
5924
- className: "mt-1 w-fit flex-none",
5918
+ className: "w-fit flex-none py-1.5!",
5925
5919
  "aria-label": "remove",
5926
5920
  onClick: addRule,
5927
- children: [
5928
- /* @__PURE__ */ jsx33(LuPlus, { className: classNames9("h-4 w-4"), "aria-hidden": "true" }),
5929
- "Add Formatting Rule"
5930
- ]
5921
+ icon: /* @__PURE__ */ jsx33(LuPlus, {}),
5922
+ children: "Add Formatting Rule"
5931
5923
  }
5932
5924
  )
5933
5925
  ] });
@@ -6577,6 +6569,224 @@ function ScatterControls({
6577
6569
  }
6578
6570
  );
6579
6571
  }
6572
+
6573
+ // src/charts/options/TableControls.tsx
6574
+ import { useMemo as useMemo11 } from "react";
6575
+ import { produce as produce14 } from "immer";
6576
+ import { defaults as defaults8 } from "lodash";
6577
+ import { Checkbox as Checkbox5, DisclosurePanel as DisclosurePanel11 } from "@sentio/ui-core";
6578
+
6579
+ // src/charts/table-utils.ts
6580
+ import { startCase } from "lodash";
6581
+ var TEMPLATE_TOKEN = /{{([\s\S]+?)}}/g;
6582
+ function sanitizeLabels(labels) {
6583
+ const result = {};
6584
+ for (const k in labels) {
6585
+ switch (k) {
6586
+ case "contract_name":
6587
+ result["contract"] = labels[k];
6588
+ break;
6589
+ case "contract_address":
6590
+ result["address"] = labels[k];
6591
+ break;
6592
+ }
6593
+ result[k] = labels[k];
6594
+ }
6595
+ return result;
6596
+ }
6597
+ function aliasTemplate(alias, labels) {
6598
+ if (alias) {
6599
+ try {
6600
+ const safe = sanitizeLabels(labels);
6601
+ return alias.replace(TEMPLATE_TOKEN, (_, m1) => {
6602
+ const value = safe[m1.trim()];
6603
+ return value == null ? `` : value;
6604
+ });
6605
+ } catch (e) {
6606
+ return alias;
6607
+ }
6608
+ }
6609
+ }
6610
+ function escapeColumnId(id) {
6611
+ return id.replace(/[\W_.]+/g, "_");
6612
+ }
6613
+ function getColumnNameId(labels, alias, displayName) {
6614
+ const s = aliasTemplate(alias, labels) || startCase(displayName);
6615
+ return { columnName: s, columnId: escapeColumnId(s) };
6616
+ }
6617
+
6618
+ // src/charts/options/TableControls.tsx
6619
+ import { jsx as jsx39, jsxs as jsxs29 } from "react/jsx-runtime";
6620
+ var defaultConfig7 = {
6621
+ calculation: "LAST",
6622
+ sortColumns: [],
6623
+ showColumns: void 0,
6624
+ columnWidths: {},
6625
+ columnOrders: [],
6626
+ showPlainData: false,
6627
+ calculations: {},
6628
+ valueConfigs: {}
6629
+ };
6630
+ function getDefaultValueConfig(type) {
6631
+ switch (type) {
6632
+ case "NUMBER":
6633
+ return {
6634
+ ...defaultConfig4,
6635
+ valueFormatter: "NumberFormatter"
6636
+ };
6637
+ case "TIME":
6638
+ return {
6639
+ ...defaultConfig4,
6640
+ valueFormatter: "DateFormatter"
6641
+ };
6642
+ default:
6643
+ return {
6644
+ ...defaultConfig4,
6645
+ valueFormatter: "StringFormatter"
6646
+ };
6647
+ }
6648
+ }
6649
+ var CalculationItems3 = [
6650
+ { label: "All", value: "ALL" },
6651
+ { label: "Last", value: "LAST" },
6652
+ { label: "First", value: "FIRST" },
6653
+ { label: "Total", value: "TOTAL" },
6654
+ { label: "Mean", value: "MEAN" },
6655
+ { label: "Max", value: "MAX" },
6656
+ { label: "Min", value: "MIN" }
6657
+ ];
6658
+ function TableControls({ config, defaultOpen, onChange, data }) {
6659
+ config = defaults8({}, config, defaultConfig7);
6660
+ function onCalculationChange(col, cal) {
6661
+ config && onChange(
6662
+ produce14(config, (draft) => {
6663
+ if (col === "") {
6664
+ delete draft.calculations;
6665
+ draft.calculation = cal;
6666
+ } else {
6667
+ draft.calculations = draft.calculations || {};
6668
+ draft.calculations[col] = cal;
6669
+ }
6670
+ })
6671
+ );
6672
+ }
6673
+ function onValueConfigChange(col, valueConfig) {
6674
+ config && onChange(
6675
+ produce14(config, (draft) => {
6676
+ draft.valueConfigs = draft.valueConfigs || {};
6677
+ draft.valueConfigs[col] = valueConfig;
6678
+ })
6679
+ );
6680
+ }
6681
+ function onMapSeriesAsColumnsChange(checked) {
6682
+ config && onChange(produce14(config, (draft) => void (draft.showPlainData = checked)));
6683
+ }
6684
+ const calculations = useMemo11(() => {
6685
+ if (!config?.showPlainData) {
6686
+ return CalculationItems3.filter((item) => item.value !== "ALL");
6687
+ }
6688
+ return CalculationItems3;
6689
+ }, [config?.showPlainData]);
6690
+ const isSql = data?.result !== void 0;
6691
+ const columns = useMemo11(() => {
6692
+ if (config?.showPlainData) {
6693
+ return [];
6694
+ }
6695
+ const map = {};
6696
+ if (isSql) {
6697
+ const results = data?.result;
6698
+ if (results) {
6699
+ for (const [name, type] of Object.entries(results?.columnTypes || {})) {
6700
+ map[name] = {
6701
+ name,
6702
+ type
6703
+ };
6704
+ }
6705
+ }
6706
+ } else {
6707
+ const results = data?.results;
6708
+ for (const r of results || []) {
6709
+ for (const s of r?.matrix?.samples || []) {
6710
+ const { columnId, columnName } = getColumnNameId(
6711
+ s?.metric?.labels || {},
6712
+ r.alias,
6713
+ s.metric?.displayName
6714
+ );
6715
+ map[columnId] = {
6716
+ name: columnName
6717
+ };
6718
+ }
6719
+ }
6720
+ }
6721
+ return Object.keys(map).sort().map((k) => ({ columnId: k, column: map[k] }));
6722
+ }, [data, config]);
6723
+ return /* @__PURE__ */ jsxs29(
6724
+ DisclosurePanel11,
6725
+ {
6726
+ title: "Table Options",
6727
+ defaultOpen,
6728
+ containerClassName: "w-full bg-default-bg",
6729
+ children: [
6730
+ !isSql && /* @__PURE__ */ jsxs29("div", { className: "min-h-8 flex items-center", children: [
6731
+ /* @__PURE__ */ jsx39("div", { className: "w-48 px-2", children: /* @__PURE__ */ jsx39(
6732
+ Checkbox5,
6733
+ {
6734
+ checked: config?.showPlainData,
6735
+ onChange: onMapSeriesAsColumnsChange,
6736
+ label: "Show plain data"
6737
+ }
6738
+ ) }),
6739
+ config?.showPlainData && /* @__PURE__ */ jsxs29("div", { className: "flex", children: [
6740
+ /* @__PURE__ */ jsx39("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" }),
6741
+ /* @__PURE__ */ jsx39(
6742
+ "select",
6743
+ {
6744
+ value: config.calculation,
6745
+ 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",
6746
+ onChange: (e) => {
6747
+ onCalculationChange("", e.target.value);
6748
+ },
6749
+ children: calculations.map((d) => {
6750
+ return /* @__PURE__ */ jsx39("option", { value: d.value, children: d.label }, d.value);
6751
+ })
6752
+ }
6753
+ )
6754
+ ] }),
6755
+ /* @__PURE__ */ jsx39("div", {})
6756
+ ] }),
6757
+ /* @__PURE__ */ jsx39("div", { className: "divide-border-color flex flex-col gap-2 divide-y", children: columns.map(({ columnId, column }) => /* @__PURE__ */ jsxs29("div", { className: "flex items-start pb-2", children: [
6758
+ /* @__PURE__ */ jsx39("h4", { className: "text-text-foreground text-icontent leading-7.5 w-48 px-2 font-medium", children: column.name }),
6759
+ /* @__PURE__ */ jsxs29("div", { className: "flex flex-1 flex-wrap items-start gap-2 rounded-md", children: [
6760
+ !isSql && /* @__PURE__ */ jsxs29("div", { className: "flex", children: [
6761
+ /* @__PURE__ */ jsx39("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" }),
6762
+ /* @__PURE__ */ jsx39(
6763
+ "select",
6764
+ {
6765
+ value: config?.calculations && config?.calculations[columnId] || "LAST",
6766
+ 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",
6767
+ onChange: (e) => onCalculationChange(
6768
+ columnId,
6769
+ e.target.value
6770
+ ),
6771
+ children: calculations.map((d) => {
6772
+ return /* @__PURE__ */ jsx39("option", { value: d.value, children: d.label }, d.value);
6773
+ })
6774
+ }
6775
+ )
6776
+ ] }),
6777
+ /* @__PURE__ */ jsx39(
6778
+ ValueOptions,
6779
+ {
6780
+ onChange: (cfg) => onValueConfigChange(columnId, cfg),
6781
+ config: config?.valueConfigs && config.valueConfigs[columnId] || getDefaultValueConfig(column.type)
6782
+ }
6783
+ )
6784
+ ] })
6785
+ ] }, columnId)) })
6786
+ ]
6787
+ }
6788
+ );
6789
+ }
6580
6790
  export {
6581
6791
  AggregateInput,
6582
6792
  AreaIcon_default as AreaIcon,
@@ -6614,6 +6824,7 @@ export {
6614
6824
  ScatterControls,
6615
6825
  ScatterIcon_default as ScatterIcon,
6616
6826
  SystemLabels,
6827
+ TableControls,
6617
6828
  TableIcon_default as TableIcon,
6618
6829
  TimeSeriesChart,
6619
6830
  ValueControls,
@@ -6626,8 +6837,10 @@ export {
6626
6837
  defaultConfig5 as defaultDataConfig,
6627
6838
  defaultConfig as defaultPieConfig,
6628
6839
  defaultConfig6 as defaultScatterConfig,
6840
+ defaultConfig7 as defaultTableConfig,
6629
6841
  defaultConfig3 as defaultValueConfig,
6630
6842
  defaultConfig4 as defaultValueControlsConfig,
6843
+ getDefaultValueConfig,
6631
6844
  isAggrOrRollupFunction,
6632
6845
  sentioColors,
6633
6846
  sentioTheme,