Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Split dashboard threshold slider runtime owners

rcourtman61400e86be80
diff --git a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
index 247787a462..6d652f274f 100644
--- a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
+++ b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
@@ -30,27 +30,32 @@ regression protection.
8. `frontend-modern/src/components/Dashboard/DashboardFilter.tsx`
9. `frontend-modern/src/components/Dashboard/dashboardFilterModel.ts`
10. `frontend-modern/src/components/Dashboard/useDashboardFilterState.ts`
-11. `frontend-modern/src/components/Dashboard/DiskList.tsx`
-12. `frontend-modern/src/components/Dashboard/diskListModel.ts`
-13. `frontend-modern/src/components/Dashboard/useDiskListState.ts`
-14. `frontend-modern/src/components/Dashboard/GuestRow.tsx`
-15. `frontend-modern/src/components/Dashboard/guestRowModel.tsx`
-16. `frontend-modern/src/components/Dashboard/useGuestRowState.ts`
-17. `frontend-modern/src/components/Dashboard/GuestDrawer.tsx`
-18. `frontend-modern/src/components/Dashboard/guestDrawerModel.ts`
-19. `frontend-modern/src/components/Dashboard/useGuestDrawerState.ts`
-20. `frontend-modern/src/components/Dashboard/workloadSelectors.ts`
-21. `frontend-modern/src/components/Infrastructure/UnifiedResourceTable.tsx`
-22. `frontend-modern/src/components/Infrastructure/useUnifiedResourceTableState.ts`
-23. `frontend-modern/src/components/Infrastructure/infrastructureSelectors.ts`
-24. `frontend-modern/src/components/Infrastructure/resourceDetailMappers.ts`
-25. `frontend-modern/src/components/Dashboard/__tests__/Dashboard.performance.contract.test.tsx`
-26. `frontend-modern/src/components/Dashboard/__tests__/DashboardFilter.test.tsx`
-27. `frontend-modern/src/components/Dashboard/__tests__/useDashboardFilterState.test.ts`
-28. `frontend-modern/src/components/Dashboard/__tests__/DiskList.test.tsx`
-29. `frontend-modern/src/components/Dashboard/__tests__/GuestRow.test.tsx`
-30. `frontend-modern/src/components/Dashboard/GuestDrawer.test.tsx`
-31. `frontend-modern/src/components/Infrastructure/__tests__/UnifiedResourceTable.performance.contract.test.tsx`
+11. `frontend-modern/src/components/Dashboard/ThresholdSlider.tsx`
+12. `frontend-modern/src/components/Dashboard/thresholdSliderModel.ts`
+13. `frontend-modern/src/components/Dashboard/useThresholdSliderState.ts`
+14. `frontend-modern/src/components/Dashboard/DiskList.tsx`
+15. `frontend-modern/src/components/Dashboard/diskListModel.ts`
+16. `frontend-modern/src/components/Dashboard/useDiskListState.ts`
+17. `frontend-modern/src/components/Dashboard/GuestRow.tsx`
+18. `frontend-modern/src/components/Dashboard/guestRowModel.tsx`
+19. `frontend-modern/src/components/Dashboard/useGuestRowState.ts`
+20. `frontend-modern/src/components/Dashboard/GuestDrawer.tsx`
+21. `frontend-modern/src/components/Dashboard/guestDrawerModel.ts`
+22. `frontend-modern/src/components/Dashboard/useGuestDrawerState.ts`
+23. `frontend-modern/src/components/Dashboard/workloadSelectors.ts`
+24. `frontend-modern/src/components/Infrastructure/UnifiedResourceTable.tsx`
+25. `frontend-modern/src/components/Infrastructure/useUnifiedResourceTableState.ts`
+26. `frontend-modern/src/components/Infrastructure/infrastructureSelectors.ts`
+27. `frontend-modern/src/components/Infrastructure/resourceDetailMappers.ts`
+28. `frontend-modern/src/components/Dashboard/__tests__/Dashboard.performance.contract.test.tsx`
+29. `frontend-modern/src/components/Dashboard/__tests__/DashboardFilter.test.tsx`
+30. `frontend-modern/src/components/Dashboard/__tests__/useDashboardFilterState.test.ts`
+31. `frontend-modern/src/components/Dashboard/ThresholdSlider.test.tsx`
+32. `frontend-modern/src/components/Dashboard/__tests__/useThresholdSliderState.test.ts`
+33. `frontend-modern/src/components/Dashboard/__tests__/DiskList.test.tsx`
+34. `frontend-modern/src/components/Dashboard/__tests__/GuestRow.test.tsx`
+35. `frontend-modern/src/components/Dashboard/GuestDrawer.test.tsx`
+36. `frontend-modern/src/components/Infrastructure/__tests__/UnifiedResourceTable.performance.contract.test.tsx`
## Shared Boundaries
@@ -74,6 +79,7 @@ regression protection.
10. Extend dashboard drawer derivations and runtime wiring through `frontend-modern/src/components/Dashboard/guestDrawerModel.ts` and `frontend-modern/src/components/Dashboard/useGuestDrawerState.ts` rather than rebuilding canonical guest identity, discovery routing, or drawer-local normalization inside `frontend-modern/src/components/Dashboard/GuestDrawer.tsx`
11. Extend dashboard disk-list derivations and fallback runtime wiring through `frontend-modern/src/components/Dashboard/diskListModel.ts` and `frontend-modern/src/components/Dashboard/useDiskListState.ts` rather than rebuilding usage math, progress-state mapping, or tooltip fallback logic inside `frontend-modern/src/components/Dashboard/DiskList.tsx`
12. Extend dashboard filter defaults, active-filter counting, reset semantics, and mobile toolbar state through `frontend-modern/src/components/Dashboard/dashboardFilterModel.ts` and `frontend-modern/src/components/Dashboard/useDashboardFilterState.ts`, and keep dashboard-owned filter-config assembly in `frontend-modern/src/components/Dashboard/useDashboardState.ts`, rather than rebuilding filter-local state inside `frontend-modern/src/components/Dashboard/DashboardFilter.tsx` or inline config IIFEs in `frontend-modern/src/components/Dashboard/Dashboard.tsx`
+13. Extend threshold-slider value-position math, title/label derivation, and drag scroll-lock runtime through `frontend-modern/src/components/Dashboard/thresholdSliderModel.ts` and `frontend-modern/src/components/Dashboard/useThresholdSliderState.ts` rather than rebuilding slider-local state and pointer lifecycle inside `frontend-modern/src/components/Dashboard/ThresholdSlider.tsx`
## Forbidden Paths
@@ -138,6 +144,14 @@ The dashboard-owned filter-config assembly now lives in
filter runtime changes must extend through those owners instead of
reintroducing dashboard-local state, reset drift, or inline config assembly
into the shell.
+The dashboard threshold slider now follows that same pattern: the shell stays
+in `frontend-modern/src/components/Dashboard/ThresholdSlider.tsx`, while
+slider bounds math, thumb-position transforms, and title/label derivations
+live in `frontend-modern/src/components/Dashboard/thresholdSliderModel.ts`
+and drag scroll-lock lifecycle lives in
+`frontend-modern/src/components/Dashboard/useThresholdSliderState.ts`.
+Future slider runtime changes must extend through those owners instead of
+reintroducing mixed drag state and formatting logic into the shell.
The unified resource table hot path is now also governed as explicit
performance-owned runtime, with shared ownership against the unified-resource
diff --git a/docs/release-control/v6/internal/subsystems/registry.json b/docs/release-control/v6/internal/subsystems/registry.json
index 9b83ec5cce..2467711560 100644
--- a/docs/release-control/v6/internal/subsystems/registry.json
+++ b/docs/release-control/v6/internal/subsystems/registry.json
@@ -2526,11 +2526,14 @@
"frontend-modern/src/components/Dashboard/guestDrawerModel.ts",
"frontend-modern/src/components/Dashboard/GuestRow.tsx",
"frontend-modern/src/components/Dashboard/guestRowModel.tsx",
+ "frontend-modern/src/components/Dashboard/ThresholdSlider.tsx",
+ "frontend-modern/src/components/Dashboard/thresholdSliderModel.ts",
"frontend-modern/src/components/Dashboard/useDashboardFilterState.ts",
"frontend-modern/src/components/Dashboard/useDashboardState.ts",
"frontend-modern/src/components/Dashboard/useDiskListState.ts",
"frontend-modern/src/components/Dashboard/useGuestDrawerState.ts",
"frontend-modern/src/components/Dashboard/useGuestRowState.ts",
+ "frontend-modern/src/components/Dashboard/useThresholdSliderState.ts",
"frontend-modern/src/components/Dashboard/workloadSelectors.ts",
"frontend-modern/src/components/Infrastructure/infrastructureSelectors.ts",
"frontend-modern/src/components/Infrastructure/resourceDetailMappers.ts",
@@ -2548,6 +2551,8 @@
"frontend-modern/src/components/Dashboard/__tests__/DashboardFilter.test.tsx",
"frontend-modern/src/components/Dashboard/__tests__/DiskList.test.tsx",
"frontend-modern/src/components/Dashboard/__tests__/useDashboardFilterState.test.ts",
+ "frontend-modern/src/components/Dashboard/__tests__/useThresholdSliderState.test.ts",
+ "frontend-modern/src/components/Dashboard/ThresholdSlider.test.tsx",
"internal/api/router_bench_test.go",
"internal/api/slo_bench_test.go",
"pkg/metrics/store_bench_test.go",
@@ -2586,11 +2591,14 @@
"frontend-modern/src/components/Dashboard/guestDrawerModel.ts",
"frontend-modern/src/components/Dashboard/GuestRow.tsx",
"frontend-modern/src/components/Dashboard/guestRowModel.tsx",
+ "frontend-modern/src/components/Dashboard/ThresholdSlider.tsx",
+ "frontend-modern/src/components/Dashboard/thresholdSliderModel.ts",
"frontend-modern/src/components/Dashboard/useDashboardFilterState.ts",
"frontend-modern/src/components/Dashboard/useDashboardState.ts",
"frontend-modern/src/components/Dashboard/useDiskListState.ts",
"frontend-modern/src/components/Dashboard/useGuestDrawerState.ts",
"frontend-modern/src/components/Dashboard/useGuestRowState.ts",
+ "frontend-modern/src/components/Dashboard/useThresholdSliderState.ts",
"frontend-modern/src/components/Dashboard/workloadSelectors.ts",
"frontend-modern/src/components/Infrastructure/infrastructureSelectors.ts",
"frontend-modern/src/components/Infrastructure/resourceDetailMappers.ts",
@@ -2605,8 +2613,10 @@
"frontend-modern/src/components/Dashboard/__tests__/DiskList.test.tsx",
"frontend-modern/src/components/Dashboard/__tests__/GuestRow.test.tsx",
"frontend-modern/src/components/Dashboard/__tests__/useDashboardFilterState.test.ts",
+ "frontend-modern/src/components/Dashboard/__tests__/useThresholdSliderState.test.ts",
"frontend-modern/src/components/Dashboard/__tests__/workloadSelectors.test.ts",
"frontend-modern/src/components/Dashboard/GuestDrawer.test.tsx",
+ "frontend-modern/src/components/Dashboard/ThresholdSlider.test.tsx",
"frontend-modern/src/components/Infrastructure/__tests__/UnifiedResourceTable.performance.contract.test.tsx"
]
},
diff --git a/frontend-modern/src/components/Dashboard/ThresholdSlider.test.tsx b/frontend-modern/src/components/Dashboard/ThresholdSlider.test.tsx
index 5a335581bb..4501f07667 100644
--- a/frontend-modern/src/components/Dashboard/ThresholdSlider.test.tsx
+++ b/frontend-modern/src/components/Dashboard/ThresholdSlider.test.tsx
@@ -145,4 +145,20 @@ describe('ThresholdSlider', () => {
// Rose
expect(screen.getByText('50°C').closest('.text-rose-500')).toBeInTheDocument();
});
+
+ it('releases drag scroll lock listeners on unmount', () => {
+ const removeWindowSpy = vi.spyOn(window, 'removeEventListener');
+ const removeDocumentSpy = vi.spyOn(document, 'removeEventListener');
+
+ const { unmount } = render(() => <ThresholdSlider value={50} onChange={vi.fn()} type="disk" />);
+ const input = screen.getByTitle('DISK: 50%');
+
+ fireEvent.mouseDown(input);
+ unmount();
+
+ expect(removeWindowSpy).toHaveBeenCalledWith('scroll', expect.any(Function), {
+ capture: true,
+ });
+ expect(removeDocumentSpy).toHaveBeenCalledWith('mouseup', expect.any(Function));
+ });
});
diff --git a/frontend-modern/src/components/Dashboard/ThresholdSlider.tsx b/frontend-modern/src/components/Dashboard/ThresholdSlider.tsx
index f6e0346938..77354872a5 100644
--- a/frontend-modern/src/components/Dashboard/ThresholdSlider.tsx
+++ b/frontend-modern/src/components/Dashboard/ThresholdSlider.tsx
@@ -1,74 +1,18 @@
-import { createSignal, createEffect, onMount } from 'solid-js';
-import { formatTemperature, getTemperatureSymbol } from '@/utils/temperature';
import {
getThresholdSliderFillClass,
getThresholdSliderTextClass,
} from '@/utils/thresholdSliderPresentation';
-
-interface ThresholdSliderProps {
- value: number;
- onChange: (value: number) => void;
- type: 'cpu' | 'memory' | 'disk' | 'temperature';
- min?: number;
- max?: number;
- disabled?: boolean;
-}
+import { type ThresholdSliderProps } from './thresholdSliderModel';
+import { useThresholdSliderState } from './useThresholdSliderState';
export function ThresholdSlider(props: ThresholdSliderProps) {
- let sliderRef: HTMLInputElement | undefined;
- let thumbRef: HTMLDivElement | undefined;
- const [thumbPosition, setThumbPosition] = createSignal(0);
- const [isDragging, setIsDragging] = createSignal(false);
-
- // Calculate visual position - allow full range 0-100%
- const calculateVisualPosition = (value: number) => {
- const min = props.min || 0;
- const max = props.max || 100;
- const percent = ((value - min) / (max - min)) * 100;
- // Use full range, handle edge cases with CSS
- return Math.max(0, Math.min(100, percent));
- };
-
- // Update thumb position when value changes
- createEffect(() => {
- if (sliderRef) {
- setThumbPosition(calculateVisualPosition(props.value));
- }
- });
-
- onMount(() => {
- // Initialize thumb position
- setThumbPosition(calculateVisualPosition(props.value));
- });
-
- // Prevent scrolling while dragging
- const handleMouseDown = () => {
- setIsDragging(true);
-
- // Store the current scroll position
- const scrollY = window.scrollY;
- const scrollX = window.scrollX;
-
- const handleScroll = () => {
- window.scrollTo(scrollX, scrollY);
- };
-
- const handleMouseUp = () => {
- setIsDragging(false);
- window.removeEventListener('scroll', handleScroll, { capture: true });
- document.removeEventListener('mouseup', handleMouseUp);
- };
-
- // Lock scroll position while dragging
- window.addEventListener('scroll', handleScroll, { capture: true });
- document.addEventListener('mouseup', handleMouseUp);
- };
+ const state = useThresholdSliderState(props);
return (
<div
class={`relative w-full h-3.5 overflow-visible transition-opacity ${props.disabled ? 'opacity-30 grayscale pointer-events-none' : ''}`}
- onWheel={(e) => !props.disabled && isDragging() && e.preventDefault()}
- style={{ 'touch-action': isDragging() ? 'none' : 'auto' }}
+ onWheel={state.handleContainerWheel}
+ style={{ 'touch-action': state.isDragging() ? 'none' : 'auto' }}
>
{/* Track background */}
<div class="absolute inset-0 h-3.5 rounded bg-surface-hover"></div>
@@ -76,51 +20,35 @@ export function ThresholdSlider(props: ThresholdSliderProps) {
{/* Colored fill */}
<div
class={`absolute left-0 h-3.5 rounded ${getThresholdSliderFillClass(props.type)}`}
- style={{ width: `${calculateVisualPosition(props.value)}%` }}
+ style={{ width: `${state.thumbPosition()}%` }}
></div>
{/* Native range input (invisible but functional) */}
<input
- ref={sliderRef}
type="range"
- min={props.min || 0}
- max={props.max || 100}
+ min={props.min ?? 0}
+ max={props.max ?? 100}
value={props.value}
- onInput={(e) => props.onChange(parseInt(e.currentTarget.value))}
- onMouseDown={!props.disabled ? handleMouseDown : undefined}
- onWheel={(e) => !props.disabled && e.preventDefault()}
+ onInput={state.handleInput}
+ onMouseDown={state.handleMouseDown}
+ onWheel={state.handleInputWheel}
class={`absolute inset-0 w-full h-3.5 opacity-0 ${props.disabled ? 'cursor-not-allowed' : 'cursor-pointer'} z-20`}
disabled={props.disabled}
style={{ 'touch-action': 'none' }}
- title={
- props.type === 'temperature'
- ? `Temperature: ${formatTemperature(props.value)}`
- : `${props.type.toUpperCase()}: ${props.value}%`
- }
+ title={state.sliderTitle()}
/>
{/* Custom thumb with value */}
<div
- ref={thumbRef}
class={`absolute top-1/2 pointer-events-none z-10 ${getThresholdSliderTextClass(props.type)}`}
style={{
- left: `${thumbPosition()}%`,
- transform: `translateY(-50%) translateX(${
- thumbPosition() <= 1
- ? '0%' // At 0-1%, keep at left edge
- : thumbPosition() >= 99
- ? '-100%' // At 99-100%, keep at right edge
- : '-50%' // Otherwise center
- })`,
+ left: `${state.thumbPosition()}%`,
+ transform: state.thumbTransform(),
}}
>
<div class="relative">
<div class="w-9 h-4 bg-surface rounded-full shadow-sm border-2 border-current flex items-center justify-center">
- <span class="text-[9px] font-semibold">
- {props.type === 'temperature'
- ? `${props.value}${getTemperatureSymbol().replace('°', '°')}`
- : `${props.value}%`}
- </span>
+ <span class="text-[9px] font-semibold">{state.sliderLabel()}</span>
</div>
</div>
</div>
diff --git a/frontend-modern/src/components/Dashboard/__tests__/Dashboard.performance.contract.test.tsx b/frontend-modern/src/components/Dashboard/__tests__/Dashboard.performance.contract.test.tsx
index 52965f7410..88a47aa261 100644
--- a/frontend-modern/src/components/Dashboard/__tests__/Dashboard.performance.contract.test.tsx
+++ b/frontend-modern/src/components/Dashboard/__tests__/Dashboard.performance.contract.test.tsx
@@ -8,6 +8,9 @@ import dashboardFilterSource from '../DashboardFilter.tsx?raw';
import dashboardFilterModelSource from '../dashboardFilterModel.ts?raw';
import dashboardStateSource from '../useDashboardState.ts?raw';
import dashboardFilterStateSource from '../useDashboardFilterState.ts?raw';
+import thresholdSliderSource from '../ThresholdSlider.tsx?raw';
+import thresholdSliderModelSource from '../thresholdSliderModel.ts?raw';
+import thresholdSliderStateSource from '../useThresholdSliderState.ts?raw';
import diskListSource from '../DiskList.tsx?raw';
import diskListModelSource from '../diskListModel.ts?raw';
import diskListStateSource from '../useDiskListState.ts?raw';
@@ -494,6 +497,19 @@ describe('Dashboard performance contract', () => {
expect(dashboardStateSource).toContain('namespaceFilterConfig');
});
+ it('keeps threshold slider runtime and derivations in canonical slider owners', () => {
+ expect(thresholdSliderSource).toContain('useThresholdSliderState');
+ expect(thresholdSliderSource).not.toContain('const [thumbPosition, setThumbPosition] =');
+ expect(thresholdSliderSource).not.toContain('const handleMouseDown = () => {');
+ expect(thresholdSliderSource).not.toContain('formatTemperature(');
+ expect(thresholdSliderStateSource).toContain('window.addEventListener');
+ expect(thresholdSliderStateSource).toContain('document.addEventListener');
+ expect(thresholdSliderStateSource).toContain('onCleanup');
+ expect(thresholdSliderModelSource).toContain('export function getThresholdSliderPosition');
+ expect(thresholdSliderModelSource).toContain('export function getThresholdSliderTitle');
+ expect(thresholdSliderModelSource).toContain('export function getThresholdSliderLabel');
+ });
+
it('keeps guest row contract and hot-path state in canonical row owners', () => {
expect(guestRowSource).toContain('useGuestRowState');
expect(guestRowSource).not.toContain('export const GUEST_COLUMNS');
diff --git a/frontend-modern/src/components/Dashboard/__tests__/useThresholdSliderState.test.ts b/frontend-modern/src/components/Dashboard/__tests__/useThresholdSliderState.test.ts
new file mode 100644
index 0000000000..fa84ada47c
--- /dev/null
+++ b/frontend-modern/src/components/Dashboard/__tests__/useThresholdSliderState.test.ts
@@ -0,0 +1,57 @@
+import { cleanup, renderHook } from '@solidjs/testing-library';
+import { describe, expect, it, vi } from 'vitest';
+import { useThresholdSliderState } from '@/components/Dashboard/useThresholdSliderState';
+
+vi.mock('@/utils/temperature', () => ({
+ formatTemperature: (value: number) => `${value}°C`,
+ getTemperatureSymbol: () => '°C',
+}));
+
+describe('useThresholdSliderState', () => {
+ it('centralizes threshold slider derivations and drag cleanup', () => {
+ const onChange = vi.fn();
+ const scrollToSpy = vi.spyOn(window, 'scrollTo').mockImplementation(() => {});
+ const addWindowSpy = vi.spyOn(window, 'addEventListener');
+ const removeWindowSpy = vi.spyOn(window, 'removeEventListener');
+ const addDocumentSpy = vi.spyOn(document, 'addEventListener');
+ const removeDocumentSpy = vi.spyOn(document, 'removeEventListener');
+
+ const { result } = renderHook(() =>
+ useThresholdSliderState({
+ value: 45,
+ onChange,
+ type: 'temperature',
+ }),
+ );
+
+ expect(result.thumbPosition()).toBe(45);
+ expect(result.thumbTransform()).toBe('translateY(-50%) translateX(-50%)');
+ expect(result.sliderLabel()).toBe('45°C');
+ expect(result.sliderTitle()).toBe('Temperature: 45°C');
+ expect(result.isDragging()).toBe(false);
+
+ result.handleInput({
+ currentTarget: { value: '75' },
+ } as unknown as InputEvent & { currentTarget: HTMLInputElement; target: HTMLInputElement });
+ expect(onChange).toHaveBeenCalledWith(75);
+
+ result.handleMouseDown?.();
+ expect(result.isDragging()).toBe(true);
+ expect(addWindowSpy).toHaveBeenCalledWith('scroll', expect.any(Function), { capture: true });
+ expect(addDocumentSpy).toHaveBeenCalledWith('mouseup', expect.any(Function));
+
+ const scrollHandler = addWindowSpy.mock.calls.find((call) => call[0] === 'scroll')?.[1] as
+ | EventListener
+ | undefined;
+ expect(scrollHandler).toBeTypeOf('function');
+ scrollHandler?.(new Event('scroll'));
+ expect(scrollToSpy).toHaveBeenCalled();
+
+ cleanup();
+
+ expect(removeWindowSpy).toHaveBeenCalledWith('scroll', expect.any(Function), {
+ capture: true,
+ });
+ expect(removeDocumentSpy).toHaveBeenCalledWith('mouseup', expect.any(Function));
+ });
+});
diff --git a/frontend-modern/src/components/Dashboard/thresholdSliderModel.ts b/frontend-modern/src/components/Dashboard/thresholdSliderModel.ts
new file mode 100644
index 0000000000..2068920fea
--- /dev/null
+++ b/frontend-modern/src/components/Dashboard/thresholdSliderModel.ts
@@ -0,0 +1,55 @@
+import { formatTemperature, getTemperatureSymbol } from '@/utils/temperature';
+import type { ThresholdSliderMetricType } from '@/utils/thresholdSliderPresentation';
+
+export interface ThresholdSliderProps {
+ value: number;
+ onChange: (value: number) => void;
+ type: ThresholdSliderMetricType;
+ min?: number;
+ max?: number;
+ disabled?: boolean;
+}
+
+export const DEFAULT_THRESHOLD_SLIDER_MIN = 0;
+export const DEFAULT_THRESHOLD_SLIDER_MAX = 100;
+
+export function getThresholdSliderBounds(min?: number, max?: number): {
+ min: number;
+ max: number;
+} {
+ return {
+ min: min ?? DEFAULT_THRESHOLD_SLIDER_MIN,
+ max: max ?? DEFAULT_THRESHOLD_SLIDER_MAX,
+ };
+}
+
+export function getThresholdSliderPosition(value: number, min?: number, max?: number): number {
+ const bounds = getThresholdSliderBounds(min, max);
+ const range = bounds.max - bounds.min;
+ if (range <= 0) {
+ return 0;
+ }
+
+ const percent = ((value - bounds.min) / range) * 100;
+ return Math.max(0, Math.min(100, percent));
+}
+
+export function getThresholdSliderThumbTransform(position: number): string {
+ if (position <= 1) {
+ return 'translateY(-50%) translateX(0%)';
+ }
+ if (position >= 99) {
+ return 'translateY(-50%) translateX(-100%)';
+ }
+ return 'translateY(-50%) translateX(-50%)';
+}
+
+export function getThresholdSliderTitle(type: ThresholdSliderMetricType, value: number): string {
+ return type === 'temperature'
+ ? `Temperature: ${formatTemperature(value)}`
+ : `${type.toUpperCase()}: ${value}%`;
+}
+
+export function getThresholdSliderLabel(type: ThresholdSliderMetricType, value: number): string {
+ return type === 'temperature' ? `${value}${getTemperatureSymbol()}` : `${value}%`;
+}
diff --git a/frontend-modern/src/components/Dashboard/useThresholdSliderState.ts b/frontend-modern/src/components/Dashboard/useThresholdSliderState.ts
new file mode 100644
index 0000000000..9f380772d9
--- /dev/null
+++ b/frontend-modern/src/components/Dashboard/useThresholdSliderState.ts
@@ -0,0 +1,103 @@
+import { createMemo, createSignal, onCleanup } from 'solid-js';
+import type { JSX } from 'solid-js';
+import {
+ getThresholdSliderLabel,
+ getThresholdSliderPosition,
+ getThresholdSliderThumbTransform,
+ getThresholdSliderTitle,
+ type ThresholdSliderProps,
+} from './thresholdSliderModel';
+
+type ThresholdSliderInputEvent = InputEvent & {
+ currentTarget: HTMLInputElement;
+ target: HTMLInputElement;
+};
+
+type ThresholdSliderWheelEvent<T extends HTMLElement> = WheelEvent & {
+ currentTarget: T;
+ target: Element;
+};
+
+export function useThresholdSliderState(props: ThresholdSliderProps) {
+ const [isDragging, setIsDragging] = createSignal(false);
+ let releaseDragLock: (() => void) | undefined;
+
+ const clearDragLock = () => {
+ releaseDragLock?.();
+ releaseDragLock = undefined;
+ setIsDragging(false);
+ };
+
+ const thumbPosition = createMemo(() =>
+ getThresholdSliderPosition(props.value, props.min, props.max),
+ );
+ const thumbTransform = createMemo(() => getThresholdSliderThumbTransform(thumbPosition()));
+ const sliderTitle = createMemo(() => getThresholdSliderTitle(props.type, props.value));
+ const sliderLabel = createMemo(() => getThresholdSliderLabel(props.type, props.value));
+
+ const handleInput = (event: ThresholdSliderInputEvent) => {
+ props.onChange(parseInt(event.currentTarget.value, 10));
+ };
+
+ const handleInputWheel: JSX.EventHandlerUnion<
+ HTMLInputElement,
+ ThresholdSliderWheelEvent<HTMLInputElement>
+ > = (event) => {
+ if (!props.disabled) {
+ event.preventDefault();
+ }
+ };
+
+ const handleContainerWheel: JSX.EventHandlerUnion<
+ HTMLDivElement,
+ ThresholdSliderWheelEvent<HTMLDivElement>
+ > = (event) => {
+ if (!props.disabled && isDragging()) {
+ event.preventDefault();
+ }
+ };
+
+ const handleMouseDown = () => {
+ if (props.disabled) {
+ return;
+ }
+
+ clearDragLock();
+ setIsDragging(true);
+
+ const scrollY = window.scrollY;
+ const scrollX = window.scrollX;
+
+ const handleScroll = () => {
+ window.scrollTo(scrollX, scrollY);
+ };
+
+ const handleMouseUp = () => {
+ clearDragLock();
+ };
+
+ window.addEventListener('scroll', handleScroll, { capture: true });
+ document.addEventListener('mouseup', handleMouseUp);
+
+ releaseDragLock = () => {
+ window.removeEventListener('scroll', handleScroll, { capture: true });
+ document.removeEventListener('mouseup', handleMouseUp);
+ };
+ };
+
+ onCleanup(() => {
+ clearDragLock();
+ });
+
+ return {
+ handleContainerWheel,
+ handleInput,
+ handleInputWheel,
+ handleMouseDown: props.disabled ? undefined : handleMouseDown,
+ isDragging,
+ sliderLabel,
+ sliderTitle,
+ thumbPosition,
+ thumbTransform,
+ };
+}
diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
index e5fc14e554..561001247a 100644
--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
@@ -83,6 +83,8 @@ import dashboardFilterSource from '@/components/Dashboard/DashboardFilter.tsx?ra
import dashboardFilterModelSource from '@/components/Dashboard/dashboardFilterModel.ts?raw';
import dashboardStateSource from '@/components/Dashboard/useDashboardState.ts?raw';
import dashboardFilterStateSource from '@/components/Dashboard/useDashboardFilterState.ts?raw';
+import thresholdSliderModelSource from '@/components/Dashboard/thresholdSliderModel.ts?raw';
+import thresholdSliderStateSource from '@/components/Dashboard/useThresholdSliderState.ts?raw';
import workloadsSummarySource from '@/components/Workloads/WorkloadsSummary.tsx?raw';
import dashboardRouteSource from '@/pages/Dashboard.tsx?raw';
import dashboardHelpersSource from '@/pages/DashboardPanels/dashboardHelpers.ts?raw';
@@ -511,6 +513,17 @@ describe('frontend resource type boundaries', () => {
expect(dashboardStateSource).toContain('containerRuntimeFilterConfig');
expect(dashboardStateSource).toContain('hostFilterConfig');
expect(dashboardStateSource).toContain('namespaceFilterConfig');
+ expect(thresholdSliderSource).toContain('useThresholdSliderState');
+ expect(thresholdSliderSource).not.toContain('const [thumbPosition, setThumbPosition] =');
+ expect(thresholdSliderSource).not.toContain('const handleMouseDown = () => {');
+ expect(thresholdSliderSource).not.toContain('formatTemperature(');
+ expect(thresholdSliderStateSource).toContain('window.addEventListener');
+ expect(thresholdSliderStateSource).toContain('document.addEventListener');
+ expect(thresholdSliderStateSource).toContain('onCleanup');
+ expect(thresholdSliderModelSource).toContain('export function getThresholdSliderPosition');
+ expect(thresholdSliderModelSource).toContain('export function getThresholdSliderThumbTransform');
+ expect(thresholdSliderModelSource).toContain('export function getThresholdSliderTitle');
+ expect(thresholdSliderModelSource).toContain('export function getThresholdSliderLabel');
expect(workloadsSummarySource).toContain('normalizeOrgScope(getOrgID())');
expect(workloadsSummarySource).not.toContain("const DEFAULT_ORG_SCOPE = 'default'");
expect(workloadsSummarySource).not.toContain('const normalizeOrgScope =');
diff --git a/scripts/release_control/subsystem_lookup_test.py b/scripts/release_control/subsystem_lookup_test.py
index 35ac7794b7..a92ebcab79 100644
--- a/scripts/release_control/subsystem_lookup_test.py
+++ b/scripts/release_control/subsystem_lookup_test.py
@@ -1886,6 +1886,36 @@ class SubsystemLookupTest(unittest.TestCase):
match["verification_requirement"]["id"],
"dashboard-workload-hot-path",
)
+
+ def test_lookup_paths_assigns_dashboard_threshold_slider_runtime_to_performance_and_scalability(self) -> None:
+ result = lookup_paths(
+ [
+ "frontend-modern/src/components/Dashboard/ThresholdSlider.tsx",
+ "frontend-modern/src/components/Dashboard/thresholdSliderModel.ts",
+ "frontend-modern/src/components/Dashboard/useThresholdSliderState.ts",
+ ]
+ )
+ self.assertEqual(result["unowned_runtime_files"], [])
+ self.assertEqual(
+ {item["subsystem"] for item in result["impacted_subsystems"]},
+ {"performance-and-scalability"},
+ )
+ for file_entry in result["files"]:
+ self.assertEqual(file_entry["classification"], "runtime")
+ self.assertEqual(
+ {match["subsystem"] for match in file_entry["matches"]},
+ {"performance-and-scalability"},
+ )
+ match = file_entry["matches"][0]
+ self.assertEqual(
+ match["contract"],
+ "docs/release-control/v6/internal/subsystems/performance-and-scalability.md",
+ )
+ self.assertEqual(match["lane_context"]["lane_id"], "L10")
+ self.assertEqual(
+ match["verification_requirement"]["id"],
+ "dashboard-workload-hot-path",
+ )
self.assertEqual(
match["verification_requirement"]["id"],
"dashboard-workload-hot-path",