@sentio/ui-dashboard 0.3.4 → 0.3.6

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
@@ -41,13 +41,17 @@ __export(index_exports, {
41
41
  ChartLegend: () => ChartLegend,
42
42
  ChartTooltip: () => ChartTooltip,
43
43
  ChartTypeButtonGroup: () => ChartTypeButtonGroup,
44
+ DEFAULT_HIGHLIGHT_KEY: () => DEFAULT_HIGHLIGHT_KEY,
44
45
  DataControls: () => DataControls,
46
+ EditDashboardDialog: () => EditDashboardDialog,
47
+ EditGroupDialog: () => EditGroupDialog,
45
48
  EventsFunctionCategories: () => EventsFunctionCategories,
46
49
  EventsFunctionMap: () => EventsFunctionMap,
47
50
  FunctionInput: () => FunctionInput,
48
51
  FunctionMap: () => FunctionMap,
49
52
  FunctionsCategories: () => FunctionsCategories,
50
53
  FunctionsPanel: () => FunctionsPanel,
54
+ HIGHLIGHT_COLORS: () => HIGHLIGHT_COLORS,
51
55
  LabelControls: () => LabelControls,
52
56
  LabelSearchProvider: () => LabelSearchProvider,
53
57
  LabelsInput: () => LabelsInput,
@@ -83,7 +87,10 @@ __export(index_exports, {
83
87
  defaultValueConfig: () => defaultConfig3,
84
88
  defaultValueControlsConfig: () => defaultConfig4,
85
89
  getDefaultValueConfig: () => getDefaultValueConfig,
90
+ getHighlightHex: () => getHighlightHex,
86
91
  isAggrOrRollupFunction: () => isAggrOrRollupFunction,
92
+ resolveHeaderStyle: () => resolveHeaderStyle,
93
+ resolveHighlight: () => resolveHighlight,
87
94
  sentioColors: () => sentioColors,
88
95
  sentioTheme: () => sentioTheme,
89
96
  sentioThemeDark: () => sentioThemeDark,
@@ -5948,7 +5955,7 @@ function ValueStringMapping({ rules, onChange }) {
5948
5955
  {
5949
5956
  type: "button",
5950
5957
  role: "secondary",
5951
- className: "w-fit flex-none py-1.5!",
5958
+ className: "py-1.5! w-fit flex-none",
5952
5959
  "aria-label": "remove",
5953
5960
  onClick: addRule,
5954
5961
  icon: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_lu7.LuPlus, {}),
@@ -6820,6 +6827,339 @@ function TableControls({ config, defaultOpen, onChange, data }) {
6820
6827
  }
6821
6828
  );
6822
6829
  }
6830
+
6831
+ // src/dashboard/EditDashboardDialog.tsx
6832
+ var import_react25 = require("react");
6833
+ var import_ui_core28 = require("@sentio/ui-core");
6834
+ var import_jsx_runtime40 = require("react/jsx-runtime");
6835
+ var EditDashboardDialog = ({
6836
+ dashboard,
6837
+ open,
6838
+ onClose,
6839
+ onUpdate
6840
+ }) => {
6841
+ const [processing, setProcessing] = (0, import_react25.useState)(false);
6842
+ const [updateDisabled, setUpdateDisabled] = (0, import_react25.useState)(true);
6843
+ const inputElementRef = (0, import_react25.useRef)(null);
6844
+ const onCloseAndReset = (0, import_react25.useCallback)(() => {
6845
+ onClose?.();
6846
+ if (dashboard?.name && inputElementRef.current) {
6847
+ inputElementRef.current.value = dashboard.name;
6848
+ }
6849
+ }, [onClose, dashboard?.name]);
6850
+ const onOk = (0, import_react25.useCallback)(() => {
6851
+ if (!inputElementRef.current?.value) {
6852
+ return;
6853
+ }
6854
+ setProcessing(true);
6855
+ onUpdate({ ...dashboard, name: inputElementRef.current?.value }).then(() => {
6856
+ onCloseAndReset();
6857
+ }).finally(() => {
6858
+ setProcessing(false);
6859
+ });
6860
+ }, [onCloseAndReset, onUpdate, dashboard]);
6861
+ (0, import_react25.useEffect)(() => {
6862
+ if (open && dashboard?.name && inputElementRef.current) {
6863
+ inputElementRef.current.value = dashboard.name;
6864
+ }
6865
+ }, [open, dashboard?.name]);
6866
+ const onInputChange = (0, import_react25.useCallback)(
6867
+ (evt) => {
6868
+ const value = evt.target.value;
6869
+ if (!value || value === dashboard?.name) {
6870
+ setUpdateDisabled(true);
6871
+ } else {
6872
+ setUpdateDisabled(false);
6873
+ }
6874
+ },
6875
+ [dashboard?.name]
6876
+ );
6877
+ const okProps = (0, import_react25.useMemo)(
6878
+ () => ({
6879
+ processing,
6880
+ disabled: updateDisabled
6881
+ }),
6882
+ [updateDisabled, processing]
6883
+ );
6884
+ return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
6885
+ import_ui_core28.BaseDialog,
6886
+ {
6887
+ title: "Edit Dashboard",
6888
+ open,
6889
+ onClose: onCloseAndReset,
6890
+ cancelText: "Close",
6891
+ onCancel: onCloseAndReset,
6892
+ onOk,
6893
+ okProps,
6894
+ okText: "Update",
6895
+ footerBorder: false,
6896
+ initialFocus: inputElementRef,
6897
+ children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
6898
+ "form",
6899
+ {
6900
+ method: "dialog",
6901
+ className: "text-text-foreground relative mb-4 mt-2 px-4",
6902
+ onSubmit: onOk,
6903
+ children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: "grid py-2 text-sm", children: [
6904
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: "sm:text-ilabel text-text-foreground-secondary mb-2 mt-1", children: "Dashboard Name" }),
6905
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
6906
+ "input",
6907
+ {
6908
+ defaultValue: dashboard?.name,
6909
+ placeholder: "Provide a new name for your dashboard",
6910
+ type: "text",
6911
+ required: true,
6912
+ name: "dashboard-name",
6913
+ id: "new-dashboard-name",
6914
+ className: "focus:border-primary-600 focus:ring-primary-600/30 focus:ring-3 hover:border-primary-600 sm:text-ilabel border-main block w-full rounded-md",
6915
+ ref: inputElementRef,
6916
+ onChange: onInputChange
6917
+ }
6918
+ )
6919
+ ] })
6920
+ }
6921
+ )
6922
+ }
6923
+ );
6924
+ };
6925
+
6926
+ // src/dashboard/EditGroupDialog.tsx
6927
+ var import_react26 = require("react");
6928
+ var import_ui_core29 = require("@sentio/ui-core");
6929
+ var import_lu9 = require("react-icons/lu");
6930
+
6931
+ // src/dashboard/group-styles.ts
6932
+ var CLASSIC_INDEX = {
6933
+ blue: 0,
6934
+ cyan: 1,
6935
+ pink: 2,
6936
+ yellow: 3,
6937
+ green: 4,
6938
+ lightblue: 5,
6939
+ purple: 6,
6940
+ red: 7,
6941
+ orange: 8
6942
+ };
6943
+ var HIGHLIGHT_COLORS = [
6944
+ { key: "green", name: "Sentio Green" },
6945
+ { key: "blue", name: "Sentio Blue" },
6946
+ { key: "cyan", name: "Sentio Cyan" },
6947
+ { key: "lightblue", name: "Sentio Light Blue" },
6948
+ { key: "purple", name: "Sentio Purple" },
6949
+ { key: "pink", name: "Sentio Pink" },
6950
+ { key: "red", name: "Sentio Red" },
6951
+ { key: "orange", name: "Sentio Orange" },
6952
+ { key: "yellow", name: "Sentio Yellow" }
6953
+ ];
6954
+ var DEFAULT_HIGHLIGHT_KEY = "green";
6955
+ function getHighlightHex(key, isDark) {
6956
+ if (!key) return void 0;
6957
+ const idx = CLASSIC_INDEX[key];
6958
+ if (idx === void 0) return void 0;
6959
+ return sentioColors[isDark ? "dark" : "light"].classic[idx];
6960
+ }
6961
+ function readableForeground(hex) {
6962
+ const m = hex.replace("#", "");
6963
+ const r = parseInt(m.slice(0, 2), 16) / 255;
6964
+ const g = parseInt(m.slice(2, 4), 16) / 255;
6965
+ const b = parseInt(m.slice(4, 6), 16) / 255;
6966
+ const lin = (v) => v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
6967
+ const L = 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
6968
+ return L > 0.5 ? "#1f2937" : "#ffffff";
6969
+ }
6970
+ function resolveHighlight(colorKey, isDark) {
6971
+ const hex = getHighlightHex(colorKey, isDark) ?? getHighlightHex(DEFAULT_HIGHLIGHT_KEY, isDark);
6972
+ return { solid: hex, foreground: readableForeground(hex) };
6973
+ }
6974
+ function resolveHeaderStyle(style, colorKey, isDark) {
6975
+ if (!style || style === "DEFAULT") return {};
6976
+ const color = resolveHighlight(colorKey, isDark);
6977
+ return { backgroundColor: color.solid, color: color.foreground };
6978
+ }
6979
+
6980
+ // src/dashboard/EditGroupDialog.tsx
6981
+ var import_jsx_runtime41 = require("react/jsx-runtime");
6982
+ function StyleCard({ selected, label, onClick, preview }) {
6983
+ return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
6984
+ "button",
6985
+ {
6986
+ type: "button",
6987
+ onClick,
6988
+ className: (0, import_ui_core29.classNames)(
6989
+ "flex flex-col items-stretch overflow-hidden rounded-lg border text-left transition-colors",
6990
+ selected ? "border-primary-600 ring-primary-600/30 ring-3 shadow-sm" : "border-main hover:border-primary-400"
6991
+ ),
6992
+ children: [
6993
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "bg-hover/40 flex h-28 items-center justify-center", children: preview }),
6994
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
6995
+ "div",
6996
+ {
6997
+ className: (0, import_ui_core29.classNames)(
6998
+ "border-main flex items-center justify-center gap-1.5 border-t px-2 py-2 text-sm",
6999
+ selected ? "text-primary-600 font-semibold" : "text-text-foreground font-medium"
7000
+ ),
7001
+ children: [
7002
+ selected && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(import_lu9.LuCheck, { className: "h-3.5 w-3.5" }),
7003
+ label
7004
+ ]
7005
+ }
7006
+ )
7007
+ ]
7008
+ }
7009
+ );
7010
+ }
7011
+ function DefaultPreview() {
7012
+ return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "border-main bg-default-bg text-text-foreground flex h-16 w-32 items-center rounded border px-2 text-base", children: "Title" });
7013
+ }
7014
+ function EmphasisPreview({
7015
+ color
7016
+ }) {
7017
+ return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "border-main bg-default-bg flex h-16 w-32 flex-col rounded border", children: [
7018
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
7019
+ "div",
7020
+ {
7021
+ className: "flex h-9 items-center justify-center text-sm font-semibold",
7022
+ style: { backgroundColor: color.solid, color: color.foreground },
7023
+ children: "Title"
7024
+ }
7025
+ ),
7026
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "flex-1" })
7027
+ ] });
7028
+ }
7029
+ function EditGroupDialog({
7030
+ open,
7031
+ onClose,
7032
+ title,
7033
+ style,
7034
+ highlightColor,
7035
+ onSave
7036
+ }) {
7037
+ const [draftTitle, setDraftTitle] = (0, import_react26.useState)(title);
7038
+ const [draftStyle, setDraftStyle] = (0, import_react26.useState)(style);
7039
+ const [draftColor, setDraftColor] = (0, import_react26.useState)(highlightColor);
7040
+ const titleRef = (0, import_react26.useRef)(null);
7041
+ const isDark = useDarkMode();
7042
+ (0, import_react26.useEffect)(() => {
7043
+ if (!open) return;
7044
+ setDraftTitle(title);
7045
+ setDraftStyle(style || "DEFAULT");
7046
+ setDraftColor(
7047
+ highlightColor || (style && style !== "DEFAULT" ? DEFAULT_HIGHLIGHT_KEY : "")
7048
+ );
7049
+ }, [open, title, style, highlightColor]);
7050
+ const previewColor = (0, import_react26.useMemo)(
7051
+ () => resolveHighlight(draftColor, isDark),
7052
+ [draftColor, isDark]
7053
+ );
7054
+ const onPickStyle = (next) => {
7055
+ setDraftStyle(next);
7056
+ if (next !== "DEFAULT" && !draftColor) {
7057
+ setDraftColor(DEFAULT_HIGHLIGHT_KEY);
7058
+ }
7059
+ };
7060
+ const onOk = () => {
7061
+ onSave({
7062
+ title: draftTitle.trim() || "Group",
7063
+ style: draftStyle,
7064
+ // Persist '' for DEFAULT so we don't pollute the model with an unused
7065
+ // color when the user reverts.
7066
+ highlightColor: draftStyle === "DEFAULT" ? "" : draftColor || DEFAULT_HIGHLIGHT_KEY
7067
+ });
7068
+ onClose();
7069
+ };
7070
+ const colorOptions = (0, import_react26.useMemo)(
7071
+ () => HIGHLIGHT_COLORS.map((c) => {
7072
+ const resolved = resolveHighlight(c.key, isDark);
7073
+ return {
7074
+ value: c.key,
7075
+ title: c.name,
7076
+ label: ({ selected }) => /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "flex w-full items-center gap-2.5 pr-2", children: [
7077
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
7078
+ "div",
7079
+ {
7080
+ className: "flex h-5 w-5 items-center justify-center rounded text-xs font-bold",
7081
+ style: {
7082
+ backgroundColor: resolved.solid,
7083
+ color: resolved.foreground
7084
+ },
7085
+ children: "T"
7086
+ }
7087
+ ),
7088
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("span", { className: "flex-1 text-sm", children: c.name }),
7089
+ selected && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(import_lu9.LuCheck, { className: "text-primary-600 h-4 w-4" })
7090
+ ] })
7091
+ };
7092
+ }),
7093
+ [isDark]
7094
+ );
7095
+ return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
7096
+ import_ui_core29.BaseDialog,
7097
+ {
7098
+ title: "Edit Group",
7099
+ open,
7100
+ onClose,
7101
+ cancelText: "Cancel",
7102
+ onCancel: onClose,
7103
+ onOk,
7104
+ okText: "Save",
7105
+ panelClassName: "sm:max-w-xl",
7106
+ initialFocus: titleRef,
7107
+ children: /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "text-text-foreground px-4 pb-2 pt-4", children: [
7108
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("h4", { className: "text-text-foreground mb-3 text-sm font-semibold", children: "Display options" }),
7109
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("label", { className: "text-text-foreground-secondary text-ilabel mb-1 block", children: "Title" }),
7110
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
7111
+ "input",
7112
+ {
7113
+ ref: titleRef,
7114
+ type: "text",
7115
+ value: draftTitle,
7116
+ onChange: (e) => setDraftTitle(e.target.value),
7117
+ onKeyDown: (e) => {
7118
+ if (e.key === "Enter") {
7119
+ e.preventDefault();
7120
+ onOk();
7121
+ }
7122
+ },
7123
+ className: "focus:border-primary-600 focus:ring-primary-600/30 focus:ring-3 hover:border-primary-600 sm:text-ilabel border-main mb-4 block w-full rounded-md"
7124
+ }
7125
+ ),
7126
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: "mb-4 grid grid-cols-2 gap-3", children: [
7127
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
7128
+ StyleCard,
7129
+ {
7130
+ selected: draftStyle === "DEFAULT",
7131
+ label: "Default",
7132
+ onClick: () => onPickStyle("DEFAULT"),
7133
+ preview: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(DefaultPreview, {})
7134
+ }
7135
+ ),
7136
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
7137
+ StyleCard,
7138
+ {
7139
+ selected: draftStyle === "EMPHASIS",
7140
+ label: "Emphasis",
7141
+ onClick: () => onPickStyle("EMPHASIS"),
7142
+ preview: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(EmphasisPreview, { color: previewColor })
7143
+ }
7144
+ )
7145
+ ] }),
7146
+ draftStyle !== "DEFAULT" && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(import_jsx_runtime41.Fragment, { children: [
7147
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("label", { className: "text-text-foreground-secondary text-ilabel mb-1 block", children: "Highlight Color" }),
7148
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
7149
+ import_ui_core29.Select,
7150
+ {
7151
+ value: draftColor || DEFAULT_HIGHLIGHT_KEY,
7152
+ onChange: (v) => setDraftColor(v),
7153
+ options: colorOptions,
7154
+ size: "md",
7155
+ asLayer: true
7156
+ }
7157
+ )
7158
+ ] })
7159
+ ] })
7160
+ }
7161
+ );
7162
+ }
6823
7163
  // Annotate the CommonJS export names for ESM import in node:
