Skip to content

Commit

Permalink
fix: cannot recognize current semantic route for my company pages (#1…
Browse files Browse the repository at this point in the history
…2805)

Previously, the routing config chunks for my company pages were provided in the components modules, which were lazy loaded. This caused 2 issues:
- We could not recognize the semantic route for any my-accunt page (because `SemanticRoutesService.getRouteName()` depends on the routing config provided in the root injector on the app start, but not on configs provided lazily).
-  it was impossible to create a link to any my-company page (using `cxUrl` pipe) from another pages outside the my-company feature. (Currently we don't need such a links in OOTB Spartacus, but it's a potential future limitation.)

Now above 2 issues are fixed, as we moved all the default routing config chunks to the `OrganizationAdministrationRootModule`, which provides the config chunks in the root injector. Therefore they are available in the `SemanticRoutesService` on app start.

### QA steps
1. Add in the constructor of the `StorefrontComponent` this snippet (log the semantic route on page change):
    ```ts
    this.routingService
      .getRouterState()
      .pipe(
        map((state) => state.state.semanticRoute),
        distinctUntilChanged(),
        tap((semanticRoute) => console.log({ semanticRoute }))
      )
      .subscribe();
    ```
2. Turn on 'b2b' in `environment.ts`
3. Login as `[email protected]`
4. Navigate through my-company pages and verify the correct semantic route name is logged in the console for each feature's pages: budgets, cost centers, user groups, users, permissions, units

Note: Some content pages like FAQ, find a store or help don't have route config provided - therefore it's a valid result that they `undefined` semantic route is logged in the console for those pages. 

----
fixes #12717
  • Loading branch information
