@digital-realty/ix-account-switcher
Advanced tools
Comparing version 1.0.5 to 1.0.6
export { IxAccountSwitcher } from './IxAccountSwitcher.js'; | ||
export { authedUser } from './state/authedUser.js'; |
export { IxAccountSwitcher } from './IxAccountSwitcher.js'; | ||
export { authedUser } from './state/authedUser.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
import{html,nothing,css}from"lit";import{elementTheme}from"@digital-realty/theme";import{__decorate}from"tslib";import"@digital-realty/ix-dialog/ix-dialog.js";import"@digital-realty/ix-field/ix-field.js";import"@digital-realty/ix-icon-button/ix-icon-button.js";import"@digital-realty/ix-label-tag/ix-label-tag.js";import"@digital-realty/ix-select/ix-select.js";import"@digital-realty/ix-select/ix-select-option.js";import"@digital-realty/ix-tree/ix-tree.js";import{property,state}from"lit/decorators.js";import{MobxLitElement}from"@adobe/lit-mobx";import{makeAutoObservable,toJS}from"mobx";import{makePersistable}from"mobx-persist-store";class UserProfileState{constructor(){this.accountNumber=void 0,this.accountPermissions=[],makeAutoObservable(this),makePersistable(this,{name:"user-profile",properties:["accountNumber","accountPermissions","contact"],storage:window.localStorage})}setPermissions(e){this.accountPermissions=e}setAccountNumber(e){this.accountNumber=e}setContact(e){this.contact=e}get account(){var e;return null==(e=this.contact)?void 0:e.accounts.find(e=>e.accountNumber===this.accountNumber)}hasUserManagementExternalUserRead(){return this.hasPermission("User Management - External User","read")}hasUserManagementExternalUserUpdate(){return this.hasPermission("User Management - External User","update")}hasUserManagementInternalUserUpdate(){return this.hasPermission("User Management - Internal User","update")}hasCustomRoleManagementApprove(){return this.hasPermission("Role Management - Custom Role","approve")}hasCustomRoleManagementCreate(){return this.hasPermission("Role Management - Custom Roles","create")}hasCustomRoleManagementUpdate(){return this.hasPermission("Role Management - Custom Roles","update")}hasCustomRoleManagementRead(){return this.hasPermission("Role Management - Custom Roles","read")}hasInternalRoleManagementCreate(){return this.hasPermission("Role Management - Internal Roles","create")}hasInternalRoleManagementUpdate(){return this.hasPermission("Role Management - Internal Roles","update")}hasInternalRoleManagementRead(){return this.hasPermission("Role Management - Internal Roles","read")}hasDefaultSystemRoleManagementCreate(){return this.hasPermission("Role Management - Default System Roles","create")}hasDefaultSystemRoleManagementUpdate(){return this.hasPermission("Role Management - Default System Roles","update")}hasDefaultSystemRoleManagementRead(){return this.hasPermission("Role Management - Default System Roles","read")}hasPrivilegeLevel(t,s){var e=["approve","create","update","read"],o=e.findIndex(e=>e===t.toLowerCase());return e.findIndex(e=>e===s.toLowerCase())<=o}hasPermission(t,s){var e=toJS(this.accountPermissions).find(e=>e.accountNumber===this.accountNumber||null===e.accountNumber);let o=!1;return e&&e.permissions.forEach(e=>{e.permissionName===t&&s&&this.hasPrivilegeLevel(s.toLowerCase(),e.privilege.toLowerCase())&&(o=!0)}),o}}const userProfile=new UserProfileState,findAccountById=(e,t)=>{var s=e.find(e=>e.id===t);if(s)return s;for(const a of e)if(a.subaccounts){var o=findAccountById(a.subaccounts,t);if(o)return o}return null},mapAccountToTreeNode=(e,t)=>{const s={expanded:!1,id:e.id,label:e.name,parentId:t.id};return s.children=null==(t=e.subaccounts)?void 0:t.map(e=>mapAccountToTreeNode(e,s)),s},mapAccountsToTreeNode=e=>{const t={expanded:!1,id:"root",label:"",parentId:void 0};return t.children=e.map(e=>mapAccountToTreeNode(e,t)),t};class IxAccountSwitcher extends MobxLitElement{constructor(){super(...arguments),this.accounts=[],this.showDialog=!1}renderDialog(){var e=mapAccountsToTreeNode(this.accounts);return html`<ix-dialog id="account-switcher-dialog" class="relative z-50" ?open="${this.showDialog}" @blur="${()=>{this.showDialog=!1}}"><div class="headline" slot="headline"><span class="title">Switch Account</span><ix-icon-button @click="${()=>{this.showDialog=!1}}" icon="close"></ix-icon-button></div><form id="account-switcher-dialog-form" class="form" method="dialog" slot="content"><ix-tree .rootNode="${e}" .selectedNodeId="${userProfile.accountNumber}" @on-tree-node-selected="${e=>{userProfile.setAccountNumber(e.detail.message.id),this.showDialog=!1,this.requestUpdate(),this.dispatchEvent(new CustomEvent("account-switched",{detail:e.detail.message.id,bubbles:!0,composed:!0}))}}"></ix-tree></form></ix-dialog>`}getSelectedAccount(){return findAccountById(this.accounts,userProfile.accountNumber)}renderNestedAccountStructureSelect(){var e=this.getSelectedAccount();return html`<ix-field @click="${()=>{this.showDialog=!0}}"><div class="subaccount-wrap"><span class="subaccount-name">${null==e?void 0:e.name}</span><ix-icon class="dd-icon">arrow_drop_down</ix-icon></div></ix-field>`}renderFlatAccountStructureSelect(){const s=this.getSelectedAccount(),o=html`<ix-label-tag>Active</ix-label-tag>`;var e=this.accounts.map(e=>{var t=e.id===(null===s||void 0===s?void 0:s.id);return html`<ix-select-option value="${e.id}" .selected="${t}"><div slot="headline">${e.name}</div><div slot="end">${t?o:nothing}</div></ix-select-option>`});return html`<div class="account-switcher__select"><ix-select @request-selection="${e=>{e=e.target;userProfile.setAccountNumber(e.value)}}">${e}</ix-select></div>`}render(){var e=this.accounts.some(e=>e.subaccounts&&0<e.subaccounts.length);return html`<div class="account-switcher-container">${e?this.renderNestedAccountStructureSelect():this.renderFlatAccountStructureSelect()}</div>${e?this.renderDialog():null}`}}__decorate([property({type:Array})],IxAccountSwitcher.prototype,"accounts",void 0),__decorate([state()],IxAccountSwitcher.prototype,"showDialog",void 0);const AccountSwitcherStyles=css`.subaccount-wrap{display:flex;--ix-icon-font-size:1.6rem}.subaccount-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;width:0;flex:1}.dd-icon{margin:-2px -5px -5px 0}.headline{display:flex}.title{flex:1}.form{border:1px solid #e0e0e0;border-radius:.25rem;height:calc(488px - 3rem);margin:1rem 1.5rem 1.5rem 1.5rem;padding:0;width:calc(560px - 3rem);overflow:auto}`;class IxAccountSwitcherStyled extends IxAccountSwitcher{}IxAccountSwitcherStyled.styles=[elementTheme,AccountSwitcherStyles,css`:host{--md-theme-primary:var(--ix-sys-primary, blue)}`],window.customElements.define("ix-account-switcher",IxAccountSwitcherStyled);export{IxAccountSwitcherStyled}; | ||
import{html,nothing,css}from"lit";import{elementTheme}from"@digital-realty/theme";import{__decorate}from"tslib";import"@digital-realty/ix-dialog/ix-dialog.js";import"@digital-realty/ix-field/ix-field.js";import"@digital-realty/ix-icon-button/ix-icon-button.js";import"@digital-realty/ix-label-tag/ix-label-tag.js";import"@digital-realty/ix-select/ix-select.js";import"@digital-realty/ix-select/ix-select-option.js";import"@digital-realty/ix-tree/ix-tree.js";import{property,state}from"lit/decorators.js";import{MobxLitElement}from"@adobe/lit-mobx";import{makeAutoObservable}from"mobx";import{makePersistable}from"mobx-persist-store";class AuthedUserState{constructor(){this.account_number="",this.email="",this.name="",this.auth_time="",makeAutoObservable(this),makePersistable(this,{name:"x-auth",properties:["email","account_number","name","auth_time"],storage:window.localStorage})}setAccount({accountNumber:e,email:t,name:i,authTime:o}){this.account_number=e,this.email=t,this.name=i,this.auth_time=o}getAccount(){return{accountNumber:this.account_number,email:this.email,name:this.name,authTime:this.auth_time}}}const authedUser=new AuthedUserState,findAccountById=(e,t)=>{var i=e.find(e=>e.id===t);if(i)return i;for(const c of e)if(c.subaccounts){var o=findAccountById(c.subaccounts,t);if(o)return o}return null},mapAccountToTreeNode=(e,t)=>{const i={expanded:!1,id:e.id,label:e.name,parentId:t.id};return i.children=null==(t=e.subaccounts)?void 0:t.map(e=>mapAccountToTreeNode(e,i)),i},mapAccountsToTreeNode=e=>{const t={expanded:!1,id:"root",label:"",parentId:void 0};return t.children=e.map(e=>mapAccountToTreeNode(e,t)),t};class IxAccountSwitcher extends MobxLitElement{constructor(){super(...arguments),this.accounts=[],this.showDialog=!1}renderDialog(){var e=mapAccountsToTreeNode(this.accounts);return html`<ix-dialog id="account-switcher-dialog" class="relative z-50" ?open="${this.showDialog}" @blur="${()=>{this.showDialog=!1}}"><div class="headline" slot="headline"><span class="title">Switch Account</span><ix-icon-button @click="${()=>{this.showDialog=!1}}" icon="close"></ix-icon-button></div><form id="account-switcher-dialog-form" class="form" method="dialog" slot="content"><ix-tree .rootNode="${e}" .selectedNodeId="${authedUser.account_number}" @on-tree-node-selected="${e=>{this.showDialog=!1,this.dispatchEvent(new CustomEvent("account-switched",{detail:e.detail.message.id,bubbles:!0,composed:!0}))}}"></ix-tree></form></ix-dialog>`}getSelectedAccount(){return findAccountById(this.accounts,authedUser.account_number)}renderNestedAccountStructureSelect(){var e=this.getSelectedAccount();return html`<ix-field @click="${()=>{this.showDialog=!0}}"><div class="subaccount-wrap"><span class="subaccount-name">${null==e?void 0:e.name}</span><ix-icon class="dd-icon">arrow_drop_down</ix-icon></div></ix-field>`}renderFlatAccountStructureSelect(){const i=this.getSelectedAccount(),o=html`<ix-label-tag>Active</ix-label-tag>`;var e=this.accounts.map(e=>{var t=e.id===(null===i||void 0===i?void 0:i.id);return html`<ix-select-option value="${e.id}" .selected="${t}"><div slot="headline">${e.name}</div><div slot="end">${t?o:nothing}</div></ix-select-option>`});return html`<div class="account-switcher__select"><ix-select @request-selection="${e=>{e=e.target;this.dispatchEvent(new CustomEvent("account-switched",{detail:e.value,bubbles:!0,composed:!0}))}}">${e}</ix-select></div>`}render(){var e=this.accounts.some(e=>e.subaccounts&&0<e.subaccounts.length);return html`<div class="account-switcher-container">${e?this.renderNestedAccountStructureSelect():this.renderFlatAccountStructureSelect()}</div>${e?this.renderDialog():null}`}}__decorate([property({type:Array})],IxAccountSwitcher.prototype,"accounts",void 0),__decorate([state()],IxAccountSwitcher.prototype,"showDialog",void 0);const AccountSwitcherStyles=css`.subaccount-wrap{display:flex;--ix-icon-font-size:1.6rem}.subaccount-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;width:0;flex:1}.dd-icon{margin:-2px -5px -5px 0}.headline{display:flex}.title{flex:1}.form{border:1px solid #e0e0e0;border-radius:.25rem;height:calc(488px - 3rem);margin:1rem 1.5rem 1.5rem 1.5rem;padding:0;width:calc(560px - 3rem);overflow:auto}`;class IxAccountSwitcherStyled extends IxAccountSwitcher{}IxAccountSwitcherStyled.styles=[elementTheme,AccountSwitcherStyles,css`:host{--md-theme-primary:var(--ix-sys-primary, blue)}`],window.customElements.define("ix-account-switcher",IxAccountSwitcherStyled);export{IxAccountSwitcherStyled}; |
@@ -12,3 +12,3 @@ import { __decorate } from "tslib"; | ||
import { MobxLitElement } from '@adobe/lit-mobx'; | ||
import { userProfile } from './state/userProfile.js'; | ||
import { authedUser } from './state/authedUser.js'; | ||
import findAccountById from './utils/find-account-by-id.js'; | ||
@@ -50,7 +50,5 @@ import { mapAccountsToTreeNode } from './utils/map-accounts-to-tree.js'; | ||
.rootNode=${rootNode} | ||
.selectedNodeId=${userProfile.accountNumber} | ||
.selectedNodeId=${authedUser.account_number} | ||
@on-tree-node-selected=${(e) => { | ||
userProfile.setAccountNumber(e.detail.message.id); | ||
this.showDialog = false; | ||
this.requestUpdate(); | ||
this.dispatchEvent(new CustomEvent('account-switched', { | ||
@@ -67,3 +65,3 @@ detail: e.detail.message.id, | ||
getSelectedAccount() { | ||
return findAccountById(this.accounts, userProfile.accountNumber); | ||
return findAccountById(this.accounts, authedUser.account_number); | ||
} | ||
@@ -99,3 +97,7 @@ renderNestedAccountStructureSelect() { | ||
const target = e.target; | ||
userProfile.setAccountNumber(target.value); | ||
this.dispatchEvent(new CustomEvent('account-switched', { | ||
detail: target.value, | ||
bubbles: true, | ||
composed: true, | ||
})); | ||
}} | ||
@@ -102,0 +104,0 @@ > |
@@ -6,3 +6,3 @@ { | ||
"author": "Digital Realty", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"type": "module", | ||
@@ -13,4 +13,3 @@ "main": "dist/index.js", | ||
".": "./dist/index.js", | ||
"./ix-account-switcher.js": "./dist/ix-account-switcher.js", | ||
"./dist/state/userProfile.js": "./dist/state/userProfile.js" | ||
"./ix-account-switcher.js": "./dist/ix-account-switcher.js" | ||
}, | ||
@@ -112,3 +111,3 @@ "publishConfig": { | ||
], | ||
"gitHead": "cd091e62ba14576aaeef360449550aa45986c32d" | ||
"gitHead": "c8089ae61b532ce8e7b0649d70974f329e6a4400" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37768
364