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

fix(server): revert sort logic [VIZ-1423] #1528

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

hexaforce
Copy link
Contributor

@hexaforce hexaforce commented Mar 27, 2025

Overview

Sort the properties according to the order defined in manifest.yml.

Since property sorting was added, the display order has changed.

The sort that was previously added for debugging was affecting the display order.

スクリーンショット 2025-03-27 10 46 32 スクリーンショット 2025-03-27 10 47 12

What I've done

Revert previous changes

What I haven't done

How I tested

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • New Features

    • Introduced a new property identifier in scene details to enhance client data visibility.
    • Added a new test to validate the order of property fields in a scene's schema.
  • Refactor

    • Improved the handling of property items and fields by aligning them with associated schemas.
    • Enhanced property operations to consistently integrate schema data, offering a more predictable presentation.
    • Simplified the output of property fields by removing sorting logic.
  • Bug Fixes

    • Adjusted expected field order in tests to reflect changes in property field arrangements.
  • Chores

    • Removed outdated test function to streamline the test suite.
    • Added a new function for end-to-end testing context.

Copy link

coderabbitai bot commented Mar 27, 2025

Walkthrough

This pull request updates multiple modules to incorporate and leverage a property schema during conversion and mutation operations. The changes add schema-based sorting logic for property items in conversion functions and adapt method signatures to accept a new schema parameter. Several test cases have been updated to reflect different field orders, and obsolete tests have been removed. Additionally, sorting logic in group processing has been removed, and a new GraphQL field (schemaGroupId) has been introduced in one query.

Changes

Files Change Summary
server/internal/adapter/gql/gqlmodel/convert_property.go
server/internal/adapter/gql/resolver_mutation_property.go
Added schema-based sorting logic, updated function signatures to include a property schema parameter, and modified mutation resolvers to fetch and pass the schema to conversion functions.
server/pkg/property/group.go
server/pkg/property/schema_group.go
Removed sorting logic in the Fields methods so that they now return fields in their original order without using sort.Slice.
server/internal/infrastructure/mongo/migration/221028204300_move_terrain_properties_test.go
server/pkg/property/property_test.go
Adjusted test expectations for field ordering: reordering of terrain property fields and changes to the expected positions of fields in move operations.
server/e2e/gql_property_test.go
server/e2e/gql_nlslayer_test.go
Removed the obsolete TestUpdateScenePropertyValue function and added a new schemaGroupId field to the GraphQL query structure in fetchSceneForNewLayers.
server/e2e/gql_property_schema_test.go
server/pkg/builtin/main.go
Introduced a new test file for validating property schema order and added a new function for parsing plugin manifests in an end-to-end testing context.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Resolver
  participant Builtin
  participant Converter

  Client->>Resolver: Send AddPropertyItem mutation
  Resolver->>Builtin: GetPropertySchema()
  Builtin-->>Resolver: Return property schema object
  Resolver->>Converter: ToPropertyItem(item, property, groupList, schema)
  Converter-->>Resolver: Return PropertyItem
  Resolver-->>Client: Return PropertyItemPayload
Loading

Possibly related PRs

Poem

I'm a rabbit, hopping through the code,
With schemas and fields, I lighten the load.
Sorting is now a tale of yore,
New orders and queries make the system soar.
I nibble on bugs, one by one,
Celebrating changes 'til the coding day's done!
🐇🌟


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 42640b8 and 8e914be.

📒 Files selected for processing (1)
  • server/e2e/gql_storytelling_test.go (1 hunks)
🔇 Additional comments (1)
server/e2e/gql_storytelling_test.go (1)

223-226: Order of property tests has been correctly modified to match reverted sort logic.

The changes reflect the PR's objective to revert the property sorting that was inadvertently affecting display order. The test now expects properties in their natural order - SPACING type first followed by STRING type - rather than in a sorted order. This ensures tests pass with the reverted sorting logic in the codebase.

✨ 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 plan to trigger planning for file edits and PR creation.
  • @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

netlify bot commented Mar 27, 2025

Deploy Preview for reearth-web canceled.

Name Link
🔨 Latest commit 8e914be
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/67e65154f266b00008754261

@hexaforce hexaforce changed the title fix(server): revert sort logic fix(server): revert sort logic [VIZ-1423] Mar 27, 2025
@hexaforce hexaforce enabled auto-merge (squash) March 27, 2025 03:06
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.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea5d5e5 and e6c0bdd.

📒 Files selected for processing (1)
  • server/internal/adapter/gql/loader_property.go (2 hunks)
🔇 Additional comments (3)
server/internal/adapter/gql/loader_property.go (3)

9-9: No issues with the new import.
Importing builtin is appropriate given its usage below; no concerns here.


11-11: No issues with the new import.
Importing the property package is necessary for the subsequent logic; no concerns here.


37-42: Validate fallback logic if no built-in schema is found.
When builtin.GetPropertySchema(prop.Schema()) returns nil, the property is appended as-is. This fallback is fine, but ensure no edge cases (e.g. partial or unknown schemas) lead to lost data or duplication. Consider verifying all properties are always appended once.

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