Platonn authored Jun 22, 2021
1 parent 633f4b0 commit 868c420
Show file tree
Hide file tree
Showing 41 changed files with 453 additions and 386 deletions.
10 changes: 10 additions & 0 deletions docs/migration/4_0.md
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,15 @@ The following properties where removed in 4.0:
- Key `register.titleRequired` was moved to separated lib. Now is a part of `userProfileTranslations`, `userProfileTranslationChunksConfig` from `@spartacus/user/profile/assets`.
- Key `register.postRegisterMessage` was moved to separated lib. Now is a part of `userProfileTranslations`, `userProfileTranslationChunksConfig` from `@spartacus/user/profile/assets`.
### Default routing config for the My Company feature
The default routing config for the My Company pages was moved from various modules in `@spartacus/organization/administration/components` to `OrganizationAdministrationRootModule` in `@spartacus/organization/administration/root`. Therefore the default config is now provided eagerly, so it's available early on app start (but not only after the feature is lazy loaded). Also, the following objects were renamed and moved to `@spartacus/organization/administration/root`:
- `budgetRoutingConfig` -> `defaultBudgetRoutingConfig`
- `costCenterRoutingConfig` -> `defaultCostCenterRoutingConfig`
- `permissionRoutingConfig` -> `defaultPermissionRoutingConfig`
- `unitsRoutingConfig` -> `defaultUnitsRoutingConfig`
- `userGroupRoutingConfig` -> `defaultUserGroupRoutingConfig`
- `userRoutingConfig` -> `defaultUserRoutingConfig`
#### Checkout Related Translations (i18n) changes
The checkout related translation keys were moved to the `@spartacus/checkout/assets`. If you use some checkout
Expand Down Expand Up @@ -1211,3 +1220,4 @@ related labels outside of checkout and the checkout lib is not used, you will ne
- `#reportNotAuthGuard` - method not needed anymore. Every visited URL is now remembered automatically as redirect URL on `NavigationEnd` event.
- `#reportAuthGuard` - method deprecated; use the new equivalent method instead: `#saveCurrentNavigationUrl`. It remembers the anticipated page, when being invoked during the navigation.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { NgModule } from '@angular/core';
import { provideDefaultConfig, RoutingConfig } from '@spartacus/core';
import { BudgetComponentsModule } from './budget/budget-components.module';
import { CostCenterComponentsModule } from './cost-center/cost-center-components.module';
import { PermissionComponentsModule } from './permission/permission-components.module';
Expand All @@ -16,16 +15,5 @@ import { UserComponentsModule } from './user/user-components.module';
UserComponentsModule,
PermissionComponentsModule,
],
providers: [
provideDefaultConfig(<RoutingConfig>{
routing: {
routes: {
organization: {
paths: ['organization'],
},
},
},
}),
],
})
export class AdministrationComponentsModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import {
provideDefaultConfigFactory,
} from '@spartacus/core';
import { SharedOrganizationModule } from '../shared/shared-organization.module';
import {
budgetCmsConfig,
budgetRoutingConfig,
budgetTableConfigFactory,
} from './budget.config';
import { budgetCmsConfig, budgetTableConfigFactory } from './budget.config';
import { BudgetCostCenterListModule } from './cost-centers/budget-cost-center-list.module';
import { BudgetDetailsModule } from './details/budget-details.module';
import { BudgetFormModule } from './form/budget-form.module';
Expand All @@ -21,7 +17,6 @@ import { BudgetFormModule } from './form/budget-form.module';
BudgetCostCenterListModule,
],
providers: [
provideDefaultConfig(budgetRoutingConfig),
provideDefaultConfig(budgetCmsConfig),
provideDefaultConfigFactory(budgetTableConfigFactory),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,24 @@
import {
AuthGuard,
CmsConfig,
ParamsMapping,
RoutingConfig,
} from '@spartacus/core';
import { AuthGuard, CmsConfig } from '@spartacus/core';
import { AdminGuard } from '@spartacus/organization/administration/core';
import { ROUTE_PARAMS } from '@spartacus/organization/administration/root';
import { TableConfig } from '@spartacus/storefront';
import { MAX_OCC_INTEGER_VALUE, ROUTE_PARAMS } from '../constants';
import { MAX_OCC_INTEGER_VALUE } from '../constants';
import { CostCenterDetailsCellComponent } from '../cost-center/details-cell/cost-center-details-cell.component';
import { ItemService } from '../shared/item.service';
import { ListComponent } from '../shared/list/list.component';
import { ListService } from '../shared/list/list.service';
import { OrganizationTableType } from '../shared/organization.model';
import { ActiveLinkCellComponent } from '../shared/table';
import { AmountCellComponent } from '../shared/table/amount/amount-cell.component';
import { DateRangeCellComponent } from '../shared/table/date-range/date-range-cell.component';
import { StatusCellComponent } from '../shared/table/status/status-cell.component';
import { UnitCellComponent } from '../shared/table/unit/unit-cell.component';
import { OrganizationTableType } from '../shared/organization.model';
import { BudgetCostCenterListComponent } from './cost-centers/budget-cost-center-list.component';
import { BudgetDetailsComponent } from './details/budget-details.component';
import { BudgetFormComponent } from './form/budget-form.component';
import { BudgetItemService } from './services/budget-item.service';
import { BudgetListService } from './services/budget-list.service';
import { BudgetRoutePageMetaResolver } from './services/budget-route-page-meta.resolver';
import { CostCenterDetailsCellComponent } from '../cost-center/details-cell/cost-center-details-cell.component';

const listPath = `organization/budgets/:${ROUTE_PARAMS.budgetCode}`;
const paramsMapping: ParamsMapping = {
budgetCode: 'code',
};

export const budgetRoutingConfig: RoutingConfig = {
routing: {
routes: {
orgBudget: {
paths: ['organization/budgets'],
},
orgBudgetCreate: {
paths: ['organization/budgets/create'],
},
orgBudgetDetails: {
paths: [`${listPath}`],
paramsMapping,
},
orgBudgetCostCenters: {
paths: [`${listPath}/cost-centers`],
paramsMapping,
},
orgBudgetEdit: {
paths: [`${listPath}/edit`],
paramsMapping,
},
},
},
};

export const budgetCmsConfig: CmsConfig = {
cmsComponents: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TestBed } from '@angular/core/testing';
import { RoutingService } from '@spartacus/core';
import { BudgetService } from '@spartacus/organization/administration/core';
import { ROUTE_PARAMS } from '@spartacus/organization/administration/root';
import { of, Subject } from 'rxjs';
import { ROUTE_PARAMS } from '../../constants';
import { CurrentBudgetService } from './current-budget.service';

const mockParams = new Subject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
Budget,
BudgetService,
} from '@spartacus/organization/administration/core';
import { ROUTE_PARAMS } from '@spartacus/organization/administration/root';
import { Observable } from 'rxjs';
import { ROUTE_PARAMS } from '../../constants';
import { CurrentItemService } from '../../shared/current-item.service';

