Skip to content

Commit aa54ff5

Browse files
authored
Merge pull request #36 from platform-mesh/fix/organization-managment
fix: fix empty organization bug
2 parents bdcb88e + 9a95cc4 commit aa54ff5

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

projects/wc/src/app/components/organization-management/organization-management.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
<div class="organization-management-input">
1212
<ui5-select
1313
id="select-switch"
14-
[value]="organizationToSwitch"
14+
[value]="organizationToSwitch()"
1515
(input)="setOrganizationToSwitch($event)"
1616
(change)="setOrganizationToSwitch($event)"
1717
>
1818
@for (org of organizations(); track org) {
19-
<ui5-option [value]="org" [selected]="org === organizationToSwitch">{{
19+
<ui5-option [value]="org" [selected]="org === organizationToSwitch()">{{
2020
org
2121
}}</ui5-option>
2222
}
2323
</ui5-select>
24-
<ui5-button design="Emphasized" (ui5Click)="switchOrganization()">{{
24+
<ui5-button [disabled]="!organizationToSwitch()" design="Emphasized" (ui5Click)="switchOrganization()">{{
2525
texts.switchOrganization.button
2626
}}</ui5-button>
2727
</div>

projects/wc/src/app/components/organization-management/organization-management.component.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ describe('OrganizationManagementComponent', () => {
121121
it('should set organization to switch', () => {
122122
const event = { target: { value: 'testOrg' } };
123123
component.setOrganizationToSwitch(event);
124-
expect(component.organizationToSwitch).toBe('testOrg');
124+
expect(component.organizationToSwitch()).toBe('testOrg');
125125
});
126126

127127
it('should onboard new organization successfully', () => {
@@ -141,7 +141,7 @@ describe('OrganizationManagementComponent', () => {
141141

142142
expect(resourceServiceMock.create).toHaveBeenCalled();
143143
expect(component.organizations()).toEqual(['newOrg', 'existingOrg']);
144-
expect(component.organizationToSwitch).toBe('newOrg');
144+
expect(component.organizationToSwitch()).toBe('newOrg');
145145
expect(component.newOrganization).toBe('');
146146
expect(luigiClientMock.uxManager().showAlert).toHaveBeenCalled();
147147
});
@@ -176,7 +176,7 @@ describe('OrganizationManagementComponent', () => {
176176
},
177177
};
178178
envConfigServiceMock.getEnvConfig.mockResolvedValue(mockEnvConfig);
179-
component.organizationToSwitch = 'newOrg';
179+
component.organizationToSwitch.set('newOrg');
180180
Object.defineProperty(window, 'location', {
181181
value: { protocol: 'https:', port: '8080' },
182182
writable: true,
@@ -203,7 +203,7 @@ describe('OrganizationManagementComponent', () => {
203203
},
204204
};
205205
envConfigServiceMock.getEnvConfig.mockResolvedValue(mockEnvConfig);
206-
component.organizationToSwitch = 'invalid-org-name-'; // Invalid: ends with hyphen
206+
component.organizationToSwitch.set('invalid-org-name-'); // Invalid: ends with hyphen
207207

208208
await component.switchOrganization();
209209

@@ -229,7 +229,7 @@ describe('OrganizationManagementComponent', () => {
229229
},
230230
};
231231
envConfigServiceMock.getEnvConfig.mockResolvedValue(mockEnvConfig);
232-
component.organizationToSwitch = 'validorg';
232+
component.organizationToSwitch.set('validorg');
233233
Object.defineProperty(window, 'location', {
234234
value: { protocol: 'https:', port: '' },
235235
writable: true,

projects/wc/src/app/components/organization-management/organization-management.component.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
effect,
77
inject,
88
input,
9+
linkedSignal,
910
signal,
1011
} from '@angular/core';
1112
import { FormsModule } from '@angular/forms';
@@ -54,7 +55,7 @@ export class OrganizationManagementComponent implements OnInit {
5455

5556
texts: any = {};
5657
organizations = signal<string[]>([]);
57-
organizationToSwitch: string;
58+
organizationToSwitch = linkedSignal(() => this.organizations()[0] ?? '');
5859
newOrganization: string;
5960

6061
constructor() {
@@ -72,7 +73,7 @@ export class OrganizationManagementComponent implements OnInit {
7273
}
7374

7475
setOrganizationToSwitch($event: any) {
75-
this.organizationToSwitch = $event.target.value;
76+
this.organizationToSwitch.set($event.target.value);
7677
}
7778

7879
readOrganizations() {
@@ -118,7 +119,7 @@ export class OrganizationManagementComponent implements OnInit {
118119
this.newOrganization,
119120
...this.organizations(),
120121
]);
121-
this.organizationToSwitch = this.newOrganization;
122+
this.organizationToSwitch.set(this.newOrganization);
122123
this.newOrganization = '';
123124
this.LuigiClient().uxManager().showAlert({
124125
text: 'New organization has been created, select it from the list to switch to it.',
@@ -181,7 +182,9 @@ export class OrganizationManagementComponent implements OnInit {
181182
async switchOrganization() {
182183
const { baseDomain } = await this.envConfigService.getEnvConfig();
183184
const protocol = window.location.protocol;
184-
const sanitizedOrg = this.sanitizeSubdomainInput(this.organizationToSwitch);
185+
const sanitizedOrg = this.sanitizeSubdomainInput(
186+
this.organizationToSwitch(),
187+
);
185188

186189
if (!sanitizedOrg) {
187190
this.LuigiClient().uxManager().showAlert({

0 commit comments

Comments
 (0)