Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

565 exemplarische offline fähigkeit #806

Closed
wants to merge 50 commits into from

Conversation

vjohnslhm
Copy link
Contributor

@vjohnslhm vjohnslhm commented Feb 11, 2025

Beschreibung:

  • Service Worker aus dem Altsystem hinzugefügt und entsprechend für die Anwendung angepasst
  • WLS-heartbeat integriert

Definition of Done (DoD):

Dokumentation

  • Links geprüft

Frontend

Referenzen1:

Closes #565

Summary by CodeRabbit

  • New Features
    • Introduced a real-time connectivity indicator with updated visual cues to clearly show online/offline status.
    • Enhanced offline support and caching by integrating robust service worker functionality for a smoother Progressive Web App experience.
    • Streamlined background data retrieval for user authentication to help ensure a more responsive interface.

Footnotes

  1. Nicht zutreffende Referenzen vor dem Speichern entfernen

@vjohnslhm vjohnslhm added the service-gui-wls frontend related issues label Feb 11, 2025
@vjohnslhm vjohnslhm self-assigned this Feb 11, 2025
@vjohnslhm vjohnslhm linked an issue Feb 11, 2025 that may be closed by this pull request
3 tasks
Copy link
Contributor

coderabbitai bot commented Feb 11, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes span several areas of the codebase. The PR updates the .gitignore to exclude build and cache directories. Both H2 and Oracle SQL scripts are modified to update the user PIN field for dummy user entries. The package.json file is expanded with new scripts, dependencies, and dev dependencies that support PWA features and offline operations. In the Vue application, a heartbeat component is introduced along with functions to manage connectivity status, including retrieving user data and communicating with the service worker. A new composable is provided for interval-based operations. The Vuetify configuration is updated with additional icons for online/offline indicators. A comprehensive service worker script is added to handle caching, process GET and POST requests, and manage request routing. Finally, the Vite configuration is updated with the VitePWA plugin to enable auto-updating of the service worker and previewing of the built application.

Assessment against linked issues

Objective Addressed Explanation
Service Worker implementation for offline usage (#565)
Offline operability of the application (#565) Components and connectivity checks support offline usage.
Automatic synchronization of cached data when connectivity is restored (#565) No explicit mechanism for syncing cached offline data is evident.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or `` to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or `` anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (9)
wls-gui-wahllokalsystem/vite.config.ts (1)

33-52: Populate the PWA information for better user experience.

The manifest currently has limited information such as an empty description and icons. Consider expanding these fields (icons, background_color, etc.) to provide a complete PWA experience for users.

 manifest: {
   name: "Wahllokalsystem",
   short_name: "WLS",
-  description: "",
+  description: "Offline-enabled Wahllokalsystem application",
   theme_color: "#546e7a",
   display: "standalone",
-  icons: [],
+  icons: [
+    {
+      src: "icons/android-chrome-192x192.png",
+      sizes: "192x192",
+      type: "image/png"
+    },
+    ...
+  ],
 },
wls-gui-wahllokalsystem/src/wahl-worker.js (5)

1-6: Pin library versions and handle potential runtime failures.

While imports for crypto-js, localforage, and workbox modules are straightforward, pinning exact versions in package.json and handling possible missing/failed imports can improve reliability.


37-41: Avoid verbose logging in production.

doLog is set to true, which may clutter logs and potentially reveal sensitive workflow details in production. Consider toggling this flag off in production builds or providing a config-based approach.

-const doLog = true;
+const doLog = process.env.NODE_ENV !== 'production';

83-89: Ensure secure handling of PIN.

The PIN is assigned to self.pin and persisted in IndexedDB. Confirm that this approach meets security requirements, as the PIN is a key part of the encryption process. Consider ephemeral or session-based usage if feasible.


91-101: Caution with skipWaiting().

Calling skipWaiting() immediately activates the new worker, potentially serving old pages with the new worker. Ensure this won't break backward compatibility for pages loaded under the old worker. If uncertain, consider removing or gating skipWaiting() behind user acceptance.


384-408: Consider using a salt/IV for encryption.

The current AES encryption approach uses only the PIN, which may be predictable or reused across sessions. For stronger security, consider salting or using unique IVs to enhance encryption strength against potential replay or dictionary attacks.

wls-gui-wahllokalsystem/src/composables/useInterval.ts (1)

6-28: Add an optional immediate-invoke feature.

Some intervals benefit from running the callback immediately before the first setInterval tick. An optional parameter could help. E.g.:

 export function useInterval(callback: () => void, delay: number, immediate = false) {
   const intervalId = ref<null | number>(null);

   const start = () => {
     if (intervalId.value === null) {
+      if (immediate) callback();
       intervalId.value = window.setInterval(callback, delay);
     }
   };
wls-gui-wahllokalsystem/src/components/wlscomponents/WlsHeartbeat.vue (1)

44-46: Consider making the heartbeat interval configurable.

The 30-second interval is hardcoded. Consider making it configurable through props or environment variables.

+const props = defineProps({
+  isOffline: { type: Boolean, default: false },
+  heartbeatInterval: { type: Number, default: 30000 }
+});

-}, 30000); // updates every 30 seconds
+}, props.heartbeatInterval);
wls-gui-wahllokalsystem/package.json (1)

21-23: Lock dependency versions for better stability.

Using caret (^) ranges for dependencies can lead to unexpected updates. Consider locking the versions for better stability and reproducible builds.

-    "axios": "^1.7.9",
-    "crypto-js": "^4.2.0",
-    "localforage": "^1.10.0",
+    "axios": "1.7.9",
+    "crypto-js": "4.2.0",
+    "localforage": "1.10.0",
-    "@types/crypto-js": "^4.2.2",
+    "@types/crypto-js": "4.2.2",
-    "vite-plugin-pwa": "^0.21.1",
+    "vite-plugin-pwa": "0.21.1",
-    "workbox-core": "^7.3.0",
-    "workbox-precaching": "^7.3.0",
-    "workbox-routing": "^7.3.0",
-    "workbox-strategies": "^7.3.0"
+    "workbox-core": "7.3.0",
+    "workbox-precaching": "7.3.0",
+    "workbox-routing": "7.3.0",
+    "workbox-strategies": "7.3.0"

Also applies to: 34-34, 48-48, 52-55

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c522048 and 904ad3c.

⛔ Files ignored due to path filters (1)
  • wls-gui-wahllokalsystem/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (10)
  • .gitignore (1 hunks)
  • wls-auth-service/src/main/resources/db/dummydata/h2/R__updateDummyUserWithPin.sql (1 hunks)
  • wls-auth-service/src/main/resources/db/dummydata/oracle/R__updateDummyUserWithPin.sql (1 hunks)
  • wls-gui-wahllokalsystem/package.json (3 hunks)
  • wls-gui-wahllokalsystem/src/App.vue (4 hunks)
  • wls-gui-wahllokalsystem/src/components/wlscomponents/WlsHeartbeat.vue (1 hunks)
  • wls-gui-wahllokalsystem/src/composables/useInterval.ts (1 hunks)
  • wls-gui-wahllokalsystem/src/plugins/vuetify.ts (2 hunks)
  • wls-gui-wahllokalsystem/src/wahl-worker.js (1 hunks)
  • wls-gui-wahllokalsystem/vite.config.ts (3 hunks)
✅ Files skipped from review due to trivial changes (3)
  • wls-auth-service/src/main/resources/db/dummydata/oracle/R__updateDummyUserWithPin.sql
  • wls-auth-service/src/main/resources/db/dummydata/h2/R__updateDummyUserWithPin.sql
  • .gitignore
🔇 Additional comments (6)
wls-gui-wahllokalsystem/vite.config.ts (2)

6-6: Validate compatibility of the vite-plugin-pwa version.

It's great to see the PWA plugin integrated. However, ensure that the installed version is compatible with the current Vite version and any other associated configuration or dependencies.

Would you like a script to check the installed version of vite-plugin-pwa in your package.json and confirm it against npm?


65-68: Preview environment configuration.

Defining the same port for both dev server and preview can be convenient. Just confirm there's no conflict when the dev server is still running. If you need them running concurrently, consider using a different port for preview to avoid collisions.

wls-gui-wahllokalsystem/src/wahl-worker.js (2)

75-77: Validate concurrency for shared self.state.

Storing state and isOnline in the service worker global scope works well if there's only one controlling worker. However, if multiple tabs or complex concurrency scenarios exist, double-check that toggling these variables won’t introduce race conditions or inconsistent states across tabs.


107-120: Offline-first routes look well-designed.

The GET and POST request handling, caching, and fallback logic are comprehensive, covering both online-first and offline scenarios. Just remain alert to large payloads or repeated writes to the IDB, particularly under poor network conditions.

Also applies to: 125-129

wls-gui-wahllokalsystem/src/composables/useInterval.ts (1)

1-3: Well-structured composable.

The imports and function declaration follow Vue 3 best practices, making the composable easy to integrate.

wls-gui-wahllokalsystem/src/plugins/vuetify.ts (1)

3-9: LGTM!

The addition of online/offline status icons aligns well with the offline capabilities feature.

Also applies to: 21-22

@vjohnslhm vjohnslhm marked this pull request as draft February 11, 2025 14:27
@vjohnslhm
Copy link
Contributor Author

änderungen werden auf neuem branch in pr #830 gemerged, daher geschlossen

@vjohnslhm vjohnslhm closed this Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service-gui-wls frontend related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exemplarische Offline-Fähigkeit
1 participant