Skip to content

Commit

Permalink
feat(app): display selected organization in the organization pane
Browse files Browse the repository at this point in the history
  • Loading branch information
belsman committed Jan 28, 2025
1 parent 058d4da commit 5511ac0
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export const setPreviousSelectedGlobalOrganizationHistory = createAction(
'[ORGANIZATION] Set previously selected global organization'
);

export const cancelSelection = createAction(
'[ORGANIZATION] Set the global selected leaf to null'
);

export const organizationCreateRequest = createAction(
'[ORGANIZATION] Organization create request',
props<{ payload: IIoRestorecommerceOrganizationOrganizationList }>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export class OrganizationFacade {
organizationSelectors.selectGlobalChildrenOrganizations
);

readonly globalOrganizationLeafId$ = this.store.select(
organizationSelectors.selectGlobalOrganizationLeafId
);

readonly globalOrganizationLeaf$ = this.store.select(
organizationSelectors.selectGlobalOrganizationLeaf
);
Expand Down Expand Up @@ -104,6 +108,9 @@ export class OrganizationFacade {
organizationActions.setPreviousSelectedGlobalOrganizationHistory()
);

cancelSelection = () =>
this.store.dispatch(organizationActions.cancelSelection());

create = (payload: IIoRestorecommerceOrganizationOrganizationList) =>
this.store.dispatch(
organizationActions.organizationCreateRequest({ payload })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ const reducer = createReducer<IOrganizationState>(
state.selectedGlobalOrganizationHistory.slice(0, -1),
})
),
on(
organizationActions.cancelSelection,
(state): IOrganizationState => ({
...state,
setSelectedGlobalLeaf: null,
selectedGlobalOrganizationHistory:
state.selectedGlobalOrganizationHistory.slice(),
})
),
on(
organizationActions.organizationCreateRequest,
(state): IOrganizationState => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,20 @@ export const selectGlobalChildrenOrganizations = createSelector(
}
);

export const selectGlobalOrganizationLeaf = createSelector(
export const selectGlobalOrganizationLeafId = createSelector(
selectOrganization,
(state: IOrganizationState) => state.setSelectedGlobalLeaf
);

export const selectGlobalOrganizationLeaf = createSelector(
selectOrganizationEntities,
selectGlobalOrganizationLeafId,
(entities, selectGlobalOrganizationLeafId) => {
return (
selectGlobalOrganizationLeafId &&
selectGlobalOrganizationLeafId in entities
? entities[selectGlobalOrganizationLeafId]
: null
) as IOrganization | null;
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
>
<vcl-icogram>
<vcl-icon icon="mdi:home-outline" />
{{ vm.globalOrganization?.name }}
{{ vm.globalOrganization?.name || vm.selectedParent?.name }}
<vcl-icon icon="mdi:chevron-down" />
</vcl-icogram>
</button>
Expand Down Expand Up @@ -44,7 +44,6 @@
[closeOnOffClick]="true"
[positions]="rightOrientedPositions"
>
<!-- This are children -->
<div>
<div class="row justify-content-between align-items-center">
<div class="flex p-2">
Expand All @@ -70,12 +69,22 @@
{{ vm.globalOrganization?.name }}
</div>

<div class="flex"></div>
<div class="flex row justify-content-end">
@if (vm.globalOrganization?.isLeaf) {
<button
vcl-button
class="half-transparent organization"
(click)="cancelSelection()"
>
<vcl-icon icon="vcl:close"></vcl-icon>
</button>
}
</div>
</div>

<vcl-data-list
[noBorder]="true"
[value]="vm.selectedLeaf"
[value]="vm.globalOrganization?.id"
class="m-0"
(valueChange)="
onSelectGlobalOrganization($event); templatePopoverOrganization.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
OnInit,
} from '@angular/core';
import { Router } from '@angular/router';
import { combineLatest } from 'rxjs';
import { combineLatest, merge } from 'rxjs';

import { ROUTER } from '@console-core/config';
import { AccountFacade, OrganizationFacade } from '@console-core/state';
Expand Down Expand Up @@ -35,8 +35,11 @@ export class RcHeaderToolbarComponent implements OnInit {
readonly vm$ = combineLatest({
user: this.accountFacade.user$,
organizations: this.organizationFacade.globalChildrenOrganizations$,
selectedLeaf: this.organizationFacade.globalOrganizationLeaf$,
globalOrganization: this.organizationFacade.globalOrganization$,
globalOrganization: merge(
this.organizationFacade.globalOrganizationLeaf$,
this.organizationFacade.globalOrganization$
),
selectedParent: this.organizationFacade.globalOrganization$,
});

constructor(
Expand All @@ -63,6 +66,10 @@ export class RcHeaderToolbarComponent implements OnInit {
this.organizationFacade.setSelectedGlobalOrganizationId(id);
}

cancelSelection(): void {
this.organizationFacade.cancelSelection();
}

onSearchOrganizations(str: string): void {
// TODO: Implement search
console.log('Search', str);
Expand Down

0 comments on commit 5511ac0

Please sign in to comment.