Skip to content

Commit

Permalink
refactor: update SelectView options value
Browse files Browse the repository at this point in the history
  • Loading branch information
lawvs committed Jul 26, 2024
1 parent 6dd7c1c commit 9689e23
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions packages/filter/src/filter-rule/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,20 @@ export const FilterRule = ({ rule }: FilterRuleProps) => {
return (
<div>
<SelectView
// Note: Can't use path.join('.') here because
// [].join('.') will return an empty string ''
// but ''.split('.') will return ['']
// which is not same as []
value={JSON.stringify(rule.path)}
value={selectedField}
options={filterableFields.map((field) => ({
value: JSON.stringify(field.path),
value: field,
label: mapFieldName(field),
}))}
onChange={(pathStr) => {
onChange={(newField) => {
updateRule({
...rule,
// Clear filter name when field changed
name: undefined,
// name: newField.filterList[0].name,
// Reset arguments when field changed
arguments: [],
path: JSON.parse(pathStr),
path: newField.path,
});
}}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/filter/src/specs/preset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const SelectView = <T,>({
);
return (
<SelectPrimitive value={selectedIdx} onChange={handleChange} {...props}>
<OptionPrimitive key={-1} value={-1} hidden disabled></OptionPrimitive>
<OptionPrimitive key={-1} value={-1} disabled></OptionPrimitive>
{options.map(({ label }, index) => (
<OptionPrimitive key={label} value={index}>
{label}
Expand Down

0 comments on commit 9689e23

Please sign in to comment.