always pretty list
This commit is contained in:
1 parent
f4a41331b1
commit
736a6053ef
2 files changed
+87
-55
No files matched your search
@@ -27,7 +27,7 @@ export function InputList<T extends string | Object>({
|
||||
label,
|
||||
id,
|
||||
className,
|
||||
prettyOptionLabels,
|
||||
prettyOptionLabels = true,
|
||||
getKey = String,
|
||||
placeholder,
|
||||
title,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import "./index.css";
|
||||
|
||||
import { FC, ReactNode } from 'react';
|
||||
import { AutomationNode, AutomationNodeMapping } from 'types/automations/index';
|
||||
import { FC, ReactNode } from "react";
|
||||
import { AutomationNode, AutomationNodeMapping } from "types/automations/index";
|
||||
import { useEditorNodeState } from "./OptionManager";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import InputBoolean from "components/Inputs/InputBoolean";
|
||||
|
||||
export interface NodeEditorProps {
|
||||
node: AutomationNode
|
||||
node: AutomationNode;
|
||||
allowedTypes?: Array<keyof AutomationNodeMapping>;
|
||||
onClose?: () => void;
|
||||
onSave?: (n: AutomationNode) => void;
|
||||
@@ -21,9 +21,9 @@ export interface NodeEditorProps {
|
||||
export const NodeEditor: FC<NodeEditorProps> = ({
|
||||
node,
|
||||
allowedTypes = ["action", "condition", "trigger"],
|
||||
onClose = () => { },
|
||||
onSave = () => { },
|
||||
onFlags = () => { },
|
||||
onClose = () => {},
|
||||
onSave = () => {},
|
||||
onFlags = () => {},
|
||||
saveBtnCreateText = false,
|
||||
children,
|
||||
isErrored = false,
|
||||
@@ -34,58 +34,90 @@ export const NodeEditor: FC<NodeEditorProps> = ({
|
||||
// alias
|
||||
const isModified = state.isModified;
|
||||
const isReady = state.isReady();
|
||||
const areYouSureNotReady = (what: string) => !isReady ?
|
||||
window.confirm(`This node is missing some values, are you sure you want to ${what}?`) :
|
||||
state.isErrored ?
|
||||
window.confirm(`This node contains errors, are you sure you want to ${what}?`) :
|
||||
true;
|
||||
const areYouSureNotReady = (what: string) =>
|
||||
!isReady
|
||||
? window.confirm(
|
||||
`This node is missing some values, are you sure you want to ${what}?`
|
||||
)
|
||||
: state.isErrored
|
||||
? window.confirm(
|
||||
`This node contains errors, are you sure you want to ${what}?`
|
||||
)
|
||||
: true;
|
||||
|
||||
// events
|
||||
onFlags(isReady, isModified);
|
||||
// render
|
||||
return <div className={[
|
||||
"node-editor--root",
|
||||
isModified ? "modded" : "",
|
||||
(!isReady && isModified) ? 'not-ready' : '',
|
||||
state.data.enabled === false ? 'disabled' : 'enabled'
|
||||
].join(" ")}>
|
||||
<div className="node-editor--body">
|
||||
<div className="node-editor--body-title">
|
||||
{allowedTypes.length > 1 ? <InputList
|
||||
label="Type"
|
||||
current={state.nodeType}
|
||||
options={allowedTypes}
|
||||
onChange={state.setNodeType}
|
||||
/> : <></>}
|
||||
{state.nodeType !== 'condition' ? <InputList
|
||||
label={state.prettyNodeType}
|
||||
current={state.subType as any}
|
||||
options={state.subTypes}
|
||||
onChange={state.setSubType}
|
||||
/> : <></>}
|
||||
<div className="node-editor--body-flags">
|
||||
<InputBoolean label="Yaml" onChange={state.setYamlMode} value={state.yamlMode} disabled={state.isErrored} />
|
||||
<InputBoolean className="enabled-flag" label='Enabled' value={state.data.enabled ?? true} onChange={state.setEnabled} />
|
||||
return (
|
||||
<div
|
||||
className={[
|
||||
"node-editor--root",
|
||||
isModified ? "modded" : "",
|
||||
!isReady && isModified ? "not-ready" : "",
|
||||
state.data.enabled === false ? "disabled" : "enabled",
|
||||
].join(" ")}
|
||||
>
|
||||
<div className="node-editor--body">
|
||||
<div className="node-editor--body-title">
|
||||
{allowedTypes.length > 1 ? (
|
||||
<InputList
|
||||
label="Type"
|
||||
current={state.nodeType}
|
||||
options={allowedTypes}
|
||||
onChange={state.setNodeType}
|
||||
prettyOptionLabels
|
||||
/>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
{state.nodeType !== "condition" ? (
|
||||
<InputList
|
||||
label={state.prettyNodeType}
|
||||
current={state.subType as any}
|
||||
options={state.subTypes}
|
||||
onChange={state.setSubType}
|
||||
prettyOptionLabels
|
||||
/>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
<div className="node-editor--body-flags">
|
||||
<InputBoolean
|
||||
label="Yaml"
|
||||
onChange={state.setYamlMode}
|
||||
value={state.yamlMode}
|
||||
disabled={state.isErrored}
|
||||
/>
|
||||
<InputBoolean
|
||||
className="enabled-flag"
|
||||
label="Enabled"
|
||||
value={state.data.enabled ?? true}
|
||||
onChange={state.setEnabled}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{state.renderOptionList()}
|
||||
</div>
|
||||
<div className="node-editor--footer">
|
||||
<Button
|
||||
className="node-editor--footer--close"
|
||||
onClick={() => areYouSureNotReady("close") && onClose()}
|
||||
>
|
||||
Close
|
||||
</Button>
|
||||
<Button
|
||||
className="node-editor--footer--save"
|
||||
onClick={() => {
|
||||
if (areYouSureNotReady("save")) {
|
||||
onSave(state.data);
|
||||
}
|
||||
}}
|
||||
title={!isReady ? "Some fields have not been properly filled up" : ""}
|
||||
>
|
||||
{saveBtnCreateText ? "Create" : "Save"}
|
||||
</Button>
|
||||
{children}
|
||||
</div>
|
||||
{state.renderOptionList()}
|
||||
</div>
|
||||
<div className="node-editor--footer">
|
||||
<Button className="node-editor--footer--close" onClick={() => areYouSureNotReady('close') && onClose()}>Close</Button>
|
||||
<Button
|
||||
className="node-editor--footer--save"
|
||||
onClick={() => {
|
||||
if (areYouSureNotReady('save')) {
|
||||
onSave(state.data)
|
||||
}
|
||||
}}
|
||||
title={
|
||||
!isReady ? "Some fields have not been properly filled up" : ""
|
||||
}
|
||||
>
|
||||
{saveBtnCreateText ? "Create" : "Save"}
|
||||
</Button>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user