🧹 Nitpick comments (2)
server/pkg/builtin/main.go (1)

74-79: Global state modification needs a reset mechanism

The E2ETestChange function modifies the global pluginManifest variable without providing a way to restore the original state after testing. This could lead to test interdependencies if multiple tests use this function sequentially.

Consider adding a companion function to restore the original state:

+var originalPluginManifest = pluginManifest

+// RestoreOriginalPluginManifest restores the original plugin manifest after testing
+func RestoreOriginalPluginManifest() {
+	pluginManifest = originalPluginManifest
+}

func E2ETestChange(e2ePluginManifestJSON []byte) {
	var pluginTranslationList = manifest.TranslationMap{
		"ja": manifest.MustParseTranslationFromBytes(pluginManifestJSON_ja),
	}
	pluginManifest = manifest.MustParseSystemFromBytes(e2ePluginManifestJSON, nil, pluginTranslationList.TranslatedRef())
}
server/e2e/gql_property_schema_test.go (1)

41-123: Consider extracting test schema to a separate file

The large YAML schema definition embedded in the test code makes the test less readable and harder to maintain.

Consider moving this schema definition to a separate file in a testdata directory and loading it in the test:

-	data := `
-id: reearth
-system: true
...
-`
+	data, err := os.ReadFile("testdata/test_schema.yml")
+	if err != nil {
+		t.Fatalf("Failed to read test schema: %v", err)
+	}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f04003b and 366c79f.

📒 Files selected for processing (2)
  • server/e2e/gql_property_schema_test.go (1 hunks)
  • server/pkg/builtin/main.go (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
server/e2e/gql_property_schema_test.go (1)
server/pkg/builtin/main.go (1)
  • E2ETestChange (74-79)
🔇 Additional comments (2)
server/e2e/gql_property_schema_test.go (2)

13-137: Test validates field ordering matches schema definition

This test confirms that the property field ordering follows the schema definition rather than being automatically sorted, which aligns with the PR objective to revert sorting logic affecting display order.


26-26:

❓ Verification inconclusive

Investigate potential bug in array property handling

The comment // bug? suggests there might be an issue with how array values are being processed or returned. This should be investigated to determine if it's a real bug or expected behavior.


🏁 Script executed:

#!/bin/bash
# Search for other similar array property handling in tests or implementation
rg -A 10 -B 5 "updatePropertyValue.*ARRAY" --glob "*.go" | grep -v "test_"

Length of output: 2975


Double-check integer array conversion in updatePropertyValue
It appears that when handling integer array updates (for example, in the "tile_zoomLevel" property), the test currently expects the result to be []*int{nil, nil}, whereas other array types (such as string arrays) return correctly populated values. This discrepancy suggests that the conversion logic for integer arrays might not be working as intended.

  • In server/e2e/gql_property_schema_test.go, the call:
     _, r = updatePropertyValue(e, propID, "tiles", groupID, "tile_zoomLevel", []int{10, 20}, "ARRAY")
     r.Path("$.data.updatePropertyValue.propertyField.value").IsEqual([]*int{nil, nil}) // bug?
    returns nil pointers instead of the expected integer values.
  • Compare this with other cases (e.g., string arrays) where the returned values match the input.

Please investigate whether this behavior is an intentional side effect or a bug in the conversion process for integer arrays.

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

🧹 Nitpick comments (1)
server/pkg/property/schema_group.go (1)

122-146: Enhance error handling and handle no-op moves.

Currently, out-of-range indices or a nil receiver cause a silent return, which might obscure logic errors. Also, skipping the operation when from == to can be beneficial.

 func (s *SchemaGroup) Move(from int, to int) {
+    // Consider a quick check for no-op moves
+    if s == nil || from == to {
+        return
+    }
     if from < 0 || from >= len(s.fields) {
-        return
+        // Optionally log or return an error
         return
     }
     if to < 0 || to >= len(s.fields) {
-        return
+        // Optionally log or return an error
         return
     }

     // existing logic remains unchanged
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 355a4ab and 42640b8.

📒 Files selected for processing (3)
  • server/e2e/gql_property_schema_test.go (1 hunks)
  • server/pkg/builtin/main.go (1 hunks)
  • server/pkg/property/schema_group.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • server/pkg/builtin/main.go
  • server/e2e/gql_property_schema_test.go
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - reearth-web
  • GitHub Check: Header rules - reearth-web
  • GitHub Check: Pages changed - reearth-web
🔇 Additional comments (2)
server/pkg/property/schema_group.go (2)

39-39: Reverted sorting logic with a shallow copy.

This line reverts the sorting by returning a shallow copy of s.fields. It looks aligned with the stated goal of removing sorting. Keep in mind that the fields themselves remain mutable references, so any in-place modification to a field will still affect the underlying objects.


121-121: No functional change.

This line is merely whitespace or a blank line; no impact on code logic is observed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant