Skip to content

Commit

Permalink
feat(navigation)!: standardize magento driver config (#2784)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `MagentoNavigationDriverConfiguration` -> `MagentoNavigationDriverConfig`
  • Loading branch information
griest024 committed May 13, 2024
1 parent bdc59f0 commit 0f20924
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 38 deletions.
8 changes: 8 additions & 0 deletions libs/navigation/driver/magento/src/config/default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { MagentoNavigationDriverConfig } from './interface';

/**
* The default configuration for the {@link MagentoNavigationDriverConfig}.
*/
export const MAGENTO_NAVIGATION_DRIVER_CONFIG_DEFAULT: MagentoNavigationDriverConfig = {
navigationTreeQueryDepth: 3,
};
11 changes: 11 additions & 0 deletions libs/navigation/driver/magento/src/config/interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

/**
* An interface for providing @daffodil/search/state with necessary config values.
*/
export interface MagentoNavigationDriverConfig {
/**
* The maximum depth of category children that the navigation driver will query.
* Defaults to 3.
*/
navigationTreeQueryDepth: number;
}
3 changes: 3 additions & 0 deletions libs/navigation/driver/magento/src/config/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { MAGENTO_NAVIGATION_DRIVER_CONFIG_DEFAULT } from './default';
export { MagentoNavigationDriverConfig } from './interface';
export * from './token';
18 changes: 18 additions & 0 deletions libs/navigation/driver/magento/src/config/token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createConfigInjectionToken } from '@daffodil/core';

import { MAGENTO_NAVIGATION_DRIVER_CONFIG_DEFAULT } from './default';
import { MagentoNavigationDriverConfig } from './interface';

export const {
/**
* The token used to provide @daffodil/navigation/driver/magento config data.
*/
token: MAGENTO_NAVIGATION_DRIVER_CONFIG,
/**
* Provider function for {@link MAGENTO_NAVIGATION_DRIVER_CONFIG}.
*/
provider: provideMagentoNavigationDriverConfig,
} = createConfigInjectionToken<MagentoNavigationDriverConfig>(
MAGENTO_NAVIGATION_DRIVER_CONFIG_DEFAULT,
'MAGENTO_NAVIGATION_DRIVER_CONFIG',
);

This file was deleted.

20 changes: 10 additions & 10 deletions libs/navigation/driver/magento/src/navigation-driver.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,21 @@ import {
} from '@daffodil/navigation/driver';

import {
MagentoNavigationDriverConfiguration,
MAGENTO_NAVIGATION_TREE_QUERY_DEPTH,
} from './interfaces/navigation-config.interface';
MagentoNavigationDriverConfig,
MAGENTO_NAVIGATION_DRIVER_CONFIG_DEFAULT,
MAGENTO_NAVIGATION_DRIVER_CONFIG,
} from './config/public_api';
import { DaffMagentoNavigationService } from './navigation.service';
import { DAFF_MAGENTO_GET_CATEGORY_TREE_QUERY_NAME } from './queries/get-category-tree';
import { DaffMagentoNavigationTransformerService } from './transformers/navigation-transformer';

export const MAGENTO_NAVIGATION_DEFAULT_CONFIGURATION: MagentoNavigationDriverConfiguration = {
navigationTreeQueryDepth: 3,
};

