import * as appstate from '../appstate.js'; import * as shared from './shared/index.js'; import { css, cssManager, customElement, DeesElement, html, state, type TemplateResult, } from '@design.estate/dees-element'; @customElement('sg-view-organizations') export class SgViewOrganizations extends DeesElement { @state() accessor organizationsState: appstate.IOrganizationsState = { organizations: [], currentOrg: null, repositories: [], members: [], }; @state() accessor uiState: appstate.IUiState = { activeView: 'organizations' }; constructor() { super(); const orgSub = appstate.organizationsStatePart .select((s) => s) .subscribe((s) => { this.organizationsState = s; }); this.rxSubscriptions.push(orgSub); const uiSub = appstate.uiStatePart .select((s) => s) .subscribe((s) => { this.uiState = s; }); this.rxSubscriptions.push(uiSub); } public static styles = [ cssManager.defaultStyles, shared.viewHostCss, ]; async connectedCallback() { super.connectedCallback(); await appstate.organizationsStatePart.dispatchAction(appstate.fetchOrganizationsAction, null); // If there's an entity ID, load the detail if (this.uiState.activeEntityId) { await this.loadOrgDetail(this.uiState.activeEntityId); } } private async loadOrgDetail(orgId: string) { await appstate.organizationsStatePart.dispatchAction( appstate.fetchOrganizationAction, { organizationId: orgId }, ); await appstate.organizationsStatePart.dispatchAction( appstate.fetchRepositoriesAction, { organizationId: orgId }, ); await appstate.organizationsStatePart.dispatchAction( appstate.fetchMembersAction, { organizationId: orgId }, ); } public render(): TemplateResult { if (this.uiState.activeEntityId && this.organizationsState.currentOrg) { return html` `; } return html` `; } private selectOrg(orgId: string) { appstate.uiStatePart.setState({ ...appstate.uiStatePart.getState(), activeEntityId: orgId, }); this.loadOrgDetail(orgId); } private selectRepo(repoId: string) { // Navigate to repository within org context // For now, we could switch to packages view } private goBack() { appstate.uiStatePart.setState({ ...appstate.uiStatePart.getState(), activeEntityId: undefined, }); appstate.organizationsStatePart.setState({ ...appstate.organizationsStatePart.getState(), currentOrg: null, repositories: [], members: [], }); } private async createOrg(data: { name: string; displayName?: string; description?: string }) { await appstate.organizationsStatePart.dispatchAction( appstate.createOrganizationAction, data, ); } }