6824
7164
  0 && (module.exports = {
6825
7165
  AggregateInput,
@@ -6833,13 +7173,17 @@ function TableControls({ config, defaultOpen, onChange, data }) {
6833
7173
  ChartLegend,
6834
7174
  ChartTooltip,
6835
7175
  ChartTypeButtonGroup,
7176
+ DEFAULT_HIGHLIGHT_KEY,
6836
7177
  DataControls,
7178
+ EditDashboardDialog,
7179
+ EditGroupDialog,
6837
7180
  EventsFunctionCategories,
6838
7181
  EventsFunctionMap,
6839
7182
  FunctionInput,
6840
7183
  FunctionMap,
6841
7184
  FunctionsCategories,
6842
7185
  FunctionsPanel,
7186
+ HIGHLIGHT_COLORS,
6843
7187
  LabelControls,
6844
7188
  LabelSearchProvider,
6845
7189
  LabelsInput,
@@ -6875,7 +7219,10 @@ function TableControls({ config, defaultOpen, onChange, data }) {
6875
7219
  defaultValueConfig,
6876
7220
  defaultValueControlsConfig,
6877
7221
  getDefaultValueConfig,
7222
+ getHighlightHex,
6878
7223
  isAggrOrRollupFunction,
7224
+ resolveHeaderStyle,
7225
+ resolveHighlight,
6879
7226
  sentioColors,
6880
7227
  sentioTheme,
6881
7228
  sentioThemeDark,