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

Organisation model update #2739

Open
wants to merge 4 commits into
base: develop-postgres
Choose a base branch
from

Conversation

MohitMaulekhi
Copy link
Contributor

@MohitMaulekhi MohitMaulekhi commented Feb 17, 2025

What kind of change does this PR introduce?

Bug fix, model updates, and query updates for organizations.

Issue Number:

Fixes #2734

Snapshots/Videos:

WhatsApp.Video.2025-02-17.at.9.43.09.AM.mp4

Summary

This pull request addresses an existing problem by fixing bugs and updating models and queries related to organizations. It aims to improve the interaction with organization-related features in the app.

Does this PR introduce a breaking change?

No

Other information

The backend currently lacks the following capabilities:

  1. Membership Requests
  2. Fetching all organizations
  3. Accesing creator info while logging in with user as regular role

As discussed on Slack, these features need to be implemented in the app. For now, only users who have joined an organization can interact with organization-related features.

The aforementioned capabilities need to be first handled in the API and then in the admin panel to allow implementation in the app. Some test cases were also commented out as the UI related to membership is present, but due to lack of information on how the JSON will be for membership requests, it is not possible to work on them.

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • New Features

    • Organization details now include a refined, multi-part address (city, state, postal code, etc.) for a clearer display on profile screens.
    • Enhanced organization membership information is now provided during registration and login, offering richer context.
  • Bug Fixes

    • Improved display logic ensures that location information appears only when complete address details are available.

Copy link
Contributor

coderabbitai bot commented Feb 17, 2025

Walkthrough

This pull request refactors the handling of an organization’s address by replacing a single nested address field with multiple discrete fields. The JSON parsing and serialization logic in the OrgInfo model and its adapter have been updated accordingly, including key renaming. Additionally, user membership data extraction and related GraphQL queries have been refined. UI components and associated tests are modified to directly access the new address fields, and obsolete test files and models have been removed.

Changes

File(s) Change Summary
lib/models/organization/org_info.dart
lib/models/organization/org_info.g.dart
Replaced the address field with individual fields (city, countryCode, line1, line2, postalCode, state), updated JSON key mappings (e.g., _idid, imageavatarURL), and refined serialization/deserialization logic.
lib/models/organization/org_info_address.dart
test/model_tests/organization/org_info_address_test.dart
Removed the Address model and its tests as the address handling has been transitioned to discrete fields.
lib/models/user/user_info.dart
lib/utils/queries.dart
Adjusted the logic for populating joinedOrganizations by mapping nested JSON structures and updated GraphQL queries to include additional organization details.
lib/views/after_auth_screens/org_info_screen.dart
lib/widgets/custom_list_tile.dart
Updated conditional rendering to check for city and countryCode directly rather than a nested address object, reflecting the new data structure.
test/model_tests/events/event_agenda_item_test.dart
test/model_tests/organization/org_info_test.dart
test/views/after_auth_screens/org_info_screen_test.dart
test/widget_tests/widgets/custom_list_tile_test.dart
Modified tests to align with the updated OrgInfo model, including changes to JSON keys, removal of the nested address field, and related adjustments in test data structures (some tests disabled or removed).

Sequence Diagram(s)

sequenceDiagram
    participant JSON as JSON Data
    participant Parser as OrgInfo.fromJson
    participant Model as OrgInfo Object
    JSON->>Parser: Provide JSON with new address fields
    Parser->>Model: Parse fields (city, countryCode, line1, line2, postalCode, state)
    Parser->>Model: Extract members and admins from nested JSON
    Parser-->>JSON: Return updated OrgInfo Object
Loading
sequenceDiagram
    participant UI as User Interface
    participant Screen as OrgInfoScreen/CustomListTile
    participant Data as OrgInfo Object
    UI->>Screen: Request organization details
    Screen->>Data: Retrieve city & countryCode
    alt Both fields available
        Data-->>Screen: Provide address details
        Screen-->>UI: Display organization location
    else Data missing
        Screen-->>UI: Skip displaying location
    end
Loading

Possibly related PRs

Suggested labels

ignore-sensitive-files-pr

Suggested reviewers

  • palisadoes
  • noman2002

Poem

I’m a rabbit in a code field, hopping on the go,
Address fields now gleam in a brand new flow.
JSON whispers secrets in neatly parsed delight,
UI screens shimmer with clarity so bright.
I nibble on bugs and dance with pure cheer—
Celebrating these changes with a joyful ear!
🐇✨


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

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

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

Other

🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.

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

