From 96e160f1220c7a6685e146a1169cef36e1ba72c8 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sat, 16 May 2020 07:55:02 +0200 Subject: [PATCH] set filter modal --- .../web/src/datagrid/DataFilterControl.js | 12 +- packages/web/src/modals/SetFilterModal.js | 134 ++++++++++++++++++ packages/web/src/utility/forms.js | 34 ++++- packages/web/src/utility/inputs.js | 10 +- 4 files changed, 178 insertions(+), 12 deletions(-) create mode 100644 packages/web/src/modals/SetFilterModal.js diff --git a/packages/web/src/datagrid/DataFilterControl.js b/packages/web/src/datagrid/DataFilterControl.js index 4c48d52e..39356c2f 100644 --- a/packages/web/src/datagrid/DataFilterControl.js +++ b/packages/web/src/datagrid/DataFilterControl.js @@ -7,6 +7,7 @@ import { parseFilter, createMultiLineFilter } from '@dbgate/filterparser'; import InlineButton from '../widgets/InlineButton'; import showModal from '../modals/showModal'; import FilterMultipleValuesModal from '../modals/FilterMultipleValuesModal'; +import SetFilterModal from '../modals/SetFilterModal'; // import { $ } from '../../Utility/jquery'; // import autobind from 'autobind-decorator'; // import * as React from 'react'; @@ -184,7 +185,16 @@ export default function DataFilterControl({ isReadOnly = false, filterType, filt /> )); }; - const openFilterWindow = (operator) => {}; + const openFilterWindow = (operator) => { + showModal((modalState) => ( + setFilterText(text)} + condition1={operator} + /> + )); + }; const buttonRef = React.useRef(); const editorRef = React.useRef(); diff --git a/packages/web/src/modals/SetFilterModal.js b/packages/web/src/modals/SetFilterModal.js new file mode 100644 index 00000000..81ff3250 --- /dev/null +++ b/packages/web/src/modals/SetFilterModal.js @@ -0,0 +1,134 @@ +import React from 'react'; +import ModalBase from './ModalBase'; +import FormStyledButton from '../widgets/FormStyledButton'; +import styled from 'styled-components'; +import { FontIcon } from '../icons'; +import { FormButtonRow, FormSubmit, FormSelectFieldRaw, FormRow, FormRadioGroupItem, FormTextFieldRaw } from '../utility/forms'; +import ModalHeader from './ModalHeader'; +import ModalFooter from './ModalFooter'; +import ModalContent from './ModalContent'; +import { Formik, Form } from 'formik'; +import { TextField } from '../utility/inputs'; + +const Wrapper = styled.div` + display: flex; +`; + +const OptionsWrapper = styled.div` + margin-left: 10px; +`; + +function RadioGroupItem({ text, value, defaultChecked = undefined, setMode }) { + return ( +
+ setMode(value)} + /> + +
+ ); +} + +function Select({ filterType, name }) { + return ( + + {filterType == 'number' && ( + <> + + + + + + + + )} + {filterType == 'string' && ( + <> + + + + + + + + + + + + + + )} + {filterType == 'datetime' && ( + <> + + + + + + + + )} + + ); +} + +export default function SetFilterModal({ modalState, onFilter, filterType, condition1 }) { + const editorRef = React.useRef(null); + // const [condition1, setValue1] = React.useState(condition); + // const [value2, setValue2] = React.useState('equals'); + // const [mode, setMode] = React.useState('and'); + React.useEffect(() => { + setTimeout(() => { + if (editorRef.current) editorRef.current.focus(); + }, 1); + }, []); + + const createTerm = (condition, value) => { + if (!value) return null; + if (filterType == 'string') return `${condition}"${value}"`; + return `${condition}${value}`; + }; + + const handleOk = (values) => { + const { value1, condition1, value2, condition2, joinOperator } = values; + const term1 = createTerm(condition1, value1); + const term2 = createTerm(condition2, value2); + if (term1 && term2) onFilter(`${term1}${joinOperator}${term2}`); + else if (term1) onFilter(term1); + else if (term2) onFilter(term2); + modalState.close(); + }; + + return ( + + +
+ Set filter + + Show rows where + + + + + + + + + +
+
+
+ ); +} diff --git a/packages/web/src/utility/forms.js b/packages/web/src/utility/forms.js index 555c225f..8f22f6a7 100644 --- a/packages/web/src/utility/forms.js +++ b/packages/web/src/utility/forms.js @@ -22,25 +22,35 @@ export const FormLabel = styled.div` export const FormValue = styled.div``; +export function FormTextFieldRaw({ ...other }) { + return ; +} + export function FormTextField({ label, ...other }) { return ( {label} - + ); } +export function FormSelectFieldRaw({ children, ...other }) { + return ( + + {children} + + ); +} + export function FormSelectField({ label, children, ...other }) { return ( {label} - - {children} - + {children} ); @@ -54,3 +64,19 @@ export function FormButton({ text, onClick, ...other }) { const { values } = useFormikContext(); return onClick(values)} {...other} />; } + +export function FormRadioGroupItem({ name, text, value }) { + const { setFieldValue, values } = useFormikContext(); + return ( +
+ setFieldValue(name, value)} + /> + +
+ ); +} diff --git a/packages/web/src/utility/inputs.js b/packages/web/src/utility/inputs.js index ba3deee8..06ba97d2 100644 --- a/packages/web/src/utility/inputs.js +++ b/packages/web/src/utility/inputs.js @@ -1,13 +1,9 @@ import React from 'react'; -export function TextField({ ...other }) { - return ; +export function TextField({ editorRef = undefined, ...other }) { + return ; } export function SelectField({ children, ...other }) { - return ( - - ); + return ; }