standardized rendering of inputs

This commit is contained in:
Ari Sosnovsky committed 2021-10-31 14:13:51 -04:00
1 parent 32fd7f2dff
commit 53ec0d417b
10 files changed
+77 -53

No files matched your search

+5 -10
View File
@@ -1,4 +1,4 @@
import InputWrapper from "../../components/InputWrapper"; import InputText from "../../components/InputText";
import { ServiceScript } from "../types/script"; import { ServiceScript } from "../types/script";
import { BaseState } from "./BaseState"; import { BaseState } from "./BaseState";
@@ -12,15 +12,10 @@ export default class Generic extends BaseState<{alias: string}> {
} }
renderOptionList(state: ServiceScript): JSX.Element { renderOptionList(state: ServiceScript): JSX.Element {
return <div className="state-manager-options"> return <div className="state-manager-options">
<InputWrapper label="Description"> <InputText label="Description"
<input value={state.alias} onChange={e => { value={state.alias}
e.preventDefault(); onChange={alias => this.setState({...state, alias})}
this.setState({ />
...state,
alias: e.target.value,
})
}}/>
</InputWrapper>
<br/> <br/>
<b>THIS IS NOT SUPPORTED YET!</b> <b>THIS IS NOT SUPPORTED YET!</b>
</div> </div>
@@ -1,3 +1,4 @@
import InputText from "../../components/InputText";
import InputWrapper from "../../components/InputWrapper"; import InputWrapper from "../../components/InputWrapper";
import { ServiceScript } from "../types/script"; import { ServiceScript } from "../types/script";
import { BaseState } from "./BaseState"; import { BaseState } from "./BaseState";
@@ -17,33 +18,18 @@ export default class ScriptCallServiceState extends BaseState<ServiceScript> {
} }
renderOptionList(state: ServiceScript): JSX.Element { renderOptionList(state: ServiceScript): JSX.Element {
return <div className="state-manager-options"> return <div className="state-manager-options">
<InputWrapper label="Description"> <InputText label="Description"
<input value={state.alias} onChange={e => { value={state.alias}
e.preventDefault(); onChange={alias => this.setState({...state, alias})}
this.setState({ />
...state, <InputText label="Service"
alias: e.target.value, value={state.service}
}) onChange={service => this.setState({...state, service})}
}}/> />
</InputWrapper> <InputText label="Target"
<InputWrapper label="Service"> value={state.target}
<input value={state.service} onChange={e => { onChange={target => this.setState({...state, target})}
e.preventDefault(); />
this.setState({
...state,
service: e.target.value,
})
}}/>
</InputWrapper>
<InputWrapper label="Target">
<input value={state.target} onChange={e => {
e.preventDefault();
this.setState({
...state,
target: e.target.value,
})
}}/>
</InputWrapper>
</div> </div>
} }
} }
+7 -1
View File
@@ -1,4 +1,4 @@
import { useState } from "react"; import { useEffect, useState } from "react";
import { AutomationNodeType, NodeSubType } from "../types"; import { AutomationNodeType, NodeSubType } from "../types";
import { BaseState } from "./BaseState"; import { BaseState } from "./BaseState";
import Generic from "./Generic"; import Generic from "./Generic";
@@ -24,9 +24,15 @@ export default class StateManager {
} }
this.nodeType = nodeType; this.nodeType = nodeType;
this.nodeSubtype = nodeSubtype; this.nodeSubtype = nodeSubtype;
useEffect(() => {
this.setState(this.baseState.defaultState());
}, [this.nodeType, this.nodeSubtype]);
return this.baseState; return this.baseState;
} }
renderOptionList() { renderOptionList() {
return this.baseState.renderOptionList(this.state) return this.baseState.renderOptionList(this.state)
} }
get isReady() {
return this.baseState.isReady(this.state);
}
} }
@@ -28,14 +28,19 @@ export default function NewNodeModal<T extends AutomationNodeType>({
<div className="new-node-modal--inner" onClick={e => e.preventDefault()}> <div className="new-node-modal--inner" onClick={e => e.preventDefault()}>
<div className="new-node-modal--title">Create {node_type[0].toUpperCase()}{node_type.slice(1)}</div> <div className="new-node-modal--title">Create {node_type[0].toUpperCase()}{node_type.slice(1)}</div>
<div className="new-node-modal--body"> <div className="new-node-modal--body">
<InputWrapper label="Type:"> <InputList label="Type:"
<InputList options={typeList[node_type]} current={selectedSubType} onChange={n => setSubType(n as NodeSubType)}/> options={typeList[node_type]}
</InputWrapper> current={selectedSubType}
onChange={n => setSubType(n as NodeSubType)}
/>
{stateManager.renderOptionList()} {stateManager.renderOptionList()}
</div> </div>
<div className="new-node-modal--footer"> <div className="new-node-modal--footer">
<button className="secondary" onClick={() => onClose()}>Close</button> <button onClick={() => onClose()}>Close</button>
<button onClick={() => onCreate({} as any)}>Create</button> <button onClick={() => onCreate({} as any)}
disabled={!stateManager.isReady}>
Create
</button>
</div> </div>
</div> </div>
</div> </div>
+11 -7
View File
@@ -1,4 +1,5 @@
import { SelectHTMLAttributes } from "react"; import { SelectHTMLAttributes } from "react";
import InputWrapper from "./InputWrapper";
export interface Props { export interface Props {
@@ -7,12 +8,15 @@ export interface Props {
onChange: (n: string) => void; onChange: (n: string) => void;
id?: string; id?: string;
className?: string; className?: string;
label: string;
} }
export default function InputList({current, options, onChange, ...selattr}: Props) { export default function InputList({current, options, onChange, label, ...selattr}: Props) {
return <select {...selattr} value={current} onChange={e => { return <InputWrapper label={label}>
e.preventDefault(); <select {...selattr} value={current} onChange={e => {
onChange(e.currentTarget.value); e.preventDefault();
}}> onChange(e.currentTarget.value);
{options.map((t, i) => <option id={String(i)} key={i}>{t}</option>)} }}>
</select> {options.map((t, i) => <option id={String(i)} key={i}>{t}</option>)}
</select>
</InputWrapper>
} }
+18
View File
@@ -0,0 +1,18 @@
import InputWrapper from "./InputWrapper";
export interface Props {
label: string;
value: string;
onChange: (v: string) => void;
}
export default function InputText({
label, value, onChange
}: Props) {
return <InputWrapper label={label}>
<input value={value} onChange={e => {
e.preventDefault();
onChange(e.target.value)
}}/>
</InputWrapper>
}
-1
View File
@@ -16,7 +16,6 @@ export default function AutomationNode({
onXClick = () => {}, onXClick = () => {},
}: PropsWithChildren<Props>) { }: PropsWithChildren<Props>) {
const [isOpen, setOpen] = useState(initialOpenState); const [isOpen, setOpen] = useState(initialOpenState);
console.log(children);
return <div className="automation-node"> return <div className="automation-node">
<div className="automation-node-inner"> <div className="automation-node-inner">
<div <div
-2
View File
@@ -1,8 +1,6 @@
import AutomationEditor from "../components/AutomationEditor"; import AutomationEditor from "../components/AutomationEditor";
import sample from "../sample/auto_01.yaml"; import sample from "../sample/auto_01.yaml";
console.log(sample)
export function Home() { export function Home() {
return ( return (
<div id="page--home" className="page"> <div id="page--home" className="page">
+1
View File
@@ -5,5 +5,6 @@ $secondary-accent: #929191;
$font-color-primary: #e1e1e1; $font-color-primary: #e1e1e1;
$gray: #403f3f;
$green: #68caa4; $green: #68caa4;
$blue: #68aaca; $blue: #68aaca;
+12
View File
@@ -80,6 +80,13 @@ button {
border-color: $secondary-accent; border-color: $secondary-accent;
} }
&:disabled {
background-color: $gray;
border-color: $gray;
color: darken($gray, 50);
cursor: not-allowed;
}
&.secondary { &.secondary {
background-color: $primary; background-color: $primary;
color: $secondary-accent; color: $secondary-accent;
@@ -103,3 +110,8 @@ select {
@extend button; @extend button;
margin: 0; margin: 0;
} }
input {
@extend button;
margin: 0;
cursor: text;
}