Skip to content

Commit

Permalink
Merge pull request #901 from devinit/fix/disappearing-filter-value
Browse files Browse the repository at this point in the history
Fix | Disappearing Filter Value
  • Loading branch information
edwinmp committed Feb 15, 2023
2 parents b83cbed + 5cf3d57 commit af4c29e
Show file tree
Hide file tree
Showing 5 changed files with 929 additions and 45 deletions.
19 changes: 19 additions & 0 deletions frontend/src/components/ReactQueryBuilder/CustomValueEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { FC, useState } from 'react';
import { FormControl } from 'react-bootstrap';
import { ValueEditorProps } from 'react-querybuilder';

const CustomValueEditor: FC<ValueEditorProps> = (props) => {
const [value, setValue] = useState(props.value);

return (
<FormControl
value={value}
onChange={(event) => {
setValue(event.currentTarget.value);
props.handleOnChange(event.currentTarget.value);
}}
/>
);
};

export { CustomValueEditor };
18 changes: 5 additions & 13 deletions frontend/src/components/ReactQueryBuilder/ReactQueryBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import {
bootstrapControlClassnames,
bootstrapControlElements,
} from '@react-querybuilder/bootstrap';
import React, { FC, KeyboardEvent } from 'react';
import { Button, FormControl } from 'react-bootstrap';
import QueryBuilder, { QueryBuilderProps, ValueEditorProps } from 'react-querybuilder';
import React, { FC } from 'react';
import { Button } from 'react-bootstrap';
import QueryBuilder, { QueryBuilderProps } from 'react-querybuilder';
import 'react-querybuilder/dist/query-builder.scss';
import CustomSelector from './CustomSelector';
import { CustomValueEditor } from './CustomValueEditor';
import DeleteAction from './DeleteAction';
import './styles.css';
import { getClasses } from './utils/config';
Expand All @@ -33,16 +34,7 @@ const ReactQueryBuilder: FC<QueryBuilderProps> = (props) => {
),
removeRuleAction: (props) => <DeleteAction onClick={props.handleOnClick} />,
removeGroupAction: (props) => <DeleteAction onClick={props.handleOnClick} />,
valueEditor: (props: ValueEditorProps) => (
<FormControl
defaultValue={props.value}
onKeyDown={(event: KeyboardEvent<HTMLInputElement>) => {
if (event.key === 'Enter') {
props.handleOnChange(event.currentTarget.value);
}
}}
/>
),
valueEditor: CustomValueEditor,
}}
controlClassnames={getClasses(bootstrapControlClassnames)}
{...props}
Expand Down
Loading

0 comments on commit af4c29e

Please sign in to comment.