🔭 Outside diff range comments (2)
lib/models/organization/org_info.dart (1)

63-84: 🛠️ Refactor suggestion

Standardize JSON field names.

The JSON field names in the API response don't match the model's field names:

  • 'avatarURL' vs 'image'
  • 'addressLine1' vs 'line1'
  • 'addressLine2' vs 'line2'

Consider using consistent field names or adding a mapping layer to handle the differences.

test/views/after_auth_screens/org_info_screen_test.dart (1)

16-64: ⚠️ Potential issue

Update mockOrgInfo to include all required fields.

The mock data has been partially updated to use the new flattened address structure, but:

  1. The members and admins arrays are commented out, which could affect tests that depend on this data
  2. The id field has been renamed from _id to match the new model

Please verify if the commented-out members and admins data is still needed for the tests. If so, update them to match the new model structure.

🧹 Nitpick comments (4)
lib/models/organization/org_info.dart (1)

35-61: Simplify member extraction logic.

The current implementation is overly complex with multiple type casts and transformations.

Consider simplifying the member extraction:

-    final membersJson = json['members'] as Map<String, dynamic>?;
-    final List<dynamic> edgesDynamic =
-        membersJson?['edges'] as List<dynamic>? ?? [];
-
-    final List<Map<String, dynamic>> memberEdges =
-        edgesDynamic.map((e) => e as Map<String, dynamic>).toList();
-
-    final List<User> members = memberEdges
-        .map(
-          (e) =>
-              User.fromJson(e['node'] as Map<String, dynamic>, fromOrg: true),
-        )
-        .toList();
+    final List<User> members = (((json['members'] as Map<String, dynamic>?)?['edges'] 
+        as List<dynamic>?) ?? [])
+        .map((e) => User.fromJson(
+            (e as Map<String, dynamic>)['node'] as Map<String, dynamic>,
+            fromOrg: true))
+        .toList();
lib/models/user/user_info.dart (1)

37-42: Simplify organization data extraction.

The current implementation uses multiple intermediate variables and type casts.

Consider simplifying:

-    final Map<String, dynamic>? org =
-        userData['organizationsWhereMember'] as Map<String, dynamic>?;
-    final List<dynamic>? edges = org?['edges'] as List<dynamic>?;
-    final List<Map<String, dynamic>>? orgList =
-        edges?.map((e) => e as Map<String, dynamic>).toList();
+    final edges = ((userData['organizationsWhereMember'] 
+        as Map<String, dynamic>?)?['edges'] as List<dynamic>?) ?? [];
lib/utils/queries.dart (1)

38-38: Consider implementing pagination for large datasets.

The fixed limit of 32 records (first:32) for both organizations and members might not scale well for:

  • Organizations with many members
  • Users who are members of many organizations

Consider implementing proper pagination using cursor-based pagination with after parameter.

Also applies to: 88-88

lib/views/after_auth_screens/org_info_screen.dart (1)

124-130: Consider showing more address details.

The current implementation only shows city and country code. Consider showing a more comprehensive address by including:

  • Address lines (when available)
  • Postal code
  • State/Province

This would provide users with complete location information.

-if (orgInfo.city != null && orgInfo.countryCode != null)
+if (orgInfo.city != null || orgInfo.countryCode != null)
   Padding(
     padding: const EdgeInsets.only(top: 8, left: 8),
     child: Center(
       child: Text(
-        '${orgInfo.city}, ${orgInfo.countryCode}',
+        [
+          if (orgInfo.addressLine1 != null) orgInfo.addressLine1,
+          if (orgInfo.addressLine2 != null) orgInfo.addressLine2,
+          if (orgInfo.city != null) orgInfo.city,
+          if (orgInfo.state != null) orgInfo.state,
+          if (orgInfo.postalCode != null) orgInfo.postalCode,
+          if (orgInfo.countryCode != null) orgInfo.countryCode,
+        ].where((e) => e != null).join(', '),
         style: const TextStyle(
           fontSize: 16.0,
           color: Color.fromARGB(255, 179, 168, 168),
         ),
       ),
     ),
   ),
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4a24515 and fb2fc75.

