-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic nodes prevent navigation tree mutation #321
Changes from 113 commits
ec5f47c
1f7802a
830407f
7e110fa
d600374
e530f6d
66776e8
d4d3412
fbc2301
446bac3
b589a3d
ab1cc3f
47d28b6
aedd8da
6656a2b
3cf4917
ccc8157
a0c8f0e
38afc97
6670654
6b83b17
8abd146
2ea8f6b
996844a
a6b091c
259a587
19146ee
eb1a472
0f1f65e
6c91d1d
d7b3b8b
a1f7843
12d000d
057c7ee
1686dae
ae77b09
dd539e6
40c4a48
bc3ffbe
242c90f
18e1ba6
87d0060
84fc378
22779f3
d3293e3
4a51b86
8165408
488c767
70fd297
3c5820f
9de58aa
46ceedd
4c7b559
ebf539c
597f33f
fa4943b
13bcf62
5852ca4
d7b0cee
4d92318
7bf4fb3
9aa3241
6a31016
2d3bd78
92988f2
c33e2fc
102e434
216c667
0c014fe
2bf41d9
1e51dfc
04f046a
3e78486
9c5f6cb
ad5b55d
9e698c9
eecd8a1
a690e56
131bf8c
7806a56
07fe6e6
ac311a9
f0ad156
77b76c7
8997828
6f32df2
dbdd6d2
c502d65
47673ed
755576b
812a67d
8d1d9fa
3885d0b
ae830d0
ff6f493
71c8798
402f60e
583356e
d00da70
1fc1b6d
ba7d076
375678b
7256e38
239bbcb
a8ffb82
35e2658
0a9db70
cca92c6
6ae9d06
3f33af2
41bb0fd
0d085e7
abeb231
9bfd741
3916f15
a3a8b27
476b752
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import * as NavigationHelpers from '../../utilities/helpers/navigation-helpers'; | ||
import * as AsyncHelpers from '../../utilities/helpers/async-helpers'; | ||
import * as GenericHelpers from '../../utilities/helpers/generic-helpers'; | ||
import * as RoutingHelpers from '../../utilities/helpers/routing-helpers'; | ||
|
||
export const getNavigationPath = async (rootNavProviderPromise, activePath) => { | ||
if (!rootNavProviderPromise) { | ||
|
@@ -25,12 +26,17 @@ export const getNavigationPath = async (rootNavProviderPromise, activePath) => { | |
} | ||
await getChildren(rootNode); // keep it, mutates and filters children | ||
const nodeNamesInCurrentPath = (activePath || '').split('/'); | ||
return buildNode( | ||
const navObj = await buildNode( | ||
nodeNamesInCurrentPath, | ||
[rootNode], | ||
rootNode.children, | ||
rootNode.context || {} | ||
); | ||
navObj.isExistingRoute = | ||
!activePath || | ||
nodeNamesInCurrentPath.length === | ||
navObj.navigationPath.filter(x => x.pathSegment).length; | ||
return navObj; | ||
} catch (err) { | ||
console.error('Failed to load top navigation nodes.', err); | ||
} | ||
|
@@ -83,21 +89,23 @@ const buildNode = async ( | |
nodeNamesInCurrentPath, | ||
nodesInCurrentPath, | ||
childrenOfCurrentNode, | ||
context | ||
context, | ||
pathParams = {} | ||
) => { | ||
if (!context.parentNavigationContexts) { | ||
context.parentNavigationContexts = []; | ||
} | ||
let result = { | ||
navigationPath: nodesInCurrentPath, | ||
context: context | ||
context: context, | ||
pathParams: pathParams | ||
}; | ||
if ( | ||
nodeNamesInCurrentPath.length > 0 && | ||
childrenOfCurrentNode && | ||
childrenOfCurrentNode.length > 0 | ||
) { | ||
const urlPathElement = nodeNamesInCurrentPath.splice(0, 1)[0]; | ||
const urlPathElement = nodeNamesInCurrentPath[0]; | ||
const node = findMatchingNode(urlPathElement, childrenOfCurrentNode); | ||
if (node) { | ||
nodesInCurrentPath.push(node); | ||
|
@@ -109,11 +117,21 @@ const buildNode = async ( | |
try { | ||
let children = await getChildren(node, newContext); | ||
|
||
if (node.pathSegment.startsWith(':')) { | ||
pathParams[ | ||
node.pathSegment.replace(':', '') | ||
] = RoutingHelpers.sanitizeParam(urlPathElement); | ||
} | ||
const newNodeNamesInCurrentPath = nodeNamesInCurrentPath.slice(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can write it in just one line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But a |
||
newNodeNamesInCurrentPath.shift(); | ||
|
||
result = buildNode( | ||
nodeNamesInCurrentPath, | ||
newNodeNamesInCurrentPath, | ||
// nodeNamesInCurrentPath, | ||
nodesInCurrentPath, | ||
children, | ||
newContext | ||
newContext, | ||
pathParams | ||
); | ||
} catch (err) { | ||
console.error('Error getting nodes children', err); | ||
|
@@ -147,52 +165,13 @@ export const findMatchingNode = (urlPathElement, nodes) => { | |
} | ||
} | ||
nodes.some(node => { | ||
// Static nodes | ||
if (node.pathSegment === urlPathElement) { | ||
result = node; | ||
return true; | ||
} | ||
|
||
// Dynamic nodes | ||
if ( | ||
(node.pathSegment && node.pathSegment.startsWith(':')) || | ||
(node.pathParam && node.pathParam.key) | ||
// Static nodes | ||
node.pathSegment === urlPathElement || | ||
// Dynamic nodes | ||
(node.pathSegment && node.pathSegment.startsWith(':')) | ||
) { | ||
if (node.pathParam && node.pathParam.key) { | ||
node.viewUrl = node.pathParam.viewUrl; | ||
node.context = node.pathParam.context | ||
? Object.assign({}, node.pathParam.context) | ||
: undefined; | ||
node.pathSegment = node.pathParam.pathSegment; | ||
} else { | ||
node.pathParam = { | ||
key: node.pathSegment.slice(0), | ||
pathSegment: node.pathSegment, | ||
viewUrl: node.viewUrl, | ||
context: node.context ? Object.assign({}, node.context) : undefined | ||
}; | ||
} | ||
node.pathParam.value = urlPathElement; | ||
|
||
// path substitutions | ||
node.pathSegment = node.pathSegment.replace( | ||
node.pathParam.key, | ||
urlPathElement | ||
); | ||
|
||
if (node.viewUrl) { | ||
node.viewUrl = node.viewUrl.replace(node.pathParam.key, urlPathElement); | ||
} | ||
|
||
if (node.context) { | ||
Object.entries(node.context).map(entry => { | ||
const dynKey = entry[1]; | ||
if (dynKey === node.pathParam.key) { | ||
node.context[entry[0]] = dynKey.replace(dynKey, urlPathElement); | ||
} | ||
}); | ||
} | ||
|
||
// Return last matching node | ||
result = node; | ||
return true; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look nice when clicked. I would recommend using the same approach as for the
groups
dynamic nodeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added
keepSelectedForChildren: true,
since we are not able to drill down here, because the child is dynamic. Think this is what you meant.