@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.mjs CHANGED
@@ -5915,7 +5915,7 @@ function ValueStringMapping({ rules, onChange }) {
5915
5915
  {
5916
5916
  type: "button",
5917
5917
  role: "secondary",
5918
- className: "w-fit flex-none py-1.5!",
5918
+ className: "py-1.5! w-fit flex-none",
5919
5919
  "aria-label": "remove",
5920
5920
  onClick: addRule,
5921
5921
  icon: /* @__PURE__ */ jsx33(LuPlus, {}),
@@ -6787,6 +6787,339 @@ function TableControls({ config, defaultOpen, onChange, data }) {
6787
6787
  }
6788
6788
  );
6789
6789
  }
6790
+
6791
+ // src/dashboard/EditDashboardDialog.tsx
6792
+ import { useState as useState11, useRef as useRef5, useCallback as useCallback6, useEffect as useEffect10, useMemo as useMemo12 } from "react";
6793
+ import { BaseDialog } from "@sentio/ui-core";
6794
+ import { jsx as jsx40, jsxs as jsxs30 } from "react/jsx-runtime";
6795
+ var EditDashboardDialog = ({
6796
+ dashboard,
6797
+ open,
6798
+ onClose,
6799
+ onUpdate
6800
+ }) => {
6801
+ const [processing, setProcessing] = useState11(false);
6802
+ const [updateDisabled, setUpdateDisabled] = useState11(true);
6803
+ const inputElementRef = useRef5(null);
6804
+ const onCloseAndReset = useCallback6(() => {
6805
+ onClose?.();
6806
+ if (dashboard?.name && inputElementRef.current) {
6807
+ inputElementRef.current.value = dashboard.name;
6808
+ }
6809
+ }, [onClose, dashboard?.name]);
6810
+ const onOk = useCallback6(() => {
6811
+ if (!inputElementRef.current?.value) {
6812
+ return;
6813
+ }
6814
+ setProcessing(true);
6815
+ onUpdate({ ...dashboard, name: inputElementRef.current?.value }).then(() => {
6816
+ onCloseAndReset();
6817
+ }).finally(() => {
6818
+ setProcessing(false);
6819
+ });
6820
+ }, [onCloseAndReset, onUpdate, dashboard]);
6821
+ useEffect10(() => {
6822
+ if (open && dashboard?.name && inputElementRef.current) {
6823
+ inputElementRef.current.value = dashboard.name;
6824
+ }
6825
+ }, [open, dashboard?.name]);
6826
+ const onInputChange = useCallback6(
6827
+ (evt) => {
6828
+ const value = evt.target.value;
6829
+ if (!value || value === dashboard?.name) {
6830
+ setUpdateDisabled(true);
6831
+ } else {
6832
+ setUpdateDisabled(false);
6833
+ }
6834
+ },
6835
+ [dashboard?.name]
6836
+ );
6837
+ const okProps = useMemo12(
6838
+ () => ({
6839
+ processing,
6840
+ disabled: updateDisabled
6841
+ }),
6842
+ [updateDisabled, processing]
6843
+ );
6844
+ return /* @__PURE__ */ jsx40(
6845
+ BaseDialog,
6846
+ {
6847
+ title: "Edit Dashboard",
6848
+ open,
6849
+ onClose: onCloseAndReset,
6850
+ cancelText: "Close",
6851
+ onCancel: onCloseAndReset,
6852
+ onOk,
6853
+ okProps,
6854
+ okText: "Update",
6855
+ footerBorder: false,
6856
+ initialFocus: inputElementRef,
6857
+ children: /* @__PURE__ */ jsx40(
6858
+ "form",
6859
+ {
6860
+ method: "dialog",
6861
+ className: "text-text-foreground relative mb-4 mt-2 px-4",
6862
+ onSubmit: onOk,
6863
+ children: /* @__PURE__ */ jsxs30("div", { className: "grid py-2 text-sm", children: [
6864
+ /* @__PURE__ */ jsx40("div", { className: "sm:text-ilabel text-text-foreground-secondary mb-2 mt-1", children: "Dashboard Name" }),
6865
+ /* @__PURE__ */ jsx40(
6866
+ "input",
6867
+ {
6868
+ defaultValue: dashboard?.name,
6869
+ placeholder: "Provide a new name for your dashboard",
6870
+ type: "text",
6871
+ required: true,
6872
+ name: "dashboard-name",
6873
+ id: "new-dashboard-name",
6874
+ 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",
6875
+ ref: inputElementRef,
6876
+ onChange: onInputChange
6877
+ }
6878
+ )
6879
+ ] })
6880
+ }
6881
+ )
6882
+ }
6883
+ );
6884
+ };
6885
+
6886
+ // src/dashboard/EditGroupDialog.tsx
6887
+ import { useEffect as useEffect11, useMemo as useMemo13, useRef as useRef6, useState as useState12 } from "react";
6888
+ import { BaseDialog as BaseDialog2, Select as Select2, classNames as classNames12 } from "@sentio/ui-core";
6889
+ import { LuCheck as LuCheck2 } from "react-icons/lu";
6890
+
6891
+ // src/dashboard/group-styles.ts
6892
+ var CLASSIC_INDEX = {
6893
+ blue: 0,
6894
+ cyan: 1,
6895
+ pink: 2,
6896
+ yellow: 3,
6897
+ green: 4,
6898
+ lightblue: 5,
6899
+ purple: 6,
6900
+ red: 7,
6901
+ orange: 8
6902
+ };
6903
+ var HIGHLIGHT_COLORS = [
6904
+ { key: "green", name: "Sentio Green" },
6905
+ { key: "blue", name: "Sentio Blue" },
6906
+ { key: "cyan", name: "Sentio Cyan" },
6907
+ { key: "lightblue", name: "Sentio Light Blue" },
6908
+ { key: "purple", name: "Sentio Purple" },
6909
+ { key: "pink", name: "Sentio Pink" },
6910
+ { key: "red", name: "Sentio Red" },
6911
+ { key: "orange", name: "Sentio Orange" },
6912
+ { key: "yellow", name: "Sentio Yellow" }
6913
+ ];
6914
+ var DEFAULT_HIGHLIGHT_KEY = "green";
6915
+ function getHighlightHex(key, isDark) {
6916
+ if (!key) return void 0;
6917
+ const idx = CLASSIC_INDEX[key];
6918
+ if (idx === void 0) return void 0;
6919
+ return sentioColors[isDark ? "dark" : "light"].classic[idx];
6920
+ }
6921
+ function readableForeground(hex) {
6922
+ const m = hex.replace("#", "");
6923
+ const r = parseInt(m.slice(0, 2), 16) / 255;
6924
+ const g = parseInt(m.slice(2, 4), 16) / 255;
6925
+ const b = parseInt(m.slice(4, 6), 16) / 255;
6926
+ const lin = (v) => v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
6927
+ const L = 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
6928
+ return L > 0.5 ? "#1f2937" : "#ffffff";
6929
+ }
6930
+ function resolveHighlight(colorKey, isDark) {
6931
+ const hex = getHighlightHex(colorKey, isDark) ?? getHighlightHex(DEFAULT_HIGHLIGHT_KEY, isDark);
6932
+ return { solid: hex, foreground: readableForeground(hex) };
6933
+ }
6934
+ function resolveHeaderStyle(style, colorKey, isDark) {
6935
+ if (!style || style === "DEFAULT") return {};
6936
+ const color = resolveHighlight(colorKey, isDark);
6937
+ return { backgroundColor: color.solid, color: color.foreground };
6938
+ }
6939
+
6940
+ // src/dashboard/EditGroupDialog.tsx
6941
+ import { Fragment as Fragment10, jsx as jsx41, jsxs as jsxs31 } from "react/jsx-runtime";
6942
+ function StyleCard({ selected, label, onClick, preview }) {
6943
+ return /* @__PURE__ */ jsxs31(
6944
+ "button",
6945
+ {
6946
+ type: "button",
6947
+ onClick,
6948
+ className: classNames12(
6949
+ "flex flex-col items-stretch overflow-hidden rounded-lg border text-left transition-colors",
6950
+ selected ? "border-primary-600 ring-primary-600/30 ring-3 shadow-sm" : "border-main hover:border-primary-400"
6951
+ ),
6952
+ children: [
6953
+ /* @__PURE__ */ jsx41("div", { className: "bg-hover/40 flex h-28 items-center justify-center", children: preview }),
6954
+ /* @__PURE__ */ jsxs31(
6955
+ "div",
6956
+ {
6957
+ className: classNames12(
6958
+ "border-main flex items-center justify-center gap-1.5 border-t px-2 py-2 text-sm",
6959
+ selected ? "text-primary-600 font-semibold" : "text-text-foreground font-medium"
6960
+ ),
6961
+ children: [
6962
+ selected && /* @__PURE__ */ jsx41(LuCheck2, { className: "h-3.5 w-3.5" }),
6963
+ label
6964
+ ]
6965
+ }
6966
+ )
6967
+ ]
6968
+ }
6969
+ );
6970
+ }
6971
+ function DefaultPreview() {
6972
+ return /* @__PURE__ */ jsx41("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" });
6973
+ }
6974
+ function EmphasisPreview({
6975
+ color
6976
+ }) {
6977
+ return /* @__PURE__ */ jsxs31("div", { className: "border-main bg-default-bg flex h-16 w-32 flex-col rounded border", children: [
6978
+ /* @__PURE__ */ jsx41(
6979
+ "div",
6980
+ {
6981
+ className: "flex h-9 items-center justify-center text-sm font-semibold",
6982
+ style: { backgroundColor: color.solid, color: color.foreground },
6983
+ children: "Title"
6984
+ }
6985
+ ),
6986
+ /* @__PURE__ */ jsx41("div", { className: "flex-1" })
6987
+ ] });
6988
+ }
6989
+ function EditGroupDialog({
6990
+ open,
6991
+ onClose,
6992
+ title,
6993
+ style,
6994
+ highlightColor,
6995
+ onSave
6996
+ }) {
6997
+ const [draftTitle, setDraftTitle] = useState12(title);
6998
+ const [draftStyle, setDraftStyle] = useState12(style);
6999
+ const [draftColor, setDraftColor] = useState12(highlightColor);
7000
+ const titleRef = useRef6(null);
7001
+ const isDark = useDarkMode();
7002
+ useEffect11(() => {
7003
+ if (!open) return;
7004
+ setDraftTitle(title);
7005
+ setDraftStyle(style || "DEFAULT");
7006
+ setDraftColor(
7007
+ highlightColor || (style && style !== "DEFAULT" ? DEFAULT_HIGHLIGHT_KEY : "")
7008
+ );
7009
+ }, [open, title, style, highlightColor]);
7010
+ const previewColor = useMemo13(
7011
+ () => resolveHighlight(draftColor, isDark),
7012
+ [draftColor, isDark]
7013
+ );
7014
+ const onPickStyle = (next) => {
7015
+ setDraftStyle(next);
7016
+ if (next !== "DEFAULT" && !draftColor) {
7017
+ setDraftColor(DEFAULT_HIGHLIGHT_KEY);
7018
+ }
7019
+ };
7020
+ const onOk = () => {
7021
+ onSave({
7022
+ title: draftTitle.trim() || "Group",
7023
+ style: draftStyle,
7024
+ // Persist '' for DEFAULT so we don't pollute the model with an unused
7025
+ // color when the user reverts.
7026
+ highlightColor: draftStyle === "DEFAULT" ? "" : draftColor || DEFAULT_HIGHLIGHT_KEY
7027
+ });
7028
+ onClose();
7029
+ };
7030
+ const colorOptions = useMemo13(
7031
+ () => HIGHLIGHT_COLORS.map((c) => {
7032
+ const resolved = resolveHighlight(c.key, isDark);
7033
+ return {
7034
+ value: c.key,
7035
+ title: c.name,
7036
+ label: ({ selected }) => /* @__PURE__ */ jsxs31("div", { className: "flex w-full items-center gap-2.5 pr-2", children: [
7037
+ /* @__PURE__ */ jsx41(
7038
+ "div",
7039
+ {
7040
+ className: "flex h-5 w-5 items-center justify-center rounded text-xs font-bold",
7041
+ style: {
7042
+ backgroundColor: resolved.solid,
7043
+ color: resolved.foreground
7044
+ },
7045
+ children: "T"
7046
+ }
7047
+ ),
7048
+ /* @__PURE__ */ jsx41("span", { className: "flex-1 text-sm", children: c.name }),
7049
+ selected && /* @__PURE__ */ jsx41(LuCheck2, { className: "text-primary-600 h-4 w-4" })
7050
+ ] })
7051
+ };
7052
+ }),
7053
+ [isDark]
7054
+ );
7055
+ return /* @__PURE__ */ jsx41(
7056
+ BaseDialog2,
7057
+ {
7058
+ title: "Edit Group",
7059
+ open,
7060
+ onClose,
7061
+ cancelText: "Cancel",
7062
+ onCancel: onClose,
7063
+ onOk,
7064
+ okText: "Save",
7065
+ panelClassName: "sm:max-w-xl",
7066
+ initialFocus: titleRef,
7067
+ children: /* @__PURE__ */ jsxs31("div", { className: "text-text-foreground px-4 pb-2 pt-4", children: [
7068
+ /* @__PURE__ */ jsx41("h4", { className: "text-text-foreground mb-3 text-sm font-semibold", children: "Display options" }),
7069
+ /* @__PURE__ */ jsx41("label", { className: "text-text-foreground-secondary text-ilabel mb-1 block", children: "Title" }),
7070
+ /* @__PURE__ */ jsx41(
7071
+ "input",
7072
+ {
7073
+ ref: titleRef,
7074
+ type: "text",
7075
+ value: draftTitle,
7076
+ onChange: (e) => setDraftTitle(e.target.value),
7077
+ onKeyDown: (e) => {
7078
+ if (e.key === "Enter") {
7079
+ e.preventDefault();
7080
+ onOk();
7081
+ }
7082
+ },
7083
+ 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"
7084
+ }
7085
+ ),
7086
+ /* @__PURE__ */ jsxs31("div", { className: "mb-4 grid grid-cols-2 gap-3", children: [
7087
+ /* @__PURE__ */ jsx41(
7088
+ StyleCard,
7089
+ {
7090
+ selected: draftStyle === "DEFAULT",
7091
+ label: "Default",
7092
+ onClick: () => onPickStyle("DEFAULT"),
7093
+ preview: /* @__PURE__ */ jsx41(DefaultPreview, {})
7094
+ }
7095
+ ),
7096
+ /* @__PURE__ */ jsx41(
7097
+ StyleCard,
7098
+ {
7099
+ selected: draftStyle === "EMPHASIS",
7100
+ label: "Emphasis",
7101
+ onClick: () => onPickStyle("EMPHASIS"),
7102
+ preview: /* @__PURE__ */ jsx41(EmphasisPreview, { color: previewColor })
7103
+ }
7104
+ )
7105
+ ] }),
7106
+ draftStyle !== "DEFAULT" && /* @__PURE__ */ jsxs31(Fragment10, { children: [
7107
+ /* @__PURE__ */ jsx41("label", { className: "text-text-foreground-secondary text-ilabel mb-1 block", children: "Highlight Color" }),
7108
+ /* @__PURE__ */ jsx41(
7109
+ Select2,
7110
+ {
7111
+ value: draftColor || DEFAULT_HIGHLIGHT_KEY,
7112
+ onChange: (v) => setDraftColor(v),
7113
+ options: colorOptions,
7114
+ size: "md",
7115
+ asLayer: true
7116
+ }
7117
+ )
7118
+ ] })
7119
+ ] })
7120
+ }
7121
+ );
7122
+ }
6790
7123
  export {
6791
7124
  AggregateInput,
6792
7125
  AreaIcon_default as AreaIcon,
@@ -6799,13 +7132,17 @@ export {
6799
7132
  ChartLegend,
6800
7133
  ChartTooltip,
6801
7134
  ChartTypeButtonGroup,
7135
+ DEFAULT_HIGHLIGHT_KEY,
6802
7136
  DataControls,
7137
+ EditDashboardDialog,
7138
+ EditGroupDialog,
6803
7139
  EventsFunctionCategories,
6804
7140
  EventsFunctionMap,
6805
7141
  FunctionInput,
6806
7142
  FunctionMap,
6807
7143
  FunctionsCategories,
6808
7144
  FunctionsPanel,
7145
+ HIGHLIGHT_COLORS,
6809
7146
  LabelControls,
6810
7147
  LabelSearchProvider,
6811
7148
  LabelsInput,
@@ -6841,7 +7178,10 @@ export {
6841
7178
  defaultConfig3 as defaultValueConfig,
6842
7179
  defaultConfig4 as defaultValueControlsConfig,
6843
7180
  getDefaultValueConfig,
7181
+ getHighlightHex,
6844
7182
  isAggrOrRollupFunction,
7183
+ resolveHeaderStyle,
7184
+ resolveHighlight,
6845
7185
  sentioColors,
6846
7186
  sentioTheme,
6847
7187
  sentioThemeDark,