yamchart 0.4.9 → 0.4.11
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/{chunk-ZLFZUYVM.js → chunk-F6QAWPYU.js} +13 -2
- package/dist/chunk-F6QAWPYU.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/public/assets/{LoginPage-8kMwzXQY.js → LoginPage-CbdZWMo9.js} +1 -1
- package/dist/public/assets/{PublicViewer-CCd0694Q.js → PublicViewer-Bmou0C7a.js} +1 -1
- package/dist/public/assets/{SetupWizard-FRVXmmVV.js → SetupWizard-QKYmGhuZ.js} +1 -1
- package/dist/public/assets/{ShareManagement-WkjpLgIb.js → ShareManagement-DqAZn-XZ.js} +1 -1
- package/dist/public/assets/{UserManagement-Yir6iim5.js → UserManagement-CH3vPfqJ.js} +1 -1
- package/dist/public/assets/{index-BPNqaKrL.js → index-DfVKHqnj.js} +32 -32
- package/dist/public/assets/{index.es-CkGh6XRY.js → index.es-Czu18YDf.js} +1 -1
- package/dist/public/assets/{jspdf.es.min-BllGrT6z.js → jspdf.es.min-D-4pZi5g.js} +3 -3
- package/dist/public/index.html +1 -1
- package/dist/{update-ATYDSPT4.js → update-HCR6MYJX.js} +2 -2
- package/package.json +4 -4
- package/dist/chunk-ZLFZUYVM.js.map +0 -1
- /package/dist/{update-ATYDSPT4.js.map → update-HCR6MYJX.js.map} +0 -0
|
@@ -33,7 +33,7 @@ async function checkForUpdate(currentVersion, { skipCache = false } = {}) {
|
|
|
33
33
|
if (!cached) {
|
|
34
34
|
writeCache(latest);
|
|
35
35
|
}
|
|
36
|
-
if (latest !== currentVersion && latest
|
|
36
|
+
if (latest !== currentVersion && isNewerVersion(latest, currentVersion)) {
|
|
37
37
|
return { current: currentVersion, latest };
|
|
38
38
|
}
|
|
39
39
|
return null;
|
|
@@ -64,6 +64,17 @@ async function fetchReleaseNotes(version) {
|
|
|
64
64
|
}
|
|
65
65
|
return null;
|
|
66
66
|
}
|
|
67
|
+
function isNewerVersion(a, b) {
|
|
68
|
+
const pa = a.split(".").map(Number);
|
|
69
|
+
const pb = b.split(".").map(Number);
|
|
70
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
71
|
+
const na = pa[i] ?? 0;
|
|
72
|
+
const nb = pb[i] ?? 0;
|
|
73
|
+
if (na > nb) return true;
|
|
74
|
+
if (na < nb) return false;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
67
78
|
async function fetchLatestVersion() {
|
|
68
79
|
const controller = new AbortController();
|
|
69
80
|
const timeout = setTimeout(() => controller.abort(), 3e3);
|
|
@@ -86,4 +97,4 @@ export {
|
|
|
86
97
|
checkForUpdate,
|
|
87
98
|
fetchReleaseNotes
|
|
88
99
|
};
|
|
89
|
-
//# sourceMappingURL=chunk-
|
|
100
|
+
//# sourceMappingURL=chunk-F6QAWPYU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/update-check.ts"],"sourcesContent":["import { readFileSync, writeFileSync, mkdirSync } from 'fs';\nimport { join } from 'path';\nimport { homedir } from 'os';\n\nconst REGISTRY_URL = 'https://registry.npmjs.org/yamchart';\nconst GITHUB_RELEASES_URL = 'https://api.github.com/repos/simon-spenc/yamchart/releases/tags';\nconst CACHE_DIR = join(homedir(), '.yamchart');\nconst CACHE_FILE = join(CACHE_DIR, 'update-check.json');\nconst CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours\n\nexport interface UpdateCheckResult {\n current: string;\n latest: string;\n}\n\ninterface CachedCheck {\n latest: string;\n checkedAt: number;\n}\n\nfunction readCache(): CachedCheck | null {\n try {\n const raw = readFileSync(CACHE_FILE, 'utf-8');\n const data = JSON.parse(raw) as CachedCheck;\n if (Date.now() - data.checkedAt < CACHE_TTL_MS) {\n return data;\n }\n } catch {\n // Cache miss or corrupt — ignore\n }\n return null;\n}\n\nfunction writeCache(latest: string): void {\n try {\n mkdirSync(CACHE_DIR, { recursive: true });\n writeFileSync(CACHE_FILE, JSON.stringify({ latest, checkedAt: Date.now() }));\n } catch {\n // Non-critical — ignore write errors\n }\n}\n\nexport async function checkForUpdate(currentVersion: string, { skipCache = false } = {}): Promise<UpdateCheckResult | null> {\n try {\n // Check cache first (unless explicitly bypassed)\n const cached = skipCache ? null : readCache();\n const latest = cached?.latest ?? await fetchLatestVersion();\n if (!latest) return null;\n\n if (!cached) {\n writeCache(latest);\n }\n\n if (latest !== currentVersion && isNewerVersion(latest, currentVersion)) {\n return { current: currentVersion, latest };\n }\n\n return null;\n } catch {\n return null; // Silent fail — never block CLI on update check\n }\n}\n\nexport async function fetchReleaseNotes(version: string): Promise<string | null> {\n // Try with v prefix first (v0.4.0), then without (0.4.0)\n for (const tag of [`v${version}`, version]) {\n try {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), 3000);\n\n const response = await fetch(`${GITHUB_RELEASES_URL}/${tag}`, {\n signal: controller.signal,\n headers: {\n Accept: 'application/vnd.github.v3+json',\n 'User-Agent': 'yamchart-cli',\n },\n });\n clearTimeout(timeout);\n\n if (!response.ok) continue;\n\n const data = await response.json() as { body?: string | null };\n const body = data.body?.trim();\n return body || null;\n } catch {\n continue;\n }\n }\n return null;\n}\n\n/** Compare semver strings numerically (a > b). */\nfunction isNewerVersion(a: string, b: string): boolean {\n const pa = a.split('.').map(Number);\n const pb = b.split('.').map(Number);\n for (let i = 0; i < Math.max(pa.length, pb.length); i++) {\n const na = pa[i] ?? 0;\n const nb = pb[i] ?? 0;\n if (na > nb) return true;\n if (na < nb) return false;\n }\n return false;\n}\n\nasync function fetchLatestVersion(): Promise<string | null> {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), 3000); // 3s timeout\n\n try {\n const response = await fetch(REGISTRY_URL, {\n signal: controller.signal,\n headers: { Accept: 'application/vnd.npm.install-v1+json' },\n });\n clearTimeout(timeout);\n\n if (!response.ok) return null;\n\n const data = await response.json() as { 'dist-tags'?: { latest?: string } };\n return data['dist-tags']?.latest ?? null;\n } catch {\n clearTimeout(timeout);\n return null;\n }\n}\n"],"mappings":";AAAA,SAAS,cAAc,eAAe,iBAAiB;AACvD,SAAS,YAAY;AACrB,SAAS,eAAe;AAExB,IAAM,eAAe;AACrB,IAAM,sBAAsB;AAC5B,IAAM,YAAY,KAAK,QAAQ,GAAG,WAAW;AAC7C,IAAM,aAAa,KAAK,WAAW,mBAAmB;AACtD,IAAM,eAAe,KAAK,KAAK,KAAK;AAYpC,SAAS,YAAgC;AACvC,MAAI;AACF,UAAM,MAAM,aAAa,YAAY,OAAO;AAC5C,UAAM,OAAO,KAAK,MAAM,GAAG;AAC3B,QAAI,KAAK,IAAI,IAAI,KAAK,YAAY,cAAc;AAC9C,aAAO;AAAA,IACT;AAAA,EACF,QAAQ;AAAA,EAER;AACA,SAAO;AACT;AAEA,SAAS,WAAW,QAAsB;AACxC,MAAI;AACF,cAAU,WAAW,EAAE,WAAW,KAAK,CAAC;AACxC,kBAAc,YAAY,KAAK,UAAU,EAAE,QAAQ,WAAW,KAAK,IAAI,EAAE,CAAC,CAAC;AAAA,EAC7E,QAAQ;AAAA,EAER;AACF;AAEA,eAAsB,eAAe,gBAAwB,EAAE,YAAY,MAAM,IAAI,CAAC,GAAsC;AAC1H,MAAI;AAEF,UAAM,SAAS,YAAY,OAAO,UAAU;AAC5C,UAAM,SAAS,QAAQ,UAAU,MAAM,mBAAmB;AAC1D,QAAI,CAAC,OAAQ,QAAO;AAEpB,QAAI,CAAC,QAAQ;AACX,iBAAW,MAAM;AAAA,IACnB;AAEA,QAAI,WAAW,kBAAkB,eAAe,QAAQ,cAAc,GAAG;AACvE,aAAO,EAAE,SAAS,gBAAgB,OAAO;AAAA,IAC3C;AAEA,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,eAAsB,kBAAkB,SAAyC;AAE/E,aAAW,OAAO,CAAC,IAAI,OAAO,IAAI,OAAO,GAAG;AAC1C,QAAI;AACF,YAAM,aAAa,IAAI,gBAAgB;AACvC,YAAM,UAAU,WAAW,MAAM,WAAW,MAAM,GAAG,GAAI;AAEzD,YAAM,WAAW,MAAM,MAAM,GAAG,mBAAmB,IAAI,GAAG,IAAI;AAAA,QAC5D,QAAQ,WAAW;AAAA,QACnB,SAAS;AAAA,UACP,QAAQ;AAAA,UACR,cAAc;AAAA,QAChB;AAAA,MACF,CAAC;AACD,mBAAa,OAAO;AAEpB,UAAI,CAAC,SAAS,GAAI;AAElB,YAAM,OAAO,MAAM,SAAS,KAAK;AACjC,YAAM,OAAO,KAAK,MAAM,KAAK;AAC7B,aAAO,QAAQ;AAAA,IACjB,QAAQ;AACN;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAGA,SAAS,eAAe,GAAW,GAAoB;AACrD,QAAM,KAAK,EAAE,MAAM,GAAG,EAAE,IAAI,MAAM;AAClC,QAAM,KAAK,EAAE,MAAM,GAAG,EAAE,IAAI,MAAM;AAClC,WAAS,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK;AACvD,UAAM,KAAK,GAAG,CAAC,KAAK;AACpB,UAAM,KAAK,GAAG,CAAC,KAAK;AACpB,QAAI,KAAK,GAAI,QAAO;AACpB,QAAI,KAAK,GAAI,QAAO;AAAA,EACtB;AACA,SAAO;AACT;AAEA,eAAe,qBAA6C;AAC1D,QAAM,aAAa,IAAI,gBAAgB;AACvC,QAAM,UAAU,WAAW,MAAM,WAAW,MAAM,GAAG,GAAI;AAEzD,MAAI;AACF,UAAM,WAAW,MAAM,MAAM,cAAc;AAAA,MACzC,QAAQ,WAAW;AAAA,MACnB,SAAS,EAAE,QAAQ,sCAAsC;AAAA,IAC3D,CAAC;AACD,iBAAa,OAAO;AAEpB,QAAI,CAAC,SAAS,GAAI,QAAO;AAEzB,UAAM,OAAO,MAAM,SAAS,KAAK;AACjC,WAAO,KAAK,WAAW,GAAG,UAAU;AAAA,EACtC,QAAQ;AACN,iBAAa,OAAO;AACpB,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
checkForUpdate
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-F6QAWPYU.js";
|
|
5
5
|
import {
|
|
6
6
|
findProjectRoot,
|
|
7
7
|
loadEnvFile,
|
|
@@ -218,7 +218,7 @@ program.command("test").description("Run model tests (@returns schema checks and
|
|
|
218
218
|
}
|
|
219
219
|
});
|
|
220
220
|
program.command("update").description("Check for yamchart updates").action(async () => {
|
|
221
|
-
const { runUpdate } = await import("./update-
|
|
221
|
+
const { runUpdate } = await import("./update-HCR6MYJX.js");
|
|
222
222
|
await runUpdate(pkg.version);
|
|
223
223
|
});
|
|
224
224
|
program.command("reset-password").description("Reset a user password (requires auth to be enabled)").requiredOption("-e, --email <email>", "Email address of the user").action(async (options) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as m,j as e,A as f}from"./index-
|
|
1
|
+
import{u as m,j as e,A as f}from"./index-DfVKHqnj.js";import{a as r}from"./echarts-DtOYsfLX.js";const p="",y={google:"Google",microsoft:"Microsoft",oidc:"SSO"};function v(){const u=m(s=>s.login),a=m(s=>s.providers),[o,x]=r.useState(""),[l,h]=r.useState(""),[i,t]=r.useState(""),[n,d]=r.useState(!1);r.useEffect(()=>{window.location.hash.includes("error=account_conflict")&&(t("An account with this email already exists. Please sign in with your password."),window.location.hash="#/")},[]);const b=async s=>{s.preventDefault(),t(""),d(!0);try{await u(o,l)}catch(c){c instanceof f?t(c.message):t("An unexpected error occurred")}finally{d(!1)}},g=s=>{window.location.href=`${p}/api/auth/sso/${s}`};return e.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-8 w-full max-w-md",children:[e.jsx("h1",{className:"text-2xl font-semibold text-gray-900 mb-2",children:"Sign in to Yamchart"}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:"Enter your credentials to access dashboards."}),i&&e.jsx("div",{className:"bg-red-50 border border-red-200 text-red-700 text-sm rounded-md px-4 py-3 mb-4",children:i}),a.length>0&&e.jsxs("div",{className:"space-y-2 mb-6",children:[a.map(s=>e.jsxs("button",{onClick:()=>g(s),className:"w-full py-2 px-4 border border-gray-300 text-gray-700 text-sm font-medium rounded-md hover:bg-gray-50",children:["Sign in with ",y[s]??s]},s)),e.jsxs("div",{className:"relative my-4",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t border-gray-200"})}),e.jsx("div",{className:"relative flex justify-center text-xs text-gray-400",children:e.jsx("span",{className:"bg-white px-2",children:"or"})})]})]}),e.jsxs("form",{onSubmit:b,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium text-gray-700 mb-1",children:"Email"}),e.jsx("input",{id:"email",type:"email",value:o,onChange:s=>x(s.target.value),required:!0,className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"you@example.com"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"password",className:"block text-sm font-medium text-gray-700 mb-1",children:"Password"}),e.jsx("input",{id:"password",type:"password",value:l,onChange:s=>h(s.target.value),required:!0,className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"Password"})]}),e.jsx("button",{type:"submit",disabled:n,className:"w-full py-2 px-4 bg-blue-600 text-white text-sm font-medium rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",children:n?"Signing in...":"Sign in"})]})]})})}export{v as LoginPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as t,c as S,b as U,d as I,e as Y,f as q,g as H,F as z,S as G,D as K,C as X,T as Q,G as J,W as Z,h as ee,H as te,i as re,k as se,l as ae,P as ne,m as ie,B as le,L as ce,a as oe,n as de}from"./index-BPNqaKrL.js";import{a as f}from"./echarts-DtOYsfLX.js";function xe({title:s,description:n,loading:e=!1,error:l=null,cached:a,durationMs:i,hasDrillDown:D,onRefresh:r,children:h}){return t.jsxs("div",{className:"chart-container",children:[t.jsxs("div",{className:"flex items-start justify-between p-4 border-b border-gray-100",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:s}),D&&t.jsxs("svg",{className:"w-4 h-4 text-gray-400 flex-shrink-0",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:[t.jsx("title",{children:"Right-click to drill down"}),t.jsx("path",{fillRule:"evenodd",d:"M5.22 14.78a.75.75 0 001.06 0l7.22-7.22v5.69a.75.75 0 001.5 0v-7.5a.75.75 0 00-.75-.75h-7.5a.75.75 0 000 1.5h5.69l-7.22 7.22a.75.75 0 000 1.06z",clipRule:"evenodd"})]})]}),n&&t.jsx("p",{className:"text-sm text-gray-500 mt-1",children:n})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[a!==void 0&&t.jsx("span",{className:S("text-xs px-2 py-1 rounded",a?"bg-green-100 text-green-700":"bg-blue-100 text-blue-700"),children:a?"Cached":"Fresh"}),i!==void 0&&t.jsxs("span",{className:"text-xs text-gray-400",children:[i,"ms"]}),r&&t.jsx("button",{onClick:r,disabled:e,className:"p-1.5 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded transition-colors disabled:opacity-50",title:"Refresh",children:t.jsx("svg",{className:S("w-4 h-4",e&&"animate-spin"),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})})]})]}),t.jsx("div",{className:"p-4",children:l?t.jsx("div",{className:"flex items-center justify-center h-64 text-red-500",children:t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"font-medium",children:"Failed to load chart"}),t.jsx("p",{className:"text-sm mt-1",children:l.message})]})}):h})]})}const he={day:{label:"Date",format:"%b %d, %Y"},week:{label:"Week Starting",format:"%b %d"},month:{label:"Month",format:"%b '%y"},quarter:{label:"Quarter",format:"quarter"},year:{label:"Year",format:"%Y"}};function me({chartName:s}){const[n,e]=f.useState(!1),l=async()=>{const a=`{{${s}}}`;try{await navigator.clipboard.writeText(a),e(!0),setTimeout(()=>e(!1),2e3)}catch(i){console.error("Failed to copy:",i)}};return t.jsx("button",{onClick:l,className:"text-sm text-gray-500 hover:text-gray-700 flex items-center gap-1.5 px-2 py-1 rounded hover:bg-gray-100 transition-colors",title:`Copy {{${s}}} for use in markdown widgets`,children:n?t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-4 h-4 text-green-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),t.jsx("span",{className:"text-green-600",children:"Copied!"})]}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})}),t.jsx("span",{children:"Copy Reference"})]})})}function M(s,n){if(!n)return s.toLocaleString();const e=n.decimals??0;switch(n.type){case"currency":return new Intl.NumberFormat("en-US",{style:"currency",currency:n.currency||"USD",minimumFractionDigits:e,maximumFractionDigits:e}).format(s);case"percent":return new Intl.NumberFormat("en-US",{style:"percent",minimumFractionDigits:e,maximumFractionDigits:e}).format(s/100);default:return s.toLocaleString(void 0,{minimumFractionDigits:e,maximumFractionDigits:e})}}function ue(s,n){const e=s>=0?"+":"";return n==="percent_change"?`${e}${s.toFixed(1)}%`:`${e}${s.toLocaleString()}`}function fe({data:s,config:n,title:e,comparison:l}){var p,b,w;if(!(s!=null&&s[0])||!((p=n.value)!=null&&p.field))return t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-400",children:"No data available"});const a=s[0],i=a[n.value.field],D=M(i,n.format);let r=null,h="percent_change",C,k,g;if(l)r=l.change,h=l.changeType,C=l.currentPeriodLabel,k=l.previousPeriodLabel,g=M(l.previousValue,n.format);else if((b=n.comparison)!=null&&b.enabled&&n.comparison.field){const o=a[n.comparison.field];h=n.comparison.type,o&&o!==0&&(h==="percent_change"?r=(i-o)/o*100:r=i-o,g=M(o,n.format))}return t.jsxs("div",{className:"h-80 flex flex-col items-center justify-center p-8",children:[t.jsxs("div",{className:"text-6xl font-bold text-gray-900 tabular-nums",children:[D,n.unit&&t.jsx("span",{className:"text-3xl font-normal text-gray-400 ml-2",children:n.unit})]}),C&&t.jsx("div",{className:"text-sm text-gray-400 mt-2",children:C}),e&&t.jsx("div",{className:"text-lg text-gray-500 mt-3",children:e}),r!==null&&t.jsxs("div",{className:"mt-4 flex flex-col items-center gap-1",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:S("text-lg font-medium px-3 py-1 rounded",r>=0?"bg-green-100 text-green-700":"bg-red-100 text-red-700"),children:ue(r,h)}),g&&t.jsxs("span",{className:"text-sm text-gray-400",children:["vs ",g]}),!g&&((w=n.comparison)==null?void 0:w.label)&&t.jsx("span",{className:"text-sm text-gray-400",children:n.comparison.label})]}),k&&t.jsx("div",{className:"text-xs text-gray-400",children:k})]})]})}function ge({chartName:s,drillParams:n}){var V,$,B,R;const{data:e,isLoading:l}=U(s),{data:a,isLoading:i,error:D}=I(s),{data:r}=Y(),h=q(),C=H(c=>c.getEffectiveFilters),k=H(c=>c.setChartFilter),g=l||i,p=n==null?void 0:n._from,b=n?Object.fromEntries(Object.entries(n).filter(([c])=>!c.startsWith("_"))):{},w=Object.keys(b).length>0,o=Object.entries(b).map(([c,x])=>`${c}: ${x}`).join(", ");f.useEffect(()=>{if(w)for(const[c,x]of Object.entries(b))k(s,c,x)},[s,w]);const[y,A]=f.useState(null),N=f.useCallback((c,x,m)=>{var u;(u=e==null?void 0:e.drillDown)!=null&&u.chart&&A({x:m.x,y:m.y,field:c,value:x})},[(V=e==null?void 0:e.drillDown)==null?void 0:V.chart]),O=f.useCallback(()=>{var m,u;if(!y||!((m=e==null?void 0:e.drillDown)!=null&&m.chart))return;const c=e.drillDown.field??((u=e.chart.x)==null?void 0:u.field)??y.field,x=new URLSearchParams({[c]:y.value,_from:s});window.location.hash=`/charts/${e.drillDown.chart}?${x.toString()}`,A(null)},[y,e,s]),T=C(s).granularity,d=T?he[T]:void 0,F=d==null?void 0:d.label,L=d==null?void 0:d.format;if(l)return t.jsxs("div",{className:"chart-container animate-pulse",children:[t.jsx("div",{className:"p-4 border-b border-gray-100",children:t.jsx("div",{className:"h-6 bg-gray-200 rounded w-48"})}),t.jsx("div",{className:"p-4",children:t.jsx("div",{className:"h-80 bg-gray-100 rounded"})})]});if(!e)return t.jsxs("div",{className:"chart-container p-8 text-center text-gray-500",children:["Chart not found: ",s]});const P=()=>{var x,m,u,E,W,_;if(!a)return t.jsx("div",{className:"h-80 bg-gray-50 rounded animate-pulse"});const c=e.chart.type;switch(c){case"line":if(!e.chart.x||!e.chart.y&&!e.chart.series)return t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,v=(x=e.drillDown)!=null&&x.chart?N:void 0;return t.jsx(ce,{data:a.rows,columns:a.columns,xAxis:j,yAxis:e.chart.y,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i,onDrillDown:v})}case"bar":if(!e.chart.x||!e.chart.y&&!e.chart.series)return t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,v=(m=e.drillDown)!=null&&m.chart?N:void 0;return t.jsx(le,{data:a.rows,xAxis:j,yAxis:e.chart.y,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i,onDrillDown:v})}case"area":if(!e.chart.x||!e.chart.y&&!e.chart.series)return t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,v=(u=e.drillDown)!=null&&u.chart?N:void 0;return t.jsx(ie,{data:a.rows,xAxis:j,yAxis:e.chart.y,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i,onDrillDown:v})}case"pie":return!e.chart.x||!e.chart.y?t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing pie chart configuration"}):t.jsx(ne,{data:a.rows,xAxis:e.chart.x,yAxis:e.chart.y,theme:r==null?void 0:r.theme,loading:i,onDrillDown:(E=e.drillDown)!=null&&E.chart?N:void 0});case"donut":return!e.chart.x||!e.chart.y?t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing donut chart configuration"}):t.jsx(ae,{data:a.rows,xAxis:e.chart.x,yAxis:e.chart.y,centerValue:e.chart.centerValue,theme:r==null?void 0:r.theme,loading:i,onDrillDown:(W=e.drillDown)!=null&&W.chart?N:void 0});case"scatter":return!e.chart.x||!e.chart.y?t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing axis configuration"}):t.jsx(se,{data:a.rows,xAxis:e.chart.x,yAxis:e.chart.y,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i});case"combo":if(!e.chart.x)return t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,v=(_=e.drillDown)!=null&&_.chart?N:void 0;return t.jsx(re,{data:a.rows,xAxis:j,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i,onDrillDown:v})}case"kpi":return t.jsx(fe,{data:a.rows,config:e.chart,title:e.title,comparison:a.comparison});case"heatmap":return!e.chart.x||!e.chart.y?t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing axis configuration"}):t.jsx(te,{data:a.rows,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i});case"funnel":return t.jsx(ee,{data:a.rows,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i});case"waterfall":return t.jsx(Z,{data:a.rows,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i});case"gauge":return t.jsx(J,{data:a.rows,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i});case"table":return t.jsx(Q,{data:a.rows,columns:a.columns,height:"100%",loading:i});default:return t.jsxs("div",{className:"h-80 flex items-center justify-center text-gray-500",children:['Chart type "',c,'" not yet implemented']})}};return t.jsxs("div",{className:"space-y-4",children:[p&&t.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[t.jsx("button",{onClick:()=>{window.location.hash=`/charts/${p}`},className:"hover:text-blue-600 transition-colors",children:p}),t.jsx("span",{children:"/"}),t.jsx("span",{className:"text-gray-700 font-medium",children:e.title}),o&&t.jsxs("span",{className:"text-gray-400",children:["(",o,")"]})]}),t.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-4",children:[e.parameters.length>0?t.jsx(z,{parameters:e.parameters,chartName:s}):t.jsx("div",{}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(me,{chartName:s}),t.jsx(G,{resourceType:"chart",resourceName:s})]})]}),t.jsx(xe,{title:e.title,description:e.description,loading:g,error:D,cached:a==null?void 0:a.meta.cached,durationMs:a==null?void 0:a.meta.durationMs,hasDrillDown:!!(($=e.drillDown)!=null&&$.chart),onRefresh:()=>h(s),children:P()}),w&&a&&t.jsx(K,{data:a.rows,columns:a.columns,drillDownColumns:(B=e.drillDown)==null?void 0:B.columns,filterDisplay:o,chartName:s}),y&&((R=e.drillDown)==null?void 0:R.chart)&&t.jsx(X,{x:y.x,y:y.y,targetChartTitle:e.drillDown.chart,onDrillDown:O,onClose:()=>A(null)})]})}function pe({parsed:s}){const n=s.params.token,[e,l]=f.useState(null),[a,i]=f.useState(!1);return f.useEffect(()=>{if(!n){l("No share token provided");return}oe.getPublicConfig(n).then(()=>i(!0)).catch(()=>l("This link has expired or been revoked"))},[n]),e?t.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:t.jsx("div",{className:"text-center",children:t.jsx("div",{className:"text-gray-400 text-lg",children:e})})}):a?t.jsxs("div",{className:"min-h-screen bg-gray-50",children:[t.jsx("div",{className:"max-w-7xl mx-auto py-6 px-4",children:s.type==="public_chart"?t.jsx(ge,{chartName:s.name}):t.jsx(de,{dashboardId:s.name,initialTab:s.params.tab})}),t.jsx("div",{className:"text-center py-4 text-xs text-gray-400",children:"Shared via yamchart"})]}):t.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:t.jsx("div",{className:"text-gray-500",children:"Loading..."})})}export{pe as PublicViewer};
|
|
1
|
+
import{j as t,c as S,b as U,d as I,e as Y,f as q,g as H,F as z,S as G,D as K,C as X,T as Q,G as J,W as Z,h as ee,H as te,i as re,k as se,l as ae,P as ne,m as ie,B as le,L as ce,a as oe,n as de}from"./index-DfVKHqnj.js";import{a as f}from"./echarts-DtOYsfLX.js";function xe({title:s,description:n,loading:e=!1,error:l=null,cached:a,durationMs:i,hasDrillDown:D,onRefresh:r,children:h}){return t.jsxs("div",{className:"chart-container",children:[t.jsxs("div",{className:"flex items-start justify-between p-4 border-b border-gray-100",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:s}),D&&t.jsxs("svg",{className:"w-4 h-4 text-gray-400 flex-shrink-0",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:[t.jsx("title",{children:"Right-click to drill down"}),t.jsx("path",{fillRule:"evenodd",d:"M5.22 14.78a.75.75 0 001.06 0l7.22-7.22v5.69a.75.75 0 001.5 0v-7.5a.75.75 0 00-.75-.75h-7.5a.75.75 0 000 1.5h5.69l-7.22 7.22a.75.75 0 000 1.06z",clipRule:"evenodd"})]})]}),n&&t.jsx("p",{className:"text-sm text-gray-500 mt-1",children:n})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[a!==void 0&&t.jsx("span",{className:S("text-xs px-2 py-1 rounded",a?"bg-green-100 text-green-700":"bg-blue-100 text-blue-700"),children:a?"Cached":"Fresh"}),i!==void 0&&t.jsxs("span",{className:"text-xs text-gray-400",children:[i,"ms"]}),r&&t.jsx("button",{onClick:r,disabled:e,className:"p-1.5 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded transition-colors disabled:opacity-50",title:"Refresh",children:t.jsx("svg",{className:S("w-4 h-4",e&&"animate-spin"),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})})]})]}),t.jsx("div",{className:"p-4",children:l?t.jsx("div",{className:"flex items-center justify-center h-64 text-red-500",children:t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"font-medium",children:"Failed to load chart"}),t.jsx("p",{className:"text-sm mt-1",children:l.message})]})}):h})]})}const he={day:{label:"Date",format:"%b %d, %Y"},week:{label:"Week Starting",format:"%b %d"},month:{label:"Month",format:"%b '%y"},quarter:{label:"Quarter",format:"quarter"},year:{label:"Year",format:"%Y"}};function me({chartName:s}){const[n,e]=f.useState(!1),l=async()=>{const a=`{{${s}}}`;try{await navigator.clipboard.writeText(a),e(!0),setTimeout(()=>e(!1),2e3)}catch(i){console.error("Failed to copy:",i)}};return t.jsx("button",{onClick:l,className:"text-sm text-gray-500 hover:text-gray-700 flex items-center gap-1.5 px-2 py-1 rounded hover:bg-gray-100 transition-colors",title:`Copy {{${s}}} for use in markdown widgets`,children:n?t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-4 h-4 text-green-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),t.jsx("span",{className:"text-green-600",children:"Copied!"})]}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})}),t.jsx("span",{children:"Copy Reference"})]})})}function M(s,n){if(!n)return s.toLocaleString();const e=n.decimals??0;switch(n.type){case"currency":return new Intl.NumberFormat("en-US",{style:"currency",currency:n.currency||"USD",minimumFractionDigits:e,maximumFractionDigits:e}).format(s);case"percent":return new Intl.NumberFormat("en-US",{style:"percent",minimumFractionDigits:e,maximumFractionDigits:e}).format(s/100);default:return s.toLocaleString(void 0,{minimumFractionDigits:e,maximumFractionDigits:e})}}function ue(s,n){const e=s>=0?"+":"";return n==="percent_change"?`${e}${s.toFixed(1)}%`:`${e}${s.toLocaleString()}`}function fe({data:s,config:n,title:e,comparison:l}){var p,b,w;if(!(s!=null&&s[0])||!((p=n.value)!=null&&p.field))return t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-400",children:"No data available"});const a=s[0],i=a[n.value.field],D=M(i,n.format);let r=null,h="percent_change",C,k,g;if(l)r=l.change,h=l.changeType,C=l.currentPeriodLabel,k=l.previousPeriodLabel,g=M(l.previousValue,n.format);else if((b=n.comparison)!=null&&b.enabled&&n.comparison.field){const o=a[n.comparison.field];h=n.comparison.type,o&&o!==0&&(h==="percent_change"?r=(i-o)/o*100:r=i-o,g=M(o,n.format))}return t.jsxs("div",{className:"h-80 flex flex-col items-center justify-center p-8",children:[t.jsxs("div",{className:"text-6xl font-bold text-gray-900 tabular-nums",children:[D,n.unit&&t.jsx("span",{className:"text-3xl font-normal text-gray-400 ml-2",children:n.unit})]}),C&&t.jsx("div",{className:"text-sm text-gray-400 mt-2",children:C}),e&&t.jsx("div",{className:"text-lg text-gray-500 mt-3",children:e}),r!==null&&t.jsxs("div",{className:"mt-4 flex flex-col items-center gap-1",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:S("text-lg font-medium px-3 py-1 rounded",r>=0?"bg-green-100 text-green-700":"bg-red-100 text-red-700"),children:ue(r,h)}),g&&t.jsxs("span",{className:"text-sm text-gray-400",children:["vs ",g]}),!g&&((w=n.comparison)==null?void 0:w.label)&&t.jsx("span",{className:"text-sm text-gray-400",children:n.comparison.label})]}),k&&t.jsx("div",{className:"text-xs text-gray-400",children:k})]})]})}function ge({chartName:s,drillParams:n}){var V,$,B,R;const{data:e,isLoading:l}=U(s),{data:a,isLoading:i,error:D}=I(s),{data:r}=Y(),h=q(),C=H(c=>c.getEffectiveFilters),k=H(c=>c.setChartFilter),g=l||i,p=n==null?void 0:n._from,b=n?Object.fromEntries(Object.entries(n).filter(([c])=>!c.startsWith("_"))):{},w=Object.keys(b).length>0,o=Object.entries(b).map(([c,x])=>`${c}: ${x}`).join(", ");f.useEffect(()=>{if(w)for(const[c,x]of Object.entries(b))k(s,c,x)},[s,w]);const[y,A]=f.useState(null),N=f.useCallback((c,x,m)=>{var u;(u=e==null?void 0:e.drillDown)!=null&&u.chart&&A({x:m.x,y:m.y,field:c,value:x})},[(V=e==null?void 0:e.drillDown)==null?void 0:V.chart]),O=f.useCallback(()=>{var m,u;if(!y||!((m=e==null?void 0:e.drillDown)!=null&&m.chart))return;const c=e.drillDown.field??((u=e.chart.x)==null?void 0:u.field)??y.field,x=new URLSearchParams({[c]:y.value,_from:s});window.location.hash=`/charts/${e.drillDown.chart}?${x.toString()}`,A(null)},[y,e,s]),T=C(s).granularity,d=T?he[T]:void 0,F=d==null?void 0:d.label,L=d==null?void 0:d.format;if(l)return t.jsxs("div",{className:"chart-container animate-pulse",children:[t.jsx("div",{className:"p-4 border-b border-gray-100",children:t.jsx("div",{className:"h-6 bg-gray-200 rounded w-48"})}),t.jsx("div",{className:"p-4",children:t.jsx("div",{className:"h-80 bg-gray-100 rounded"})})]});if(!e)return t.jsxs("div",{className:"chart-container p-8 text-center text-gray-500",children:["Chart not found: ",s]});const P=()=>{var x,m,u,E,W,_;if(!a)return t.jsx("div",{className:"h-80 bg-gray-50 rounded animate-pulse"});const c=e.chart.type;switch(c){case"line":if(!e.chart.x||!e.chart.y&&!e.chart.series)return t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,v=(x=e.drillDown)!=null&&x.chart?N:void 0;return t.jsx(ce,{data:a.rows,columns:a.columns,xAxis:j,yAxis:e.chart.y,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i,onDrillDown:v})}case"bar":if(!e.chart.x||!e.chart.y&&!e.chart.series)return t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,v=(m=e.drillDown)!=null&&m.chart?N:void 0;return t.jsx(le,{data:a.rows,xAxis:j,yAxis:e.chart.y,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i,onDrillDown:v})}case"area":if(!e.chart.x||!e.chart.y&&!e.chart.series)return t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,v=(u=e.drillDown)!=null&&u.chart?N:void 0;return t.jsx(ie,{data:a.rows,xAxis:j,yAxis:e.chart.y,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i,onDrillDown:v})}case"pie":return!e.chart.x||!e.chart.y?t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing pie chart configuration"}):t.jsx(ne,{data:a.rows,xAxis:e.chart.x,yAxis:e.chart.y,theme:r==null?void 0:r.theme,loading:i,onDrillDown:(E=e.drillDown)!=null&&E.chart?N:void 0});case"donut":return!e.chart.x||!e.chart.y?t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing donut chart configuration"}):t.jsx(ae,{data:a.rows,xAxis:e.chart.x,yAxis:e.chart.y,centerValue:e.chart.centerValue,theme:r==null?void 0:r.theme,loading:i,onDrillDown:(W=e.drillDown)!=null&&W.chart?N:void 0});case"scatter":return!e.chart.x||!e.chart.y?t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing axis configuration"}):t.jsx(se,{data:a.rows,xAxis:e.chart.x,yAxis:e.chart.y,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i});case"combo":if(!e.chart.x)return t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,v=(_=e.drillDown)!=null&&_.chart?N:void 0;return t.jsx(re,{data:a.rows,xAxis:j,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i,onDrillDown:v})}case"kpi":return t.jsx(fe,{data:a.rows,config:e.chart,title:e.title,comparison:a.comparison});case"heatmap":return!e.chart.x||!e.chart.y?t.jsx("div",{className:"h-80 flex items-center justify-center text-gray-500",children:"Missing axis configuration"}):t.jsx(te,{data:a.rows,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i});case"funnel":return t.jsx(ee,{data:a.rows,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i});case"waterfall":return t.jsx(Z,{data:a.rows,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i});case"gauge":return t.jsx(J,{data:a.rows,chartConfig:e.chart,theme:r==null?void 0:r.theme,loading:i});case"table":return t.jsx(Q,{data:a.rows,columns:a.columns,height:"100%",loading:i});default:return t.jsxs("div",{className:"h-80 flex items-center justify-center text-gray-500",children:['Chart type "',c,'" not yet implemented']})}};return t.jsxs("div",{className:"space-y-4",children:[p&&t.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[t.jsx("button",{onClick:()=>{window.location.hash=`/charts/${p}`},className:"hover:text-blue-600 transition-colors",children:p}),t.jsx("span",{children:"/"}),t.jsx("span",{className:"text-gray-700 font-medium",children:e.title}),o&&t.jsxs("span",{className:"text-gray-400",children:["(",o,")"]})]}),t.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-4",children:[e.parameters.length>0?t.jsx(z,{parameters:e.parameters,chartName:s}):t.jsx("div",{}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(me,{chartName:s}),t.jsx(G,{resourceType:"chart",resourceName:s})]})]}),t.jsx(xe,{title:e.title,description:e.description,loading:g,error:D,cached:a==null?void 0:a.meta.cached,durationMs:a==null?void 0:a.meta.durationMs,hasDrillDown:!!(($=e.drillDown)!=null&&$.chart),onRefresh:()=>h(s),children:P()}),w&&a&&t.jsx(K,{data:a.rows,columns:a.columns,drillDownColumns:(B=e.drillDown)==null?void 0:B.columns,filterDisplay:o,chartName:s}),y&&((R=e.drillDown)==null?void 0:R.chart)&&t.jsx(X,{x:y.x,y:y.y,targetChartTitle:e.drillDown.chart,onDrillDown:O,onClose:()=>A(null)})]})}function pe({parsed:s}){const n=s.params.token,[e,l]=f.useState(null),[a,i]=f.useState(!1);return f.useEffect(()=>{if(!n){l("No share token provided");return}oe.getPublicConfig(n).then(()=>i(!0)).catch(()=>l("This link has expired or been revoked"))},[n]),e?t.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:t.jsx("div",{className:"text-center",children:t.jsx("div",{className:"text-gray-400 text-lg",children:e})})}):a?t.jsxs("div",{className:"min-h-screen bg-gray-50",children:[t.jsx("div",{className:"max-w-7xl mx-auto py-6 px-4",children:s.type==="public_chart"?t.jsx(ge,{chartName:s.name}):t.jsx(de,{dashboardId:s.name,initialTab:s.params.tab})}),t.jsx("div",{className:"text-center py-4 text-xs text-gray-400",children:"Shared via yamchart"})]}):t.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:t.jsx("div",{className:"text-gray-500",children:"Loading..."})})}export{pe as PublicViewer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as g,j as e,A as y}from"./index-
|
|
1
|
+
import{u as g,j as e,A as y}from"./index-DfVKHqnj.js";import{a as s}from"./echarts-DtOYsfLX.js";function N(){const c=g(r=>r.setup),[o,b]=s.useState(""),[l,x]=s.useState(""),[a,p]=s.useState(""),[d,f]=s.useState(""),[n,t]=s.useState(""),[u,m]=s.useState(!1),h=async r=>{if(r.preventDefault(),t(""),a!==d){t("Passwords do not match");return}if(a.length<8){t("Password must be at least 8 characters");return}m(!0);try{await c(o,l,a)}catch(i){i instanceof y?t(i.message):t("An unexpected error occurred")}finally{m(!1)}};return e.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-8 w-full max-w-md",children:[e.jsx("h1",{className:"text-2xl font-semibold text-gray-900 mb-2",children:"Welcome to Yamchart"}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:"Create your admin account to get started."}),n&&e.jsx("div",{className:"bg-red-50 border border-red-200 text-red-700 text-sm rounded-md px-4 py-3 mb-4",children:n}),e.jsxs("form",{onSubmit:h,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"name",className:"block text-sm font-medium text-gray-700 mb-1",children:"Name"}),e.jsx("input",{id:"name",type:"text",value:l,onChange:r=>x(r.target.value),required:!0,className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"Your Name"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"setup-email",className:"block text-sm font-medium text-gray-700 mb-1",children:"Email"}),e.jsx("input",{id:"setup-email",type:"email",value:o,onChange:r=>b(r.target.value),required:!0,className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"admin@example.com"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"setup-password",className:"block text-sm font-medium text-gray-700 mb-1",children:"Password"}),e.jsx("input",{id:"setup-password",type:"password",value:a,onChange:r=>p(r.target.value),required:!0,minLength:8,className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"At least 8 characters"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"confirm-password",className:"block text-sm font-medium text-gray-700 mb-1",children:"Confirm Password"}),e.jsx("input",{id:"confirm-password",type:"password",value:d,onChange:r=>f(r.target.value),required:!0,className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"Confirm password"})]}),e.jsx("button",{type:"submit",disabled:u,className:"w-full py-2 px-4 bg-blue-600 text-white text-sm font-medium rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",children:u?"Creating account...":"Create Admin Account"})]})]})})}export{N as SetupWizard};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,a as c}from"./index-
|
|
1
|
+
import{j as e,a as c}from"./index-DfVKHqnj.js";import{a as s}from"./echarts-DtOYsfLX.js";function p(){const[r,l]=s.useState([]),[d,i]=s.useState(!0),x=async()=>{try{const t=await c.listShareLinks();l(t.links)}catch(t){console.error("Failed to load share links:",t)}finally{i(!1)}};s.useEffect(()=>{x()},[]);const n=async t=>{try{await c.revokeShareLink(t),l(a=>a.filter(o=>o.id!==t))}catch(a){console.error("Failed to revoke share link:",a)}};return d?e.jsx("div",{className:"p-6 text-gray-500",children:"Loading..."}):e.jsxs("div",{className:"p-6 max-w-4xl",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Shared Links"}),r.length===0?e.jsx("p",{className:"text-gray-500 text-sm",children:"No active share links."}):e.jsx("div",{className:"border border-gray-200 rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50 border-b border-gray-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-4 py-2 font-medium text-gray-600",children:"Resource"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium text-gray-600",children:"Type"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium text-gray-600",children:"Created"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium text-gray-600",children:"Expires"}),e.jsx("th",{className:"px-4 py-2"})]})}),e.jsx("tbody",{children:r.map(t=>e.jsxs("tr",{className:"border-b border-gray-100 last:border-0",children:[e.jsx("td",{className:"px-4 py-3 font-medium text-gray-900",children:t.resource_name}),e.jsx("td",{className:"px-4 py-3 text-gray-600 capitalize",children:t.resource_type}),e.jsx("td",{className:"px-4 py-3 text-gray-500",children:new Date(t.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-4 py-3 text-gray-500",children:t.expires_at?new Date(t.expires_at).toLocaleDateString():"Never"}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsx("button",{onClick:()=>n(t.id),className:"text-red-600 hover:text-red-700 text-sm",children:"Revoke"})})]},t.id))})]})})]})}export{p as ShareManagement};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,a as p,A as v}from"./index-
|
|
1
|
+
import{j as e,a as p,A as v}from"./index-DfVKHqnj.js";import{a as r}from"./echarts-DtOYsfLX.js";function O(){var k;const[c,N]=r.useState([]),[b,w]=r.useState(!0),[g,y]=r.useState(!1),[x,A]=r.useState(""),[n,f]=r.useState(null),[u,d]=r.useState([]),[m,h]=r.useState(!1),o=async()=>{try{const{users:t}=await p.authListUsers();N(t)}catch{A("Failed to load users")}finally{w(!1)}};r.useEffect(()=>{o()},[]);const l=async(t,s)=>{try{await p.authUpdateUser(t,{role:s}),await o()}catch(a){alert(a instanceof v?a.message:"Failed to update role")}},j=async(t,s)=>{if(confirm(`Delete user "${s}"? This cannot be undone.`))try{await p.authDeleteUser(t),await o()}catch(a){alert(a instanceof v?a.message:"Failed to delete user")}},U=t=>{if(n===t.id)f(null),d([]);else{f(t.id);const s=JSON.parse(t.attributes||"{}");d(Object.entries(s).map(([a,i])=>({key:a,value:i})))}},C=(t,s,a)=>{d(i=>i.map((S,M)=>M===t?{...S,[s]:a}:S))},E=()=>{d(t=>[...t,{key:"",value:""}])},L=t=>{d(s=>s.filter((a,i)=>i!==t))},D=async()=>{if(n){h(!0);try{const t={};for(const{key:s,value:a}of u){const i=s.trim();i&&(t[i]=a)}await p.authUpdateUser(n,{attributes:t}),await o(),d(Object.entries(t).map(([s,a])=>({key:s,value:a})))}catch(t){alert(t instanceof v?t.message:"Failed to save attributes")}finally{h(!1)}}};return b?e.jsx("div",{className:"p-6 text-gray-500",children:"Loading users..."}):e.jsxs("div",{className:"p-6 max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"User Management"}),e.jsx("button",{onClick:()=>y(!0),className:"px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-md hover:bg-blue-700",children:"Add User"})]}),x&&e.jsx("div",{className:"bg-red-50 border border-red-200 text-red-700 text-sm rounded-md px-4 py-3 mb-4",children:x}),e.jsx("div",{className:"bg-white border border-gray-200 rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-gray-50 border-b border-gray-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Name"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Email"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Role"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Created"}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-200",children:c.map(t=>e.jsxs("tr",{className:"group",children:[e.jsx("td",{className:"px-4 py-3 text-sm text-gray-900",children:t.name}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-500",children:t.email}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("select",{value:t.role,onChange:s=>l(t.id,s.target.value),className:"text-sm border border-gray-300 rounded px-2 py-1",children:[e.jsx("option",{value:"admin",children:"Admin"}),e.jsx("option",{value:"editor",children:"Editor"}),e.jsx("option",{value:"viewer",children:"Viewer"})]})}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-500",children:new Date(t.created_at).toLocaleDateString()}),e.jsxs("td",{className:"px-4 py-3 text-right space-x-3",children:[e.jsx("button",{onClick:()=>U(t),className:"text-sm text-blue-600 hover:text-blue-800",children:n===t.id?"Hide Attrs":"Attrs"}),e.jsx("button",{onClick:()=>j(t.id,t.name),className:"text-sm text-red-600 hover:text-red-800",children:"Delete"})]})]},t.id))})]})}),n&&e.jsxs("div",{className:"mt-4 bg-white border border-gray-200 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h3",{className:"text-sm font-medium text-gray-700",children:["Attributes for ",(k=c.find(t=>t.id===n))==null?void 0:k.name]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:E,className:"px-3 py-1 text-xs font-medium text-blue-600 border border-blue-300 rounded hover:bg-blue-50",children:"Add Attribute"}),e.jsx("button",{onClick:D,disabled:m,className:"px-3 py-1 text-xs font-medium text-white bg-blue-600 rounded hover:bg-blue-700 disabled:opacity-50",children:m?"Saving...":"Save"})]})]}),u.length===0?e.jsx("p",{className:"text-sm text-gray-400",children:'No attributes. Click "Add Attribute" to define key-value pairs for row-level security.'}):e.jsx("div",{className:"space-y-2",children:u.map((t,s)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",placeholder:"Key (e.g. department)",value:t.key,onChange:a=>C(s,"key",a.target.value),className:"flex-1 px-3 py-1.5 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"}),e.jsx("input",{type:"text",placeholder:"Value (e.g. Sales)",value:t.value,onChange:a=>C(s,"value",a.target.value),className:"flex-1 px-3 py-1.5 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"}),e.jsx("button",{onClick:()=>L(s),className:"p-1.5 text-gray-400 hover:text-red-500",title:"Remove attribute",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},s))})]}),g&&e.jsx(R,{onClose:()=>y(!1),onCreated:o})]})}function R({onClose:c,onCreated:N}){const[b,w]=r.useState(""),[g,y]=r.useState(""),[x,A]=r.useState(""),[n,f]=r.useState("viewer"),[u,d]=r.useState(""),[m,h]=r.useState(!1),o=async l=>{l.preventDefault(),d(""),h(!0);try{await p.authCreateUser({email:b,name:g,password:x,role:n}),N(),c()}catch(j){d(j instanceof v?j.message:"Failed to create user")}finally{h(!1)}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",onClick:c,children:e.jsxs("div",{className:"bg-white rounded-lg shadow-lg p-6 w-full max-w-md",onClick:l=>l.stopPropagation(),children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Add User"}),u&&e.jsx("div",{className:"bg-red-50 border border-red-200 text-red-700 text-sm rounded-md px-4 py-3 mb-4",children:u}),e.jsxs("form",{onSubmit:o,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Name"}),e.jsx("input",{type:"text",value:g,onChange:l=>y(l.target.value),required:!0,className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Email"}),e.jsx("input",{type:"email",value:b,onChange:l=>w(l.target.value),required:!0,className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Temporary Password"}),e.jsx("input",{type:"password",value:x,onChange:l=>A(l.target.value),required:!0,minLength:8,className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Role"}),e.jsxs("select",{value:n,onChange:l=>f(l.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"viewer",children:"Viewer"}),e.jsx("option",{value:"editor",children:"Editor"}),e.jsx("option",{value:"admin",children:"Admin"})]})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:c,className:"px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-md",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:m,className:"px-4 py-2 text-sm bg-blue-600 text-white rounded-md hover:bg-blue-700 disabled:opacity-50",children:m?"Creating...":"Create User"})]})]})]})})}export{O as UserManagement};
|