@banch0u/core-project-test-repository 1.11.7 → 1.12.0

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.
@@ -1,7 +1,7 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
- import React, { useEffect, useState, useCallback } from "react";
4
+ import React, { useEffect, useState, useCallback, useMemo } from "react";
5
5
  import { Link, useLocation } from "react-router-dom";
6
6
  import Cookies from "js-cookie";
7
7
  import style from "./index.module.scss";
@@ -13,7 +13,6 @@ import { getCompanyInfo } from "../../store/slices/companyInfo";
13
13
  import api from "../../utils/axios";
14
14
  var Sider = Layout.Sider;
15
15
  var Sidebar = function Sidebar(_ref) {
16
- var _items$flatMap$find;
17
16
  var _ref$items = _ref.items,
18
17
  items = _ref$items === void 0 ? [] : _ref$items;
19
18
  var location = useLocation();
@@ -110,11 +109,44 @@ var Sidebar = function Sidebar(_ref) {
110
109
  window.removeEventListener("themeChange", handleThemeChange);
111
110
  };
112
111
  }, []);
113
- var selectedKey = (_items$flatMap$find = items.flatMap(function (item) {
114
- return item.children ? item.children : item;
115
- }).find(function (item) {
116
- return location.pathname.includes(item.key);
117
- })) === null || _items$flatMap$find === void 0 ? void 0 : _items$flatMap$find.key;
112
+
113
+ // --- FIX: compute selectedKey by exact segment match OR full-path prefix match, prefer the longest match
114
+ var flatItems = useMemo(function () {
115
+ var _flatten = function flatten(arr) {
116
+ return arr.flatMap(function (it) {
117
+ var _it$children;
118
+ return it !== null && it !== void 0 && (_it$children = it.children) !== null && _it$children !== void 0 && _it$children.length ? _flatten(it.children) : [it];
119
+ });
120
+ };
121
+ return _flatten(items || []);
122
+ }, [items]);
123
+ var selectedKey = useMemo(function () {
124
+ var rawPath = location.pathname || "/";
125
+ var path = rawPath.replace(/\/+$/, ""); // trim trailing slash
126
+ var segments = path.split("/").filter(Boolean);
127
+ var normalize = function normalize(s) {
128
+ return typeof s === "string" ? s.trim() : "";
129
+ };
130
+ var candidates = flatItems.map(function (it) {
131
+ return normalize(it === null || it === void 0 ? void 0 : it.key);
132
+ }).filter(Boolean);
133
+ var isMatch = function isMatch(key) {
134
+ // Case A: key looks like a full path
135
+ if (key.startsWith("/")) {
136
+ var nk = key.replace(/\/+$/, "");
137
+ return path === nk || path.startsWith(nk + "/");
138
+ }
139
+ // Case B: key is a segment/token (e.g., "chlorine" or "chlorine-percentage")
140
+ // Match only exact segment equality, not substring
141
+ return segments.includes(key);
142
+ };
143
+
144
+ // gather all matches, then prefer the most specific (longest key string)
145
+ var matches = candidates.filter(isMatch).sort(function (a, b) {
146
+ return b.length - a.length;
147
+ });
148
+ return matches[0]; // undefined if none
149
+ }, [location.pathname, flatItems]);
118
150
  return /*#__PURE__*/React.createElement(Sider, {
119
151
  width: 287,
120
152
  collapsible: true,
@@ -127,7 +159,7 @@ var Sidebar = function Sidebar(_ref) {
127
159
  }, /*#__PURE__*/React.createElement(Menu, {
128
160
  mode: "inline",
129
161
  items: items,
130
- selectedKeys: [selectedKey],
162
+ selectedKeys: selectedKey ? [selectedKey] : [],
131
163
  className: style.menu
132
164
  })), /*#__PURE__*/React.createElement(Link, {
133
165
  to: PLATFORM_PATH,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@banch0u/core-project-test-repository",
3
- "version": "1.11.7",
3
+ "version": "1.12.0",
4
4
  "description": "Shared core features for all projects",
5
5
  "main": "dist/index.js",
6
6
  "files": [