Skip to content

Commit

Permalink
fix: advanced search filter boolean files (#3685)
Browse files Browse the repository at this point in the history
  • Loading branch information
leopuleo committed Nov 10, 2023
1 parent d9afadc commit 20e651b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ describe("GraphQLInputMapper", () => {
field: "field-4",
condition: "_not_contains",
value: "value-4"
},
{
field: "boolean-field-true",
condition: " ",
value: "true"
},
{
field: "boolean-field-false",
condition: " ",
value: "false"
}
]
}
Expand Down Expand Up @@ -62,6 +72,12 @@ describe("GraphQLInputMapper", () => {
},
{
"field-4_not_contains": "value-4"
},
{
"boolean-field-true": true
},
{
"boolean-field-false": false
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,22 @@ export class GraphQLInputMapper {
const { field, condition, value } = filter;
const key = `${field}${condition}`.trim();

return { [key]: value };
return { [key]: this.convertToBooleanOrString(value) };
})
};
})
};
}

private static convertToBooleanOrString(value: string | boolean): string | boolean {
if (value === "true") {
return true;
}

if (value === "false") {
return false;
}

return value ?? "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ interface BooleanProps {
export const Boolean = ({ name }: BooleanProps) => {
return (
<Bind name={name}>
{({ value, onChange }) => (
<RadioGroup>
{({ value, onChange, validation }) => (
<RadioGroup validation={validation}>
{() => {
return (
<>
<Radio
label="True"
value={value}
value={value === "true"}
onChange={() => {
onChange(true);
onChange("true");
}}
/>
<Radio
label="False"
value={!value}
value={value === "false"}
onChange={() => {
onChange(false);
onChange("false");
}}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class FilterMapper {
operation: group.operation,
filters: group.filters.map(filter => ({
field: filter.field || "",
value: filter.value || "",
value: (filter.value ?? "").toString(),
condition: filter.condition || ""
}))
}))
Expand All @@ -29,7 +29,7 @@ export class FilterMapper {
operation: group.operation,
filters: group.filters.map(filter => ({
field: filter.field || "",
value: filter.value || "",
value: (filter.value ?? "").toString(),
condition: filter.condition || ""
}))
}))
Expand Down

0 comments on commit 20e651b

Please sign in to comment.