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

Make jsonapi local relationship always a resource #1320

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

paulfalgout
Copy link
Member

@paulfalgout paulfalgout commented Sep 18, 2024

Shortcut Story ID: [sc-55079]

This is potentially the final step, but we should be able to apply changes mostly without test updates until things are fixed.

We need to look for fooModel.get('_,... fooModel.set('_... and fooModel.set({ _... and make sure we're handling resources { id, type } and not just ids.

Summary by CodeRabbit

  • New Features

    • Enhanced relationship data structure to include both id and type for each item, improving clarity and detail in relationships.
  • Bug Fixes

    • Removed deprecated relationship parsing methods, streamlining the handling of relationships in the application.
  • Refactor

    • Simplified model and collection definitions by eliminating custom relationship parsing logic, potentially improving performance and maintainability.

Copy link

coderabbitai bot commented Sep 18, 2024

Walkthrough

The changes involve a significant refactoring of the relationship handling within the codebase. The JsonApiMixin and its associated _parseRelationship function have been removed from multiple files, including actions.js, flows.js, form-responses.js, and program-actions.js. The parseRelationship method has been updated in jsonapi-mixin.js to return a more detailed object for relationships, while its usage has been eliminated in other files, indicating a shift towards default behavior for relationship processing.

Changes

Files Change Summary
src/js/base/jsonapi-mixin.js Updated parseRelationship to return both id and type for relationship items.
src/js/entities-service/entities/actions.js Removed JsonApiMixin import and _parseRelationship function; parseRelationship method no longer used.
src/js/entities-service/entities/flows.js Removed JsonApiMixin import and _parseRelationship function; parseRelationship method no longer used.
src/js/entities-service/entities/form-responses.js Removed JsonApiMixin import and _parseRelationship function; parseRelationship method no longer defined.
src/js/entities-service/entities/program-actions.js Removed JsonApiMixin import and _parseRelationship function; parseRelationship method no longer defined.
src/js/entities-service/entities/program-flows.js Removed JsonApiMixin import and _parseRelationship function; parseRelationship method no longer defined.

Sequence Diagram(s)

sequenceDiagram
    participant A as Application
    participant B as jsonapi-mixin.js
    participant C as Model/Collection

    A->>B: Call parseRelationship(relationship)
    B->>B: Check relationship validity
    B-->>A: Return {id, type} for each relationship item
    A->>C: Process relationships with new structure
Loading

🐰 "In the code where rabbits play,
Relationships now find their way.
With id and type in a neat array,
We hop along, come what may!
No more mixins, just default sway,
Hooray for changes, hip-hip-hooray!" 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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 generate interesting stats about this repository and render them as a table.
    -- @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 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.

Copy link

cypress bot commented Sep 18, 2024

RoundingWell Care Ops Frontend    Run #6758

Run Properties:  status check failed Failed #6758  •  git commit 3f33279e68: Make jsonapi local relationship always a resource
Project RoundingWell Care Ops Frontend
Branch Review consistent-relationships
Run status status check failed Failed #6758
Run duration 03m 26s
Commit git commit 3f33279e68: Make jsonapi local relationship always a resource
Committer Paul Falgout
View all properties for this run ↗︎

Test results
Tests that failed  Failures 15
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 296
View all changes introduced in this branch ↗︎

Tests for review

Failed  patients/worklist/worklist.js • 2 failed tests • care-ops-e2e

View Output

Test Artifacts
worklist page > flow list Test Replay Screenshots
worklist page > action list Test Replay Screenshots
Failed  forms/action.js • 3 failed tests • care-ops-e2e

View Output

Test Artifacts
Patient Action Form > prefill a form with latest submission by flow Test Replay Screenshots
Patient Action Form > routing to form Test Replay Screenshots
Patient Action Form > submit and go back button Test Replay Screenshots
Failed  patients/patient/patient-flow.js • 2 failed tests • care-ops-e2e

View Output

Test Artifacts
patient flow page > flow progress bar Test Replay Screenshots
patient flow page > bulk edit actions Test Replay Screenshots
Failed  patients/worklist/schedule.js • 1 failed test • care-ops-e2e

View Output

Test Artifacts
schedule page > display schedule Test Replay Screenshots
Failed  programs/sidebar/action-sidebar.js • 1 failed test • care-ops-e2e

View Output

Test Artifacts
program action sidebar > display new action sidebar Test Replay Screenshots

The first 5 failed specs are shown, see all 11 specs in Cypress Cloud.

Flakiness  test/integration/forms/form.js • 1 flaky test • care-ops-e2e

View Output

Test Artifacts
Noncontext Form > update patient field Test Replay Screenshots

Copy link

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cc37026 and 3f33279.

Files selected for processing (6)
  • src/js/base/jsonapi-mixin.js (1 hunks)
  • src/js/entities-service/entities/actions.js (0 hunks)
  • src/js/entities-service/entities/flows.js (0 hunks)
  • src/js/entities-service/entities/form-responses.js (0 hunks)
  • src/js/entities-service/entities/program-actions.js (0 hunks)
  • src/js/entities-service/entities/program-flows.js (0 hunks)
Files not reviewed due to no reviewable changes (5)
  • src/js/entities-service/entities/actions.js
  • src/js/entities-service/entities/flows.js
  • src/js/entities-service/entities/form-responses.js
  • src/js/entities-service/entities/program-actions.js
  • src/js/entities-service/entities/program-flows.js
Additional comments not posted (1)
src/js/base/jsonapi-mixin.js (1)

25-25: LGTM!

The consolidation of the initial checks for the relationship parameter into a single conditional statement improves code readability and maintainability without altering the functionality.


return map(relationship, item => {
const itemRelationship = { id: item.id };
const itemRelationship = { id: item.id, type: item.type };
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Approve the change, but ensure comprehensive testing and updates.

The modification to include both id and type for each item in the relationship array aligns with the existing pattern of using underscore-prefixed properties for relationships in the codebase. This change enhances the data structure and provides more detailed representation of relationship items.

However, given the widespread use of underscore-prefixed properties across various components and files, it's crucial to:

  1. Thoroughly test the impact of this change on all parts of the application that interact with relationship objects.
  2. Update any code that may be expecting only the id in the relationship object to now handle both id and type.
  3. Pay special attention to instances of fooModel.get('_,..., fooModel.set('_..., and fooModel.set({ _... as mentioned in the PR description, and ensure they correctly handle the new structure.

While the change is approved, it's important to proceed with caution and ensure that all affected parts of the codebase are updated and tested accordingly.

Analysis chain

Verify the impact of the relationship object structure change.

The modification to include both id and type for each item in the relationship array aligns with the PR objective of treating local relationships as resources. This change enhances the data structure returned for relationships, providing more detailed representation of the relationship items.

Please ensure that the rest of the codebase is updated to handle the new structure of the relationship objects. Pay special attention to instances of fooModel.get('_,..., fooModel.set('_..., and fooModel.set({ _... as mentioned in the PR description.

Run the following script to verify the usage of the _ prefixed properties:


These new scripts should help us gather more comprehensive information about the usage of underscore-prefixed properties and model structures in the codebase. This will allow us to better assess the impact of the relationship object structure change.


These corrected scripts should now execute without syntax errors and provide us with the necessary information to assess the impact of the relationship object structure change on the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `_` prefixed properties in the codebase.

# Test 1: Search for `fooModel.get('_,...` usage. 
# Expect: Review the results to ensure they handle the new relationship object structure.
rg --type js -A 5 $'fooModel\.get\(\'_'

# Test 2: Search for `fooModel.set('_...` usage.
# Expect: Review the results to ensure they handle the new relationship object structure.
rg --type js -A 5 $'fooModel\.set\(\'_'

# Test 3: Search for `fooModel.set({ _...` usage.
# Expect: Review the results to ensure they handle the new relationship object structure.
rg --type js -A 5 $'fooModel\.set\(\{ _'

Length of output: 127


Script:

#!/bin/bash
# Description: Perform a broader search for usage of underscore-prefixed properties and model definitions

# Test 1: Search for any .get('_ usage
echo "Searching for .get('_ usage:"
rg --type js -A 3 '\.get\(\'_'

# Test 2: Search for any .set('_ usage
echo "Searching for .set('_ usage:"
rg --type js -A 3 '\.set\(\'_'

# Test 3: Search for any ._someProperty usage
echo "Searching for ._someProperty usage:"
rg --type js -A 3 '\._\w+'

# Test 4: Search for model definitions or imports
echo "Searching for model definitions or imports:"
rg --type js -A 3 '(class\s+\w+Model|import.*Model)'

# Test 5: Search for any usage of underscore-prefixed properties in object literals
echo "Searching for underscore-prefixed properties in object literals:"
rg --type js -A 3 '\{\s*_\w+:'

Length of output: 682


Script:

#!/bin/bash
# Description: Perform a broader search for usage of underscore-prefixed properties and model definitions (corrected version)

# Test 1: Search for any .get('_ usage
echo "Searching for .get('_ usage:"
rg --type js -A 3 "\.get\('_"

# Test 2: Search for any .set('_ usage
echo "Searching for .set('_ usage:"
rg --type js -A 3 "\.set\('_"

# Test 3: Search for any ._someProperty usage
echo "Searching for ._someProperty usage:"
rg --type js -A 3 "\._\w+"

# Test 4: Search for model definitions or imports
echo "Searching for model definitions or imports:"
rg --type js -A 3 "class\s+\w+Model"
rg --type js -A 3 "import.*Model"

# Test 5: Search for any usage of underscore-prefixed properties in object literals
echo "Searching for underscore-prefixed properties in object literals:"
rg --type js -A 3 "\{\s*_\w+:"

Length of output: 91518

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