📒 Files selected for processing (12)
  • lib/models/organization/org_info.dart (4 hunks)
  • lib/models/organization/org_info.g.dart (2 hunks)
  • lib/models/organization/org_info_address.dart (0 hunks)
  • lib/models/user/user_info.dart (2 hunks)
  • lib/utils/queries.dart (2 hunks)
  • lib/views/after_auth_screens/org_info_screen.dart (1 hunks)
  • lib/widgets/custom_list_tile.dart (1 hunks)
  • test/model_tests/events/event_agenda_item_test.dart (1 hunks)
  • test/model_tests/organization/org_info_address_test.dart (0 hunks)
  • test/model_tests/organization/org_info_test.dart (1 hunks)
  • test/views/after_auth_screens/org_info_screen_test.dart (4 hunks)
  • test/widget_tests/widgets/custom_list_tile_test.dart (1 hunks)
💤 Files with no reviewable changes (2)
  • test/model_tests/organization/org_info_address_test.dart
  • lib/models/organization/org_info_address.dart
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Checking codebase
🔇 Additional comments (11)
lib/models/organization/org_info.g.dart (2)

28-33: LGTM! Address fields are properly mapped.

The generated code correctly maps the new address fields with sequential field IDs.


58-68: LGTM! Write method properly serializes all fields.

The write method correctly handles all 14 fields, including the new address components.

test/model_tests/events/event_agenda_item_test.dart (1)

32-32: LGTM! ID field name standardized.

The change from '_id' to 'id' aligns with the standardization of identifier field names across the codebase.

lib/models/organization/org_info.dart (1)

149-171: LGTM! Well-documented address fields.

The new address fields are properly documented with clear descriptions.

lib/models/user/user_info.dart (1)

56-60: LGTM! Null-safe organization list initialization.

The code properly handles null cases by defaulting to an empty list.

lib/widgets/custom_list_tile.dart (1)

119-124: LGTM! The address display logic has been updated correctly.

The changes correctly reflect the new organization model structure by directly accessing city and countryCode fields instead of using a nested address object.

test/views/after_auth_screens/org_info_screen_test.dart (1)

70-124: LGTM! The mock data structure has been updated correctly.

The changes to mockOrgInfo2 correctly reflect the new organization model structure with flattened address fields.

test/widget_tests/widgets/custom_list_tile_test.dart (1)

98-99: LGTM! The test data has been updated correctly.

The OrgInfo instantiation has been updated to use the new flattened address structure with direct city and countryCode fields.

lib/utils/queries.dart (2)

38-60: LGTM! Enhanced organization data retrieval in registration.

The addition of detailed organization fields in the registration mutation improves data completeness and aligns with the organization model update.


88-110: LGTM! Consistent organization data retrieval in login.

The login query maintains consistency with the registration mutation by including the same detailed organization fields.

lib/views/after_auth_screens/org_info_screen.dart (1)

124-130: LGTM! Improved address field handling.

The update properly handles the new organization address structure by:

  1. Checking both city and countryCode for null values
  2. Using direct field access instead of the nested address object

Copy link

codecov bot commented Feb 17, 2025

Codecov Report

Attention: Patch coverage is 68.00000% with 16 lines in your changes missing coverage. Please review.

Project coverage is 95.16%. Comparing base (392b929) to head (fb2fc75).
Report is 3 commits behind head on develop-postgres.

Files with missing lines Patch % Lines
lib/models/organization/org_info.g.dart 66.66% 6 Missing ⚠️
lib/models/organization/org_info.dart 78.26% 5 Missing ⚠️
lib/models/user/user_info.dart 25.00% 3 Missing ⚠️
lib/views/after_auth_screens/org_info_screen.dart 0.00% 2 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##           develop-postgres    #2739      +/-   ##
====================================================
- Coverage             96.38%   95.16%   -1.22%     
====================================================
  Files                   189      188       -1     
  Lines                 10029    10065      +36     
====================================================
- Hits                   9666     9578      -88     
- Misses                  363      487     +124     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@palisadoes
Copy link
Contributor

  1. Please make coderabbit.ai approves your work.
  2. Make sure all tests pass and are valid.
  3. Ensure the test code coverage for your patch reaches as close to 100% as possible.

Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

  1. Please make coderabbit.ai approves your work.
  2. Make sure all tests pass and are valid.
  3. Ensure the test code coverage for your patch reaches as close to 100% as possible.

@MohitMaulekhi
Copy link
Contributor Author

Currently, certain features such as membership requests, fetching all organizations, and accessing the creator as a regular member of an organization have not yet been implemented in the API or the admin interface. As a result, writing tests related to these features and screen is not feasible at this time.

@varshith257
Copy link
Member

@MohitMaulekhi I think we have support for fetching orgs in api. Once check there and open issue there if itn't so. Let's merge this PR later on if we need any changes in API

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.

3 participants