cleaned up styles a bit
This commit is contained in:
1 parent
3acbaf576d
commit
451b3638bf
28 files changed
+864
-705
No files matched your search
@@ -2,11 +2,12 @@ import "./AutoInfoBox.css";
|
||||
import { AutomationMetadata } from "types/automations";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { FC, ReactNode, useRef, useState } from 'react';
|
||||
import { FC, ReactNode, useRef, useState } from "react";
|
||||
import { AddIcon, TrashIcon } from "components/Icons";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import InputAutoText from "components/Inputs/InputAutoText";
|
||||
import { TagDB } from "components/AutomationList/TagDB";
|
||||
import from "@mui/material/IconButton";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
interface Props {
|
||||
className: string;
|
||||
@@ -25,122 +26,154 @@ export const AutoInfoBox: FC<Props> = ({
|
||||
tagDB,
|
||||
}) => {
|
||||
// state
|
||||
const [newTag, setNewTag] = useState<[string, string]>(["", ""])
|
||||
const [[errorIndex, error], _setError] = useState<[number | 'new', string]>([-1, ""]);
|
||||
const [newTag, setNewTag] = useState<[string, string]>(["", ""]);
|
||||
const [[errorIndex, error], _setError] = useState<[number | "new", string]>([
|
||||
-1,
|
||||
"",
|
||||
]);
|
||||
const errorTimeoutId = useRef(-1);
|
||||
|
||||
// aliases
|
||||
const foundNewTagNames = tagDB.getTagNames(tags.map(([n, _]) => n));
|
||||
const setError = (index: number | 'new', msg: string) => {
|
||||
_setError([index, msg])
|
||||
const setError = (index: number | "new", msg: string) => {
|
||||
_setError([index, msg]);
|
||||
if (errorTimeoutId.current >= 0) {
|
||||
window.clearTimeout(errorTimeoutId.current);
|
||||
}
|
||||
errorTimeoutId.current = window.setTimeout(() => _setError([-1, ""]), 5000);
|
||||
}
|
||||
const onUpdateMetadata = <K extends keyof AutomationMetadata>(k: K) => (update: AutomationMetadata[K]) => onUpdate({
|
||||
...metadata,
|
||||
[k]: update
|
||||
}, tags);
|
||||
};
|
||||
const onUpdateMetadata =
|
||||
<K extends keyof AutomationMetadata>(k: K) =>
|
||||
(update: AutomationMetadata[K]) =>
|
||||
onUpdate(
|
||||
{
|
||||
...metadata,
|
||||
[k]: update,
|
||||
},
|
||||
tags
|
||||
);
|
||||
const validTagName = (newName: string): string | undefined => {
|
||||
if (newName.length <= 0) {
|
||||
return "Name must be at least 1 character long"
|
||||
return "Name must be at least 1 character long";
|
||||
}
|
||||
// eslint-disable-next-line
|
||||
for (const [name, _] of tags) {
|
||||
if (name.trim() === newName.trim()) {
|
||||
return `The tag '${name}' already exists`
|
||||
return `The tag '${name}' already exists`;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
const updateTagName = (newName: string, tagIndex: number) => {
|
||||
const error = validTagName(newName);
|
||||
if (error) {
|
||||
return setError(tagIndex, error)
|
||||
return setError(tagIndex, error);
|
||||
}
|
||||
onUpdate(metadata, [
|
||||
...tags.slice(0, tagIndex),
|
||||
[newName, tags[tagIndex][1]],
|
||||
...tags.slice(tagIndex + 1),
|
||||
])
|
||||
}
|
||||
const onUpdateTags = (tagValue: string, tagIndex: number) => onUpdate(metadata, [
|
||||
...tags.slice(0, tagIndex),
|
||||
[tags[tagIndex][0], tagValue],
|
||||
...tags.slice(tagIndex + 1),
|
||||
])
|
||||
]);
|
||||
};
|
||||
const onUpdateTags = (tagValue: string, tagIndex: number) =>
|
||||
onUpdate(metadata, [
|
||||
...tags.slice(0, tagIndex),
|
||||
[tags[tagIndex][0], tagValue],
|
||||
...tags.slice(tagIndex + 1),
|
||||
]);
|
||||
const addNewTag = () => {
|
||||
const error = validTagName(newTag[0]);
|
||||
if (error) {
|
||||
return setError('new', error)
|
||||
return setError("new", error);
|
||||
}
|
||||
onUpdate(metadata, tags.concat([
|
||||
newTag.map(x => x.trim()) as [string, string]
|
||||
]));
|
||||
setNewTag(['', '']);
|
||||
}
|
||||
const onRemoveTag = (tagIndex: number) => onUpdate(metadata, [
|
||||
...tags.slice(0, tagIndex),
|
||||
...tags.slice(tagIndex + 1),
|
||||
])
|
||||
onUpdate(
|
||||
metadata,
|
||||
tags.concat([newTag.map((x) => x.trim()) as [string, string]])
|
||||
);
|
||||
setNewTag(["", ""]);
|
||||
};
|
||||
const onRemoveTag = (tagIndex: number) =>
|
||||
onUpdate(metadata, [
|
||||
...tags.slice(0, tagIndex),
|
||||
...tags.slice(tagIndex + 1),
|
||||
]);
|
||||
// render
|
||||
return <div className={`automation-editor--info-box ${className}`}>
|
||||
<div className="automation-editor--info-box-inner">
|
||||
<InputText label="ID" value={metadata.id} onChange={onUpdateMetadata('id')} />
|
||||
<InputText label="Name" value={metadata.alias ?? ""} onChange={onUpdateMetadata('alias')} />
|
||||
<InputText multiline label="Description" value={metadata.description ?? ""} onChange={onUpdateMetadata('description')} />
|
||||
<InputList
|
||||
label="Mode"
|
||||
current={metadata.mode}
|
||||
onChange={onUpdateMetadata('mode')}
|
||||
options={[
|
||||
'parallel',
|
||||
'single',
|
||||
'queued',
|
||||
'restart'
|
||||
]}
|
||||
/>
|
||||
<div className="automation-editor--info-box--tags">
|
||||
<h1>Tags</h1>
|
||||
<div className="automation-editor--info-box--tag-list">
|
||||
{tags.map(([tagName, tagValue], tagIndex) => <div key={tagIndex} className="automation-editor--info-box--tag">
|
||||
return (
|
||||
<div className={`automation-editor--info-box ${className}`}>
|
||||
<div className="automation-editor--info-box-inner">
|
||||
<InputText
|
||||
label="ID"
|
||||
value={metadata.id}
|
||||
onChange={onUpdateMetadata("id")}
|
||||
/>
|
||||
<InputText
|
||||
label="Name"
|
||||
value={metadata.alias ?? ""}
|
||||
onChange={onUpdateMetadata("alias")}
|
||||
/>
|
||||
<InputText
|
||||
multiline
|
||||
label="Description"
|
||||
value={metadata.description ?? ""}
|
||||
onChange={onUpdateMetadata("description")}
|
||||
/>
|
||||
<InputList
|
||||
label="Mode"
|
||||
current={metadata.mode}
|
||||
onChange={onUpdateMetadata("mode")}
|
||||
options={["parallel", "single", "queued", "restart"]}
|
||||
/>
|
||||
<div className="automation-editor--info-box--tags">
|
||||
<h1>Tags</h1>
|
||||
<div className="automation-editor--info-box--tag-list">
|
||||
{tags.map(([tagName, tagValue], tagIndex) => (
|
||||
<div key={tagIndex} className="automation-editor--info-box--tag">
|
||||
<InputAutoText
|
||||
value={tagName}
|
||||
label="Name"
|
||||
onChange={(v) => updateTagName(v, tagIndex)}
|
||||
options={foundNewTagNames}
|
||||
error={errorIndex === tagIndex ? error : undefined}
|
||||
/>
|
||||
<InputAutoText
|
||||
value={tagValue}
|
||||
label="Tag"
|
||||
onChange={(v) => onUpdateTags(v, tagIndex)}
|
||||
options={tagDB.getTagValues(tagName)}
|
||||
error={errorIndex === tagIndex ? error : undefined}
|
||||
/>
|
||||
<ButtonIcon
|
||||
className="automation-editor--info-box--tag--trash"
|
||||
onClick={() => onRemoveTag(tagIndex)}
|
||||
icon={<TrashIcon />}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<hr />
|
||||
<div className="automation-editor--info-box--tag">
|
||||
<InputAutoText
|
||||
value={tagName}
|
||||
value={newTag[0]}
|
||||
label="Name"
|
||||
onChange={v => updateTagName(v, tagIndex)}
|
||||
onChange={(v) => setNewTag([v, newTag[1]])}
|
||||
options={foundNewTagNames}
|
||||
error={errorIndex === tagIndex ? error : undefined}
|
||||
error={errorIndex === "new" ? error : undefined}
|
||||
/>
|
||||
<InputAutoText
|
||||
value={tagValue}
|
||||
value={newTag[1]}
|
||||
label="Tag"
|
||||
onChange={v => onUpdateTags(v, tagIndex)}
|
||||
options={tagDB.getTagValues(tagName)}
|
||||
error={errorIndex === tagIndex ? error : undefined}
|
||||
onChange={(v) => setNewTag([newTag[0], v])}
|
||||
options={tagDB.getTagValues(newTag[0])}
|
||||
error={errorIndex === "new" ? error : undefined}
|
||||
/>
|
||||
<Button className="automation-editor--info-box--tag--trash" onClick={() => onRemoveTag(tagIndex)} ><TrashIcon /></Button>
|
||||
</div>)}
|
||||
</div>
|
||||
<hr />
|
||||
<div className="automation-editor--info-box--tag">
|
||||
<InputAutoText
|
||||
value={newTag[0]}
|
||||
label="Name"
|
||||
onChange={v => setNewTag([v, newTag[1]])}
|
||||
options={foundNewTagNames}
|
||||
error={errorIndex === 'new' ? error : undefined}
|
||||
/>
|
||||
<InputAutoText
|
||||
value={newTag[1]}
|
||||
label="Tag"
|
||||
onChange={v => setNewTag([newTag[0], v])}
|
||||
options={tagDB.getTagValues(newTag[0])}
|
||||
error={errorIndex === 'new' ? error : undefined}
|
||||
/>
|
||||
<Button className="automation-editor--info-box--tag--add" onClick={addNewTag} ><AddIcon /></Button>
|
||||
<ButtonIcon
|
||||
className="automation-editor--info-box--tag--add"
|
||||
onClick={addNewTag}
|
||||
icon={<AddIcon />}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -61,16 +61,19 @@
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.automation-editor--info-box--icon {
|
||||
.automation-editor .automation-editor--info-box--icon {
|
||||
position: absolute;
|
||||
right: 0em;
|
||||
bottom: 0.5em;
|
||||
left: 0.25em;
|
||||
bottom: 0em;
|
||||
z-index: 10;
|
||||
max-width: 1.5em;
|
||||
max-height: 1.5em;
|
||||
}
|
||||
|
||||
.automation-editor--info-box.hide>.automation-editor--info-box--icon {
|
||||
transform: rotate(180deg);
|
||||
z-index: 2;
|
||||
left: 0.1em;
|
||||
}
|
||||
|
||||
.automation-editor.loading .mock-list {
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import "./index.css";
|
||||
import Icon from '@mui/material/Icon';
|
||||
import { ArrowIcon, CheckMarkIcon } from "components/Icons";
|
||||
import Icon from "@mui/material/Icon";
|
||||
import { CheckMarkIcon } from "components/Icons";
|
||||
import { FC, useEffect, useState } from "react";
|
||||
import { AutomationData } from "types/automations";
|
||||
import { AutoInfoBox } from "./AutoInfoBox";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { useAutomatioEditorState, EditorData } from './state';
|
||||
import { useAutomatioEditorState, EditorData } from "./state";
|
||||
import { SafeDAGAutomationFlow } from "components/DAGFlow/safe";
|
||||
import { DAGAutomationFlowDims } from "components/DAGFlow/types";
|
||||
import { MiniFailure } from 'types/validators/helper';
|
||||
import { MiniFailure } from "types/validators/helper";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import { TagDB } from "components/AutomationList/TagDB";
|
||||
import Skeleton from "@mui/material/Skeleton";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
import { ArrowBack } from "@mui/icons-material";
|
||||
|
||||
interface Props {
|
||||
automation?: AutomationData;
|
||||
@@ -44,129 +45,166 @@ export const AutomationEditor: FC<Props> = ({
|
||||
// effect
|
||||
useEffect(() => {
|
||||
if (dims.flipped !== flipped) {
|
||||
setFlipped(dims.flipped)
|
||||
setFlipped(dims.flipped);
|
||||
}
|
||||
// eslint-disable-next-line
|
||||
}, [dims.flipped])
|
||||
}, [dims.flipped]);
|
||||
|
||||
// render
|
||||
if (state.status === 'loading') {
|
||||
return <div className="automation-editor loading">
|
||||
<LinearProgress className="linear-loader" />
|
||||
<Skeleton className="mock-list" variant="rectangular" />
|
||||
<Skeleton className="mock-graph" variant="rectangular" />
|
||||
</div>
|
||||
}
|
||||
if (state.status === 'invalid') {
|
||||
return <ValidationBox
|
||||
failures={state.failures}
|
||||
data={state.data}
|
||||
validate={validate}
|
||||
onSave={saveAndUpdate}
|
||||
/>
|
||||
}
|
||||
return <div className="automation-editor">
|
||||
{state.status === 'saving' && <LinearProgress className="linear-loader" />}
|
||||
<AutoInfoBox
|
||||
className={closeInfo ? "hide" : "show"}
|
||||
metadata={state.data.metadata}
|
||||
tags={state.data.tags}
|
||||
onUpdate={updateMetadata}
|
||||
tagDB={tagDB}
|
||||
>
|
||||
<ButtonIcon
|
||||
className="automation-editor--info-box--icon"
|
||||
onClick={() => setCloseInfo(!closeInfo)}
|
||||
title={closeInfo ? "Show Metadata" : "Hide Metadata"}
|
||||
Icon={ArrowIcon}
|
||||
/>
|
||||
</AutoInfoBox>
|
||||
|
||||
<div className={["automation-editor--flow-wrapper", state.status].join(" ")}>
|
||||
<div className="automation-editor--flow-wrapper--toolbar">
|
||||
{!dims.flipped && <Button
|
||||
className={"automation-editor--flow-wrapper--toolbar--flip-btn"}
|
||||
onClick={() => setFlipped(!flipped)}
|
||||
>
|
||||
<Icon>{flipped ? 'flip_to_front' : 'flip_to_back'}</Icon>
|
||||
Flip
|
||||
</Button>}
|
||||
<Button
|
||||
className={"automation-editor--flow-wrapper--toolbar--save-btn"}
|
||||
onClick={save}
|
||||
disabled={state.status !== 'changed'}
|
||||
>
|
||||
Save <CheckMarkIcon color="#bf4" />
|
||||
</Button>
|
||||
if (state.status === "loading") {
|
||||
return (
|
||||
<div className="automation-editor loading">
|
||||
<LinearProgress className="linear-loader" />
|
||||
<Skeleton className="mock-list" variant="rectangular" />
|
||||
<Skeleton className="mock-graph" variant="rectangular" />
|
||||
</div>
|
||||
<SafeDAGAutomationFlow
|
||||
className="automation-editor--flow-wrapper--flow"
|
||||
sequence={state.data.sequence}
|
||||
trigger={state.data.trigger}
|
||||
condition={state.data.condition}
|
||||
onSequenceUpdate={updateSequence}
|
||||
onTriggerUpdate={updateTrigger}
|
||||
onConditionUpdate={updateCondition}
|
||||
dims={{
|
||||
...dims,
|
||||
flipped,
|
||||
}}
|
||||
);
|
||||
}
|
||||
if (state.status === "invalid") {
|
||||
return (
|
||||
<ValidationBox
|
||||
failures={state.failures}
|
||||
data={state.data}
|
||||
validate={validate}
|
||||
onSave={saveAndUpdate}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="automation-editor">
|
||||
{state.status === "saving" && (
|
||||
<LinearProgress className="linear-loader" />
|
||||
)}
|
||||
<AutoInfoBox
|
||||
className={closeInfo ? "hide" : "show"}
|
||||
metadata={state.data.metadata}
|
||||
tags={state.data.tags}
|
||||
onUpdate={updateMetadata}
|
||||
tagDB={tagDB}
|
||||
>
|
||||
<ButtonIcon
|
||||
className="automation-editor--info-box--icon"
|
||||
onClick={() => setCloseInfo(!closeInfo)}
|
||||
title={closeInfo ? "Show Metadata" : "Hide Metadata"}
|
||||
color="success"
|
||||
icon={<ArrowBack />}
|
||||
/>
|
||||
</AutoInfoBox>
|
||||
|
||||
<div
|
||||
className={["automation-editor--flow-wrapper", state.status].join(" ")}
|
||||
>
|
||||
<div className="automation-editor--flow-wrapper--toolbar">
|
||||
{!dims.flipped && (
|
||||
<Button
|
||||
className={"automation-editor--flow-wrapper--toolbar--flip-btn"}
|
||||
onClick={() => setFlipped(!flipped)}
|
||||
>
|
||||
<Icon>{flipped ? "flip_to_front" : "flip_to_back"}</Icon>
|
||||
Flip
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
className={"automation-editor--flow-wrapper--toolbar--save-btn"}
|
||||
onClick={save}
|
||||
disabled={state.status !== "changed"}
|
||||
>
|
||||
Save <CheckMarkIcon color="#bf4" />
|
||||
</Button>
|
||||
</div>
|
||||
<SafeDAGAutomationFlow
|
||||
className="automation-editor--flow-wrapper--flow"
|
||||
sequence={state.data.sequence}
|
||||
trigger={state.data.trigger}
|
||||
condition={state.data.condition}
|
||||
onSequenceUpdate={updateSequence}
|
||||
onTriggerUpdate={updateTrigger}
|
||||
onConditionUpdate={updateCondition}
|
||||
dims={{
|
||||
...dims,
|
||||
flipped,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const ValidationBox: FC<{
|
||||
failures: MiniFailure[]
|
||||
validate: (d: any) => MiniFailure[] | null,
|
||||
data: EditorData,
|
||||
onSave: (d: EditorData) => void,
|
||||
}> = props => {
|
||||
|
||||
failures: MiniFailure[];
|
||||
validate: (d: any) => MiniFailure[] | null;
|
||||
data: EditorData;
|
||||
onSave: (d: EditorData) => void;
|
||||
}> = (props) => {
|
||||
const [{ failures, data }, setState] = useState({
|
||||
failures: props.failures,
|
||||
data: props.data,
|
||||
});
|
||||
|
||||
const makeSave = <K extends keyof EditorData>(k: K) => (d: EditorData[K]) => {
|
||||
const newData = {
|
||||
...data,
|
||||
[k]: d,
|
||||
}
|
||||
const newFails = props.validate(newData);
|
||||
if (newFails) {
|
||||
setState({
|
||||
failures: newFails,
|
||||
data: newData,
|
||||
})
|
||||
} else {
|
||||
setState({
|
||||
failures: [],
|
||||
data: newData,
|
||||
})
|
||||
}
|
||||
}
|
||||
const makeSave =
|
||||
<K extends keyof EditorData>(k: K) =>
|
||||
(d: EditorData[K]) => {
|
||||
const newData = {
|
||||
...data,
|
||||
[k]: d,
|
||||
};
|
||||
const newFails = props.validate(newData);
|
||||
if (newFails) {
|
||||
setState({
|
||||
failures: newFails,
|
||||
data: newData,
|
||||
});
|
||||
} else {
|
||||
setState({
|
||||
failures: [],
|
||||
data: newData,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return <div className="automation-editor-failures">
|
||||
<ul>
|
||||
{failures.map((f, i) => <>
|
||||
<li key={i}>
|
||||
<b>{f.path}</b>:
|
||||
<ul>
|
||||
{f.message.map((m, j) => <li key={j}>
|
||||
{m}
|
||||
</li>)}
|
||||
</ul>
|
||||
</li>
|
||||
</>)}
|
||||
</ul>
|
||||
<span>Please correct the automation file manually and then continue!</span>
|
||||
<InputYaml label="Metadata" value={data.metadata} onChange={makeSave('metadata')} />
|
||||
<InputYaml label="Tags" value={data.tags} onChange={makeSave('tags')} />
|
||||
<InputYaml label="Trigger" value={data.trigger} onChange={makeSave('trigger')} />
|
||||
<InputYaml label="Condition" value={data.condition} onChange={makeSave('condition')} />
|
||||
<InputYaml label="Actions" value={data.sequence} onChange={makeSave('sequence')} />
|
||||
<Button disabled={failures.length > 0} onClick={() => props.onSave(data)}>Save</Button>
|
||||
</div>
|
||||
}
|
||||
return (
|
||||
<div className="automation-editor-failures">
|
||||
<ul>
|
||||
{failures.map((f, i) => (
|
||||
<>
|
||||
<li key={i}>
|
||||
<b>{f.path}</b>:
|
||||
<ul>
|
||||
{f.message.map((m, j) => (
|
||||
<li key={j}>{m}</li>
|
||||
))}
|
||||
</ul>
|
||||
</li>
|
||||
</>
|
||||
))}
|
||||
</ul>
|
||||
<span>
|
||||
Please correct the automation file manually and then continue!
|
||||
</span>
|
||||
<InputYaml
|
||||
label="Metadata"
|
||||
value={data.metadata}
|
||||
onChange={makeSave("metadata")}
|
||||
/>
|
||||
<InputYaml label="Tags" value={data.tags} onChange={makeSave("tags")} />
|
||||
<InputYaml
|
||||
label="Trigger"
|
||||
value={data.trigger}
|
||||
onChange={makeSave("trigger")}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Condition"
|
||||
value={data.condition}
|
||||
onChange={makeSave("condition")}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Actions"
|
||||
value={data.sequence}
|
||||
onChange={makeSave("sequence")}
|
||||
/>
|
||||
<Button disabled={failures.length > 0} onClick={() => props.onSave(data)}>
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
import "./AutomationListBox.css";
|
||||
import { FC, useState } from 'react';
|
||||
import { FC, useState } from "react";
|
||||
import { AutomationData } from "types/automations";
|
||||
import InputMultiSelect from "components/Inputs/InputMultiSelect";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
@@ -8,126 +8,135 @@ import { makeGrouping } from "./automationGrouper";
|
||||
import { AutomationListBoxGroup } from "./AutomationListBoxGroup";
|
||||
import { useCookies } from "react-cookie";
|
||||
|
||||
|
||||
export type Props = {
|
||||
automations: AutomationData[];
|
||||
selected: number;
|
||||
onSelectAutomation: (i: number) => void;
|
||||
onRemove: (i: number) => void;
|
||||
onAdd: () => void;
|
||||
}
|
||||
automations: AutomationData[];
|
||||
selected: number;
|
||||
onSelectAutomation: (i: number) => void;
|
||||
onRemove: (i: number) => void;
|
||||
onAdd: () => void;
|
||||
};
|
||||
|
||||
const useAutomationListBoxState = () => {
|
||||
const [
|
||||
cookies,
|
||||
setCookies,
|
||||
// eslint-disable-next-line
|
||||
_
|
||||
] = useCookies(['albSearchText', 'albSelected']);
|
||||
let initialSelected = [];
|
||||
try {
|
||||
initialSelected = JSON.parse(cookies.albSelected)
|
||||
if (!Array.isArray(initialSelected)) {
|
||||
initialSelected = [initialSelected]
|
||||
}
|
||||
initialSelected = initialSelected.map(Number)
|
||||
// eslint-disable-next-line
|
||||
} catch (_) { }
|
||||
const [searchText, setSearchText] = useState(cookies.albSearchText ?? "");
|
||||
const [selectedTagIdx, setSelectedTagIdx] = useState<number[]>(initialSelected);
|
||||
|
||||
return {
|
||||
searchText,
|
||||
setSearchText(v: string) {
|
||||
setSearchText(v)
|
||||
setCookies('albSearchText', v)
|
||||
},
|
||||
setSelectedTagIdx(n: number[]) {
|
||||
setSelectedTagIdx(n)
|
||||
setCookies('albSelected', JSON.stringify(n))
|
||||
},
|
||||
selectedTagIdx,
|
||||
const [
|
||||
cookies,
|
||||
setCookies,
|
||||
// eslint-disable-next-line
|
||||
_,
|
||||
] = useCookies(["albSearchText", "albSelected"]);
|
||||
let initialSelected = [];
|
||||
try {
|
||||
initialSelected = JSON.parse(cookies.albSelected);
|
||||
if (!Array.isArray(initialSelected)) {
|
||||
initialSelected = [initialSelected];
|
||||
}
|
||||
}
|
||||
initialSelected = initialSelected.map(Number);
|
||||
// eslint-disable-next-line
|
||||
} catch (_) {}
|
||||
const [searchText, setSearchText] = useState(cookies.albSearchText ?? "");
|
||||
const [selectedTagIdx, setSelectedTagIdx] =
|
||||
useState<number[]>(initialSelected);
|
||||
|
||||
return {
|
||||
searchText,
|
||||
setSearchText(v: string) {
|
||||
setSearchText(v);
|
||||
setCookies("albSearchText", v);
|
||||
},
|
||||
setSelectedTagIdx(n: number[]) {
|
||||
setSelectedTagIdx(n);
|
||||
setCookies("albSelected", JSON.stringify(n));
|
||||
},
|
||||
selectedTagIdx,
|
||||
};
|
||||
};
|
||||
|
||||
export const AutomationListBox: FC<Props> = ({
|
||||
automations,
|
||||
selected,
|
||||
onSelectAutomation,
|
||||
onAdd,
|
||||
onRemove,
|
||||
automations,
|
||||
selected,
|
||||
onSelectAutomation,
|
||||
onAdd,
|
||||
onRemove,
|
||||
}) => {
|
||||
const tags = getTagList(automations);
|
||||
const { searchText, setSearchText, selectedTagIdx, setSelectedTagIdx } =
|
||||
useAutomationListBoxState();
|
||||
const filteredAutomations = filterAutomations(
|
||||
automations,
|
||||
searchText.toLowerCase()
|
||||
);
|
||||
const grouping = makeGrouping(
|
||||
filteredAutomations.map(([a, _]) => a),
|
||||
selectedTagIdx.map((i) => tags[i]),
|
||||
selected
|
||||
);
|
||||
|
||||
const tags = getTagList(automations);
|
||||
const {
|
||||
searchText,
|
||||
setSearchText,
|
||||
selectedTagIdx,
|
||||
setSelectedTagIdx,
|
||||
} = useAutomationListBoxState();
|
||||
const filteredAutomations = filterAutomations(automations, searchText.toLowerCase(), selectedTagIdx, tags);
|
||||
const grouping = makeGrouping(
|
||||
filteredAutomations.map(([a, _]) => a),
|
||||
selectedTagIdx.map(i => tags[i]),
|
||||
selected,
|
||||
)
|
||||
|
||||
return <div className="automation-list-box">
|
||||
<div className="automation-list-box--nav">
|
||||
<InputText
|
||||
label="Search"
|
||||
value={searchText}
|
||||
onChange={setSearchText}
|
||||
/>
|
||||
<InputMultiSelect
|
||||
label="Tags"
|
||||
selected={selectedTagIdx}
|
||||
onChange={setSelectedTagIdx}
|
||||
options={tags}
|
||||
max={3}
|
||||
/>
|
||||
</div>
|
||||
<div className="automation-list-box--body">
|
||||
<AutomationListBoxGroup
|
||||
events={{
|
||||
onSelectAutomation,
|
||||
onRemove
|
||||
}}
|
||||
autos={filteredAutomations}
|
||||
grouping={grouping}
|
||||
selectedAutomationIdx={selected}
|
||||
/>
|
||||
</div>
|
||||
<div className="automation-list-box--bottom">
|
||||
<Button onClick={onAdd}>Add</Button>
|
||||
<span>Showing Automations: {filteredAutomations.length} out of {automations.length}</span>
|
||||
</div>
|
||||
return (
|
||||
<div className="automation-list-box">
|
||||
<div className="automation-list-box--nav">
|
||||
<InputText label="Search" value={searchText} onChange={setSearchText} />
|
||||
<InputMultiSelect
|
||||
label="Tags"
|
||||
selected={selectedTagIdx}
|
||||
onChange={setSelectedTagIdx}
|
||||
options={tags}
|
||||
max={3}
|
||||
/>
|
||||
</div>
|
||||
<div className="automation-list-box--body">
|
||||
<AutomationListBoxGroup
|
||||
events={{
|
||||
onSelectAutomation,
|
||||
onRemove,
|
||||
}}
|
||||
autos={filteredAutomations}
|
||||
grouping={grouping}
|
||||
selectedAutomationIdx={selected}
|
||||
/>
|
||||
</div>
|
||||
<div className="automation-list-box--bottom">
|
||||
<Button onClick={onAdd}>Add</Button>
|
||||
<span>
|
||||
Showing Automations: {filteredAutomations.length} out of{" "}
|
||||
{automations.length}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
export const getTagList = (autos: AutomationData[]): string[] => Object.keys(autos
|
||||
.map(a => Object.keys(a.tags))
|
||||
.reduce((all: any, keys) => {
|
||||
export const getTagList = (autos: AutomationData[]): string[] =>
|
||||
Object.keys(
|
||||
autos
|
||||
.map((a) => Object.keys(a.tags))
|
||||
.reduce((all: any, keys) => {
|
||||
for (const k of keys) {
|
||||
all[k] = 1
|
||||
all[k] = 1;
|
||||
}
|
||||
return all;
|
||||
}, {}))
|
||||
}, {})
|
||||
);
|
||||
|
||||
const filterAutomations = (autos: AutomationData[], searchText: string, selected: number[], tags: string[]): Array<[AutomationData, number]> => autos.map<[AutomationData, number]>((a, i) => [a, i]).filter(([a, i]) => {
|
||||
if (!a.metadata) {
|
||||
return true
|
||||
}
|
||||
if (searchText.length > 0) {
|
||||
const filterAutomations = (
|
||||
autos: AutomationData[],
|
||||
searchText: string
|
||||
): Array<[AutomationData, number]> =>
|
||||
autos
|
||||
.map<[AutomationData, number]>((a, i) => [a, i])
|
||||
.filter(([a, i]) => {
|
||||
if (!a.metadata) {
|
||||
return true;
|
||||
}
|
||||
if (searchText.length > 0) {
|
||||
if (
|
||||
!(
|
||||
(a.metadata.description ?? "").toLocaleLowerCase().includes(searchText) ||
|
||||
(a.metadata.alias ?? "").toLocaleLowerCase().includes(searchText)
|
||||
)
|
||||
!(
|
||||
(a.metadata.description ?? "")
|
||||
.toLocaleLowerCase()
|
||||
.includes(searchText) ||
|
||||
(a.metadata.alias ?? "").toLocaleLowerCase().includes(searchText)
|
||||
)
|
||||
) {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
return true;
|
||||
});
|
||||
@@ -1,141 +1,166 @@
|
||||
|
||||
import { TrashIcon } from "components/Icons";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { MetadataBox } from "./AutomationMetadataBox";
|
||||
import { AutomationData } from "types/automations";
|
||||
import { AutomationGrouping } from "./automationGrouper";
|
||||
import { FC, useState } from "react";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
export type AutomationListBoxEvents = {
|
||||
onSelectAutomation: (i: number) => void,
|
||||
onRemove: (i: number) => void,
|
||||
}
|
||||
onSelectAutomation: (i: number) => void;
|
||||
onRemove: (i: number) => void;
|
||||
};
|
||||
export type AutomationListBoxGroups = {
|
||||
grouping: AutomationGrouping,
|
||||
currentNode: number,
|
||||
}
|
||||
grouping: AutomationGrouping;
|
||||
currentNode: number;
|
||||
};
|
||||
export type AutomationListBoxProps = {
|
||||
events: AutomationListBoxEvents,
|
||||
groups: AutomationListBoxGroups,
|
||||
autos: Array<[AutomationData, number]>,
|
||||
selectedAutomationIdx: number,
|
||||
events: AutomationListBoxEvents;
|
||||
groups: AutomationListBoxGroups;
|
||||
autos: Array<[AutomationData, number]>;
|
||||
selectedAutomationIdx: number;
|
||||
};
|
||||
export type AutomationListBoxGroupProps = {
|
||||
events: AutomationListBoxEvents,
|
||||
grouping: AutomationGrouping,
|
||||
autos: Array<[AutomationData, number]>,
|
||||
selectedAutomationIdx: number,
|
||||
}
|
||||
events: AutomationListBoxEvents;
|
||||
grouping: AutomationGrouping;
|
||||
autos: Array<[AutomationData, number]>;
|
||||
selectedAutomationIdx: number;
|
||||
};
|
||||
export const AutomationListBoxGroup: FC<AutomationListBoxGroupProps> = ({
|
||||
events, grouping, autos, selectedAutomationIdx,
|
||||
events,
|
||||
grouping,
|
||||
autos,
|
||||
selectedAutomationIdx,
|
||||
}) => {
|
||||
if (grouping.top.length === 1) {
|
||||
return <>
|
||||
{convertGroupsToItems(autos, {
|
||||
grouping, currentNode: grouping.top[0],
|
||||
}, events, selectedAutomationIdx)}
|
||||
</>
|
||||
} else {
|
||||
return <>
|
||||
{grouping.top.map(groupIdx => <AutomationListBoxGroupItem
|
||||
key={groupIdx}
|
||||
autos={autos}
|
||||
groups={{
|
||||
grouping,
|
||||
currentNode: groupIdx
|
||||
}}
|
||||
events={events}
|
||||
selectedAutomationIdx={selectedAutomationIdx}
|
||||
/>)}
|
||||
</>
|
||||
}
|
||||
}
|
||||
|
||||
export const convertGroupsToItems = (
|
||||
autos: Array<[AutomationData, number]>,
|
||||
{ grouping, currentNode }: AutomationListBoxGroups,
|
||||
events: AutomationListBoxEvents,
|
||||
selectedAutomationIdx: number,
|
||||
) => {
|
||||
const automations = grouping.getAutomations(currentNode);
|
||||
if (automations.length > 0) {
|
||||
return automations.map(autoIndex =>
|
||||
<AutomationListBoxItem
|
||||
key={`${autoIndex}-${autos[autoIndex][1]}`}
|
||||
events={events}
|
||||
auto={autos[autoIndex]}
|
||||
isSelected={selectedAutomationIdx === autos[autoIndex][1]}
|
||||
/>
|
||||
)
|
||||
}
|
||||
const subgroups = grouping.getSubGroups(currentNode);
|
||||
if (subgroups.length > 0) {
|
||||
return subgroups.map(groupIdx => <AutomationListBoxGroupItem
|
||||
if (grouping.top.length === 1) {
|
||||
return (
|
||||
<>
|
||||
{convertGroupsToItems(
|
||||
autos,
|
||||
{
|
||||
grouping,
|
||||
currentNode: grouping.top[0],
|
||||
},
|
||||
events,
|
||||
selectedAutomationIdx
|
||||
)}
|
||||
</>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<>
|
||||
{grouping.top.map((groupIdx) => (
|
||||
<AutomationListBoxGroupItem
|
||||
key={groupIdx}
|
||||
autos={autos}
|
||||
groups={{
|
||||
grouping,
|
||||
currentNode: groupIdx
|
||||
grouping,
|
||||
currentNode: groupIdx,
|
||||
}}
|
||||
events={events}
|
||||
selectedAutomationIdx={selectedAutomationIdx}
|
||||
/>)
|
||||
}
|
||||
return <></>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const convertGroupsToItems = (
|
||||
autos: Array<[AutomationData, number]>,
|
||||
{ grouping, currentNode }: AutomationListBoxGroups,
|
||||
events: AutomationListBoxEvents,
|
||||
selectedAutomationIdx: number
|
||||
) => {
|
||||
const automations = grouping.getAutomations(currentNode);
|
||||
if (automations.length > 0) {
|
||||
return automations.map((autoIndex) => (
|
||||
<AutomationListBoxItem
|
||||
key={`${autoIndex}-${autos[autoIndex][1]}`}
|
||||
events={events}
|
||||
auto={autos[autoIndex]}
|
||||
isSelected={selectedAutomationIdx === autos[autoIndex][1]}
|
||||
/>
|
||||
));
|
||||
}
|
||||
const subgroups = grouping.getSubGroups(currentNode);
|
||||
if (subgroups.length > 0) {
|
||||
return subgroups.map((groupIdx) => (
|
||||
<AutomationListBoxGroupItem
|
||||
key={groupIdx}
|
||||
autos={autos}
|
||||
groups={{
|
||||
grouping,
|
||||
currentNode: groupIdx,
|
||||
}}
|
||||
events={events}
|
||||
selectedAutomationIdx={selectedAutomationIdx}
|
||||
/>
|
||||
));
|
||||
}
|
||||
return <></>;
|
||||
};
|
||||
|
||||
export const AutomationListBoxGroupItem: FC<{
|
||||
events: AutomationListBoxEvents,
|
||||
groups: AutomationListBoxGroups,
|
||||
autos: Array<[AutomationData, number]>,
|
||||
selectedAutomationIdx: number,
|
||||
}> = ({
|
||||
autos, groups, events, selectedAutomationIdx,
|
||||
}) => {
|
||||
const groupData = groups.grouping.getData(groups.currentNode);
|
||||
const automations = groups.grouping.getAutomations(groups.currentNode);
|
||||
const [open, setOpen] = useState(false);
|
||||
const isOther = groupData.isOther;
|
||||
const openIcon = !open ? "⊕" : "⊖";
|
||||
const total = isOther ? <small>
|
||||
{automations.length} automation{automations.length !== 1 ? 's' : ''} {groupData.isOther ? "" : "(untagged)"}
|
||||
</small> : <></>
|
||||
return <div className={[
|
||||
"automation-list-box--body--group",
|
||||
isOther ? 'other' : '',
|
||||
groupData.selected ? 'selected' : '',
|
||||
].join(' ')}>
|
||||
<b onClick={() => setOpen(!open)}>{groupData.name} {openIcon} {total}</b>
|
||||
{open && convertGroupsToItems(autos, groups, events, selectedAutomationIdx)}
|
||||
</div>
|
||||
}
|
||||
|
||||
events: AutomationListBoxEvents;
|
||||
groups: AutomationListBoxGroups;
|
||||
autos: Array<[AutomationData, number]>;
|
||||
selectedAutomationIdx: number;
|
||||
}> = ({ autos, groups, events, selectedAutomationIdx }) => {
|
||||
const groupData = groups.grouping.getData(groups.currentNode);
|
||||
const automations = groups.grouping.getAutomations(groups.currentNode);
|
||||
const [open, setOpen] = useState(false);
|
||||
const isOther = groupData.isOther;
|
||||
const openIcon = !open ? "⊕" : "⊖";
|
||||
const total = isOther ? (
|
||||
<small>
|
||||
{automations.length} automation{automations.length !== 1 ? "s" : ""}{" "}
|
||||
{groupData.isOther ? "" : "(untagged)"}
|
||||
</small>
|
||||
) : (
|
||||
<></>
|
||||
);
|
||||
return (
|
||||
<div
|
||||
className={[
|
||||
"automation-list-box--body--group",
|
||||
isOther ? "other" : "",
|
||||
groupData.selected ? "selected" : "",
|
||||
].join(" ")}
|
||||
>
|
||||
<b onClick={() => setOpen(!open)}>
|
||||
{groupData.name} {openIcon} {total}
|
||||
</b>
|
||||
{open &&
|
||||
convertGroupsToItems(autos, groups, events, selectedAutomationIdx)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const AutomationListBoxItem: FC<{
|
||||
auto: [AutomationData, number],
|
||||
isSelected: boolean,
|
||||
events: AutomationListBoxEvents,
|
||||
auto: [AutomationData, number];
|
||||
isSelected: boolean;
|
||||
events: AutomationListBoxEvents;
|
||||
}> = ({
|
||||
events: {
|
||||
onRemove,
|
||||
onSelectAutomation,
|
||||
},
|
||||
auto: [
|
||||
auto, autoIndex
|
||||
],
|
||||
isSelected,
|
||||
events: { onRemove, onSelectAutomation },
|
||||
auto: [auto, autoIndex],
|
||||
isSelected,
|
||||
}) => {
|
||||
let title = "BadAuto<<Missing Metadata>>"
|
||||
if (auto.metadata) {
|
||||
title = `Name = ${auto.metadata.alias}\nID = ${auto.metadata.id}\nDescription = ${auto.metadata.description}`
|
||||
}
|
||||
return <div
|
||||
key={autoIndex}
|
||||
className={["automation-list-box--body--item", isSelected ? 'selected' : ''].join(' ')}
|
||||
title={title}
|
||||
onClick={() => onSelectAutomation(autoIndex)}
|
||||
>
|
||||
<MetadataBox metadata={auto.metadata} tags={auto.tags} />
|
||||
<Button onClick={() => onRemove(autoIndex)}><TrashIcon /></Button>
|
||||
</div>
|
||||
}
|
||||
let title = "BadAuto<<Missing Metadata>>";
|
||||
if (auto.metadata) {
|
||||
title = `Name = ${auto.metadata.alias}\nID = ${auto.metadata.id}\nDescription = ${auto.metadata.description}`;
|
||||
}
|
||||
return (
|
||||
<div
|
||||
key={autoIndex}
|
||||
className={[
|
||||
"automation-list-box--body--item",
|
||||
isSelected ? "selected" : "",
|
||||
].join(" ")}
|
||||
title={title}
|
||||
onClick={() => onSelectAutomation(autoIndex)}
|
||||
>
|
||||
<MetadataBox metadata={auto.metadata} tags={auto.tags} />
|
||||
<ButtonIcon onClick={() => onRemove(autoIndex)} icon={<TrashIcon />} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -50,6 +50,7 @@
|
||||
|
||||
.automation-list--list.hide>.automation-list--list-hide {
|
||||
transform: rotate(180deg);
|
||||
left: 0;
|
||||
}
|
||||
|
||||
/* list children: normal */
|
||||
@@ -58,8 +59,10 @@
|
||||
border-width: 1px;
|
||||
}
|
||||
|
||||
.automation-list--list-hide {
|
||||
.automation-list--list .automation-list--list-hide {
|
||||
position: absolute;
|
||||
bottom: 0.5em;
|
||||
right: 0.5em;
|
||||
bottom: 0em;
|
||||
left: 0.5em;
|
||||
max-width: 1.5em;
|
||||
max-height: 1.5em;
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
.automation-list--root.mobile .automation-list--list-hide {
|
||||
transform: rotate(90deg);
|
||||
left: 1.25em;
|
||||
left: 0.25em;
|
||||
}
|
||||
|
||||
.automation-list--root.mobile .automation-editor--info-box {
|
||||
@@ -33,7 +33,7 @@
|
||||
}
|
||||
|
||||
.automation-list--root.mobile .automation-editor--info-box--icon {
|
||||
left: 1.25em;
|
||||
left: 0.5em;
|
||||
bottom: 0em;
|
||||
background-color: var(--primary);
|
||||
transform: rotate(90deg);
|
||||
@@ -50,8 +50,8 @@
|
||||
.automation-list--root.mobile .automation-list--list.hide .automation-list--list-hide {
|
||||
transform: rotate(270deg);
|
||||
position: fixed;
|
||||
top: 0.75em;
|
||||
z-index: 20;
|
||||
top: 0;
|
||||
z-index: 5;
|
||||
}
|
||||
|
||||
/* info box hide */
|
||||
@@ -64,9 +64,9 @@
|
||||
.automation-list--root.mobile .automation-editor--info-box.hide .automation-editor--info-box--icon {
|
||||
transform: rotate(270deg);
|
||||
position: fixed;
|
||||
top: 0.75em;
|
||||
background-color: var(--green-opaque);
|
||||
z-index: 30;
|
||||
top: 0em;
|
||||
left: 0.25em;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import { AutomationEditor } from "components/AutomationEditor";
|
||||
import { FC, ReactNode, useState } from "react";
|
||||
import { AutomationData } from "types/automations";
|
||||
import { defaultAutomation } from "utils/defaults";
|
||||
import { ArrowIcon } from "components/Icons";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { ApiService } from "apiService/core";
|
||||
import { AutomationListBox } from "./AutomationListBox";
|
||||
@@ -15,6 +14,7 @@ import LinearProgress from "@mui/material/LinearProgress";
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
import { useCookies } from "react-cookie";
|
||||
import { useHA } from "haService";
|
||||
import { ArrowBack } from "@mui/icons-material";
|
||||
|
||||
interface AutomationListParams {
|
||||
automations: AutomationData[];
|
||||
@@ -97,7 +97,7 @@ export const AutomationList: FC<AutomationListParams> = ({
|
||||
<ButtonIcon
|
||||
onClick={() => setHideList(!hideList)}
|
||||
className="automation-list--list-hide"
|
||||
Icon={ArrowIcon}
|
||||
icon={<ArrowBack />}
|
||||
/>
|
||||
</div>
|
||||
<div className="automation-list--viewer">
|
||||
|
||||
@@ -39,11 +39,13 @@ export function DeviceEditor<DBT extends DeviceBaseType>({
|
||||
return (
|
||||
<>
|
||||
<InputDevice
|
||||
key="devices"
|
||||
label="Device"
|
||||
value={state.device_id ?? ""}
|
||||
onChange={(device_id) => setState({ device_id: device_id ?? "" })}
|
||||
/>
|
||||
<InputAutoComplete
|
||||
key="action"
|
||||
label="Action"
|
||||
multiple={false}
|
||||
value={actionId}
|
||||
@@ -76,6 +78,7 @@ export function DeviceEditor<DBT extends DeviceBaseType>({
|
||||
)}
|
||||
{caps?.extra_fields && (
|
||||
<InputDeviceCapabilties
|
||||
key="caps"
|
||||
state={state}
|
||||
setState={setState}
|
||||
defn={caps.extra_fields}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
.MuiButtonBase-root.icon-button[type="button"] {
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
max-width: 1.5em;
|
||||
max-height: 1.5em;
|
||||
}
|
||||
@@ -1,30 +1,24 @@
|
||||
import { FC } from 'react';
|
||||
import { IconBaseProps } from './base';
|
||||
import { createAppUseStyles } from 'styles/theme';
|
||||
import "./ButtonIcons.css";
|
||||
import { FC, ReactNode } from "react";
|
||||
import MuiIconButton, { IconButtonTypeMap } from "@mui/material/IconButton";
|
||||
|
||||
export interface ButtonIconStyleProps {
|
||||
}
|
||||
export interface ButtonIconProps extends IconBaseProps, ButtonIconStyleProps {
|
||||
Icon: FC<IconBaseProps>;
|
||||
}
|
||||
const useButtonIconStyles = createAppUseStyles(theme => ({
|
||||
buttonIcon: {
|
||||
borderRadius: "100%",
|
||||
borderWidth: 1,
|
||||
borderStyle: "groove",
|
||||
padding: "0.25em",
|
||||
"&:hover": {
|
||||
backgroundColor: theme.secondaryAccent,
|
||||
cursor: 'pointer',
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
|
||||
export const ButtonIcon: FC<ButtonIconProps> = ({
|
||||
Icon,
|
||||
className,
|
||||
...props
|
||||
}) => <Icon
|
||||
className={`${useButtonIconStyles({}).classes.buttonIcon} ${className}`} {...props}
|
||||
/>
|
||||
export const ButtonIcon: FC<{
|
||||
icon: ReactNode;
|
||||
onClick?: () => void;
|
||||
className?: string;
|
||||
title?: string;
|
||||
disabled?: boolean;
|
||||
color?: IconButtonTypeMap["props"]["color"];
|
||||
}> = (props) => {
|
||||
return (
|
||||
<MuiIconButton
|
||||
className={["icon-button", props.className ?? ""].join(" ")}
|
||||
onClick={props.onClick}
|
||||
title={props.title}
|
||||
color={props.color}
|
||||
disabled={props.disabled}
|
||||
>
|
||||
{props.icon}
|
||||
</MuiIconButton>
|
||||
);
|
||||
};
|
||||
@@ -1,41 +1,50 @@
|
||||
import { ComponentStory } from "@storybook/react";
|
||||
|
||||
import { IconBase } from "./base";
|
||||
import { PencilIcon, CheckMarkIcon, TrashIcon, InfoIcon, ArrowIcon, AddIcon, ZoomIcon, GearIcon } from ".";
|
||||
import {
|
||||
PencilIcon,
|
||||
CheckMarkIcon,
|
||||
TrashIcon,
|
||||
InfoIcon,
|
||||
ArrowIcon,
|
||||
AddIcon,
|
||||
ZoomIcon,
|
||||
GearIcon,
|
||||
} from ".";
|
||||
import { ButtonIcon } from "./ButtonIcons";
|
||||
import { Page } from "components/Page";
|
||||
|
||||
export default {
|
||||
title: 'Icons',
|
||||
title: "Icons",
|
||||
component: IconBase,
|
||||
};
|
||||
|
||||
|
||||
export const IconList: ComponentStory<typeof IconBase> = (args) => {
|
||||
|
||||
return <Page>
|
||||
<PencilIcon {...args} />
|
||||
<CheckMarkIcon {...args} />
|
||||
<AddIcon {...args} />
|
||||
<TrashIcon {...args} />
|
||||
<InfoIcon {...args} />
|
||||
<ZoomIcon {...args} />
|
||||
<GearIcon {...args} />
|
||||
</Page>
|
||||
}
|
||||
return (
|
||||
<Page>
|
||||
<PencilIcon {...args} />
|
||||
<CheckMarkIcon {...args} />
|
||||
<AddIcon {...args} />
|
||||
<TrashIcon {...args} />
|
||||
<InfoIcon {...args} />
|
||||
<ZoomIcon {...args} />
|
||||
<GearIcon {...args} />
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
IconList.args = {
|
||||
size: 2,
|
||||
color: 'red'
|
||||
}
|
||||
|
||||
color: "red",
|
||||
};
|
||||
|
||||
export const ButtonIconExample: ComponentStory<typeof IconBase> = (args) => {
|
||||
|
||||
return <Page>
|
||||
<ButtonIcon {...args} Icon={ArrowIcon} />
|
||||
</Page>
|
||||
}
|
||||
return (
|
||||
<Page>
|
||||
<ButtonIcon icon={<ArrowIcon {...args} />} />
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
ButtonIconExample.args = {
|
||||
size: 2,
|
||||
color: 'red'
|
||||
}
|
||||
color: "red",
|
||||
};
|
||||
@@ -1,7 +1,21 @@
|
||||
import { ButtonHTMLAttributes, FC } from "react";
|
||||
import { useButtonStyles } from "./styles";
|
||||
import { FC, ReactNode } from "react";
|
||||
import MuiButton from "@mui/material/Button";
|
||||
|
||||
export const Button: FC<ButtonHTMLAttributes<HTMLButtonElement>> = props => {
|
||||
const { classes } = useButtonStyles({});
|
||||
return <button {...props} className={`${classes.input} ${props.className ?? ''}`} />
|
||||
}
|
||||
export const Button: FC<{
|
||||
className?: string;
|
||||
title?: string;
|
||||
disabled?: boolean;
|
||||
children?: ReactNode;
|
||||
onClick?: () => void;
|
||||
}> = (props) => {
|
||||
return (
|
||||
<MuiButton
|
||||
className={props.className}
|
||||
title={props.title}
|
||||
disabled={props.disabled}
|
||||
onClick={props.onClick}
|
||||
variant="outlined"
|
||||
children={props.children}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -2,7 +2,8 @@ import "./InputAutoComplete.css";
|
||||
import Autocomplete from "@mui/material/Autocomplete";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import Chip from "@mui/material/Chip";
|
||||
import { Badge, Popper } from "@mui/material";
|
||||
import Badge from "@mui/material/Badge";
|
||||
import Popper from "@mui/material/Popper";
|
||||
import { SearchItem } from "./extras";
|
||||
import { ReactNode } from "react";
|
||||
import { prettyName } from "utils/formatting";
|
||||
|
||||
@@ -2,7 +2,8 @@ import Checkbox from "@mui/material/Checkbox";
|
||||
import FormGroup from "@mui/material/FormGroup";
|
||||
import FormControlLabel from "@mui/material/FormControlLabel";
|
||||
import { ReactNode } from "react";
|
||||
import { FormHelperText, InputAdornment } from "@mui/material";
|
||||
import FormHelperText from "@mui/material/FormHelperText";
|
||||
import InputAdornment from "@mui/material/InputAdornment";
|
||||
|
||||
export interface Props {
|
||||
label: string;
|
||||
|
||||
@@ -3,7 +3,6 @@ import { useState, useEffect, FC } from "react";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import CloseIcon from "@mui/icons-material/Close";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import { AutomationTime, AutomationTimeObject } from "types/automations/common";
|
||||
import {
|
||||
convertAutomationTimeToTimeObject,
|
||||
@@ -12,6 +11,7 @@ import {
|
||||
import { convertAutomationTimeToTimeString } from "utils/time";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import InputLabel from "@mui/material/InputLabel";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
// constants
|
||||
const fields: Array<keyof AutomationTimeObject> = [
|
||||
@@ -140,9 +140,10 @@ export const InputTime: FC<Props> = (props) => {
|
||||
onChange={(e) => updateOne(name)(e.target.value)}
|
||||
/>
|
||||
))}
|
||||
<IconButton onClick={() => setDisabled(!disabled)}>
|
||||
{disabled ? <EditIcon /> : <CloseIcon />}
|
||||
</IconButton>
|
||||
<ButtonIcon
|
||||
onClick={() => setDisabled(!disabled)}
|
||||
icon={disabled ? <EditIcon /> : <CloseIcon />}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
.input-number .MuiButtonBase-root.icon-button[type="button"].icon-button {
|
||||
border-style: none;
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
import "./InputNumber.css";
|
||||
import Close from "@mui/icons-material/Close";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import InputAdornment from "@mui/material/InputAdornment";
|
||||
import Edit from "@mui/icons-material/Edit";
|
||||
import { ReactNode } from "react";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
export interface Props {
|
||||
label: string | JSX.Element;
|
||||
@@ -57,7 +58,7 @@ export default function InputNumber({
|
||||
value={value}
|
||||
onChange={(e) => onChange(Number(e.target.value ?? 0))}
|
||||
disabled={disabled}
|
||||
className={className}
|
||||
className={["input-number", className ?? ""].join(" ")}
|
||||
placeholder={placeholder}
|
||||
required={required}
|
||||
fullWidth
|
||||
@@ -67,9 +68,10 @@ export default function InputNumber({
|
||||
endAdornment
|
||||
) : (
|
||||
<InputAdornment position="end">
|
||||
<IconButton onClick={() => onChange(disabled ? 0 : undefined)}>
|
||||
{disabled ? <Edit /> : <Close />}
|
||||
</IconButton>
|
||||
<ButtonIcon
|
||||
onClick={() => onChange(disabled ? 0 : undefined)}
|
||||
icon={disabled ? <Edit /> : <Close />}
|
||||
/>
|
||||
</InputAdornment>
|
||||
),
|
||||
inputProps: {
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
display: flex;
|
||||
gap: 0;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.input-time>.input-time--inner>.icon-button {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.input-time>.input-time--inner>.MuiFormControl-root {
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
import "./InputTime.css";
|
||||
import { useState, useEffect, FC } from "react";
|
||||
import TextField from '@mui/material/TextField';
|
||||
import EditIcon from '@mui/icons-material/Edit';
|
||||
import TextField from "@mui/material/TextField";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import CloseIcon from "@mui/icons-material/Close";
|
||||
import IconButton from "@mui/material/IconButton"
|
||||
import { AutomationTime, AutomationTimeObject } from "types/automations/common";
|
||||
import { convertAutomationTimeToTimeObject, convertObjectToAutomationTimeString, convertAutomationTimeToTimeString } from 'utils/time';
|
||||
import {
|
||||
convertAutomationTimeToTimeObject,
|
||||
convertObjectToAutomationTimeString,
|
||||
convertAutomationTimeToTimeString,
|
||||
} from "utils/time";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
// constants
|
||||
const fields: Array<keyof AutomationTimeObject> = [
|
||||
'hours',
|
||||
'minutes',
|
||||
'seconds',
|
||||
'milliseconds'
|
||||
]
|
||||
"hours",
|
||||
"minutes",
|
||||
"seconds",
|
||||
"milliseconds",
|
||||
];
|
||||
export interface Props {
|
||||
label: string;
|
||||
value?: AutomationTime;
|
||||
@@ -22,73 +26,73 @@ export interface Props {
|
||||
className?: string;
|
||||
}
|
||||
export const InputTime: FC<Props> = (props) => {
|
||||
|
||||
|
||||
// state
|
||||
const [disabled, setDisabled] = useState(!props.value)
|
||||
const [displayValue, setDisplayValue] = useState(convertAutomationTimeToTimeObject(props.value))
|
||||
const [disabled, setDisabled] = useState(!props.value);
|
||||
const [displayValue, setDisplayValue] = useState(
|
||||
convertAutomationTimeToTimeObject(props.value)
|
||||
);
|
||||
|
||||
// process display input
|
||||
const updateOne = (k: keyof AutomationTimeObject) => (v: string) => {
|
||||
if (Number(v) < 0) {
|
||||
setDisplayValue({
|
||||
...displayValue,
|
||||
[k]: 0
|
||||
})
|
||||
[k]: 0,
|
||||
});
|
||||
} else if (k === "hours") {
|
||||
setDisplayValue({
|
||||
...displayValue,
|
||||
[k]: Number(v)
|
||||
})
|
||||
[k]: Number(v),
|
||||
});
|
||||
} else if (k === "minutes") {
|
||||
let minutes = Number(v);
|
||||
let { hours = 0 } = displayValue
|
||||
let { hours = 0 } = displayValue;
|
||||
if (minutes > 59) {
|
||||
const additonalHours = Math.floor(minutes / 60)
|
||||
hours += additonalHours
|
||||
minutes = minutes - additonalHours * 60
|
||||
const additonalHours = Math.floor(minutes / 60);
|
||||
hours += additonalHours;
|
||||
minutes = minutes - additonalHours * 60;
|
||||
}
|
||||
setDisplayValue({
|
||||
...displayValue,
|
||||
minutes,
|
||||
hours,
|
||||
})
|
||||
});
|
||||
} else if (k === "seconds") {
|
||||
let seconds = Number(v);
|
||||
let { hours = 0, minutes = 0 } = displayValue
|
||||
let { hours = 0, minutes = 0 } = displayValue;
|
||||
if (seconds > 59) {
|
||||
const additonalHours = Math.floor(seconds / (60 * 60))
|
||||
hours += additonalHours
|
||||
seconds = seconds - additonalHours * 60
|
||||
const additonalHours = Math.floor(seconds / (60 * 60));
|
||||
hours += additonalHours;
|
||||
seconds = seconds - additonalHours * 60;
|
||||
}
|
||||
if (seconds > 59) {
|
||||
const additionalMinutes = Math.floor(seconds / 60)
|
||||
minutes += additionalMinutes
|
||||
seconds = seconds - additionalMinutes * 60
|
||||
const additionalMinutes = Math.floor(seconds / 60);
|
||||
minutes += additionalMinutes;
|
||||
seconds = seconds - additionalMinutes * 60;
|
||||
}
|
||||
setDisplayValue({
|
||||
...displayValue,
|
||||
minutes,
|
||||
hours,
|
||||
seconds,
|
||||
})
|
||||
});
|
||||
} else if (k === "milliseconds") {
|
||||
let milliseconds = Number(v);
|
||||
let { hours = 0, minutes = 0, seconds = 0 } = displayValue
|
||||
let { hours = 0, minutes = 0, seconds = 0 } = displayValue;
|
||||
if (milliseconds > 1000) {
|
||||
const additonalHours = Math.floor(milliseconds / (60 * 60 * 1000))
|
||||
hours += additonalHours
|
||||
milliseconds = milliseconds - additonalHours * 60 * 60 * 1000
|
||||
const additonalHours = Math.floor(milliseconds / (60 * 60 * 1000));
|
||||
hours += additonalHours;
|
||||
milliseconds = milliseconds - additonalHours * 60 * 60 * 1000;
|
||||
}
|
||||
if (milliseconds > 1000) {
|
||||
const additionalMinutes = Math.floor(milliseconds / (60 * 1000))
|
||||
minutes += additionalMinutes
|
||||
milliseconds = milliseconds - additionalMinutes * 60 * 1000
|
||||
const additionalMinutes = Math.floor(milliseconds / (60 * 1000));
|
||||
minutes += additionalMinutes;
|
||||
milliseconds = milliseconds - additionalMinutes * 60 * 1000;
|
||||
}
|
||||
if (milliseconds > 1000) {
|
||||
const additionalSeconds = Math.floor(milliseconds / 1000)
|
||||
seconds += additionalSeconds
|
||||
milliseconds = milliseconds - additionalSeconds * 1000
|
||||
const additionalSeconds = Math.floor(milliseconds / 1000);
|
||||
seconds += additionalSeconds;
|
||||
milliseconds = milliseconds - additionalSeconds * 1000;
|
||||
}
|
||||
setDisplayValue({
|
||||
...displayValue,
|
||||
@@ -96,50 +100,51 @@ export const InputTime: FC<Props> = (props) => {
|
||||
hours,
|
||||
seconds,
|
||||
milliseconds,
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// effect
|
||||
useEffect(() => {
|
||||
if (disabled && !props.value) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
if (disabled) {
|
||||
props.onChange(undefined)
|
||||
props.onChange(undefined);
|
||||
} else {
|
||||
const pVal = convertAutomationTimeToTimeString(props.value);
|
||||
const cVal = convertObjectToAutomationTimeString(displayValue);
|
||||
if (pVal !== cVal) {
|
||||
props.onChange(displayValue)
|
||||
props.onChange(displayValue);
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line
|
||||
}, [disabled, displayValue])
|
||||
}, [disabled, displayValue]);
|
||||
|
||||
|
||||
return <div className={["input-time", props.className ?? ""].join(" ")}>
|
||||
{/* <InputLabel >{props.label}</InputLabel> */}
|
||||
<div className="input-time--inner">
|
||||
{fields.map(name =>
|
||||
<TextField
|
||||
key={name}
|
||||
variant="filled"
|
||||
label={prettyName(name)}
|
||||
defaultValue="00"
|
||||
InputProps={{
|
||||
disabled,
|
||||
type: "number",
|
||||
title: prettyName(name),
|
||||
}}
|
||||
value={displayValue[name] ?? 0}
|
||||
onChange={e => updateOne(name)(e.target.value)}
|
||||
return (
|
||||
<div className={["input-time", props.className ?? ""].join(" ")}>
|
||||
{/* <InputLabel >{props.label}</InputLabel> */}
|
||||
<div className="input-time--inner">
|
||||
{fields.map((name) => (
|
||||
<TextField
|
||||
key={name}
|
||||
variant="filled"
|
||||
label={prettyName(name)}
|
||||
defaultValue="00"
|
||||
InputProps={{
|
||||
disabled,
|
||||
type: "number",
|
||||
title: prettyName(name),
|
||||
}}
|
||||
value={displayValue[name] ?? 0}
|
||||
onChange={(e) => updateOne(name)(e.target.value)}
|
||||
/>
|
||||
))}
|
||||
<ButtonIcon
|
||||
onClick={() => setDisabled(!disabled)}
|
||||
icon={disabled ? <EditIcon /> : <CloseIcon />}
|
||||
/>
|
||||
)}
|
||||
<IconButton onClick={() => setDisabled(!disabled)}>
|
||||
{disabled ? <EditIcon /> : <CloseIcon />}
|
||||
</IconButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
.input-yaml .MuiInputAdornment-positionEnd {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 55%;
|
||||
right: 0.5em;
|
||||
top: 3.5em;
|
||||
}
|
||||
|
||||
.input-yaml .input-yaml--placeholder {
|
||||
@@ -34,4 +34,8 @@
|
||||
left: 2em;
|
||||
top: 2.5em;
|
||||
color: var(--primary-accent);
|
||||
}
|
||||
|
||||
.input-yaml .MuiButtonBase-root.icon-button[type="button"].icon-button {
|
||||
border-style: none;
|
||||
}
|
||||
@@ -5,8 +5,10 @@ import { useEffect, useState, ReactNode } from "react";
|
||||
import CodeMirror from "@uiw/react-codemirror";
|
||||
import FormControl from "@mui/material/FormControl";
|
||||
import InputLabel from "@mui/material/InputLabel";
|
||||
import { FormHelperText, IconButton, InputAdornment } from "@mui/material";
|
||||
import FormHelperText from "@mui/material/FormHelperText";
|
||||
import InputAdornment from "@mui/material/InputAdornment";
|
||||
import { Save } from "@mui/icons-material";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
export interface Props<T extends {}> {
|
||||
label: string;
|
||||
@@ -94,15 +96,16 @@ export default function InputYaml<T extends {}>({
|
||||
{!!text ? "" : placeholder}
|
||||
</span>
|
||||
<InputAdornment position="end">
|
||||
<IconButton
|
||||
<ButtonIcon
|
||||
disabled={!hasChanged}
|
||||
onClick={() => onSave()}
|
||||
title={!!error ? "Invalid YAML" : hasChanged ? "Save" : ""}
|
||||
>
|
||||
<Save
|
||||
color={hasChanged ? (!!error ? "error" : "success") : "disabled"}
|
||||
/>
|
||||
</IconButton>
|
||||
icon={
|
||||
<Save
|
||||
color={hasChanged ? (!!error ? "error" : "success") : "disabled"}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
{endAdornment}
|
||||
</InputAdornment>
|
||||
<FormHelperText variant="filled" error={!!error}>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
.modal--root {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 10;
|
||||
position: fixed;
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.modal--root>div {
|
||||
max-width: fit-content;
|
||||
min-width: 100px;
|
||||
padding: 0.25em;
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import "./index.css";
|
||||
import Paper from "@mui/material/Paper";
|
||||
import MuiModal from "@mui/material/Modal";
|
||||
import { FC, ReactNode } from "react";
|
||||
import { createAppUseStyles } from "styles/theme";
|
||||
|
||||
export interface ModalStyleProps {
|
||||
open: boolean;
|
||||
@@ -7,55 +9,12 @@ export interface ModalStyleProps {
|
||||
export interface Props extends ModalStyleProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
const useModalStyle = createAppUseStyles<ModalStyleProps>(theme => ({
|
||||
root: ({ open }) => ({
|
||||
display: open ? 'flex' : 'none',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
zIndex: open ? 10 : -1,
|
||||
position: 'fixed',
|
||||
height: '100vh',
|
||||
width: '100vw',
|
||||
top: 0,
|
||||
left: 0,
|
||||
}),
|
||||
background: {
|
||||
zIndex: 5,
|
||||
position: 'absolute',
|
||||
height: '100vh',
|
||||
width: '100vw',
|
||||
top: 0,
|
||||
left: 0,
|
||||
backgroundColor: theme.secondaryOpaque,
|
||||
},
|
||||
inner: {
|
||||
zIndex: 10,
|
||||
maxWidth: '80vw',
|
||||
maxHeight: '90vh',
|
||||
minHeight: 'min-content',
|
||||
minWidth: '100px',
|
||||
padding: '15px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
backgroundColor: theme.primary,
|
||||
borderSize: '1px',
|
||||
borderStyle: 'solid',
|
||||
borderColor: theme.primaryAccent,
|
||||
borderRadius: '10px',
|
||||
color: theme.primaryAccent,
|
||||
overflow: "auto",
|
||||
resize: "auto",
|
||||
}
|
||||
}));
|
||||
export const Modal: FC<Props> = ({
|
||||
children,
|
||||
...props
|
||||
}) => {
|
||||
const { classes } = useModalStyle(props);
|
||||
return <div className={classes.root}>
|
||||
<div className={classes.background} />
|
||||
<div className={classes.inner}>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
export const Modal: FC<Props> = ({ children, ...props }) => {
|
||||
return (
|
||||
<MuiModal open={props.open}>
|
||||
<div className="modal--root">
|
||||
<Paper>{children}</Paper>
|
||||
</div>
|
||||
</MuiModal>
|
||||
);
|
||||
};
|
||||
@@ -1,80 +1,97 @@
|
||||
import "./index.css";
|
||||
import { createRef, FC, ReactNode, useEffect, useRef } from 'react';
|
||||
import { createTheme, ThemeProvider, useTheme } from '@mui/material/styles';
|
||||
import { createRef, FC, ReactNode, useEffect, useRef } from "react";
|
||||
import { createTheme, ThemeProvider, useTheme } from "@mui/material/styles";
|
||||
import { VersionBox } from "components/VersionBox";
|
||||
import { SnackbarKey, SnackbarProvider, useSnackbar } from 'notistack';
|
||||
import { Button } from "@mui/material";
|
||||
import { useHAConnection } from 'haService/connection';
|
||||
import { SnackbarKey, SnackbarProvider, useSnackbar } from "notistack";
|
||||
import Button from "@mui/material/Button";
|
||||
import { useHAConnection } from "haService/connection";
|
||||
|
||||
const theme = createTheme({
|
||||
palette: {
|
||||
mode: 'dark'
|
||||
},
|
||||
palette: {
|
||||
mode: "dark",
|
||||
},
|
||||
});
|
||||
|
||||
export const InternalPage: FC<{
|
||||
children: ReactNode
|
||||
children: ReactNode;
|
||||
}> = ({ children }) => {
|
||||
const conn = useHAConnection();
|
||||
const theme = useTheme();
|
||||
const snackbar = useSnackbar();
|
||||
const snackbarKeyHAConKey = useRef<SnackbarKey | null>(null);
|
||||
const conn = useHAConnection();
|
||||
const theme = useTheme();
|
||||
const snackbar = useSnackbar();
|
||||
const snackbarKeyHAConKey = useRef<SnackbarKey | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (conn.status === 'error') {
|
||||
if (snackbarKeyHAConKey.current) {
|
||||
snackbar.closeSnackbar(snackbarKeyHAConKey.current)
|
||||
}
|
||||
snackbarKeyHAConKey.current = snackbar.enqueueSnackbar(`Failed to connect to homeassistant due to "${JSON.stringify(conn.error)}"`, {
|
||||
"variant": "error",
|
||||
"persist": true,
|
||||
})
|
||||
} else if (conn.status === 'loading') {
|
||||
if (snackbarKeyHAConKey.current) {
|
||||
snackbar.closeSnackbar(snackbarKeyHAConKey.current)
|
||||
}
|
||||
snackbarKeyHAConKey.current = snackbar.enqueueSnackbar(`Connecting to websocket...`, {
|
||||
"variant": "info",
|
||||
})
|
||||
} else if (conn.status === "loaded") {
|
||||
if (snackbarKeyHAConKey.current) {
|
||||
snackbar.closeSnackbar(snackbarKeyHAConKey.current)
|
||||
}
|
||||
snackbarKeyHAConKey.current = snackbar.enqueueSnackbar(`Connected to HA!`, {
|
||||
"variant": "success",
|
||||
})
|
||||
useEffect(() => {
|
||||
if (conn.status === "error") {
|
||||
if (snackbarKeyHAConKey.current) {
|
||||
snackbar.closeSnackbar(snackbarKeyHAConKey.current);
|
||||
}
|
||||
snackbarKeyHAConKey.current = snackbar.enqueueSnackbar(
|
||||
`Failed to connect to homeassistant due to "${JSON.stringify(
|
||||
conn.error
|
||||
)}"`,
|
||||
{
|
||||
variant: "error",
|
||||
persist: true,
|
||||
}
|
||||
}, [conn, snackbar])
|
||||
);
|
||||
} else if (conn.status === "loading") {
|
||||
if (snackbarKeyHAConKey.current) {
|
||||
snackbar.closeSnackbar(snackbarKeyHAConKey.current);
|
||||
}
|
||||
snackbarKeyHAConKey.current = snackbar.enqueueSnackbar(
|
||||
`Connecting to websocket...`,
|
||||
{
|
||||
variant: "info",
|
||||
}
|
||||
);
|
||||
} else if (conn.status === "loaded") {
|
||||
if (snackbarKeyHAConKey.current) {
|
||||
snackbar.closeSnackbar(snackbarKeyHAConKey.current);
|
||||
}
|
||||
snackbarKeyHAConKey.current = snackbar.enqueueSnackbar(
|
||||
`Connected to HA!`,
|
||||
{
|
||||
variant: "success",
|
||||
}
|
||||
);
|
||||
}
|
||||
}, [conn, snackbar]);
|
||||
|
||||
return <main className="page" style={{
|
||||
return (
|
||||
<main
|
||||
className="page"
|
||||
style={{
|
||||
color: theme.palette.text.primary,
|
||||
background: theme.palette.background.default,
|
||||
}}>
|
||||
<VersionBox />
|
||||
{children}
|
||||
}}
|
||||
>
|
||||
<VersionBox />
|
||||
{children}
|
||||
</main>
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const Page: FC<{
|
||||
children: ReactNode
|
||||
children: ReactNode;
|
||||
}> = ({ children }) => {
|
||||
const notistackRef = createRef<any>();
|
||||
const onClickDismiss = (key: SnackbarKey) => () => {
|
||||
notistackRef.current.closeSnackbar(key);
|
||||
}
|
||||
return <ThemeProvider theme={theme}>
|
||||
<SnackbarProvider
|
||||
anchorOrigin={{
|
||||
"vertical": "bottom",
|
||||
"horizontal": "center"
|
||||
}}
|
||||
ref={notistackRef}
|
||||
action={key => <Button onClick={onClickDismiss(key)}>Dismiss</Button>}
|
||||
dense preventDuplicate
|
||||
>
|
||||
<InternalPage>
|
||||
{children}
|
||||
</InternalPage>
|
||||
</SnackbarProvider>
|
||||
const notistackRef = createRef<any>();
|
||||
const onClickDismiss = (key: SnackbarKey) => () => {
|
||||
notistackRef.current.closeSnackbar(key);
|
||||
};
|
||||
return (
|
||||
<ThemeProvider theme={theme}>
|
||||
<SnackbarProvider
|
||||
anchorOrigin={{
|
||||
vertical: "bottom",
|
||||
horizontal: "center",
|
||||
}}
|
||||
ref={notistackRef}
|
||||
action={(key) => <Button onClick={onClickDismiss(key)}>Dismiss</Button>}
|
||||
dense
|
||||
preventDuplicate
|
||||
>
|
||||
<InternalPage>{children}</InternalPage>
|
||||
</SnackbarProvider>
|
||||
</ThemeProvider>
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -16,4 +16,8 @@
|
||||
white-space: nowrap;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.service-editor--field .service-editor--field--remove.icon-button.MuiButtonBase-root.icon-button[type="button"] {
|
||||
border-style: none;
|
||||
}
|
||||
@@ -3,7 +3,6 @@ import { FC, useRef } from "react";
|
||||
import { ServiceEditorOption } from "./options";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import InputNumber from "components/Inputs/InputNumber";
|
||||
import { IconButton } from "@mui/material";
|
||||
import { RemoveCircle } from "@mui/icons-material";
|
||||
import { InputAutoComplete, Option } from "components/Inputs/InputAutoComplete";
|
||||
import { prettyName } from "utils/formatting";
|
||||
@@ -12,6 +11,7 @@ import { SelectorNumber, SelectorText } from "haService/fieldTypes";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { InputEntity } from "components/Inputs/InputEntities";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
export type ServiceEditorFieldProps = {
|
||||
option: ServiceEditorOption;
|
||||
@@ -34,13 +34,12 @@ export const ServiceEditorField: FC<ServiceEditorFieldProps> = ({
|
||||
const removeIcon = !onRemove ? (
|
||||
<></>
|
||||
) : (
|
||||
<IconButton
|
||||
<ButtonIcon
|
||||
className="service-editor--field--remove"
|
||||
onClick={onRemove}
|
||||
title={`Remove ${label}`}
|
||||
>
|
||||
<RemoveCircle />
|
||||
</IconButton>
|
||||
icon={<RemoveCircle color="secondary" />}
|
||||
/>
|
||||
);
|
||||
example = option.data.example ? `Example: ${option.data.example}` : "";
|
||||
const prop = {
|
||||
|
||||
@@ -132,7 +132,7 @@ export const useHAEntities = () => {
|
||||
label: entities.collection.state[key].attributes.friendly_name ?? key,
|
||||
domain: key.split(".")[0] ?? "n/a",
|
||||
integration: entitySource.ready
|
||||
? entitySource.collection.state[key].domain ?? "n/a"
|
||||
? (entitySource.collection.state[key] ?? {}).domain ?? "n/a"
|
||||
: "...",
|
||||
}));
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user