@Injectable({
Expand Down
10 changes: 0 additions & 10 deletions feature-libs/organization/administration/components/constants.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// This is not for the public API
export const ROUTE_PARAMS = {
budgetCode: 'budgetCode',
unitCode: 'unitCode',
costCenterCode: 'costCenterCode',
userCode: 'userCode',
userGroupCode: 'userGroupCode',
permissionCode: 'permissionCode',
addressCode: 'addressId',
};

// TODO:#my-account-architecture - Number.MAX_VALUE?
export const MAX_OCC_INTEGER_VALUE = 2147483647;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { SharedOrganizationModule } from '../shared/shared-organization.module';
import { CostCenterBudgetListModule } from './budgets/cost-center-budget-list.module';
import {
costCenterCmsConfig,
costCenterRoutingConfig,
costCenterTableConfigFactory,
} from './cost-center.config';
import { CostCenterDetailsModule } from './details/cost-center-details.module';
Expand All @@ -23,7 +22,6 @@ import { CostCenterFormModule } from './form/cost-center-form.module';
BudgetDetailsCellModule,
],
providers: [
provideDefaultConfig(costCenterRoutingConfig),
provideDefaultConfig(costCenterCmsConfig),
provideDefaultConfigFactory(costCenterTableConfigFactory),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,63 +1,25 @@
import {
AuthGuard,
CmsConfig,
ParamsMapping,
RoutingConfig,
} from '@spartacus/core';
import { AuthGuard, CmsConfig } from '@spartacus/core';
import { AdminGuard } from '@spartacus/organization/administration/core';
import { ROUTE_PARAMS } from '@spartacus/organization/administration/root';
import { TableConfig } from '@spartacus/storefront';
import { MAX_OCC_INTEGER_VALUE, ROUTE_PARAMS } from '../constants';
import { BudgetDetailsCellComponent } from '../budget/details-cell/budget-details-cell.component';
import { MAX_OCC_INTEGER_VALUE } from '../constants';
import { ItemService } from '../shared/item.service';
import { ListComponent } from '../shared/list/list.component';
import { ListService } from '../shared/list/list.service';
import { OrganizationTableType } from '../shared/organization.model';
import { AssignCellComponent } from '../shared/sub-list/assign-cell.component';
import { ActiveLinkCellComponent } from '../shared/table/active-link/active-link-cell.component';
import { CellComponent } from '../shared/table/cell.component';
import { StatusCellComponent } from '../shared/table/status/status-cell.component';
import { UnitCellComponent } from '../shared/table/unit/unit-cell.component';
import { OrganizationTableType } from '../shared/organization.model';
import { CostCenterAssignedBudgetListComponent } from './budgets/assigned/cost-center-assigned-budget-list.component';
import { CostCenterBudgetListComponent } from './budgets/cost-center-budget-list.component';
import { CostCenterDetailsComponent } from './details/cost-center-details.component';
import { CostCenterFormComponent } from './form/cost-center-form.component';
import { CostCenterItemService } from './services/cost-center-item.service';
import { CostCenterListService } from './services/cost-center-list.service';
import { CostCenterRoutePageMetaResolver } from './services/cost-center-route-page-meta.resolver';
import { BudgetDetailsCellComponent } from '../budget/details-cell/budget-details-cell.component';

const listPath = `organization/cost-centers/:${ROUTE_PARAMS.costCenterCode}`;
const paramsMapping: ParamsMapping = {
costCenterCode: 'code',
};

export const costCenterRoutingConfig: RoutingConfig = {
routing: {
routes: {
orgCostCenter: {
paths: ['/organization/cost-centers'],
},
orgCostCenterCreate: {
paths: ['organization/cost-centers/create'],
},
orgCostCenterDetails: {
paths: [`${listPath}`],
paramsMapping,
},
orgCostCenterBudgets: {
paths: [`${listPath}/budgets`],
paramsMapping,
},
orgCostCenterAssignBudgets: {
paths: [`${listPath}/budgets/assign`],
paramsMapping,
},
orgCostCenterEdit: {
paths: [`${listPath}/edit`],
paramsMapping,
},
},
},
};

export const costCenterCmsConfig: CmsConfig = {
cmsComponents: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from '@angular/core';
import { CostCenter, RoutingService } from '@spartacus/core';
import { CostCenterService } from '@spartacus/organization/administration/core';
import { ROUTE_PARAMS } from '@spartacus/organization/administration/root';
import { Observable } from 'rxjs';
import { ROUTE_PARAMS } from '../../constants';
import { CurrentItemService } from '../../shared/current-item.service';

@Injectable({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { PermissionDetailsModule } from './details/permission-details.module';
import { PermissionFormModule } from './form/permission-form.module';
import {
permissionCmsConfig,
permissionRoutingConfig,
permissionTableConfigFactory,
} from './permission.config';

Expand All @@ -19,7 +18,6 @@ import {
PermissionFormModule,
],
providers: [
provideDefaultConfig(permissionRoutingConfig),
provideDefaultConfig(permissionCmsConfig),
provideDefaultConfigFactory(permissionTableConfigFactory),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,21 @@
import {
AuthGuard,
CmsConfig,
ParamsMapping,
RoutingConfig,
} from '@spartacus/core';
import { AuthGuard, CmsConfig } from '@spartacus/core';
import { AdminGuard } from '@spartacus/organization/administration/core';
import { ROUTE_PARAMS } from '@spartacus/organization/administration/root';
import { TableConfig } from '@spartacus/storefront';
import { ROUTE_PARAMS } from '../constants';
import { ItemService } from '../shared/item.service';
import { ListComponent } from '../shared/list/list.component';
import { ListService } from '../shared/list/list.service';
import { OrganizationTableType } from '../shared/organization.model';
import { ActiveLinkCellComponent } from '../shared/table/active-link/active-link-cell.component';
import { LimitCellComponent } from '../shared/table/limit/limit-cell.component';
import { StatusCellComponent } from '../shared/table/status/status-cell.component';
import { UnitCellComponent } from '../shared/table/unit/unit-cell.component';
import { OrganizationTableType } from '../shared/organization.model';
import { PermissionDetailsComponent } from './details/permission-details.component';
import { PermissionFormComponent } from './form/permission-form.component';
import { PermissionItemService } from './services/permission-item.service';
import { PermissionListService } from './services/permission-list.service';
import { PermissionRoutePageMetaResolver } from './services/permission-route-page-meta.resolver';

const listPath = `organization/purchase-limits/:${ROUTE_PARAMS.permissionCode}`;
const paramsMapping: ParamsMapping = {
permissionCode: 'code',
};

export const permissionRoutingConfig: RoutingConfig = {
routing: {
routes: {
orgPurchaseLimit: {
paths: ['organization/purchase-limits'],
},
orgPurchaseLimitCreate: {
paths: ['organization/purchase-limits/create'],
},
orgPurchaseLimitDetails: {
paths: [listPath],
paramsMapping,
},
orgPurchaseLimitEdit: {
paths: [`${listPath}/edit`],
paramsMapping,
},
},
},
};

export const permissionCmsConfig: CmsConfig = {
cmsComponents: {
ManagePermissionsListComponent: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
Permission,
PermissionService,
} from '@spartacus/organization/administration/core';
import { ROUTE_PARAMS } from '@spartacus/organization/administration/root';
import { Observable } from 'rxjs';
import { ROUTE_PARAMS } from '../../constants';
import { CurrentItemService } from '../../shared/current-item.service';

@Injectable({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from '@angular/core';
import { RoutingService } from '@spartacus/core';
import { ROUTE_PARAMS } from '@spartacus/organization/administration/root';
import { Observable, of } from 'rxjs';
import { distinctUntilChanged, map, pluck, switchMap } from 'rxjs/operators';
import { ROUTE_PARAMS } from '../constants';

/**
* Abstract Base class for all organization entities. This class simplifies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ROUTE_PARAMS } from '../../../../constants';
import { ROUTE_PARAMS } from '@spartacus/organization/administration/root';
import { ListService } from '../../../../shared/list/list.service';
import { UnitAddressListService } from './unit-address-list.service';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Injectable } from '@angular/core';
import { Address, RoutingService } from '@spartacus/core';
import { OrgUnitService } from '@spartacus/organization/administration/core';
import { ROUTE_PARAMS } from '@spartacus/organization/administration/root';
import { Observable, of } from 'rxjs';
import { filter, switchMap } from 'rxjs/operators';
import { ROUTE_PARAMS } from '../../../../constants';
import { CurrentItemService } from '../../../../shared/current-item.service';

@Injectable({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
OrganizationItemStatus,
OrgUnitService,
} from '@spartacus/organization/administration/core';
import { ROUTE_PARAMS } from '@spartacus/organization/administration/root';
import { Observable } from 'rxjs';
import { distinctUntilChanged, filter, first, pluck } from 'rxjs/operators';
import { ROUTE_PARAMS } from '../../../../constants';
import { ItemService } from '../../../../shared/item.service';
import { UnitAddressFormService } from '../form/unit-address-form.service';
import { CurrentUnitAddressService } from './current-unit-address.service';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TestBed } from '@angular/core/testing';
import { RoutingService } from '@spartacus/core';
import { OrgUnitService } from '@spartacus/organization/administration/core';
import { ROUTE_PARAMS } from 'feature-libs/organization/administration/components/constants';
import { ROUTE_PARAMS } from '@spartacus/organization/administration/root';
import { of, Subject } from 'rxjs';
import { CurrentUnitChildService } from './current-unit-child.service';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { B2BUnit } from '@spartacus/core';
import { ROUTE_PARAMS } from '@spartacus/organization/administration/root';
import { Observable, of } from 'rxjs';
import { ROUTE_PARAMS } from '../../../../constants';
import { ListService } from '../../../../shared/list/list.service';
import { CurrentUnitService } from '../../../services/current-unit.service';
import { UnitUserListService } from '../services/unit-user-list.service';
Expand Down
Loading

0 comments on commit 868c420

Please sign in to comment.