Skip to content

Commit 122704b

Browse files
committed
feat: add version check for routing feature availability
1 parent 8ff88ed commit 122704b

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/features/Routing.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
RoutingDevicesAndTieLines,
2323
TieLine,
2424
useGetRoutingDevicesAndTieLinesQuery,
25+
useGetVersionsQuery,
2526
} from "../store/apiSlice";
2627
import styles from "./Routing.module.scss";
2728
import RoutingDeviceNode, {
@@ -176,6 +177,18 @@ function uniqueSignalTypes(tieLines: TieLine[]): string[] {
176177
return [...new Set(tieLines.map((tl) => tl.signalType))].sort();
177178
}
178179

180+
// Compares dot-separated version strings numerically (e.g. "2.29" > "2.9").
181+
function meetsMinVersion(version: string, minimum: string): boolean {
182+
const vParts = version.split(".").map(Number);
183+
const mParts = minimum.split(".").map(Number);
184+
for (let i = 0; i < Math.max(vParts.length, mParts.length); i++) {
185+
const a = vParts[i] ?? 0;
186+
const b = mParts[i] ?? 0;
187+
if (a !== b) return a > b;
188+
}
189+
return true;
190+
}
191+
179192
// ─── Node types registry (stable reference outside component) ────────────────
180193

181194
const nodeTypes: NodeTypes = {
@@ -186,6 +199,7 @@ const nodeTypes: NodeTypes = {
186199

187200
const Routing = () => {
188201
const { appId } = useAppParams();
202+
const { data: versions } = useGetVersionsQuery(appId ? { appId } : skipToken);
189203
const { data, isLoading, isError } = useGetRoutingDevicesAndTieLinesQuery(
190204
appId ? { appId } : skipToken,
191205
);
@@ -285,6 +299,20 @@ const Routing = () => {
285299
if (isLoading) return <div className="p-3">Loading routing data…</div>;
286300
if (isError || !data)
287301
return <div className="p-3 text-danger">Failed to load routing data.</div>;
302+
if (
303+
versions &&
304+
!versions.some(
305+
(v) =>
306+
v.Name === "PepperDashEssentials" &&
307+
meetsMinVersion(v.Version, "2.29"),
308+
)
309+
) {
310+
return (
311+
<div className="p-3 text-danger">
312+
Routing feature is not available for this version.
313+
</div>
314+
);
315+
}
288316

289317
return (
290318
<div className="h-100 d-flex flex-column overflow-hidden">

0 commit comments

Comments
 (0)