From 0e5ff9b7b7dbaea1100a81aeb9db8abcd9bed0a5 Mon Sep 17 00:00:00 2001 From: Chris Farhood Date: Thu, 12 Feb 2026 12:23:33 -0500 Subject: [PATCH] fix: add explicit GET method to API requests and make refresh interval reactive - Add explicit method: 'GET' to ApiProxy.request() calls in polaris.ts and PolarisSettings.tsx for compatibility with Headlamp SDK - Make refresh interval reactive by polling localStorage every second in PolarisDataContext so settings changes take effect immediately without page reload Fixes connection test button and data refresh issues. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- src/api/PolarisDataContext.tsx | 16 ++++++++++++++-- src/api/polaris.ts | 4 +++- src/components/PolarisSettings.tsx | 4 +++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/api/PolarisDataContext.tsx b/src/api/PolarisDataContext.tsx index 7d510ad..d943a98 100644 --- a/src/api/PolarisDataContext.tsx +++ b/src/api/PolarisDataContext.tsx @@ -35,8 +35,20 @@ const PolarisDataContext = React.createContext(n * ``` */ export function PolarisDataProvider(props: { children: React.ReactNode }) { - const interval = getRefreshInterval(); - const state = usePolarisData(interval); + // Re-read interval on every render to pick up changes from settings + const [refreshInterval, setRefreshInterval] = React.useState(getRefreshInterval()); + + // Poll for interval changes (localStorage changes from settings) + React.useEffect(() => { + const intervalId = window.setInterval(() => { + const newInterval = getRefreshInterval(); + setRefreshInterval(prev => (prev !== newInterval ? newInterval : prev)); + }, 1000); // Check every second + + return () => window.clearInterval(intervalId); + }, []); + + const state = usePolarisData(refreshInterval); // Rename triggerRefresh to refresh for consistency const value = React.useMemo( diff --git a/src/api/polaris.ts b/src/api/polaris.ts index 12bb833..5bf8656 100644 --- a/src/api/polaris.ts +++ b/src/api/polaris.ts @@ -373,7 +373,9 @@ export function usePolarisData(refreshIntervalSeconds: number): PolarisDataState result = await response.json(); } else { // Kubernetes proxy for relative URLs - result = await ApiProxy.request(apiPath); + result = await ApiProxy.request(apiPath, { + method: 'GET', + }); } if (!cancelled) { diff --git a/src/components/PolarisSettings.tsx b/src/components/PolarisSettings.tsx index 907d8c3..445c5a9 100644 --- a/src/components/PolarisSettings.tsx +++ b/src/components/PolarisSettings.tsx @@ -58,7 +58,9 @@ export default function PolarisSettings(props: PluginSettingsProps) { } result = await response.json(); } else { - result = await ApiProxy.request(apiPath); + result = await ApiProxy.request(apiPath, { + method: 'GET', + }); } setTestResult({