@dashadmin/dash-components 1.3.24 → 1.3.26
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/components/AuditLog/AuditLog.js +345 -1
- package/dist/components/AuditLog/index.js +4 -1
- package/dist/components/AutoCompleteArrayInput/AutoCompleteCheckBoxInput.js +630 -3
- package/dist/components/AutoCompleteArrayInput/AutocompleteCheckBoxArrayInput.js +53 -1
- package/dist/components/AutoCompleteArrayInputAutoSearch/AutoCompleteCheckBoxInput.js +647 -3
- package/dist/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayInput.js +53 -1
- package/dist/components/Json/Json.js +235 -1
- package/dist/components/JsonColorSelector/JsonColorSelector.js +1172 -1
- package/dist/components/JsonColorSelector/JsonColorSelectorEnhanced.js +863 -2
- package/dist/components/JsonColorSelector/JsonCssVarValues.js +738 -1
- package/dist/components/JsonColorSelector/components/ColorEditDialog.js +426 -1
- package/dist/components/JsonColorSelector/components/ColorPaletteItem.js +75 -1
- package/dist/components/JsonColorSelector/components/ImageColorExtractor.js +283 -1
- package/dist/components/JsonColorSelector/helpers/functions.js +101 -1
- package/dist/components/JsonColorSelector/useAsyncColorThief.js +105 -1
- package/dist/components/ListActive/ListActive.js +126 -1
- package/dist/components/ListActive/ListBoolean.js +124 -1
- package/dist/components/NotificationPreferences/NotificationPreferences.js +317 -1
- package/dist/components/NotificationPreferences/index.js +7 -1
- package/dist/components/SearchableSelects/RASearchableSelect.js +236 -1
- package/dist/components/SearchableSelects/RASearchableSelectCheckboxes.js +479 -1
- package/dist/components/SearchableSelects/RASearchableSelectChips.js +465 -1
- package/dist/components/SearchableSelects/RASearchableSelectChipsRecordContext.js +295 -1
- package/dist/components/SearchableSelects/SearchableSelect.js +202 -1
- package/dist/components/SearchableSelects/SearchableSelectCheckboxes.js +290 -1
- package/dist/components/SortableDataGrid/SortableDataGrid.js +72 -1
- package/dist/components/SortableDataGrid/SortableDataGridBody.js +167 -1
- package/dist/components/SortableDataGrid/SortableDataGridHeader.js +109 -1
- package/dist/components/SortableDataGrid/SortableDataGridRow.js +283 -1
- package/dist/components/Upload/SingleImageUploader.js +40 -1
- package/dist/components/custom/PackageCopyMethod.js +78 -1
- package/dist/components/custom/PackageRadioButtonGroup.js +45 -1
- package/dist/components/dialog/Basic.js +8 -1
- package/dist/components/dialog/Correct.js +14 -1
- package/dist/components/dialog/Error.js +14 -1
- package/dist/components/dialog/Info.js +14 -1
- package/dist/components/dialog/InfoV2.js +21 -1
- package/dist/components/dialog/NotFound.js +14 -1
- package/dist/components/dialog/QuickSearch.js +117 -1
- package/dist/components/notifications/NotificationsCenter.js +597 -1
- package/dist/components/notifications/index.js +24 -1
- package/dist/components/tables/PaginationComponent.js +36 -1
- package/dist/components/theme/AppLoadingFallback.js +38 -2
- package/dist/components/theme/ErrorBoundary.js +52 -1
- package/dist/components/theme/InitialLoader.js +13 -1
- package/dist/components/theme/NotFound.js +136 -1
- package/dist/components/theme/NotResults.js +38 -1
- package/dist/hooks/useDraggable.js +6 -1
- package/dist/hooks/useNotifications.js +8 -1
- package/dist/hooks/useQuickSearch.js +26 -1
- package/dist/index.js +66 -5567
- package/dist/utils/setNativeValue.js +17 -1
- package/package.json +149 -132
- package/src/components/AuditLog/AuditLog.tsx +476 -0
- package/src/components/AuditLog/index.ts +2 -0
- package/src/components/AutoCompleteArrayInput/AutoCompleteCheckBoxInput.tsx +917 -0
- package/src/components/AutoCompleteArrayInput/AutocompleteCheckBoxArrayInput.tsx +39 -0
- package/src/components/AutoCompleteArrayInputAutoSearch/AutoCompleteCheckBoxInput.tsx +916 -0
- package/src/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayInput.tsx +44 -0
- package/src/components/Json/Json.tsx +312 -0
- package/src/components/JsonColorSelector/JsonColorSelector.tsx +1435 -0
- package/src/components/JsonColorSelector/JsonColorSelectorEnhanced.tsx +1029 -0
- package/src/components/JsonColorSelector/JsonCssVarValues.tsx +863 -0
- package/src/components/JsonColorSelector/components/ColorEditDialog.tsx +491 -0
- package/src/components/JsonColorSelector/components/ColorPaletteItem.tsx +80 -0
- package/src/components/JsonColorSelector/components/ImageColorExtractor.tsx +328 -0
- package/src/components/JsonColorSelector/helpers/functions.tsx +123 -0
- package/src/components/JsonColorSelector/interfaces/interfaces.tsx +22 -0
- package/src/components/JsonColorSelector/useAsyncColorThief.tsx +97 -0
- package/src/components/ListActive/ListActive.tsx +106 -0
- package/src/components/ListActive/ListBoolean.tsx +96 -0
- package/src/components/NotificationPreferences/NotificationPreferences.tsx +463 -0
- package/src/components/NotificationPreferences/index.tsx +2 -0
- package/src/components/SearchableSelects/RASearchableSelect.tsx +300 -0
- package/src/components/SearchableSelects/RASearchableSelectCheckboxes.tsx +604 -0
- package/src/components/SearchableSelects/RASearchableSelectChips.tsx +558 -0
- package/src/components/SearchableSelects/RASearchableSelectChipsRecordContext.tsx +362 -0
- package/src/components/SearchableSelects/SearchableSelect.tsx +321 -0
- package/src/components/SearchableSelects/SearchableSelectCheckboxes.tsx +355 -0
- package/src/components/SortableDataGrid/SortableDataGrid.tsx +56 -0
- package/src/components/SortableDataGrid/SortableDataGridBody.tsx +175 -0
- package/src/components/SortableDataGrid/SortableDataGridHeader.tsx +171 -0
- package/src/components/SortableDataGrid/SortableDataGridRow.tsx +247 -0
- package/src/components/Upload/SingleImageUploader.tsx +55 -0
- package/src/components/custom/PackageCopyMethod.tsx +109 -0
- package/src/components/custom/PackageRadioButtonGroup.tsx +47 -0
- package/src/components/dialog/Basic.tsx +11 -0
- package/src/components/dialog/Correct.tsx +16 -0
- package/src/components/dialog/Error.tsx +15 -0
- package/src/components/dialog/Info.tsx +15 -0
- package/src/components/dialog/InfoV2.tsx +35 -0
- package/src/components/dialog/NotFound.tsx +18 -0
- package/src/components/dialog/QuickSearch.tsx +115 -0
- package/src/components/notifications/NotificationsCenter.tsx +792 -0
- package/src/components/notifications/index.ts +42 -0
- package/src/components/tables/PaginationComponent.tsx +17 -0
- package/src/components/theme/AppLoadingFallback.tsx +42 -0
- package/src/components/theme/ErrorBoundary.tsx +57 -0
- package/src/components/theme/InitialLoader.tsx +16 -0
- package/src/components/theme/NotFound.tsx +124 -0
- package/src/components/theme/NotResults.tsx +54 -0
- package/src/hooks/useDraggable.ts +11 -0
- package/src/hooks/useNotifications.ts +14 -0
- package/src/hooks/useQuickSearch.tsx +29 -0
- package/src/index.tsx +77 -0
- package/src/utils/setNativeValue.tsx +23 -0
- package/dist/color-thief-CTwGFhOB.js +0 -272
- /package/{dist → src}/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayAutoSearch.tsx.wip +0 -0
- /package/{dist → src}/components/JsonColorSelector/JsonColorSelector.tsx.bkup +0 -0
- /package/{dist → src}/components/SortableDataGrid/README.md +0 -0
- /package/{dist → src}/styles/index.less +0 -0
|
@@ -1 +1,738 @@
|
|
|
1
|
-
import{Fragment as ae,jsx as e,jsxs as f}from"react/jsx-runtime";import{useRecordContext as $}from"react-admin";import{useFormContext as Z}from"react-hook-form";import{Box as a,Button as F,IconButton as H,TextField as N,Typography as m,Card as U,CardContent as _,Chip as R,InputAdornment as W}from"@mui/material";import ee from"@mui/icons-material/Delete";import Y from"@mui/icons-material/Add";import q from"@mui/icons-material/Search";import G from"@mui/icons-material/Clear";import{useState as b,useEffect as J,useMemo as M}from"react";const L=r=>r==="true"||r==="false"?"boolean":!isNaN(Number(r))&&r.trim()!==""?"number":r.startsWith("{")&&r.endsWith("}")||r.startsWith("[")&&r.endsWith("]")?"json":"string",Q=(r,u=30)=>r.length<=u?r:r.substring(0,u)+"...",te=({pair:r,onUpdate:u,onDelete:d,existingKeys:h})=>{const[I,y]=b(!1),[x,V]=b(!1),[p,B]=b(r.key),[i,A]=b(r.value),[D,S]=b(""),[w,P]=b(""),s=L(r.value),l=t=>{switch(t){case"string":return"#2196f3";case"number":return"#4caf50";case"boolean":return"#ff9800";case"json":return"#9c27b0";default:return"#757575"}},g=t=>{const n=h.some(o=>o===t&&t!==r.key);return S(n?"Key already exists":""),!n&&t.trim()!==""},C=(t,n)=>{let o="";if(n==="number"&&isNaN(Number(t))&&t.trim()!=="")o="Invalid number format";else if(n==="boolean"&&!["true","false"].includes(t.toLowerCase()))o='Boolean must be "true" or "false"';else if(n==="json")try{JSON.parse(t)}catch{o="Invalid JSON format"}return P(o),!o},T=()=>{g(p)&&(u({...r,key:p}),y(!1))},K=()=>{const t=L(i);C(i,t)&&(u({...r,value:i}),V(!1))},j=()=>{B(r.key),S(""),y(!1)},E=()=>{A(r.value),P(""),V(!1)};return e(U,{variant:"outlined",sx:{mb:1,"&:hover":{boxShadow:2}},children:e(_,{sx:{p:2,"&:last-child":{pb:2}},children:f(a,{sx:{display:"flex",alignItems:"flex-start",gap:2},children:[f(a,{sx:{flex:1,minWidth:0},children:[e(m,{variant:"caption",color:"textSecondary",sx:{display:"block",mb:.5},children:"Key"}),I?e(N,{fullWidth:!0,size:"small",value:p,onChange:t=>{B(t.target.value),g(t.target.value)},error:!!D,helperText:D,onKeyDown:t=>{t.key==="Enter"&&T(),t.key==="Escape"&&j()},onBlur:T,autoFocus:!0}):e(a,{onClick:()=>y(!0),sx:{cursor:"pointer",p:1,borderRadius:1,backgroundColor:"rgba(0,0,0,0.04)","&:hover":{backgroundColor:"rgba(0,0,0,0.08)"},minHeight:24,display:"flex",alignItems:"center"},children:e(m,{variant:"body2",sx:{fontFamily:"monospace",wordBreak:"break-all"},children:r.key||"Click to add key"})})]}),f(a,{sx:{flex:1,minWidth:0},children:[f(a,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[e(m,{variant:"caption",color:"textSecondary",children:"Value"}),e(R,{label:s.toUpperCase(),size:"small",sx:{height:16,fontSize:"0.6rem",backgroundColor:l(s),color:"#fff","& .MuiChip-label":{padding:"0 4px"}}})]}),x?e(N,{fullWidth:!0,size:"small",value:i,onChange:t=>{A(t.target.value);const n=L(t.target.value);C(t.target.value,n)},error:!!w,helperText:w,multiline:s==="json",rows:s==="json"?3:1,onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&s!=="json"&&(t.preventDefault(),K()),t.key==="Escape"&&E()},onBlur:K,autoFocus:!0}):e(a,{onClick:()=>V(!0),sx:{cursor:"pointer",p:1,borderRadius:1,backgroundColor:"rgba(0,0,0,0.04)","&:hover":{backgroundColor:"rgba(0,0,0,0.08)"},minHeight:24,display:"flex",alignItems:"center"},children:e(m,{variant:"body2",sx:{fontFamily:"monospace",wordBreak:"break-all"},title:r.value,children:Q(r.value)||"Click to add value"})})]}),e(a,{sx:{display:"flex",alignItems:"center"},children:e(H,{size:"small",onClick:()=>d(r.id),color:"error",children:e(ee,{fontSize:"small"})})})]})})})},X=r=>{const{attribute:u}=r,d=$(),{setValue:h,getValues:I}=Z(),y=u.attribute,x=y.startsWith("settings."),V=x?y.split(".").slice(1).join("."):y,[p,B]=b([]),[i,A]=b(""),[D,S]=b(!0),w=M(()=>i.trim()?p.filter(t=>t.key.toLowerCase().includes(i.toLowerCase())||t.value.toLowerCase().includes(i.toLowerCase())):p,[p,i]),P=t=>{A(t.target.value)},s=()=>{A("")};J(()=>{(async()=>{S(!0);try{let n={},o={};try{o=u?.default_value||{}}catch{o={}}if(x&&d?.settings){const v=d.settings||{};n={...o,...l(v,V)}}else d?.[y]?n={...o,...d[y]}:n=o;const c=Object.entries(n).map(([v,k])=>({key:v,value:String(k),id:C()}));B(c)}catch(n){console.error("Error loading initial data:",n)}finally{S(!1)}})()},[d,y]);const l=(t,n)=>n?n.split(".").reduce((c,v)=>c&&c[v]!==void 0?c[v]:{},t):t,g=(t,n,o)=>{if(!n)return o;const c=n.split("."),v=c.pop(),k=c.reduce((z,O)=>(z[O]===void 0&&(z[O]={}),z[O]),t);return v&&(k[v]=o),t},C=()=>Math.random().toString(36).substring(2,11),T=()=>{const t={key:"",value:"",id:C()},n=[...p,t];B(n),E(n)},K=t=>{const n=p.map(o=>o.id===t.id?t:o);B(n),E(n)},j=t=>{const n=p.filter(o=>o.id!==t);B(n),E(n)},E=t=>{const n=t.reduce((o,c)=>{if(c.key.trim()){const v=L(c.value);let k=c.value;try{switch(v){case"number":k=Number(c.value);break;case"boolean":k=c.value.toLowerCase()==="true";break;case"json":k=JSON.parse(c.value);break;default:k=c.value;break}}catch{k=c.value}o[c.key]=k}return o},{});if(x){const o=I("settings")||{},c=g({...o},V,n);h("settings",c,{shouldDirty:!0})}else h(y,n,{shouldDirty:!0})};return D?e(a,{sx:{mt:1,mb:2,display:"flex",justifyContent:"center",alignItems:"center",minHeight:200},children:e(m,{variant:"body2",color:"textSecondary",children:"Loading values..."})}):f(a,{sx:{mt:1,mb:2},children:[e(m,{variant:"subtitle1",gutterBottom:!0,children:u.label||"Key-Value Pairs"}),e(a,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:3},children:e(F,{startIcon:e(Y,{}),variant:"outlined",size:"small",onClick:T,children:"Add Pair"})}),p.length>0&&e(a,{sx:{mb:3},children:e(N,{fullWidth:!0,size:"small",placeholder:"Search by key or value...",value:i,onChange:P,InputProps:{startAdornment:e(W,{position:"start",children:e(q,{})}),endAdornment:i&&e(W,{position:"end",children:e(H,{size:"small",onClick:s,edge:"end",children:e(G,{})})})}})}),i&&e(a,{sx:{mb:2},children:e(R,{label:`${w.length} of ${p.length} pairs`,size:"small",variant:"outlined",onDelete:s})}),e(a,{sx:{mb:2},children:w.map(t=>e(te,{pair:t,onUpdate:K,onDelete:j,existingKeys:p.map(n=>n.key)},t.id))}),i&&w.length===0&&f(a,{sx:{textAlign:"center",py:4},children:[e(m,{variant:"body2",color:"textSecondary",children:"No pairs found matching your search"}),e(F,{size:"small",onClick:s,sx:{mt:1},children:"Clear search"})]}),p.length===0&&f(a,{sx:{textAlign:"center",py:4},children:[e(m,{variant:"body2",color:"textSecondary",gutterBottom:!0,children:"No key-value pairs configured yet"}),e(F,{startIcon:e(Y,{}),variant:"contained",onClick:T,children:"Add Your First Pair"})]})]})},ne=r=>{const{attribute:u}=r,d=$(),h=u.attribute,I=h.startsWith("settings."),y=I?h.split(".").slice(1).join("."):h,[x,V]=b(""),[p,B]=b(!0),[i,A]=b({}),D=M(()=>Object.entries(i).map(([s,l])=>({key:s,value:String(l),id:s})),[i]);J(()=>{(async()=>{B(!0);try{let l={},g={};try{g=u?.default_value||{}}catch{g={}}if(I&&d?.settings){const C=d.settings||{};if(y){const T=y.split(".");l={...g,...T.reduce((K,j)=>K&&K[j]!==void 0?K[j]:{},C)}}else l={...g,...C}}else d?.[h]?l={...g,...d[h]}:l=g;A(l)}catch(l){console.error("Error loading view data:",l)}finally{B(!1)}})()},[d,h,u,I,y]);const S=M(()=>x.trim()?Object.entries(i).filter(([s,l])=>s.toLowerCase().includes(x.toLowerCase())||String(l).toLowerCase().includes(x.toLowerCase())).reduce((s,[l,g])=>(s[l]=g,s),{}):i,[i,x]),w=s=>{V(s.target.value)},P=()=>{V("")};return p?e(a,{sx:{mt:1,mb:2,display:"flex",justifyContent:"center",alignItems:"center",minHeight:200},children:e(m,{variant:"body2",color:"textSecondary",children:"Loading values..."})}):f(a,{sx:{mt:1,mb:2},children:[e(m,{variant:"subtitle1",gutterBottom:!0,children:u.label||"Key-Value Pairs"}),Object.keys(i).length>0&&f(ae,{children:[e(a,{sx:{mb:3},children:e(N,{fullWidth:!0,size:"small",placeholder:"Search by key or value...",value:x,onChange:w,InputProps:{startAdornment:e(W,{position:"start",children:e(q,{})}),endAdornment:x&&e(W,{position:"end",children:e(H,{size:"small",onClick:P,edge:"end",children:e(G,{})})})}})}),x&&e(a,{sx:{mb:2},children:e(R,{label:`${Object.keys(S).length} of ${Object.keys(i).length} pairs`,size:"small",variant:"outlined",onDelete:P})}),Object.keys(S).length>0?e(a,{sx:{mb:2},children:Object.entries(S).map(([s,l])=>{const g=L(String(l)),C=T=>{switch(T){case"string":return"#2196f3";case"number":return"#4caf50";case"boolean":return"#ff9800";case"json":return"#9c27b0";default:return"#757575"}};return e(U,{variant:"outlined",sx:{mb:1,border:`2px solid ${C(g)}`},children:e(_,{sx:{p:2,"&:last-child":{pb:2}},children:f(a,{sx:{display:"flex",alignItems:"flex-start",gap:2},children:[f(a,{sx:{flex:1,minWidth:0},children:[e(m,{variant:"caption",color:"textSecondary",sx:{display:"block",mb:.5},children:"Key"}),e(a,{sx:{p:1,borderRadius:1,backgroundColor:"rgba(0,0,0,0.04)",minHeight:24,display:"flex",alignItems:"center"},children:e(m,{variant:"body2",sx:{fontFamily:"monospace",wordBreak:"break-all"},children:s})})]}),f(a,{sx:{flex:1,minWidth:0},children:[f(a,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[e(m,{variant:"caption",color:"textSecondary",children:"Value"}),e(R,{label:g.toUpperCase(),size:"small",sx:{height:16,fontSize:"0.6rem",backgroundColor:C(g),color:"#fff","& .MuiChip-label":{padding:"0 4px"}}})]}),e(a,{sx:{p:1,borderRadius:1,backgroundColor:"rgba(0,0,0,0.04)",minHeight:24,display:"flex",alignItems:"center"},children:e(m,{variant:"body2",sx:{fontFamily:"monospace",wordBreak:"break-all"},title:String(l),children:Q(String(l))})})]})]})})},s)})}):f(a,{sx:{textAlign:"center",py:4},children:[e(m,{variant:"body2",color:"textSecondary",children:"No pairs found matching your search"}),e(F,{size:"small",onClick:P,sx:{mt:1},children:"Clear search"})]})]}),Object.keys(i).length===0&&e(a,{sx:{textAlign:"center",py:4},children:e(m,{variant:"body2",color:"textSecondary",children:"No key-value pairs configured"})})]})},re=({method:r,attribute:u,resourceConfig:d})=>{const[h,I]=b(!0);if(J(()=>{const y=setTimeout(()=>{I(!1)},50);return()=>{clearTimeout(y)}},[]),h)return e(a,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:100},children:e(m,{variant:"body2",color:"textSecondary",children:"Initializing key-value editor..."})});switch(r){case"edit":return e(X,{attribute:u,method:r,resourceConfig:d});case"create":return e(X,{attribute:u,method:r,resourceConfig:d});case"view":return e(ne,{attribute:u,method:r,resourceConfig:d});default:return null}};var fe=re;export{X as JsonEdit,ne as JsonView,fe as default};
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
41
|
+
import { useRecordContext } from "react-admin";
|
|
42
|
+
import { useFormContext } from "react-hook-form";
|
|
43
|
+
import {
|
|
44
|
+
Box,
|
|
45
|
+
Button,
|
|
46
|
+
IconButton,
|
|
47
|
+
TextField,
|
|
48
|
+
Typography,
|
|
49
|
+
Card,
|
|
50
|
+
CardContent,
|
|
51
|
+
Chip,
|
|
52
|
+
InputAdornment
|
|
53
|
+
} from "@mui/material";
|
|
54
|
+
import DeleteIcon from "@mui/icons-material/Delete";
|
|
55
|
+
import AddIcon from "@mui/icons-material/Add";
|
|
56
|
+
import SearchIcon from "@mui/icons-material/Search";
|
|
57
|
+
import ClearIcon from "@mui/icons-material/Clear";
|
|
58
|
+
import { useState, useEffect, useMemo } from "react";
|
|
59
|
+
const detectValueType = (value) => {
|
|
60
|
+
if (value === "true" || value === "false") return "boolean";
|
|
61
|
+
if (!isNaN(Number(value)) && value.trim() !== "") return "number";
|
|
62
|
+
if (value.startsWith("{") && value.endsWith("}") || value.startsWith("[") && value.endsWith("]")) return "json";
|
|
63
|
+
return "string";
|
|
64
|
+
};
|
|
65
|
+
const formatValueForDisplay = (value, maxLength = 30) => {
|
|
66
|
+
if (value.length <= maxLength) return value;
|
|
67
|
+
return value.substring(0, maxLength) + "...";
|
|
68
|
+
};
|
|
69
|
+
const ValueItem = ({ pair, onUpdate, onDelete, existingKeys }) => {
|
|
70
|
+
const [isEditingKey, setIsEditingKey] = useState(false);
|
|
71
|
+
const [isEditingValue, setIsEditingValue] = useState(false);
|
|
72
|
+
const [editKey, setEditKey] = useState(pair.key);
|
|
73
|
+
const [editValue, setEditValue] = useState(pair.value);
|
|
74
|
+
const [keyError, setKeyError] = useState("");
|
|
75
|
+
const [valueError, setValueError] = useState("");
|
|
76
|
+
const valueType = detectValueType(pair.value);
|
|
77
|
+
const getTypeColor = (type) => {
|
|
78
|
+
switch (type) {
|
|
79
|
+
case "string":
|
|
80
|
+
return "#2196f3";
|
|
81
|
+
// Blue
|
|
82
|
+
case "number":
|
|
83
|
+
return "#4caf50";
|
|
84
|
+
// Green
|
|
85
|
+
case "boolean":
|
|
86
|
+
return "#ff9800";
|
|
87
|
+
// Orange
|
|
88
|
+
case "json":
|
|
89
|
+
return "#9c27b0";
|
|
90
|
+
// Purple
|
|
91
|
+
default:
|
|
92
|
+
return "#757575";
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const validateKey = (key) => {
|
|
96
|
+
const isDuplicate = existingKeys.some((k) => k === key && key !== pair.key);
|
|
97
|
+
setKeyError(isDuplicate ? "Key already exists" : "");
|
|
98
|
+
return !isDuplicate && key.trim() !== "";
|
|
99
|
+
};
|
|
100
|
+
const validateValue = (value, type) => {
|
|
101
|
+
let error = "";
|
|
102
|
+
if (type === "number" && isNaN(Number(value)) && value.trim() !== "") {
|
|
103
|
+
error = "Invalid number format";
|
|
104
|
+
} else if (type === "boolean" && !["true", "false"].includes(value.toLowerCase())) {
|
|
105
|
+
error = 'Boolean must be "true" or "false"';
|
|
106
|
+
} else if (type === "json") {
|
|
107
|
+
try {
|
|
108
|
+
JSON.parse(value);
|
|
109
|
+
} catch (e) {
|
|
110
|
+
error = "Invalid JSON format";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
setValueError(error);
|
|
114
|
+
return !error;
|
|
115
|
+
};
|
|
116
|
+
const handleKeySubmit = () => {
|
|
117
|
+
if (validateKey(editKey)) {
|
|
118
|
+
onUpdate(__spreadProps(__spreadValues({}, pair), { key: editKey }));
|
|
119
|
+
setIsEditingKey(false);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const handleValueSubmit = () => {
|
|
123
|
+
const currentType = detectValueType(editValue);
|
|
124
|
+
if (validateValue(editValue, currentType)) {
|
|
125
|
+
onUpdate(__spreadProps(__spreadValues({}, pair), { value: editValue }));
|
|
126
|
+
setIsEditingValue(false);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const handleKeyCancel = () => {
|
|
130
|
+
setEditKey(pair.key);
|
|
131
|
+
setKeyError("");
|
|
132
|
+
setIsEditingKey(false);
|
|
133
|
+
};
|
|
134
|
+
const handleValueCancel = () => {
|
|
135
|
+
setEditValue(pair.value);
|
|
136
|
+
setValueError("");
|
|
137
|
+
setIsEditingValue(false);
|
|
138
|
+
};
|
|
139
|
+
return /* @__PURE__ */ jsx(
|
|
140
|
+
Card,
|
|
141
|
+
{
|
|
142
|
+
variant: "outlined",
|
|
143
|
+
sx: {
|
|
144
|
+
mb: 1,
|
|
145
|
+
//border: `2px solid ${getTypeColor(valueType)}`,
|
|
146
|
+
"&:hover": {
|
|
147
|
+
boxShadow: 2
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
children: /* @__PURE__ */ jsx(CardContent, { sx: { p: 2, "&:last-child": { pb: 2 } }, children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "flex-start", gap: 2 }, children: [
|
|
151
|
+
/* @__PURE__ */ jsxs(Box, { sx: { flex: 1, minWidth: 0 }, children: [
|
|
152
|
+
/* @__PURE__ */ jsx(Typography, { variant: "caption", color: "textSecondary", sx: { display: "block", mb: 0.5 }, children: "Key" }),
|
|
153
|
+
isEditingKey ? /* @__PURE__ */ jsx(
|
|
154
|
+
TextField,
|
|
155
|
+
{
|
|
156
|
+
fullWidth: true,
|
|
157
|
+
size: "small",
|
|
158
|
+
value: editKey,
|
|
159
|
+
onChange: (e) => {
|
|
160
|
+
setEditKey(e.target.value);
|
|
161
|
+
validateKey(e.target.value);
|
|
162
|
+
},
|
|
163
|
+
error: !!keyError,
|
|
164
|
+
helperText: keyError,
|
|
165
|
+
onKeyDown: (e) => {
|
|
166
|
+
if (e.key === "Enter") handleKeySubmit();
|
|
167
|
+
if (e.key === "Escape") handleKeyCancel();
|
|
168
|
+
},
|
|
169
|
+
onBlur: handleKeySubmit,
|
|
170
|
+
autoFocus: true
|
|
171
|
+
}
|
|
172
|
+
) : /* @__PURE__ */ jsx(
|
|
173
|
+
Box,
|
|
174
|
+
{
|
|
175
|
+
onClick: () => setIsEditingKey(true),
|
|
176
|
+
sx: {
|
|
177
|
+
cursor: "pointer",
|
|
178
|
+
p: 1,
|
|
179
|
+
borderRadius: 1,
|
|
180
|
+
backgroundColor: "rgba(0,0,0,0.04)",
|
|
181
|
+
"&:hover": {
|
|
182
|
+
backgroundColor: "rgba(0,0,0,0.08)"
|
|
183
|
+
},
|
|
184
|
+
minHeight: 24,
|
|
185
|
+
display: "flex",
|
|
186
|
+
alignItems: "center"
|
|
187
|
+
},
|
|
188
|
+
children: /* @__PURE__ */ jsx(
|
|
189
|
+
Typography,
|
|
190
|
+
{
|
|
191
|
+
variant: "body2",
|
|
192
|
+
sx: {
|
|
193
|
+
fontFamily: "monospace",
|
|
194
|
+
wordBreak: "break-all"
|
|
195
|
+
},
|
|
196
|
+
children: pair.key || "Click to add key"
|
|
197
|
+
}
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
)
|
|
201
|
+
] }),
|
|
202
|
+
/* @__PURE__ */ jsxs(Box, { sx: { flex: 1, minWidth: 0 }, children: [
|
|
203
|
+
/* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1, mb: 0.5 }, children: [
|
|
204
|
+
/* @__PURE__ */ jsx(Typography, { variant: "caption", color: "textSecondary", children: "Value" }),
|
|
205
|
+
/* @__PURE__ */ jsx(
|
|
206
|
+
Chip,
|
|
207
|
+
{
|
|
208
|
+
label: valueType.toUpperCase(),
|
|
209
|
+
size: "small",
|
|
210
|
+
sx: {
|
|
211
|
+
height: 16,
|
|
212
|
+
fontSize: "0.6rem",
|
|
213
|
+
backgroundColor: getTypeColor(valueType),
|
|
214
|
+
color: "#fff",
|
|
215
|
+
"& .MuiChip-label": {
|
|
216
|
+
padding: "0 4px"
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
] }),
|
|
222
|
+
isEditingValue ? /* @__PURE__ */ jsx(
|
|
223
|
+
TextField,
|
|
224
|
+
{
|
|
225
|
+
fullWidth: true,
|
|
226
|
+
size: "small",
|
|
227
|
+
value: editValue,
|
|
228
|
+
onChange: (e) => {
|
|
229
|
+
setEditValue(e.target.value);
|
|
230
|
+
const currentType = detectValueType(e.target.value);
|
|
231
|
+
validateValue(e.target.value, currentType);
|
|
232
|
+
},
|
|
233
|
+
error: !!valueError,
|
|
234
|
+
helperText: valueError,
|
|
235
|
+
multiline: valueType === "json",
|
|
236
|
+
rows: valueType === "json" ? 3 : 1,
|
|
237
|
+
onKeyDown: (e) => {
|
|
238
|
+
if (e.key === "Enter" && !e.shiftKey && valueType !== "json") {
|
|
239
|
+
e.preventDefault();
|
|
240
|
+
handleValueSubmit();
|
|
241
|
+
}
|
|
242
|
+
if (e.key === "Escape") handleValueCancel();
|
|
243
|
+
},
|
|
244
|
+
onBlur: handleValueSubmit,
|
|
245
|
+
autoFocus: true
|
|
246
|
+
}
|
|
247
|
+
) : /* @__PURE__ */ jsx(
|
|
248
|
+
Box,
|
|
249
|
+
{
|
|
250
|
+
onClick: () => setIsEditingValue(true),
|
|
251
|
+
sx: {
|
|
252
|
+
cursor: "pointer",
|
|
253
|
+
p: 1,
|
|
254
|
+
borderRadius: 1,
|
|
255
|
+
backgroundColor: "rgba(0,0,0,0.04)",
|
|
256
|
+
"&:hover": {
|
|
257
|
+
backgroundColor: "rgba(0,0,0,0.08)"
|
|
258
|
+
},
|
|
259
|
+
minHeight: 24,
|
|
260
|
+
display: "flex",
|
|
261
|
+
alignItems: "center"
|
|
262
|
+
},
|
|
263
|
+
children: /* @__PURE__ */ jsx(
|
|
264
|
+
Typography,
|
|
265
|
+
{
|
|
266
|
+
variant: "body2",
|
|
267
|
+
sx: {
|
|
268
|
+
fontFamily: "monospace",
|
|
269
|
+
wordBreak: "break-all"
|
|
270
|
+
},
|
|
271
|
+
title: pair.value,
|
|
272
|
+
children: formatValueForDisplay(pair.value) || "Click to add value"
|
|
273
|
+
}
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
)
|
|
277
|
+
] }),
|
|
278
|
+
/* @__PURE__ */ jsx(Box, { sx: { display: "flex", alignItems: "center" }, children: /* @__PURE__ */ jsx(
|
|
279
|
+
IconButton,
|
|
280
|
+
{
|
|
281
|
+
size: "small",
|
|
282
|
+
onClick: () => onDelete(pair.id),
|
|
283
|
+
color: "error",
|
|
284
|
+
children: /* @__PURE__ */ jsx(DeleteIcon, { fontSize: "small" })
|
|
285
|
+
}
|
|
286
|
+
) })
|
|
287
|
+
] }) })
|
|
288
|
+
}
|
|
289
|
+
);
|
|
290
|
+
};
|
|
291
|
+
const JsonEdit = (props) => {
|
|
292
|
+
const { attribute } = props;
|
|
293
|
+
const record = useRecordContext();
|
|
294
|
+
const { setValue, getValues } = useFormContext();
|
|
295
|
+
const attributePath = attribute.attribute;
|
|
296
|
+
const isNestedSetting = attributePath.startsWith("settings.");
|
|
297
|
+
const settingsPath = isNestedSetting ? attributePath.split(".").slice(1).join(".") : attributePath;
|
|
298
|
+
const [pairs, setPairs] = useState([]);
|
|
299
|
+
const [searchTerm, setSearchTerm] = useState("");
|
|
300
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
301
|
+
const filteredPairs = useMemo(() => {
|
|
302
|
+
if (!searchTerm.trim()) return pairs;
|
|
303
|
+
return pairs.filter(
|
|
304
|
+
(pair) => pair.key.toLowerCase().includes(searchTerm.toLowerCase()) || pair.value.toLowerCase().includes(searchTerm.toLowerCase())
|
|
305
|
+
);
|
|
306
|
+
}, [pairs, searchTerm]);
|
|
307
|
+
const handleSearchChange = (event) => {
|
|
308
|
+
setSearchTerm(event.target.value);
|
|
309
|
+
};
|
|
310
|
+
const handleClearSearch = () => {
|
|
311
|
+
setSearchTerm("");
|
|
312
|
+
};
|
|
313
|
+
useEffect(() => {
|
|
314
|
+
const loadInitialData = () => __async(null, null, function* () {
|
|
315
|
+
setIsLoading(true);
|
|
316
|
+
try {
|
|
317
|
+
let initialValue = {};
|
|
318
|
+
let defaultValues = {};
|
|
319
|
+
try {
|
|
320
|
+
defaultValues = (attribute == null ? void 0 : attribute.default_value) || {};
|
|
321
|
+
} catch (e) {
|
|
322
|
+
defaultValues = {};
|
|
323
|
+
}
|
|
324
|
+
if (isNestedSetting && (record == null ? void 0 : record.settings)) {
|
|
325
|
+
const settings = record.settings || {};
|
|
326
|
+
initialValue = __spreadValues(__spreadValues({}, defaultValues), getNestedValue(settings, settingsPath));
|
|
327
|
+
} else if (record == null ? void 0 : record[attributePath]) {
|
|
328
|
+
initialValue = __spreadValues(__spreadValues({}, defaultValues), record[attributePath]);
|
|
329
|
+
} else {
|
|
330
|
+
initialValue = defaultValues;
|
|
331
|
+
}
|
|
332
|
+
const initialPairs = Object.entries(initialValue).map(([key, value]) => ({
|
|
333
|
+
key,
|
|
334
|
+
value: String(value),
|
|
335
|
+
id: generateId()
|
|
336
|
+
}));
|
|
337
|
+
setPairs(initialPairs);
|
|
338
|
+
} catch (error) {
|
|
339
|
+
console.error("Error loading initial data:", error);
|
|
340
|
+
} finally {
|
|
341
|
+
setIsLoading(false);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
loadInitialData();
|
|
345
|
+
}, [record, attributePath]);
|
|
346
|
+
const getNestedValue = (obj, path) => {
|
|
347
|
+
if (!path) return obj;
|
|
348
|
+
const keys = path.split(".");
|
|
349
|
+
return keys.reduce((o, key) => o && o[key] !== void 0 ? o[key] : {}, obj);
|
|
350
|
+
};
|
|
351
|
+
const setNestedValue = (obj, path, value) => {
|
|
352
|
+
if (!path) return value;
|
|
353
|
+
const keys = path.split(".");
|
|
354
|
+
const lastKey = keys.pop();
|
|
355
|
+
const lastObj = keys.reduce((o, key) => {
|
|
356
|
+
if (o[key] === void 0) o[key] = {};
|
|
357
|
+
return o[key];
|
|
358
|
+
}, obj);
|
|
359
|
+
if (lastKey) {
|
|
360
|
+
lastObj[lastKey] = value;
|
|
361
|
+
}
|
|
362
|
+
return obj;
|
|
363
|
+
};
|
|
364
|
+
const generateId = () => {
|
|
365
|
+
return Math.random().toString(36).substring(2, 11);
|
|
366
|
+
};
|
|
367
|
+
const addPair = () => {
|
|
368
|
+
const newPair = { key: "", value: "", id: generateId() };
|
|
369
|
+
const updatedPairs = [...pairs, newPair];
|
|
370
|
+
setPairs(updatedPairs);
|
|
371
|
+
updateFormValue(updatedPairs);
|
|
372
|
+
};
|
|
373
|
+
const handleUpdatePair = (updatedPair) => {
|
|
374
|
+
const updatedPairs = pairs.map((p) => p.id === updatedPair.id ? updatedPair : p);
|
|
375
|
+
setPairs(updatedPairs);
|
|
376
|
+
updateFormValue(updatedPairs);
|
|
377
|
+
};
|
|
378
|
+
const handleDeletePair = (id) => {
|
|
379
|
+
const updatedPairs = pairs.filter((pair) => pair.id !== id);
|
|
380
|
+
setPairs(updatedPairs);
|
|
381
|
+
updateFormValue(updatedPairs);
|
|
382
|
+
};
|
|
383
|
+
const updateFormValue = (currentPairs) => {
|
|
384
|
+
const obj = currentPairs.reduce((acc, pair) => {
|
|
385
|
+
if (pair.key.trim()) {
|
|
386
|
+
const valueType = detectValueType(pair.value);
|
|
387
|
+
let parsedValue = pair.value;
|
|
388
|
+
try {
|
|
389
|
+
switch (valueType) {
|
|
390
|
+
case "number":
|
|
391
|
+
parsedValue = Number(pair.value);
|
|
392
|
+
break;
|
|
393
|
+
case "boolean":
|
|
394
|
+
parsedValue = pair.value.toLowerCase() === "true";
|
|
395
|
+
break;
|
|
396
|
+
case "json":
|
|
397
|
+
parsedValue;
|
|
398
|
+
parsedValue = JSON.parse(pair.value);
|
|
399
|
+
break;
|
|
400
|
+
case "string":
|
|
401
|
+
default:
|
|
402
|
+
parsedValue = pair.value;
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
} catch (e) {
|
|
406
|
+
parsedValue = pair.value;
|
|
407
|
+
}
|
|
408
|
+
acc[pair.key] = parsedValue;
|
|
409
|
+
}
|
|
410
|
+
return acc;
|
|
411
|
+
}, {});
|
|
412
|
+
if (isNestedSetting) {
|
|
413
|
+
const currentSettings = getValues("settings") || {};
|
|
414
|
+
const updatedSettings = setNestedValue(__spreadValues({}, currentSettings), settingsPath, obj);
|
|
415
|
+
setValue("settings", updatedSettings, { shouldDirty: true });
|
|
416
|
+
} else {
|
|
417
|
+
setValue(attributePath, obj, { shouldDirty: true });
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
if (isLoading) {
|
|
421
|
+
return /* @__PURE__ */ jsx(Box, { sx: { mt: 1, mb: 2, display: "flex", justifyContent: "center", alignItems: "center", minHeight: 200 }, children: /* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", children: "Loading values..." }) });
|
|
422
|
+
}
|
|
423
|
+
return /* @__PURE__ */ jsxs(Box, { sx: { mt: 1, mb: 2 }, children: [
|
|
424
|
+
/* @__PURE__ */ jsx(Typography, { variant: "subtitle1", gutterBottom: true, children: attribute.label || "Key-Value Pairs" }),
|
|
425
|
+
/* @__PURE__ */ jsx(Box, { sx: { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 3 }, children: /* @__PURE__ */ jsx(
|
|
426
|
+
Button,
|
|
427
|
+
{
|
|
428
|
+
startIcon: /* @__PURE__ */ jsx(AddIcon, {}),
|
|
429
|
+
variant: "outlined",
|
|
430
|
+
size: "small",
|
|
431
|
+
onClick: addPair,
|
|
432
|
+
children: "Add Pair"
|
|
433
|
+
}
|
|
434
|
+
) }),
|
|
435
|
+
pairs.length > 0 && /* @__PURE__ */ jsx(Box, { sx: { mb: 3 }, children: /* @__PURE__ */ jsx(
|
|
436
|
+
TextField,
|
|
437
|
+
{
|
|
438
|
+
fullWidth: true,
|
|
439
|
+
size: "small",
|
|
440
|
+
placeholder: "Search by key or value...",
|
|
441
|
+
value: searchTerm,
|
|
442
|
+
onChange: handleSearchChange,
|
|
443
|
+
InputProps: {
|
|
444
|
+
startAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", children: /* @__PURE__ */ jsx(SearchIcon, {}) }),
|
|
445
|
+
endAdornment: searchTerm && /* @__PURE__ */ jsx(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx(
|
|
446
|
+
IconButton,
|
|
447
|
+
{
|
|
448
|
+
size: "small",
|
|
449
|
+
onClick: handleClearSearch,
|
|
450
|
+
edge: "end",
|
|
451
|
+
children: /* @__PURE__ */ jsx(ClearIcon, {})
|
|
452
|
+
}
|
|
453
|
+
) })
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
) }),
|
|
457
|
+
searchTerm && /* @__PURE__ */ jsx(Box, { sx: { mb: 2 }, children: /* @__PURE__ */ jsx(
|
|
458
|
+
Chip,
|
|
459
|
+
{
|
|
460
|
+
label: `${filteredPairs.length} of ${pairs.length} pairs`,
|
|
461
|
+
size: "small",
|
|
462
|
+
variant: "outlined",
|
|
463
|
+
onDelete: handleClearSearch
|
|
464
|
+
}
|
|
465
|
+
) }),
|
|
466
|
+
/* @__PURE__ */ jsx(Box, { sx: { mb: 2 }, children: filteredPairs.map((pair) => /* @__PURE__ */ jsx(
|
|
467
|
+
ValueItem,
|
|
468
|
+
{
|
|
469
|
+
pair,
|
|
470
|
+
onUpdate: handleUpdatePair,
|
|
471
|
+
onDelete: handleDeletePair,
|
|
472
|
+
existingKeys: pairs.map((p) => p.key)
|
|
473
|
+
},
|
|
474
|
+
pair.id
|
|
475
|
+
)) }),
|
|
476
|
+
searchTerm && filteredPairs.length === 0 && /* @__PURE__ */ jsxs(Box, { sx: { textAlign: "center", py: 4 }, children: [
|
|
477
|
+
/* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", children: "No pairs found matching your search" }),
|
|
478
|
+
/* @__PURE__ */ jsx(Button, { size: "small", onClick: handleClearSearch, sx: { mt: 1 }, children: "Clear search" })
|
|
479
|
+
] }),
|
|
480
|
+
pairs.length === 0 && /* @__PURE__ */ jsxs(Box, { sx: { textAlign: "center", py: 4 }, children: [
|
|
481
|
+
/* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", gutterBottom: true, children: "No key-value pairs configured yet" }),
|
|
482
|
+
/* @__PURE__ */ jsx(
|
|
483
|
+
Button,
|
|
484
|
+
{
|
|
485
|
+
startIcon: /* @__PURE__ */ jsx(AddIcon, {}),
|
|
486
|
+
variant: "contained",
|
|
487
|
+
onClick: addPair,
|
|
488
|
+
children: "Add Your First Pair"
|
|
489
|
+
}
|
|
490
|
+
)
|
|
491
|
+
] })
|
|
492
|
+
] });
|
|
493
|
+
};
|
|
494
|
+
const JsonView = (props) => {
|
|
495
|
+
const { attribute } = props;
|
|
496
|
+
const record = useRecordContext();
|
|
497
|
+
const attributePath = attribute.attribute;
|
|
498
|
+
const isNestedSetting = attributePath.startsWith("settings.");
|
|
499
|
+
const settingsPath = isNestedSetting ? attributePath.split(".").slice(1).join(".") : attributePath;
|
|
500
|
+
const [searchTerm, setSearchTerm] = useState("");
|
|
501
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
502
|
+
const [displayValue, setDisplayValue] = useState({});
|
|
503
|
+
const displayPairs = useMemo(() => {
|
|
504
|
+
return Object.entries(displayValue).map(([key, value]) => ({
|
|
505
|
+
key,
|
|
506
|
+
value: String(value),
|
|
507
|
+
id: key
|
|
508
|
+
}));
|
|
509
|
+
}, [displayValue]);
|
|
510
|
+
useEffect(() => {
|
|
511
|
+
const loadViewData = () => __async(null, null, function* () {
|
|
512
|
+
setIsLoading(true);
|
|
513
|
+
try {
|
|
514
|
+
let viewValue = {};
|
|
515
|
+
let defaultValues = {};
|
|
516
|
+
try {
|
|
517
|
+
defaultValues = (attribute == null ? void 0 : attribute.default_value) || {};
|
|
518
|
+
} catch (e) {
|
|
519
|
+
defaultValues = {};
|
|
520
|
+
}
|
|
521
|
+
if (isNestedSetting && (record == null ? void 0 : record.settings)) {
|
|
522
|
+
const settings = record.settings || {};
|
|
523
|
+
if (settingsPath) {
|
|
524
|
+
const keys = settingsPath.split(".");
|
|
525
|
+
viewValue = __spreadValues(__spreadValues({}, defaultValues), keys.reduce((o, key) => o && o[key] !== void 0 ? o[key] : {}, settings));
|
|
526
|
+
} else {
|
|
527
|
+
viewValue = __spreadValues(__spreadValues({}, defaultValues), settings);
|
|
528
|
+
}
|
|
529
|
+
} else if (record == null ? void 0 : record[attributePath]) {
|
|
530
|
+
viewValue = __spreadValues(__spreadValues({}, defaultValues), record[attributePath]);
|
|
531
|
+
} else {
|
|
532
|
+
viewValue = defaultValues;
|
|
533
|
+
}
|
|
534
|
+
setDisplayValue(viewValue);
|
|
535
|
+
} catch (error) {
|
|
536
|
+
console.error("Error loading view data:", error);
|
|
537
|
+
} finally {
|
|
538
|
+
setIsLoading(false);
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
loadViewData();
|
|
542
|
+
}, [record, attributePath, attribute, isNestedSetting, settingsPath]);
|
|
543
|
+
const filteredDisplayValue = useMemo(() => {
|
|
544
|
+
if (!searchTerm.trim()) return displayValue;
|
|
545
|
+
return Object.entries(displayValue).filter(
|
|
546
|
+
([key, value]) => key.toLowerCase().includes(searchTerm.toLowerCase()) || String(value).toLowerCase().includes(searchTerm.toLowerCase())
|
|
547
|
+
).reduce((acc, [key, value]) => {
|
|
548
|
+
acc[key] = value;
|
|
549
|
+
return acc;
|
|
550
|
+
}, {});
|
|
551
|
+
}, [displayValue, searchTerm]);
|
|
552
|
+
const handleSearchChange = (event) => {
|
|
553
|
+
setSearchTerm(event.target.value);
|
|
554
|
+
};
|
|
555
|
+
const handleClearSearch = () => {
|
|
556
|
+
setSearchTerm("");
|
|
557
|
+
};
|
|
558
|
+
if (isLoading) {
|
|
559
|
+
return /* @__PURE__ */ jsx(Box, { sx: { mt: 1, mb: 2, display: "flex", justifyContent: "center", alignItems: "center", minHeight: 200 }, children: /* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", children: "Loading values..." }) });
|
|
560
|
+
}
|
|
561
|
+
return /* @__PURE__ */ jsxs(Box, { sx: { mt: 1, mb: 2 }, children: [
|
|
562
|
+
/* @__PURE__ */ jsx(Typography, { variant: "subtitle1", gutterBottom: true, children: attribute.label || "Key-Value Pairs" }),
|
|
563
|
+
Object.keys(displayValue).length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
564
|
+
/* @__PURE__ */ jsx(Box, { sx: { mb: 3 }, children: /* @__PURE__ */ jsx(
|
|
565
|
+
TextField,
|
|
566
|
+
{
|
|
567
|
+
fullWidth: true,
|
|
568
|
+
size: "small",
|
|
569
|
+
placeholder: "Search by key or value...",
|
|
570
|
+
value: searchTerm,
|
|
571
|
+
onChange: handleSearchChange,
|
|
572
|
+
InputProps: {
|
|
573
|
+
startAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", children: /* @__PURE__ */ jsx(SearchIcon, {}) }),
|
|
574
|
+
endAdornment: searchTerm && /* @__PURE__ */ jsx(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx(
|
|
575
|
+
IconButton,
|
|
576
|
+
{
|
|
577
|
+
size: "small",
|
|
578
|
+
onClick: handleClearSearch,
|
|
579
|
+
edge: "end",
|
|
580
|
+
children: /* @__PURE__ */ jsx(ClearIcon, {})
|
|
581
|
+
}
|
|
582
|
+
) })
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
) }),
|
|
586
|
+
searchTerm && /* @__PURE__ */ jsx(Box, { sx: { mb: 2 }, children: /* @__PURE__ */ jsx(
|
|
587
|
+
Chip,
|
|
588
|
+
{
|
|
589
|
+
label: `${Object.keys(filteredDisplayValue).length} of ${Object.keys(displayValue).length} pairs`,
|
|
590
|
+
size: "small",
|
|
591
|
+
variant: "outlined",
|
|
592
|
+
onDelete: handleClearSearch
|
|
593
|
+
}
|
|
594
|
+
) }),
|
|
595
|
+
Object.keys(filteredDisplayValue).length > 0 ? /* @__PURE__ */ jsx(Box, { sx: { mb: 2 }, children: Object.entries(filteredDisplayValue).map(([key, value]) => {
|
|
596
|
+
const valueType = detectValueType(String(value));
|
|
597
|
+
const getTypeColor = (type) => {
|
|
598
|
+
switch (type) {
|
|
599
|
+
case "string":
|
|
600
|
+
return "#2196f3";
|
|
601
|
+
// Blue
|
|
602
|
+
case "number":
|
|
603
|
+
return "#4caf50";
|
|
604
|
+
// Green
|
|
605
|
+
case "boolean":
|
|
606
|
+
return "#ff9800";
|
|
607
|
+
// Orange
|
|
608
|
+
case "json":
|
|
609
|
+
return "#9c27b0";
|
|
610
|
+
// Purple
|
|
611
|
+
default:
|
|
612
|
+
return "#757575";
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
return /* @__PURE__ */ jsx(
|
|
616
|
+
Card,
|
|
617
|
+
{
|
|
618
|
+
variant: "outlined",
|
|
619
|
+
sx: {
|
|
620
|
+
mb: 1,
|
|
621
|
+
border: `2px solid ${getTypeColor(valueType)}`
|
|
622
|
+
},
|
|
623
|
+
children: /* @__PURE__ */ jsx(CardContent, { sx: { p: 2, "&:last-child": { pb: 2 } }, children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "flex-start", gap: 2 }, children: [
|
|
624
|
+
/* @__PURE__ */ jsxs(Box, { sx: { flex: 1, minWidth: 0 }, children: [
|
|
625
|
+
/* @__PURE__ */ jsx(Typography, { variant: "caption", color: "textSecondary", sx: { display: "block", mb: 0.5 }, children: "Key" }),
|
|
626
|
+
/* @__PURE__ */ jsx(
|
|
627
|
+
Box,
|
|
628
|
+
{
|
|
629
|
+
sx: {
|
|
630
|
+
p: 1,
|
|
631
|
+
borderRadius: 1,
|
|
632
|
+
backgroundColor: "rgba(0,0,0,0.04)",
|
|
633
|
+
minHeight: 24,
|
|
634
|
+
display: "flex",
|
|
635
|
+
alignItems: "center"
|
|
636
|
+
},
|
|
637
|
+
children: /* @__PURE__ */ jsx(
|
|
638
|
+
Typography,
|
|
639
|
+
{
|
|
640
|
+
variant: "body2",
|
|
641
|
+
sx: {
|
|
642
|
+
fontFamily: "monospace",
|
|
643
|
+
wordBreak: "break-all"
|
|
644
|
+
},
|
|
645
|
+
children: key
|
|
646
|
+
}
|
|
647
|
+
)
|
|
648
|
+
}
|
|
649
|
+
)
|
|
650
|
+
] }),
|
|
651
|
+
/* @__PURE__ */ jsxs(Box, { sx: { flex: 1, minWidth: 0 }, children: [
|
|
652
|
+
/* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1, mb: 0.5 }, children: [
|
|
653
|
+
/* @__PURE__ */ jsx(Typography, { variant: "caption", color: "textSecondary", children: "Value" }),
|
|
654
|
+
/* @__PURE__ */ jsx(
|
|
655
|
+
Chip,
|
|
656
|
+
{
|
|
657
|
+
label: valueType.toUpperCase(),
|
|
658
|
+
size: "small",
|
|
659
|
+
sx: {
|
|
660
|
+
height: 16,
|
|
661
|
+
fontSize: "0.6rem",
|
|
662
|
+
backgroundColor: getTypeColor(valueType),
|
|
663
|
+
color: "#fff",
|
|
664
|
+
"& .MuiChip-label": {
|
|
665
|
+
padding: "0 4px"
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
)
|
|
670
|
+
] }),
|
|
671
|
+
/* @__PURE__ */ jsx(
|
|
672
|
+
Box,
|
|
673
|
+
{
|
|
674
|
+
sx: {
|
|
675
|
+
p: 1,
|
|
676
|
+
borderRadius: 1,
|
|
677
|
+
backgroundColor: "rgba(0,0,0,0.04)",
|
|
678
|
+
minHeight: 24,
|
|
679
|
+
display: "flex",
|
|
680
|
+
alignItems: "center"
|
|
681
|
+
},
|
|
682
|
+
children: /* @__PURE__ */ jsx(
|
|
683
|
+
Typography,
|
|
684
|
+
{
|
|
685
|
+
variant: "body2",
|
|
686
|
+
sx: {
|
|
687
|
+
fontFamily: "monospace",
|
|
688
|
+
wordBreak: "break-all"
|
|
689
|
+
},
|
|
690
|
+
title: String(value),
|
|
691
|
+
children: formatValueForDisplay(String(value))
|
|
692
|
+
}
|
|
693
|
+
)
|
|
694
|
+
}
|
|
695
|
+
)
|
|
696
|
+
] })
|
|
697
|
+
] }) })
|
|
698
|
+
},
|
|
699
|
+
key
|
|
700
|
+
);
|
|
701
|
+
}) }) : /* @__PURE__ */ jsxs(Box, { sx: { textAlign: "center", py: 4 }, children: [
|
|
702
|
+
/* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", children: "No pairs found matching your search" }),
|
|
703
|
+
/* @__PURE__ */ jsx(Button, { size: "small", onClick: handleClearSearch, sx: { mt: 1 }, children: "Clear search" })
|
|
704
|
+
] })
|
|
705
|
+
] }),
|
|
706
|
+
Object.keys(displayValue).length === 0 && /* @__PURE__ */ jsx(Box, { sx: { textAlign: "center", py: 4 }, children: /* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", children: "No key-value pairs configured" }) })
|
|
707
|
+
] });
|
|
708
|
+
};
|
|
709
|
+
const JsonCssVarValues = ({ method, attribute, resourceConfig }) => {
|
|
710
|
+
const [componentLoading, setComponentLoading] = useState(true);
|
|
711
|
+
useEffect(() => {
|
|
712
|
+
const timer = setTimeout(() => {
|
|
713
|
+
setComponentLoading(false);
|
|
714
|
+
}, 50);
|
|
715
|
+
return () => {
|
|
716
|
+
clearTimeout(timer);
|
|
717
|
+
};
|
|
718
|
+
}, []);
|
|
719
|
+
if (componentLoading) {
|
|
720
|
+
return /* @__PURE__ */ jsx(Box, { sx: { display: "flex", justifyContent: "center", alignItems: "center", minHeight: 100 }, children: /* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", children: "Initializing key-value editor..." }) });
|
|
721
|
+
}
|
|
722
|
+
switch (method) {
|
|
723
|
+
case "edit":
|
|
724
|
+
return /* @__PURE__ */ jsx(JsonEdit, { attribute, method, resourceConfig });
|
|
725
|
+
case "create":
|
|
726
|
+
return /* @__PURE__ */ jsx(JsonEdit, { attribute, method, resourceConfig });
|
|
727
|
+
case "view":
|
|
728
|
+
return /* @__PURE__ */ jsx(JsonView, { attribute, method, resourceConfig });
|
|
729
|
+
default:
|
|
730
|
+
return null;
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
var JsonCssVarValues_default = JsonCssVarValues;
|
|
734
|
+
export {
|
|
735
|
+
JsonEdit,
|
|
736
|
+
JsonView,
|
|
737
|
+
JsonCssVarValues_default as default
|
|
738
|
+
};
|