UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.

2 lines (1 loc) 8.06 kB
import{ce as L,b9 as k,bb as H,j as e,aY as P,C as p,V as m,T as C,L as y,aW as R,aX as D,e as M,bf as W,fL as E,aU as _,aV as z,h as G,r as f,fo as F,fp as V,s as N,A as J,m as K,l as X,n as Y,o as Q,j5 as Z,as as U,B as T,f7 as I,j6 as A,f8 as b}from"./index-CBxzHo9v.js";const ee=t=>fetch(t).then(H("ChangeRequest")).then(s=>s.json()),te=(t,s)=>{const r=s.map(i=>`feature=${i}`).join("&"),{data:n,error:a,mutate:o}=L([],k(`api/admin/projects/${t}/change-requests/scheduled?${r}`),ee);return{changeRequests:n,loading:!a&&!n,refetch:o,error:a}},S=()=>e.jsx(m,{severity:"warning",sx:{m:t=>t.spacing(2,0)},children:"Archiving flags with dependencies will also remove those dependencies."}),ne=({ids:t,projectId:s})=>{const r=n=>`/projects/${s}/features/${n}`;return t?e.jsxs(m,{severity:"warning",sx:{m:n=>n.spacing(2,0)},children:[e.jsx(C,{fontWeight:"bold",variant:"body2",display:"inline",children:`${t.length} feature flags `}),e.jsx("span",{children:"have usage from applications. If you archive these feature flags they will not be available to Client SDKs:"}),e.jsx("ul",{children:t==null?void 0:t.map(n=>e.jsx("li",{children:e.jsx(y,{to:r(n),children:n})},n))})]}):null},$=({ids:t,projectId:s})=>{const r=n=>`/projects/${s}/features/${n}`;return t&&t.length>1?e.jsxs(m,{severity:"error",sx:{m:n=>n.spacing(2,0)},children:[e.jsx(C,{fontWeight:"bold",variant:"body2",display:"inline",children:`${t.length} feature flags `}),e.jsx("span",{children:"have child features that depend on them and are not part of the archive operation. These parent features can not be archived:"}),e.jsx("ul",{children:t==null?void 0:t.map(n=>e.jsx("li",{children:e.jsx(y,{to:r(n),children:n})},n))})]}):t&&t.length===1?e.jsxs(m,{severity:"error",sx:{m:n=>n.spacing(2,0)},children:[e.jsx(y,{to:r(t[0]),children:t[0]})," has child features that depend on it and are not part of the archive operation."]}):null},q=({changeRequests:t,projectId:s})=>t&&t.length>0?e.jsxs(m,{severity:"warning",sx:{m:r=>r.spacing(2,0)},children:[e.jsxs("p",{children:["This archive operation would conflict with"," ",t.length," scheduled change request(s). The change request(s) that would be affected by this are:"]}),e.jsx("ul",{children:t.map(({id:r,title:n})=>{const a=n?`#${r} (${n})`:`Change request #${r}`;return e.jsx("li",{children:e.jsx(y,{to:`/projects/${s}/change-requests/${r}`,target:"_blank",rel:"noopener noreferrer",title:`Change request ${r}`,children:a})},r)})})]}):t===void 0?e.jsx(m,{severity:"warning",children:e.jsx("p",{children:"This archive operation might conflict with one or more scheduled change requests. If you complete it, those change requests can no longer be applied."})}):null,se=(t,s)=>{const n=R(t)(),{isChangeRequestConfiguredForReview:a}=D(t);return n&&a(n)&&s?"Add to change request":n&&a(n)?"Add change to draft":s?"Archive flags":"Archive flag"},ae=({projectId:t,featureIds:s,onSuccess:r,onError:n})=>{const{setToastData:a,setToastApiError:o}=M(),{archiveFeatureToggle:i}=W(),{archiveFeatures:c}=E(),{isChangeRequestConfiguredForReview:h}=D(t),{addChange:x}=_(),{refetch:u}=z(t),d=R(t),g=(s==null?void 0:s.length)>1,l=d(),v=async()=>{if(!l){console.error("No change request environment");return}await x(t,l,s.map(w=>({action:"archiveFeature",feature:w,payload:void 0}))),u(),a({type:"success",text:g?"Changes added to a draft":"Change added to a draft"})},j=async()=>{await i(t,s[0]),a({type:"success",text:"Feature flag archived"})},O=async()=>{await c(t,s),a({type:"success",text:"Feature flags archived"})};return async()=>{try{l&&h(l)?await v():g?await O():await j(),r()}catch(w){o(G(w)),n()}}},re=(t,s,r)=>{const[n,a]=f.useState(!0),[o,i]=f.useState([]),[c,h]=f.useState(!1),{verifyArchiveFeatures:x}=E();return f.useEffect(()=>{r&&x(s,t).then(u=>u.json()).then(({hasDeletedDependencies:u,parentsWithChildFeatures:d})=>{d.length===0?(a(!1),i(d)):(a(!0),i(d)),h(u)})},[JSON.stringify(t),r,s,i,a,h]),{disableArchive:n,offendingParents:o,hasDeletedDependencies:c}},ue=({isOpen:t,onClose:s,onConfirm:r,projectId:n,featureIds:a,featuresWithUsage:o})=>{const i=(a==null?void 0:a.length)>1,c=se(n,i),h=i?"Archive feature flags":"Archive feature flag",x=ae({projectId:n,featureIds:a,onSuccess(){r(),s()},onError(){s()}}),{changeRequests:u}=te(n,a),{disableArchive:d,offendingParents:g,hasDeletedDependencies:l}=re(a,n,t),v=g.length===0&&l;return e.jsx(P,{onClick:x,open:t,onClose:s,primaryButtonText:c,secondaryButtonText:"Cancel",title:h,disabledPrimaryButton:d,children:e.jsx(p,{condition:i,show:e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:["Are you sure you want to archive"," ",e.jsx("strong",{children:a==null?void 0:a.length})," feature flags?"]}),e.jsx(p,{condition:!!(o&&(o==null?void 0:o.length)>0),show:e.jsx(ne,{ids:o,projectId:n})}),e.jsx(p,{condition:g.length>0,show:e.jsx($,{ids:g,projectId:n})}),e.jsx(p,{condition:v,show:e.jsx(S,{})}),e.jsx(q,{changeRequests:u,projectId:n}),e.jsx(p,{condition:(a==null?void 0:a.length)<=5,show:e.jsx("ul",{children:a==null?void 0:a.map(j=>e.jsx("li",{children:j},j))})})]}),elseShow:e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:["Are you sure you want to archive"," ",i?"these feature flags":"this feature flag","?"]}),e.jsx(p,{condition:g.length>0,show:e.jsx($,{ids:g,projectId:n})}),e.jsx(p,{condition:v,show:e.jsx(S,{})}),e.jsx(q,{changeRequests:u,projectId:n})]})})})},ie=(t,s)=>`/api/admin/projects/${t}/features/${s}/parents`,ge=(t,s)=>{const r=k(ie(t,s)),{data:n,refetch:a,loading:o,error:i}=F(r,()=>V(r,"Parent Options"));return{parentOptions:n,loading:o,error:i}},oe=(t,s)=>`/api/admin/projects/${t}/features/${s}/parent-variants`,B=(t,s)=>{const r=k(oe(t,s)),{data:n,refetch:a,loading:o,error:i}=F(r,()=>V(r,"Parent Variant Options"));return{parentVariantOptions:n||[],loading:o,error:i}},ce=N(J)(({theme:t})=>({marginTop:t.spacing(2),marginBottom:t.spacing(1.5)})),le=({project:t,parent:s,onSelect:r})=>{const{parentVariantOptions:n}=B(t,s),a=e.jsx(Y,{fontSize:"small"}),o=e.jsx(Q,{fontSize:"small"});return e.jsx(ce,{id:"single-variant-options",options:n,renderOption:(i,c,{selected:h})=>e.jsxs("li",{...i,children:[e.jsx(K,{icon:a,checkedIcon:o,style:{marginRight:8},checked:h}),c]}),renderInput:i=>e.jsx(X,{...i,placeholder:"Select variant"}),fullWidth:!0,onChange:(i,c)=>{r(String(c))}})},de=({projectId:t,featureId:s,isOpen:r,setIsOpen:n,onComplete:a})=>{const{markFeatureCompleted:o}=Z(),{parentVariantOptions:i}=B(t,s),[c,h]=f.useState("kept"),[x,u]=f.useState(void 0),{trackEvent:d}=U(),g=async()=>{const l=c==="kept-with-variant"?"kept":c;await o(s,t,{status:l,statusValue:x}),n(!1),a(),d("feature-lifecycle",{props:{eventType:"complete",status:l}})};return e.jsx(P,{open:r,title:"Mark completed",onClose:()=>{n(!1)},disabledPrimaryButton:c==="kept-with-variant"&&x===null,onClick:g,primaryButtonText:"Mark completed",secondaryButtonText:"Cancel",children:e.jsxs(T,{children:[e.jsxs(T,{sx:{mt:2,mb:4},children:["Marking the feature ",e.jsx("b",{children:s})," as complete does not affect any configuration, but it moves the feature flag into it’s next life cycle stage and is an indication that you have learned what you needed in order to progress with the feature. It serves as a reminder to start cleaning up the feature flag and removing it from the code."]}),e.jsx(C,{sx:{mb:2},children:e.jsx("b",{children:"What was the outcome of this feature?"})}),e.jsxs(I,{"aria-label":"selected-value",name:"selected",sx:{gap:l=>l.spacing(.5)},onChange:(l,v)=>{h(v)},children:[e.jsx(A,{value:"kept",legal:{value:"We decided to keep the feature"},control:e.jsx(b,{})},"kept"),e.jsx(A,{value:"discarded",legal:{value:"We decided to discard the feature"},control:e.jsx(b,{})},"discarded"),e.jsx(p,{condition:i.length>0,show:e.jsx(A,{value:"kept-with-variant",legal:{value:"We decided to keep the feature variant",description:"Choose to specify which feature variant will be kept"},control:e.jsx(b,{})},"kept-with-variant")}),e.jsx(p,{condition:i.length>0&&c==="kept-with-variant",show:e.jsx(le,{parent:s,project:t,onSelect:l=>{u(l)}})})]})]})})};export{ue as F,de as M,ge as a,B as u};