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 <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -35,8 +35,20 @@ const PolarisDataContext = React.createContext<PolarisDataContextValue | null>(n
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function PolarisDataProvider(props: { children: React.ReactNode }) {
|
export function PolarisDataProvider(props: { children: React.ReactNode }) {
|
||||||
const interval = getRefreshInterval();
|
// Re-read interval on every render to pick up changes from settings
|
||||||
const state = usePolarisData(interval);
|
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
|
// Rename triggerRefresh to refresh for consistency
|
||||||
const value = React.useMemo(
|
const value = React.useMemo(
|
||||||
|
|||||||
+3
-1
@@ -373,7 +373,9 @@ export function usePolarisData(refreshIntervalSeconds: number): PolarisDataState
|
|||||||
result = await response.json();
|
result = await response.json();
|
||||||
} else {
|
} else {
|
||||||
// Kubernetes proxy for relative URLs
|
// Kubernetes proxy for relative URLs
|
||||||
result = await ApiProxy.request(apiPath);
|
result = await ApiProxy.request(apiPath, {
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
|
|||||||
@@ -58,7 +58,9 @@ export default function PolarisSettings(props: PluginSettingsProps) {
|
|||||||
}
|
}
|
||||||
result = await response.json();
|
result = await response.json();
|
||||||
} else {
|
} else {
|
||||||
result = await ApiProxy.request(apiPath);
|
result = await ApiProxy.request(apiPath, {
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setTestResult({
|
setTestResult({
|
||||||
|
|||||||
Reference in New Issue
Block a user