Skip to content

Commit

Permalink
fix(external-router): extract daff paths ignoring full path (#2955)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 authored Aug 7, 2024
1 parent 16b6000 commit 961512d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions libs/external-router/src/util/extract-daff-path-data.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { ActivatedRouteSnapshot } from '@angular/router';

import { daffExtractDaffPathData } from './extract-daff-path-data';

describe('@daffodil/external-router | daffExtractDaffPathData', () => {
let snapshot: ActivatedRouteSnapshot;

beforeEach(() => {
snapshot = <ActivatedRouteSnapshot><unknown>{
data: {
daffPaths: {
'00/01/02/10/11/12': {
test: 'test',
},
},
},
pathFromRoot: [
{
url: [],
},
{
url: [
{ path: '00' },
{ path: '01' },
{ path: '02' },
],
},
{
url: [
{ path: '10' },
{ path: '11' },
{ path: '12' },
],
},
{
url: [],
},
],
};
});

it('should return the correct data', () => {
expect(daffExtractDaffPathData(snapshot, 'test')).toEqual('test');
});
});
2 changes: 1 addition & 1 deletion libs/external-router/src/util/extract-daff-path-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import {
* RouteSnapshot.
*/
export const daffExtractDaffPathData = <T extends Data = Data, K extends keyof T = keyof T>(snapshot: ActivatedRouteSnapshot, key: K): T[K] => {
const pathFromRoot = snapshot.pathFromRoot[snapshot.pathFromRoot.length - 1].url.map((seg) => seg.path).join('/');
const pathFromRoot = snapshot.pathFromRoot.flatMap((route) => route.url).map((seg) => seg.path).join('/');
return snapshot.data?.daffPaths?.[pathFromRoot]?.[key] ?? null;
};

0 comments on commit 961512d

Please sign in to comment.