Skip to content

feat: add global auto-refresh for monitors - #786

Open
lokiee0 wants to merge 7 commits into
rajnandan1:mainfrom
lokiee0:feature/auto-refresh-v4
Open

feat: add global auto-refresh for monitors#786
lokiee0 wants to merge 7 commits into
rajnandan1:mainfrom
lokiee0:feature/auto-refresh-v4

Conversation

@lokiee0

@lokiee0 lokiee0 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds a global auto-refresh option to the public status page.

Users can enable or disable auto-refresh, configure the refresh interval, and the selected settings are saved locally so they persist across page reloads.

Changes

  • Added a global auto-refresh control to the toolbar
  • Added configurable refresh interval
  • Persist refresh settings using localStorage
  • Refresh page data using invalidateAll()
  • Prevent overlapping refresh requests
  • Added English and Brazilian Portuguese translations

Testing

  • npm run check
  • npm run build
  • Verified auto-refresh works in the browser
  • Verified enable/disable
  • Verified settings persist after reload
  • Verified no duplicate refresh timers

Related to #533.

Summary by CodeRabbit

  • New Features
    • Added configurable global auto-refresh for application data from the main layout.
    • Users can enable/disable auto-refresh and choose an interval (bounded from 5 seconds to 24 hours).
    • Added auto-refresh controls to the top navigation, including an active-state indicator and interval input; settings persist between visits.
  • Documentation
    • Added English and Brazilian Portuguese translations for the auto-refresh controls and interval options.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 55e4e497-a4ae-4057-bd46-601da3771c63

📥 Commits

Reviewing files that changed from the base of the PR and between 83f8df5 and 1e9b7b6.

📒 Files selected for processing (3)
  • src/lib/client/types/refresh.ts
  • src/lib/stores/refreshStore.ts
  • src/routes/(kener)/+layout.svelte

📝 Walkthrough

Walkthrough

Adds app-wide auto-refresh with persisted interval and enablement settings, a navigation popover for refresh controls, a refresh store, and English and Portuguese localization entries.

Changes

Auto-refresh controls

Layer / File(s) Summary
Refresh state contract
src/lib/client/types/refresh.ts, src/lib/stores/refreshStore.ts
Defines refresh state, interval bounds, defaults, and methods for updating, resetting, and recording refresh state.
Global refresh lifecycle
src/routes/(kener)/+layout.svelte
Restores persisted settings, schedules guarded invalidateAll() calls, updates refresh state, and cleans up the timer on unmount.
Navigation controls and localization
src/lib/components/KenerNav.svelte, src/routes/(kener)/+layout.svelte, src/lib/locales/en.json, src/lib/locales/pt-BR.json
Adds an optional navigation controls snippet, renders the auto-refresh popover, preserves mobile navigation behavior, and adds localized control labels.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant KenerNav
  participant KenerLayout
  participant refreshStore
  participant AppData
  User->>KenerNav: Open auto-refresh controls
  KenerNav->>KenerLayout: Render refreshControls snippet
  User->>KenerLayout: Set interval or enable refresh
  KenerLayout->>refreshStore: Update refresh settings
  KenerLayout->>AppData: invalidateAll()
  AppData-->>KenerLayout: Refresh completed
  KenerLayout->>refreshStore: Record last refresh
Loading

Suggested reviewers: rajnandan1, kukks

Poem

A rabbit taps refresh with care,
Settings hop through stored-up air.
The nav now holds a handy nest,
Fresh data visits every quest.
English, Portuguese bells ring—
Hop along with everything!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding global auto-refresh behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a global auto-refresh control to the public status page navbar, allowing users to enable periodic data reloads via invalidateAll() at a configurable interval (5 s – 24 h) that persists in localStorage.

  • Timer management: onMount restores saved settings and starts/stops a window.setInterval; the cleanup return value (stopGlobalRefresh) is correctly wired so the timer is cleared on component teardown.
  • Overlap prevention: refreshInProgress guards against concurrent invalidateAll() calls from back-to-back interval ticks.
  • KenerNav extension: The nav component now accepts an optional controls Snippet prop rendered before the mobile dropdown, keeping the change non-breaking for other consumers.

Confidence Score: 5/5

Safe to merge; the timer lifecycle and overlap-prevention logic are correct, and the change is additive with no modifications to existing data paths.

The auto-refresh feature is self-contained: it adds a UI control, a small store, and a timer loop that calls the standard SvelteKit invalidateAll(). The timer is properly cleaned up on unmount, concurrent refreshes are guarded, and the nav change is backward-compatible.

The error toast in +layout.svelte and both locale files (en.json, pt-BR.json) are missing the 'Failed to refresh page data' translation key.

Important Files Changed

