(window.webpackJsonp=window.webpackJsonp||[]).push([[88],{"./runtime-repl/environment/sidebar/EnvironmentSidebarController.js":function(e,t,o){"use strict";o.r(t),function(e){o.d(t,"default",(function(){return u}));var s=o("../../node_modules/mobx/lib/mobx.module.js"),n=o("./js/modules/services/RemoteSyncRequestService.js"),i=o("./js/stores/get-store.js"),r=o("./js/modules/controllers/PermissionController.js"),d=o("./runtime-repl/_common/SyncEndpoints.js"),a=o("./runtime-repl/environment/sidebar/EnvironmentSidebarModel.js"),m=o("./runtime-repl/environment/datastores/adapters/EnvironmentModelEventsAdapter.js"),l=o("./runtime-repl/environment/_api/EnvironmentStoreV2.js"),c=o("./onboarding/src/common/dependencies.js");class u{constructor(){this.model=null,this.adapter=null}async didCreate(){this.model=new a.default,this.model.setLoading&&this.model.setLoading(!0);const t=await this.fetchEnvironments();!function(t){if(e.isEmpty(t))return;const o=[],s=[];t.forEach((t=>{const n=e.get(t,"attributes.permissions.anybodyCanView"),i=e.get(t,"attributes.permissions.teamCanView");n&&o.push({id:t.id}),i&&s.push({id:t.id})})),!e.isEmpty(o)&&Object(i.getStore)("PublicEntityStore").add(o),!e.isEmpty(s)&&Object(i.getStore)("SharedEnvironmentsStore").add(s)}(e.get(t,"body.data",[])),this.model.environmentList=await l.default.subscribe();const o=e=>e&&Object(i.getStore)("EnvironmentStore").find(Object(c.decomposeUID)(e).modelId);try{await Object(s.when)((()=>this.model.environmentList.ids.every(o)),{timeout:6e4})}catch(e){pm.logger.warn("EnvironmentSidebarController~didCreate: Timed out while waiting for store to be fully hydrated",e)}this.adapter=new m.default(this.model),await this.adapter.hydrate(),this.model.setLoading&&this.model.setLoading(!1)}async fetchEnvironments(){await Object(i.getStore)("SyncStatusStore").onSyncAvailable();const t=Object(i.getStore)("ActiveWorkspaceStore").id,o=await n.default.request(d.ENVIRONMENT_LIST_AND_SUBSCRIBE`${t}`,{method:"POST"}),s=e.forEach(e.get(o,"body.data",[]),(t=>{const o={model:"environment",modelId:t.id,action:"UPDATE_ENVIRONMENT"},s=r.default.getCompositeKey(o);!Object(i.getStore)("PermissionStore").members.has(s)&&e.set(t,"attributes.permissions.userCanUpdate",!0)}));return this.model.hydrate&&this.model.hydrate(s),this.model.setLoading&&this.model.setLoading(!1),o}beforeDestroy(){this.model.dispose(),this.model=null,this.adapter&&this.adapter.dispose(),this.adapter=null}}}.call(this,o("./node_modules/lodash/lodash.js"))}}]);