Files
HSAP/platform/web/node_modules/react-router-dom/modules/NavLink.js
Chengfang Lu e72bc061c5 feat: HSAP platform v2 — modular navigation, quality review, audit log, world model simulation
Major changes:
- New frontend (platform/web/): Vite + React 18 + TypeScript + Tailwind
- 4-module navigation: 数据送标 / 模型管理 / 车队管理 / 系统管理
- Data catalog with charts (DMS/ADAS/Lane 3-tab view)
- Quality review workflow (标注质检): Good/Fine/Bad scoring with auto-advance
- Audit enhancements: batch operations, rejection categories, Feishu notifications
- Operation audit log (操作日志)
- World model simulation studio (仿真工坊)
- Dataset version management with snapshots and diff
- ADAS 7-class dataset integration (138K images organized + compressed)
- User management with Feishu integration and pagination
- CRUD/search/filter on all pages, card layout redesign
- PIL-optimized image overlay rendering
- Auto-snapshot on build, in_review workflow stage
- Removed embedded algorithm code (now in workspace)
2026-06-03 11:40:21 +08:00

135 lines
3.5 KiB
JavaScript

import React from "react";
import { __RouterContext as RouterContext, matchPath } from "react-router";
import PropTypes from "prop-types";
import invariant from "tiny-invariant";
import Link from "./Link.js";
import {
resolveToLocation,
normalizeToLocation
} from "./utils/locationUtils.js";
// React 15 compat
const forwardRefShim = C => C;
let { forwardRef } = React;
if (typeof forwardRef === "undefined") {
forwardRef = forwardRefShim;
}
function joinClassnames(...classnames) {
return classnames.filter(i => i).join(" ");
}
/**
* A <Link> wrapper that knows if it's "active" or not.
*/
const NavLink = forwardRef(
(
{
"aria-current": ariaCurrent = "page",
activeClassName = "active", // TODO: deprecate
activeStyle, // TODO: deprecate
className: classNameProp,
exact,
isActive: isActiveProp,
location: locationProp,
sensitive,
strict,
style: styleProp,
to,
innerRef, // TODO: deprecate
...rest
},
forwardedRef
) => {
return (
<RouterContext.Consumer>
{context => {
invariant(context, "You should not use <NavLink> outside a <Router>");
const currentLocation = locationProp || context.location;
const toLocation = normalizeToLocation(
resolveToLocation(to, currentLocation),
currentLocation
);
const { pathname: path } = toLocation;
// Regex taken from: https://github.com/pillarjs/path-to-regexp/blob/master/index.js#L202
const escapedPath =
path && path.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
const match = escapedPath
? matchPath(currentLocation.pathname, {
path: escapedPath,
exact,
sensitive,
strict
})
: null;
const isActive = !!(isActiveProp
? isActiveProp(match, currentLocation)
: match);
let className =
typeof classNameProp === "function"
? classNameProp(isActive)
: classNameProp;
let style =
typeof styleProp === "function" ? styleProp(isActive) : styleProp;
if (isActive) {
className = joinClassnames(className, activeClassName);
style = { ...style, ...activeStyle };
}
const props = {
"aria-current": (isActive && ariaCurrent) || null,
className,
style,
to: toLocation,
...rest
};
// React 15 compat
if (forwardRefShim !== forwardRef) {
props.ref = forwardedRef || innerRef;
} else {
props.innerRef = innerRef;
}
return <Link {...props} />;
}}
</RouterContext.Consumer>
);
}
);
if (__DEV__) {
NavLink.displayName = "NavLink";
const ariaCurrentType = PropTypes.oneOf([
"page",
"step",
"location",
"date",
"time",
"true",
"false"
]);
NavLink.propTypes = {
...Link.propTypes,
"aria-current": ariaCurrentType,
activeClassName: PropTypes.string,
activeStyle: PropTypes.object,
className: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
exact: PropTypes.bool,
isActive: PropTypes.func,
location: PropTypes.object,
sensitive: PropTypes.bool,
strict: PropTypes.bool,
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
};
}
export default NavLink;