Skip to content

feat: show resolved value in dep variables view#570

Merged
adityachoudhari26 merged 5 commits intomainfrom
show-resolved-value
May 17, 2025
Merged

feat: show resolved value in dep variables view#570
adityachoudhari26 merged 5 commits intomainfrom
show-resolved-value

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented May 17, 2025

Summary by CodeRabbit

  • New Features

    • Deployment variables now display resolved values for resource references, making it easier to see the actual values assigned to each resource.
    • Resource links in the interface now use a filtered view for more precise navigation.
  • Improvements

    • Variable value displays have been updated to show enriched resource information, consolidating resource details for clarity.
    • Enhanced API endpoints provide deployment variables with resolved resource values for improved data accuracy.
    • Simplified variable fetching logic improves performance and reduces complexity.
  • Bug Fixes

    • Improved handling of null and undefined values when resolving variable references to prevent display inconsistencies.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 17, 2025

Warning

Rate limit exceeded

@adityachoudhari26 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 57 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c5e2a44 and 310985e.

📒 Files selected for processing (1)
  • apps/webservice/src/app/[workspaceSlug]/(app)/resources/(raw)/[resourceId]/variables/page.tsx (1 hunks)

"""

Walkthrough

The changes refactor how deployment variable values and their associated resources are handled and displayed. Resource-related data now includes resolved values and is consolidated into enriched arrays, removing separate count and hash properties. API logic for fetching deployment variables is centralized in a new module, and URL generation for filtered resource lists is updated to use compressed selectors.

Changes

File(s) Change Summary
apps/webservice/src/app/[workspaceSlug]/.../VariableTable.tsx Updated ResourceRow to accept a resolvedValue and valueType prop; renders resolved value for references; switched from resource count to resource array; updated resource link logic.
apps/webservice/src/app/[workspaceSlug]/.../variables/page.tsx Removed complex resource-enrichment logic; now fetches deployment variables directly via API without additional processing.
apps/webservice/src/app/[workspaceSlug]/.../variables/variable-data.ts Changed VariableValue type: removed resourceCount and conditionHash, updated resources to include resolvedValue.
apps/webservice/src/app/urls.ts Added filtered method to resource URLs; generates compressed, encoded selector-based URLs for filtered resource lists.
packages/rule-engine/src/manager/variables/resolve-reference-variable.ts Improved null handling and type assertion for resolved reference variable values.
packages/api/src/router/deployment-variable/by-deployment-id.ts New file: Implements protected API procedure to retrieve deployment variables with enriched resource and resolved value data for a deployment.
packages/api/src/router/deployment-variable/deployment-variable.ts Replaces inline byDeploymentId logic with import from new module; removes unused import; updates import paths.
packages/api/src/router/deployment.ts Changed import path for deploymentVariableRouter to point to new location; no logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Webservice
    participant API
    participant RuleEngine
    participant DB

    Client->>Webservice: Request deployment variables page
    Webservice->>API: Fetch variables by deployment ID
    API->>DB: Query deployment, variables, values, resources
    API->>RuleEngine: Resolve reference variable values (if needed)
    RuleEngine-->>API: Return resolved values
    API-->>Webservice: Return variables with enriched resources and resolved values
    Webservice-->>Client: Render variable table with resolved resource values
Loading

Poem

In the warren of code, a new path we pave,
Where variables leap and resources behave.
With resolved values bright, and selectors compressed,
URLs hop swiftly, the logic’s addressed.
The rabbit applauds this tidy refactor—
Each carrot of data now tastes so much better! 🥕
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

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

🧹 Nitpick comments (4)
packages/api/src/router/deployment-variable.ts (4)

275-275: Typo in variable name.

There's a typo in the variable name resolvedVarliablesPromises. It should be resolvedVariablesPromises.

-      const resolvedVarliablesPromises = deploymentVariables.map(
+      const resolvedVariablesPromises = deploymentVariables.map(

275-371: Consider breaking down the complex function.

The function that processes deployment variables and resolves references is quite long and complex. Consider breaking it down into smaller, more focused functions for better maintainability and readability.

You could extract separate functions for:

  1. Processing non-default values
  2. Matching resources to variable values
  3. Resolving reference values
  4. Handling default values

This would make the code easier to understand, test, and maintain.


313-316: Duplicated code for resolving reference values.

There's duplicated logic for resolving reference values in two different places. Consider extracting this into a helper function to avoid duplication.

You could create a helper function like:

const resolveReference = async (resourceId: string, value: any) => {
  const resolvedValue = await getReferenceVariableValue(
    resourceId,
    value
  );
  return resolvedValue;
};

And then use this function in both places where you're resolving references.

Also applies to: 345-348


373-373: Update variable name in Promise.all.

Remember to update the variable name here to match the fixed typo suggested earlier.

-      return Promise.all(resolvedVarliablesPromises);
+      return Promise.all(resolvedVariablesPromises);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 62c21e3 and a85e915.

📒 Files selected for processing (6)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(sidebar)/variables/VariableTable.tsx (5 hunks)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(sidebar)/variables/page.tsx (1 hunks)
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(sidebar)/variables/variable-data.ts (1 hunks)
  • apps/webservice/src/app/urls.ts (2 hunks)
  • packages/api/src/router/deployment-variable.ts (4 hunks)
  • packages/rule-engine/src/manager/variables/resolve-reference-variable.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{ts,tsx}`: **Note on Error Handling:** Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error...

**/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.

  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(sidebar)/variables/page.tsx
  • packages/rule-engine/src/manager/variables/resolve-reference-variable.ts
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(sidebar)/variables/variable-data.ts
  • apps/webservice/src/app/urls.ts
  • apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(sidebar)/variables/VariableTable.tsx
  • packages/api/src/router/deployment-variable.ts
🧬 Code Graph Analysis (4)
apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(sidebar)/variables/page.tsx (1)
packages/db/src/schema/deployment.ts (1)
  • deployment (69-93)
packages/rule-engine/src/manager/variables/resolve-reference-variable.ts (1)
packages/logger/src/index.ts (1)
  • logger (48-48)
apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(sidebar)/variables/variable-data.ts (1)
packages/db/src/schema/resource.ts (1)
  • Resource (105-105)
packages/api/src/router/deployment-variable.ts (5)
packages/db/src/schema/release.ts (1)
  • releaseTarget (20-42)
packages/db/src/schema/resource.ts (2)
  • resource (59-87)
  • Resource (105-105)
packages/db/src/schema/deployment-variables.ts (2)
  • deploymentVariable (28-50)
  • isDeploymentVariableValueReference (148-152)
packages/db/src/selectors/index.ts (1)
  • selector (13-13)
packages/rule-engine/src/manager/variables/resolve-reference-variable.ts (1)
  • getReferenceVariableValue (8-31)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Lint
  • GitHub Check: build (linux/amd64)
  • GitHub Check: Typecheck
  • GitHub Check: build (linux/amd64)
🔇 Additional comments (15)
packages/rule-engine/src/manager/variables/resolve-reference-variable.ts (2)

23-26: Improved null handling and explicit typing for reference variable resolution.

The changes improve the function by:

  1. Explicitly returning null when the target resource is not found (instead of potentially returning undefined)
  2. Extracting the resolved path to a variable with null coalescing
  3. Adding a type assertion to clarify the return type

This makes the function's behavior more predictable and type-safe.


29-29: Consistent null handling in error cases.

This change ensures consistent behavior by explicitly returning null when the default value is undefined, matching the same pattern used in the success path.

apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(sidebar)/variables/page.tsx (1)

37-37: Simplified data fetching with improved API.

The code has been significantly simplified by replacing complex client-side processing with a single API call. This improves maintainability by moving the data enrichment logic to the backend.

apps/webservice/src/app/urls.ts (2)

1-3: Added necessary imports for resource filtering.

These imports support the new URL filtering functionality by providing the required types and compression library.


96-108: Added method to generate resource URLs with compressed filter conditions.

This new filtered method provides a clean way to generate URLs for filtered resource views. The implementation:

  1. Returns the standard list URL when no filter is provided
  2. Uses LZString compression to efficiently encode complex filter objects in URLs
  3. Properly handles the query parameter format

This is a good approach for maintaining state in URLs without creating excessively long URLs.

apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(sidebar)/variables/variable-data.ts (1)

3-7: Enhanced resource type with resolved values.

The resources property has been enhanced to include a resolvedValue property for each resource. This change:

  1. Streamlines the data structure by removing separate resourceCount and conditionHash properties
  2. Makes the resolved values of reference variables directly accessible in the UI
  3. Provides better type safety with explicit typing of the resolved value

This change properly supports the display of resolved reference values in the UI.

apps/webservice/src/app/[workspaceSlug]/(app)/(deploy)/(raw)/systems/[systemSlug]/(raw)/deployments/[deploymentSlug]/(sidebar)/variables/VariableTable.tsx (5)

53-59: Props now support resolved values for reference variables.

The ResourceRow component now properly supports showing resolved values for deployment variables that reference resources, with the added valueType prop to correctly differentiate display behavior.


78-84: Good conditional rendering of resolved values.

The conditional rendering of resolved values when valueType is "reference" improves the user experience by showing the concrete values from referenced resources. The code correctly handles different data types, including proper JSON stringification for object values.


265-267: Updated resource count display.

The code now correctly uses the length of the resources array instead of a resourceCount property, aligning with the backend changes.


287-287: Proper propagation of value type.

The valueType is correctly passed to child components, ensuring proper rendering of different value types.


299-301: Updated resource filtering URL generation.

The code now uses the new filtered method to generate URLs for filtered resources, which aligns with the backend changes.

packages/api/src/router/deployment-variable.ts (4)

1-30: Updated imports to support the new implementation.

The imports have been updated to include necessary components for the new implementation, including Resource, selector, isDeploymentVariableValueReference, releaseTarget, and getReferenceVariableValue. These imports align with the new approach to fetching and processing deployment variables.


263-273: Improved data fetching approach.

The implementation now uses a multi-step process that first fetches release targets with resources and then retrieves deployment variables with their values. This approach is more explicit and provides better support for resolving reference values.


310-322: Good implementation of reference value resolution.

The code correctly identifies reference-type values and resolves them for each matched resource. The implementation properly uses the getReferenceVariableValue function and enriches resources with their resolved values.


332-368: Proper handling of default values.

The code correctly handles default values separately, applying them to resources that don't match any non-default values. This ensures that all resources have appropriate variable values.

Copy link
Copy Markdown
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: 1

🧹 Nitpick comments (1)
packages/api/src/router/deployment-variable/by-deployment-id.ts (1)

106-108: Minor typo – resolvedVarliablesPromises

Small nit: the variable is spelt resolvedVarliablesPromises. Correcting improves readability and avoids future grepping mishaps.

-const resolvedVarliablesPromises = …
+const resolvedVariablesPromises = …
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between a85e915 and 929cad5.

📒 Files selected for processing (3)
  • packages/api/src/router/deployment-variable/by-deployment-id.ts (1 hunks)
  • packages/api/src/router/deployment-variable/deployment-variable.ts (2 hunks)
  • packages/api/src/router/deployment.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/api/src/router/deployment.ts
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{ts,tsx}`: **Note on Error Handling:** Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error...

**/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.

  • packages/api/src/router/deployment-variable/deployment-variable.ts
  • packages/api/src/router/deployment-variable/by-deployment-id.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build (linux/amd64)
  • GitHub Check: Lint
  • GitHub Check: Typecheck
  • GitHub Check: build (linux/amd64)
🔇 Additional comments (4)
packages/api/src/router/deployment-variable/deployment-variable.ts (1)

28-30: Module split greatly improves cohesion – nice!

Extracting the byDeploymentId procedure into its own module removes ~200 LOC of mixed concerns from this router and makes the file much easier to reason about. 👍

packages/api/src/router/deployment-variable/by-deployment-id.ts (3)

41-50: resolvedValue may be undefined – check typing & null-coalescing

getReferenceVariableValue can legitimately return undefined (e.g. when the reference cannot be resolved).
ResolvedResource["resolvedValue"] excludes undefined, so TypeScript will silently widen to any.

Consider either:

  1. Extending the union type to undefined, or
  2. Converting undefined to null before assignment:
-const resolvedValue = await getReferenceVariableValue(r.id, val);
+const resolved = await getReferenceVariableValue(r.id, val);
+const resolvedValue = resolved ?? null;

This avoids accidental any leakage and keeps JSON serialisable payloads predictable.


61-74: Default value ignores its own selector

getDefaultValueWithRemainingResources assigns the default value to all resources that were not matched earlier, even if the default itself has a non-null resourceSelector.

If the API ever allows defaults with selectors (e.g. “default for databases”), those resources will be over-matched.

Please either:
• Assert val.resourceSelector === null for defaults, or
• Apply the selector filter in the same way as for non-default values.


106-146: Missing stable sort may change client ordering

The previous inline implementation returned variables ordered by key ASC; the new code relies on the natural order of findMany, which is undefined without an orderBy.

If any UI tests or screenshots assume alphabetical ordering, this may introduce subtle diffs.

Add an explicit orderBy: asc(schema.deploymentVariable.key) when querying deploymentVariable.

@adityachoudhari26 adityachoudhari26 merged commit d4e2b48 into main May 17, 2025
3 of 7 checks passed
@adityachoudhari26 adityachoudhari26 deleted the show-resolved-value branch May 17, 2025 17:53
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