Skip to content

Commit 680211a

Browse files
committed
chore: use organization context for resource filtering
1 parent 88fa9a2 commit 680211a

File tree

18 files changed

+61
-105
lines changed

18 files changed

+61
-105
lines changed

packages/core/config/src/lib/constants/store.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export const STORE: Readonly<IStoreConstant> = {
1414
invoiceState: 'invoiceStateV1',
1515
localeState: 'localeStateV1',
1616
orderState: 'orderStateV1',
17-
organizationState: 'organizationStateV3',
17+
organizationState: 'organizationStateV4',
18+
organizationContextState: 'organizationContextStateV1',
1819
policyState: 'policyStateV1',
1920
productState: 'productStateV1',
2021
roleState: 'roleStateV1',

packages/core/state/src/lib/+state/fulfillment/fulfillment.effects.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { AppFacade } from '../app';
1717
import * as fulfillmentActions from './fulfillment.actions';
1818
import {
1919
FulfillmentFacade,
20-
OrganizationFacade,
20+
OrganizationContextFacade,
2121
withLatestOrganizationData,
2222
} from '@console-core/state';
2323
import { IoRestorecommerceResourcebaseFilterOperation } from '@console-core/graphql';
@@ -27,7 +27,7 @@ export class FulfillmentEffects {
2727
fulfillmentReadRequest$ = createEffect(() => {
2828
return this.actions$.pipe(
2929
withLatestOrganizationData(
30-
this.organizationFacade,
30+
this.organizationContextFacade,
3131
fulfillmentActions.fulfillmentReadRequest.type
3232
),
3333
switchMap(([action, organization]) =>
@@ -279,7 +279,7 @@ export class FulfillmentEffects {
279279
private readonly router: Router,
280280
private readonly actions$: Actions,
281281
private readonly appFacade: AppFacade,
282-
private readonly organizationFacade: OrganizationFacade,
282+
private readonly organizationContextFacade: OrganizationContextFacade,
283283
private readonly fulfilmentFacade: FulfillmentFacade,
284284
private readonly fulfillmentService: FulfillmentService,
285285
private readonly errorHandlingService: ErrorHandlingService

packages/core/state/src/lib/+state/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from './authn';
44
export * from './fulfillment';
55
export * from './invoice';
66
export * from './management';
7+
export * from './organization-context';
78
export * from './order';
89
export * from './product';
910
export * from './router';

packages/core/state/src/lib/+state/management/country/country.effects.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { AppFacade } from '../../app';
2020

2121
import * as countryActions from './country.actions';
2222
import {
23-
OrganizationFacade,
23+
OrganizationContextFacade,
2424
withLatestOrganizationData,
2525
} from '@console-core/state';
2626

@@ -29,7 +29,7 @@ export class CountryEffects {
2929
countryReadRequest$ = createEffect(() => {
3030
return this.actions$.pipe(
3131
withLatestOrganizationData(
32-
this.organizationFacade,
32+
this.organizationContextFacade,
3333
countryActions.countryReadRequest.type
3434
),
3535
exhaustMap(([action, organization]) =>
@@ -271,7 +271,7 @@ export class CountryEffects {
271271
private readonly actions$: Actions,
272272
private readonly appFacade: AppFacade,
273273
private readonly countryService: CountryService,
274-
private readonly organizationFacade: OrganizationFacade,
274+
private readonly organizationContextFacade: OrganizationContextFacade,
275275
private readonly errorHandlingService: ErrorHandlingService
276276
) {}
277277
}

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

-25
Original file line numberDiff line numberDiff line change
@@ -304,31 +304,6 @@ export class OrganizationEffects {
304304
{ dispatch: false }
305305
);
306306

307-
handleOrganizationChangedNotification$ = createEffect(
308-
() => {
309-
return this.actions$.pipe(
310-
ofType(
311-
organizationActions.setSelectedGlobalOrganizationId,
312-
organizationActions.selectedGlobalOrganizationHistory,
313-
organizationActions.setPreviousSelectedGlobalOrganizationHistory,
314-
organizationActions.cancelSelection
315-
),
316-
concatLatestFrom(() => [
317-
this.organizationFacade.globalOrganizationLeaf$,
318-
this.organizationFacade.globalOrganization$,
319-
]),
320-
tap(([, leafOrganization, parentOrganization]) => {
321-
const organization = leafOrganization || parentOrganization;
322-
this.appFacade.addNotification({
323-
content: `Organization changed to ${organization?.name}`,
324-
type: ENotificationTypes.Info,
325-
});
326-
})
327-
);
328-
},
329-
{ dispatch: false }
330-
);
331-
332307
handleNotificationErrors$ = createEffect(
333308
() => {
334309
return this.actions$.pipe(

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

-35
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,6 @@ export class OrganizationFacade {
5454
readonly childsAll$ = this.store.select(
5555
organizationSelectors.selectOrganizationChildsAll
5656
);
57-
readonly globalOrganizationId$ = this.store.select(
58-
organizationSelectors.selectOrganizationSelectedGlobalOrganizationId
59-
);
60-
readonly globalOrganization$ = this.store.select(
61-
organizationSelectors.selectOrganizationSelectedGlobalOrganization
62-
);
63-
64-
readonly globalChildrenOrganizations$ = this.store.select(
65-
organizationSelectors.selectGlobalChildrenOrganizations
66-
);
67-
68-
readonly globalOrganizationLeafId$ = this.store.select(
69-
organizationSelectors.selectGlobalOrganizationLeafId
70-
);
71-
72-
readonly globalOrganizationLeaf$ = this.store.select(
73-
organizationSelectors.selectGlobalOrganizationLeaf
74-
);
7557

7658
readonly actionStatus$ = this.store.select(
7759
organizationSelectors.selectActionStatus
@@ -93,23 +75,6 @@ export class OrganizationFacade {
9375
);
9476
setSelectedId = (payload: string | null) =>
9577
this.store.dispatch(organizationActions.setSelectedId({ payload }));
96-
setSelectedGlobalOrganizationId = (payload: string | null) =>
97-
this.store.dispatch(
98-
organizationActions.setSelectedGlobalOrganizationId({ payload })
99-
);
100-
101-
resetSelectedGlobalOrganization = () =>
102-
this.store.dispatch(
103-
organizationActions.selectedGlobalOrganizationHistory()
104-
);
105-
106-
lastSelectedGlobalOrganization = () =>
107-
this.store.dispatch(
108-
organizationActions.setPreviousSelectedGlobalOrganizationHistory()
109-
);
110-
111-
cancelSelection = () =>
112-
this.store.dispatch(organizationActions.cancelSelection());
11378

11479
create = (payload: IIoRestorecommerceOrganizationOrganizationList) =>
11580
this.store.dispatch(

packages/core/state/src/lib/+state/management/shop/shop.effects.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { AppFacade } from '../../app';
2020

2121
import * as shopActions from './shop.actions';
2222
import {
23-
OrganizationFacade,
23+
OrganizationContextFacade,
2424
withLatestOrganizationData,
2525
} from '@console-core/state';
2626

@@ -29,7 +29,7 @@ export class ShopEffects {
2929
shopReadRequest$ = createEffect(() => {
3030
return this.actions$.pipe(
3131
withLatestOrganizationData(
32-
this.organizationFacade,
32+
this.organizationContextFacade,
3333
shopActions.shopReadRequest.type
3434
),
3535
exhaustMap(([action, organization]) =>
@@ -281,7 +281,7 @@ export class ShopEffects {
281281
private readonly actions$: Actions,
282282
private readonly appFacade: AppFacade,
283283
private readonly shopService: ShopService,
284-
private readonly organizationFacade: OrganizationFacade,
284+
private readonly organizationContextFacade: OrganizationContextFacade,
285285
private readonly errorHandlingService: ErrorHandlingService
286286
) {}
287287
}

packages/core/state/src/lib/+state/order/order.effects.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { AppFacade } from '../app';
2323
import * as orderActions from './order.actions';
2424
import { OrderFacade } from './order.facade';
2525
import {
26-
OrganizationFacade,
26+
OrganizationContextFacade,
2727
withLatestOrganizationData,
2828
} from '@console-core/state';
2929

@@ -32,7 +32,7 @@ export class OrderEffects {
3232
orderReadRequest$ = createEffect(() => {
3333
return this.actions$.pipe(
3434
withLatestOrganizationData(
35-
this.organizationFacade,
35+
this.organizationContextFacade,
3636
orderActions.orderReadRequest.type
3737
),
3838
exhaustMap(([action, organization]) => {
@@ -322,7 +322,7 @@ export class OrderEffects {
322322
private readonly router: Router,
323323
private readonly actions$: Actions,
324324
private readonly appFacade: AppFacade,
325-
private readonly organizationFacade: OrganizationFacade,
325+
private readonly organizationContextFacade: OrganizationContextFacade,
326326
private readonly orderService: OrderService,
327327
private readonly orderFacade: OrderFacade,
328328
private readonly errorHandlingService: ErrorHandlingService
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { OrganizationContextEffects } from './organization-context.effects';
2+
export { OrganizationContextFacade } from './organization-context.facade';
3+
export { organizationContextReducer } from './organization-context.reducer';

packages/core/state/src/lib/+state/organization-context/organization-context.effects.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { concatLatestFrom } from '@ngrx/operators';
2323
import { OrganizationContextFacade } from './organization-context.facade';
2424

2525
@Injectable()
26-
export class OrganizationEffects {
26+
export class OrganizationContextEffects {
2727
// organizationReadRequest$ = createEffect(() => {
2828
// return this.actions$.pipe(
2929
// ofType(organizationActions.organizationReadRequest),

packages/core/state/src/lib/+state/organization-context/organization-context.reducer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const reducer = createReducer<IOrganizationContextState>(
8585
)
8686
);
8787

88-
export const organizationReducer = (
88+
export const organizationContextReducer = (
8989
state: IOrganizationContextState | undefined,
9090
action: Action
9191
) => reducer(state, action);

packages/core/state/src/lib/+state/product/product.effects.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import * as productActions from './product.actions';
2424
import { productReadOneByIdRequest } from './product.actions';
2525
import { concatLatestFrom } from '@ngrx/operators';
2626
import {
27-
OrganizationFacade,
27+
OrganizationContextFacade,
2828
withLatestOrganizationData,
2929
} from '@console-core/state';
3030

@@ -53,7 +53,7 @@ export class ProductEffects {
5353
let isLoadMore = false;
5454
return this.actions$.pipe(
5555
withLatestOrganizationData(
56-
this.organizationFacade,
56+
this.organizationContextFacade,
5757
productActions.productReadRequest.type // Pass only the effect-specific action
5858
),
5959
exhaustMap(([action, organization]) => {
@@ -302,7 +302,7 @@ export class ProductEffects {
302302
private readonly router: Router,
303303
private readonly actions$: Actions,
304304
private readonly appFacade: AppFacade,
305-
private readonly organizationFacade: OrganizationFacade,
305+
private readonly organizationContextFacade: OrganizationContextFacade,
306306
private readonly productService: ProductService,
307307
private readonly errorHandlingService: ErrorHandlingService
308308
) {}

packages/core/state/src/lib/core-state.module.ts

+9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ import {
3838
OrganizationEffects,
3939
OrganizationFacade,
4040
organizationReducer,
41+
OrganizationContextEffects,
42+
OrganizationContextFacade,
43+
organizationContextReducer,
4144
ProductEffects,
4245
ProductFacade,
4346
productReducer,
@@ -73,6 +76,7 @@ const facades = [
7376
RoleFacade,
7477
LocaleFacade,
7578
OrderFacade,
79+
OrganizationContextFacade,
7680
ProductFacade,
7781
RouterFacade,
7882
TaxFacade,
@@ -118,6 +122,11 @@ const facades = [
118122
StoreModule.forFeature(STORE.states.shopState, shopReducer),
119123
EffectsModule.forFeature([ShopEffects]),
120124
StoreModule.forFeature(STORE.states.routerState, fromRouter.routerReducer),
125+
EffectsModule.forFeature([OrganizationContextEffects]),
126+
StoreModule.forFeature(
127+
STORE.states.organizationContextState,
128+
organizationContextReducer
129+
),
121130
],
122131
providers: [...facades],
123132
})

packages/core/state/src/lib/utils/with-latest-organization-data.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,31 @@ import { concatLatestFrom } from '@ngrx/operators';
33
import { Action } from '@ngrx/store';
44
import { map, Observable, OperatorFunction } from 'rxjs';
55

6-
import { OrganizationFacade } from '../+state/management/organization/organization.facade';
7-
import * as organizationActions from '../+state/organization-context/organization-context.actions';
6+
import { OrganizationContextFacade } from '../+state';
7+
import * as organizationContextActions from '../+state/organization-context/organization-context.actions';
88

99
export type OrganizationDataTuple = [
1010
globalOrganizationLeafId: string,
1111
globalOrganizationId: string
1212
];
1313

1414
export function withLatestOrganizationData<T extends Action>(
15-
organizationFacade: OrganizationFacade,
15+
organizationContextFacade: OrganizationContextFacade,
1616
...additionalActionTypes: string[]
1717
): OperatorFunction<T, [T, string]> {
1818
return (source$: Observable<T>) =>
1919
source$.pipe(
2020
ofType<T>(
2121
...additionalActionTypes,
22-
organizationActions.setSelectedGlobalOrganizationId.type,
23-
organizationActions.selectedGlobalOrganizationHistory.type,
24-
organizationActions.setPreviousSelectedGlobalOrganizationHistory.type,
25-
organizationActions.cancelOrganizationContextSelection.type
22+
organizationContextActions.setSelectedGlobalOrganizationId.type,
23+
organizationContextActions.selectedGlobalOrganizationHistory.type,
24+
organizationContextActions.setPreviousSelectedGlobalOrganizationHistory
25+
.type,
26+
organizationContextActions.cancelOrganizationContextSelection.type
2627
),
2728
concatLatestFrom(() => [
28-
organizationFacade.globalOrganizationLeafId$,
29-
organizationFacade.globalOrganizationId$,
29+
organizationContextFacade.globalOrganizationLeafId$,
30+
organizationContextFacade.globalOrganizationId$,
3031
]),
3132
map(([action, organizationLeaf, organization]) => {
3233
const selectedOrganization = organizationLeaf || organization;

packages/core/types/src/lib/interfaces/store.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export interface IStoreConstant {
1010
readonly invoiceState: 'invoiceStateV1';
1111
readonly localeState: 'localeStateV1';
1212
readonly orderState: 'orderStateV1';
13-
readonly organizationState: 'organizationStateV3';
13+
readonly organizationState: 'organizationStateV4';
14+
readonly organizationContextState: 'organizationContextStateV1';
1415
readonly policyState: 'policyStateV1';
1516
readonly productState: 'productStateV1';
1617
readonly roleState: 'roleStateV1';

packages/modules/ui/src/lib/components/organisms/crud/crud-create.component.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { combineLatest } from 'rxjs';
1212
import { JssFormComponent, VCLFormFieldSchemaRoot } from '@vcl/ng-vcl';
1313

1414
import { ModeType } from '@console-core/graphql';
15-
import { AccountFacade, OrganizationFacade } from '@console-core/state';
15+
import { AccountFacade, OrganizationContextFacade } from '@console-core/state';
1616

1717
@Component({
1818
selector: 'rc-crud-create',
@@ -51,13 +51,13 @@ export class RcCrudCreateComponent implements OnInit {
5151

5252
constructor(
5353
private accountFacade: AccountFacade,
54-
private organizationFacade: OrganizationFacade
54+
private organizationContextFacade: OrganizationContextFacade
5555
) {}
5656

5757
ngOnInit(): void {
5858
combineLatest([
59-
this.organizationFacade.globalOrganizationLeafId$,
60-
this.organizationFacade.globalOrganizationId$,
59+
this.organizationContextFacade.globalOrganizationLeafId$,
60+
this.organizationContextFacade.globalOrganizationId$,
6161
]).subscribe(([leafOrganizationId, organizationId]) => {
6262
this.currentOrganizationId = leafOrganizationId
6363
? leafOrganizationId

0 commit comments

Comments
 (0)