@verifiedinc-public/shared-ui-elements 12.15.1 → 12.17.0
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/DataTable/DataTable.filterState.mjs +1 -1
- package/dist/components/DataTable/DataTable.types.d.ts +21 -1
- package/dist/components/DataTable/DataTableFieldFilterPanel.mjs +1 -1
- package/dist/components/NetworkRules/dialog/NetworkRuleDeleteDialog.mjs +1 -1
- package/dist/components/NetworkRules/editor/NetworkRuleEditorForm.mjs +1 -1
- package/dist/components/NetworkRules/editor/fields/ConditionRow.mjs +1 -1
- package/dist/components/NetworkRules/editor/fields/MetadataField.d.ts +12 -0
- package/dist/components/NetworkRules/editor/fields/MetadataField.mjs +1 -0
- package/dist/components/NetworkRules/editor/fields/MetadataRow.d.ts +14 -0
- package/dist/components/NetworkRules/editor/fields/MetadataRow.mjs +1 -0
- package/dist/components/NetworkRules/editor/fields/PresetTextInput.d.ts +22 -0
- package/dist/components/NetworkRules/editor/fields/PresetTextInput.mjs +1 -0
- package/dist/components/NetworkRules/editor/schema.d.ts +44 -2
- package/dist/components/NetworkRules/editor/schema.mjs +1 -1
- package/dist/components/NetworkRules/hooks/useNetworkRulesDialogs.d.ts +1 -1
- package/dist/components/NetworkRules/hooks/useNetworkRulesDialogs.mjs +1 -1
- package/dist/components/NetworkRules/index.mjs +1 -1
- package/dist/components/NetworkRules/table/NetworkRuleConditionsTable.d.ts +1 -4
- package/dist/components/NetworkRules/table/NetworkRuleConditionsTable.mjs +1 -1
- package/dist/components/NetworkRules/table/NetworkRuleExpandedPanel.d.ts +1 -3
- package/dist/components/NetworkRules/table/NetworkRuleExpandedPanel.mjs +1 -1
- package/dist/components/NetworkRules/table/NetworkRuleMetadataTable.d.ts +9 -0
- package/dist/components/NetworkRules/table/NetworkRuleMetadataTable.mjs +1 -0
- package/dist/components/NetworkRules/table/NetworkRulesTable.d.ts +1 -1
- package/dist/components/NetworkRules/table/filters.d.ts +6 -2
- package/dist/components/NetworkRules/table/filters.mjs +1 -1
- package/dist/components/NetworkRules/table/index.d.ts +1 -0
- package/dist/components/NetworkRules/table/query.d.ts +11 -0
- package/dist/components/NetworkRules/table/query.mjs +1 -1
- package/dist/components/NetworkRules/types.d.ts +33 -3
- package/dist/components/NetworkRules/utils/catalog.d.ts +5 -2
- package/dist/components/NetworkRules/utils/catalog.mjs +1 -1
- package/dist/components/NetworkRules/utils/condition.d.ts +0 -5
- package/dist/components/NetworkRules/utils/condition.mjs +1 -1
- package/dist/components/NetworkRules/utils/index.d.ts +1 -0
- package/dist/components/NetworkRules/utils/metadata.d.ts +41 -0
- package/dist/components/NetworkRules/utils/metadata.mjs +1 -0
- package/dist/components/UI/SectionLabel.d.ts +6 -0
- package/dist/components/UI/SectionLabel.mjs +1 -0
- package/dist/components/UI/index.d.ts +1 -0
- package/dist/components/form/AddressInput/index.mjs +1 -1
- package/dist/components/form/NewOneClickForm/core/fields/employer.d.ts +5 -0
- package/dist/components/form/NewOneClickForm/core/fields/index.d.ts +5 -0
- package/dist/components/form/NewOneClickForm/core/validations/employer/employer.schema.d.ts +5 -0
- package/dist/components/form/NewOneClickForm/core/validations/employer/employer.schema.mjs +1 -1
- package/dist/components/form/NewOneClickForm/react/ui/fields/input/employer.field.mjs +1 -1
- package/dist/components/form/NewOneClickForm/react/ui/fields/readonly/employer.field.mjs +1 -1
- package/dist/components/form/NewOneClickForm/react/ui/fields/readonly/healthInsurance.field.mjs +1 -1
- package/dist/components/form/NewOneClickForm/react/ui/fields/shared.d.ts +2 -0
- package/dist/components/index.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/styles/theme.mjs +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function d(
|
|
1
|
+
"use strict";function d(n){var e,r;switch(n.kind){case"text":return{kind:"text",operator:((e=n.operators)==null?void 0:e[0])??"contains",value:""};case"select":return{kind:"select",value:null};case"multiSelect":return{kind:"multiSelect",values:[]};case"boolean":return{kind:"boolean",value:null};case"group":return{kind:"group",values:{}};case"keyedText":return{kind:"keyedText",key:null,operator:((r=n.operators)==null?void 0:r[0])??"contains",value:""}}}function k(n){const e={};for(const r of n)e[r.id]=d(r);return e}function i(n,e,r){return r&&e.length>0&&e.every(l=>n.includes(l))&&n.every(l=>e.includes(l))}function c(n,e){if(!e||e.kind!==n.kind)return!1;const r=n.selectAllClears??!0;switch(e.kind){case"text":return v(e);case"select":return e.value!=null&&e.value!=="";case"multiSelect":return e.values.length>0&&!i(e.values,(n.options??[]).map(l=>l.value),r);case"boolean":return e.value!=null;case"group":return(n.sections??[]).some(l=>{const u=e.values[l.key]??[];return u.length>0&&!i(u,l.options.map(t=>t.value),r)});case"keyedText":return!!e.key&&v(e)}}function v(n){return n.operator==="isEmpty"||n.operator==="isNotEmpty"?!0:n.value.trim()!==""}function y(n,e){return n.filter(r=>c(r,e[r.id])).length}function p(n,e,r){const l=n==null||n==="",u=l?"":String(n).toLowerCase();if(e==="isEmpty")return l;if(e==="isNotEmpty")return!l;const t=r.trim().toLowerCase();if(t==="")return!0;switch(e){case"doesNotContain":return!u.includes(t);case"equals":return u===t;case"doesNotEqual":return u!==t;case"startsWith":return u.startsWith(t);case"endsWith":return u.endsWith(t);case"contains":default:return u.includes(t)}}function g(n){return typeof n=="boolean"?n:n==="true"||n==="Yes"?!0:n==="false"||n==="No"?!1:null}function m(n,e){switch(e.kind){case"text":return p(n,e.operator,e.value);case"select":return e.value==null||String(n)===e.value;case"multiSelect":return e.values.length===0||e.values.includes(String(n));case"boolean":return e.value==null||g(n)===e.value;case"group":return!0;case"keyedText":return e.key==null?!0:p((typeof n=="object"&&n!==null?n:{})[e.key],e.operator,e.value)}}function h(n,e,r){const l=n.selectAllClears??!0;return(n.sections??[]).every(u=>{const t=e[u.key]??[];return t.length===0||i(t,u.options.map(s=>s.value),l)?!0:t.includes(String(r(u.key)))})}function x(n,e,r,l=(u,t)=>u[t]){const u=e.filter(t=>c(t,r[t.id])?t.kind==="group"||t.columnId!==void 0:!1);return u.length===0?n:n.filter((t,s)=>u.every(a=>{const o=r[a.id];return o===void 0?!0:o.kind==="group"?h(a,o.values,f=>l(t,f,s)):m(l(t,a.columnId,s),o)}))}export{x as applyFieldFilters,k as buildInitialFilterState,y as effectiveFilterFieldCount,d as emptyFieldValue,c as isFilterFieldActive};
|
|
@@ -11,7 +11,7 @@ export type DataTableData = Record<string, unknown>;
|
|
|
11
11
|
/** Text-match operators for a `text` filter field. */
|
|
12
12
|
export type DataTableFilterOperator = 'contains' | 'doesNotContain' | 'equals' | 'doesNotEqual' | 'startsWith' | 'endsWith' | 'isEmpty' | 'isNotEmpty' | 'isAnyOf';
|
|
13
13
|
/** Control kind a `DataTableFilterField` renders in the filter panel. */
|
|
14
|
-
export type DataTableFilterFieldKind = 'text' | 'select' | 'multiSelect' | 'boolean' | 'group';
|
|
14
|
+
export type DataTableFilterFieldKind = 'text' | 'select' | 'multiSelect' | 'boolean' | 'group' | 'keyedText';
|
|
15
15
|
/**
|
|
16
16
|
* One selectable choice. `value` is the server value carried end-to-end (a
|
|
17
17
|
* uuid, enum code, `'true'`/`'false'`, ...), `label` is what the user sees.
|
|
@@ -66,6 +66,10 @@ export interface DataTableFilterField {
|
|
|
66
66
|
loadOptions?: (search: string) => Promise<DataTableFilterOption[]>;
|
|
67
67
|
/** Sections for `group`. */
|
|
68
68
|
sections?: DataTableFilterSection[];
|
|
69
|
+
/** Keys suggested for a `keyedText` field's match; any key can still be typed. `options` then suggests values. */
|
|
70
|
+
keys?: DataTableFilterOption[];
|
|
71
|
+
/** Label of a `keyedText` field's key picker. Defaults to "Key"; `label` names the value input. */
|
|
72
|
+
keyLabel?: string;
|
|
69
73
|
/**
|
|
70
74
|
* Text operators offered (and their order) for a `text` field. Defaults to
|
|
71
75
|
* `['contains']`. The first entry is the default operator.
|
|
@@ -79,6 +83,17 @@ export interface DataTableFilterField {
|
|
|
79
83
|
selectAllClears?: boolean;
|
|
80
84
|
/** Placeholder for the input (text / select / multiSelect). */
|
|
81
85
|
placeholder?: string;
|
|
86
|
+
/**
|
|
87
|
+
* For `multiSelect`: typed entries are accepted alongside the listed options and kept as their
|
|
88
|
+
* own value, for a set the list only suggests — the keys a record may carry, say.
|
|
89
|
+
*/
|
|
90
|
+
freeSolo?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Groups the field under a labelled separator in the panel: consecutive fields sharing a
|
|
93
|
+
* heading sit together beneath it. Fields without one are listed plainly, so the rule's own
|
|
94
|
+
* columns can lead and the related controls follow in named sections.
|
|
95
|
+
*/
|
|
96
|
+
heading?: string;
|
|
82
97
|
}
|
|
83
98
|
/**
|
|
84
99
|
* The value of a single field, discriminated by `kind`. Stored under the
|
|
@@ -100,6 +115,11 @@ export type DataTableFilterFieldValue = {
|
|
|
100
115
|
} | {
|
|
101
116
|
kind: 'group';
|
|
102
117
|
values: Record<string, string[]>;
|
|
118
|
+
} | {
|
|
119
|
+
kind: 'keyedText';
|
|
120
|
+
key: string | null;
|
|
121
|
+
operator: DataTableFilterOperator;
|
|
122
|
+
value: string;
|
|
103
123
|
};
|
|
104
124
|
/** Full filter state: each field's value keyed by its `id`. */
|
|
105
125
|
export type DataTableFilterState = Record<string, DataTableFilterFieldValue>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useState as
|
|
1
|
+
"use strict";import{useState as S,useRef as M,useEffect as Q,createElement as j}from"react";import{Popover as X,Box as Z,Typography as B,Stack as C,Divider as R,Button as ee,TextField as I,Autocomplete as N,CircularProgress as le,Checkbox as ne,Chip as ae,createFilterOptions as oe}from"@mui/material";import{DeleteOutline as te}from"@mui/icons-material";import{useDebounceValue as ie}from"../../hooks/useDebounceValue.mjs";import{LogoAvatar as re}from"../UI/LogoAvatar.mjs";import{LogoChip as se}from"../UI/LogoChip.mjs";import{SectionLabel as ue}from"../UI/SectionLabel.mjs";import{buildInitialFilterState as ce,emptyFieldValue as pe}from"./DataTable.filterState.mjs";import{jsxs as f,jsx as t,Fragment as U}from"react/jsx-runtime";const D="__select_all__",H=2,Y=[{label:"Yes",value:"true"},{label:"No",value:"false"}],de={contains:"contains",doesNotContain:"does not contain",equals:"equals",doesNotEqual:"does not equal",startsWith:"starts with",endsWith:"ends with",isEmpty:"is empty",isNotEmpty:"is not empty",isAnyOf:"is any of"},G=oe({stringify:n=>`${n.label} ${n.value}`}),P=n=>typeof n=="string"?{label:n,value:n}:n;function he({operators:n,value:h,onChange:p}){return t(N,{size:"small",disableClearable:!0,options:n,getOptionLabel:d=>de[d],value:h,onChange:(d,b)=>p(b),renderInput:d=>t(I,{...d,size:"small",label:"Operator"}),sx:{minWidth:150}})}function K({option:n}){return f(U,{children:[n.logoUrl!==void 0&&t(re,{name:n.label,logoUrl:n.logoUrl,size:24,sx:{mr:1}}),f(B,{variant:"body2",children:[n.label,n.caption&&t(B,{component:"span",variant:"caption",color:"text.secondary",sx:{ml:1},children:n.caption})]})]})}function J({field:n,value:h,onChange:p}){const d=(n.options??[]).map(m=>m.value),b=n.placeholder??"Filter value";return d.length===0?t(I,{size:"small",label:n.label,placeholder:b,value:h,onChange:m=>p(m.target.value),sx:{flex:1,minWidth:200}}):t(N,{freeSolo:!0,autoHighlight:!0,size:"small",options:d,value:h,inputValue:h,onInputChange:(m,g)=>p(g),renderInput:m=>t(I,{...m,size:"small",label:n.label,placeholder:b}),sx:{flex:1,minWidth:200}})}function ve({field:n,options:h,values:p,onChange:d,label:b,pickedOptions:m}){const g=n.loadOptions!==void 0,[k,T]=S(!1),[y,x]=S(""),[V,O]=S([]),[F,w]=S(!1),[E,A]=S(!1),z=ie(y,300),W=M(n.loadOptions);W.current=n.loadOptions;const q=l=>`${n.id}\0${l}`,L=l=>{l.forEach(o=>{m.set(q(o.value),o)})};Q(()=>{const l=W.current;if(!k||l===void 0)return;let o=!0;return w(!0),l(z).then(u=>{o&&(O(u),A(!1))}).catch(()=>{o&&(O([]),A(!0))}).finally(()=>{o&&w(!1)}),()=>{o=!1}},[k,z]);const e=g?V:h,a=h.map(l=>l.value),i=!g&&a.length>0&&a.every(l=>p.includes(l)),s=!g&&h.length>1?[{label:"Select all",value:D},...e]:e,r=p.map(l=>m.get(q(l))??e.find(o=>o.value===l)??{label:l,value:l});return t(N,{multiple:!0,freeSolo:n.freeSolo,clearOnBlur:!0,size:"small",disableCloseOnSelect:!0,open:k,onOpen:()=>T(!0),onClose:()=>{T(!1),x("")},options:s,loading:F,noOptionsText:E?"The options could not be loaded":"No options",getOptionLabel:l=>P(l).label,filterOptions:g?l=>l:G,isOptionEqualToValue:(l,o)=>P(l).value===P(o).value,onInputChange:(l,o,u)=>{g&&u==="input"&&x(o)},value:r,onChange:(l,o)=>{const u=o.map(P).filter(c=>c.value.trim()!=="");if(u.some(c=>c.value===D)){const c=p.filter(v=>!a.includes(v));d(i?c:[...c,...a]);return}L(u),d(u.map(c=>c.value))},renderTags:(l,o)=>{const u=l.slice(0,H).map(P);return f(U,{children:[u.map((c,v)=>{const{key:_,...$}=o({index:v});return c.logoUrl===void 0?j(ae,{...$,key:c.value,size:"small",label:c.label}):j(se,{...$,key:c.value,size:"small",name:c.label,logoUrl:c.logoUrl,label:c.label})}),l.length>H&&f(B,{variant:"body2",color:"text.secondary",sx:{ml:.5},children:["+",l.length-H," more"]})]})},renderOption:(l,o,{selected:u})=>{const{key:c,...v}=l,_=o.value===D?i:u;return f("li",{...v,children:[t(ne,{size:"small",checked:_,sx:{mr:1}}),t(K,{option:o})]},o.value)},renderInput:l=>t(I,{...l,size:"small",label:b,placeholder:p.length===0?n.placeholder:void 0,inputProps:{...l.inputProps,onBlur:o=>{var u,c;const v=n.freeSolo?o.target.value.trim():"";(c=(u=l.inputProps).onBlur)==null||c.call(u,o),v!==""&&!p.includes(v)&&(L([{label:v,value:v}]),d([...p,v]))}},InputProps:{...l.InputProps,endAdornment:f(U,{children:[F&&t(le,{size:16}),l.InputProps.endAdornment]})}}),sx:{flex:1,minWidth:240}})}function me(n){const h=[];return n.forEach(p=>{const d=h.at(-1);d&&d.heading===p.heading?d.fields.push(p):h.push({heading:p.heading,fields:[p]})}),h}function fe({fields:n,pickedOptions:h,filterState:p,onFilterStateChange:d,anchorPosition:b,transformHorizontal:m="left",icons:g={},onClose:k}){const{removeAllFilters:T=te}=g,y=e=>p[e.id]??pe(e),x=(e,a)=>{d({...p,[e.id]:a})},V=()=>{d(ce(n)),k()},O=(e,a,i,s)=>{const r=e.operators??["contains"];return f(C,{direction:"row",spacing:1,useFlexGap:!0,flexWrap:"wrap",sx:{flex:1},children:[s,r.length>1&&t(he,{operators:r,value:a.operator,onChange:l=>i({operator:l})}),t(J,{field:e,value:a.value,onChange:l=>i({value:l})})]})},F=e=>{var a;const i=y(e),s=i.kind==="text"?i:{operator:((a=e.operators)==null?void 0:a[0])??"contains",value:""};return O(e,s,r=>x(e,{kind:"text",...s,...r}))},w=e=>{var a;const i=y(e),s=i.kind==="keyedText"?i:{key:null,operator:((a=e.operators)==null?void 0:a[0])??"contains",value:""},r=l=>{x(e,{kind:"keyedText",...s,...l})};return O(e,s,r,t(J,{field:{...e,label:e.keyLabel??"Key",options:e.keys,placeholder:"Type or pick a key"},value:s.key??"",onChange:l=>r({key:l.trim()===""?null:l})}))},E=(e,a,i,s,r,l)=>t(N,{size:"small",options:a,getOptionLabel:o=>o.label,filterOptions:G,isOptionEqualToValue:(o,u)=>o.value===u.value,value:i,onChange:(o,u)=>s(u),renderOption:(o,u)=>{const{key:c,...v}=o;return t("li",{...v,children:t(K,{option:u})},u.value)},renderInput:o=>t(I,{...o,size:"small",label:e.label,placeholder:r}),sx:{flex:1,minWidth:l}}),A=e=>{var a;const i=y(e),s=i.kind==="select"&&i.value!=null?((a=e.options)==null?void 0:a.find(r=>r.value===i.value))??null:null;return E(e,e.options??[],s,r=>x(e,{kind:"select",value:r?.value??null}),e.placeholder,220)},z=(e,a,i,s,r)=>t(ve,{field:e,options:a,values:i,onChange:s,label:r,pickedOptions:h}),W=e=>{const a=y(e),i=a.kind==="boolean"?a.value:null,s=i===null?null:Y.find(r=>r.value===String(i))??null;return E(e,Y,s,r=>x(e,{kind:"boolean",value:r?r.value==="true":null}),e.placeholder??"Any",200)},q=e=>{const a=y(e),i=a.kind==="group"?a.values:{};return t(C,{spacing:1,sx:{flex:1},children:(e.sections??[]).map(s=>z(e,s.options,i[s.key]??[],r=>x(e,{kind:"group",values:{...i,[s.key]:r}}),s.label))})},L=e=>{switch(e.kind){case"text":return F(e);case"select":return A(e);case"multiSelect":{const a=y(e);return z(e,e.options??[],a.kind==="multiSelect"?a.values:[],i=>x(e,{kind:"multiSelect",values:i}),e.label)}case"boolean":return W(e);case"group":return q(e);case"keyedText":return w(e)}};return f(X,{open:!0,anchorReference:"anchorPosition",anchorPosition:b,transformOrigin:{vertical:"top",horizontal:m},onClose:k,slotProps:{paper:{sx:{display:"flex",flexDirection:"column",maxHeight:"calc(100vh - 32px)"}}},children:[t(Z,{sx:{p:1.5,width:"min(420px, calc(100vw - 32px))",overflowY:"auto",minHeight:0},children:n.length===0?t(B,{variant:"body2",color:"text.secondary",sx:{pl:.5},children:"No filters available."}):t(C,{spacing:2,children:me(n).map(e=>f(C,{spacing:1.5,children:[e.heading!==void 0&&t(R,{textAlign:"left",children:t(ue,{color:"text.secondary",children:e.heading})}),e.fields.map(a=>t(C,{direction:"row",alignItems:"flex-start",children:L(a)},a.id))]},e.fields[0].id))})}),n.length>0&&f(U,{children:[t(R,{}),t(C,{direction:"row",alignItems:"center",justifyContent:"flex-end",sx:{px:1.5,py:.75},children:t(ee,{size:"small",color:"primary",startIcon:t(T,{}),onClick:V,children:"Clear all"})})]})]})}export{fe as DataTableFieldFilterPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Dialog as D,DialogTitle as b,DialogContent as $,DialogContentText as x,DialogActions as k,Button as d,CircularProgress as w}from"@mui/material";import{useHeldWhileClosed as c}from"../hooks/useHeldWhileClosed.mjs";import{useNetworkRulesCatalog as T}from"../hooks/useNetworkRulesCatalog.mjs";import{getKeyLabel as j,getOperatorLabel as L}from"../utils/catalog.mjs";import{
|
|
1
|
+
"use strict";import{Dialog as D,DialogTitle as b,DialogContent as $,DialogContentText as x,DialogActions as k,Button as d,CircularProgress as w}from"@mui/material";import{useHeldWhileClosed as c}from"../hooks/useHeldWhileClosed.mjs";import{useNetworkRulesCatalog as T}from"../hooks/useNetworkRulesCatalog.mjs";import{getKeyLabel as j,getOperatorLabel as L}from"../utils/catalog.mjs";import{jsxs as u,jsx as n}from"react/jsx-runtime";function W(o,e,t){if(t===void 0){const l=e.conditions.length;return`"${e.name}" and its ${l} ${l===1?"condition":"conditions"} will be removed. This cannot be undone.`}const i=e.conditions[t];return`"${i?`${j(o,i.key)} ${L(o,i.operator)} ${i.values.join(", ")}`:`Condition ${t+1}`}" will be removed from "${e.name}". The rule keeps its other conditions.`}function y({open:o,rule:e,conditionIndex:t,onConfirm:i,onClose:l,isDeleting:a=!1,title:m,description:h,confirmLabel:v="Delete",cancelLabel:g="Cancel"}){const{data:p}=T(),r=c(o,e??void 0),s=c(o,t??void 0),C=m??(s!==void 0?"Delete condition?":"Delete rule?"),f=h??(r===void 0?void 0:W(p,r,s));return u(D,{open:o,onClose:a?void 0:l,maxWidth:"xs",fullWidth:!0,children:[n(b,{children:C}),n($,{children:n(x,{children:f})}),u(k,{children:[n(d,{color:"neutral",onClick:l,disabled:a,children:g}),n(d,{color:"error",variant:"contained",disabled:a||r===void 0,startIcon:a?n(w,{size:16,color:"inherit"}):void 0,onClick:()=>{r!==void 0&&i(r,s)},children:v})]})]})}export{y as NetworkRuleDeleteDialog};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useState as V,
|
|
1
|
+
"use strict";import{useState as V,useMemo as z,useEffect as k,useRef as Q}from"react";import{Stack as f,Alert as L,Button as w,TextField as ee,FormControlLabel as re,Switch as oe,CircularProgress as te,Skeleton as C}from"@mui/material";import{zodResolver as ae}from"@hookform/resolvers/zod";import{addDays as ne}from"date-fns";import{useForm as se,useWatch as ie,FormProvider as le,Controller as y}from"react-hook-form";import{useNetworkRuleStatuses as de}from"../NetworkRules.context.mjs";import{useNetworkRulesCatalog as ue}from"../hooks/useNetworkRulesCatalog.mjs";import{getPresets as M}from"../utils/catalog.mjs";import{fromNetworkRuleFormValues as ce,toNetworkRuleFormValues as me,emptyConditionFormValues as fe}from"../utils/condition.mjs";import{ruleDateToDay as he}from"../utils/date.mjs";import{ConditionsField as ve}from"./fields/ConditionsField.mjs";import{DateField as W}from"./fields/DateField.mjs";import{MetadataField as pe}from"./fields/MetadataField.mjs";import{NotesField as ge}from"./fields/NotesField.mjs";import{StatusField as be}from"./fields/StatusField.mjs";import{createNetworkRuleFormSchema as Ce}from"./schema.mjs";import{jsx as e,jsxs as h,Fragment as ye}from"react/jsx-runtime";function A(i,d){const n=me(i);return!(i!=null&&i.uuid)&&!n.name&&d&&(n.name=d),n.conditions.length===0&&(n.conditions=[fe()]),n}function Se(i,d){const n=[],p=[];for(const u of d){const c=u.message??u.code;if(typeof u.index=="number"){const v=`conditions.${u.index}.values`;i.setError(v,{type:"server",message:c}),p.push(v)}else n.push(c)}return n.length>0&&i.setError("root.server",{type:"server",message:n.join(" ")}),p}function xe(){return h(f,{spacing:2,"aria-busy":!0,children:[e(C,{variant:"rounded",height:56}),e(C,{variant:"rounded",height:56}),e(C,{variant:"rounded",height:56}),e(C,{variant:"rounded",height:120})]})}function Fe({rule:i,defaultName:d,canCreatePresets:n=!1,onSubmit:p,onCancel:u,isSubmitting:c=!1,serverErrors:v,focusConditionIndex:I,submitLabel:O="Save",cancelLabel:U="Cancel",disabled:$=!1,id:q,hideActions:G=!1,onDirtyChange:S}){var E,D;const g=ue(),s=g.data,H=de()??s?.statuses??[],b=i?.uuid??"new",[R,J]=V(b),K=z(()=>ae(Ce(s?.metadata)),[s]),t=se({defaultValues:A(i,d),resolver:K,mode:"onSubmit",reValidateMode:"onChange"}),[m,P]=V({});k(()=>{b!==R&&(t.reset(A(i,d)),P({}),J(b))},[t,i,d,b,R]);const x=Q([]);k(()=>{t.clearErrors("root.server"),x.current.length>0&&t.clearErrors(x.current),x.current=Se(t,v??[])},[t,v]);const{isDirty:N}=t.formState;k(()=>{S?.(N)},[N,S]);const l=$||c,T=(D=(E=t.formState.errors.root)==null?void 0:E.server)==null?void 0:D.message,X=ie({control:t.control,name:"startDate"}),B=he(X),Y=B?ne(B,1):void 0,Z=z(()=>M(s,"notes",m),[s,m]),F=(r,a)=>{P(o=>{const j=o[r]??[];return j.includes(a)?o:{...o,[r]:[...j,a]}})},_=t.handleSubmit(async r=>{if(s===void 0)return;const a=Object.fromEntries(Object.keys(m).map(o=>[o,M(s,o,m)]));await p(ce(r),{presets:a})});return e(le,{...t,children:e("form",{id:q,noValidate:!0,onSubmit:r=>{r.preventDefault(),r.stopPropagation(),_(r)},children:h(f,{spacing:3,children:[g.isError&&e(L,{severity:"error",action:e(w,{color:"inherit",size:"small",onClick:()=>{g.refetch()},children:"Retry"}),children:"The rule catalog could not be loaded."}),T&&e(L,{severity:"error",children:T}),s===void 0?!g.isError&&e(xe,{}):h(ye,{children:[h(f,{direction:{xs:"column",md:"row"},spacing:2,children:[e(y,{control:t.control,name:"name",render:({field:r,fieldState:a})=>{var o;return e(ee,{...r,label:"Rule Name",required:!0,fullWidth:!0,disabled:l,error:a.error!==void 0,helperText:(o=a.error)==null?void 0:o.message,sx:{flex:2}})}}),e(f,{flex:1,minWidth:{md:220},children:e(be,{statuses:H,disabled:l})})]}),h(f,{direction:{xs:"column",md:"row"},spacing:2,children:[e(y,{control:t.control,name:"startDate",render:({field:r,fieldState:a})=>{var o;return e(W,{label:"Starts",value:r.value,onChange:r.onChange,onBlur:r.onBlur,disabled:l,error:a.error!==void 0,helperText:((o=a.error)==null?void 0:o.message)??"Starts applying at the start of this day (UTC)"})}}),e(y,{control:t.control,name:"endDate",render:({field:r,fieldState:a})=>{var o;return e(W,{label:"Ends",value:r.value,onChange:r.onChange,onBlur:r.onBlur,disabled:l,minDate:Y,error:a.error!==void 0,helperText:((o=a.error)==null?void 0:o.message)??"Stops applying at the start of this day (UTC)"})}})]}),e(ge,{presets:Z,onCreatePreset:n?r=>{F("notes",r)}:void 0,disabled:l}),e(y,{control:t.control,name:"enabled",render:({field:r})=>e(re,{label:"Enabled",control:e(oe,{checked:r.value,onChange:(a,o)=>{r.onChange(o)},onBlur:r.onBlur,inputRef:r.ref,disabled:l})})}),e(ve,{catalog:s,addedPresets:m,onCreatePreset:n?F:void 0,disabled:l,focusIndex:I}),e(pe,{catalog:s,addedPresets:m,onCreatePreset:n?F:void 0,disabled:l})]}),!G&&h(f,{direction:"row",spacing:1,justifyContent:"flex-end",children:[u&&e(w,{onClick:u,disabled:c,children:U}),e(w,{type:"submit",variant:"contained",disabled:l||s===void 0,startIcon:c?e(te,{size:16,color:"inherit"}):void 0,children:O})]})]})})})}export{Fe as NetworkRuleEditorForm};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Stack as
|
|
1
|
+
"use strict";import{Stack as C,Typography as j,TextField as S,MenuItem as b,IconButton as O}from"@mui/material";import{Delete as P}from"@mui/icons-material";import{useFormContext as q,useController as h,useWatch as K}from"react-hook-form";import{getKeyDef as k,isOperatorMulti as $,getPresets as M,getOperatorLabel as z}from"../../utils/catalog.mjs";import{ConditionValuesInput as A}from"./ConditionValuesInput.mjs";import{jsxs as H,jsx as l}from"react/jsx-runtime";function L({index:o,catalog:a,onRemove:D,addedPresets:R,onCreatePreset:v,canRemove:w=!0,disabled:s=!1,autoFocus:B}){var p,g,x;const{control:d,setValue:u,formState:I}=q(),i=h({control:d,name:`conditions.${o}.key`}),r=h({control:d,name:`conditions.${o}.operator`}),m=h({control:d,name:`conditions.${o}.values`}),c=K({control:d,name:`conditions.${o}.values`})??[],t=k(a,i.field.value),T=t?.operators??[],V=$(a,r.field.value),f=I.isSubmitted,W=t?M(a,t.key,R):[],F=e=>{var n;i.field.onChange(e);const y=((n=k(a,e))==null?void 0:n.operators)??[];u(`conditions.${o}.operator`,y.length===1?y[0]:"",{shouldDirty:!0,shouldValidate:f}),u(`conditions.${o}.values`,[],{shouldDirty:!0,shouldValidate:f})};return H(C,{direction:{xs:"column",md:"row"},spacing:1.5,alignItems:"flex-start",children:[l(j,{fontSize:20,fontWeight:300,sx:{display:"flex",alignItems:"center",justifyContent:{md:"flex-end"},minHeight:{md:56},minWidth:{md:48},flexShrink:0},children:o===0?"IF":"AND"}),l(S,{select:!0,required:!0,label:"Key",value:i.field.value,onChange:e=>{F(e.target.value)},onBlur:i.field.onBlur,inputRef:i.field.ref,disabled:s,autoFocus:B,error:i.fieldState.error!==void 0,helperText:(p=i.fieldState.error)==null?void 0:p.message,sx:{minWidth:{md:200},width:{xs:"100%",md:"auto"}},children:a.keys.map(e=>l(b,{value:e.key,children:e.label},e.key))}),l(S,{select:!0,required:!0,label:"Operator",value:r.field.value,onChange:e=>{const n=e.target.value;r.field.onChange(n),!$(a,n)&&c.length>1&&u(`conditions.${o}.values`,c.slice(0,1),{shouldDirty:!0,shouldValidate:f})},onBlur:r.field.onBlur,inputRef:r.field.ref,disabled:s||t===void 0,error:r.fieldState.error!==void 0,helperText:(g=r.fieldState.error)==null?void 0:g.message,sx:{minWidth:{md:180},width:{xs:"100%",md:"auto"}},children:T.map(e=>l(b,{value:e,children:z(a,e)},e))}),l(C,{flex:1,width:"100%",minWidth:0,children:l(A,{keyDef:t,multi:V,values:c,onChange:e=>{m.field.onChange(e)},presets:W,onCreatePreset:v&&t?e=>{v(t.key,e)}:void 0,disabled:s||r.field.value==="",error:m.fieldState.error!==void 0,helperText:(x=m.fieldState.error)==null?void 0:x.message})}),l(O,{"aria-label":`Remove condition ${o+1}`,color:"error",onClick:D,disabled:s||!w,sx:{mt:{md:1}},children:l(P,{})})]})}export{L as ConditionRow};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NetworkRuleCatalog } from '../../types';
|
|
2
|
+
export interface MetadataFieldProps {
|
|
3
|
+
catalog: NetworkRuleCatalog;
|
|
4
|
+
addedPresets?: Readonly<Record<string, readonly string[]>>;
|
|
5
|
+
onCreatePreset?: (field: string, value: string) => void;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Typed key/value pairs returned with the decision. Optional: a rule may have none, and a catalog
|
|
10
|
+
* without `metadata` offers no section at all, as the filter panel offers no controls.
|
|
11
|
+
*/
|
|
12
|
+
export declare function MetadataField({ catalog, addedPresets, onCreatePreset, disabled, }: Readonly<MetadataFieldProps>): import("react").JSX.Element | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";import{Stack as c,Typography as u,Button as k,FormHelperText as w}from"@mui/material";import{Add as R}from"@mui/icons-material";import{useFormContext as T,useFieldArray as b}from"react-hook-form";import{getPresets as h}from"../../utils/catalog.mjs";import{NETWORK_RULE_METADATA_PRESET_FIELDS as y,emptyMetadataFormValues as C}from"../../utils/metadata.mjs";import{MetadataRow as S}from"./MetadataRow.mjs";import{jsxs as f,jsx as e}from"react/jsx-runtime";function _({catalog:a,addedPresets:o,onCreatePreset:g,disabled:s=!1}){var d,n,i;const{control:v,formState:m}=T(),{fields:r,append:x,remove:P}=b({control:v,name:"metadata"}),{metadata:t}=a;if(t===void 0)return null;const l=((n=(d=m.errors.metadata)==null?void 0:d.root)==null?void 0:n.message)??((i=m.errors.metadata)==null?void 0:i.message),A=h(a,y.key,o),E=h(a,y.value,o),F=r.length>=t.limits.maxEntries;return f(c,{spacing:2,children:[f(c,{direction:"row",justifyContent:"space-between",alignItems:"center",children:[e(u,{fontWeight:700,children:"Metadata"}),e(k,{startIcon:e(R,{}),disabled:s||F,onClick:()=>{x(C(t.types[0]))},children:"Add Metadata"})]}),r.length===0&&e(u,{variant:"body2",color:"text.secondary",children:"No metadata yet. Pairs added here are returned with the network status so your app can act on them."}),r.map((M,p)=>e(S,{index:p,types:t.types,limits:t.limits,keyPresets:A,valuePresets:E,onCreatePreset:g,disabled:s,onRemove:()=>{P(p)}},M.id)),l&&e(w,{error:!0,children:l})]})}export{_ as MetadataField};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { NetworkRuleMetadataLimits, NetworkRuleMetadataType } from '../../types';
|
|
2
|
+
export interface MetadataRowProps {
|
|
3
|
+
index: number;
|
|
4
|
+
onRemove: () => void;
|
|
5
|
+
types: readonly NetworkRuleMetadataType[];
|
|
6
|
+
limits: NetworkRuleMetadataLimits;
|
|
7
|
+
keyPresets?: readonly string[];
|
|
8
|
+
valuePresets?: readonly string[];
|
|
9
|
+
/** Called with the preset field the value belongs to, as `ConditionRow` does with its key. */
|
|
10
|
+
onCreatePreset?: (field: string, value: string) => void;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** One `key: value` pair. No IF/AND: metadata is carried along, not matched on. */
|
|
14
|
+
export declare function MetadataRow({ index, onRemove, types, limits, keyPresets, valuePresets, onCreatePreset, disabled, }: Readonly<MetadataRowProps>): import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";import{Stack as f,TextField as h,MenuItem as y,IconButton as w}from"@mui/material";import{Delete as D}from"@mui/icons-material";import{useFormContext as M,useController as p}from"react-hook-form";import{NETWORK_RULE_METADATA_PRESET_FIELDS as P,metadataTypeLabel as N,NETWORK_RULE_METADATA_BOOLEAN_OPTIONS as V,isPartialNumberInput as S}from"../../utils/metadata.mjs";import{PresetTextInput as E}from"./PresetTextInput.mjs";import{jsxs as R,jsx as a}from"react/jsx-runtime";function $({index:i,onRemove:k,types:L,limits:c,keyPresets:_=[],valuePresets:A=[],onCreatePreset:v,disabled:d=!1}){var g,x,b;const{control:u,setValue:B,formState:W}=M(),r=p({control:u,name:`metadata.${i}.key`}),o=p({control:u,name:`metadata.${i}.type`}),t=p({control:u,name:`metadata.${i}.value`}),n=o.field.value,l=t.field.value,I=W.isSubmitted,C=(g=t.fieldState.error)==null?void 0:g.message,m={required:!0,label:"Value",onBlur:t.field.onBlur,inputRef:t.field.ref,disabled:d,error:C!==void 0,helperText:C},T=e=>v?s=>{v(e,s)}:void 0,O=e=>{o.field.onChange(e),e==="string"||e==="number"&&S(l)||e==="boolean"&&(l==="true"||l==="false")||B(`metadata.${i}.value`,"",{shouldDirty:!0,shouldValidate:I})};return R(f,{direction:{xs:"column",md:"row"},spacing:1.5,alignItems:"flex-start",children:[a(f,{sx:{minWidth:{md:200},width:{xs:"100%",md:"auto"}},children:a(E,{label:"Key",required:!0,value:r.field.value,onChange:r.field.onChange,onBlur:r.field.onBlur,inputRef:r.field.ref,presets:_,onCreatePreset:T(P.key),maxLength:c.maxKeyLength,placeholder:"Pick a preset or type a key",disabled:d,error:r.fieldState.error!==void 0,helperText:(x=r.fieldState.error)==null?void 0:x.message})}),a(h,{select:!0,required:!0,label:"Type",value:n,onChange:e=>{O(e.target.value)},onBlur:o.field.onBlur,inputRef:o.field.ref,disabled:d,error:o.fieldState.error!==void 0,helperText:(b=o.fieldState.error)==null?void 0:b.message,sx:{minWidth:{md:140},width:{xs:"100%",md:"auto"}},children:L.map(e=>a(y,{value:e,children:N(e)},e))}),R(f,{flex:1,width:"100%",minWidth:0,children:[n==="boolean"&&a(h,{...m,select:!0,fullWidth:!0,value:l==="true"||l==="false"?l:"",onChange:e=>{t.field.onChange(e.target.value)},children:V.map(e=>a(y,{value:e.value,children:e.label},e.value))}),n==="number"&&a(h,{...m,fullWidth:!0,value:l,onChange:e=>{const s=e.target.value;S(s)&&t.field.onChange(s)},placeholder:"Type a number",inputProps:{inputMode:"decimal"}}),n==="string"&&a(E,{...m,value:l,onChange:t.field.onChange,presets:A,onCreatePreset:T(P.value),maxLength:c.maxValueLength,placeholder:"Pick a preset or type a value"})]}),a(w,{"aria-label":`Remove metadata ${i+1}`,color:"error",onClick:k,disabled:d,sx:{mt:{md:1}},children:a(D,{})})]})}export{$ as MetadataRow};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Ref } from 'react';
|
|
2
|
+
export interface PresetTextInputProps {
|
|
3
|
+
label: string;
|
|
4
|
+
value: string;
|
|
5
|
+
onChange: (value: string) => void;
|
|
6
|
+
onBlur?: () => void;
|
|
7
|
+
presets?: readonly string[];
|
|
8
|
+
onCreatePreset?: (value: string) => void;
|
|
9
|
+
maxLength?: number;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
error?: boolean;
|
|
14
|
+
helperText?: string;
|
|
15
|
+
inputRef?: Ref<HTMLInputElement>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A single free-text value with the brand's presets as suggestions; the chip-based
|
|
19
|
+
* `TextValuesInput` is for a condition's several values. Leaving the field keeps the text but
|
|
20
|
+
* creates no preset — see the note in `presetOptions.ts` before changing that.
|
|
21
|
+
*/
|
|
22
|
+
export declare function PresetTextInput({ label, value, onChange, onBlur, presets, onCreatePreset, maxLength, placeholder, required, disabled, error, helperText, inputRef, }: Readonly<PresetTextInputProps>): import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";import{Autocomplete as c,TextField as O}from"@mui/material";import{presetOptionLabel as n,filterPresetOptions as T}from"./presetOptions.mjs";import{jsx as i}from"react/jsx-runtime";function P({label:a,value:l,onChange:r,onBlur:p,presets:s=[],onCreatePreset:o,maxLength:u,placeholder:d,required:h,disabled:f,error:m,helperText:g,inputRef:x}){return i(c,{freeSolo:!0,autoHighlight:!0,selectOnFocus:!0,handleHomeEndKeys:!0,options:s,value:l,inputValue:l,disabled:f,getOptionLabel:n,isOptionEqualToValue:(t,e)=>n(t)===n(e),filterOptions:(t,e)=>T(t,e,o!==void 0),onInputChange:(t,e,b)=>{b!=="reset"&&r(e)},onChange:(t,e)=>{e===null?r(""):typeof e=="string"?r(e):(r(e.inputValue),o?.(e.inputValue))},onBlur:p,renderInput:t=>i(O,{...t,label:a,required:h,placeholder:d,error:m,helperText:g,inputRef:x,inputProps:{...t.inputProps,maxLength:u}})})}export{P as PresetTextInput};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { NetworkRuleCatalogMetadata, NetworkRuleMetadataType } from '../types';
|
|
2
3
|
export declare const networkRuleConditionFormSchema: z.ZodObject<{
|
|
3
4
|
key: z.ZodString;
|
|
4
5
|
operator: z.ZodString;
|
|
@@ -12,13 +13,34 @@ export declare const networkRuleConditionFormSchema: z.ZodObject<{
|
|
|
12
13
|
operator: string;
|
|
13
14
|
values: string[];
|
|
14
15
|
}>;
|
|
15
|
-
export declare
|
|
16
|
+
export declare function createNetworkRuleFormSchema(metadata: NetworkRuleCatalogMetadata | undefined): z.ZodEffects<z.ZodObject<{
|
|
16
17
|
name: z.ZodString;
|
|
17
18
|
status: z.ZodString;
|
|
18
19
|
notes: z.ZodNullable<z.ZodString>;
|
|
19
20
|
enabled: z.ZodBoolean;
|
|
20
21
|
startDate: z.ZodNullable<z.ZodString>;
|
|
21
22
|
endDate: z.ZodNullable<z.ZodString>;
|
|
23
|
+
metadata: z.ZodArray<z.ZodEffects<z.ZodObject<{
|
|
24
|
+
key: z.ZodString;
|
|
25
|
+
type: z.ZodEnum<[NetworkRuleMetadataType, ...NetworkRuleMetadataType[]]>;
|
|
26
|
+
value: z.ZodString;
|
|
27
|
+
}, "strip", z.ZodTypeAny, {
|
|
28
|
+
key: string;
|
|
29
|
+
type: NetworkRuleMetadataType;
|
|
30
|
+
value: string;
|
|
31
|
+
}, {
|
|
32
|
+
key: string;
|
|
33
|
+
type: NetworkRuleMetadataType;
|
|
34
|
+
value: string;
|
|
35
|
+
}>, {
|
|
36
|
+
key: string;
|
|
37
|
+
type: NetworkRuleMetadataType;
|
|
38
|
+
value: string;
|
|
39
|
+
}, {
|
|
40
|
+
key: string;
|
|
41
|
+
type: NetworkRuleMetadataType;
|
|
42
|
+
value: string;
|
|
43
|
+
}>, "many"> | z.ZodArray<z.ZodNever, "many">;
|
|
22
44
|
conditions: z.ZodArray<z.ZodObject<{
|
|
23
45
|
key: z.ZodString;
|
|
24
46
|
operator: z.ZodString;
|
|
@@ -33,6 +55,11 @@ export declare const networkRuleFormSchema: z.ZodEffects<z.ZodObject<{
|
|
|
33
55
|
values: string[];
|
|
34
56
|
}>, "many">;
|
|
35
57
|
}, "strip", z.ZodTypeAny, {
|
|
58
|
+
metadata: never[] | {
|
|
59
|
+
key: string;
|
|
60
|
+
type: NetworkRuleMetadataType;
|
|
61
|
+
value: string;
|
|
62
|
+
}[];
|
|
36
63
|
name: string;
|
|
37
64
|
status: string;
|
|
38
65
|
enabled: boolean;
|
|
@@ -45,6 +72,11 @@ export declare const networkRuleFormSchema: z.ZodEffects<z.ZodObject<{
|
|
|
45
72
|
values: string[];
|
|
46
73
|
}[];
|
|
47
74
|
}, {
|
|
75
|
+
metadata: never[] | {
|
|
76
|
+
key: string;
|
|
77
|
+
type: NetworkRuleMetadataType;
|
|
78
|
+
value: string;
|
|
79
|
+
}[];
|
|
48
80
|
name: string;
|
|
49
81
|
status: string;
|
|
50
82
|
enabled: boolean;
|
|
@@ -57,6 +89,11 @@ export declare const networkRuleFormSchema: z.ZodEffects<z.ZodObject<{
|
|
|
57
89
|
values: string[];
|
|
58
90
|
}[];
|
|
59
91
|
}>, {
|
|
92
|
+
metadata: never[] | {
|
|
93
|
+
key: string;
|
|
94
|
+
type: NetworkRuleMetadataType;
|
|
95
|
+
value: string;
|
|
96
|
+
}[];
|
|
60
97
|
name: string;
|
|
61
98
|
status: string;
|
|
62
99
|
enabled: boolean;
|
|
@@ -69,6 +106,11 @@ export declare const networkRuleFormSchema: z.ZodEffects<z.ZodObject<{
|
|
|
69
106
|
values: string[];
|
|
70
107
|
}[];
|
|
71
108
|
}, {
|
|
109
|
+
metadata: never[] | {
|
|
110
|
+
key: string;
|
|
111
|
+
type: NetworkRuleMetadataType;
|
|
112
|
+
value: string;
|
|
113
|
+
}[];
|
|
72
114
|
name: string;
|
|
73
115
|
status: string;
|
|
74
116
|
enabled: boolean;
|
|
@@ -81,4 +123,4 @@ export declare const networkRuleFormSchema: z.ZodEffects<z.ZodObject<{
|
|
|
81
123
|
values: string[];
|
|
82
124
|
}[];
|
|
83
125
|
}>;
|
|
84
|
-
export type NetworkRuleFormSchema = z.infer<typeof
|
|
126
|
+
export type NetworkRuleFormSchema = z.infer<ReturnType<typeof createNetworkRuleFormSchema>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{z as e}from"zod";const a=e.object({key:e.string().min(1,"Select a key"),operator:e.string().min(1,"Select an operator"),values:e.array(e.string().trim().min(1,"Values cannot be empty")).min(1,"Add at least one value")})
|
|
1
|
+
"use strict";import{z as e}from"zod";import{isNumberValue as l,isExactNumberValue as d,NETWORK_RULE_METADATA_TYPES as c}from"../utils/metadata.mjs";const y=a=>a.length>0?a:c,b=({types:a,limits:{maxKeyLength:s,maxValueLength:i}})=>e.object({key:e.string().trim().min(1,"Key is required").max(s,`Key must be at most ${s} characters`),type:e.enum(y(a)),value:e.string()}).superRefine((n,m)=>{const r=n.value.trim(),t=u=>{m.addIssue({code:e.ZodIssueCode.custom,path:["value"],message:u})};if(!r){t("Value is required");return}n.type==="string"&&r.length>i&&t(`Value must be at most ${i} characters`),n.type==="number"&&(l(r)?d(r)||t("Too many digits to keep as a number. Use the String type instead"):t("Value must be a number")),n.type==="boolean"&&r!=="true"&&r!=="false"&&t("Select True or False")}),o=e.object({key:e.string().min(1,"Select a key"),operator:e.string().min(1,"Select an operator"),values:e.array(e.string().trim().min(1,"Values cannot be empty")).min(1,"Add at least one value")});function g(a){return e.object({name:e.string().trim().min(1,"Rule name is required"),status:e.string().min(1,"Select a status"),notes:e.string().nullable(),enabled:e.boolean(),startDate:e.string().nullable(),endDate:e.string().nullable(),metadata:a?e.array(b(a)).max(a.limits.maxEntries,`A rule may have at most ${a.limits.maxEntries} metadata entries`):e.array(e.never()).max(0,"Metadata is not available"),conditions:e.array(o).min(1,"Add at least one condition")}).superRefine((s,i)=>{const n=new Set;s.metadata.forEach((m,r)=>{const t=m.key.trim().toLowerCase();if(t){if(n.has(t)){i.addIssue({code:e.ZodIssueCode.custom,path:["metadata",r,"key"],message:"Key already used"});return}n.add(t)}}),s.startDate!==null&&s.endDate!==null&&s.endDate<=s.startDate&&i.addIssue({code:e.ZodIssueCode.custom,path:["endDate"],message:"End must be after start"})})}export{g as createNetworkRuleFormSchema,o as networkRuleConditionFormSchema};
|
|
@@ -15,7 +15,7 @@ export interface NetworkRulesDeletionState {
|
|
|
15
15
|
conditionIndex?: number;
|
|
16
16
|
}
|
|
17
17
|
/** Table callbacks wired to the dialogs; `onToggleEnabled` stays with the consumer. */
|
|
18
|
-
export type NetworkRulesDialogTableHandlers = Required<Pick<NetworkRuleRowHandlers, 'onEdit' | 'onDelete'
|
|
18
|
+
export type NetworkRulesDialogTableHandlers = Required<Pick<NetworkRuleRowHandlers, 'onEdit' | 'onDelete'>>;
|
|
19
19
|
export type NetworkRulesEditorDialogProps = Pick<NetworkRuleEditorDialogProps, 'open' | 'rule' | 'focusConditionIndex' | 'serverErrors' | 'onClose'>;
|
|
20
20
|
export type NetworkRulesDeleteDialogProps = Pick<NetworkRuleDeleteDialogProps, 'open' | 'rule' | 'conditionIndex' | 'onClose'>;
|
|
21
21
|
export interface UseNetworkRulesDialogsResult {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useState as
|
|
1
|
+
"use strict";import{useState as C,useCallback as o,useMemo as v}from"react";function b(){const[n,t]=C({open:!1}),[r,s]=C({open:!1}),[d,i]=C(),x=o(()=>{i(void 0),t({open:!0})},[]),l=o(e=>{i(void 0),t({open:!0,rule:e})},[]),D=o((e,c)=>{i(void 0),t({open:!0,rule:e,focusConditionIndex:c})},[]),u=o(()=>{i(void 0),t(e=>({...e,open:!1}))},[]),p=o(e=>{s({open:!0,rule:e})},[]),E=o((e,c)=>{s({open:!0,rule:e,conditionIndex:c})},[]),a=o(()=>{s(e=>({...e,open:!1}))},[]),I=v(()=>({onEdit:l,onDelete:p}),[l,p]),f=v(()=>({open:n.open,rule:n.rule,focusConditionIndex:n.focusConditionIndex,serverErrors:d,onClose:u}),[n,d,u]),g=v(()=>({open:r.open,rule:r.rule,conditionIndex:r.conditionIndex,onClose:a}),[r,a]);return{editor:n,deletion:r,serverErrors:d,setServerErrors:i,openCreate:x,openEdit:l,openEditCondition:D,closeEditor:u,requestDeleteRule:p,requestDeleteCondition:E,closeDeletion:a,tableHandlers:I,editorDialogProps:f,deleteDialogProps:g}}export{b as useNetworkRulesDialogs};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{NETWORK_RULE_STATUSES as e,getStatusPresentation as
|
|
1
|
+
"use strict";import{NETWORK_RULE_STATUSES as e,getStatusPresentation as a}from"./statuses.mjs";import{NetworkRulesProvider as s,useNetworkRuleStatuses as t,useNetworkRulesServices as o}from"./NetworkRules.context.mjs";import{ConditionValuesInput as r}from"./editor/fields/ConditionValuesInput.mjs";import{DateField as l}from"./editor/fields/DateField.mjs";import{NETWORK_RULES_COLUMN_IDS as u,buildNetworkRulesColumns as i}from"./table/columns.mjs";import{NETWORK_RULES_FILTER_IDS as m,NETWORK_RULES_TEXT_OPERATORS as R,buildNetworkRulesFilterFields as N,conditionFilterId as d,conditionFilterKey as p}from"./table/filters.mjs";import{NETWORK_RULE_METADATA_BOOLEAN_OPTIONS as E,NETWORK_RULE_METADATA_PRESET_FIELDS as n,NETWORK_RULE_METADATA_TYPES as T,emptyMetadataFormValues as w,formatMetadataValue as k,fromMetadataFormValues as S,isExactNumberValue as _,isNumberValue as O,isPartialNumberInput as f,metadataTypeLabel as D,toMetadataFormValues as F,typeOfMetadataValue as L}from"./utils/metadata.mjs";import{NetworkRuleConditionsTable as b}from"./table/NetworkRuleConditionsTable.mjs";import{NetworkRuleDeleteDialog as g}from"./dialog/NetworkRuleDeleteDialog.mjs";import{NetworkRuleDiscardDialog as A}from"./dialog/NetworkRuleDiscardDialog.mjs";import{NetworkRuleEditorDialog as V}from"./editor/NetworkRuleEditorDialog.mjs";import{NetworkRuleEditorForm as y}from"./editor/NetworkRuleEditorForm.mjs";import{NetworkRuleExpandedPanel as C}from"./table/NetworkRuleExpandedPanel.mjs";import{NetworkRuleMetadataTable as c}from"./table/NetworkRuleMetadataTable.mjs";import{NetworkRuleRow as K}from"./table/NetworkRuleRow.mjs";import{NetworkRulesTable as M}from"./table/NetworkRulesTable.mjs";import{NetworkStatusChip as I}from"./shared/NetworkStatusChip.mjs";import{OptionChips as P}from"./shared/OptionChips.mjs";import{buildNetworkRulesListQuery as U}from"./table/query.mjs";import{createNetworkRuleFormSchema as h,networkRuleConditionFormSchema as W}from"./editor/schema.mjs";import{dayToRuleDate as v,formatRuleDate as x,ruleDateToDay as Q}from"./utils/date.mjs";import{dedupeValues as B,emptyConditionFormValues as X,fromNetworkRuleFormValues as H,toNetworkRuleFormValues as Y}from"./utils/condition.mjs";import{getKeyDef as j,getKeyLabel as z,getOperatorLabel as J,getPresets as $,getStatusLabel as q,hasInlineOptions as G,hasRemoteSource as Z,isOperatorMulti as ee,toOptions as ae}from"./utils/catalog.mjs";import{networkRulesCatalogQueryKey as se,useNetworkRulesCatalog as te}from"./hooks/useNetworkRulesCatalog.mjs";import{useHeldWhileClosed as oe}from"./hooks/useHeldWhileClosed.mjs";import{useNetworkRuleSourceSearch as re}from"./hooks/useNetworkRuleSourceSearch.mjs";import{useNetworkRulesDialogs as le}from"./hooks/useNetworkRulesDialogs.mjs";import{useResolvedConditionOptions as ue}from"./hooks/useResolvedConditionOptions.mjs";export{r as ConditionValuesInput,l as DateField,u as NETWORK_RULES_COLUMN_IDS,m as NETWORK_RULES_FILTER_IDS,R as NETWORK_RULES_TEXT_OPERATORS,E as NETWORK_RULE_METADATA_BOOLEAN_OPTIONS,n as NETWORK_RULE_METADATA_PRESET_FIELDS,T as NETWORK_RULE_METADATA_TYPES,e as NETWORK_RULE_STATUSES,b as NetworkRuleConditionsTable,g as NetworkRuleDeleteDialog,A as NetworkRuleDiscardDialog,V as NetworkRuleEditorDialog,y as NetworkRuleEditorForm,C as NetworkRuleExpandedPanel,c as NetworkRuleMetadataTable,K as NetworkRuleRow,s as NetworkRulesProvider,M as NetworkRulesTable,I as NetworkStatusChip,P as OptionChips,i as buildNetworkRulesColumns,N as buildNetworkRulesFilterFields,U as buildNetworkRulesListQuery,d as conditionFilterId,p as conditionFilterKey,h as createNetworkRuleFormSchema,v as dayToRuleDate,B as dedupeValues,X as emptyConditionFormValues,w as emptyMetadataFormValues,k as formatMetadataValue,x as formatRuleDate,S as fromMetadataFormValues,H as fromNetworkRuleFormValues,j as getKeyDef,z as getKeyLabel,J as getOperatorLabel,$ as getPresets,q as getStatusLabel,a as getStatusPresentation,G as hasInlineOptions,Z as hasRemoteSource,_ as isExactNumberValue,O as isNumberValue,ee as isOperatorMulti,f as isPartialNumberInput,D as metadataTypeLabel,W as networkRuleConditionFormSchema,se as networkRulesCatalogQueryKey,Q as ruleDateToDay,F as toMetadataFormValues,Y as toNetworkRuleFormValues,ae as toOptions,L as typeOfMetadataValue,oe as useHeldWhileClosed,re as useNetworkRuleSourceSearch,t as useNetworkRuleStatuses,te as useNetworkRulesCatalog,le as useNetworkRulesDialogs,o as useNetworkRulesServices,ue as useResolvedConditionOptions};
|
|
@@ -2,8 +2,5 @@ import { NetworkRule, NetworkRuleCatalog } from '../types';
|
|
|
2
2
|
export interface NetworkRuleConditionsTableProps {
|
|
3
3
|
rule: NetworkRule;
|
|
4
4
|
catalog?: NetworkRuleCatalog;
|
|
5
|
-
readOnly?: boolean;
|
|
6
|
-
onEditCondition?: (rule: NetworkRule, index: number) => void;
|
|
7
|
-
onDeleteCondition?: (rule: NetworkRule, index: number) => void;
|
|
8
5
|
}
|
|
9
|
-
export declare function NetworkRuleConditionsTable({ rule, catalog,
|
|
6
|
+
export declare function NetworkRuleConditionsTable({ rule, catalog, }: Readonly<NetworkRuleConditionsTableProps>): import("react").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{
|
|
1
|
+
"use strict";import{Typography as c,Table as p,TableHead as h,TableRow as s,TableCell as a,TableBody as m,Chip as b,Skeleton as y}from"@mui/material";import{useResolvedConditionOptions as f}from"../hooks/useResolvedConditionOptions.mjs";import{OptionChips as g}from"../shared/OptionChips.mjs";import{getKeyDef as u,getKeyLabel as w,getOperatorLabel as x}from"../utils/catalog.mjs";import{jsx as e,jsxs as n}from"react/jsx-runtime";function T({condition:o,catalog:i}){const r=u(i,o.key),{options:t,isLoading:l,service:d}=f(r,o.values);return n(s,{children:[e(a,{sx:{whiteSpace:"nowrap"},children:e(b,{label:w(i,o.key)})}),e(a,{sx:{whiteSpace:"nowrap"},children:x(i,o.operator)}),e(a,{sx:{width:"100%"},children:l?e(y,{variant:"text",width:160}):e(g,{options:t,withLogo:d!==void 0})})]})}function C({rule:o,catalog:i}){return o.conditions.length===0?e(c,{variant:"body2",color:"text.secondary",children:"No conditions"}):n(p,{"aria-label":`Conditions for ${o.name}`,children:[e(h,{children:n(s,{children:[e(a,{children:"Key"}),e(a,{children:"Operator"}),e(a,{children:"Values"})]})}),e(m,{children:o.conditions.map((r,t)=>e(T,{condition:r,catalog:i},`${r.key}-${r.operator}-${t}`))})]})}export{C as NetworkRuleConditionsTable};
|
|
@@ -3,12 +3,10 @@ export interface NetworkRuleRowHandlers {
|
|
|
3
3
|
onToggleEnabled?: (rule: NetworkRule, enabled: boolean) => void;
|
|
4
4
|
onEdit?: (rule: NetworkRule) => void;
|
|
5
5
|
onDelete?: (rule: NetworkRule) => void;
|
|
6
|
-
onEditCondition?: (rule: NetworkRule, index: number) => void;
|
|
7
|
-
onDeleteCondition?: (rule: NetworkRule, index: number) => void;
|
|
8
6
|
}
|
|
9
7
|
export interface NetworkRuleExpandedPanelProps extends NetworkRuleRowHandlers {
|
|
10
8
|
rule: NetworkRule;
|
|
11
9
|
catalog?: NetworkRuleCatalog;
|
|
12
10
|
readOnly?: boolean;
|
|
13
11
|
}
|
|
14
|
-
export declare function NetworkRuleExpandedPanel({ rule, catalog, readOnly, onEdit, onDelete,
|
|
12
|
+
export declare function NetworkRuleExpandedPanel({ rule, catalog, readOnly, onEdit, onDelete, }: Readonly<NetworkRuleExpandedPanelProps>): import("react").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Stack as
|
|
1
|
+
"use strict";import{Stack as a,Button as l,Typography as i}from"@mui/material";import{Edit as p,Delete as m}from"@mui/icons-material";import{CopyableUuid as h}from"../../CopyableUuid/index.mjs";import{SectionLabel as c}from"../../UI/SectionLabel.mjs";import{NetworkRuleConditionsTable as u}from"./NetworkRuleConditionsTable.mjs";import{NetworkRuleMetadataTable as x}from"./NetworkRuleMetadataTable.mjs";import{jsxs as o,jsx as t}from"react/jsx-runtime";function f({rule:e,catalog:d,readOnly:s=!1,onEdit:n,onDelete:r}){return o(a,{spacing:2,useFlexGap:!0,sx:{px:3,py:2},children:[!s&&(n!==void 0||r!==void 0)&&o(a,{direction:"row",spacing:2,alignItems:"center",children:[n&&t(l,{variant:"text",startIcon:t(p,{}),onClick:()=>n(e),children:"Edit"}),r&&t(l,{variant:"text",color:"error",startIcon:t(m,{}),onClick:()=>r(e),children:"Delete"})]}),o(a,{direction:"row",spacing:4,alignItems:"flex-start",children:[o(a,{children:[t(i,{variant:"caption",color:"text.secondary",children:"Rule UUID"}),t(h,{uuid:e.uuid,label:"Rule UUID",variant:"button",head:36,tail:0,mono:!0,iconSx:{fontSize:14,p:.125}})]}),e.notes&&o(a,{sx:{maxWidth:480},children:[t(i,{variant:"caption",color:"text.secondary",children:"Notes"}),t(i,{variant:"body2",children:e.notes})]})]}),o(a,{spacing:1,children:[t(c,{children:"Conditions"}),t(u,{rule:e,catalog:d})]}),o(a,{spacing:1,children:[t(c,{children:"Metadata"}),t(x,{rule:e})]})]})}export{f as NetworkRuleExpandedPanel};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NetworkRule } from '../types';
|
|
2
|
+
export interface NetworkRuleMetadataTableProps {
|
|
3
|
+
rule: NetworkRule;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The rule's metadata as the editor lays it out: key, type, value. Read-only; a pair is changed
|
|
7
|
+
* through the rule editor, there being no per-entry endpoint to hang row actions on.
|
|
8
|
+
*/
|
|
9
|
+
export declare function NetworkRuleMetadataTable({ rule, }: Readonly<NetworkRuleMetadataTableProps>): import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";import{Typography as s,Table as i,TableHead as c,TableRow as n,TableCell as e,TableBody as h,Chip as p}from"@mui/material";import{metadataTypeLabel as m,formatMetadataValue as b,typeOfMetadataValue as y}from"../utils/metadata.mjs";import{jsx as a,jsxs as r}from"react/jsx-runtime";function f({rule:l}){const t=Object.entries(l.metadata??{});return t.length===0?a(s,{variant:"body2",color:"text.secondary",children:"No metadata"}):r(i,{"aria-label":`Metadata for ${l.name}`,children:[a(c,{children:r(n,{children:[a(e,{children:"Key"}),a(e,{children:"Type"}),a(e,{children:"Value"})]})}),a(h,{children:t.map(([d,o])=>r(n,{children:[a(e,{sx:{whiteSpace:"nowrap"},children:a(p,{label:d})}),a(e,{sx:{whiteSpace:"nowrap"},children:m(y(o))}),a(e,{sx:{width:"100%",overflowWrap:"anywhere"},children:b(o)})]},d))})]})}export{f as NetworkRuleMetadataTable};
|
|
@@ -9,7 +9,7 @@ type ListStateProps = Pick<DataTableProps<NetworkRule>, 'pagination' | 'onPagina
|
|
|
9
9
|
export interface NetworkRulesTableProps extends NetworkRuleRowHandlers, ListStateProps {
|
|
10
10
|
rules: NetworkRule[];
|
|
11
11
|
isLoading?: boolean;
|
|
12
|
-
/** No toggle, no row
|
|
12
|
+
/** No toggle, no row actions. */
|
|
13
13
|
readOnly?: boolean;
|
|
14
14
|
emptyMessage?: string;
|
|
15
15
|
/** Defaults to 640. `'100%'` fills a parent with a definite height. */
|
|
@@ -5,6 +5,10 @@ export declare const NETWORK_RULES_FILTER_IDS: {
|
|
|
5
5
|
readonly enabled: "enabled";
|
|
6
6
|
/** "Has a condition on" any of the selected keys. */
|
|
7
7
|
readonly conditionKey: "conditionKey";
|
|
8
|
+
/** "Has metadata under" any of the selected keys. */
|
|
9
|
+
readonly metadataKey: "metadataKey";
|
|
10
|
+
/** One key's value, picked together with the key; the API takes one such match per request. */
|
|
11
|
+
readonly metadataValue: "metadataValue";
|
|
8
12
|
};
|
|
9
13
|
/** The filter id matching the values of one condition key. */
|
|
10
14
|
export declare function conditionFilterId(key: string): string;
|
|
@@ -13,7 +17,7 @@ export declare function conditionFilterKey(filterId: string): string | undefined
|
|
|
13
17
|
/** The text operators the rules list accepts; the first is the default. */
|
|
14
18
|
export declare const NETWORK_RULES_TEXT_OPERATORS: DataTableFilterOperator[];
|
|
15
19
|
/**
|
|
16
|
-
* The table's filter controls: the rule's own status and enabled flag,
|
|
17
|
-
* which keys it has a condition on, and the values of each key.
|
|
20
|
+
* The table's filter controls: the rule's own status and enabled flag, what the rule checks —
|
|
21
|
+
* which keys it has a condition on, and the values of each key — then the metadata it carries.
|
|
18
22
|
*/
|
|
19
23
|
export declare function buildNetworkRulesFilterFields(catalog: NetworkRuleCatalog | undefined, statuses: readonly string[], sources?: NetworkRulesServices['sources']): DataTableFilterField[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{getStatusLabel as
|
|
1
|
+
"use strict";import{getStatusLabel as S,isOperatorMulti as E,hasInlineOptions as v,hasRemoteSource as K,getPresets as r}from"../utils/catalog.mjs";import{NETWORK_RULE_METADATA_PRESET_FIELDS as b}from"../utils/metadata.mjs";import{NETWORK_RULES_COLUMN_IDS as d}from"./columns.mjs";const o={status:d.status,enabled:d.enabled,conditionKey:"conditionKey",metadataKey:"metadataKey",metadataValue:"metadataValue"},u="condition.",c={metadata:"Metadata",conditions:"Conditions"};function y(e){return`${u}${e}`}function R(e){return e.startsWith(u)?e.slice(u.length):void 0}const m=["contains","equals","startsWith","endsWith"],_=20,k=e=>({value:e.value,label:e.label,caption:e.value}),f=e=>({...k(e),logoUrl:e.logoUrl??null}),p=e=>({label:e,value:e});function T(e,a,n){const l=y(a.key),t=a.label,s=a.operators.some(i=>E(e,i));if(v(a))return{id:l,label:t,kind:s?"multiSelect":"select",options:a.values.options.map(k),selectAllClears:!1};if(K(a)){const i=n?.[a.values.source];return i?{id:l,label:t,kind:"multiSelect",selectAllClears:!1,placeholder:i.searchPlaceholder,loadOptions:async h=>(await i.search({search:h.trim()||void 0,limit:_})).map(f)}:void 0}return{id:l,label:t,kind:"text",operators:m,options:r(e,a.key).map(p)}}function O(e){if(e?.metadata===void 0)return[];const a=r(e,b.key).map(p);return[{id:o.metadataKey,label:"Has Metadata with Key",heading:c.metadata,kind:"multiSelect",freeSolo:!0,selectAllClears:!1,options:a,placeholder:"Pick or type keys"},{id:o.metadataValue,label:"Metadata Value",keyLabel:"Metadata Key",heading:c.metadata,kind:"keyedText",keys:a,operators:m,placeholder:"What the key is set to",options:r(e,b.value).map(p)}]}function A(e,a,n){const l=e?.keys??[];return[{id:o.status,label:"Status",kind:"multiSelect",columnId:d.status,selectAllClears:!1,options:a.map(t=>({label:S(t),value:t}))},{id:o.enabled,label:"Enabled",kind:"boolean",columnId:d.enabled},{id:o.conditionKey,label:"Has Condition with Key",kind:"multiSelect",selectAllClears:!1,options:l.map(t=>({label:t.label,value:t.key}))},...l.flatMap(t=>{const s=T(e,t,n);return s?[{...s,heading:c.conditions}]:[]}),...O(e)]}export{o as NETWORK_RULES_FILTER_IDS,m as NETWORK_RULES_TEXT_OPERATORS,A as buildNetworkRulesFilterFields,y as conditionFilterId,R as conditionFilterKey};
|
|
@@ -12,12 +12,23 @@ export type NetworkRuleTextFilter = {
|
|
|
12
12
|
export type NetworkRuleConditionFilter = {
|
|
13
13
|
key?: string[];
|
|
14
14
|
} & Record<string, string | string[] | NetworkRuleTextFilter | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Filters over the metadata a rule carries: `key` is "has metadata under any of these"; `value`
|
|
17
|
+
* matches one key's value as text. The API takes a single `value`, so the key is part of it.
|
|
18
|
+
*/
|
|
19
|
+
export type NetworkRuleMetadataFilter = {
|
|
20
|
+
key?: string[];
|
|
21
|
+
value?: NetworkRuleTextFilter & {
|
|
22
|
+
key: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
15
25
|
/** The rules list query the table's filters, search and sorting map to, ready to send as-is. */
|
|
16
26
|
export type NetworkRulesListQuery = {
|
|
17
27
|
status?: {
|
|
18
28
|
$in: string[];
|
|
19
29
|
};
|
|
20
30
|
enabled?: boolean;
|
|
31
|
+
metadata?: NetworkRuleMetadataFilter;
|
|
21
32
|
condition?: NetworkRuleConditionFilter;
|
|
22
33
|
search?: string;
|
|
23
34
|
$sort?: Record<string, 1 | -1>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{NETWORK_RULES_FILTER_IDS as
|
|
1
|
+
"use strict";import{NETWORK_RULES_FILTER_IDS as l,conditionFilterKey as k}from"./filters.mjs";const y=120,a=e=>{const t=e.trim().slice(0,y);return t===""?void 0:t},c=(e,t)=>{const n=e[t];return n?.kind==="multiSelect"&&n.values.length>0?n.values:void 0};function f(e){const t=e.map(a).filter(n=>n!==void 0);if(t.length!==0)return t.length===1?t[0]:t}function m(e){switch(e.kind){case"multiSelect":return f(e.values);case"select":return e.value===null?void 0:f([e.value]);case"text":{const t=a(e.value);return t===void 0?void 0:{value:t,operator:e.operator}}default:return}}function h(e){const t={};for(const[o,r]of Object.entries(e)){const i=k(o),s=i===void 0?void 0:m(r);i!==void 0&&s!==void 0&&(t[i]=s)}const n=c(e,l.conditionKey);return n&&(t.key=n),Object.keys(t).length===0?void 0:t}function b(e){const t={},n=c(e,l.metadataKey);n&&(t.key=n);const o=e[l.metadataValue];if(o?.kind==="keyedText"&&o.key){const r=a(o.value);r!==void 0&&(t.value={key:o.key,value:r,operator:o.operator})}return Object.keys(t).length===0?void 0:t}function p({filterState:e={},search:t="",sorting:n=[]}){const o={},r=c(e,l.status);r&&(o.status={$in:r});const i=e[l.enabled];i?.kind==="boolean"&&i.value!==null&&(o.enabled=i.value);const s=b(e);s!==void 0&&(o.metadata=s);const u=h(e);u!==void 0&&(o.condition=u);const d=a(t);return d!==void 0&&(o.search=d),n.length>0&&(o.$sort=Object.fromEntries(n.map(v=>[v.id,v.desc?-1:1]))),o}export{p as buildNetworkRulesListQuery};
|