@sentio/ui-dashboard 0.3.6 → 0.3.7

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
@@ -7120,6 +7120,227 @@ function EditGroupDialog({
7120
7120
  }
7121
7121
  );
7122
7122
  }
7123
+
7124
+ // src/dashboard/DashboardRefresh.tsx
7125
+ import dayjs6 from "dayjs";
7126
+ import relativeTime from "dayjs/plugin/relativeTime";
7127
+ import updateLocale from "dayjs/plugin/updateLocale";
7128
+ import { classNames as classNames13 } from "@sentio/ui-core";
7129
+ import { useCallback as useCallback7, useEffect as useEffect12, useRef as useRef7, useState as useState13 } from "react";
7130
+ import { IoMdRefresh as IoMdRefresh2 } from "react-icons/io";
7131
+ import dayjsEn from "dayjs/locale/en";
7132
+ import { jsx as jsx42, jsxs as jsxs32 } from "react/jsx-runtime";
7133
+ dayjs6.extend(relativeTime);
7134
+ dayjs6.extend(updateLocale);
7135
+ dayjs6.locale("en.short", {
7136
+ ...dayjsEn,
7137
+ relativeTime: {
7138
+ // relative time format strings, keep %s %d as the same
7139
+ future: "in %s",
7140
+ past: "%s ago",
7141
+ s: "<1s",
7142
+ m: "1min",
7143
+ mm: "%dmin",
7144
+ h: "1h",
7145
+ hh: "%dh",
7146
+ d: "1d",
7147
+ dd: "%dd",
7148
+ M: "1m",
7149
+ MM: "%dm",
7150
+ y: "1y",
7151
+ yy: "%dy"
7152
+ }
7153
+ });
7154
+ dayjs6.locale("en");
7155
+ var DashboardRefresh = ({ stats, onRefresh }) => {
7156
+ const timeRef = useRef7(null);
7157
+ const [fetching, setFetching] = useState13(false);
7158
+ const [currentColor, setCurrentColor] = useState13("text-[#4CAF1D] border-[#4CAF1D] border" /* NORMAL */);
7159
+ useEffect12(() => {
7160
+ const updateFn = () => {
7161
+ if (!stats || !stats.computedAt) return;
7162
+ const computedAt = dayjs6(stats.computedAt).locale("en.short");
7163
+ timeRef.current.textContent = computedAt.fromNow(true);
7164
+ if (computedAt.isBefore(dayjs6().subtract(1, "hour"))) {
7165
+ setCurrentColor("text-[#D98200] border-[#D98200] border" /* WARNNING */);
7166
+ } else {
7167
+ setCurrentColor("text-[#4CAF1D] border-[#4CAF1D] border" /* NORMAL */);
7168
+ }
7169
+ };
7170
+ updateFn();
7171
+ const interval = setInterval(() => {
7172
+ updateFn();
7173
+ }, 1e3);
7174
+ return () => {
7175
+ clearInterval(interval);
7176
+ };
7177
+ }, [stats]);
7178
+ const onClick = useCallback7(() => {
7179
+ setFetching((prevState) => {
7180
+ if (prevState) return prevState;
7181
+ onRefresh().finally(() => {
7182
+ setFetching(false);
7183
+ });
7184
+ return true;
7185
+ });
7186
+ }, [onRefresh]);
7187
+ useEffect12(() => {
7188
+ if (typeof window == "object") {
7189
+ window.addEventListener("refresh_all", onClick);
7190
+ return () => {
7191
+ window.removeEventListener("refresh_all", onClick);
7192
+ };
7193
+ }
7194
+ }, []);
7195
+ const showReload = fetching || stats?.isRefreshing;
7196
+ return /* @__PURE__ */ jsxs32(
7197
+ "div",
7198
+ {
7199
+ className: classNames13(
7200
+ "group/refresh relative ml-1 flex items-center gap-1 rounded-sm py-px pl-1 text-xs transition-all",
7201
+ currentColor,
7202
+ showReload ? "pr-5" : "pr-1.5 hover:pr-5"
7203
+ ),
7204
+ children: [
7205
+ /* @__PURE__ */ jsx42("span", { className: "cursor-default text-[10px]", ref: timeRef }),
7206
+ /* @__PURE__ */ jsx42(
7207
+ "button",
7208
+ {
7209
+ onClick,
7210
+ className: classNames13(
7211
+ "absolute right-1",
7212
+ showReload ? "block" : "hidden group-hover/refresh:block"
7213
+ ),
7214
+ children: /* @__PURE__ */ jsx42(
7215
+ IoMdRefresh2,
7216
+ {
7217
+ className: classNames13(
7218
+ "h-3.5 w-3.5",
7219
+ showReload ? "animate-spin" : ""
7220
+ )
7221
+ }
7222
+ )
7223
+ }
7224
+ )
7225
+ ]
7226
+ }
7227
+ );
7228
+ };
7229
+
7230
+ // src/dashboard/ShareDashboardDialog.tsx
7231
+ import { useMemo as useMemo14, useState as useState14 } from "react";
7232
+ import {
7233
+ BaseDialog as BaseDialog3,
7234
+ CopyButton as CopyButton3,
7235
+ Checkbox as Checkbox6,
7236
+ dateTimeToString as dateTimeToString2
7237
+ } from "@sentio/ui-core";
7238
+ import { jsx as jsx43, jsxs as jsxs33 } from "react/jsx-runtime";
7239
+ var ShareDashboardDialog = ({
7240
+ open,
7241
+ initData,
7242
+ onUnshare,
7243
+ onClose,
7244
+ onConfigChange,
7245
+ startTime,
7246
+ endTime,
7247
+ tz
7248
+ }) => {
7249
+ const [isReadonly, setIsReadonly] = useState14(
7250
+ initData?.config?.isReadonly ?? false
7251
+ );
7252
+ const [hideModifiers, setHideModifiers] = useState14(
7253
+ initData?.config?.hideModifiers ?? false
7254
+ );
7255
+ const linkText = useMemo14(() => {
7256
+ if (initData?.id) {
7257
+ let timeSuffix = startTime && endTime ? `?from=${encodeURIComponent(dateTimeToString2(startTime))}&to=${encodeURIComponent(dateTimeToString2(endTime))}&tz=${tz}` : "";
7258
+ if (tz) {
7259
+ timeSuffix += `&tz=${tz}`;
7260
+ }
7261
+ return `${location.origin}/share/${initData?.id}${timeSuffix}`;
7262
+ }
7263
+ return "";
7264
+ }, [initData?.id, startTime, endTime]);
7265
+ const handleConfigChange = (newIsReadonly, newHideModifiers) => {
7266
+ const config = {
7267
+ isReadonly: newIsReadonly,
7268
+ hideModifiers: newHideModifiers
7269
+ };
7270
+ onConfigChange?.(config);
7271
+ };
7272
+ const handleReadonlyChange = (checked) => {
7273
+ setIsReadonly(checked);
7274
+ handleConfigChange(checked, hideModifiers);
7275
+ };
7276
+ const handleHideModifiersChange = (checked) => {
7277
+ setHideModifiers(checked);
7278
+ handleConfigChange(isReadonly, checked);
7279
+ };
7280
+ return /* @__PURE__ */ jsx43(
7281
+ BaseDialog3,
7282
+ {
7283
+ title: "Sharing: ON",
7284
+ open,
7285
+ onCancel: () => {
7286
+ onUnshare?.();
7287
+ onClose();
7288
+ },
7289
+ cancelText: "Revoke URL",
7290
+ cancelProps: {
7291
+ status: "danger"
7292
+ },
7293
+ okText: "Done",
7294
+ onOk: () => {
7295
+ onClose();
7296
+ },
7297
+ onClose,
7298
+ buttonsClassName: "justify-between",
7299
+ footerBorder: false,
7300
+ children: /* @__PURE__ */ jsxs33("div", { className: "mx-4 my-4", children: [
7301
+ /* @__PURE__ */ jsxs33("div", { className: "flex overflow-hidden rounded-md border pl-3", children: [
7302
+ /* @__PURE__ */ jsx43("span", { className: "text-ilabel font-ilabel text-text-foreground flex-1 grow truncate leading-8", children: linkText }),
7303
+ /* @__PURE__ */ jsx43("div", { className: "group cursor-pointer border-l bg-gray-200 px-2 py-1 hover:bg-gray-100", children: /* @__PURE__ */ jsx43(
7304
+ CopyButton3,
7305
+ {
7306
+ text: linkText,
7307
+ size: 18,
7308
+ className: "text-text-foreground group-hover:text-primary h-4 w-4 align-middle"
7309
+ }
7310
+ ) })
7311
+ ] }),
7312
+ /* @__PURE__ */ jsx43("div", { className: "text-text-foreground-secondary mt-2 text-[11px]", children: "Anyone with the link can access this dashboard. You can revoke the link at any time." }),
7313
+ /* @__PURE__ */ jsxs33("div", { className: "mt-4 space-y-3 border-t pt-4", children: [
7314
+ /* @__PURE__ */ jsx43("div", { className: "text-text-foreground text-sm font-medium", children: "Access Settings" }),
7315
+ /* @__PURE__ */ jsxs33("div", { className: "space-y-4", children: [
7316
+ /* @__PURE__ */ jsxs33("div", { children: [
7317
+ /* @__PURE__ */ jsx43(
7318
+ Checkbox6,
7319
+ {
7320
+ checked: isReadonly,
7321
+ onChange: handleReadonlyChange,
7322
+ label: "Panel read-only access"
7323
+ }
7324
+ ),
7325
+ /* @__PURE__ */ jsx43("div", { className: "text-text-foreground-secondary ml-6 text-xs", children: "Viewers can only view the dashboard without entering panel edit mode or copy configuration." })
7326
+ ] }),
7327
+ /* @__PURE__ */ jsxs33("div", { children: [
7328
+ /* @__PURE__ */ jsx43(
7329
+ Checkbox6,
7330
+ {
7331
+ checked: hideModifiers,
7332
+ onChange: handleHideModifiersChange,
7333
+ label: "Hide controls"
7334
+ }
7335
+ ),
7336
+ /* @__PURE__ */ jsx43("div", { className: "text-text-foreground-secondary ml-6 text-xs", children: "Hide panel creator and modifier for viewers" })
7337
+ ] })
7338
+ ] })
7339
+ ] })
7340
+ ] })
7341
+ }
7342
+ );
7343
+ };
7123
7344
  export {
7124
7345
  AggregateInput,
7125
7346
  AreaIcon_default as AreaIcon,
@@ -7133,6 +7354,7 @@ export {
7133
7354
  ChartTooltip,
7134
7355
  ChartTypeButtonGroup,
7135
7356
  DEFAULT_HIGHLIGHT_KEY,
7357
+ DashboardRefresh,
7136
7358
  DataControls,
7137
7359
  EditDashboardDialog,
7138
7360
  EditGroupDialog,
@@ -7160,6 +7382,7 @@ export {
7160
7382
  ScatterChartTooltip,
7161
7383
  ScatterControls,
7162
7384
  ScatterIcon_default as ScatterIcon,
7385
+ ShareDashboardDialog,
7163
7386
  SystemLabels,
7164
7387
  TableControls,
7165
7388
  TableIcon_default as TableIcon,