2 lines
5.8 KiB
JavaScript
2 lines
5.8 KiB
JavaScript
|
var B=Object.defineProperty,j=Object.defineProperties;var F=Object.getOwnPropertyDescriptors;var R=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var _=(e,t,r)=>t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,u=(e,t)=>{for(var r in t||(t={}))S.call(t,r)&&_(e,r,t[r]);if(R)for(var r of R(t))$.call(t,r)&&_(e,r,t[r]);return e},v=(e,t)=>j(e,F(t));import{e as A,u as g,N as q,U as E,V as x,r as l,k as P,R as o}from"./vendor.38e754a4.js";import{a as L,V as Q}from"./index.esm.edbe839b.js";import{t as y,E as W,B as z,c as D,g as U,C as V}from"./index.ee5bc09a.js";import{R as b,T as H}from"./TextFitler.cc7f7fa3.js";import{f as M}from"./index.9233837d.js";import{F as O,p as G}from"./Fab.4dc9cb99.js";import{u as J}from"./useRemainingViewPortHeight.7baef998.js";import"./debounce.76599460.js";function K(e){const t=e.providers,r=Object.keys(t),s={};for(let n=0;n<r.length;n++){const a=r[n];s[a]=v(u({},t[a]),{idx:n})}return{byName:s,names:r}}async function X(e,t){const{url:r,init:s}=y(t);let n={providers:{}};try{const a=await fetch(r+e,s);a.ok&&(n=await a.json())}catch(a){console.log("failed to GET /providers/rules",a)}return K(n)}async function w({name:e,apiConfig:t}){const{url:r,init:s}=y(t);try{return(await fetch(r+`/providers/rules/${e}`,u({method:"PUT"},s))).ok}catch(n){return console.log("failed to PUT /providers/rules/:name",n),!1}}async function Y({names:e,apiConfig:t}){for(let r=0;r<e.length;r++)await w({name:e[r],apiConfig:t})}var Z=function(e,t,r,s,n,a,i,d){if(!e){var c;if(t===void 0)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var f=[r,s,n,a,i,d],k=0;c=new Error(t.replace(/%s/g,function(){return f[k++]})),c.name="Invariant Violation"}throw c.framesToPop=1,c}},ee=Z;function te(e){return ee(e.rules&&e.rules.length>=0,"there is no valid rules list in the rules API response"),e.rules.map((t,r)=>v(u({},t),{id:r}))}async function re(e,t){let r={rules:[]};try{const{url:s,init:n}=y(t),a=await fetch(s+e,n);a.ok&&(r=await a.json())}catch(s){console.log("failed to fetch rules",s)}return te(r)}const I=A({key:"ruleFilterText",default:""});function ne(e,t){const r=E(),{mutate:s,isLoading:n}=x(w,{onSuccess:()=>{r.invalidateQueries("/providers/rules")}});return[i=>{i.preventDefault(),s({name:e,apiConfig:t})},n]}function se(e){const t=E(),{data:r}=N(e),{mutate:s,isLoading:n}=x(Y,{onSuccess:()=>{t.invalidateQueries("/providers/rules")}});return[i=>{i.preventDefault(),s({names:r.names,apiConfig:e})},n]}function N(e){return g(["/providers/rules",e],()=>X("/providers/rules",e))}function ae(e){const{data:t,isFetching:r}=g(["/rules",e],()=>re("/rules",e)),{data:s}=N(e),[n]=q(I);if(n==="")return{rules:t,provider:s,isFetching:r};{const a=n.toLowerCase();return{rules:t.filter(i=>i.payload.toLowerCase().indexOf(a)>=0),isFetching:r,provider:{byName:s.byName,names:s.names.filter(i=>i.toLowerCase().indexOf(a)>=0)}}}}const oe="_RuleProviderItem_ly9yn_1",ie="_left_ly9yn_7",le="_middle_ly9yn_14",ce="_gray_ly9yn_20",ue="_refreshButtonWrapper_ly9yn_24";var m={RuleProviderItem:oe,left:ie,middle:le,gray:ce,refreshButtonWrapper:ue};function me({idx:e,name:t,vehicleType:r,behavior:s,updatedAt:n,ruleCount:a,apiConfig:i}){const[d,c]=ne(t,i),f=M(new Date(n),new Date);return l.exports.createElement("div",{className:m.RuleProviderItem},l.exports.createElement("span",{className:m.left},e),l.exports.createElement("div",{className:m.middle},l.exports.createElement(W,{name:t,type:`${r} / ${s}`}),l.exports.createElement("div",{className:m.gray},a<2?`${a} rule`:`${a} rules`),l.exports.createElement("small",{className:m.gray},"Updated ",f," ago")),l.exports.createElement("span",{className:m.refreshButtonWrapper},l.exports.createElement(z,{onClick:d,disabled:c},l.exports.createElement(b,{isRotating:c}))))}function de({apiConfig:e}){const[t,r]=se(e),{t:s}=P();return l.exports.createElement(O,{icon:l.exports.createElement(b,{isRotating:r}),text:s("update_all_rule_provider"),style:G,onClick:t})}co
|