-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(product-composite): fix and extract query param (#2437)
The `DaffProductPageLoadSuccess` runs at different times in the action stream depending on server side render or not. This meant that, during SSR, the `composite_configuration` was feature was never used correctly as the Router state is only set AFTER the `DaffProductPageLoadSuccess`. Additionally, previously the query param service retrieval was inside of the effect that handled the query param. This made testing the effect difficult so I extracted it.
- Loading branch information
1 parent
37e0548
commit 98d5272
Showing
5 changed files
with
91 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
libs/product-composite/routing/src/services/query-param.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { DaffProductCompositeQueryParamService } from './query-param.service'; | ||
|
||
describe('@daffodil/product-composite/routing | DaffProductCompositeQueryParamService', () => { | ||
let service: DaffProductCompositeQueryParamService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
], | ||
providers: [ | ||
DaffProductCompositeQueryParamService, | ||
], | ||
}); | ||
|
||
service = TestBed.inject(DaffProductCompositeQueryParamService); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
libs/product-composite/routing/src/services/query-param.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { DOCUMENT } from '@angular/common'; | ||
import { | ||
Inject, | ||
Injectable, | ||
} from '@angular/core'; | ||
|
||
import { | ||
DAFF_PRODUCT_COMPOSITE_ROUTING_CONFIG, | ||
DaffProductCompositeRoutingConfig, | ||
} from '../config/public_api'; | ||
|
||
@Injectable() | ||
export class DaffProductCompositeQueryParamService { | ||
|
||
constructor( | ||
@Inject(DOCUMENT) private document: any, | ||
@Inject(DAFF_PRODUCT_COMPOSITE_ROUTING_CONFIG) private config: DaffProductCompositeRoutingConfig) { | ||
} | ||
|
||
/** | ||
* Get the value of the configured composite selection query param. | ||
*/ | ||
public get(): string { | ||
return ( | ||
new URL((<any>this.document).location.toString()) | ||
).searchParams.get(this.config.compositeSelectionQueryParam); | ||
} | ||
} |