@corva/ui 0.31.0-2 → 0.31.0-3
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/toConsumableArray";import{isEmpty as n,get as r}from"lodash";import{jsxs as a,jsx as i}from"react/jsx-runtime";import{makeStyles as
|
|
1
|
+
import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/toConsumableArray";import{isEmpty as n,get as r}from"lodash";import{jsxs as a,jsx as i}from"react/jsx-runtime";import{makeStyles as s,Fab as c,Dialog as l,DialogTitle as o,DialogContent as d,FormControl as u,InputLabel as p,Select as f,MenuItem as m,Checkbox as h,ListItemText as S,DialogActions as g,Button as E}from"@material-ui/core";import{useMemo as b,useEffect as I}from"react";import{getPads as _}from"../../clients/jsonApi/index.js";import C from"prop-types";import{Add as D}from"@material-ui/icons";import O from"jsona";import P from"use-tiny-state-machine";function y(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function v(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?y(Object(r),!0).forEach((function(n){e(t,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):y(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var W=new O,w=s({fabSmallBtn:{width:24,height:24,minHeight:24,margin:"0 6px 0 1px"},fabSmallBtnIcon:{width:20,height:20},dialogPaper:{width:"75%",maxWidth:420}});var L={id:"requests",initial:"idle",context:{padsData:[],wellsData:[],lastStage:[],error:null,companyId:0},states:{idle:{on:{FETCH_PADS:{target:"pending",action:function(e){var t=e.dispatch,a=e.context;_({fields:["pad.name","pad.wells"],sort:"name",per_page:1e3,company:a.companyId}).then((function(e){return W.deserialize(e)})).then((function(e){return e.filter((function(e){return!n(r(e,"wells"))}))})).then((function(e){return t("PADS_REQUEST_SUCCESS",e)})).catch((function(e){return t("FAILURE",e)}))}}}},pending:{on:{PADS_REQUEST_SUCCESS:{target:"success",beforeStateChange:function(e,t){return(0,e.updateContext)((function(e){return v(v({},e),{},{padsData:t})}))}},FAILURE:{target:"failure",beforeStateChange:function(e,t){throw new Error(t.message)}}}},success:{on:{FETCH_WELLS:{target:"success",action:function(e,t){(0,e.dispatch)("WELLS_REQUEST_SUCCESS",t.reduce((function(e,t){return e.concat(t.wells)}),[]))}},WELLS_REQUEST_SUCCESS:{target:"success",beforeStateChange:function(e,t){return(0,e.updateContext)((function(e){return v(v({},e),{},{wellsData:t})}))}}}}}},x={id:"dialog",initial:"closed",context:{selectedPadIds:[],selectedWellIds:[]},states:{closed:{on:{OPEN_DIALOG:{target:"open",beforeStateChange:function(e,r){var a=e.updateContext,i=r.currentWellIds,s=r.padsData,c=[];return n(i)||s.forEach((function(e){e.wells.forEach((function(t){i.includes(t.asset_id)&&!c.includes(e.id)&&c.push(e.id)}))})),a((function(e){return v(v({},e),{},{selectedPadIds:[].concat(c),selectedWellIds:t(i)})}))}}}},open:{on:{CLOSE_DIALOG:{target:"closed",beforeStateChange:function(e){return(0,e.updateContext)((function(e){return v(v({},e),{},{selectedPadIds:[],selectedWellIds:[]})}))}},SET_PAD_ID:{target:"open",beforeStateChange:function(e,t){var r=e.updateContext,a=t.selectedPadIds,i=t.currentWellIds,s=t.padsData,c=[];return n(i)||s.forEach((function(e){e.wells.forEach((function(t){a.includes(e.id)&&i.includes(t.asset_id)&&c.push(t.asset_id)}))})),r((function(e){return v(v({},e),{},{selectedPadIds:a,selectedWellIds:[].concat(c)})}))}},SET_WELL_ID:{target:"open",beforeStateChange:function(e,t){return(0,e.updateContext)((function(e){return v(v({},e),{},{selectedWellIds:t})}))}}}}}},j=function(e){var t=e.onSave,r=e.currentOffsetSetting,s=e.assets,_=e.companyId,C=w(),O=P(L),y=O.state,v=O.dispatch,W=O.context,j=P(x),A=j.state,T=j.dispatch,k=j.context,R=b((function(){return n(r)&&!n(s)?s.map((function(e){return e.asset_id})):r.map((function(e){return e.selectedWellId}))}),[r,s]),U=function(){return T("CLOSE_DIALOG")},F=k.selectedPadIds,q=k.selectedWellIds;I((function(){W.companyId=_,v("FETCH_PADS")}),[]),I((function(){if(!n(F)){var e=W.padsData.filter((function(e){return F.includes(e.id)}));v("FETCH_WELLS",e)}}),[F]);var N=new Set(s.map((function(e){return Number(e.asset_id)})));return a("div",{children:[i(c,{size:"small",color:"primary",classes:{sizeSmall:C.fabSmallBtn},onClick:function(){return T("OPEN_DIALOG",{currentWellIds:R,padsData:W.padsData})},disabled:"success"!==y,children:i(D,{className:C.fabSmallBtnIcon})}),"success"===y&&a(l,{open:"open"===A,onBackdropClick:U,classes:{paper:C.dialogPaper},children:[i(o,{children:"Offset Wells"}),a(d,{children:[a(u,{margin:"normal",fullWidth:!0,required:!0,children:[i(p,{htmlFor:"pad-select",shrink:!n(F),children:"Pad"}),i(f,{multiple:!0,inputProps:{name:"pads",id:"pad-select"},value:F,onChange:function(e){return T("SET_PAD_ID",{selectedPadIds:e.target.value,currentWellIds:R,padsData:W.padsData})},renderValue:function(e){return"".concat(e.length," selected")},children:W.padsData.map((function(e){return a(m,{value:e.id,children:[i(h,{checked:F.includes(e.id)}),i(S,{primary:e.name})]},e.id)}))})]}),a(u,{margin:"normal",disabled:n(F),fullWidth:!0,required:!0,children:[i(p,{htmlFor:"wells",shrink:!n(q),children:"Well"}),i(f,{multiple:!0,inputProps:{name:"wells",id:"well-select"},value:q,onChange:function(e){return T("SET_WELL_ID",e.target.value)},renderValue:function(e){return"".concat(e.length," selected")},children:W.wellsData.map((function(e){var t=N.has(e.asset_id);return a(m,{value:e.asset_id,disabled:t,children:[i(h,{checked:q.includes(e.asset_id)}),i(S,{primary:e.name})]},e.id)}))})]})]}),a(g,{children:[i(E,{onClick:U,children:"Cancel"}),i(E,{variant:"contained",color:"primary",disabled:n(q),onClick:function(){var e=W.wellsData.filter((function(e){return q.includes(e.asset_id)})).map((function(e){var t=r.find((function(t){return t.selectedWellId===Number(e.asset_id)}));return t||{selectedWellId:Number(e.asset_id),selectedWellName:e.name,selectedWellStatus:e.status,selectedStages:[],stages:{}}}));U(),t(e)},children:"Save"})]})]})]})};j.propTypes={currentOffsetSetting:C.arrayOf(C.shape({})).isRequired,onSave:C.func.isRequired,companyId:C.string.isRequired,assets:C.arrayOf(C.shape({})).isRequired};export default j;
|