Skip to content

Conversation

@robertherber
Copy link
Member

@robertherber robertherber commented Apr 18, 2025

Allow any events starting with the specified activityName

Summary by CodeRabbit

  • New Features

    • Introduced support for multiple action types within a single shield action, including setting badge counts, managing notifications, and enhanced whitelist operations.
    • Added the ability to handle grouped actions and pass contextual placeholders for more dynamic action handling.
  • Improvements

    • Broadened event filtering logic to include more relevant keys.
    • Enhanced action handling for greater flexibility and extensibility.
  • Bug Fixes

    • Updated action type naming for consistency.
  • Chores

    • Updated package version to 0.4.28.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 18, 2025

Walkthrough

This update introduces a new executeGenericAction function to centralize and standardize the handling of various action types within the iOS implementation of the react-native-device-activity package. The ShieldAction type system is expanded in TypeScript to support new action variants and an array-based grouping of actions. The iOS extensions are refactored to use the new generic action execution, with placeholder support for contextual information. The filtering logic for events is slightly broadened, and the package version is incremented.

Changes

File(s) Change Summary
packages/react-native-device-activity/ios/Shared.swift Added executeGenericAction function to handle a broad set of action types, supporting delays, notifications, badge counts, HTTP requests, whitelist/blocklist management, and placeholder replacement.
packages/react-native-device-activity/targets/ActivityMonitorExtension/DeviceActivityMonitorExtension.swift Removed the old executeAction function; updated executeActionsForEvent to use executeGenericAction and renamed a local variable for clarity. Added import for NotificationCenter.
packages/react-native-device-activity/targets/ShieldAction/ShieldActionExtension.swift Renamed handleAction to handleShieldAction and added a placeholders parameter. Updated to process an array of actions and use executeGenericAction for each. Enhanced the caller to construct and pass contextual placeholders. Changed the whitelist action type string.
packages/react-native-device-activity/src/ReactNativeDeviceActivity.types.ts Refactored the ShieldAction type: deprecated the single type property, added an actions array, and introduced new action types such as badge count management and notification removals. Renamed "whitelistCurrent" to "addCurrentToWhitelist". Extended sendHttpRequest action.
packages/react-native-device-activity/ios/ReactNativeDeviceActivityModule.swift Modified event filtering logic in getEvents to broaden matches for activityName by removing a trailing underscore from the prefix.
packages/react-native-device-activity/package.json Updated package version from 0.4.24 to 0.4.28.

Sequence Diagram(s)

sequenceDiagram
    participant JS as React Native JS
    participant Swift as iOS Native (Swift)
    participant Ext as DeviceActivity/ShieldAction Extension

    JS->>Swift: Dispatch ShieldAction (with actions array)
    Swift->>Ext: handleShieldAction(config, placeholders, tokens)
    loop For each action in config["actions"]
        Ext->>Swift: executeGenericAction(action, placeholders, tokens)
        Swift-->>Ext: (Performs action: badge, notification, HTTP, etc.)
    end
    Ext-->>Swift: ShieldActionResponse
    Swift-->>JS: Result/Completion
Loading

Possibly related PRs

Suggested reviewers

  • mfazekas

Poem

In the warren where code bunnies dwell,
We refactor and tidy, and do it quite well!
Actions now generic, with placeholders in tow,
Shielding and whitelisting with a broader flow.
Typescript and Swift, in harmony sing—
A hop, a skip, and a version bump—spring!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/react-native-device-activity/src/ReactNativeDeviceActivity.types.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "universe/native" to extend from. Please check that the name of the config is correct.

The config "universe/native" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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.
  • @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 to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Apr 18, 2025

Open in StackBlitz

npm i https://pkg.pr.new/kingstinct/react-native-device-activity@55

commit: fe4855e

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: 7

🔭 Outside diff range comments (1)
packages/react-native-device-activity/targets/ShieldAction/ShieldActionExtension.swift (1)

136-153: 🛠️ Refactor suggestion

