Skip to content

Commit

Permalink
chore(shared): shared organization context ngrx pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
belsman committed Feb 6, 2025
1 parent 3f08964 commit 15256dd
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,41 @@ import { AppFacade } from '../../app';
import * as organizationActions from './organization.actions';
import { concatLatestFrom } from '@ngrx/operators';
import { OrganizationFacade } from './organization.facade';
import { RouterFacade } from '@console-core/state';

@Injectable()
export class OrganizationEffects {
// updateOrgUrl$ = createEffect(
// () =>
// this.actions$.pipe(
// ofType(
// organizationActions.setSelectedGlobalOrganizationId,
// organizationActions.selectedGlobalOrganizationHistory,
// organizationActions.setPreviousSelectedGlobalOrganizationHistory,
// organizationActions.cancelSelection
// ),
// concatLatestFrom(() => [
// this.organizationFacade.globalOrganizationLeafId$,
// this.organizationFacade.globalOrganizationId$,
// this.routerFacade.url$,
// this.routerFacade.params$,
// ]),
// switchMap(
// ([, organizationLeaf, organization, currentRoute, params]) => {
// const newUrl = currentRoute.replace(
// params.org,
// organizationLeaf || organization
// );

// this.routerFacade.navigateByUrl(newUrl);

// return [];
// }
// )
// ),
// { dispatch: false }
// );

organizationReadRequest$ = createEffect(() => {
return this.actions$.pipe(
ofType(organizationActions.organizationReadRequest),
Expand Down Expand Up @@ -355,6 +387,7 @@ export class OrganizationEffects {
private readonly router: Router,
private readonly actions$: Actions,
private readonly appFacade: AppFacade,
private readonly routerFacade: RouterFacade,
private readonly organizationService: OrganizationService,
private readonly organizationFacade: OrganizationFacade,
private readonly errorHandlingService: ErrorHandlingService
Expand Down
33 changes: 33 additions & 0 deletions packages/core/state/src/lib/utils/with-latest-organization-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ofType } from '@ngrx/effects';
import { concatLatestFrom } from '@ngrx/operators';
import { Action } from '@ngrx/store';
import { Observable, OperatorFunction } from 'rxjs';

import * as organizationActions from '../+state/management/organization/organization.actions';
import { OrganizationFacade } from '../+state/management/organization/organization.facade';

// Import your organization actions
export type OrganizationDataTuple = [
globalOrganizationLeafId: string,
globalOrganizationId: string
];

export function withLatestOrganizationData<T extends Action>(
organizationFacade: OrganizationFacade,
...additionalActionTypes: string[]
): OperatorFunction<T, [T, ...OrganizationDataTuple]> {
return (source$: Observable<T>) =>
source$.pipe(
ofType<T>(
...additionalActionTypes, // Primary effect-specific actions
organizationActions.setSelectedGlobalOrganizationId.type,
organizationActions.selectedGlobalOrganizationHistory.type,
organizationActions.setPreviousSelectedGlobalOrganizationHistory.type,
organizationActions.cancelSelection.type
),
concatLatestFrom(() => [
organizationFacade.globalOrganizationLeafId$,
organizationFacade.globalOrganizationId$,
])
) as Observable<[T, ...OrganizationDataTuple]>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ export class RcHeaderToolbarComponent implements OnInit {
this.organizationFacade.cancelSelection();
}

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

onAccountItemSelected(value: string) {
switch (value) {
case 'profile':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export class RcPrivateTemplateComponent implements OnInit, OnDestroy {
})
)
.subscribe((currentRoute: string) => {
console.log('***currentRouter:', currentRoute);
this.currentRoute = currentRoute;
this.changeDetectorRef.markForCheck();
this.changeDetectorRef.detectChanges();
Expand Down

0 comments on commit 15256dd

Please sign in to comment.