@NgModule({
imports: [
CommonModule,
],
})
export class DaffNavigationMagentoDriverModule {
static forRoot(config: MagentoNavigationDriverConfiguration = MAGENTO_NAVIGATION_DEFAULT_CONFIGURATION): ModuleWithProviders<DaffNavigationMagentoDriverModule> {
static forRoot(config: MagentoNavigationDriverConfig = MAGENTO_NAVIGATION_DRIVER_CONFIG_DEFAULT): ModuleWithProviders<DaffNavigationMagentoDriverModule> {
return {
ngModule: DaffNavigationMagentoDriverModule,
providers: [
Expand All @@ -41,8 +38,11 @@ export class DaffNavigationMagentoDriverModule {
useExisting: DaffMagentoNavigationTransformerService,
},
{
provide: MAGENTO_NAVIGATION_TREE_QUERY_DEPTH,
useValue: config.navigationTreeQueryDepth,
provide: MAGENTO_NAVIGATION_DRIVER_CONFIG,
useValue: {
...MAGENTO_NAVIGATION_DRIVER_CONFIG_DEFAULT,
...config,
},
},
{
provide: DAFF_MAGENTO_CACHEABLE_OPERATIONS,
Expand Down
9 changes: 4 additions & 5 deletions libs/navigation/driver/magento/src/navigation.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { schema } from '@daffodil/driver/magento';
import { DaffNavigationTransformer } from '@daffodil/navigation/driver';
import {
DaffMagentoNavigationTransformerService,
MAGENTO_NAVIGATION_TREE_QUERY_DEPTH,
daffMagentoGetCategoryTree,
provideMagentoNavigationDriverConfig,
} from '@daffodil/navigation/driver/magento';
import { DaffNavigationTreeFactory } from '@daffodil/navigation/testing';

Expand All @@ -34,10 +34,9 @@ describe('Driver | Magento | Navigation | NavigationService', () => {
providers: [
DaffMagentoNavigationService,
{ provide: DaffNavigationTransformer, useExisting: DaffMagentoNavigationTransformerService },
{
provide: MAGENTO_NAVIGATION_TREE_QUERY_DEPTH,
useValue: queryDepth,
},
provideMagentoNavigationDriverConfig({
navigationTreeQueryDepth: queryDepth,
}),
{
provide: APOLLO_TESTING_CACHE,
useValue: new InMemoryCache({
Expand Down
9 changes: 6 additions & 3 deletions libs/navigation/driver/magento/src/navigation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
DaffNavigationTransformerInterface,
} from '@daffodil/navigation/driver';

import { MAGENTO_NAVIGATION_TREE_QUERY_DEPTH } from './interfaces/navigation-config.interface';
import {
MAGENTO_NAVIGATION_DRIVER_CONFIG,
MagentoNavigationDriverConfig,
} from './config/public_api';
import { GetCategoryTreeResponse } from './models/get-category-tree-response';
import { daffMagentoGetCategoryTree } from './queries/get-category-tree';

Expand All @@ -28,12 +31,12 @@ export class DaffMagentoNavigationService implements DaffNavigationServiceInterf
constructor(
private apollo: Apollo,
@Inject(DaffNavigationTransformer) private transformer: DaffNavigationTransformerInterface<DaffNavigationTree>,
@Inject(MAGENTO_NAVIGATION_TREE_QUERY_DEPTH) private categoryTreeQueryDepth: number,
@Inject(MAGENTO_NAVIGATION_DRIVER_CONFIG) private config: MagentoNavigationDriverConfig,
) {}

get(categoryId: string): Observable<DaffNavigationTree> {
return this.apollo.query<GetCategoryTreeResponse>({
query: daffMagentoGetCategoryTree(this.categoryTreeQueryDepth),
query: daffMagentoGetCategoryTree(this.config.navigationTreeQueryDepth),
variables: {
filters: { category_uid: { eq: categoryId }},
},
Expand Down
10 changes: 2 additions & 8 deletions libs/navigation/driver/magento/src/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
export {
MAGENTO_NAVIGATION_TREE_QUERY_DEPTH,
MagentoNavigationDriverConfiguration,
} from './interfaces/navigation-config.interface';
export {
DaffNavigationMagentoDriverModule,
MAGENTO_NAVIGATION_DEFAULT_CONFIGURATION,
} from './navigation-driver.module';
export { DaffNavigationMagentoDriverModule } from './navigation-driver.module';
export { DaffMagentoNavigationService } from './navigation.service';
export { DaffMagentoNavigationTransformerService } from './transformers/navigation-transformer';
export * from './queries/get-category-tree';
export * from './config/public_api';
export * from './models/public_api';
export * from './transforms/public_api';

0 comments on commit 0f20924

Please sign in to comment.