diff --git a/packages/web/src/charts/ChartEditor.js b/packages/web/src/charts/ChartEditor.js index 253a5670c..4507f273c 100644 --- a/packages/web/src/charts/ChartEditor.js +++ b/packages/web/src/charts/ChartEditor.js @@ -12,6 +12,8 @@ import { loadChartData, loadChartStructure } from './chartDataLoader'; import useExtensions from '../utility/useExtensions'; import { getConnectionInfo } from '../utility/metadataLoaders'; import { findEngineDriver } from 'dbgate-tools'; +import { FormFieldTemplateTiny } from '../utility/formStyle'; +import { ManagerInnerContainer } from '../datagrid/ManagerStyles'; const LeftContainer = styled.div` background-color: ${(props) => props.theme.manager_background}; @@ -72,36 +74,46 @@ export default function ChartEditor({ data, config, setConfig, sql, conid, datab }, [config, sql, conid, database]); return ( - + - - - - {/* */} - - - {/* + + + + + {/* */} + + + {/* */} - - + + + + + + + + + - {availableColumnNames.length > 0 && ( - - - {availableColumnNames.map((col) => ( - - ))} - - )} - {availableColumnNames.map((col) => ( - - ))} + + {availableColumnNames.length > 0 && ( + + + {availableColumnNames.map((col) => ( + + ))} + + )} + {availableColumnNames.map((col) => ( + + ))} + diff --git a/packages/web/src/charts/DataChart.js b/packages/web/src/charts/DataChart.js index 80c5389bc..4ee551088 100644 --- a/packages/web/src/charts/DataChart.js +++ b/packages/web/src/charts/DataChart.js @@ -1,82 +1,28 @@ import React from 'react'; -import _ from 'lodash'; import Chart from 'react-chartjs-2'; import randomcolor from 'randomcolor'; import styled from 'styled-components'; -import useTheme from '../theme/useTheme'; import useDimensions from '../utility/useDimensions'; -import { HorizontalSplitter } from '../widgets/Splitter'; -import WidgetColumnBar, { WidgetColumnBarItem } from '../widgets/WidgetColumnBar'; -import { FormSelectField } from '../utility/forms'; import { useForm } from '../utility/FormProvider'; -import { saturateByTenth } from '../theme/colorUtil'; const ChartWrapper = styled.div` flex: 1; overflow: hidden; `; -// const chartData = { -// labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'], -// datasets: [ -// { -// label: '# of Votes', -// data: [12, 19, 3, 5, 2, 3], -// backgroundColor: [ -// 'rgba(255, 99, 132, 0.2)', -// 'rgba(54, 162, 235, 0.2)', -// 'rgba(255, 206, 86, 0.2)', -// 'rgba(75, 192, 192, 0.2)', -// 'rgba(153, 102, 255, 0.2)', -// 'rgba(255, 159, 64, 0.2)', -// ], -// borderColor: [ -// 'rgba(255, 99, 132, 1)', -// 'rgba(54, 162, 235, 1)', -// 'rgba(255, 206, 86, 1)', -// 'rgba(75, 192, 192, 1)', -// 'rgba(153, 102, 255, 1)', -// 'rgba(255, 159, 64, 1)', -// ], -// borderWidth: 1, -// }, -// ], -// }; - function createChartData(freeData, labelColumn, dataColumns, colorSeed, chartType) { if (!freeData || !labelColumn || !dataColumns || dataColumns.length == 0) return {}; - const labels = _.uniq(freeData.rows.map((x) => x[labelColumn])); const colors = randomcolor({ - count: labels.length, + count: freeData.rows.length, seed: colorSeed, }); const res = { labels: freeData.rows.map((x) => x[labelColumn]), datasets: dataColumns.map((dataColumn) => ({ label: dataColumn, - // data: [12, 19, 3, 5, 2, 3], - data: labels.map((label) => - _.sum(freeData.rows.filter((row) => row[labelColumn] == label).map((row) => row[dataColumn])) - ), + data: freeData.rows.map((row) => row[dataColumn]), backgroundColor: chartType != 'line' ? colors : null, borderColor: chartType == 'line' ? colors : null, - // borderColor: colors, // .map(saturateByTenth), - // backgroundColor: [ - // 'rgba(255, 99, 132, 0.2)', - // 'rgba(54, 162, 235, 0.2)', - // 'rgba(255, 206, 86, 0.2)', - // 'rgba(75, 192, 192, 0.2)', - // 'rgba(153, 102, 255, 0.2)', - // 'rgba(255, 159, 64, 0.2)', - // ], - // borderColor: [ - // 'rgba(255, 99, 132, 1)', - // 'rgba(54, 162, 235, 1)', - // 'rgba(255, 206, 86, 1)', - // 'rgba(75, 192, 192, 1)', - // 'rgba(153, 102, 255, 1)', - // 'rgba(255, 159, 64, 1)', - // ], borderWidth: 1, })), }; diff --git a/packages/web/src/modals/ConfirmSqlModal.js b/packages/web/src/modals/ConfirmSqlModal.js index 1c996debd..0b66bb278 100644 --- a/packages/web/src/modals/ConfirmSqlModal.js +++ b/packages/web/src/modals/ConfirmSqlModal.js @@ -1,6 +1,5 @@ import React from 'react'; import ModalBase from './ModalBase'; -import { FormButtonRow } from '../utility/forms'; import FormStyledButton from '../widgets/FormStyledButton'; import SqlEditor from '../sqleditor/SqlEditor'; import styled from 'styled-components'; diff --git a/packages/web/src/modals/InsertJoinModal.js b/packages/web/src/modals/InsertJoinModal.js index 962aff3b6..7eadc0af8 100644 --- a/packages/web/src/modals/InsertJoinModal.js +++ b/packages/web/src/modals/InsertJoinModal.js @@ -1,6 +1,5 @@ import React from 'react'; import ModalBase from './ModalBase'; -import { FormButtonRow } from '../utility/forms'; import FormStyledButton from '../widgets/FormStyledButton'; import SqlEditor from '../sqleditor/SqlEditor'; import styled from 'styled-components'; diff --git a/packages/web/src/modals/SaveArchiveModal.js b/packages/web/src/modals/SaveArchiveModal.js index b01e205aa..5119b00d1 100644 --- a/packages/web/src/modals/SaveArchiveModal.js +++ b/packages/web/src/modals/SaveArchiveModal.js @@ -1,11 +1,12 @@ import React from 'react'; import ModalBase from './ModalBase'; -import { FormTextField, FormSubmit, FormArchiveFolderSelect, FormRow, FormLabel } from '../utility/forms'; +import { FormTextField, FormSubmit, FormArchiveFolderSelect } from '../utility/forms'; import styled from 'styled-components'; import ModalHeader from './ModalHeader'; import ModalContent from './ModalContent'; import ModalFooter from './ModalFooter'; import { FormProvider } from '../utility/FormProvider'; +import { FormFieldTemplateDefault } from '../utility/formStyle'; const SelectWrapper = styled.div` width: 150px; @@ -24,13 +25,11 @@ export default function SaveArchiveModal({ file = 'new-table', folder = 'default Save to archive - {/* */} - - Folder + - + diff --git a/packages/web/src/modals/SaveFileModal.js b/packages/web/src/modals/SaveFileModal.js index 24599f08c..ef191acf9 100644 --- a/packages/web/src/modals/SaveFileModal.js +++ b/packages/web/src/modals/SaveFileModal.js @@ -1,13 +1,11 @@ import React from 'react'; import axios from '../utility/axios'; import ModalBase from './ModalBase'; -import { FormButtonRow, FormButton, FormTextField, FormSelectField, FormSubmit } from '../utility/forms'; -import { TextField } from '../utility/inputs'; +import { FormTextField, FormSubmit } from '../utility/forms'; import ModalHeader from './ModalHeader'; import ModalContent from './ModalContent'; import ModalFooter from './ModalFooter'; import { FormProvider } from '../utility/FormProvider'; -// import FormikForm from '../utility/FormikForm'; export default function SaveFileModal({ data, folder, format, modalState, name, onSave = undefined }) { const handleSubmit = async (values) => { diff --git a/packages/web/src/modals/SetFilterModal.js b/packages/web/src/modals/SetFilterModal.js index a5b21a4ca..c3b51ebb4 100644 --- a/packages/web/src/modals/SetFilterModal.js +++ b/packages/web/src/modals/SetFilterModal.js @@ -2,19 +2,13 @@ import React from 'react'; import ModalBase from './ModalBase'; import FormStyledButton from '../widgets/FormStyledButton'; import styled from 'styled-components'; -import { - FormButtonRow, - FormSubmit, - FormSelectFieldRaw, - FormRow, - FormRadioGroupItem, - FormTextFieldRaw, -} from '../utility/forms'; +import { FormSubmit, FormSelectFieldRaw, FormRadioGroupItem, FormTextFieldRaw } from '../utility/forms'; import ModalHeader from './ModalHeader'; import ModalFooter from './ModalFooter'; import ModalContent from './ModalContent'; import { TextField } from '../utility/inputs'; import { FormProvider } from '../utility/FormProvider'; +import { FormRow } from '../utility/formStyle'; const Wrapper = styled.div` display: flex; diff --git a/packages/web/src/utility/FormProvider.js b/packages/web/src/utility/FormProvider.js index 2b6fa6078..7db27e14c 100644 --- a/packages/web/src/utility/FormProvider.js +++ b/packages/web/src/utility/FormProvider.js @@ -1,18 +1,20 @@ import React from 'react'; +import { FormFieldTemplateDefault } from './formStyle'; import keycodes from './keycodes'; const FormContext = React.createContext(null); +const FormFieldTemplateContext = React.createContext(null); -export function FormProvider({ children, initialValues = {} }) { +export function FormProvider({ children, initialValues = {}, template = FormFieldTemplateDefault }) { const [values, setValues] = React.useState(initialValues); return ( - + {children} ); } -export function FormProviderCore({ children, values, setValues }) { +export function FormProviderCore({ children, values, setValues, template = FormFieldTemplateDefault }) { const [submitAction, setSubmitAction] = React.useState(null); const handleEnter = React.useCallback( (e) => { @@ -43,9 +45,21 @@ export function FormProviderCore({ children, values, setValues }) { setFieldValue, setSubmitAction, }; - return {children}; + return ( + + {children} + + ); } export function useForm() { return React.useContext(FormContext); } + +export function FormFieldTemplateProvider({ children, template = FormFieldTemplateDefault }) { + return {children}; +} + +export function useFormFieldTemplate() { + return React.useContext(FormFieldTemplateContext); +} diff --git a/packages/web/src/utility/formStyle.js b/packages/web/src/utility/formStyle.js new file mode 100644 index 000000000..93583b946 --- /dev/null +++ b/packages/web/src/utility/formStyle.js @@ -0,0 +1,54 @@ +import styled from 'styled-components'; +import React from 'react'; +import useTheme from '../theme/useTheme'; + +export const FormRow = styled.div` + display: flex; + margin: 10px; +`; + +export const FormLabel = styled.div` + width: 10vw; + font-weight: bold; +`; + +export const FormValue = styled.div``; + +export function FormFieldTemplateDefault({ label, children, type }) { + return ( + + {label} + {children} + + ); +} + +export const FormRowTiny = styled.div` + margin: 5px; +`; + +export const FormLabelTiny = styled.div` + color: ${(props) => props.theme.manager_font3}; +`; + +export const FormValueTiny = styled.div` + margin-left: 15px; + margin-top: 3px; +`; + +export function FormFieldTemplateTiny({ label, children, type }) { + const theme = useTheme(); + if (type == 'checkbox') { + return ( + + {children} {label} + + ); + } + return ( + + {label} + {children} + + ); +} diff --git a/packages/web/src/utility/forms.js b/packages/web/src/utility/forms.js index 7fd706658..bf241864e 100644 --- a/packages/web/src/utility/forms.js +++ b/packages/web/src/utility/forms.js @@ -1,5 +1,4 @@ import React from 'react'; -import styled from 'styled-components'; import Select from 'react-select'; import Creatable from 'react-select/creatable'; import { TextField, SelectField, CheckboxField } from './inputs'; @@ -14,25 +13,8 @@ import { import getAsArray from './getAsArray'; import axios from './axios'; import useTheme from '../theme/useTheme'; -import { useForm } from './FormProvider'; +import { useForm, useFormFieldTemplate } from './FormProvider'; -export const FormRow = styled.div` - display: flex; - margin: 10px; -`; - -export const FormButtonRow = styled.div` - display: flex; - // justify-content: flex-end; - margin: 10px; -`; - -export const FormLabel = styled.div` - width: 10vw; - font-weight: bold; -`; - -export const FormValue = styled.div``; export function FormTextFieldRaw({ name, focused = false, ...other }) { const { values, setFieldValue } = useForm(); @@ -48,13 +30,11 @@ export function FormTextFieldRaw({ name, focused = false, ...other }) { } export function FormTextField({ name, label, focused = false, ...other }) { + const FieldTemplate = useFormFieldTemplate(); return ( - - {label} - - - - + + + ); } @@ -70,13 +50,11 @@ export function FormCheckboxFieldRaw({ name = undefined, defaultValue = undefine } export function FormCheckboxField({ label, ...other }) { + const FieldTemplate = useFormFieldTemplate(); return ( - - {label} - - - - + + + ); } @@ -93,15 +71,13 @@ export function FormSelectFieldRaw({ children, name, ...other }) { } export function FormSelectField({ label, name, children = null, ...other }) { + const FieldTemplate = useFormFieldTemplate(); return ( - - {label} - - - {children} - - - + + + {children} + + ); }