Filename Overview
src/routes/(kener)/+layout.svelte Adds auto-refresh logic via onMount with localStorage persistence and timer management; missing translation key for the error toast
src/lib/stores/refreshStore.ts New Svelte 4-style writable store for refresh state; uses legacy pattern instead of Svelte 5 runes recommended by CLAUDE.md
src/lib/client/types/refresh.ts Simple type definition for RefreshState; straightforward and correct
src/lib/components/KenerNav.svelte Accepts an optional controls Snippet prop and renders it before the mobile nav; clean, minimal change
src/lib/locales/en.json Adds six new translation keys for auto-refresh UI; missing the error toast key 'Failed to refresh page data'
src/lib/locales/pt-BR.json Adds Brazilian Portuguese translations for new auto-refresh keys; also missing the error toast key

Reviews (5): Last reviewed commit: "Merge branch 'main' into feature/auto-re..." | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/components/KenerNav.svelte`:
- Line 12: Update the `controls` prop declaration in `KenerNav.svelte` to use a
type-only `Snippet` import from `svelte` instead of the inline
`import("svelte").Snippet` type. Preserve the optional prop and existing
`Snippet` typing.

In `@src/lib/stores/refreshStore.ts`:
- Around line 9-12: Define and export a shared default refresh-interval constant
alongside defaultState in refreshStore.ts, then replace the store’s hardcoded
30-second reset value and the layout’s 60-second initialization/fallback values
with that constant so all default refresh behavior stays consistent.

In `@src/routes/`(kener)/+layout.svelte:
- Around line 63-67: The refresh interval handling in +layout.svelte only
enforces a minimum and must also cap values below the browser timer limit. Apply
the same maximum normalization when loading and saving the interval, and
configure the corresponding input with that identical max while preserving the
existing minimum and refreshStore updates.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: eb90f2ae-699b-4301-bffc-e3ea8ed052a7

📥 Commits

Reviewing files that changed from the base of the PR and between e5b745e and 7324c9e.

📒 Files selected for processing (8)
  • src/lib/components/KenerNav.svelte
  • src/lib/components/ui/chart/chart-container.svelte
  • src/lib/components/ui/toggle-group/toggle-group.svelte
  • src/lib/locales/en.json
  • src/lib/locales/pt-BR.json
  • src/lib/server/dns.ts
  • src/lib/stores/refreshStore.ts
  • src/routes/(kener)/+layout.svelte

Comment thread src/lib/components/KenerNav.svelte Outdated
Comment thread src/lib/stores/refreshStore.ts
Comment thread src/routes/(kener)/+layout.svelte Outdated
@lokiee0
lokiee0 force-pushed the feature/auto-refresh-v4 branch from 7324c9e to da56cc3 Compare July 13, 2026 17:46
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
putComment timed out

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/stores/refreshStore.ts`:
- Around line 3-7: Move the client-only RefreshState type from refreshStore.ts
into the established src/lib/client/types/ location, then import and use that
type in the refresh store. Preserve its existing enabled, interval, and
lastRefresh fields and avoid leaving a duplicate inline definition.

In `@src/routes/`(kener)/+layout.svelte:
- Around line 34-47: The refreshPageData error handler currently logs failures
without notifying the user. Update the catch block to use the existing
Toaster/sonner integration to display a visible refresh-failure notification,
while retaining the console error and existing refreshInProgress cleanup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9264c516-6041-49ae-95ef-67b59853cd43

📥 Commits

Reviewing files that changed from the base of the PR and between 7324c9e and da56cc3.

📒 Files selected for processing (5)
  • src/lib/components/KenerNav.svelte
  • src/lib/locales/en.json
  • src/lib/locales/pt-BR.json
  • src/lib/stores/refreshStore.ts
  • src/routes/(kener)/+layout.svelte

Comment thread src/lib/stores/refreshStore.ts Outdated
Comment thread src/routes/(kener)/+layout.svelte

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
src/lib/stores/refreshStore.ts (1)

7-14: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Still unresolved: RefreshState should live in src/lib/client/types/.

This client-only type remains inline despite the prior review flagging it. As per coding guidelines, "Place shared types (used by both client and server) in src/lib/types/, server-only types in src/lib/server/types/, and client-only types in src/lib/client/types/."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/stores/refreshStore.ts` around lines 7 - 14, Move the client-only
RefreshState type from refreshStore.ts into src/lib/client/types/, then import
and reuse it in the refresh store while preserving its existing fields and
behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@src/lib/stores/refreshStore.ts`:
- Around line 7-14: Move the client-only RefreshState type from refreshStore.ts
into src/lib/client/types/, then import and reuse it in the refresh store while
preserving its existing fields and behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1f451f64-b71f-47a5-b089-bf8dde09e3b5

📥 Commits

Reviewing files that changed from the base of the PR and between da56cc3 and 83f8df5.

📒 Files selected for processing (3)
  • src/lib/components/KenerNav.svelte
  • src/lib/stores/refreshStore.ts
  • src/routes/(kener)/+layout.svelte

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant