@visns-studio/visns-components 6.17.1 → 6.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -95,7 +95,7 @@
95
95
  "react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
96
96
  },
97
97
  "name": "@visns-studio/visns-components",
98
- "version": "6.17.1",
98
+ "version": "6.17.2",
99
99
  "description": "Various packages to assist in the development of our Custom Applications.",
100
100
  "main": "src/index.js",
101
101
  "files": [
@@ -30,7 +30,7 @@ import CustomFetch from './Fetch';
30
30
  import Notification from './Notification';
31
31
  import SwitchAccount from './SwitchAccount';
32
32
  import BusinessCardOcr from './BusinessCardOcr';
33
- import { isNavActive } from './navActive';
33
+ import { isNavActive, bestMatchingUrl, cleanUrl } from './navActive';
34
34
  import styles from './styles/Navigation.module.scss';
35
35
 
36
36
  // Opt-in icons for the sidebar (simple/cms) layouts: a nav entry names one
@@ -598,7 +598,11 @@ function Navigation({
598
598
  <Link
599
599
  to={child.url}
600
600
  className={
601
- isNavActive(child.url, [], currentPage)
601
+ cleanUrl(child.url) ===
602
+ bestMatchingUrl(
603
+ n.children.map((one) => one.url),
604
+ currentPage
605
+ )
602
606
  ? styles.active
603
607
  : ''
604
608
  }
@@ -57,4 +57,29 @@ export function isNavActive(navUrl, childUrls, currentUrl) {
57
57
  return (childUrls || []).some((child) => covers(cleanUrl(child), current));
58
58
  }
59
59
 
60
+
61
+ /**
62
+ * Which ONE of a set of sibling urls is the current page's best match: the
63
+ * longest url that covers it. `/reports` and `/reports/prebuilt` both cover
64
+ * `/reports/prebuilt`; only the second is the page you are on.
65
+ *
66
+ * @param {string[]} urls sibling urls (dropdown children).
67
+ * @param {string} currentUrl the path being viewed.
68
+ * @returns {string|null} the cleaned winning url, or null when none covers it.
69
+ */
70
+ export function bestMatchingUrl(urls, currentUrl) {
71
+ const current = cleanUrl(currentUrl) || '/';
72
+ let best = null;
73
+
74
+ (urls || []).forEach((url) => {
75
+ const base = cleanUrl(url);
76
+
77
+ if (!base || base === '/') return;
78
+ if (!covers(base, current)) return;
79
+ if (best === null || base.length > best.length) best = base;
80
+ });
81
+
82
+ return best;
83
+ }
84
+
60
85
  export default isNavActive;