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: Identifier filter and other filter cleanup #180

Merged
merged 3 commits into from
Oct 28, 2024

Conversation

adityachoudhari26
Copy link
Contributor

@adityachoudhari26 adityachoudhari26 commented Oct 28, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced support for IdentifierCondition, enhancing the condition management capabilities.
    • Added ColumnOperator for improved condition evaluations across various components.
  • Improvements

    • Updated existing components to utilize ColumnOperator instead of VersionOperator, ensuring consistency in condition handling.
    • Enhanced rendering logic to remove percentage signs from displayed values for better clarity.
    • Streamlined validation logic for target conditions, improving extensibility.
  • Bug Fixes

    • Corrected operator handling in multiple components to align with the new column-based logic.
  • Chores

    • Consolidated import statements for better organization and readability across various files.

Copy link
Contributor

coderabbitai bot commented Oct 28, 2024

Walkthrough

This pull request encompasses a comprehensive refactor of various components and schemas within the application, transitioning from version-based logic to column-based logic. Key changes include the renaming of types and variables, updates to operator handling across multiple components, and the introduction of new components for managing identifier conditions. The modifications enhance the clarity and consistency of condition handling, ensuring that components utilize the newly defined ColumnOperator and related types.

Changes

File Change Summary
apps/webservice/src/app/[workspaceSlug]/_components/filter/ColumnConditionRender.tsx Refactored to replace VersionOperatorType with ColumnOperatorType, updated props and export names accordingly, and modified JSX to use new operator values.
apps/webservice/src/app/[workspaceSlug]/_components/job-condition/JobComparisonConditionRender.tsx Updated operator from VersionOperator.Equals to ColumnOperator.Equals and removed the import for VersionOperator.
apps/webservice/src/app/[workspaceSlug]/_components/job-condition/JobConditionBadge.tsx Modified to remove percentage signs from the displayed condition.value.
apps/webservice/src/app/[workspaceSlug]/_components/job-condition/VersionConditionRender.tsx Updated to utilize ColumnOperatorType instead of VersionOperatorType and changed the rendered component from VersionConditionRender to ColumnConditionRender.
apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ComparisonConditionRender.tsx Added import for ColumnOperator, updated operator for "Version" condition from ReleaseOperator.Equals to ColumnOperator.Equals.
apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ReleaseConditionBadge.tsx Similar to JobConditionBadge, modified to remove percentage signs from the displayed condition.value.
apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ReleaseVersionConditionRender.tsx Removed VersionOperatorType import, added ColumnOperatorType, and changed rendered component from VersionConditionRender to ColumnConditionRender.
apps/webservice/src/app/[workspaceSlug]/_components/target-condition/ComparisonConditionRender.tsx Added ColumnOperator import and introduced ColumnOperator.Like in the dropdown for adding conditions.
apps/webservice/src/app/[workspaceSlug]/_components/target-condition/IdentifierConditionRender.tsx New component for managing identifier conditions, utilizing ColumnConditionRender.
apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionBadge.tsx Introduced StringifiedIdentifierCondition component for rendering identifier conditions and integrated it into the existing logic.
apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionRender.tsx Added condition check for isIdentifierCondition to render IdentifierConditionRender.
apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/FlowPolicyNode.tsx Updated operator in useEvaluateReleaseFilterCheck from ReleaseOperator.Equals to ColumnOperator.Equals and refined approval handling logic.
packages/db/src/schema/job.ts Replaced VersionOperator with MetadataOperator, introduced ColumnOperator, and updated condition-building functions accordingly.
packages/db/src/schema/release.ts Similar updates as job.ts, replacing VersionOperator with ColumnOperator and MetadataOperator in condition-building functions.
packages/db/src/schema/target.ts Added IdentifierCondition, updated buildMetadataCondition, and refactored buildCondition to include TargetFilterType.Identifier.
packages/validators/src/conditions/index.ts Removed version-condition.js, introduced columnOperator, and defined ColumnOperatorType and VersionCondition.
packages/validators/src/conditions/version-condition.ts Complete removal of the file, including versionCondition, VersionCondition, and VersionOperator.
packages/validators/src/jobs/conditions/comparison-condition.ts Updated imports to consolidate VersionCondition from index.js, integrating it into the comparisonCondition schema.
packages/validators/src/jobs/conditions/job-condition.ts Updated to include VersionCondition from index.js, added type guard for VersionCondition.
packages/validators/src/releases/conditions/comparison-condition.ts Consolidated imports for MetadataCondition and VersionCondition from index.js.
packages/validators/src/releases/conditions/release-condition.ts Similar consolidation of imports as in comparison-condition.ts.
packages/validators/src/targets/conditions/comparison-condition.ts Added support for IdentifierCondition in the comparisonCondition schema.
packages/validators/src/targets/conditions/identifier-condition.ts New file defining a Zod schema for validating identifier conditions, including types and structure.
packages/validators/src/targets/conditions/index.ts Added export for identifier-condition.js.
packages/validators/src/targets/conditions/target-condition.ts Enhanced TargetCondition type with IdentifierCondition, updated TargetFilterType to include Identifier, and streamlined validation logic.

Possibly related PRs

  • fix: Variable sets #150: This PR involves changes to the VariableSet components, which may relate to the refactoring of variable handling in the main PR, particularly in how variables are defined and managed.
  • fix: Check existence from identifiers #155: This PR updates the handling of operators in the context of job comparisons, which aligns with the main PR's focus on transitioning from version-based to column-based logic.
  • fix: Remove semver and regex release filter #160: This PR simplifies the release filter logic, which could relate to the changes in the main PR that involve updating operator types and conditions.
  • fix: Release dependencies refactor #165: This PR refactors release dependencies, which may connect to the main PR's focus on updating how conditions and operators are handled in the context of releases.
  • fix: Init target variable ui #171: This PR introduces UI components for managing target variables, which directly relates to the main PR's focus on variable handling and refactoring.
  • Fix: Approval Usability #172: This PR enhances the approval process, which may connect to the main PR's updates regarding how conditions and approvals are managed in the context of job releases.

Suggested reviewers

  • jsbroks: Suggested reviewer for the changes made in this pull request.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f22b885 and 46424ea.

📒 Files selected for processing (5)
  • apps/webservice/src/app/[workspaceSlug]/_components/target-condition/ComparisonConditionRender.tsx (2 hunks)
  • apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionRender.tsx (4 hunks)
  • apps/webservice/src/app/[workspaceSlug]/_components/target-condition/target-condition-props.ts (0 hunks)
  • packages/db/src/schema/target.ts (6 hunks)
  • packages/validators/src/targets/conditions/identifier-condition.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/webservice/src/app/[workspaceSlug]/_components/target-condition/target-condition-props.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/webservice/src/app/[workspaceSlug]/_components/target-condition/ComparisonConditionRender.tsx
  • apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionRender.tsx
  • packages/validators/src/targets/conditions/identifier-condition.ts
🔇 Additional comments (4)
packages/db/src/schema/target.ts (4)

2-5: LGTM: Clean import organization for new types and operators

The new imports are well-organized and properly structured, supporting the transition to column-based logic for filters.

Also applies to: 23-31


Line range hint 139-152: LGTM: Improved type safety in metadata condition handling

The refactoring to use MetadataOperator enum values improves type safety while maintaining proper SQL query construction and parameterization.

Also applies to: 152-166, 166-196


206-213: LGTM: Well-structured condition builder with proper type safety

The changes to use TargetFilterType enum and the addition of identifier condition handling improve the code's type safety and maintainability. The handling of empty conditions and boolean operators is also well-implemented.

Also applies to: 218-220


197-203: ⚠️ Potential issue

Security concern: Unsafe regex pattern in default case

The default case directly interpolates cond.value into the SQL query without proper sanitization:

return sql`${target.identifier} ~ ${cond.value}`;

This could lead to SQL injection if cond.value contains malicious input.

Consider one of these approaches:

  1. Validate the regex pattern before using it:
const isValidRegex = (pattern: string): boolean => {
  try {
    new RegExp(pattern);
    return true;
  } catch {
    return false;
  }
};

if (!isValidRegex(cond.value)) {
  throw new Error("Invalid regex pattern");
}
  1. Use a parameterized query with proper escaping:
