Skip to content

Commit 03eaaf3

Browse files
committed
fix(app): replace organization selection with the vcl's data-list
1 parent 11bf0d5 commit 03eaaf3

File tree

2 files changed

+88
-45
lines changed

2 files changed

+88
-45
lines changed

packages/core/state/src/lib/+state/management/organization/organization.selectors.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,43 @@ export const selectError = createSelector(
142142
(state: IOrganizationState) => state.error
143143
);
144144

145+
export const selectGlobalOrganizationHistory = createSelector(
146+
selectOrganization,
147+
(state: IOrganizationState) => state.selectedGlobalOrganizationHistory
148+
);
149+
150+
export const selectGlobalChildrenOrganizationsHelperSelector = createSelector({
151+
organizations: selectOrganizationAll,
152+
currentParentId: selectOrganizationSelectedGlobalOrganizationId,
153+
globalOrganizationHistory: selectGlobalOrganizationHistory,
154+
});
155+
145156
export const selectGlobalChildrenOrganizations = createSelector(
146-
selectOrganizationAll,
147-
selectOrganizationSelectedGlobalOrganizationId,
148-
(organizations, currentParentId) => {
149-
const filteredOrganization = organizations.filter(
150-
(org) => org.parentId === currentParentId
157+
selectGlobalChildrenOrganizationsHelperSelector,
158+
(data) => {
159+
const filteredOrganization = data.organizations.filter(
160+
(org) => org.parentId === data.currentParentId
151161
) as IOrganization[];
152162

163+
if (filteredOrganization.length === 0) {
164+
// This is most likely a Leaf organization
165+
const currentIndex = data.globalOrganizationHistory.findIndex(
166+
(his) => his === data.currentParentId
167+
);
168+
169+
console.log(
170+
'data.globalOrganizationHistory[currentIndex - 1]',
171+
data.globalOrganizationHistory[currentIndex - 1]
172+
);
173+
174+
if (currentIndex > 0) {
175+
return data.organizations.filter(
176+
(org) =>
177+
org.parentId === data.globalOrganizationHistory[currentIndex - 1]
178+
) as IOrganization[];
179+
}
180+
}
181+
153182
return filteredOrganization;
154183
}
155184
);

packages/modules/ui/src/lib/components/organisms/header/header-toolbar.component.html

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,25 @@
11
@if (vm$ | async; as vm) {
22
<div>
3-
<div
3+
<span
44
#popoverOrganizationTarget
55
class="inline-block"
66
>
7-
<div
8-
class="row align-items-center"
7+
<button
8+
vcl-button
9+
[selectable]="true"
910
(click)="
1011
templatePopoverOrganization.toggle();
1112
onClickGlobalOrganizationSelector()
1213
"
14+
class="half-transparent organization"
1315
>
14-
<button
15-
vcl-button
16-
class="half-transparent organization"
17-
(click)="resetGlobalSelectOrganization($event)"
18-
>
19-
<vcl-icon icon="vcl:home"></vcl-icon>
20-
</button>
21-
<button
22-
vcl-button
23-
class="half-transparent organization"
24-
(click)="lastSelectedGlobalOrganization($event)"
25-
>
26-
<vcl-icon icon="vcl:arrow-left"></vcl-icon>
27-
</button>
28-
<div class="row">
16+
<vcl-icogram>
17+
<vcl-icon icon="mdi:home-outline" />
2918
{{ vm.globalOrganization?.name }}
30-
</div>
31-
32-
<button
33-
vcl-button
34-
class="half-transparent organization"
35-
>
36-
<vcl-icon icon="vcl:arrow-down"></vcl-icon>
37-
</button>
38-
</div>
39-
</div>
19+
<vcl-icon icon="mdi:chevron-down" />
20+
</vcl-icogram>
21+
</button>
22+
</span>
4023

4124
<span
4225
#popoverAccountTarget
@@ -65,19 +48,50 @@
6548
[positions]="rightOrientedPositions"
6649
>
6750
<!-- This are children -->
68-
<vcl-select-list
69-
(valueChange)="
70-
onSelectGlobalOrganization($event, vm.globalOrganization?.id ?? '');
71-
templatePopoverOrganization.close()
72-
"
73-
>
74-
<vcl-select-list-item
75-
[value]="o?.id"
76-
*ngFor="let o of vm.organizations"
51+
<div>
52+
<div class="row justify-content-between align-items-center">
53+
<div class="flex p-2">
54+
@if (vm.globalOrganization?.parentId) {
55+
<button
56+
vcl-button
57+
class="half-transparent organization"
58+
(click)="resetGlobalSelectOrganization($event)"
59+
>
60+
<vcl-icon icon="vcl:home"></vcl-icon>
61+
</button>
62+
63+
<button
64+
vcl-button
65+
class="half-transparent organization"
66+
(click)="lastSelectedGlobalOrganization($event)"
67+
>
68+
<vcl-icon icon="vcl:arrow-left"></vcl-icon>
69+
</button>
70+
}
71+
</div>
72+
<div class="overflow-ellipsis flex p-2">
73+
{{ vm.globalOrganization?.name }}
74+
</div>
75+
76+
<div class="flex"></div>
77+
</div>
78+
79+
<vcl-data-list
80+
[noBorder]="true"
81+
[value]="vm.globalOrganization?.id"
82+
class="m-0"
83+
(valueChange)="
84+
onSelectGlobalOrganization($event, vm.globalOrganization?.id ?? '');
85+
templatePopoverOrganization.close()
86+
"
7787
>
78-
{{ o?.name }}
79-
</vcl-select-list-item>
80-
</vcl-select-list>
88+
@for (organization of vm.organizations; track $index) {
89+
<vcl-data-list-item [value]="organization.id">
90+
<div class="p-2">{{ organization?.name }}</div>
91+
</vcl-data-list-item>
92+
}
93+
</vcl-data-list>
94+
</div>
8195
</ng-template>
8296

8397
<ng-template

0 commit comments

Comments
 (0)