mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 15:15:59 +00:00
macro checkbox args + search & replace imporved
This commit is contained in:
@@ -40,6 +40,7 @@ export default function FreeTableGrid(props) {
|
|||||||
dispatchModel({ type: 'set', value: newModel });
|
dispatchModel({ type: 'set', value: newModel });
|
||||||
setSelectedMacro(null);
|
setSelectedMacro(null);
|
||||||
};
|
};
|
||||||
|
// console.log('macroValues', macroValues);
|
||||||
return (
|
return (
|
||||||
<HorizontalSplitter initialValue="300px" size={managerSize} setSize={setManagerSize}>
|
<HorizontalSplitter initialValue="300px" size={managerSize} setSize={setManagerSize}>
|
||||||
<LeftContainer>
|
<LeftContainer>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
FormRow,
|
FormRow,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormSelectField,
|
FormSelectField,
|
||||||
|
FormCheckboxField,
|
||||||
} from '../utility/forms';
|
} from '../utility/forms';
|
||||||
import { Formik, Form, useFormikContext } from 'formik';
|
import { Formik, Form, useFormikContext } from 'formik';
|
||||||
|
|
||||||
@@ -15,6 +16,9 @@ function MacroArgument({ arg, namePrefix }) {
|
|||||||
if (arg.type == 'text') {
|
if (arg.type == 'text') {
|
||||||
return <FormTextField label={arg.label} name={name} />;
|
return <FormTextField label={arg.label} name={name} />;
|
||||||
}
|
}
|
||||||
|
if (arg.type == 'checkbox') {
|
||||||
|
return <FormCheckboxField label={arg.label} name={name} />;
|
||||||
|
}
|
||||||
if (arg.type == 'select') {
|
if (arg.type == 'select') {
|
||||||
return (
|
return (
|
||||||
<FormSelectField label={arg.label} name={name}>
|
<FormSelectField label={arg.label} name={name}>
|
||||||
|
|||||||
@@ -24,8 +24,22 @@ const macros = [
|
|||||||
label: 'Replace with',
|
label: 'Replace with',
|
||||||
name: 'replace',
|
name: 'replace',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: 'checkbox',
|
||||||
|
label: 'Case sensitive',
|
||||||
|
name: 'caseSensitive',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'checkbox',
|
||||||
|
label: 'Regular expression',
|
||||||
|
name: 'isRegex',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
code: `return value ? value.toString().replace(args.find, args.replace) : value`,
|
code: `
|
||||||
|
const rtext = args.isRegex ? args.find : modules.lodash.escapeRegExp(args.find);
|
||||||
|
const rflags = args.caseSensitive ? 'g' : 'ig';
|
||||||
|
return value ? value.toString().replace(new RegExp(rtext, rflags), args.replace || '') : value
|
||||||
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Change text case',
|
title: 'Change text case',
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import Select from 'react-select';
|
import Select from 'react-select';
|
||||||
import Creatable from 'react-select/creatable';
|
import Creatable from 'react-select/creatable';
|
||||||
import { TextField, SelectField } from './inputs';
|
import { TextField, SelectField, CheckboxField } from './inputs';
|
||||||
import { Field, useFormikContext } from 'formik';
|
import { Field, useFormikContext } from 'formik';
|
||||||
import FormStyledButton from '../widgets/FormStyledButton';
|
import FormStyledButton from '../widgets/FormStyledButton';
|
||||||
import {
|
import {
|
||||||
@@ -49,6 +49,26 @@ export function FormTextField({ label, ...other }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function FormCheckboxFieldRaw({ name = undefined, ...other }) {
|
||||||
|
const { values, setFieldValue } = useFormikContext();
|
||||||
|
const handleChange = (event) => {
|
||||||
|
setFieldValue(name, event.target.checked);
|
||||||
|
};
|
||||||
|
return <CheckboxField name={name} checked={!!values[name]} onChange={handleChange} {...other} />;
|
||||||
|
// return <Field {...other} as={CheckboxField} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FormCheckboxField({ label, ...other }) {
|
||||||
|
return (
|
||||||
|
<FormRow>
|
||||||
|
<FormLabel>{label}</FormLabel>
|
||||||
|
<FormValue>
|
||||||
|
<FormCheckboxFieldRaw {...other} />
|
||||||
|
</FormValue>
|
||||||
|
</FormRow>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function FormSelectFieldRaw({ children, ...other }) {
|
export function FormSelectFieldRaw({ children, ...other }) {
|
||||||
return (
|
return (
|
||||||
<Field {...other} as={SelectField}>
|
<Field {...other} as={SelectField}>
|
||||||
|
|||||||
@@ -16,3 +16,7 @@ export function SelectField({ children = null, options = [], ...other }) {
|
|||||||
</select>
|
</select>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function CheckboxField({ editorRef = undefined, ...other }) {
|
||||||
|
return <input type="checkbox" {...other} ref={editorRef}></input>;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user