return sql`${target.identifier} ~ ${sql.raw('?')}`.setParameter(cond.value);

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 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
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 and nitpick comments (16)
packages/validators/src/targets/conditions/index.ts (1)

6-6: LGTM! Consider maintaining alphabetical order.

The addition of the identifier condition export aligns well with the PR objectives. As a minor suggestion, consider moving it between comparison-condition.js and kind-condition.js to maintain alphabetical ordering with the other exports.

 export * from "./name-condition.js";
 export * from "./kind-condition.js";
 export * from "./comparison-condition.js";
+export * from "./identifier-condition.js";
 export * from "./target-condition.js";
 export * from "./provider-condition.js";
-export * from "./identifier-condition.js";
packages/validators/src/targets/conditions/identifier-condition.ts (1)

5-9: Add JSDoc documentation for the schema.

Consider adding documentation to explain the purpose, usage, and validation rules of this schema. This will help other developers understand how to use it correctly.

+/**
+ * Zod schema for validating identifier conditions.
+ * @property {string} type - Must be "identifier"
+ * @property {ColumnOperator} operator - Valid column comparison operator
+ * @property {string} value - Non-empty string to compare against
+ */
 export const identifierCondition = z.object({
apps/webservice/src/app/[workspaceSlug]/_components/job-condition/VersionConditionRender.tsx (1)

The transition to column-based logic is incomplete and needs attention

The verification reveals that while VersionConditionRender.tsx has been updated to use ColumnConditionRender, there are still version-specific components and types being used throughout the codebase that should be transitioned to the new column-based approach:

  • Both ReleaseVersionConditionRender and JobReleaseVersionConditionRender components are using the same column-based implementation but with different names
  • Version-specific types and conditions are still present in multiple locations:
    • packages/validators/src/releases/conditions/
    • packages/validators/src/jobs/conditions/
    • packages/db/src/schema/

The refactoring should be extended to:

  1. Consolidate the duplicate version condition render components
  2. Update the validator and schema layers to use column-based types consistently
🔗 Analysis chain

Line range hint 1-24: LGTM! Changes align well with the column-based logic transition.

The implementation correctly transitions from version-based to column-based logic while maintaining type safety and React best practices. All props are properly passed to the new ColumnConditionRender component.

Let's verify that all version-based components have been consistently updated across the codebase:


Let me gather more information about the implementation of these components to verify the consistency of the transition.


Let me check one final aspect about the version-specific types and conditions without the typescript filter.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent transition from version-based to column-based components
# Test 1: Search for any remaining VersionOperatorType usage
echo "Checking for remaining VersionOperatorType usage..."
rg "VersionOperatorType"

# Test 2: Search for any remaining VersionConditionRender components
echo "Checking for remaining VersionConditionRender components..."
rg "VersionConditionRender"

# Test 3: Verify ColumnOperatorType is used consistently
echo "Checking ColumnOperatorType usage in condition components..."
rg -A 2 "ColumnOperatorType.*condition"

Length of output: 2201


Script:

#!/bin/bash
# Check the implementation of ReleaseVersionConditionRender and JobReleaseVersionConditionRender
echo "Checking ReleaseVersionConditionRender implementation..."
ast-grep --pattern 'export const ReleaseVersionConditionRender: React.FC<$_> = $_'

echo "Checking JobReleaseVersionConditionRender implementation..."
ast-grep --pattern 'export const JobReleaseVersionConditionRender: React.FC<$_> = $_'

# Check if there are any other version-specific operators or conditions still in use
echo "Checking for version-specific types and conditions..."
rg -A 2 "Version.*Type|Version.*Condition" --type typescript

Length of output: 5393


Script:

#!/bin/bash
# Check for version-specific types and conditions in all files
echo "Checking for version-specific types and conditions..."
rg -A 2 "Version.*Type|Version.*Condition"

# Check imports of version-related types
echo "Checking version-related type imports..."
rg -A 1 "import.*Version.*from.*validators"

Length of output: 13398

apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ReleaseVersionConditionRender.tsx (1)

18-26: Consider enhancing the version title for clarity.

The component migration to ColumnConditionRender is well-implemented. However, consider making the title more descriptive, such as "Release Version" instead of just "Version", to provide better context to users.

-      title="Version"
+      title="Release Version"
apps/webservice/src/app/[workspaceSlug]/_components/target-condition/IdentifierConditionRender.tsx (1)

7-9: Consider adding runtime prop validation.

While the TypeScript types provide compile-time safety, consider adding runtime prop validation using PropTypes or a schema validation library to catch potential issues during development and testing.

Example implementation:

import PropTypes from 'prop-types';

// After the component definition
IdentifierConditionRender.propTypes = {
  condition: PropTypes.shape({
    operator: PropTypes.string.isRequired,
    value: PropTypes.string.isRequired
  }).isRequired,
  onChange: PropTypes.func.isRequired,
  className: PropTypes.string
};
packages/validators/src/conditions/index.ts (2)

12-17: Add JSDoc comments to document operator behaviors.

Consider adding JSDoc comments to document the expected behavior and use cases for each operator in the ColumnOperator enum. This would help other developers understand when to use each operator.

 export enum ColumnOperator {
+  /** Exact match comparison */
   Equals = "equals",
+  /** Case-sensitive substring match */
   Like = "like",
+  /** Regular expression pattern match */
   Regex = "regex",
 }

33-35: Consider alternative patterns for initialization order.

The current solution of keeping the schema here due to initialization order issues could be improved. Consider using a factory pattern or lazy initialization to resolve the circular dependency.

Example approach:

// In a separate file (e.g., operators.ts)
export const createVersionCondition = (columnOperator: z.ZodType) => z.object({
  type: z.literal("version"),
  operator: columnOperator,
  value: z.string().min(1),
});
packages/validators/src/targets/conditions/comparison-condition.ts (1)

Line range hint 1-44: Consider adding JSDoc documentation for the schema and type.

While the implementation is correct, adding JSDoc documentation would improve maintainability by explaining:

  • The purpose of the comparison condition
  • The role of the identifier condition in the comparison
  • Examples of valid condition structures

Here's a suggested documentation:

+/**
+ * Schema for validating comparison conditions that combine multiple conditions with logical operators.
+ * Supports metadata, kind, name, provider, and identifier conditions.
+ * @example
+ * {
+ *   type: "comparison",
+ *   operator: "and",
+ *   conditions: [
+ *     { type: "identifier", ... },
+ *     { type: "metadata", ... }
+ *   ]
+ * }
+ */
export const comparisonCondition: z.ZodType<ComparisonCondition> = z.lazy(() =>

+/**
+ * Type definition for a comparison condition that combines multiple conditions with logical operators.
+ * @property {string} type - Always "comparison"
+ * @property {("and"|"or")} operator - Logical operator to combine conditions
+ * @property {boolean} [not] - Optional flag to negate the entire comparison
+ * @property {Array<Condition>} conditions - Array of conditions to combine
+ */
export type ComparisonCondition = {
apps/webservice/src/app/[workspaceSlug]/_components/filter/ColumnConditionRender.tsx (2)

14-21: Consider strengthening type definitions.

The props type could be more specific to improve type safety:

  • value could be constrained to a more specific string type based on the operator
  • className could use a more semantic type like React.HTMLAttributes<HTMLDivElement>['className']
 type ColumnConditionRenderProps = {
   operator: ColumnOperatorType;
-  value: string;
+  value: string; // TODO: Consider union type based on operator
   setOperator: (operator: ColumnOperatorType) => void;
   setValue: (value: string) => void;
   title: string;
-  className?: string;
+  className?: React.HTMLAttributes<HTMLDivElement>['className'];
 };

Line range hint 31-63: Consider these UI/UX improvements.

  1. The grid layout uses hardcoded column spans which might not be responsive on smaller screens
  2. The placeholder logic could be extracted to a separate function for better maintainability
  3. The cursor-pointer class on the Input component seems unnecessary for a text input

Consider this refactoring:

+const getPlaceholder = (operator: ColumnOperatorType): string => {
+  switch (operator) {
+    case ColumnOperator.Regex:
+      return "^[a-zA-Z]+$";
+    case ColumnOperator.Like:
+      return "%value%";
+    default:
+      return "Value";
+  }
+};

 export const ColumnConditionRender: React.FC<ColumnConditionRenderProps> = ({
   // ...props
 }) => (
-  <div className="grid w-full grid-cols-12">
+  <div className="grid w-full grid-cols-12 md:grid-cols-12 sm:grid-cols-1">
     {/* ... */}
     <div className="col-span-7">
       <Input
-        placeholder={
-          operator === ColumnOperator.Regex
-            ? "^[a-zA-Z]+$"
-            : operator === ColumnOperator.Like
-              ? "%value%"
-              : "Value"
-        }
+        placeholder={getPlaceholder(operator)}
         value={value}
         onChange={(e) => setValue(e.target.value)}
-        className="w-full cursor-pointer rounded-l-none"
+        className="w-full rounded-l-none"
       />
     </div>
   </div>
 );
apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionRender.tsx (2)

83-90: Consider reordering conditions for better maintainability.

The identifier condition check is added at the end of all conditions. Consider grouping similar conditions together (e.g., all identifier-related conditions) to improve code organization and maintainability.

Consider moving this condition block next to similar condition checks (e.g., near isNameCondition or other identifier-related conditions) to maintain logical grouping.


Line range hint 22-25: Update component documentation.

The component's documentation comment about minimum width requirement could be enhanced to explain why this requirement exists and how it affects the new identifier condition rendering.

Consider expanding the documentation to include:

  • Rationale for the minimum width requirement
  • Impact on different condition types including the new identifier condition
  • Any specific layout considerations for implementers
packages/validators/src/releases/conditions/release-condition.ts (1)

Line range hint 13-17: Consider deprecating version-based types and functions.

Given the transition from version-based to column-based logic mentioned in the PR summary, consider:

  1. Marking version-related types and functions as deprecated
  2. Adding migration documentation for users
  3. Planning the complete removal of version-based logic in a future PR

This will help users transition to the new column-based approach smoothly.

Also applies to: 71-73

packages/db/src/schema/release.ts (1)

233-236: Consider using ColumnOperator.Regex for consistency.

While the transition to ColumnOperator enum improves type safety, the regex case should also use an enum value for consistency.

Consider updating the regex case:

  if (cond.operator === ColumnOperator.Equals)
    return eq(release.version, cond.value);
  if (cond.operator === ColumnOperator.Like)
    return like(release.version, cond.value);
-  return sql`${release.version} ~ ${cond.value}`;
+  if (cond.operator === ColumnOperator.Regex)
+    return sql`${release.version} ~ ${cond.value}`;
+  throw new Error(`Unsupported version operator: ${cond.operator}`);
apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionBadge.tsx (1)

179-189: Consider component abstraction to reduce duplication.

The implementation is correct and consistent with other condition components. However, there's an opportunity to reduce code duplication since StringifiedIdentifierCondition and StringifiedNameCondition share identical structure and behavior.

Consider creating a shared base component:

const StringifiedBasicCondition: React.FC<{
  condition: { operator: TargetOperator; value: string };
  label: string;
}> = ({ condition, label }) => (
  <ConditionBadge>
    <span className="text-white">{label}</span>
    <span className="text-muted-foreground">
      {operatorVerbs[condition.operator]}
    </span>
    <span className="text-white">{condition.value.replace(/%/g, "")}</span>
  </ConditionBadge>
);

// Then reuse it:
const StringifiedIdentifierCondition: React.FC<{
  condition: IdentifierCondition;
}> = ({ condition }) => (
  <StringifiedBasicCondition condition={condition} label="Identifier" />
);
packages/db/src/schema/target.ts (1)

205-212: Handle unexpected TargetFilterType values explicitly

In the buildCondition function, various cond.type cases are handled. However, if cond.type is an unexpected value, the function may proceed without proper handling. Consider adding an explicit else clause or throwing an error to handle unsupported TargetFilterType values, improving code robustness and readability.

Apply this diff to add error handling:

 if (cond.type === TargetFilterType.Identifier)
   return buildIdentifierCondition(tx, cond);
+else
+  throw new Error(`Unsupported TargetFilterType: ${cond.type}`);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 07dce71 and f22b885.

📒 Files selected for processing (25)
  • apps/webservice/src/app/[workspaceSlug]/_components/filter/ColumnConditionRender.tsx (3 hunks)
  • apps/webservice/src/app/[workspaceSlug]/_components/job-condition/JobComparisonConditionRender.tsx (1 hunks)
  • apps/webservice/src/app/[workspaceSlug]/_components/job-condition/JobConditionBadge.tsx (1 hunks)
  • apps/webservice/src/app/[workspaceSlug]/_components/job-condition/VersionConditionRender.tsx (1 hunks)
  • apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ComparisonConditionRender.tsx (2 hunks)
  • apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ReleaseConditionBadge.tsx (1 hunks)
  • apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ReleaseVersionConditionRender.tsx (1 hunks)
  • apps/webservice/src/app/[workspaceSlug]/_components/target-condition/ComparisonConditionRender.tsx (2 hunks)
  • apps/webservice/src/app/[workspaceSlug]/_components/target-condition/IdentifierConditionRender.tsx (1 hunks)
  • apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionBadge.tsx (4 hunks)
  • apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionRender.tsx (3 hunks)
  • apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/FlowPolicyNode.tsx (2 hunks)
  • packages/db/src/schema/job.ts (5 hunks)
  • packages/db/src/schema/release.ts (5 hunks)
  • packages/db/src/schema/target.ts (6 hunks)
  • packages/validators/src/conditions/index.ts (2 hunks)
  • packages/validators/src/conditions/version-condition.ts (0 hunks)
  • packages/validators/src/jobs/conditions/comparison-condition.ts (1 hunks)
  • packages/validators/src/jobs/conditions/job-condition.ts (2 hunks)
  • packages/validators/src/releases/conditions/comparison-condition.ts (1 hunks)
  • packages/validators/src/releases/conditions/release-condition.ts (1 hunks)
  • packages/validators/src/targets/conditions/comparison-condition.ts (3 hunks)
  • packages/validators/src/targets/conditions/identifier-condition.ts (1 hunks)
  • packages/validators/src/targets/conditions/index.ts (1 hunks)
  • packages/validators/src/targets/conditions/target-condition.ts (4 hunks)
💤 Files with no reviewable changes (1)
  • packages/validators/src/conditions/version-condition.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/validators/src/releases/conditions/comparison-condition.ts
🔇 Additional comments (46)
packages/validators/src/targets/conditions/identifier-condition.ts (3)

1-3: LGTM! Imports are correctly defined.

The necessary dependencies are imported, and the .js extension is correctly used for local imports in an ESM context.


1-15: Verify integration with the existing condition system.

Let's verify that this new condition type is properly integrated with the existing condition system.

#!/bin/bash
# Description: Check integration points with the existing condition system

# Test 1: Check if the condition is exported from the conditions index
rg "export.*identifier-condition" "packages/validators/src/targets/conditions/index.ts"

# Test 2: Check if IdentifierCondition is included in union types
rg "IdentifierCondition.*\|" "packages/validators/src/targets/"

7-7: Verify the imported columnOperator schema.

Let's verify that the imported columnOperator schema contains appropriate operators for identifier comparisons.

✅ Verification successful

The columnOperator schema is properly defined with appropriate operators for identifier comparisons

The columnOperator schema is correctly defined in conditions/index.ts and includes three appropriate operators for identifier comparisons:

  • equals: For exact matches
  • like: For pattern matching
  • regex: For regular expression matching
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the definition of columnOperator to ensure it has appropriate operators

# Test: Search for columnOperator definition
rg -A 10 "export const columnOperator = " "packages/validators/src/conditions/"

Length of output: 194


Script:

#!/bin/bash
# Let's try to find the columnOperator definition with a broader search
rg "columnOperator" packages/validators/src/ -A 5

# Also search for any operator-related type definitions
ast-grep --pattern 'type $_ = { operator: $_ }'

# Let's also check imports in the identifier-condition file
rg "import.*columnOperator" packages/validators/src/

Length of output: 2700


Script:

#!/bin/bash
# Let's find the ColumnOperator enum definition
rg "enum ColumnOperator" packages/validators/src/ -A 5

Length of output: 409

apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ReleaseVersionConditionRender.tsx (2)

1-4: LGTM: Import changes align with column-based transition.

The addition of ColumnOperatorType while retaining VersionCondition correctly supports the transition to column-based logic while maintaining type safety for version-specific conditions.


13-14: Verify operator type compatibility across usages.

The operator type change looks good, but let's verify that all possible values of condition.operator are compatible with ColumnOperatorType.

✅ Verification successful

Let me gather more specific information about the operator types and their usage.


Let me check the specific implementation of ColumnOperatorType to verify compatibility.


Let me check one final piece - the ColumnOperator enum definition to ensure complete type compatibility.


Type compatibility verified for operator changes

The operator type change is safe and correct. The setOperator function in ReleaseVersionConditionRender correctly uses ColumnOperatorType, which is derived from the ColumnOperator enum containing exactly the expected values: "equals", "like", and "regex". This matches the type used in the VersionCondition type and maintains type safety throughout the component.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining version operator references and verify column operator usage
# Expected: No references to version operators in the codebase

# Search for any remaining version operator references
rg -i 'versionoperator' 

# Search for column operator usage in condition contexts
ast-grep --pattern 'condition.operator'

Length of output: 29195


Script:

#!/bin/bash
# Search for operator type definitions and their usage in the codebase
# This will help verify compatibility between ColumnOperatorType and other operator types

# Search for operator type definitions
rg -A 5 "type.*Operator.*=" 

# Search for specific operator imports and usage in the ReleaseVersionConditionRender component
rg -l "ColumnOperatorType" 

Length of output: 2818


Script:

#!/bin/bash
# Check the implementation of ColumnOperatorType and its usage in ReleaseVersionConditionRender

# Get the definition of ColumnOperatorType
rg -A 10 "const columnOperator = " 

# Get the implementation of ReleaseVersionConditionRender
cat "apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ReleaseVersionConditionRender.tsx"

Length of output: 1732


Script:

#!/bin/bash
# Get the definition of ColumnOperator enum
rg -A 5 "enum ColumnOperator"

# Also check if VersionCondition type uses the same operator type
rg -A 5 "type VersionCondition ="

Length of output: 529

apps/webservice/src/app/[workspaceSlug]/_components/target-condition/IdentifierConditionRender.tsx (1)

1-6: LGTM! Well-structured imports.

The imports are properly organized, using type imports where appropriate and maintaining clear separation between external and internal dependencies.

packages/validators/src/conditions/index.ts (2)

36-42: LGTM! Well-structured schema definition.

The version condition schema is well-defined with proper validation:

  • Enforces literal type checking
  • Uses the column operator validation
  • Ensures non-empty string values

1-4: Verify complete transition from version-based logic.

While the version-condition.js export has been removed, we still have version-related code in this file. Let's verify that this is intentional and that no other files still depend on the removed export.

packages/validators/src/targets/conditions/comparison-condition.ts (3)

4-4: LGTM: Import statements are properly organized.

The imports for both the type and schema of IdentifierCondition are correctly added, maintaining consistency with the existing pattern of importing both types and their corresponding schemas.

Also applies to: 9-9


42-42: LGTM: Type definition is properly updated.

The IdentifierCondition type is correctly added to the union type, ensuring type safety at compile time.


26-26: LGTM: Schema union is correctly extended.

The identifierCondition schema is properly added to the union of conditions, maintaining type safety through Zod's runtime validation.

Let's verify the schema implementation:

✅ Verification successful

Schema implementation and integration verified successfully

The identifierCondition schema is correctly implemented using Zod and properly integrated into the comparisonCondition union. The schema defines:

  • A literal "identifier" type
  • An operator using the imported columnOperator
  • A non-empty string value
  • Proper type exports using Zod inference
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the identifier-condition.ts file exists and exports the expected schema
# Expected: File exists and exports both the type and schema

# Check if the file exists and contains the exports
rg -l "export const identifierCondition.*=.*z\." "identifier-condition.ts"
rg -l "export (type|interface) IdentifierCondition" "identifier-condition.ts"

Length of output: 280


Script:

#!/bin/bash
# Let's search for the identifier-condition file in the entire repository
fd "identifier-condition" --type f

# Let's also check the comparison-condition.ts file to understand the context
fd "comparison-condition.ts" --type f --exec cat {}

Length of output: 4125


Script:

#!/bin/bash
# Let's check the identifier-condition.ts file to verify its schema implementation
cat packages/validators/src/targets/conditions/identifier-condition.ts

Length of output: 457

packages/validators/src/jobs/conditions/comparison-condition.ts (3)

6-6: LGTM: Import consolidation improves maintainability

The consolidation of imports through the index file aligns with best practices for better maintainability and easier refactoring.

Also applies to: 15-15


Line range hint 23-35: LGTM: Schema definition is consistent with types

The addition of versionCondition to the schema's union type is properly implemented and maintains consistent ordering.


Line range hint 37-53: LGTM: Type definition aligns with schema changes

The addition of VersionCondition to the union type is consistent with the schema definition. However, since this is part of a broader refactor from version-based to column-based logic, let's verify the integration.

✅ Verification successful

LGTM: Version condition integration is properly implemented

The verification shows that the VersionCondition type is well-integrated across the codebase:

  • Properly imported and used in both job and release condition schemas
  • Implemented in the database layer with column-based operators (Like, Equals)
  • Has corresponding UI components for rendering and handling version conditions
  • Type guards and condition builders are in place for proper type safety

The transition to column-based logic is complete and consistent across the validators, database, and UI layers.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the transition from version-based to column-based logic
# Expected: No remaining references to version-specific operators or old version condition imports

# Check for any remaining version-specific operators
echo "Checking for version-specific operators..."
rg -g '!*.{md,json}' "VersionOperator"

# Check for direct imports from version-condition file
echo "Checking for direct version-condition imports..."
rg -g '!*.{md,json}' "from ['\"].*version-condition['\"]"

Length of output: 304


Script:

#!/bin/bash
# Let's try a different approach to verify the transition
# 1. Find all files that might contain version-related code
# 2. Check the version condition implementation
# 3. Look for any version-related imports or types

# Find the version condition implementation
echo "Version condition implementation:"
ast-grep --pattern 'type VersionCondition = {
  $$$
}'

# Check for any version-related imports
echo -e "\nVersion-related imports:"
rg -g '!*.{md,json}' 'import.*Version.*from'

# Look for version-related type usage
echo -e "\nVersion type usage:"
rg -g '!*.{md,json}' 'Version(Condition|Operator)' -A 2

Length of output: 13802

apps/webservice/src/app/[workspaceSlug]/_components/filter/ColumnConditionRender.tsx (2)

23-30: LGTM! Clean component declaration.

The component declaration follows React best practices with proper type annotations and clean props destructuring.


23-23: Verify component name change across the codebase.

Since this component has been renamed from VersionConditionRender to ColumnConditionRender, let's verify that all imports have been updated.

✅ Verification successful

Component rename verification completed successfully

The search results show that:

  • The ColumnConditionRender component is properly imported and used in multiple components (IdentifierConditionRender, ReleaseVersionConditionRender, and VersionConditionRender)
  • The occurrences of "VersionConditionRender" in the codebase are different components (ReleaseVersionConditionRender and JobReleaseVersionConditionRender) and not remnants of the old component name
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining references to the old component name
rg "VersionConditionRender" --type tsx --type ts

# Search for imports of the new component name to ensure it's being used
rg "ColumnConditionRender" --type tsx --type ts

Length of output: 152


Script:

#!/bin/bash
# Search for any remaining references to the old component name without file type restrictions
rg "VersionConditionRender"

# Search for imports of the new component name
rg "ColumnConditionRender"

Length of output: 2145

packages/validators/src/releases/conditions/release-condition.ts (2)

10-10: LGTM! Import consolidation is consistent.

The consolidation of condition imports aligns with the type imports and improves code organization.

#!/bin/bash
# Description: Verify that the imported conditions are properly used

# Test: Check usage of metadataCondition and versionCondition
rg -A 2 "metadataCondition|versionCondition" --type typescript

4-7: Verify complete migration of VersionCondition.

The import consolidation looks good, but let's verify that the version-condition.js file has been properly migrated and removed.

✅ Verification successful

Import consolidation is correct and properly implemented

The verification shows that VersionCondition type and its schema are directly defined in conditions/index.ts. The import consolidation in the review is correct as there's a comment in index.ts explicitly stating why the version condition needs to be defined there due to initialization dependencies with columnOperator.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that version-condition.js has been removed and all its contents properly migrated

# Test 1: Check if version-condition.js still exists
fd "version-condition.js"

# Test 2: Verify VersionCondition is properly exported from index.js
rg -l "export.*VersionCondition" "conditions/index.js"

Length of output: 349


Script:

#!/bin/bash
# Let's try a more comprehensive search approach

# Search for any file containing VersionCondition
rg -l "VersionCondition"

# Search for files with "condition" in their name
fd "condition"

# Look for exports of VersionCondition in any file
rg "export.*VersionCondition"

# Search for type definitions of VersionCondition
ast-grep --pattern 'type VersionCondition = $_'

Length of output: 6431


Script:

#!/bin/bash
# Let's verify the content of version-condition.ts and index.ts to ensure proper migration

# Check the content of version-condition.ts
cat packages/validators/src/conditions/version-condition.ts

# Check the content of index.ts
cat packages/validators/src/conditions/index.ts

# Check if version-condition.ts is imported in index.ts
rg -A 2 "from.*version-condition" packages/validators/src/conditions/index.ts

Length of output: 1228

packages/validators/src/targets/conditions/target-condition.ts (6)

5-5: LGTM: Import statements are properly structured.

The new imports for identifier-related modules follow the established pattern and maintain consistency with other condition imports.

Also applies to: 11-11


21-22: LGTM: Type definition is properly extended.

The IdentifierCondition is correctly added to the TargetCondition union type, maintaining alphabetical ordering and consistent formatting.


30-30: LGTM: Schema validation is properly updated.

The identifierCondition schema is correctly added to the targetCondition union schema, maintaining consistency with the type system.


46-46: LGTM: Enum is properly extended.

The Identifier value is correctly added to the TargetFilterType enum, maintaining alphabetical ordering and consistent naming conventions.


102-105: LGTM: Type guard function is properly implemented.

The isIdentifierCondition type guard follows the established pattern and correctly implements the type predicate.


115-115: Verify the validation logic for all condition types.

The simplified validation logic assumes all non-metadata conditions have a value property. Let's verify this assumption.

✅ Verification successful

The validation logic is safe and correct for all condition types

Based on the search results, all non-metadata condition types in the target conditions (KindCondition, NameCondition, ProviderCondition, IdentifierCondition) have a mandatory value property of type string with a minimum length of 1. This is enforced through their Zod schemas:

  • kindCondition: value: z.string().min(1)
  • nameCondition: value: z.string().min(1)
  • providerCondition: value: z.string().min(1)
  • identifierCondition: value: z.string().min(1)

Therefore, checking condition.value.length > 0 is a valid validation as all these conditions require a non-empty string value.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all non-metadata condition types have a 'value' property
# and that this property is always a string array or string.

# Search for condition type definitions
echo "Searching for condition type definitions..."
ast-grep --pattern 'export type $condition = {
  type: TargetFilterType.$_;
  $$$
  value: $_; 
  $$$
}'

# Search for condition schema definitions to verify value validation
echo "Searching for condition schema definitions..."
rg -A 5 'export const \w+Condition = z\.object\({'

Length of output: 501


Script:

#!/bin/bash
# Let's try a different approach to find condition types and their validation

# Search for condition type definitions
echo "=== Condition Type Definitions ==="
rg -A 10 "export\s+type.*Condition\s*=\s*{" --type typescript

# Search for condition schemas with fixed regex
echo -e "\n=== Condition Schemas ==="
rg -A 10 "export const.*Condition = z\.object" --type typescript

# Search for usage of value property in conditions
echo -e "\n=== Value Property Usage ==="
rg "value:" --type typescript packages/validators/src/targets/conditions/

Length of output: 621


Script:

#!/bin/bash
# Let's try without typescript file type and escape the curly brace

# Search for condition type definitions
echo "=== Condition Type Definitions ==="
rg -A 10 'export type.*Condition = \{'

# Search for condition schemas
echo -e "\n=== Condition Schemas ==="
rg -A 10 'export const.*Condition = z.object'

# Search for value property usage
echo -e "\n=== Value Property Usage ==="
rg "value:" packages/validators/src/targets/conditions/

Length of output: 14015

packages/validators/src/jobs/conditions/job-condition.ts (5)

6-6: LGTM: Import changes are well-organized

The addition of VersionCondition type and versionCondition imports from the consolidated index.js follows good module organization practices.

Also applies to: 20-20


Line range hint 29-35: LGTM: Type definition changes are consistent

The VersionCondition type is properly integrated into the JobCondition union type, maintaining a clean and organized type hierarchy.


Line range hint 37-44: LGTM: Schema changes maintain type-runtime consistency

The addition of versionCondition to the Zod union schema ensures proper runtime validation that matches the type system changes.


Line range hint 1-95: Verify impact of version to column-based logic transition

The AI summary mentions transitioning from version-based to column-based logic. Let's verify that this change doesn't break existing version handling code.

✅ Verification successful

Version condition implementation is consistent and properly integrated

The verification shows that the version condition is properly implemented and integrated:

  • Version condition is defined with column operator in conditions/index.ts
  • It's consistently used in both job and release conditions
  • The implementation maintains proper type safety through TypeScript types
  • Version handling is properly validated through isValidReleaseCondition
  • No TODO/FIXME comments indicating pending version-related changes

The transition to column-based logic appears to be complete and consistent across the codebase, with no signs of breaking changes to existing version handling.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Look for existing version-related code that might be affected
# Expected: Find related version handling code to assess impact

# Search for version-related conditions and handlers
rg -l 'version.*condition|condition.*version' --type ts

# Search for any TODO or FIXME comments related to version handling
rg -i 'todo.*version|fixme.*version' --type ts

Length of output: 239


Script:

#!/bin/bash
# Let's examine the version condition usage and implementation

# Check the version condition implementation
ast-grep --pattern 'export const versionCondition = $_'

# Look for version-related types and interfaces
ast-grep --pattern 'export (type|interface) $_Version'

# Check for version-related imports and usages
rg -A 5 'import.*version|from.*version' --type ts

# Check the actual implementation in the found files
cat packages/validators/src/releases/conditions/release-condition.ts
cat packages/validators/src/releases/conditions/comparison-condition.ts

Length of output: 6982


Line range hint 89-91: Verify FilterType.Version enum value

The type guard implementation looks correct, but let's verify that FilterType.Version is properly defined in the imported types.

✅ Verification successful

FilterType.Version is properly defined and used correctly

The verification confirms that:

  1. FilterType.Version is properly defined in the conditions module (packages/validators/src/conditions/index.ts)
  2. FilterType is correctly imported and used in the job conditions module
  3. The isVersionCondition type guard correctly uses FilterType.Version for type checking
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify FilterType.Version is defined in the conditions module
# Expected: Find the Version enum value definition

# Search for FilterType enum definition
rg -A 10 "export enum FilterType" 

Length of output: 239


Script:

#!/bin/bash
# Let's try different approaches to find FilterType enum definition

# Search for FilterType in all TypeScript files
rg "FilterType" --type ts -B 2 -A 5

# Also search for any enum containing Version
rg "enum.*\{[^}]*Version" --type ts -A 5

# Search for files containing JobFilterType specifically
rg "JobFilterType" --type ts -B 2 -A 5

Length of output: 90454


Script:

#!/bin/bash
# Let's check the FilterType enum definition in the conditions module
rg "FilterType.*=.*Version" --type ts -B 2 -A 2

# Also check the import of FilterType in the job-condition file
rg "import.*FilterType.*from.*conditions" --type ts -A 3

Length of output: 108


Script:

#!/bin/bash
# Let's look at the conditions/index.ts file directly since we saw it in previous results
cat packages/validators/src/conditions/index.ts

# Also check the imports in job-condition.ts
cat packages/validators/src/jobs/conditions/job-condition.ts

Length of output: 5137

apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ReleaseConditionBadge.tsx (1)

178-178: Consider handling data transformation at the data layer instead of the UI layer.

While the change removes '%' characters from version values, performing data transformations at the UI level might mask underlying data quality issues. Consider these architectural improvements:

  1. Move the transformation logic to a data processing layer
  2. Add type validation for condition.value
  3. Document why '%' characters need to be removed

Example implementation at the data layer:

// types/version.ts
export interface VersionCondition {
  value: string;
  operator: VersionOperator;
}

// utils/version.ts
export const sanitizeVersionValue = (value: string): string => {
  return value.replace(/%/g, '');
};

// Then in the component:
<span className="text-white">{sanitizeVersionValue(condition.value)}</span>

Let's verify if this pattern of removing '%' is consistent across other components:

packages/db/src/schema/job.ts (3)

35-39: LGTM: Clean operator type imports.

The new imports align well with the transition from version-based to column-based logic, improving the overall clarity of the filtering system.


Line range hint 142-180: LGTM: Well-structured metadata condition handling.

The implementation properly handles all metadata operator types (Null, Regex, Like) with appropriate SQL query construction. The code maintains good error handling through type checking and follows consistent patterns.


204-207: ⚠️ Potential issue

Security: Validate regex patterns before using in SQL queries.

The current implementation might be vulnerable to SQL injection or ReDoS attacks through malicious regex patterns. Consider adding safety measures:

  1. Validate regex patterns before using them in queries
  2. Implement a timeout mechanism for regex operations
  3. Consider using parameterized queries instead of raw SQL templates

Let's check if there are any regex pattern validations elsewhere in the codebase:

Consider adding pattern validation:

 const buildVersionCondition = (cond: VersionCondition): SQL => {
   if (cond.operator === ColumnOperator.Like)
     return like(release.version, cond.value);
-  if (cond.operator === ColumnOperator.Regex)
-    return sql`${release.version} ~ ${cond.value}`;
+  if (cond.operator === ColumnOperator.Regex) {
+    try {
+      // Validate regex pattern
+      new RegExp(cond.value);
+      return sql`${release.version} ~ ${cond.value}`;
+    } catch (e) {
+      throw new Error(`Invalid regex pattern: ${cond.value}`);
+    }
+  }
   return eq(release.version, cond.value);
 };
packages/db/src/schema/release.ts (2)

35-37: LGTM! Good transition to typed enums.

The switch from string literals to proper enums (ColumnOperator and MetadataOperator) improves type safety and maintainability.


Line range hint 168-195: LGTM! Verify operator coverage.

The transition to MetadataOperator enum improves type safety while maintaining the existing logic.

Let's verify we're handling all possible metadata operators:

✅ Verification successful

All metadata operators are properly handled

The verification confirms that all MetadataOperator enum values are covered in the code:

  • MetadataOperator.Null → handled with notExists
  • MetadataOperator.Regex → handled with exists and regex match
  • MetadataOperator.Like → handled with exists and LIKE match
  • MetadataOperator.Equals → implicitly handled as the default case (since it's optional in the schema)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all MetadataOperator enum values are handled in buildMetadataCondition

# Test: Search for MetadataOperator enum definition and compare with usage
echo "=== MetadataOperator enum definition ==="
rg --type typescript "export enum MetadataOperator" -A 10

echo -e "\n=== MetadataOperator usage in buildMetadataCondition ==="
rg --type typescript "MetadataOperator\." packages/db/src/schema/release.ts

Length of output: 546


Script:

#!/bin/bash
# Let's try a different approach using basic grep commands

# Find the MetadataOperator enum definition
echo "=== MetadataOperator enum definition ==="
find . -type f -name "*.ts" -exec grep -l "enum MetadataOperator" {} \; | xargs cat

# Find operator usage in release.ts
echo -e "\n=== MetadataOperator usage in release.ts ==="
find . -type f -name "release.ts" -exec grep -A 1 "MetadataOperator\." {} \;

Length of output: 2203

apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionBadge.tsx (3)

4-4: LGTM: Import additions are well-organized.

The new imports for IdentifierCondition type and isIdentifierCondition function are properly grouped with related imports and follow the established naming patterns.

Also applies to: 22-22


236-237: LGTM: Clean integration of identifier condition handling.

The integration follows the established pattern and is properly placed in the sequence of condition checks.


236-238: Verify integration with related components.

The changes look good, but let's verify the integration with related components mentioned in the summary.

✅ Verification successful

Integration is properly implemented across components

The verification shows that the identifier condition handling is correctly integrated:

  • StringifiedIdentifierCondition is properly used in TargetConditionBadge.tsx
  • isIdentifierCondition is consistently used in both TargetConditionBadge.tsx and TargetConditionRender.tsx
  • The component has proper imports and type definitions from @ctrlplane/validators/targets
  • There's a dedicated IdentifierConditionRender.tsx component that's properly imported and used in the target condition system

The changes are complete and properly integrated with all related components in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of identifier condition handling across components

# Test 1: Check for IdentifierConditionRender component usage
echo "Checking for IdentifierConditionRender usage..."
rg -l "IdentifierConditionRender" --type tsx

# Test 2: Verify consistent operator handling
echo "Checking for consistent operator handling..."
rg "TargetOperator" --type tsx -A 2 -B 2

# Test 3: Look for any potential missing identifier condition handling
echo "Checking for potential missing identifier condition handling..."
rg "isIdentifierCondition" --type tsx

Length of output: 548


Script:

#!/bin/bash
# Let's try without the --type flag since tsx extension might not be recognized

# Test 1: Check for StringifiedIdentifierCondition component usage
echo "Checking for StringifiedIdentifierCondition usage..."
rg "StringifiedIdentifierCondition"

# Test 2: Check for isIdentifierCondition usage
echo "Checking for isIdentifierCondition usage..."
rg "isIdentifierCondition"

# Test 3: Look for any identifier condition related imports
echo "Checking for identifier condition related imports..."
rg "import.*Identifier" -A 2

# Test 4: Find all files that might be related to target conditions
echo "Finding target condition related files..."
fd "condition" --extension tsx --extension ts

Length of output: 7458

apps/webservice/src/app/[workspaceSlug]/_components/job-condition/JobConditionBadge.tsx (1)

242-242: Verify the impact of removing % signs from version values.

The removal of % signs from version values could affect version comparison logic elsewhere in the codebase.

Let's check for any version comparison logic that might depend on these % characters:

✅ Verification successful

Let me check the version comparison logic to ensure we have a complete understanding.


Let me check the version condition implementation to understand how these values are used in comparisons.


Let me check the version condition specific implementation.


Based on the analysis of the codebase, I can now provide the final response:

Removing % signs from version values is safe in this context

The version condition implementation shows that versions are handled as simple string comparisons using basic operators (equals, like, regex) without any special treatment of % characters. The JobConditionBadge component is purely for display purposes and doesn't affect the underlying version comparison logic.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for version comparison logic in the codebase
echo "Searching for version-related files and comparisons..."
rg -l "version" | rg -i "compar|valid|check"

# Search for % usage in version-related code
echo "Checking for % usage in version-related code..."
rg "%" | rg -i "version"

Length of output: 1105


Script:

#!/bin/bash
# Check the comparison condition implementations
echo "Checking comparison condition implementations..."
cat packages/validators/src/releases/conditions/comparison-condition.ts
cat packages/validators/src/jobs/conditions/comparison-condition.ts

# Check the specific JobConditionBadge usage context
echo "Checking JobConditionBadge context..."
cat "apps/webservice/src/app/[workspaceSlug]/_components/job-condition/JobConditionBadge.tsx"

Length of output: 12051


Script:

#!/bin/bash
# Check the version condition implementation
echo "Checking version condition implementation..."
cat packages/validators/src/conditions/index.ts

# Also check if there are any version-related utilities
echo "Checking for version-related utilities..."
fd version packages/validators/src -t f

Length of output: 1376


Script:

#!/bin/bash
# Check the version condition specific implementation
echo "Checking version condition specific implementation..."
cat packages/validators/src/conditions/version-condition.ts

# Also check for any version pattern matching or comparison usage
echo "Checking for version pattern usage..."
rg -A 3 "version.*pattern|version.*match|version.*compar" packages/validators/src/

Length of output: 348

apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/FlowPolicyNode.tsx (2)

29-29: Verify complete transition to ColumnOperator.

The addition of ColumnOperator import aligns with the PR's objective. However, we should verify if ReleaseOperator is still needed since we're transitioning away from it.

✅ Verification successful

Both operators are currently needed - import is correct

The codebase search reveals that both ReleaseOperator and ColumnOperator are actively used in the file:

  • ReleaseOperator.And is used for the top-level filter combination
  • ColumnOperator.Equals is used for the version comparison

This is a valid transitional state where ReleaseOperator handles logical operations (AND/OR) while ColumnOperator handles the actual comparisons. The import of both operators is necessary and correct.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining usage of ReleaseOperator in the codebase
rg "ReleaseOperator\." --type ts --type tsx

Length of output: 195


Script:

#!/bin/bash
# Search for ReleaseOperator usage with correct file type specification
rg "ReleaseOperator\." -t typescript -t tsx

# Also search for the file content to understand the context better
cat "apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/FlowPolicyNode.tsx"

# Search for any imports of ReleaseOperator
rg "import.*ReleaseOperator" -t typescript -t tsx

Length of output: 9596


Script:

#!/bin/bash
# Try with different file extensions for ripgrep
rg "ReleaseOperator\." --type-add 'ts:*.{ts,tsx}' -t ts

# Search for actual usage of both operators in the file
rg "operator: (ReleaseOperator|ColumnOperator)\." --type-add 'ts:*.{ts,tsx}' -t ts

Length of output: 5338


134-137: Verify API compatibility with ColumnOperator.

The change from ReleaseOperator.Equals to ColumnOperator.Equals looks correct, but we should ensure:

  1. The release.list.useQuery endpoint is updated to handle ColumnOperator
  2. The version comparison logic remains compatible with this operator change
✅ Verification successful

Based on the code analysis, I can now provide a definitive response about the operator change from ReleaseOperator.Equals to ColumnOperator.Equals.

The operator change is correct and consistent with the codebase.

The codebase shows that:

  1. ColumnOperator.Equals is the correct operator for version comparisons, as seen in packages/db/src/schema/release.ts where buildVersionCondition function explicitly handles ColumnOperator.Equals for version comparisons.
  2. The version filter type is properly handled in the database layer with ReleaseFilterType.Version and ColumnOperator combinations.
  3. The change aligns with the validator definitions in packages/validators/src/conditions/index.ts where ColumnOperator is defined for such comparisons.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the API endpoint definition to verify operator handling
ast-grep --pattern 'export const list = procedure
  .input($_)
  .query(async ({ input }) => {
    $$$
  })'

# Check for any version-specific handling in the codebase
rg "ReleaseFilterType.Version" --type ts --type tsx -A 5

Length of output: 195


Script:

#!/bin/bash
# Search for the API endpoint definition with a more flexible pattern
ast-grep --pattern 'export const list = $_'

# Search for version-specific handling with correct file extensions
rg "ReleaseFilterType.Version" -t ts -t typescript -A 5

# Look for ColumnOperator usage to verify the transition
rg "ColumnOperator" -t ts -t typescript -A 5

# Search for release-related router/endpoint definitions
fd "release.*router.ts" --type f --exec cat {}

Length of output: 267


Script:

#!/bin/bash
# Search for files with .ts extension and look for patterns
find . -type f -name "*.ts" -o -name "*.tsx" | while read -r file; do
  echo "=== $file ==="
  grep -A 5 "ReleaseFilterType\|ColumnOperator\|export const list" "$file" 2>/dev/null
done

# Find and examine router files specifically
find . -type f -name "*release*.ts" -o -name "*release*.tsx" | while read -r file; do
  echo "=== $file ==="
  cat "$file"
done

Length of output: 233232

apps/webservice/src/app/[workspaceSlug]/_components/release-condition/ComparisonConditionRender.tsx (2)

33-33: LGTM: Import aligns with column-based logic transition.

The addition of ColumnOperator import aligns with the PR's objective of transitioning from version-based to column-based logic.


292-292: Verify consistent operator usage across version conditions.

The change from ReleaseOperator.Equals to ColumnOperator.Equals for version comparison aligns with the column-based logic transition.

Let's verify that this change is consistent across all version-related conditions:

✅ Verification successful

All version conditions consistently use ColumnOperator.Equals

The verification shows that all version-related conditions in the codebase have been updated to use ColumnOperator.Equals. No instances of ReleaseOperator.Equals were found with ReleaseFilterType.Version, confirming consistent operator usage across version conditions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining ReleaseOperator.Equals usage with version conditions
# Expect: No occurrences of ReleaseOperator.Equals with ReleaseFilterType.Version

rg -U "type:\s*ReleaseFilterType\.Version[^}]*operator:\s*ReleaseOperator\.Equals"

# Also check for the new pattern to ensure consistency
rg -U "type:\s*ReleaseFilterType\.Version[^}]*operator:\s*ColumnOperator\.Equals"

Length of output: 828

apps/webservice/src/app/[workspaceSlug]/_components/target-condition/ComparisonConditionRender.tsx (2)

33-33: LGTM: Import statement is correctly placed and used.

The new import for ColumnOperator aligns with the codebase's transition to column-based logic.


296-306: Implementation looks good, verify operator consistency.

The new Identifier filter implementation is well-structured and follows the existing patterns. The use of ColumnOperator.Like aligns with the codebase's transition to column-based logic.

Let's verify that other components handling identifier conditions consistently use ColumnOperator.Like:

✅ Verification successful

Let me gather more information to verify the operator consistency across the codebase.

This will help us understand:

  1. How TargetFilterType.Identifier is used in different contexts
  2. The pattern of ColumnOperator.Like usage across the codebase
  3. Whether there's consistency in operator usage for identifier conditions

Implementation is correct and consistent with codebase patterns

The verification confirms that the use of ColumnOperator.Like for the Identifier filter is correct and consistent with the codebase implementation:

  1. The database layer (packages/db/src/schema/target.ts) properly handles ColumnOperator.Like for identifier conditions through the buildIdentifierCondition function
  2. The validator layer (packages/validators/src/conditions/index.ts) includes ColumnOperator.Like in the schema
  3. Similar column-based filtering patterns using ColumnOperator.Like are used in other parts of the codebase (version conditions, column conditions)

The implementation aligns with the codebase's column-based filtering approach and maintains consistency across all layers.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other identifier condition handling to verify operator consistency
rg -l "type: TargetFilterType.Identifier" | xargs rg "operator.*="

Length of output: 224


Script:

#!/bin/bash
# Search for TargetFilterType.Identifier usage with surrounding context
rg -A 5 -B 5 "TargetFilterType\.Identifier"

# Also search for any ColumnOperator.Like usage to understand the pattern
rg -A 3 -B 3 "ColumnOperator\.Like"

Length of output: 8197

apps/webservice/src/app/[workspaceSlug]/_components/job-condition/JobComparisonConditionRender.tsx (1)

346-346: LGTM! Operator change aligns with the codebase modernization.

The change from VersionOperator.Equals to ColumnOperator.Equals is consistent with the broader transition to column-based operators.

Let's verify that this transition is complete across the codebase:

✅ Verification successful

Transition to ColumnOperator.Equals is complete and consistent

The search results confirm that all version-related conditions across the codebase now use ColumnOperator.Equals instead of VersionOperator. Specifically:

  • All version condition implementations in components (JobComparisonConditionRender.tsx, ComparisonConditionRender.tsx, FlowPolicyNode.tsx) consistently use ColumnOperator.Equals
  • No occurrences of VersionOperator were found in the codebase
  • The enum definitions show ColumnOperator as the standardized operator type for column-based comparisons
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usage of VersionOperator
# Expect: No occurrences of VersionOperator, confirming complete transition

# Search for any remaining VersionOperator usage
rg "VersionOperator\." 

# Search for Version-related conditions to ensure they use ColumnOperator
ast-grep --pattern 'type: FilterType.Version'

Length of output: 72


Script:

#!/bin/bash
# Let's try a more comprehensive search approach

# Search for any Version-related enums or types
rg -i "versionoperator|version.*operator|operator.*version" -A 3 -B 3

# Search for Version filter type usage with more context
rg "FilterType\.Version" -A 5 -B 5

# Search for any files containing both Version and Operator references
rg -l "Version.*Operator|Operator.*Version"

# Look for enum definitions that might contain version operators
ast-grep --pattern 'enum $_ {
  $$$
}'

Length of output: 21743

Comment on lines 13 to 15
export type IdentifierOperator = z.infer<
typeof identifierCondition
>["operator"];
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider a more concise type definition.

The IdentifierOperator type definition can be simplified.

-export type IdentifierOperator = z.infer<
-  typeof identifierCondition
->["operator"];
+export type IdentifierOperator = IdentifierCondition["operator"];

Committable suggestion was skipped due to low confidence.

Comment on lines +14 to +23
return (
<ColumnConditionRender
operator={condition.operator}
value={condition.value}
setOperator={setOperator}
setValue={setValue}
className={className}
title="Identifier"
/>
);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider making the title configurable.

The "Identifier" title is hardcoded, which might limit component reusability. Consider making it a prop with "Identifier" as the default value.

 export const IdentifierConditionRender: React.FC<
-  TargetConditionRenderProps<IdentifierCondition>
+  TargetConditionRenderProps<IdentifierCondition> & {
+    title?: string;
+  }
- > = ({ condition, onChange, className }) => {
+ > = ({ condition, onChange, className, title = "Identifier" }) => {
   // ... rest of the component
   return (
     <ColumnConditionRender
       // ... other props
-      title="Identifier"
+      title={title}
     />
   );
 };

Committable suggestion was skipped due to low confidence.

Comment on lines +10 to +12
const setOperator = (operator: ColumnOperatorType) =>
onChange({ ...condition, operator });
const setValue = (value: string) => onChange({ ...condition, value });
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider memoizing callback functions.

To optimize performance and prevent unnecessary re-renders, consider memoizing the callback functions using useCallback.

-  const setOperator = (operator: ColumnOperatorType) =>
-    onChange({ ...condition, operator });
-  const setValue = (value: string) => onChange({ ...condition, value });
+  const setOperator = useCallback(
+    (operator: ColumnOperatorType) => onChange({ ...condition, operator }),
+    [condition, onChange]
+  );
+  const setValue = useCallback(
+    (value: string) => onChange({ ...condition, value }),
+    [condition, onChange]
+  );

Committable suggestion was skipped due to low confidence.

Comment on lines 83 to 90
if (isIdentifierCondition(condition))
return (
<IdentifierConditionRender
condition={condition}
onChange={onChange}
className={className}
/>
);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Inconsistent prop passing detected.

The IdentifierConditionRender component is receiving fewer props compared to other condition renderers. While other renderers receive onRemove and depth props, these are omitted here. This inconsistency could lead to unexpected behavior or missing functionality.

Consider applying this change to maintain consistency with other condition renderers:

  if (isIdentifierCondition(condition))
    return (
      <IdentifierConditionRender
        condition={condition}
        onChange={onChange}
+       onRemove={onRemove}
+       depth={depth}
        className={className}
      />
    );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (isIdentifierCondition(condition))
return (
<IdentifierConditionRender
condition={condition}
onChange={onChange}
className={className}
/>
);
if (isIdentifierCondition(condition))
return (
<IdentifierConditionRender
condition={condition}
onChange={onChange}
onRemove={onRemove}
depth={depth}
className={className}
/>
);

Comment on lines +35 to +37
ColumnOperator,
DateOperator,
VersionOperator,
MetadataOperator,
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Transition to enum operators is complete with one exception

The codebase shows consistent usage of ColumnOperator, MetadataOperator, and DateOperator enums across all relevant files, with only one remaining string literal operator comparison in target.ts:

  • packages/db/src/schema/target.ts: const con = cond.operator === "and" ? and(...subCon)! : or(...subCon)!;

The other string literals found are actually enum definitions themselves, not direct usage in conditions.

🔗 Analysis chain

Verify complete transition from string literals.

Let's ensure all operator string literals have been replaced with enum values across the codebase.

Also applies to: 168-195, 233-236

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any remaining operator string literals that should use enums

echo "=== Searching for potential string literal operators ==="
rg --type typescript 'operator === "(null|regex|like|equals)"' -g '!*.test.ts'

echo -e "\n=== Verifying operator enum usage ==="
rg --type typescript '(Column|Metadata)Operator\.' -g '!*.test.ts'

Length of output: 546


Script:

#!/bin/bash
# Let's try without typescript file type specification
echo "=== Searching for potential string literal operators ==="
rg 'operator\s*===\s*["\'](null|regex|like|equals)["\']' --type-add 'ts:*.ts' -t ts -g '!*.test.ts'

echo -e "\n=== Verifying operator enum usage ==="
rg '(Column|Metadata|Date)Operator\.' --type-add 'ts:*.ts' -t ts -g '!*.test.ts'

# Also search for specific operator strings that might be used in conditions
echo -e "\n=== Checking for raw operator strings ==="
rg '["\'](null|regex|like|equals)["\']' --type-add 'ts:*.ts' -t ts -g '!*.test.ts' -g '!**/migrations/*'

Length of output: 359


Script:

#!/bin/bash
# Search for string literals with simpler patterns
echo "=== Searching for operator string comparisons ==="
rg "operator\s*===\s*['\"]" --type-add 'ts:*.ts' -t ts -g '!*.test.ts'

echo -e "\n=== Verifying enum usage ==="
rg "ColumnOperator\." --type-add 'ts:*.ts' -t ts -g '!*.test.ts'
rg "MetadataOperator\." --type-add 'ts:*.ts' -t ts -g '!*.test.ts'
rg "DateOperator\." --type-add 'ts:*.ts' -t ts -g '!*.test.ts'

echo -e "\n=== Checking operator string usage ==="
rg "['\"]equals['\"]" --type-add 'ts:*.ts' -t ts -g '!*.test.ts' -g '!**/migrations/*'
rg "['\"]like['\"]" --type-add 'ts:*.ts' -t ts -g '!*.test.ts' -g '!**/migrations/*'
rg "['\"]regex['\"]" --type-add 'ts:*.ts' -t ts -g '!*.test.ts' -g '!**/migrations/*'
rg "['\"]null['\"]" --type-add 'ts:*.ts' -t ts -g '!*.test.ts' -g '!**/migrations/*'

Length of output: 13385

@@ -239,7 +239,7 @@ const StringifiedVersionCondition: React.FC<{
<span className="text-muted-foreground">
{operatorVerbs[condition.operator]}
</span>
<span className="text-white">{condition.value}</span>
<span className="text-white">{condition.value.replace(/%/g, "")}</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null check and document the purpose of removing % signs.

While removing % signs might be intentional, the code could be more robust and clearer:

  1. Add a null check to prevent runtime errors
  2. Document why % signs are being removed

Consider this safer implementation:

-    <span className="text-white">{condition.value.replace(/%/g, "")}</span>
+    <span className="text-white">
+      {condition.value?.replace(/%/g, "") ?? condition.value}
+    </span>

Also, add a comment explaining why % signs are being removed.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<span className="text-white">{condition.value.replace(/%/g, "")}</span>
<span className="text-white">
{condition.value?.replace(/%/g, "") ?? condition.value}
</span>

Comment on lines +196 to +202
const buildIdentifierCondition = (tx: Tx, cond: IdentifierCondition): SQL => {
if (cond.operator === ColumnOperator.Like)
return like(target.identifier, cond.value);
if (cond.operator === ColumnOperator.Equals)
return eq(target.identifier, cond.value);
return sql`${target.identifier} ~ ${cond.value}`;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure safe handling of cond.value in regex operation

In the buildIdentifierCondition function, when neither ColumnOperator.Like nor ColumnOperator.Equals matches, the default case returns a regex match using:

return sql`${target.identifier} ~ ${cond.value}`;

Ensure that cond.value is properly sanitized or parameterized to prevent potential SQL injection vulnerabilities, especially if it contains user-provided input.

@adityachoudhari26 adityachoudhari26 merged commit 70c090d into main Oct 28, 2024
9 checks passed
@adityachoudhari26 adityachoudhari26 deleted the identifier-filter branch October 28, 2024 06:42
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