@api-client/ui 0.6.6 → 0.6.7
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.
- package/build/src/elements/setup/internals/OrganizationSelector.js +2 -2
- package/build/src/elements/setup/internals/OrganizationSelector.js.map +1 -1
- package/build/src/md/button/internals/base.d.ts +4 -1
- package/build/src/md/button/internals/base.d.ts.map +1 -1
- package/build/src/md/button/internals/base.js +4 -0
- package/build/src/md/button/internals/base.js.map +1 -1
- package/build/src/services/OrganizationService.d.ts +44 -6
- package/build/src/services/OrganizationService.d.ts.map +1 -1
- package/build/src/services/OrganizationService.js +79 -24
- package/build/src/services/OrganizationService.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/elements/setup/internals/OrganizationSelector.ts +2 -2
- package/src/md/button/internals/base.ts +5 -1
- package/src/services/OrganizationService.ts +84 -25
|
@@ -73,7 +73,7 @@ let OrganizationSelector = (() => {
|
|
|
73
73
|
}));
|
|
74
74
|
}
|
|
75
75
|
render() {
|
|
76
|
-
return html
|
|
76
|
+
return html `${this.renderTrigger()} ${this.renderMenu()}`;
|
|
77
77
|
}
|
|
78
78
|
renderTrigger() {
|
|
79
79
|
const { organization } = this;
|
|
@@ -84,7 +84,7 @@ let OrganizationSelector = (() => {
|
|
|
84
84
|
aria-label="Current organization: ${orgName}"
|
|
85
85
|
trailingicon
|
|
86
86
|
color="tonal"
|
|
87
|
-
|
|
87
|
+
popovertarget="org-selector-menu"
|
|
88
88
|
>
|
|
89
89
|
${orgName}
|
|
90
90
|
<ui-icon slot="icon">arrow_drop_down</ui-icon>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OrganizationSelector.js","sourceRoot":"","sources":["../../../../../src/elements/setup/internals/OrganizationSelector.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAkB,UAAU,EAAE,MAAM,KAAK,CAAA;AACtD,OAAO,EAAE,QAAQ,EAA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BAC5B,IAAI,CAAC,YAAY,EAAE,CAAA;YACrB,CAAC;QACH,CAAC;QAED;;;WAGG;QACO,YAAY,CAAC,eAAuB;YAC5C,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,QAAQ,EAAE;gBACxB,MAAM,EAAE,EAAE,YAAY,EAAE,eAAe,EAAE;gBACzC,OAAO,EAAE,KAAK;gBACd,QAAQ,EAAE,KAAK;aAChB,CAAC,CACH,CAAA;QACH,CAAC;QAED;;WAEG;QACO,YAAY;YACpB,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,QAAQ,EAAE;gBACxB,OAAO,EAAE,KAAK;gBACd,QAAQ,EAAE,KAAK;aAChB,CAAC,CACH,CAAA;QACH,CAAC;QAEkB,MAAM;YACvB,OAAO,IAAI,CAAA,
|
|
1
|
+
{"version":3,"file":"OrganizationSelector.js","sourceRoot":"","sources":["../../../../../src/elements/setup/internals/OrganizationSelector.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAkB,UAAU,EAAE,MAAM,KAAK,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAsB,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AAC5F,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAA;;sBAqBxB,UAAU;;;;;;;iBAAvC,oBAAqB,SAAQ,WAAU;;;wCAOzD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;yCAQ1D,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAC3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,CAAC,UAAU,EAAE,EAAE,CAAA;QAC3D,CAAC;QAES,aAAa;YACrB,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAA;YAC7B,MAAM,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,qBAAqB,CAAA;YACxE,OAAO,IAAI,CAAA;;;4CAG6B,OAAO;;;;;UAKzC,OAAO;;;KAGZ,CAAA;QACH,CAAC;QAES,UAAU;YAClB,MAAM,EAAE,YAAY,EAAE,aAAa,GAAG,EAAE,EAAE,GAAG,IAAI,CAAA;YACjD,MAAM,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;YACnD,OAAO,IAAI,CAAA;gEACiD,IAAI,CAAC,eAAe;UAC1E,MAAM,CACN,aAAa,EACb,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,EAChB,CAAC,GAAG,EAAE,EAAE,CACN,IAAI,CAAA;;;uBAGO,GAAG,CAAC,GAAG;2BACH,GAAG,CAAC,GAAG,KAAK,MAAM;sBACvB,GAAG,CAAC,IAAI;4BACF,CACnB;;;;;;;KAOJ,CAAA;QACH,CAAC;;;;;;;AA3HH;;;;;;;;;;;;;;;;;;GAkBG;AACH,oCAyGC","sourcesContent":["import { html, TemplateResult, LitElement } from 'lit'\nimport { property } from 'lit/decorators.js'\nimport { repeat } from 'lit/directives/repeat.js'\nimport { consume } from '@lit/context'\nimport type { UiMenuItemElement } from '../../../md/menu/ui-menu-item.js'\nimport { type IOrganization, organizationContext } from '../../../providers/organization.js'\nimport { organizationsContext } from '../../../providers/organizations.js'\n\n/**\n * An element that allows selecting an organization from a list.\n * It renders a button with the current organization name that triggers a dropdown menu with available organizations.\n *\n * The component supports creating a new organization via a dedicated menu item.\n *\n * @example\n * ```html\n * <organization-selector\n * .organization=\"${this.selectedOrg}\"\n * .organizations=\"${this.availableOrgs}\"\n * @select=\"${this.handleSelection}\"\n * @create=\"${this.handleCreate}\"\n * ></organization-selector>\n * ```\n *\n * @fires select - Dispatched when the user selects an organization. The detail object contains the `organization` key.\n * @fires create - Dispatched when the user clicks on the \"New Organization\" menu item.\n */\nexport default class OrganizationSelector extends LitElement {\n /**\n * The currently selected organization, if any.\n * When set, the button label will show this organization's name.\n *\n * This property consumes the `organizationContext`.\n */\n @property({ type: Object, attribute: false })\n @consume({ context: organizationContext, subscribe: true })\n accessor organization: IOrganization | undefined\n\n /**\n * The list of available organizations to display in the dropdown menu.\n *\n * This property consumes the `organizationsContext`.\n */\n @property({ type: Array, attribute: false })\n @consume({ context: organizationsContext, subscribe: true })\n accessor organizations: IOrganization[] | undefined\n\n /**\n * A handler for organization selection from the menu.\n */\n protected handleOrgSelect(e: CustomEvent<{ item: UiMenuItemElement }>): void {\n const { item } = e.detail\n const { action = '' } = item.dataset\n if (action === 'select' && item.value) {\n this.notifySelect(item.value)\n } else if (action === 'new') {\n this.notifyCreate()\n }\n }\n\n /**\n * Notifies about organization selection.\n * @param organizationKey The key of the organization that was selected by the user.\n */\n protected notifySelect(organizationKey: string): void {\n this.dispatchEvent(\n new CustomEvent('select', {\n detail: { organization: organizationKey },\n bubbles: false,\n composed: false,\n })\n )\n }\n\n /**\n * Notifies about the request to create a new organization.\n */\n protected notifyCreate(): void {\n this.dispatchEvent(\n new CustomEvent('create', {\n bubbles: false,\n composed: false,\n })\n )\n }\n\n protected override render(): unknown {\n return html`${this.renderTrigger()} ${this.renderMenu()}`\n }\n\n protected renderTrigger(): TemplateResult {\n const { organization } = this\n const orgName = organization ? organization.name : 'Select Organization'\n return html`\n <ui-button\n id=\"org-selector-anchor\"\n aria-label=\"Current organization: ${orgName}\"\n trailingicon\n color=\"tonal\"\n popovertarget=\"org-selector-menu\"\n >\n ${orgName}\n <ui-icon slot=\"icon\">arrow_drop_down</ui-icon>\n </ui-button>\n `\n }\n\n protected renderMenu(): TemplateResult {\n const { organization, organizations = [] } = this\n const orgKey = organization ? organization.key : ''\n return html`\n <ui-menu id=\"org-selector-menu\" popover=\"auto\" @select=\"${this.handleOrgSelect}\">\n ${repeat(\n organizations,\n (org) => org.key,\n (org) =>\n html`<ui-menu-item\n showSelectionIcon\n data-action=\"select\"\n value=\"${org.key}\"\n ?selected=\"${org.key === orgKey}\"\n ><div>${org.name}</div>\n </ui-menu-item>`\n )}\n <ui-divider role=\"separator\"></ui-divider>\n <ui-menu-item data-action=\"new\">\n <div>New Organization</div>\n <ui-icon slot=\"start\">add</ui-icon>\n </ui-menu-item>\n </ui-menu>\n `\n }\n}\n"]}
|
|
@@ -80,6 +80,9 @@ export default class BaseButton extends UiElement {
|
|
|
80
80
|
/**
|
|
81
81
|
* Turns a `<ui-button>` element into a popover control button; takes the ID
|
|
82
82
|
* of the popover element to control as its value.
|
|
83
|
+
*
|
|
84
|
+
* Note: this is required for now as the spec only allows to control popovers
|
|
85
|
+
* via buttons. Custom elements are not allowed to control popovers.
|
|
83
86
|
* @attribute
|
|
84
87
|
*/
|
|
85
88
|
accessor popoverTarget: string | undefined;
|
|
@@ -95,7 +98,7 @@ export default class BaseButton extends UiElement {
|
|
|
95
98
|
* it will be shown; if the popover is showing, it will be hidden. If popoverTargetAction is omitted,
|
|
96
99
|
* "toggle" is the default action that will be performed by the control button.
|
|
97
100
|
*/
|
|
98
|
-
accessor popoverTargetAction:
|
|
101
|
+
accessor popoverTargetAction: 'hide' | 'show' | 'toggle' | undefined;
|
|
99
102
|
/**
|
|
100
103
|
* When true, the focus ring effect will be constrained to the inside of the button's bounds.
|
|
101
104
|
* @attribute
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../../src/md/button/internals/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;AAG7E,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,KA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AW,IAAI,IAAI;IAKpB,kBAAkB,CAAC,CAAC,EAAE,YAAY,GAAG,IAAI;IAKzC,kBAAkB,CAAC,CAAC,EAAE,YAAY,GAAG,IAAI;cAK/B,MAAM,IAAI,cAAc;IAW3C,SAAS,CAAC,UAAU,IAAI,cAAc;IAItC,SAAS,CAAC,eAAe,IAAI,cAAc;IAS3C,SAAS,CAAC,YAAY,IAAI,cAAc;CAGzC"}
|
|
@@ -202,6 +202,9 @@ let BaseButton = (() => {
|
|
|
202
202
|
/**
|
|
203
203
|
* Turns a `<ui-button>` element into a popover control button; takes the ID
|
|
204
204
|
* of the popover element to control as its value.
|
|
205
|
+
*
|
|
206
|
+
* Note: this is required for now as the spec only allows to control popovers
|
|
207
|
+
* via buttons. Custom elements are not allowed to control popovers.
|
|
205
208
|
* @attribute
|
|
206
209
|
*/
|
|
207
210
|
get popoverTarget() { return this.#popoverTarget_accessor_storage; }
|
|
@@ -379,6 +382,7 @@ let BaseButton = (() => {
|
|
|
379
382
|
element.showPopover();
|
|
380
383
|
}
|
|
381
384
|
else {
|
|
385
|
+
// default to toggle
|
|
382
386
|
element.togglePopover();
|
|
383
387
|
}
|
|
384
388
|
element.focus();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../../src/md/button/internals/base.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAA4C,MAAM,KAAK,CAAA;AAC7E,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE9C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAElE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAE9D,OAAO,2BAA2B,CAAA;AAClC,OAAO,mCAAmC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,IAAI,CAAA;QACP,IAAI,CAAC,eAAe,EAAE,IAAI,IAAI,CAAC,YAAY,EAAE,IAAI,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI;;QAE9E,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO;KAChC,CAAA;QACH,CAAC;QAES,UAAU;YAClB,OAAO,IAAI,CAAA,2BAA2B,CAAA;QACxC,CAAC;QAES,eAAe;YACvB,OAAO,IAAI,CAAA;;;kBAGG,IAAI;iBACL,IAAI,CAAC,WAAW;sBACX,CAAA;QACpB,CAAC;QAES,YAAY;YACpB,OAAO,IAAI,CAAA,wCAAwC,IAAI,CAAC,QAAQ,gBAAgB,CAAA;QAClF,CAAC;;;AArXH;;;;;;;;;;GAUG;AACH","sourcesContent":["import { html, nothing, type PropertyValues, type TemplateResult } from 'lit'\nimport { property, query } from 'lit/decorators.js'\nimport { nanoid } from 'nanoid'\nimport { UiElement } from '../../UiElement.js'\nimport type { BeginPressConfig, EndPressConfig } from '../../../controllers/ActionController.js'\nimport { isDisabled, setDisabled } from '../../../lib/disabled.js'\nimport type UiRipple from '../../ripple/internals/ripple.js'\nimport { findElementInShadowRoots } from '../../../lib/Dom.js'\n\nimport '../../ripple/ui-ripple.js'\nimport '../../focus-ring/ui-focus-ring.js'\n\nexport type ButtonType = 'submit' | 'reset' | 'button'\nexport type MdButtonShape = 'round' | 'square'\nexport type MdButtonSize = 'xs' | 's' | 'm' | 'l' | 'xl'\n\n/**\n * A material design button with M3 Expressive features - CSS-native implementation.\n *\n * @slot icon - A slot for the icon element\n * @slot - The default slot for the label\n * @attribute {string} form - The form associated with this element when the element is outside the form.\n * @fires {ToggleEvent} toggle - Fired when the `toggle` property is true and the button is clicked,\n * changing its selection state.\n * The event's `newState` and `oldState` properties (string values: 'selected' or\n * 'unselected') detail this selection change.\n */\nexport default class BaseButton extends UiElement {\n static readonly formAssociated = true\n\n #internals = this.attachInternals()\n\n /**\n * The form associated with this element\n * @attribute\n */\n get form(): HTMLFormElement | null | string {\n return this.#internals.form\n }\n\n get validity() {\n return this.#internals.validity\n }\n\n get validationMessage() {\n return this.#internals.validationMessage\n }\n\n get willValidate() {\n return this.#internals.willValidate\n }\n\n /**\n * The name of the button, submitted as a pair with the button's value as part of the form data.\n * @attribute\n */\n @property({ type: String }) accessor name: string | undefined\n\n #value?: string\n\n get value(): string | undefined {\n return this.#value\n }\n\n /**\n * Defines the value associated with the button's name when it's submitted with the form data.\n * @attribute\n */\n @property({ type: String })\n set value(value: string | undefined) {\n if (this.#value === value) {\n return\n }\n this.#value = value\n this.#internals?.setFormValue(value || null)\n }\n\n /**\n * Whether to render the icon at the inline end of the label rather than the inline start.\n * @attribute\n */\n @property({ type: Boolean, attribute: 'trailingicon', reflect: true }) accessor trailingIcon = false\n\n /**\n * The default behavior of the button.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor type: ButtonType = 'button'\n\n /**\n * When set, the button is a toggle button.\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor toggle = false\n\n /**\n * Indicates that the button is currently selected.\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor selected = false\n\n /**\n * The shape of the button.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor shape: MdButtonShape = 'round'\n\n /**\n * The size of the button.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor size: MdButtonSize = 's'\n\n get disabled(): boolean {\n return isDisabled(this)\n }\n\n /**\n * When set, the button is in a disabled state.\n * @attribute\n */\n @property({ reflect: true, type: Boolean })\n set disabled(value: boolean) {\n const old = isDisabled(this)\n setDisabled(this, value)\n this.requestUpdate('disabled', old)\n }\n\n @query('ui-ripple') protected accessor ripple!: UiRipple | null\n\n /**\n * Turns a `<ui-button>` element into a popover control button; takes the ID\n * of the popover element to control as its value.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor popoverTarget: string | undefined\n /**\n * Specifies the action to be performed on a popover element being controlled\n * by a control <ui-button>. Possible values are:\n *\n * - `hide` - The button will hide a shown popover. If you try to hide an already hidden popover,\n * no action will be taken.\n * - `show` - The button will show a hidden popover. If you try to show an already showing popover,\n * no action will be taken.\n * - `toggle` - The button will toggle a popover between showing and hidden. If the popover is hidden,\n * it will be shown; if the popover is showing, it will be hidden. If popoverTargetAction is omitted,\n * \"toggle\" is the default action that will be performed by the control button.\n */\n @property({ type: String, reflect: true }) accessor popoverTargetAction: string | undefined\n /**\n * When true, the focus ring effect will be constrained to the inside of the button's bounds.\n * @attribute\n */\n @property({ type: Boolean }) accessor inwardFocus: boolean | undefined\n\n constructor() {\n super()\n this.actionController.cancelKeyboardEvents = true\n this.addEventListener('keydown', this.handleKeyDown.bind(this))\n this.addEventListener('keyup', this.handleKeyUp.bind(this))\n this.addEventListener('click', this.handleClick.bind(this))\n this.addEventListener('pointerdown', this.handlePointerDown.bind(this))\n this.addEventListener('pointerup', this.handlePointerUp.bind(this))\n this.addEventListener('pointercancel', this.handlePointerCancel.bind(this))\n this.addEventListener('pointerleave', this.handlePointerLeave.bind(this))\n this.addEventListener('pointerenter', this.handlePointerEnter.bind(this))\n this.addEventListener('contextmenu', this.handleContextMenu.bind(this))\n }\n\n override connectedCallback(): void {\n super.connectedCallback()\n if (!this.hasAttribute('role')) {\n this.setAttribute('role', 'button')\n }\n if (!this.hasAttribute('tabindex') && !this.disabled) {\n this.setAttribute('tabindex', '0')\n }\n }\n\n protected override update(changedProperties: PropertyValues<this>): void {\n if (changedProperties.has('popoverTarget')) {\n this.setupPopoverTarget()\n }\n super.update(changedProperties)\n }\n\n protected override updated(cp: PropertyValues<this>): void {\n super.updated(cp)\n\n // If the button is disabled, remove the tabindex attribute\n if (cp.has('disabled')) {\n if (this.disabled) {\n this.removeAttribute('tabindex')\n } else if (!this.hasAttribute('tabindex')) {\n this.setAttribute('tabindex', '0')\n }\n }\n\n if (cp.has('toggle') || cp.has('selected')) {\n this.updatePressedState()\n }\n }\n\n protected updatePressedState(): void {\n if (this.toggle) {\n this.ariaPressed = String(this.selected)\n } else {\n this.selected = false\n this.removeAttribute('aria-pressed')\n }\n }\n\n checkValidity() {\n return this.#internals.checkValidity()\n }\n\n reportValidity() {\n return this.#internals.reportValidity()\n }\n\n protected override firstUpdated(): void {\n this.#internals?.setFormValue(this.value || null)\n }\n\n override beginPress(options: BeginPressConfig): void {\n super.beginPress(options)\n this.classList.add('pressed')\n this.ripple?.beginFocus()\n }\n\n override endPress(config: EndPressConfig): void {\n super.endPress(config)\n this.classList.remove('pressed')\n this.ripple?.endFocus()\n const { cancelled, reason } = config\n if (cancelled) {\n return\n }\n const allowedReasons = reason === 'enter' || reason === 'space'\n if (this.type === 'submit' && (!reason || allowedReasons)) {\n this.handleSubmit()\n } else if (this.type === 'reset' && (!reason || allowedReasons)) {\n this.handleReset()\n } else if (allowedReasons) {\n this.click()\n }\n }\n\n override handleClick(e: MouseEvent): void {\n if (this.disabled) {\n e.preventDefault()\n e.stopPropagation()\n return\n }\n\n if (this.toggle) {\n this.selected = !this.selected\n const e = new ToggleEvent('toggle', {\n bubbles: true,\n composed: true,\n newState: this.selected ? 'selected' : 'unselected',\n oldState: this.selected ? 'unselected' : 'selected',\n })\n this.dispatchEvent(e)\n }\n this.handlePopoverAction()\n // Delegate to ActionController to properly end the press and reset phase\n // state; this removes the 'pressed' class via endPress() and ensures\n // subsequent pointerdown events work again.\n super.handleClick(e)\n }\n\n protected setupPopoverTarget(): void {\n const id = this.popoverTarget\n if (!id) {\n return\n }\n const element = findElementInShadowRoots(id, this)\n if (!element) {\n return\n }\n // A regular button first sets its value to the popover target ID,\n this.value = id\n // create an anchor association with the popover target\n if (!this.id) {\n this.id = nanoid()\n }\n const anchorName = `--anchor-${this.id}`\n this.style.setProperty('anchor-name', anchorName)\n element.style.setProperty('position-anchor', anchorName)\n this.setAttribute('aria-details', id)\n this.setAttribute('aria-controls', id)\n }\n\n /**\n * When the button has a popover target, this method toggles the popover\n * visibility by finding the element in the shadow roots and calling its\n * `togglePopover` method.\n */\n protected handlePopoverAction(): void {\n const id = this.popoverTarget\n if (!id) {\n return\n }\n const element = findElementInShadowRoots(id, this)\n if (!element) {\n return\n }\n const action = this.popoverTargetAction || 'toggle'\n if (action === 'hide') {\n element.hidePopover()\n } else if (action === 'show') {\n element.showPopover()\n } else {\n element.togglePopover()\n }\n element.focus()\n }\n\n protected handleSubmit(): void {\n const { name, value, type, disabled, form } = this\n if (!form || !type || disabled) {\n return\n }\n const typedForm = form as HTMLFormElement\n let button: HTMLButtonElement | undefined\n if (name || value) {\n button = document.createElement('button')\n if (name) {\n button.name = name\n }\n if (value) {\n button.value = value\n }\n button.type = type\n button.hidden = true\n typedForm.append(button)\n }\n try {\n typedForm.requestSubmit(button)\n } catch {\n // Ignore errors\n }\n if (button) {\n typedForm.removeChild(button)\n }\n }\n\n protected handleReset(): void {\n const form = this.form as HTMLFormElement\n form?.reset()\n }\n\n override handlePointerEnter(e: PointerEvent): void {\n super.handlePointerEnter(e)\n this.ripple?.beginHover(e)\n }\n\n override handlePointerLeave(e: PointerEvent): void {\n super.handlePointerLeave(e)\n this.ripple?.endHover()\n }\n\n protected override render(): TemplateResult {\n const { trailingIcon = false } = this\n const icon = this.renderIcon()\n\n return html`\n ${this.renderFocusRing()} ${this.renderRipple()} ${trailingIcon ? nothing : icon}\n <slot></slot>\n ${trailingIcon ? icon : nothing}\n `\n }\n\n protected renderIcon(): TemplateResult {\n return html`<slot name=\"icon\"></slot>`\n }\n\n protected renderFocusRing(): TemplateResult {\n return html`<ui-focus-ring\n part=\"focus-ring\"\n class=\"focus-ring\"\n .control=\"${this}\"\n ?inward=\"${this.inwardFocus}\"\n ></ui-focus-ring>`\n }\n\n protected renderRipple(): TemplateResult {\n return html`<ui-ripple class=\"ripple\" ?disabled=\"${this.disabled}\"></ui-ripple>`\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../../src/md/button/internals/base.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,OAAO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AAC,CAAC,CAAA;YAC3B,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAA;QAC5B,CAAC;QAEQ,kBAAkB,CAAC,CAAe;YACzC,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAA;YAC3B,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAA;QACzB,CAAC;QAEkB,MAAM;YACvB,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,GAAG,IAAI,CAAA;YACrC,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,CAAA;YAE9B,OAAO,IAAI,CAAA;QACP,IAAI,CAAC,eAAe,EAAE,IAAI,IAAI,CAAC,YAAY,EAAE,IAAI,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI;;QAE9E,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO;KAChC,CAAA;QACH,CAAC;QAES,UAAU;YAClB,OAAO,IAAI,CAAA,2BAA2B,CAAA;QACxC,CAAC;QAES,eAAe;YACvB,OAAO,IAAI,CAAA;;;kBAGG,IAAI;iBACL,IAAI,CAAC,WAAW;sBACX,CAAA;QACpB,CAAC;QAES,YAAY;YACpB,OAAO,IAAI,CAAA,wCAAwC,IAAI,CAAC,QAAQ,gBAAgB,CAAA;QAClF,CAAC;;;AAzXH;;;;;;;;;;GAUG;AACH","sourcesContent":["import { html, nothing, type PropertyValues, type TemplateResult } from 'lit'\nimport { property, query } from 'lit/decorators.js'\nimport { nanoid } from 'nanoid'\nimport { UiElement } from '../../UiElement.js'\nimport type { BeginPressConfig, EndPressConfig } from '../../../controllers/ActionController.js'\nimport { isDisabled, setDisabled } from '../../../lib/disabled.js'\nimport type UiRipple from '../../ripple/internals/ripple.js'\nimport { findElementInShadowRoots } from '../../../lib/Dom.js'\n\nimport '../../ripple/ui-ripple.js'\nimport '../../focus-ring/ui-focus-ring.js'\n\nexport type ButtonType = 'submit' | 'reset' | 'button'\nexport type MdButtonShape = 'round' | 'square'\nexport type MdButtonSize = 'xs' | 's' | 'm' | 'l' | 'xl'\n\n/**\n * A material design button with M3 Expressive features - CSS-native implementation.\n *\n * @slot icon - A slot for the icon element\n * @slot - The default slot for the label\n * @attribute {string} form - The form associated with this element when the element is outside the form.\n * @fires {ToggleEvent} toggle - Fired when the `toggle` property is true and the button is clicked,\n * changing its selection state.\n * The event's `newState` and `oldState` properties (string values: 'selected' or\n * 'unselected') detail this selection change.\n */\nexport default class BaseButton extends UiElement {\n static readonly formAssociated = true\n\n #internals = this.attachInternals()\n\n /**\n * The form associated with this element\n * @attribute\n */\n get form(): HTMLFormElement | null | string {\n return this.#internals.form\n }\n\n get validity() {\n return this.#internals.validity\n }\n\n get validationMessage() {\n return this.#internals.validationMessage\n }\n\n get willValidate() {\n return this.#internals.willValidate\n }\n\n /**\n * The name of the button, submitted as a pair with the button's value as part of the form data.\n * @attribute\n */\n @property({ type: String }) accessor name: string | undefined\n\n #value?: string\n\n get value(): string | undefined {\n return this.#value\n }\n\n /**\n * Defines the value associated with the button's name when it's submitted with the form data.\n * @attribute\n */\n @property({ type: String })\n set value(value: string | undefined) {\n if (this.#value === value) {\n return\n }\n this.#value = value\n this.#internals?.setFormValue(value || null)\n }\n\n /**\n * Whether to render the icon at the inline end of the label rather than the inline start.\n * @attribute\n */\n @property({ type: Boolean, attribute: 'trailingicon', reflect: true }) accessor trailingIcon = false\n\n /**\n * The default behavior of the button.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor type: ButtonType = 'button'\n\n /**\n * When set, the button is a toggle button.\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor toggle = false\n\n /**\n * Indicates that the button is currently selected.\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor selected = false\n\n /**\n * The shape of the button.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor shape: MdButtonShape = 'round'\n\n /**\n * The size of the button.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor size: MdButtonSize = 's'\n\n get disabled(): boolean {\n return isDisabled(this)\n }\n\n /**\n * When set, the button is in a disabled state.\n * @attribute\n */\n @property({ reflect: true, type: Boolean })\n set disabled(value: boolean) {\n const old = isDisabled(this)\n setDisabled(this, value)\n this.requestUpdate('disabled', old)\n }\n\n @query('ui-ripple') protected accessor ripple!: UiRipple | null\n\n /**\n * Turns a `<ui-button>` element into a popover control button; takes the ID\n * of the popover element to control as its value.\n *\n * Note: this is required for now as the spec only allows to control popovers\n * via buttons. Custom elements are not allowed to control popovers.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor popoverTarget: string | undefined\n /**\n * Specifies the action to be performed on a popover element being controlled\n * by a control <ui-button>. Possible values are:\n *\n * - `hide` - The button will hide a shown popover. If you try to hide an already hidden popover,\n * no action will be taken.\n * - `show` - The button will show a hidden popover. If you try to show an already showing popover,\n * no action will be taken.\n * - `toggle` - The button will toggle a popover between showing and hidden. If the popover is hidden,\n * it will be shown; if the popover is showing, it will be hidden. If popoverTargetAction is omitted,\n * \"toggle\" is the default action that will be performed by the control button.\n */\n @property({ type: String, reflect: true }) accessor popoverTargetAction: 'hide' | 'show' | 'toggle' | undefined\n /**\n * When true, the focus ring effect will be constrained to the inside of the button's bounds.\n * @attribute\n */\n @property({ type: Boolean }) accessor inwardFocus: boolean | undefined\n\n constructor() {\n super()\n this.actionController.cancelKeyboardEvents = true\n this.addEventListener('keydown', this.handleKeyDown.bind(this))\n this.addEventListener('keyup', this.handleKeyUp.bind(this))\n this.addEventListener('click', this.handleClick.bind(this))\n this.addEventListener('pointerdown', this.handlePointerDown.bind(this))\n this.addEventListener('pointerup', this.handlePointerUp.bind(this))\n this.addEventListener('pointercancel', this.handlePointerCancel.bind(this))\n this.addEventListener('pointerleave', this.handlePointerLeave.bind(this))\n this.addEventListener('pointerenter', this.handlePointerEnter.bind(this))\n this.addEventListener('contextmenu', this.handleContextMenu.bind(this))\n }\n\n override connectedCallback(): void {\n super.connectedCallback()\n if (!this.hasAttribute('role')) {\n this.setAttribute('role', 'button')\n }\n if (!this.hasAttribute('tabindex') && !this.disabled) {\n this.setAttribute('tabindex', '0')\n }\n }\n\n protected override update(changedProperties: PropertyValues<this>): void {\n if (changedProperties.has('popoverTarget')) {\n this.setupPopoverTarget()\n }\n super.update(changedProperties)\n }\n\n protected override updated(cp: PropertyValues<this>): void {\n super.updated(cp)\n\n // If the button is disabled, remove the tabindex attribute\n if (cp.has('disabled')) {\n if (this.disabled) {\n this.removeAttribute('tabindex')\n } else if (!this.hasAttribute('tabindex')) {\n this.setAttribute('tabindex', '0')\n }\n }\n\n if (cp.has('toggle') || cp.has('selected')) {\n this.updatePressedState()\n }\n }\n\n protected updatePressedState(): void {\n if (this.toggle) {\n this.ariaPressed = String(this.selected)\n } else {\n this.selected = false\n this.removeAttribute('aria-pressed')\n }\n }\n\n checkValidity() {\n return this.#internals.checkValidity()\n }\n\n reportValidity() {\n return this.#internals.reportValidity()\n }\n\n protected override firstUpdated(): void {\n this.#internals?.setFormValue(this.value || null)\n }\n\n override beginPress(options: BeginPressConfig): void {\n super.beginPress(options)\n this.classList.add('pressed')\n this.ripple?.beginFocus()\n }\n\n override endPress(config: EndPressConfig): void {\n super.endPress(config)\n this.classList.remove('pressed')\n this.ripple?.endFocus()\n const { cancelled, reason } = config\n if (cancelled) {\n return\n }\n const allowedReasons = reason === 'enter' || reason === 'space'\n if (this.type === 'submit' && (!reason || allowedReasons)) {\n this.handleSubmit()\n } else if (this.type === 'reset' && (!reason || allowedReasons)) {\n this.handleReset()\n } else if (allowedReasons) {\n this.click()\n }\n }\n\n override handleClick(e: MouseEvent): void {\n if (this.disabled) {\n e.preventDefault()\n e.stopPropagation()\n return\n }\n\n if (this.toggle) {\n this.selected = !this.selected\n const e = new ToggleEvent('toggle', {\n bubbles: true,\n composed: true,\n newState: this.selected ? 'selected' : 'unselected',\n oldState: this.selected ? 'unselected' : 'selected',\n })\n this.dispatchEvent(e)\n }\n this.handlePopoverAction()\n // Delegate to ActionController to properly end the press and reset phase\n // state; this removes the 'pressed' class via endPress() and ensures\n // subsequent pointerdown events work again.\n super.handleClick(e)\n }\n\n protected setupPopoverTarget(): void {\n const id = this.popoverTarget\n if (!id) {\n return\n }\n const element = findElementInShadowRoots(id, this)\n if (!element) {\n return\n }\n // A regular button first sets its value to the popover target ID,\n this.value = id\n // create an anchor association with the popover target\n if (!this.id) {\n this.id = nanoid()\n }\n const anchorName = `--anchor-${this.id}`\n this.style.setProperty('anchor-name', anchorName)\n element.style.setProperty('position-anchor', anchorName)\n this.setAttribute('aria-details', id)\n this.setAttribute('aria-controls', id)\n }\n\n /**\n * When the button has a popover target, this method toggles the popover\n * visibility by finding the element in the shadow roots and calling its\n * `togglePopover` method.\n */\n protected handlePopoverAction(): void {\n const id = this.popoverTarget\n if (!id) {\n return\n }\n const element = findElementInShadowRoots(id, this)\n if (!element) {\n return\n }\n const action = this.popoverTargetAction || 'toggle'\n if (action === 'hide') {\n element.hidePopover()\n } else if (action === 'show') {\n element.showPopover()\n } else {\n // default to toggle\n element.togglePopover()\n }\n element.focus()\n }\n\n protected handleSubmit(): void {\n const { name, value, type, disabled, form } = this\n if (!form || !type || disabled) {\n return\n }\n const typedForm = form as HTMLFormElement\n let button: HTMLButtonElement | undefined\n if (name || value) {\n button = document.createElement('button')\n if (name) {\n button.name = name\n }\n if (value) {\n button.value = value\n }\n button.type = type\n button.hidden = true\n typedForm.append(button)\n }\n try {\n typedForm.requestSubmit(button)\n } catch {\n // Ignore errors\n }\n if (button) {\n typedForm.removeChild(button)\n }\n }\n\n protected handleReset(): void {\n const form = this.form as HTMLFormElement\n form?.reset()\n }\n\n override handlePointerEnter(e: PointerEvent): void {\n super.handlePointerEnter(e)\n this.ripple?.beginHover(e)\n }\n\n override handlePointerLeave(e: PointerEvent): void {\n super.handlePointerLeave(e)\n this.ripple?.endHover()\n }\n\n protected override render(): TemplateResult {\n const { trailingIcon = false } = this\n const icon = this.renderIcon()\n\n return html`\n ${this.renderFocusRing()} ${this.renderRipple()} ${trailingIcon ? nothing : icon}\n <slot></slot>\n ${trailingIcon ? icon : nothing}\n `\n }\n\n protected renderIcon(): TemplateResult {\n return html`<slot name=\"icon\"></slot>`\n }\n\n protected renderFocusRing(): TemplateResult {\n return html`<ui-focus-ring\n part=\"focus-ring\"\n class=\"focus-ring\"\n .control=\"${this}\"\n ?inward=\"${this.inwardFocus}\"\n ></ui-focus-ring>`\n }\n\n protected renderRipple(): TemplateResult {\n return html`<ui-ripple class=\"ripple\" ?disabled=\"${this.disabled}\"></ui-ripple>`\n }\n}\n"]}
|
|
@@ -36,9 +36,53 @@ export default class OrganizationService extends Service {
|
|
|
36
36
|
*/
|
|
37
37
|
pendingOid: string | undefined | null;
|
|
38
38
|
protected onCreate(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use #setOrganization instead
|
|
41
|
+
*/
|
|
42
|
+
setupUserOrganization(org: IOrganization): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Sets an org as the current user org.
|
|
45
|
+
* @param org The organization to add.
|
|
46
|
+
*/
|
|
47
|
+
setOrganization(org: IOrganization): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Adds an organization to the list of organizations.
|
|
50
|
+
* It also updated the cache. Used when creating a new org.
|
|
51
|
+
* @param org The organization to add.
|
|
52
|
+
*/
|
|
53
|
+
addOrganization(org: IOrganization): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Removes an organization from the list of organizations.
|
|
56
|
+
* It also updated the cache. Used when deleting an org.
|
|
57
|
+
* @param org The organization to remove.
|
|
58
|
+
*/
|
|
59
|
+
removeOrganization(org: IOrganization): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Use #readOrganization instead
|
|
62
|
+
*/
|
|
39
63
|
getUserOrganization(id: string): Promise<IOrganization>;
|
|
64
|
+
/**
|
|
65
|
+
* Reads an organization from the list of organizations.
|
|
66
|
+
* @param id The organization ID.
|
|
67
|
+
* @returns The organization.
|
|
68
|
+
*/
|
|
69
|
+
readOrganization(id: string): Promise<IOrganization>;
|
|
70
|
+
/**
|
|
71
|
+
* Gets the current user organization.
|
|
72
|
+
* @returns The current organization or undefined if not set.
|
|
73
|
+
*/
|
|
40
74
|
currentOrganization(): Promise<IOrganization | undefined>;
|
|
75
|
+
/**
|
|
76
|
+
* Checks if the user has a specific grant type in the current organization.
|
|
77
|
+
* @param grantType The grant type to check.
|
|
78
|
+
* @returns `true` if the user has the specified grant type, `false` otherwise.
|
|
79
|
+
*/
|
|
41
80
|
protected hasGrantType(grantType: UserOrganizationGrantType): Promise<boolean>;
|
|
81
|
+
/**
|
|
82
|
+
* Checks if the user has any of the specified grant types in the current organization.
|
|
83
|
+
* @param types The grant types to check.
|
|
84
|
+
* @returns `true` if the user has any of the specified grant types, `false` otherwise.
|
|
85
|
+
*/
|
|
42
86
|
hasRoles(types: UserOrganizationGrantType[]): Promise<boolean>;
|
|
43
87
|
/**
|
|
44
88
|
* Checks if the user is the owner of the current organization.
|
|
@@ -68,12 +112,6 @@ export default class OrganizationService extends Service {
|
|
|
68
112
|
* @returns The state of the organization creation.
|
|
69
113
|
*/
|
|
70
114
|
revalidate(): Promise<CompletionState>;
|
|
71
|
-
/**
|
|
72
|
-
* When the user has no organizations, it set the organization as the only one
|
|
73
|
-
* and persists the organization id as the selected organization.
|
|
74
|
-
* @param org The organization to add.
|
|
75
|
-
*/
|
|
76
|
-
setupUserOrganization(org: IOrganization): Promise<void>;
|
|
77
115
|
}
|
|
78
116
|
export {};
|
|
79
117
|
//# sourceMappingURL=OrganizationService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OrganizationService.d.ts","sourceRoot":"","sources":["../../../src/services/OrganizationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,+CAA+C,CAAA;AAI7G,aAAK,KAAK;IACR,UAAU,IAAA;IACV,QAAQ,IAAA;IACR,OAAO,IAAA;CACR;AAED,oBAAY,eAAe;IACzB;;OAEG;IACH,EAAE,IAAA;IACF;;OAEG;IACH,WAAW,IAAA;IACX;;OAEG;IACH,eAAe,IAAA;IACf;;OAEG;IACH,KAAK,IAAA;CACN;AAID,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,OAAO;;IACtD,OAAgB,GAAG,SAA6B;IAEhD,KAAK,EAAE,KAAK,CAAmB;IAC/B,aAAa,EAAE,aAAa,EAAE,CAAK;IACnC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAA;IAClC;;;;OAIG;IACH,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;cAYZ,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"OrganizationService.d.ts","sourceRoot":"","sources":["../../../src/services/OrganizationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,+CAA+C,CAAA;AAI7G,aAAK,KAAK;IACR,UAAU,IAAA;IACV,QAAQ,IAAA;IACR,OAAO,IAAA;CACR;AAED,oBAAY,eAAe;IACzB;;OAEG;IACH,EAAE,IAAA;IACF;;OAEG;IACH,WAAW,IAAA;IACX;;OAEG;IACH,eAAe,IAAA;IACf;;OAEG;IACH,KAAK,IAAA;CACN;AAID,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,OAAO;;IACtD,OAAgB,GAAG,SAA6B;IAEhD,KAAK,EAAE,KAAK,CAAmB;IAC/B,aAAa,EAAE,aAAa,EAAE,CAAK;IACnC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAA;IAClC;;;;OAIG;IACH,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;cAYZ,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAMlD;;OAEG;IACH,qBAAqB,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxD;;;OAGG;IACG,eAAe,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxD;;;;OAIG;IACG,eAAe,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAQxD;;;;OAIG;IACG,kBAAkB,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAa3D;;OAEG;IACH,mBAAmB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAIvD;;;;OAIG;IACG,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAS1D;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAU/D;;;;OAIG;cACa,YAAY,CAAC,SAAS,EAAE,yBAAyB,GAAG,OAAO,CAAC,OAAO,CAAC;IAQpF;;;;OAIG;IACG,QAAQ,CAAC,KAAK,EAAE,yBAAyB,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAQpE;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IAIjC;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAInC;;;OAGG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAIlC;;;;;;;;;;;OAWG;IACH,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC;CAsFvC"}
|
|
@@ -49,8 +49,68 @@ export default class OrganizationService extends Service {
|
|
|
49
49
|
async onCreate() {
|
|
50
50
|
const url = new URL(window.location.href);
|
|
51
51
|
this.pendingOid = url.searchParams.get('oid');
|
|
52
|
+
this.revalidate();
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated Use #setOrganization instead
|
|
56
|
+
*/
|
|
57
|
+
setupUserOrganization(org) {
|
|
58
|
+
return this.setOrganization(org);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Sets an org as the current user org.
|
|
62
|
+
* @param org The organization to add.
|
|
63
|
+
*/
|
|
64
|
+
async setOrganization(org) {
|
|
65
|
+
const hasOrg = this.organizations.some((i) => i.key === org.key);
|
|
66
|
+
if (!hasOrg) {
|
|
67
|
+
this.organizations.push(org);
|
|
68
|
+
}
|
|
69
|
+
const config = await services.get('config');
|
|
70
|
+
await config.local.set(CurrentOrganizationKey, org.key);
|
|
71
|
+
this.organizationId = org.key;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Adds an organization to the list of organizations.
|
|
75
|
+
* It also updated the cache. Used when creating a new org.
|
|
76
|
+
* @param org The organization to add.
|
|
77
|
+
*/
|
|
78
|
+
async addOrganization(org) {
|
|
79
|
+
const hasOrg = this.organizations.some((i) => i.key === org.key);
|
|
80
|
+
if (!hasOrg) {
|
|
81
|
+
this.organizations.push(org);
|
|
82
|
+
await this.#saveCache();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Removes an organization from the list of organizations.
|
|
87
|
+
* It also updated the cache. Used when deleting an org.
|
|
88
|
+
* @param org The organization to remove.
|
|
89
|
+
*/
|
|
90
|
+
async removeOrganization(org) {
|
|
91
|
+
const idx = this.organizations.findIndex((i) => i.key === org.key);
|
|
92
|
+
if (idx !== -1) {
|
|
93
|
+
this.organizations.splice(idx, 1);
|
|
94
|
+
await this.#saveCache();
|
|
95
|
+
if (this.organizationId === org.key) {
|
|
96
|
+
this.organizationId = undefined;
|
|
97
|
+
const config = await services.get('config');
|
|
98
|
+
await config.local.delete(CurrentOrganizationKey);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* @deprecated Use #readOrganization instead
|
|
104
|
+
*/
|
|
105
|
+
getUserOrganization(id) {
|
|
106
|
+
return this.readOrganization(id);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Reads an organization from the list of organizations.
|
|
110
|
+
* @param id The organization ID.
|
|
111
|
+
* @returns The organization.
|
|
112
|
+
*/
|
|
113
|
+
async readOrganization(id) {
|
|
54
114
|
await this.#updateComplete;
|
|
55
115
|
const org = this.organizations.find((i) => i.key === id);
|
|
56
116
|
if (!org) {
|
|
@@ -58,6 +118,10 @@ export default class OrganizationService extends Service {
|
|
|
58
118
|
}
|
|
59
119
|
return org;
|
|
60
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Gets the current user organization.
|
|
123
|
+
* @returns The current organization or undefined if not set.
|
|
124
|
+
*/
|
|
61
125
|
async currentOrganization() {
|
|
62
126
|
if (this.state === State.Checking) {
|
|
63
127
|
await this.#updateComplete;
|
|
@@ -65,10 +129,13 @@ export default class OrganizationService extends Service {
|
|
|
65
129
|
if (!this.organizationId) {
|
|
66
130
|
return undefined;
|
|
67
131
|
}
|
|
68
|
-
// TODO: we will store the orgs list in the local/session store
|
|
69
|
-
// so we won't be pinging server with every page reload.
|
|
70
132
|
return this.organizations.find((i) => i.key === this.organizationId);
|
|
71
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Checks if the user has a specific grant type in the current organization.
|
|
136
|
+
* @param grantType The grant type to check.
|
|
137
|
+
* @returns `true` if the user has the specified grant type, `false` otherwise.
|
|
138
|
+
*/
|
|
72
139
|
async hasGrantType(grantType) {
|
|
73
140
|
const org = await this.currentOrganization();
|
|
74
141
|
if (!org) {
|
|
@@ -76,6 +143,11 @@ export default class OrganizationService extends Service {
|
|
|
76
143
|
}
|
|
77
144
|
return org.grantType === grantType;
|
|
78
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Checks if the user has any of the specified grant types in the current organization.
|
|
148
|
+
* @param types The grant types to check.
|
|
149
|
+
* @returns `true` if the user has any of the specified grant types, `false` otherwise.
|
|
150
|
+
*/
|
|
79
151
|
async hasRoles(types) {
|
|
80
152
|
const org = await this.currentOrganization();
|
|
81
153
|
if (!org) {
|
|
@@ -120,9 +192,6 @@ export default class OrganizationService extends Service {
|
|
|
120
192
|
if (this.state === State.Checking) {
|
|
121
193
|
return this.#updateComplete;
|
|
122
194
|
}
|
|
123
|
-
if (this.organizationId) {
|
|
124
|
-
return Promise.resolve(CompletionState.OK);
|
|
125
|
-
}
|
|
126
195
|
this.state = State.Checking;
|
|
127
196
|
this.#updateComplete = new Promise((resolver) => {
|
|
128
197
|
this.#updateResolver = resolver;
|
|
@@ -158,20 +227,20 @@ export default class OrganizationService extends Service {
|
|
|
158
227
|
}
|
|
159
228
|
return false;
|
|
160
229
|
}
|
|
161
|
-
async #saveCache(
|
|
230
|
+
async #saveCache() {
|
|
162
231
|
const cache = await services.get('cache');
|
|
163
|
-
if (
|
|
232
|
+
if (this.organizations.length === 0) {
|
|
164
233
|
await cache.delete(OrgsCacheKey);
|
|
165
234
|
}
|
|
166
235
|
else {
|
|
167
|
-
await cache.set(OrgsCacheKey,
|
|
236
|
+
await cache.set(OrgsCacheKey, this.organizations, cache.TTL.OneHour);
|
|
168
237
|
}
|
|
169
238
|
}
|
|
170
239
|
async #callOrganizations() {
|
|
171
240
|
const sdk = await services.get('sdk');
|
|
172
241
|
const orgs = await sdk.organizations.list();
|
|
173
242
|
this.organizations = orgs.items || [];
|
|
174
|
-
await this.#saveCache(
|
|
243
|
+
await this.#saveCache();
|
|
175
244
|
}
|
|
176
245
|
#resolve(state) {
|
|
177
246
|
if (this.#updateResolver) {
|
|
@@ -204,19 +273,5 @@ export default class OrganizationService extends Service {
|
|
|
204
273
|
}
|
|
205
274
|
return result;
|
|
206
275
|
}
|
|
207
|
-
/**
|
|
208
|
-
* When the user has no organizations, it set the organization as the only one
|
|
209
|
-
* and persists the organization id as the selected organization.
|
|
210
|
-
* @param org The organization to add.
|
|
211
|
-
*/
|
|
212
|
-
async setupUserOrganization(org) {
|
|
213
|
-
const hasOrg = this.organizations.some((i) => i.key === org.key);
|
|
214
|
-
if (!hasOrg) {
|
|
215
|
-
this.organizations.push(org);
|
|
216
|
-
}
|
|
217
|
-
const config = await services.get('config');
|
|
218
|
-
await config.local.set(CurrentOrganizationKey, org.key);
|
|
219
|
-
this.organizationId = org.key;
|
|
220
|
-
}
|
|
221
276
|
}
|
|
222
277
|
//# sourceMappingURL=OrganizationService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OrganizationService.js","sourceRoot":"","sources":["../../../src/services/OrganizationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAE5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAC5D,OAAO,QAAQ,MAAM,kBAAkB,CAAA;AAEvC,IAAK,KAIJ;AAJD,WAAK,KAAK;IACR,6CAAU,CAAA;IACV,yCAAQ,CAAA;IACR,uCAAO,CAAA;AACT,CAAC,EAJI,KAAK,KAAL,KAAK,QAIT;AAED,MAAM,CAAN,IAAY,eAiBX;AAjBD,WAAY,eAAe;IACzB;;OAEG;IACH,iDAAE,CAAA;IACF;;OAEG;IACH,mEAAW,CAAA;IACX;;OAEG;IACH,2EAAe,CAAA;IACf;;OAEG;IACH,uDAAK,CAAA;AACP,CAAC,EAjBW,eAAe,KAAf,eAAe,QAiB1B;AAED,MAAM,YAAY,GAAG,oBAAoB,CAAA;AAEzC,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,OAAO;IACtD,MAAM,CAAU,GAAG,GAAG,0BAA0B,CAAA;IAEhD,KAAK,GAAU,KAAK,CAAC,UAAU,CAAA;IAC/B,aAAa,GAAoB,EAAE,CAAA;IACnC,cAAc,CAAoB;IAClC;;;;OAIG;IACH,UAAU,CAA2B;IAErC;;OAEG;IACH,eAAe,CAA2B;IAE1C;;OAEG;IACH,eAAe,CAAmC;IAE/B,KAAK,CAAC,QAAQ;QAC/B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,C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AAM,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;YACrC,MAAM,GAAG,eAAe,CAAC,WAAW,CAAA;QACtC,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,eAAe,CAAC,eAAe,CAAA;QAC1C,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,qBAAqB,CAAC,GAAkB;QAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAA;QAChE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC9B,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAC3C,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,sBAAsB,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;QACvD,IAAI,CAAC,cAAc,GAAG,GAAG,CAAC,GAAG,CAAA;IAC/B,CAAC","sourcesContent":["import { Service } from '../core/Service.js'\nimport type { IOrganization, UserOrganizationGrantType } from '@api-client/core/models/store/Organization.js'\nimport { CurrentOrganizationKey } from '../lib/StoreKeys.js'\nimport services from './api_service.js'\n\nenum State {\n NotChecked,\n Checking,\n Checked,\n}\n\nexport enum CompletionState {\n /**\n * The user has at least one organization and the current organization is selected.\n */\n OK,\n /**\n * The user has at leas two organizations and no valid selection.\n */\n NotSelected,\n /**\n * The user have no organizations. Setup is needed.\n */\n NoOrganizations,\n /**\n * Unable to determine the state due to an error.\n */\n Error,\n}\n\nconst OrgsCacheKey = 'user_organizations'\n\nexport default class OrganizationService extends Service {\n static override key = 'api-service/organization'\n\n state: State = State.NotChecked\n organizations: IOrganization[] = []\n organizationId: string | undefined\n /**\n * A pending organization ID that was set via the URL query parameter `oid`.\n * When it is set, it preselects the organization when loading list of organizations.\n * This will override the `organizationId` set in the local storage.\n */\n pendingOid: string | undefined | null\n\n /**\n * A hidden value for the `updateComplete` getter.\n */\n #updateComplete?: Promise<CompletionState>\n\n /**\n * The resolver to call when the update completes.\n */\n #updateResolver?: (state: CompletionState) => void\n\n protected override async onCreate(): Promise<void> {\n const url = new URL(window.location.href)\n this.pendingOid = url.searchParams.get('oid')\n }\n\n async getUserOrganization(id: string): Promise<IOrganization> {\n await this.#updateComplete\n const org = this.organizations.find((i) => i.key === id)\n if (!org) {\n throw new Error(`Organization with id ${id} not found`)\n }\n return org\n }\n\n async currentOrganization(): Promise<IOrganization | undefined> {\n if (this.state === State.Checking) {\n await this.#updateComplete\n }\n if (!this.organizationId) {\n return undefined\n }\n // TODO: we will store the orgs list in the local/session store\n // so we won't be pinging server with every page reload.\n return this.organizations.find((i) => i.key === this.organizationId)\n }\n\n protected async hasGrantType(grantType: UserOrganizationGrantType): Promise<boolean> {\n const org = await this.currentOrganization()\n if (!org) {\n return false\n }\n return org.grantType === grantType\n }\n\n async hasRoles(types: UserOrganizationGrantType[]): Promise<boolean> {\n const org = await this.currentOrganization()\n if (!org) {\n return false\n }\n return types.includes(org.grantType)\n }\n\n /**\n * Checks if the user is the owner of the current organization.\n * @returns `true` if the user is the owner of the current organization, `false` otherwise.\n */\n async isOwner(): Promise<boolean> {\n return this.hasGrantType('owner')\n }\n\n /**\n * Checks if the user is a manager of the current organization.\n * @returns `true` if the user is a manager of the current organization, `false` otherwise.\n */\n async isManager(): Promise<boolean> {\n return this.hasGrantType('manager')\n }\n\n /**\n * Checks if the user is an editor of the current organization.\n * @returns `true` if the user is a editor of the current organization, `false` otherwise.\n */\n async isEditor(): Promise<boolean> {\n return this.hasGrantType('editor')\n }\n\n /**\n * Forces to get the list of organizations from the server.\n *\n * Returns one of the following states:\n *\n * - `CompletionState.OK` - The user has at least one organization and the current organization is selected.\n * - `CompletionState.NotSelected` - The user has at leas two organizations and no valid selection.\n * - `CompletionState.NoOrganizations` - The user have no organizations. Setup is needed.\n * - `CompletionState.Error` - Unable to determine the state due to an error.\n *\n * @returns The state of the organization creation.\n */\n revalidate(): Promise<CompletionState> {\n if (this.state === State.Checking) {\n return this.#updateComplete as Promise<CompletionState>\n }\n if (this.organizationId) {\n return Promise.resolve(CompletionState.OK)\n }\n this.state = State.Checking\n this.#updateComplete = new Promise<CompletionState>((resolver) => {\n this.#updateResolver = resolver\n })\n this.#getState()\n return this.#updateComplete\n }\n\n /**\n * Reads the list of organizations either from the cache or from the server.\n */\n async #getState(): Promise<void> {\n const loaded = await this.#loadCache()\n if (!loaded) {\n try {\n await this.#callOrganizations()\n } catch {\n this.#resolve(CompletionState.Error)\n this.state = State.Checked\n return\n }\n }\n const result = await this.#readState()\n this.state = State.Checked\n this.#resolve(result)\n }\n\n async #loadCache(): Promise<boolean> {\n const cache = await services.get('cache')\n const orgs = await cache.get<IOrganization[]>(OrgsCacheKey)\n if (orgs) {\n this.organizations = orgs\n return true\n }\n return false\n }\n\n async #saveCache(orgs: IOrganization[]): Promise<void> {\n const cache = await services.get('cache')\n if (orgs.length === 0) {\n await cache.delete(OrgsCacheKey)\n } else {\n await cache.set<IOrganization[]>(OrgsCacheKey, orgs, cache.TTL.OneHour)\n }\n }\n\n async #callOrganizations(): Promise<void> {\n const sdk = await services.get('sdk')\n const orgs = await sdk.organizations.list()\n this.organizations = orgs.items || []\n await this.#saveCache(orgs.items)\n }\n\n #resolve(state: CompletionState): void {\n if (this.#updateResolver) {\n this.#updateResolver(state)\n this.#updateResolver = undefined\n }\n }\n\n async #readState(): Promise<CompletionState> {\n const config = await services.get('config')\n const selected = this.pendingOid ?? ((await config.local.get(CurrentOrganizationKey)) as string | undefined)\n this.pendingOid = undefined // Clear the pending OID after reading it\n const hasSelected = this.organizations.some((i) => i.key === selected)\n let result: CompletionState\n if (selected && hasSelected) {\n this.organizationId = selected\n result = CompletionState.OK\n await config.local.set(CurrentOrganizationKey, selected)\n } else if (this.organizations.length === 1) {\n const key = this.organizations[0].key\n await config.local.set(CurrentOrganizationKey, key)\n this.organizationId = key\n result = CompletionState.OK\n } else if (this.organizations.length) {\n result = CompletionState.NotSelected\n } else {\n result = CompletionState.NoOrganizations\n }\n return result\n }\n\n /**\n * When the user has no organizations, it set the organization as the only one\n * and persists the organization id as the selected organization.\n * @param org The organization to add.\n */\n async setupUserOrganization(org: IOrganization): Promise<void> {\n const hasOrg = this.organizations.some((i) => i.key === org.key)\n if (!hasOrg) {\n this.organizations.push(org)\n }\n const config = await services.get('config')\n await config.local.set(CurrentOrganizationKey, org.key)\n this.organizationId = org.key\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OrganizationService.js","sourceRoot":"","sources":["../../../src/services/OrganizationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAE5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAC5D,OAAO,QAAQ,MAAM,kBAAkB,CAAA;AAEvC,IAAK,KAIJ;AAJD,WAAK,KAAK;IACR,6CAAU,CAAA;IACV,yCAAQ,CAAA;IACR,uCAAO,CAAA;AACT,CAAC,EAJI,KAAK,KAAL,KAAK,QAIT;AAED,MAAM,CAAN,IAAY,eAiBX;AAjBD,WAAY,eAAe;IACzB;;OAEG;IACH,iDAAE,CAAA;IACF;;OAEG;IACH,mEAAW,CAAA;IACX;;OAEG;IACH,2EAAe,CAAA;IACf;;OAEG;IACH,uDAAK,CAAA;AACP,CAAC,EAjBW,eAAe,KAAf,eAAe,QAiB1B;AAED,MAAM,YAAY,GAAG,oBAAoB,CAAA;AAEzC,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,OAAO;IACtD,MAAM,CAAU,GAAG,GAAG,0BAA0B,CAAA;IAEhD,KAAK,GAAU,KAAK,CAAC,UAAU,CAAA;IAC/B,aAAa,GAAoB,EAAE,CAAA;IACnC,cAAc,CAAoB;I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EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAA;QACtE,IAAI,MAAuB,CAAA;QAC3B,IAAI,QAAQ,IAAI,WAAW,EAAE,CAAC;YAC5B,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAA;YAC9B,MAAM,GAAG,eAAe,CAAC,EAAE,CAAA;YAC3B,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAA;QAC1D,CAAC;aAAM,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA;YACrC,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAA;YACnD,IAAI,CAAC,cAAc,GAAG,GAAG,CAAA;YACzB,MAAM,GAAG,eAAe,CAAC,EAAE,CAAA;QAC7B,CAAC;aAAM,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;YACrC,MAAM,GAAG,eAAe,CAAC,WAAW,CAAA;QACtC,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,eAAe,CAAC,eAAe,CAAA;QAC1C,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC","sourcesContent":["import { Service } from '../core/Service.js'\nimport type { IOrganization, UserOrganizationGrantType } from '@api-client/core/models/store/Organization.js'\nimport { CurrentOrganizationKey } from '../lib/StoreKeys.js'\nimport services from './api_service.js'\n\nenum State {\n NotChecked,\n Checking,\n Checked,\n}\n\nexport enum CompletionState {\n /**\n * The user has at least one organization and the current organization is selected.\n */\n OK,\n /**\n * The user has at leas two organizations and no valid selection.\n */\n NotSelected,\n /**\n * The user have no organizations. Setup is needed.\n */\n NoOrganizations,\n /**\n * Unable to determine the state due to an error.\n */\n Error,\n}\n\nconst OrgsCacheKey = 'user_organizations'\n\nexport default class OrganizationService extends Service {\n static override key = 'api-service/organization'\n\n state: State = State.NotChecked\n organizations: IOrganization[] = []\n organizationId: string | undefined\n /**\n * A pending organization ID that was set via the URL query parameter `oid`.\n * When it is set, it preselects the organization when loading list of organizations.\n * This will override the `organizationId` set in the local storage.\n */\n pendingOid: string | undefined | null\n\n /**\n * A hidden value for the `updateComplete` getter.\n */\n #updateComplete?: Promise<CompletionState>\n\n /**\n * The resolver to call when the update completes.\n */\n #updateResolver?: (state: CompletionState) => void\n\n protected override async onCreate(): Promise<void> {\n const url = new URL(window.location.href)\n this.pendingOid = url.searchParams.get('oid')\n this.revalidate()\n }\n\n /**\n * @deprecated Use #setOrganization instead\n */\n setupUserOrganization(org: IOrganization): Promise<void> {\n return this.setOrganization(org)\n }\n\n /**\n * Sets an org as the current user org.\n * @param org The organization to add.\n */\n async setOrganization(org: IOrganization): Promise<void> {\n const hasOrg = this.organizations.some((i) => i.key === org.key)\n if (!hasOrg) {\n this.organizations.push(org)\n }\n const config = await services.get('config')\n await config.local.set(CurrentOrganizationKey, org.key)\n this.organizationId = org.key\n }\n\n /**\n * Adds an organization to the list of organizations.\n * It also updated the cache. Used when creating a new org.\n * @param org The organization to add.\n */\n async addOrganization(org: IOrganization): Promise<void> {\n const hasOrg = this.organizations.some((i) => i.key === org.key)\n if (!hasOrg) {\n this.organizations.push(org)\n await this.#saveCache()\n }\n }\n\n /**\n * Removes an organization from the list of organizations.\n * It also updated the cache. Used when deleting an org.\n * @param org The organization to remove.\n */\n async removeOrganization(org: IOrganization): Promise<void> {\n const idx = this.organizations.findIndex((i) => i.key === org.key)\n if (idx !== -1) {\n this.organizations.splice(idx, 1)\n await this.#saveCache()\n if (this.organizationId === org.key) {\n this.organizationId = undefined\n const config = await services.get('config')\n await config.local.delete(CurrentOrganizationKey)\n }\n }\n }\n\n /**\n * @deprecated Use #readOrganization instead\n */\n getUserOrganization(id: string): Promise<IOrganization> {\n return this.readOrganization(id)\n }\n\n /**\n * Reads an organization from the list of organizations.\n * @param id The organization ID.\n * @returns The organization.\n */\n async readOrganization(id: string): Promise<IOrganization> {\n await this.#updateComplete\n const org = this.organizations.find((i) => i.key === id)\n if (!org) {\n throw new Error(`Organization with id ${id} not found`)\n }\n return org\n }\n\n /**\n * Gets the current user organization.\n * @returns The current organization or undefined if not set.\n */\n async currentOrganization(): Promise<IOrganization | undefined> {\n if (this.state === State.Checking) {\n await this.#updateComplete\n }\n if (!this.organizationId) {\n return undefined\n }\n return this.organizations.find((i) => i.key === this.organizationId)\n }\n\n /**\n * Checks if the user has a specific grant type in the current organization.\n * @param grantType The grant type to check.\n * @returns `true` if the user has the specified grant type, `false` otherwise.\n */\n protected async hasGrantType(grantType: UserOrganizationGrantType): Promise<boolean> {\n const org = await this.currentOrganization()\n if (!org) {\n return false\n }\n return org.grantType === grantType\n }\n\n /**\n * Checks if the user has any of the specified grant types in the current organization.\n * @param types The grant types to check.\n * @returns `true` if the user has any of the specified grant types, `false` otherwise.\n */\n async hasRoles(types: UserOrganizationGrantType[]): Promise<boolean> {\n const org = await this.currentOrganization()\n if (!org) {\n return false\n }\n return types.includes(org.grantType)\n }\n\n /**\n * Checks if the user is the owner of the current organization.\n * @returns `true` if the user is the owner of the current organization, `false` otherwise.\n */\n async isOwner(): Promise<boolean> {\n return this.hasGrantType('owner')\n }\n\n /**\n * Checks if the user is a manager of the current organization.\n * @returns `true` if the user is a manager of the current organization, `false` otherwise.\n */\n async isManager(): Promise<boolean> {\n return this.hasGrantType('manager')\n }\n\n /**\n * Checks if the user is an editor of the current organization.\n * @returns `true` if the user is a editor of the current organization, `false` otherwise.\n */\n async isEditor(): Promise<boolean> {\n return this.hasGrantType('editor')\n }\n\n /**\n * Forces to get the list of organizations from the server.\n *\n * Returns one of the following states:\n *\n * - `CompletionState.OK` - The user has at least one organization and the current organization is selected.\n * - `CompletionState.NotSelected` - The user has at leas two organizations and no valid selection.\n * - `CompletionState.NoOrganizations` - The user have no organizations. Setup is needed.\n * - `CompletionState.Error` - Unable to determine the state due to an error.\n *\n * @returns The state of the organization creation.\n */\n revalidate(): Promise<CompletionState> {\n if (this.state === State.Checking) {\n return this.#updateComplete as Promise<CompletionState>\n }\n this.state = State.Checking\n this.#updateComplete = new Promise<CompletionState>((resolver) => {\n this.#updateResolver = resolver\n })\n this.#getState()\n return this.#updateComplete\n }\n\n /**\n * Reads the list of organizations either from the cache or from the server.\n */\n async #getState(): Promise<void> {\n const loaded = await this.#loadCache()\n if (!loaded) {\n try {\n await this.#callOrganizations()\n } catch {\n this.#resolve(CompletionState.Error)\n this.state = State.Checked\n return\n }\n }\n const result = await this.#readState()\n this.state = State.Checked\n this.#resolve(result)\n }\n\n async #loadCache(): Promise<boolean> {\n const cache = await services.get('cache')\n const orgs = await cache.get<IOrganization[]>(OrgsCacheKey)\n if (orgs) {\n this.organizations = orgs\n return true\n }\n return false\n }\n\n async #saveCache(): Promise<void> {\n const cache = await services.get('cache')\n if (this.organizations.length === 0) {\n await cache.delete(OrgsCacheKey)\n } else {\n await cache.set<IOrganization[]>(OrgsCacheKey, this.organizations, cache.TTL.OneHour)\n }\n }\n\n async #callOrganizations(): Promise<void> {\n const sdk = await services.get('sdk')\n const orgs = await sdk.organizations.list()\n this.organizations = orgs.items || []\n await this.#saveCache()\n }\n\n #resolve(state: CompletionState): void {\n if (this.#updateResolver) {\n this.#updateResolver(state)\n this.#updateResolver = undefined\n }\n }\n\n async #readState(): Promise<CompletionState> {\n const config = await services.get('config')\n const selected = this.pendingOid ?? ((await config.local.get(CurrentOrganizationKey)) as string | undefined)\n this.pendingOid = undefined // Clear the pending OID after reading it\n const hasSelected = this.organizations.some((i) => i.key === selected)\n let result: CompletionState\n if (selected && hasSelected) {\n this.organizationId = selected\n result = CompletionState.OK\n await config.local.set(CurrentOrganizationKey, selected)\n } else if (this.organizations.length === 1) {\n const key = this.organizations[0].key\n await config.local.set(CurrentOrganizationKey, key)\n this.organizationId = key\n result = CompletionState.OK\n } else if (this.organizations.length) {\n result = CompletionState.NotSelected\n } else {\n result = CompletionState.NoOrganizations\n }\n return result\n }\n}\n"]}
|