Make executeonload a switch and move it to the right (#221)

- Move all form labels to the their individual components
This commit is contained in:
akash-codemonk 2020-08-05 13:32:24 +05:30 committed by GitHub
parent e768e5d131
commit 20684116fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 69 additions and 46 deletions

View File

@ -7,6 +7,7 @@ import DropdownField from "components/editorComponents/form/fields/DropdownField
import { DropdownOption } from "widgets/DropdownWidget"; import { DropdownOption } from "widgets/DropdownWidget";
import { ControlType } from "constants/PropertyControlConstants"; import { ControlType } from "constants/PropertyControlConstants";
import { theme } from "constants/DefaultTheme"; import { theme } from "constants/DefaultTheme";
import FormLabel from "components/editorComponents/FormLabel";
const DropdownSelect = styled.div` const DropdownSelect = styled.div`
font-size: 14px; font-size: 14px;
@ -39,18 +40,23 @@ const customSelectStyles = {
class DropDownControl extends BaseControl<DropDownControlProps> { class DropDownControl extends BaseControl<DropDownControlProps> {
render() { render() {
const { configProperty, options } = this.props; const { configProperty, options, label, isRequired } = this.props;
return ( return (
<DropdownSelect data-cy={configProperty}> <div>
<DropdownField <FormLabel>
placeholder="" {label} {isRequired && "*"}
name={configProperty} </FormLabel>
options={options} <DropdownSelect data-cy={configProperty}>
customSelectStyles={customSelectStyles} <DropdownField
width={"50vh"} placeholder=""
/> name={configProperty}
</DropdownSelect> options={options}
customSelectStyles={customSelectStyles}
width={"50vh"}
/>
</DropdownSelect>
</div>
); );
} }

View File

@ -10,6 +10,7 @@ import Dashboard from "@uppy/dashboard";
import { BaseButton } from "components/designSystems/blueprint/ButtonComponent"; import { BaseButton } from "components/designSystems/blueprint/ButtonComponent";
import BaseControl, { ControlProps } from "./BaseControl"; import BaseControl, { ControlProps } from "./BaseControl";
import { ControlType } from "constants/PropertyControlConstants"; import { ControlType } from "constants/PropertyControlConstants";
import FormLabel from "components/editorComponents/FormLabel";
const StyledDiv = styled.div` const StyledDiv = styled.div`
flex: 1; flex: 1;
@ -120,10 +121,13 @@ class FilePickerControl extends BaseControl<FilePickerControlProps> {
} }
render() { render() {
const { configProperty } = this.props; const { configProperty, label, isRequired } = this.props;
return ( return (
<React.Fragment> <React.Fragment>
<FormLabel>
{label} {isRequired && "*"}
</FormLabel>
<Field name={configProperty} component={FieldFileInput} /> <Field name={configProperty} component={FieldFileInput} />
</React.Fragment> </React.Fragment>
); );

View File

@ -3,6 +3,7 @@ import BaseControl, { ControlProps } from "./BaseControl";
import { InputType } from "widgets/InputWidget"; import { InputType } from "widgets/InputWidget";
import { ControlType } from "constants/PropertyControlConstants"; import { ControlType } from "constants/PropertyControlConstants";
import TextField from "components/editorComponents/form/fields/TextField"; import TextField from "components/editorComponents/form/fields/TextField";
import FormLabel from "components/editorComponents/FormLabel";
export function InputText(props: { export function InputText(props: {
label: string; label: string;
@ -14,10 +15,13 @@ export function InputText(props: {
isRequired?: boolean; isRequired?: boolean;
name: string; name: string;
}) { }) {
const { name, placeholder, dataType } = props; const { name, placeholder, dataType, label, isRequired } = props;
return ( return (
<div style={{ width: "50vh" }}> <div style={{ width: "50vh" }}>
<FormLabel>
{label} {isRequired && "*"}
</FormLabel>
<TextField <TextField
name={name} name={name}
placeholder={placeholder} placeholder={placeholder}

View File

@ -6,6 +6,7 @@ import { FormIcons } from "icons/FormIcons";
import BaseControl, { ControlProps, ControlData } from "./BaseControl"; import BaseControl, { ControlProps, ControlData } from "./BaseControl";
import TextField from "components/editorComponents/form/fields/TextField"; import TextField from "components/editorComponents/form/fields/TextField";
import { ControlType } from "constants/PropertyControlConstants"; import { ControlType } from "constants/PropertyControlConstants";
import FormLabel from "components/editorComponents/FormLabel";
const FormRowWithLabel = styled.div` const FormRowWithLabel = styled.div`
display: flex; display: flex;
@ -30,6 +31,9 @@ const KeyValueRow = (props: Props & WrappedFieldArrayProps) => {
<div> <div>
{typeof props.fields.getAll() === "object" && ( {typeof props.fields.getAll() === "object" && (
<div> <div>
<FormLabel>
{props.label} {props.isRequired && "*"}
</FormLabel>
{props.fields.map((field: any, index: number) => ( {props.fields.map((field: any, index: number) => (
<FormRowWithLabel key={index} style={{ marginTop: index ? 13 : 0 }}> <FormRowWithLabel key={index} style={{ marginTop: index ? 13 : 0 }}>
<div style={{ width: "50vh" }}> <div style={{ width: "50vh" }}>

View File

@ -4,29 +4,38 @@ import { StyledSwitch } from "./StyledControls";
import { ControlType } from "constants/PropertyControlConstants"; import { ControlType } from "constants/PropertyControlConstants";
import FormLabel from "components/editorComponents/FormLabel"; import FormLabel from "components/editorComponents/FormLabel";
import { Field, WrappedFieldProps } from "redux-form"; import { Field, WrappedFieldProps } from "redux-form";
import styled from "styled-components";
type Props = WrappedFieldProps & SwitchControlProps; type Props = WrappedFieldProps & SwitchControlProps;
class SwitchField extends React.Component<Props> { const StyledFormLabel = styled(FormLabel)`
margin-bottom: 0px;
`;
const SwitchWrapped = styled.div`
flex-direction: row;
display: flex;
align-items: center;
.bp3-control {
margin-bottom: 0px;
}
`;
export class SwitchField extends React.Component<Props> {
render() { render() {
const { label, isRequired, input } = this.props; const { label, isRequired, input } = this.props;
return ( return (
<div <SwitchWrapped>
style={{ <StyledFormLabel>
flexDirection: "row",
display: "flex",
}}
>
<FormLabel>
{label} {isRequired && "*"} {label} {isRequired && "*"}
</FormLabel> </StyledFormLabel>
<StyledSwitch <StyledSwitch
checked={input.value} checked={input.value}
onChange={value => input.onChange(value)} onChange={value => input.onChange(value)}
large large
/> />
</div> </SwitchWrapped>
); );
} }
} }

View File

@ -6,7 +6,6 @@ import { Spinner } from "@blueprintjs/core";
import { DATA_SOURCES_EDITOR_URL } from "constants/routes"; import { DATA_SOURCES_EDITOR_URL } from "constants/routes";
import Collapsible from "./Collapsible"; import Collapsible from "./Collapsible";
import history from "utils/history"; import history from "utils/history";
import FormLabel from "components/editorComponents/FormLabel";
import { Icon } from "@blueprintjs/core"; import { Icon } from "@blueprintjs/core";
import FormTitle from "./FormTitle"; import FormTitle from "./FormTitle";
import { ControlProps } from "components/formControls/BaseControl"; import { ControlProps } from "components/formControls/BaseControl";
@ -54,7 +53,6 @@ const DBForm = styled.div`
margin-right: 0px; margin-right: 0px;
max-height: 93vh; max-height: 93vh;
overflow: auto; overflow: auto;
.backBtn { .backBtn {
padding-bottom: 1px; padding-bottom: 1px;
cursor: pointer; cursor: pointer;
@ -391,7 +389,6 @@ class DatasourceDBEditor extends React.Component<
} else { } else {
try { try {
const { const {
label,
controlType, controlType,
isRequired, isRequired,
configProperty, configProperty,
@ -418,12 +415,6 @@ class DatasourceDBEditor extends React.Component<
return ( return (
<div key={configProperty} style={{ marginTop: "16px" }}> <div key={configProperty} style={{ marginTop: "16px" }}>
{controlType !== "KEYVALUE_ARRAY" &&
controlType !== "SWITCH" && (
<FormLabel>
{label} {isRequired && "*"}
</FormLabel>
)}
{FormControlFactory.createControl( {FormControlFactory.createControl(
config, config,
{}, {},

View File

@ -1,6 +1,10 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { formValueSelector, InjectedFormProps, reduxForm } from "redux-form"; import {
import CheckboxField from "components/editorComponents/form/fields/CheckboxField"; formValueSelector,
InjectedFormProps,
reduxForm,
Field,
} from "redux-form";
import styled, { createGlobalStyle } from "styled-components"; import styled, { createGlobalStyle } from "styled-components";
import { Icon, Popover } from "@blueprintjs/core"; import { Icon, Popover } from "@blueprintjs/core";
import { import {
@ -37,6 +41,7 @@ import {
getPluginResponseTypes, getPluginResponseTypes,
getPluginDocumentationLinks, getPluginDocumentationLinks,
} from "selectors/entitiesSelector"; } from "selectors/entitiesSelector";
import { SwitchField } from "components/formControls/SwitchControl";
const QueryFormContainer = styled.div` const QueryFormContainer = styled.div`
padding: 20px 32px; padding: 20px 32px;
@ -76,6 +81,12 @@ const QueryFormContainer = styled.div`
span.bp3-popover-target { span.bp3-popover-target {
display: initial !important; display: initial !important;
} }
.executeOnLoad {
display: flex;
justify-content: flex-end;
margin-top: 10px;
}
`; `;
const ActionButtons = styled.div` const ActionButtons = styled.div`
@ -185,13 +196,6 @@ const Container = styled.div`
} }
`; `;
const StyledCheckbox = styled(CheckboxField)`
&&& {
font-size: 14px;
margin-top: 10px;
}
`;
const StyledOpenDocsIcon = styled(Icon)` const StyledOpenDocsIcon = styled(Icon)`
svg { svg {
width: 12px; width: 12px;
@ -460,12 +464,13 @@ const QueryEditorForm: React.FC<Props> = (props: Props) => {
/> />
</div> </div>
)} )}
<StyledCheckbox <div className="executeOnLoad">
intent="primary" <Field
name="executeOnLoad" name="executeOnLoad"
align="left" component={SwitchField}
label="Run on Page Load" label={"Run on Page Load"}
/> />
</div>
</form> </form>
{dataSources.length === 0 && ( {dataSources.length === 0 && (