-
Notifications
You must be signed in to change notification settings - Fork 11
fix: Remove like condition for column condition #231
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import { | |
| HoverCardTrigger, | ||
| } from "@ctrlplane/ui/hover-card"; | ||
| import { | ||
| ColumnOperator, | ||
| ComparisonOperator, | ||
| DateOperator, | ||
| MetadataOperator, | ||
|
|
@@ -57,6 +58,9 @@ const operatorVerbs = { | |
| [DateOperator.Before]: "before", | ||
| [DateOperator.AfterOrOn]: "after or on", | ||
| [DateOperator.BeforeOrOn]: "before or on", | ||
| [ColumnOperator.StartsWith]: "starts with", | ||
| [ColumnOperator.EndsWith]: "ends with", | ||
| [ColumnOperator.Contains]: "contains", | ||
|
Comment on lines
+61
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Based on the codebase analysis, I can now generate the final response: Remove The codebase shows that
Please:
🔗 Analysis chainVerify removal of MetadataOperator.Like. While the new Let's verify the usage of 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check if MetadataOperator.Like is still being used elsewhere in the codebase
# Search for MetadataOperator.Like usage
echo "Searching for MetadataOperator.Like usage..."
rg "MetadataOperator\.Like"
# Search for potential string literal "like" in conditions
echo "Searching for 'like' string literals in condition files..."
rg -g "**/condition*.{ts,tsx}" '"like"'
Length of output: 1366 Script: #!/bin/bash
# Let's check the implementation details of MetadataOperator and ColumnOperator
# First, let's find the enum definitions
echo "=== Searching for MetadataOperator definition ==="
ast-grep --pattern 'enum MetadataOperator {
$$$
}'
echo -e "\n=== Searching for ColumnOperator definition ==="
ast-grep --pattern 'enum ColumnOperator {
$$$
}'
# Let's also check if there are any direct usages of these operators in condition-related files
echo -e "\n=== Checking condition files for operator usage ==="
fd "condition.*\.(ts|tsx)$" --exec cat {}
Length of output: 135584 |
||
| }; | ||
|
|
||
| const ConditionBadge: React.FC<{ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ import { | |
| HoverCardContent, | ||
| HoverCardTrigger, | ||
| } from "@ctrlplane/ui/hover-card"; | ||
| import { DateOperator } from "@ctrlplane/validators/conditions"; | ||
| import { ColumnOperator, DateOperator } from "@ctrlplane/validators/conditions"; | ||
| import { | ||
| isComparisonCondition, | ||
| isCreatedAtCondition, | ||
|
|
@@ -42,6 +42,9 @@ const operatorVerbs = { | |
| [DateOperator.Before]: "before", | ||
| [DateOperator.AfterOrOn]: "after or on", | ||
| [DateOperator.BeforeOrOn]: "before or on", | ||
| [ColumnOperator.StartsWith]: "starts with", | ||
| [ColumnOperator.EndsWith]: "ends with", | ||
| [ColumnOperator.Contains]: "contains", | ||
|
Comment on lines
+45
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Found remaining "like" operator usages that need migration The verification revealed that the "like" operator is still present in several validator files:
These files still define and use the "like" operator, which should be migrated to the new specific operators (startsWith, endsWith, contains) for consistency with the UI changes. 🔗 Analysis chainVerify complete migration from "like" operator. Let's ensure all usages of the old "like" operator have been properly migrated to the new column operators. Let me try a different search strategy to find any remaining usages of the "like" operator in the codebase. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for any remaining "like" string literals in TypeScript/JavaScript files
# that might indicate missed migrations
rg -t ts -t tsx -t js "['\"](like|LIKE)['\"]" -g '!{*.test.*,*.spec.*}'
# Search for ColumnOperator.Like usage that should have been migrated
ast-grep --pattern 'ColumnOperator.Like'
Length of output: 31028 Script: #!/bin/bash
# Search for ColumnOperator enum definition and its usages
ast-grep --pattern 'enum ColumnOperator'
# Search for any remaining "like" string literals specifically in the context of operators
rg -t ts -t js "operator.*like" -g '!{*.test.*,*.spec.*}'
# Search for any comparison with "like" in TypeScript/JavaScript files
rg -t ts -t js "=.*['\"]like['\"]" -g '!{*.test.*,*.spec.*}'
Length of output: 497 |
||
| }; | ||
|
|
||
| const ConditionBadge: React.FC<{ | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -288,7 +288,7 @@ export const ComparisonConditionRender: React.FC< | |||||
| onClick={() => | ||||||
| addCondition({ | ||||||
| type: ResourceFilterType.Name, | ||||||
| operator: ResourceOperator.Like, | ||||||
| operator: ColumnOperator.Equals, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider using Contains instead of Equals for Name filtering Using Consider using - operator: ColumnOperator.Equals,
+ operator: ColumnOperator.Contains,This would allow users to find resources by partial name matches, which is a common use case in resource filtering. 📝 Committable suggestion
Suggested change
|
||||||
| value: "", | ||||||
| }) | ||||||
| } | ||||||
|
|
@@ -299,7 +299,7 @@ export const ComparisonConditionRender: React.FC< | |||||
| onClick={() => | ||||||
| addCondition({ | ||||||
| type: ResourceFilterType.Identifier, | ||||||
| operator: ColumnOperator.Like, | ||||||
| operator: ColumnOperator.Equals, | ||||||
| value: "", | ||||||
| }) | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,24 @@ | ||
| import type { ColumnOperatorType } from "@ctrlplane/validators/conditions"; | ||
| import type { NameCondition } from "@ctrlplane/validators/resources"; | ||
|
|
||
| import { cn } from "@ctrlplane/ui"; | ||
| import { Input } from "@ctrlplane/ui/input"; | ||
|
|
||
| import type { TargetConditionRenderProps } from "./target-condition-props"; | ||
| import { ColumnConditionRender } from "../filter/ColumnConditionRender"; | ||
|
|
||
| export const NameConditionRender: React.FC< | ||
| TargetConditionRenderProps<NameCondition> | ||
| > = ({ condition, onChange, className }) => { | ||
| const setValue = (value: string) => | ||
| onChange({ ...condition, value: `%${value}%` }); | ||
| const setOperator = (operator: ColumnOperatorType) => | ||
| onChange({ ...condition, operator }); | ||
| const setValue = (value: string) => onChange({ ...condition, value }); | ||
|
|
||
| return ( | ||
| <div className={cn("flex w-full items-center gap-2", className)}> | ||
| <div className="grid w-full grid-cols-12"> | ||
| <div | ||
| className={cn( | ||
| "col-span-3 flex items-center rounded-l-md border bg-transparent px-3 text-sm text-muted-foreground", | ||
| )} | ||
| > | ||
| Name contains | ||
| </div> | ||
| <div className="col-span-9"> | ||
| <Input | ||
| placeholder="Value" | ||
| value={condition.value.replace(/^%|%$/g, "")} | ||
| onChange={(e) => setValue(e.target.value)} | ||
| className="rounded-l-none rounded-r-md bg-transparent hover:bg-neutral-800/50" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <ColumnConditionRender | ||
| operator={condition.operator} | ||
| value={condition.value} | ||
| setOperator={setOperator} | ||
| setValue={setValue} | ||
| className={className} | ||
| title="Name" | ||
| /> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,14 +5,13 @@ export * from "./date-condition.js"; | |
|
|
||
| export enum ColumnOperator { | ||
| Equals = "equals", | ||
| Like = "like", | ||
| Regex = "regex", | ||
| StartsWith = "starts-with", | ||
| EndsWith = "ends-with", | ||
| Contains = "contains", | ||
|
Comment on lines
+9
to
+11
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Based on the results, I can now generate the final response: Migration from The verification reveals several files still using the "like" operator that need to be updated:
The new operators ( 🔗 Analysis chainImproved string matching granularity, but verify migration and naming. The change from a generic Let's verify all usages have been updated: Consider using consistent casing for enum values: export enum ColumnOperator {
Equals = "equals",
Regex = "regex",
- StartsWith = "starts-with",
- EndsWith = "ends-with",
- Contains = "contains",
+ StartsWith = "startsWith",
+ EndsWith = "endsWith",
+ Contains = "contains",
}🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for any remaining uses of the old "like" operator
rg -i "\"like\"" --type ts
# Search for uses of the new operators to ensure proper adoption
rg -i "\"(starts-with|ends-with|contains)\"" --type ts
# Search for ColumnOperator usage to verify migration
ast-grep --pattern 'ColumnOperator.$_'
Length of output: 39934 |
||
| } | ||
|
|
||
| export const columnOperator = z | ||
| .literal(ColumnOperator.Equals) | ||
| .or(z.literal(ColumnOperator.Like)) | ||
| .or(z.literal(ColumnOperator.Regex)); | ||
| export const columnOperator = z.nativeEnum(ColumnOperator); | ||
|
|
||
| export type ColumnOperatorType = z.infer<typeof columnOperator>; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider enhancing regex input validation and guidance.
While the regex placeholder is helpful, consider these improvements for better user experience:
Here's a suggested implementation: