-
Notifications
You must be signed in to change notification settings - Fork 1
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
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 |
---|---|---|
@@ -1,26 +1,27 @@ | ||
import type { | ||
ColumnOperatorType, | ||
VersionCondition, | ||
VersionOperatorType, | ||
} from "@ctrlplane/validators/conditions"; | ||
import React from "react"; | ||
|
||
import type { ReleaseConditionRenderProps } from "./release-condition-props"; | ||
import { VersionConditionRender } from "../filter/VersionConditionRender"; | ||
import { ColumnConditionRender } from "../filter/ColumnConditionRender"; | ||
|
||
export const ReleaseVersionConditionRender: React.FC< | ||
ReleaseConditionRenderProps<VersionCondition> | ||
> = ({ condition, onChange, className }) => { | ||
const setOperator = (operator: VersionOperatorType) => | ||
const setOperator = (operator: ColumnOperatorType) => | ||
onChange({ ...condition, operator }); | ||
const setValue = (value: string) => onChange({ ...condition, value }); | ||
|
||
return ( | ||
<VersionConditionRender | ||
<ColumnConditionRender | ||
operator={condition.operator} | ||
value={condition.value} | ||
setOperator={setOperator} | ||
setValue={setValue} | ||
className={className} | ||
title="Version" | ||
/> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { ColumnOperatorType } from "@ctrlplane/validators/conditions"; | ||
import type { IdentifierCondition } from "@ctrlplane/validators/targets"; | ||
|
||
import type { TargetConditionRenderProps } from "./target-condition-props"; | ||
import { ColumnConditionRender } from "../filter/ColumnConditionRender"; | ||
|
||
export const IdentifierConditionRender: React.FC< | ||
TargetConditionRenderProps<IdentifierCondition> | ||
> = ({ condition, onChange, className }) => { | ||
const setOperator = (operator: ColumnOperatorType) => | ||
onChange({ ...condition, operator }); | ||
const setValue = (value: string) => onChange({ ...condition, value }); | ||
Comment on lines
+10
to
+12
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 memoizing callback functions. To optimize performance and prevent unnecessary re-renders, consider memoizing the callback functions using - 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]
+ );
|
||
|
||
return ( | ||
<ColumnConditionRender | ||
operator={condition.operator} | ||
value={condition.value} | ||
setOperator={setOperator} | ||
setValue={setValue} | ||
className={className} | ||
title="Identifier" | ||
/> | ||
); | ||
Comment on lines
+14
to
+23
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 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}
/>
);
};
|
||
}; |
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.
Add null check and document the purpose of removing % signs.
While removing % signs might be intentional, the code could be more robust and clearer:
Consider this safer implementation:
Also, add a comment explaining why % signs are being removed.
📝 Committable suggestion