Duplicate implementation – consolidate with executeGenericAction

The "addCurrentToWhitelist" logic is now implemented both here and inside executeGenericAction, risking divergence.

Prefer calling executeGenericAction (or deleting this branch) to keep behaviour in one place.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c119e34 and 467e642.

📒 Files selected for processing (6)
  • packages/react-native-device-activity/ios/ReactNativeDeviceActivityModule.swift (1 hunks)
  • packages/react-native-device-activity/ios/Shared.swift (1 hunks)
  • packages/react-native-device-activity/package.json (1 hunks)
  • packages/react-native-device-activity/src/ReactNativeDeviceActivity.types.ts (3 hunks)
  • packages/react-native-device-activity/targets/ActivityMonitorExtension/DeviceActivityMonitorExtension.swift (4 hunks)
  • packages/react-native-device-activity/targets/ShieldAction/ShieldActionExtension.swift (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/react-native-device-activity/targets/ActivityMonitorExtension/DeviceActivityMonitorExtension.swift (1)
packages/react-native-device-activity/ios/Shared.swift (1)
  • executeGenericAction (100-246)
packages/react-native-device-activity/ios/Shared.swift (1)
packages/react-native-device-activity/src/index.ts (9)
  • updateShield (569-584)
  • blockSelection (424-436)
  • unblockSelection (450-462)
  • addSelectionToWhitelistAndUpdateBlock (135-147)
  • removeSelectionFromWhitelistAndUpdateBlock (149-161)
  • clearWhitelist (105-107)
  • resetBlocks (446-448)
  • disableBlockAllMode (442-444)
  • enableBlockAllMode (438-440)
packages/react-native-device-activity/targets/ShieldAction/ShieldActionExtension.swift (1)
packages/react-native-device-activity/ios/Shared.swift (1)
  • executeGenericAction (100-246)
🔇 Additional comments (8)
packages/react-native-device-activity/package.json (1)

3-3: Version bump from 0.4.24 to 0.4.28

This version increase corresponds with the significant changes to the action system in this PR, including the introduction of the generic action execution function and new shield action types.

packages/react-native-device-activity/ios/ReactNativeDeviceActivityModule.swift (1)

356-356: Broadening event filtering logic

The filtering criteria has been relaxed to match any keys that start with the activityName, rather than requiring an exact format with a trailing underscore. This aligns with the PR objective to make event filtering less restrictive.

packages/react-native-device-activity/targets/ActivityMonitorExtension/DeviceActivityMonitorExtension.swift (3)

12-12: Added NotificationCenter import

Added import for NotificationCenter which is required for the notification functionality used with the new action system.


57-58: Improved variable naming

Renamed variable from key to triggeredBy which better describes its purpose and improves code readability.


103-107: Migrated to centralized action execution

Replaced the specialized executeAction function with the new centralized executeGenericAction function from Shared.swift. This refactoring improves code maintainability and allows for a more consistent handling of actions across the codebase.

packages/react-native-device-activity/src/ReactNativeDeviceActivity.types.ts (3)

163-163: Renamed action type for clarity

Changed "whitelistCurrent" to "addCurrentToWhitelist" for improved clarity and consistency with other action naming conventions.


173-174: Enhanced ShieldAction with multi-action support

Deprecated the single type property in favor of an array-based actions property. This provides greater flexibility by allowing multiple sequential actions to be defined within a single ShieldAction.

Also applies to: 182-182


272-289: Added new action types for enhanced functionality

Extended the Action union type with several new capabilities:

  • Badge count management
  • Notification request handling
  • Whitelist management

These additions align with the enhanced generic action execution functionality implemented in the iOS native code.

@robertherber robertherber changed the title Make get events less restrictive Make getEvents less restrictive Apr 22, 2025
@robertherber robertherber merged commit 1280393 into main Apr 22, 2025
11 checks passed
@robertherber robertherber deleted the make-getEvents-less-restrictive branch April 22, 2025 16:12
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.

2 participants