Compare commits
18
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0c1c01f14 | ||
|
|
f061894430 | ||
|
|
7769ba00c3 | ||
|
|
18241c2057 | ||
|
|
8b516d958c | ||
|
|
6422b8d974 | ||
|
|
ee77edea78 | ||
|
|
4d667d1432 | ||
|
|
3df79c17d6 | ||
|
|
5b920d366e | ||
|
|
201912f471 | ||
|
|
117595f63f | ||
|
|
a5aec24686 | ||
|
|
8a6415a58b | ||
|
|
d7ca62afa7 | ||
|
|
8fea6f1082 | ||
|
|
51bac6f0e9 | ||
|
|
7020c6aee9 |
No files matched your search
@@ -1,5 +1,10 @@
|
||||
# Changelog 
|
||||
|
||||
## [0.7.6] Bugfixes
|
||||
|
||||
- Less deadly error for invalid packages with better logs
|
||||
- Update notification
|
||||
|
||||
## [0.7.4] Bugfixes
|
||||
|
||||
- Backend now correctly returns unset alias + description
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
:no_entry: [DEPRECATED] Due to lack of time on my part, this project is no longer being worked on. :( :no_entry: [DEPRECATED]
|
||||
|
||||
----
|
||||
# <img src="logo.png" height="40x"/> Shortumation 
|
||||
|
||||
[](https://github.com/asosnovsky/Shortumation/actions/workflows/test.yml) [](https://github.com/asosnovsky/Shortumation/actions/workflows/build.yml)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
get_index # unused function (src/api/app.py:41)
|
||||
list_autos # unused function (src/api/routes/automations.py:14)
|
||||
insert_auto # unused function (src/api/routes/automations.py:30)
|
||||
update_auto # unused function (src/api/routes/automations.py:35)
|
||||
delete_auto # unused function (src/api/routes/automations.py:45)
|
||||
update_auto # unused function (src/api/routes/automations.py:37)
|
||||
delete_auto # unused function (src/api/routes/automations.py:49)
|
||||
read_details # unused function (src/api/routes/details.py:12)
|
||||
read_profile # unused function (src/api/routes/details.py:24)
|
||||
save_profile # unused function (src/api/routes/details.py:28)
|
||||
@@ -26,5 +26,6 @@ _.automation_tags # unused property (src/hass_config/loader.py:28)
|
||||
json_dumps # unused function (src/json_serializer.py:5)
|
||||
theme # unused variable (src/user_profile.py:10)
|
||||
lang # unused variable (src/user_profile.py:11)
|
||||
SecretValue # unused class (src/yaml_serializer/__init__.py:48)
|
||||
EnvVar # unused class (src/yaml_serializer/__init__.py:186)
|
||||
flags # unused variable (src/user_profile.py:12)
|
||||
SecretValue # unused class (src/yaml_serializer/__init__.py:55)
|
||||
EnvVar # unused class (src/yaml_serializer/__init__.py:193)
|
||||
+3
-3
@@ -5,8 +5,8 @@ setuptools.setup(
|
||||
python_requires=">=3.10",
|
||||
install_requires=[
|
||||
"PyYAML==6.0",
|
||||
"fastapi==0.78.0",
|
||||
"pydantic==1.9.1",
|
||||
"fastapi==0.109.1",
|
||||
"pydantic==1.10.13",
|
||||
"hypercorn==0.13.2",
|
||||
"python-decouple==3.6",
|
||||
"websockets==10.3",
|
||||
@@ -22,7 +22,7 @@ setuptools.setup(
|
||||
"pre-commit==2.20.0",
|
||||
"vulture==2.5",
|
||||
"types-requests==2.28.4",
|
||||
"types-PyYAML==6.0.11",
|
||||
"types-PyYAML==6.0.12.20240311",
|
||||
"requests==2.28.1",
|
||||
],
|
||||
},
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from itertools import chain
|
||||
from pathlib import Path
|
||||
from typing import Any, Iterator, Tuple, Union
|
||||
|
||||
@@ -141,6 +140,7 @@ def extract_automation_inline_package_refs(
|
||||
ignore_package_name=False,
|
||||
) -> AutomationExtractedIter:
|
||||
for package_name, package_data in packages_config.items():
|
||||
logger.info(f"Loading package={package_name}:{type(package_data)} from {package_data}")
|
||||
try:
|
||||
if isinstance(package_data, IncludedYaml):
|
||||
package_mapping = package_data.to_normalized_json()
|
||||
@@ -176,11 +176,11 @@ def extract_automation_inline_package_refs(
|
||||
prefix_config_keys=prefix_config_keys,
|
||||
ignore_package_name=ignore_package_name,
|
||||
)
|
||||
else:
|
||||
elif package_data is not None:
|
||||
raise InvalidPackage(
|
||||
f"configurations.homeassistant.packages[{package_name}] must be a dictionary!"
|
||||
f"configurations.homeassistant.packages.{package_name} must be a dictionary but got {type(package_data)}!"
|
||||
)
|
||||
except Exception as err:
|
||||
except InvalidPackage as err:
|
||||
logger.error(err)
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Literal
|
||||
from typing import Dict, Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from src.hass_config import HassConfig
|
||||
from src.yaml_serializer import dump_yaml, load_yaml
|
||||
@@ -9,6 +9,7 @@ from src.yaml_serializer import dump_yaml, load_yaml
|
||||
class UserProfile(BaseModel):
|
||||
theme: Literal["dark", "light"] = "dark"
|
||||
lang: str = "eng"
|
||||
flags: Dict[str, bool] = Field(default_factory=dict)
|
||||
|
||||
@classmethod
|
||||
def from_hass_config(cls, hass_config: HassConfig):
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
- alias: UI 1
|
||||
description: Example
|
||||
mode: single
|
||||
trigger:
|
||||
- platform: homeassistant
|
||||
event: start
|
||||
condition: []
|
||||
action:
|
||||
- service: counter.increment
|
||||
data: {}
|
||||
target:
|
||||
entity_id: counter.up_times
|
||||
- alias: UI 2
|
||||
description: ""
|
||||
trigger:
|
||||
- platform: sun
|
||||
event: sunrise
|
||||
offset: 0
|
||||
condition: []
|
||||
action: []
|
||||
mode: single
|
||||
@@ -0,0 +1,2 @@
|
||||
homeassistant:
|
||||
packages: !include_dir_named integrations
|
||||
@@ -0,0 +1 @@
|
||||
automation: !include ../automations.yaml
|
||||
@@ -0,0 +1 @@
|
||||
# media_player: !include_dir_list ../entities/media_players
|
||||
@@ -0,0 +1,21 @@
|
||||
- alias: UI 1
|
||||
description: Example
|
||||
mode: single
|
||||
trigger:
|
||||
- platform: homeassistant
|
||||
event: start
|
||||
condition: []
|
||||
action:
|
||||
- service: counter.increment
|
||||
data: {}
|
||||
target:
|
||||
entity_id: counter.up_times
|
||||
- alias: UI 2
|
||||
description: ""
|
||||
trigger:
|
||||
- platform: sun
|
||||
event: sunrise
|
||||
offset: 0
|
||||
condition: []
|
||||
action: []
|
||||
mode: single
|
||||
@@ -0,0 +1,2 @@
|
||||
homeassistant:
|
||||
packages: !include_dir_named integrations
|
||||
@@ -0,0 +1 @@
|
||||
automation: !include ../automations.yaml
|
||||
@@ -0,0 +1 @@
|
||||
media_player:
|
||||
@@ -0,0 +1,21 @@
|
||||
- alias: UI 1
|
||||
description: Example
|
||||
mode: single
|
||||
trigger:
|
||||
- platform: homeassistant
|
||||
event: start
|
||||
condition: []
|
||||
action:
|
||||
- service: counter.increment
|
||||
data: {}
|
||||
target:
|
||||
entity_id: counter.up_times
|
||||
- alias: UI 2
|
||||
description: ""
|
||||
trigger:
|
||||
- platform: sun
|
||||
event: sunrise
|
||||
offset: 0
|
||||
condition: []
|
||||
action: []
|
||||
mode: single
|
||||
@@ -0,0 +1,2 @@
|
||||
homeassistant:
|
||||
packages: !include_dir_named integrations
|
||||
@@ -0,0 +1 @@
|
||||
- platform: media
|
||||
@@ -0,0 +1 @@
|
||||
automation: !include ../automations.yaml
|
||||
@@ -0,0 +1,16 @@
|
||||
- platform: ping
|
||||
host: 192.168.0.119
|
||||
name: "Ping Pc Tv"
|
||||
scan_interval: 10
|
||||
- platform: ping
|
||||
host: 192.168.0.181
|
||||
name: "Ping Living Room Tv"
|
||||
scan_interval: 10
|
||||
- platform: ping
|
||||
host: 192.168.0.100
|
||||
name: "Ping Printer"
|
||||
scan_interval: 15
|
||||
- platform: ping
|
||||
host: 192.168.0.177
|
||||
name: "Ping Broadlink"
|
||||
scan_interval: 15
|
||||
@@ -0,0 +1 @@
|
||||
media_player: !include_dir_list ../entities/media_players
|
||||
@@ -10,7 +10,6 @@ from src.automations.tags import TagManager
|
||||
from src.automations.types import ExtenededAutomation
|
||||
from src.hass_config.loader import HassConfig
|
||||
from tests.utils import (
|
||||
HA_CONFIG14_EXAMPLE,
|
||||
HA_CONFIG2_EXAMPLE,
|
||||
HA_CONFIG3_EXAMPLE,
|
||||
HA_CONFIG4_EXAMPLE,
|
||||
@@ -23,6 +22,10 @@ from tests.utils import (
|
||||
HA_CONFIG11_EXAMPLE,
|
||||
HA_CONFIG12_EXAMPLE,
|
||||
HA_CONFIG13_EXAMPLE,
|
||||
HA_CONFIG14_EXAMPLE,
|
||||
HA_CONFIG15_EXAMPLE,
|
||||
HA_CONFIG16_EXAMPLE,
|
||||
HA_CONFIG17_EXAMPLE,
|
||||
HA_CONFIG_EXAMPLE,
|
||||
)
|
||||
|
||||
@@ -164,6 +167,9 @@ class loader_tests(TestCase):
|
||||
(HA_CONFIG12_EXAMPLE, 4),
|
||||
(HA_CONFIG13_EXAMPLE, 4),
|
||||
(HA_CONFIG14_EXAMPLE, 1),
|
||||
(HA_CONFIG15_EXAMPLE, 1),
|
||||
(HA_CONFIG16_EXAMPLE, 1),
|
||||
(HA_CONFIG17_EXAMPLE, 1),
|
||||
]:
|
||||
with self.subTest(config_name=ha_path.name, expected=expected):
|
||||
hass_config = HassConfig(ha_path)
|
||||
|
||||
@@ -24,6 +24,9 @@ HA_CONFIG11_EXAMPLE = SAMPLES_FOLDER / "config-11"
|
||||
HA_CONFIG12_EXAMPLE = SAMPLES_FOLDER / "config-12"
|
||||
HA_CONFIG13_EXAMPLE = SAMPLES_FOLDER / "config-13"
|
||||
HA_CONFIG14_EXAMPLE = SAMPLES_FOLDER / "config-14"
|
||||
HA_CONFIG15_EXAMPLE = SAMPLES_FOLDER / "config-15"
|
||||
HA_CONFIG16_EXAMPLE = SAMPLES_FOLDER / "config-16"
|
||||
HA_CONFIG17_EXAMPLE = SAMPLES_FOLDER / "config-17"
|
||||
|
||||
|
||||
def get_example_automation_loader(
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
name: Shortumation
|
||||
version: v0.7.4
|
||||
version: v0.7.6
|
||||
slug: shortumation
|
||||
image: "asosnovsky/shortumation-{arch}"
|
||||
url: "https://github.com/asosnovsky/Shortumation"
|
||||
|
||||
+6
-6
@@ -6,19 +6,19 @@
|
||||
"dependencies": {
|
||||
"@emotion/react": "11.9.3",
|
||||
"@emotion/styled": "11.9.3",
|
||||
"@mui/icons-material": "5.8.4",
|
||||
"@mui/material": "5.8.6",
|
||||
"@mui/icons-material": "5.10.6",
|
||||
"@mui/material": "5.10.6",
|
||||
"@mui/styles": "5.8.6",
|
||||
"@types/jest": "28.1.8",
|
||||
"@types/node": "17.0.36",
|
||||
"@types/react": "18.0.18",
|
||||
"@types/react-dom": "18.0.6",
|
||||
"@types/react": "18.0.25",
|
||||
"@types/react-dom": "18.0.8",
|
||||
"@types/ws": "8.5.3",
|
||||
"@uiw/react-codemirror": "4.10.4",
|
||||
"autosuggest-highlight": "3.3.4",
|
||||
"home-assistant-js-websocket": "7.1.0",
|
||||
"jss": "10.9.2",
|
||||
"material-ui-confirm": "3.0.4",
|
||||
"material-ui-confirm": "3.0.6",
|
||||
"notistack": "2.0.5",
|
||||
"react": "18.2.0",
|
||||
"react-cookie": "4.1.1",
|
||||
@@ -93,7 +93,7 @@
|
||||
"@types/js-yaml": "4.0.5",
|
||||
"jest-environment-jsdom": "28.1.3",
|
||||
"ts-node": "10.9.1",
|
||||
"webpack": "5.74.0",
|
||||
"webpack": "5.104.1",
|
||||
"webpack-dev-server": "4.9.3"
|
||||
},
|
||||
"moduleDirectories": [
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
.automation-editor--nodes-row .collection-nodes--wrap {
|
||||
--node-height: 12em !important;
|
||||
--node-width: 100% !important;
|
||||
}
|
||||
|
||||
.automation-editor--nodes-row .collection-nodes--wrap .collection-nodes {
|
||||
min-width: 90%;
|
||||
min-height: 10em;
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
||||
import { makeStory } from "devUtils";
|
||||
import { useState } from "react";
|
||||
import { NodesRow } from ".";
|
||||
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: NodesRow,
|
||||
BaseTemplate: (props) => {
|
||||
const [data, setData] = useState(props.data);
|
||||
return (
|
||||
<NodesRow
|
||||
{...props}
|
||||
data={data}
|
||||
onUpdate={(up) => {
|
||||
setData(up);
|
||||
props.onUpdate(up);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
title: "App/AutomationEditor/NodesRow",
|
||||
args: {
|
||||
data: [],
|
||||
sequenceNodeDims: DEFAULT_DIMS.node,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default componentMeta;
|
||||
export const Empty = make({});
|
||||
export const One = make({
|
||||
type: "trigger",
|
||||
data: [
|
||||
{
|
||||
platform: "calendar",
|
||||
event: "test",
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -1,42 +0,0 @@
|
||||
import "./index.css";
|
||||
|
||||
import { AutomationNode, AutomationNodeMapping } from "types/automations";
|
||||
import { useHA } from "services/ha";
|
||||
import { CollectionNodeElement } from "components/DAGGraph/nodes/CollectionNode/CollectionNodeElement";
|
||||
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
||||
import { Size } from "components/DAGGraph/elements/types";
|
||||
|
||||
export type NodesRowProps<
|
||||
K extends keyof AutomationNodeMapping,
|
||||
T extends AutomationNode<K>
|
||||
> = {
|
||||
type: K;
|
||||
data: T[];
|
||||
onUpdate: (d: T[]) => void;
|
||||
sequenceNodeDims: Size;
|
||||
};
|
||||
|
||||
export function NodesRow<
|
||||
K extends keyof AutomationNodeMapping,
|
||||
T extends AutomationNode<K>
|
||||
>({ type: collectionType, data, sequenceNodeDims }: NodesRowProps<K, T>) {
|
||||
const { namer } = useHA();
|
||||
return (
|
||||
<div className="automation-editor--nodes-row">
|
||||
<CollectionNodeElement
|
||||
width={0}
|
||||
height={0}
|
||||
nodes={data.map((node) => ({
|
||||
enabled: node.enabled ?? true,
|
||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
||||
onXClick: () => {},
|
||||
}))}
|
||||
onAddNode={() => {}}
|
||||
collectionType={collectionType}
|
||||
title="if"
|
||||
sequenceNode={sequenceNodeDims}
|
||||
flipped
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -127,4 +127,13 @@
|
||||
.automation-editor--info-box--buttons {
|
||||
display: flex;
|
||||
gap: 1em;
|
||||
}
|
||||
|
||||
.automation-editor.fullscreen .automation-editor--flow-wrapper--toolbar--title {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.automation-editor.fullscreen .automation-editor--flow-wrapper--toolbar {
|
||||
justify-content: flex-end;
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import "./index.css";
|
||||
import "./index.mobile.css";
|
||||
|
||||
import { FC, useState } from "react";
|
||||
import { useCookies } from "react-cookie";
|
||||
|
||||
import Skeleton from "@mui/material/Skeleton";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
@@ -11,7 +10,6 @@ import SpeedDialAction from "@mui/material/SpeedDialAction";
|
||||
|
||||
import SpeedDialIcon from "@mui/icons-material/SettingsRounded";
|
||||
import UndoIcon from "@mui/icons-material/UndoSharp";
|
||||
import Icon from "@mui/material/Icon";
|
||||
import EditIcon from "@mui/icons-material/ModeEditOutlineTwoTone";
|
||||
import DeleteIcon from "@mui/icons-material/DeleteForever";
|
||||
import { CheckMarkIcon } from "components/Icons";
|
||||
@@ -34,7 +32,16 @@ import { useAutomatioEditorState, EditorData } from "./state";
|
||||
import { useLang } from "services/lang";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { Alert } from "@mui/material";
|
||||
|
||||
import { useUserProfile } from "services/api";
|
||||
import {
|
||||
ControlButton,
|
||||
ReactFlowProvider,
|
||||
useReactFlow,
|
||||
} from "react-flow-renderer";
|
||||
import FitInIcon from "@mui/icons-material/FitScreenRounded";
|
||||
import FullscreenIcon from "@mui/icons-material/FullscreenRounded";
|
||||
import FullscreenExitIcon from "@mui/icons-material/FullscreenExitRounded";
|
||||
import { useEffect } from "react";
|
||||
interface Props {
|
||||
automation?: AutomationData | BareAutomationData;
|
||||
dims: DAGDims;
|
||||
@@ -46,7 +53,14 @@ interface Props {
|
||||
readonly: boolean;
|
||||
issue?: string;
|
||||
}
|
||||
export const AutomationEditor: FC<Props> = ({
|
||||
export const AutomationEditor: FC<Props> = (props) => {
|
||||
return (
|
||||
<ReactFlowProvider>
|
||||
<AutomationEditorInner {...props} />
|
||||
</ReactFlowProvider>
|
||||
);
|
||||
};
|
||||
export const AutomationEditorInner: FC<Props> = ({
|
||||
dims,
|
||||
automation: propsAutos,
|
||||
onUpdate: propsOnUpdate,
|
||||
@@ -57,6 +71,8 @@ export const AutomationEditor: FC<Props> = ({
|
||||
issue,
|
||||
}) => {
|
||||
// state
|
||||
const reactFlow = useReactFlow();
|
||||
const userProfile = useUserProfile();
|
||||
const langStore = useLang();
|
||||
const snackbr = useSnackbar();
|
||||
const {
|
||||
@@ -79,15 +95,18 @@ export const AutomationEditor: FC<Props> = ({
|
||||
}
|
||||
});
|
||||
const [infoBoxOpen, setInfoBox] = useState(false);
|
||||
const [
|
||||
{ ckFlipped },
|
||||
setCookies,
|
||||
// eslint-disable-next-line
|
||||
_,
|
||||
] = useCookies(["ckFlipped"]);
|
||||
const [fullScreenMode, setFullScreenMode] = useState(false);
|
||||
// alias
|
||||
const flipped = dims.flipped ? true : ckFlipped === "1";
|
||||
const setFlipped = (v: boolean) => setCookies("ckFlipped", v ? "1" : "0");
|
||||
const flipped = userProfile.flags.flipped ?? !dims.flipped;
|
||||
const useNodesRow = userProfile.flags.useNodesRow !== false;
|
||||
// effect
|
||||
useEffect(() => {
|
||||
if (reactFlow) {
|
||||
setTimeout(() => {
|
||||
reactFlow.fitView();
|
||||
}, 500);
|
||||
}
|
||||
}, [flipped, fullScreenMode, reactFlow]);
|
||||
// render
|
||||
if (state.status === "loading") {
|
||||
return (
|
||||
@@ -114,6 +133,7 @@ export const AutomationEditor: FC<Props> = ({
|
||||
"automation-editor",
|
||||
state.status,
|
||||
readonly ? "readonly" : "",
|
||||
fullScreenMode ? "fullscreen" : "",
|
||||
].join(" ")}
|
||||
>
|
||||
{state.status === "saving" && (
|
||||
@@ -220,15 +240,6 @@ export const AutomationEditor: FC<Props> = ({
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{!dims.flipped && (
|
||||
<Button
|
||||
className={"automation-editor--flow-wrapper--toolbar--flip-btn"}
|
||||
onClick={() => setFlipped(!flipped)}
|
||||
>
|
||||
<Icon>{flipped ? "flip_to_front" : "flip_to_back"}</Icon>
|
||||
{langStore.get("FLIPP")}
|
||||
</Button>
|
||||
)}
|
||||
{state.status === "changed" && (
|
||||
<Button onClick={undo}>
|
||||
<UndoIcon />
|
||||
@@ -255,6 +266,17 @@ export const AutomationEditor: FC<Props> = ({
|
||||
onTriggerUpdate={updateTrigger}
|
||||
onConditionUpdate={updateCondition}
|
||||
isFlipped={flipped}
|
||||
useNodesRow={useNodesRow}
|
||||
additionalControls={
|
||||
<>
|
||||
<ControlButton onClick={() => setFullScreenMode(!fullScreenMode)}>
|
||||
{fullScreenMode ? <FullscreenExitIcon /> : <FullscreenIcon />}
|
||||
</ControlButton>
|
||||
<ControlButton onClick={() => reactFlow.fitView()}>
|
||||
<FitInIcon />
|
||||
</ControlButton>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
<SpeedDial
|
||||
ariaLabel="options label"
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
position: relative;
|
||||
height: 100%;
|
||||
min-width: calc(min(max(25vw, 35em), 50vw));
|
||||
transition: min-width ease-in-out 500ms,
|
||||
min-height ease-in-out 500ms,
|
||||
height ease-in-out 500ms,
|
||||
width ease-in-out 500ms,
|
||||
opacity ease-in-out 500ms;
|
||||
}
|
||||
|
||||
.automation-manager--sidebar-box--nav {
|
||||
@@ -35,10 +40,14 @@
|
||||
}
|
||||
|
||||
.automation-manager--sidebar.hidden {
|
||||
width: 2.5em;
|
||||
width: 3em;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.automation-manager--sidebar.hidden .add-btn {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.automation-manager--sidebar.hidden .automation-manager--sidebar-box--nav,
|
||||
.automation-manager--sidebar.hidden .automation-manager--sidebar-box--list,
|
||||
.automation-manager--sidebar.hidden .automation-manager--sidebar-box--bottom-buttons .add-btn {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { InputList } from "components/Inputs/InputList";
|
||||
import { useLang } from "services/lang";
|
||||
import { FC, useState } from "react";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
import InputBoolean from "components/Inputs/Base/InputBoolean";
|
||||
|
||||
export type UserProfileProps = {
|
||||
api: ApiService;
|
||||
@@ -43,6 +44,26 @@ export const UserProfileEditor: FC<UserProfileProps> = ({ api }) => {
|
||||
});
|
||||
}
|
||||
};
|
||||
const updateFlag =
|
||||
<K extends keyof UserProfile["flags"], D extends UserProfile["flags"][K]>(
|
||||
key: K
|
||||
) =>
|
||||
(data: D) => {
|
||||
if (profile.ready) {
|
||||
setIsSaving(true);
|
||||
api
|
||||
.setProfile({
|
||||
...profile.data,
|
||||
flags: {
|
||||
...profile.data.flags,
|
||||
[key]: data,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
setIsSaving(false);
|
||||
});
|
||||
}
|
||||
};
|
||||
return (
|
||||
<div className="user-profile">
|
||||
<InputList
|
||||
@@ -57,6 +78,16 @@ export const UserProfileEditor: FC<UserProfileProps> = ({ api }) => {
|
||||
current={profile.data.lang}
|
||||
onChange={update("lang")}
|
||||
/>
|
||||
<InputBoolean
|
||||
label={lang.get("FLIPP_GRAPH")}
|
||||
value={profile.data.flags.flipped ?? false}
|
||||
onChange={updateFlag("flipped")}
|
||||
/>
|
||||
<InputBoolean
|
||||
label={lang.get("NODES_ROW")}
|
||||
value={profile.data.flags.useNodesRow ?? true}
|
||||
onChange={updateFlag("useNodesRow")}
|
||||
/>
|
||||
{saving && <LinearProgress />}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
||||
import { makeStory } from "devUtils";
|
||||
import { NodesRow } from ".";
|
||||
import { createUpdater } from "../updater/index";
|
||||
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: NodesRow,
|
||||
BaseTemplate: (props) => {
|
||||
const updater = createUpdater({
|
||||
openModal: () => {},
|
||||
action: {
|
||||
data: [],
|
||||
onUpdate: () => {},
|
||||
},
|
||||
condition: {
|
||||
data: [],
|
||||
onUpdate: () => {},
|
||||
},
|
||||
trigger: {
|
||||
data: [],
|
||||
onUpdate: () => {},
|
||||
},
|
||||
});
|
||||
return <NodesRow {...props} stateUpdater={updater} />;
|
||||
},
|
||||
meta: {
|
||||
title: "DAGGraph/NodesRow/Single",
|
||||
args: {
|
||||
type: "trigger",
|
||||
data: [],
|
||||
sequenceNodeDims: DEFAULT_DIMS.node,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default componentMeta;
|
||||
export const Empty = make({});
|
||||
export const One = make({
|
||||
data: [
|
||||
{
|
||||
platform: "calendar",
|
||||
event: "start",
|
||||
},
|
||||
],
|
||||
});
|
||||
export const Many = make({
|
||||
data: [
|
||||
{
|
||||
platform: "calendar",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
].map((n, id) => ({
|
||||
...n,
|
||||
id: `Trigger ${id}`,
|
||||
})),
|
||||
});
|
||||
@@ -0,0 +1,95 @@
|
||||
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
||||
import { makeStory } from "devUtils";
|
||||
import { createUpdater } from "../updater";
|
||||
import { TriggerConditionNodeRow } from ".";
|
||||
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: TriggerConditionNodeRow,
|
||||
BaseTemplate: (props) => {
|
||||
const updater = createUpdater({
|
||||
openModal: () => {},
|
||||
action: {
|
||||
data: [],
|
||||
onUpdate: () => {},
|
||||
},
|
||||
condition: {
|
||||
data: [],
|
||||
onUpdate: () => {},
|
||||
},
|
||||
trigger: {
|
||||
data: [],
|
||||
onUpdate: () => {},
|
||||
},
|
||||
});
|
||||
return <TriggerConditionNodeRow {...props} stateUpdater={updater} />;
|
||||
},
|
||||
meta: {
|
||||
title: "DAGGraph/NodesRow/TriggerAndConditions",
|
||||
args: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
sequenceNodeDims: DEFAULT_DIMS.node,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default componentMeta;
|
||||
export const Empty = make({});
|
||||
export const One = make({
|
||||
trigger: [
|
||||
{
|
||||
platform: "calendar",
|
||||
event: "start",
|
||||
},
|
||||
],
|
||||
condition: [
|
||||
{
|
||||
condition: "and",
|
||||
conditions: [],
|
||||
},
|
||||
],
|
||||
});
|
||||
export const Many = make({
|
||||
trigger: [
|
||||
{
|
||||
platform: "calendar",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
/* .nodes-row--outer {
|
||||
--nodes-row-height: 10em;
|
||||
min-width: 100%;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
|
||||
min-height: var(--nodes-row-height);
|
||||
height: var(--nodes-row-height);
|
||||
max-height: var(--nodes-row-height);
|
||||
|
||||
overflow: auto;
|
||||
|
||||
}
|
||||
|
||||
.nodes-row--inner {
|
||||
max-width: calc(100% - 4em);
|
||||
width: calc(100% - 4em);
|
||||
min-height: calc(var(--nodes-row-height) - 2em);
|
||||
max-height: calc(var(--nodes-row-height) - 2em);
|
||||
gap: 2em;
|
||||
|
||||
|
||||
padding-left: 1em;
|
||||
padding-right: 1em;
|
||||
|
||||
border-style: solid;
|
||||
border-top-width: 0.125em;
|
||||
border-left-width: 1px;
|
||||
border-right-width: 1px;
|
||||
border-radius: 10px;
|
||||
|
||||
border-bottom-color: var(--mui-grey-500);
|
||||
border-left-color: var(--mui-grey-700);
|
||||
border-right-color: var(--mui-grey-700);
|
||||
border-top-color: var(--sequence-node-color);
|
||||
|
||||
overflow: auto;
|
||||
} */
|
||||
|
||||
.nodes-row--inner.collection-nodes--wrap {
|
||||
--node-height: none !important;
|
||||
--node-width: 100% !important;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-width: 95%;
|
||||
max-width: 95%;
|
||||
}
|
||||
|
||||
|
||||
.nodes-row--inner.collection-nodes--wrap .collection-nodes {
|
||||
min-width: 90%;
|
||||
min-height: 8em;
|
||||
max-height: 8em;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.trigger-condition-nodes-row {
|
||||
gap: 0.25em;
|
||||
}
|
||||
|
||||
|
||||
.fullscreen .trigger-condition-nodes-row .nodes-row--inner {
|
||||
opacity: 0;
|
||||
height: 0;
|
||||
z-index: -10;
|
||||
}
|
||||
|
||||
.nodes-row--inner.collection-nodes--wrap .collection-nodes .collection-nodes--inner {
|
||||
min-width: inherit;
|
||||
width: inherit;
|
||||
max-width: inherit;
|
||||
|
||||
padding-bottom: 0 !important;
|
||||
padding-left: 0 !important;
|
||||
min-height: 5em;
|
||||
max-height: 7em;
|
||||
}
|
||||
|
||||
.mobile .trigger-condition-nodes-row {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
|
||||
.mobile .nodes-row.collection-nodes--wrap .collection-nodes {
|
||||
width: 80%;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import "./index.css";
|
||||
|
||||
import { AutomationNode, AutomationNodeMapping } from "types/automations";
|
||||
import { useHA } from "services/ha";
|
||||
import { CollectionNodeElement } from "components/DAGGraph/nodes/CollectionNode/CollectionNodeElement";
|
||||
import { Size } from "components/DAGGraph/elements/types";
|
||||
import { DAGGraphUpdater } from "components/DAGGraph/updater";
|
||||
import { makeCollectionNodeMakerChildProps } from "components/DAGGraph/elements/helpers";
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
import { AutomationTrigger } from "types/automations/triggers";
|
||||
import { FC } from "react";
|
||||
|
||||
export type NodesRowProps<
|
||||
K extends keyof AutomationNodeMapping,
|
||||
T extends AutomationNode<K>
|
||||
> = {
|
||||
type: K;
|
||||
data: T[];
|
||||
stateUpdater: DAGGraphUpdater;
|
||||
sequenceNodeDims: Size;
|
||||
};
|
||||
|
||||
export function NodesRow<
|
||||
K extends keyof AutomationNodeMapping,
|
||||
T extends AutomationNode<K>
|
||||
>({
|
||||
type: collectionType,
|
||||
data,
|
||||
sequenceNodeDims,
|
||||
stateUpdater,
|
||||
}: NodesRowProps<K, T>) {
|
||||
const { namer } = useHA();
|
||||
return (
|
||||
<div className="nodes-row--outer center row">
|
||||
<CollectionNodeElement
|
||||
className="nodes-row--inner"
|
||||
width={0}
|
||||
height={0}
|
||||
nodes={data.map((node, i) =>
|
||||
makeCollectionNodeMakerChildProps(
|
||||
collectionType,
|
||||
node,
|
||||
i,
|
||||
stateUpdater,
|
||||
namer
|
||||
)
|
||||
)}
|
||||
onAddNode={() => stateUpdater.basic[collectionType].addNode(null)}
|
||||
collectionType={collectionType}
|
||||
sequenceNode={sequenceNodeDims}
|
||||
flipped
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export type TriggerConditionNodeRowProps = {
|
||||
condition: AutomationCondition[];
|
||||
trigger: AutomationTrigger[];
|
||||
stateUpdater: DAGGraphUpdater;
|
||||
sequenceNodeDims: Size;
|
||||
};
|
||||
export const TriggerConditionNodeRow: FC<TriggerConditionNodeRowProps> = ({
|
||||
condition,
|
||||
trigger,
|
||||
stateUpdater,
|
||||
sequenceNodeDims,
|
||||
}) => {
|
||||
return (
|
||||
<div className={["trigger-condition-nodes-row column"].join(" ")}>
|
||||
<NodesRow
|
||||
data={trigger}
|
||||
type="trigger"
|
||||
stateUpdater={stateUpdater}
|
||||
sequenceNodeDims={sequenceNodeDims}
|
||||
/>
|
||||
<NodesRow
|
||||
data={condition}
|
||||
type="condition"
|
||||
stateUpdater={stateUpdater}
|
||||
sequenceNodeDims={sequenceNodeDims}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -11,7 +11,6 @@ const { make, componentMeta } = makeStory({
|
||||
});
|
||||
|
||||
export default componentMeta;
|
||||
export const Example = make({});
|
||||
|
||||
export const Loading = make({
|
||||
state: {
|
||||
|
||||
@@ -2,7 +2,7 @@ import "./index.css";
|
||||
|
||||
import { FC } from "react";
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
import ReactFlow, { Controls, ReactFlowProvider } from "react-flow-renderer";
|
||||
import ReactFlow, { Controls } from "react-flow-renderer";
|
||||
|
||||
import { NodeEditor } from "components/NodeEditor";
|
||||
import { Modal } from "components/Modal";
|
||||
@@ -10,15 +10,7 @@ import { Modal } from "components/Modal";
|
||||
import { nodeTypes } from "../nodes";
|
||||
import { DAGGraphBoardProps } from "./types";
|
||||
|
||||
export const DAGGraphBoard: FC<DAGGraphBoardProps> = (props) => {
|
||||
return (
|
||||
<ReactFlowProvider>
|
||||
<DAGGraphBoardInner {...props} />
|
||||
</ReactFlowProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export const DAGGraphBoardInner: FC<DAGGraphBoardProps> = ({
|
||||
export const DAGGraphBoard: FC<DAGGraphBoardProps> = ({
|
||||
modalState,
|
||||
state,
|
||||
closeModal,
|
||||
@@ -37,6 +29,12 @@ export const DAGGraphBoardInner: FC<DAGGraphBoardProps> = ({
|
||||
return <div className="dag-graphboard errored">{state.data.error}</div>;
|
||||
}
|
||||
|
||||
// useEffect(() => {
|
||||
// if (state.ready) {
|
||||
// reactFlow.fitView();
|
||||
// }
|
||||
// }, [state.ready, reactFlow]);
|
||||
|
||||
// modal
|
||||
let modalBody = <></>;
|
||||
if (modalState) {
|
||||
@@ -70,7 +68,7 @@ export const DAGGraphBoardInner: FC<DAGGraphBoardProps> = ({
|
||||
nodesDraggable={false}
|
||||
{...elements}
|
||||
>
|
||||
<Controls showInteractive={false} showFitView>
|
||||
<Controls showInteractive={false} showFitView={false}>
|
||||
{additionalControls}
|
||||
</Controls>
|
||||
</ReactFlow>
|
||||
|
||||
@@ -2,7 +2,7 @@ import { XYPosition } from "react-flow-renderer";
|
||||
|
||||
import AddBox from "@mui/icons-material/AddBox";
|
||||
|
||||
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
||||
import { getDescriptionFromAutomationNode, Namer } from "utils/formatting";
|
||||
import { validateNode } from "utils/automations";
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
import { AutomationTrigger } from "types/automations/triggers";
|
||||
@@ -13,6 +13,35 @@ import { convertFailuresToSequenceNodeDataProps } from "./util";
|
||||
|
||||
import { ButtonNodeMaker } from "../nodes/ButtonNode";
|
||||
import { CollectionNodeMaker } from "../nodes/CollectionNode";
|
||||
import { DAGGraphUpdater } from "../updater/index";
|
||||
import { AutomationActionData } from "types/automations";
|
||||
|
||||
export function makeCollectionNodeMakerChildProps<
|
||||
NodeType extends keyof AutomationActionData,
|
||||
Node extends AutomationActionData[NodeType][0]
|
||||
>(
|
||||
nodeType: NodeType,
|
||||
node: Node,
|
||||
index: number,
|
||||
stateUpdater: DAGGraphUpdater,
|
||||
namer: Namer
|
||||
) {
|
||||
const failures = validateNode(node, [nodeType]);
|
||||
|
||||
if (failures) {
|
||||
return {
|
||||
enabled: node.enabled ?? true,
|
||||
...stateUpdater.createNodeActions(nodeType, index, {}),
|
||||
...convertFailuresToSequenceNodeDataProps(failures),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
enabled: node.enabled ?? true,
|
||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
||||
...stateUpdater.createNodeActions(nodeType, index, {}),
|
||||
};
|
||||
}
|
||||
|
||||
export const makeTriggerNodes: ElementMaker<AutomationTrigger> = (
|
||||
nodes,
|
||||
@@ -24,23 +53,15 @@ export const makeTriggerNodes: ElementMaker<AutomationTrigger> = (
|
||||
...dims.collection,
|
||||
collectionType: "trigger",
|
||||
onAddNode: () => stateUpdater.basic.trigger.addNode(null),
|
||||
nodes: nodes.map((node, index) => {
|
||||
const failures = validateNode(node, ["trigger"]);
|
||||
|
||||
if (failures) {
|
||||
return {
|
||||
enabled: node.enabled ?? true,
|
||||
...stateUpdater.createNodeActions("trigger", index, {}),
|
||||
...convertFailuresToSequenceNodeDataProps(failures),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
enabled: node.enabled ?? true,
|
||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
||||
...stateUpdater.createNodeActions("trigger", index, {}),
|
||||
};
|
||||
}),
|
||||
nodes: nodes.map((node, index) =>
|
||||
makeCollectionNodeMakerChildProps(
|
||||
"trigger",
|
||||
node,
|
||||
index,
|
||||
stateUpdater,
|
||||
namer
|
||||
)
|
||||
),
|
||||
})
|
||||
);
|
||||
return outputState;
|
||||
@@ -57,23 +78,15 @@ export const makeConditionNodes: ElementMaker<AutomationCondition> = (
|
||||
collectionType: "condition",
|
||||
hasInput: !!lastNodeId,
|
||||
onAddNode: () => stateUpdater.basic.condition.addNode(null),
|
||||
nodes: nodes.map((node, index) => {
|
||||
const failures = validateNode(node, ["condition"]);
|
||||
|
||||
if (failures) {
|
||||
return {
|
||||
enabled: node.enabled ?? true,
|
||||
...stateUpdater.createNodeActions("condition", index, {}),
|
||||
...convertFailuresToSequenceNodeDataProps(failures),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
enabled: node.enabled ?? true,
|
||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
||||
...stateUpdater.createNodeActions("condition", index, {}),
|
||||
};
|
||||
}),
|
||||
nodes: nodes.map((node, index) =>
|
||||
makeCollectionNodeMakerChildProps(
|
||||
"condition",
|
||||
node,
|
||||
index,
|
||||
stateUpdater,
|
||||
namer
|
||||
)
|
||||
),
|
||||
})
|
||||
);
|
||||
if (lastNodeId && outputState.lastNodeId) {
|
||||
|
||||
@@ -24,15 +24,19 @@ const { make, componentMeta } = makeStory({
|
||||
state,
|
||||
setState
|
||||
);
|
||||
const elementData = useAutomationNodes(state, {
|
||||
dims: {
|
||||
...DEFAULT_DIMS,
|
||||
flipped: props.flipped,
|
||||
const elementData = useAutomationNodes(
|
||||
state,
|
||||
{
|
||||
dims: {
|
||||
...DEFAULT_DIMS,
|
||||
flipped: props.flipped,
|
||||
},
|
||||
namer,
|
||||
openModal: setModalState,
|
||||
stateUpdater: updater,
|
||||
},
|
||||
namer,
|
||||
openModal: setModalState,
|
||||
stateUpdater: updater,
|
||||
});
|
||||
false
|
||||
);
|
||||
return (
|
||||
<DAGGraphBoard
|
||||
modalState={modalState}
|
||||
|
||||
@@ -28,52 +28,57 @@ import * as helpers from "./helpers";
|
||||
|
||||
export const useAutomationNodes = (
|
||||
automation: AutomationActionData,
|
||||
args: ElementMakerBaseProps
|
||||
args: ElementMakerBaseProps,
|
||||
hideConditionAndTriggers: boolean
|
||||
) => {
|
||||
const dims: DAGDims = {
|
||||
...args.dims,
|
||||
};
|
||||
const state = useDAGElementsState();
|
||||
const outputState = new DAGElementsOutputState(dims.position, dims);
|
||||
outputState.extend(
|
||||
helpers.makeTriggerNodes(automation.trigger, {
|
||||
...args,
|
||||
state,
|
||||
let actionStartPos = dims.position;
|
||||
if (!hideConditionAndTriggers) {
|
||||
outputState.extend(
|
||||
helpers.makeTriggerNodes(automation.trigger, {
|
||||
...args,
|
||||
state,
|
||||
dims,
|
||||
position: dims.position,
|
||||
nodeId: `${dims.flipped}-trigger`,
|
||||
nodeIndex: 0,
|
||||
})
|
||||
);
|
||||
outputState.extend(
|
||||
helpers.makeConditionNodes(automation.condition, {
|
||||
...args,
|
||||
state,
|
||||
dims,
|
||||
position: distance.moveFromTo(
|
||||
"collection",
|
||||
"collection",
|
||||
outputState.getLastNodePos(),
|
||||
dims
|
||||
),
|
||||
nodeId: `${dims.flipped}-condition`,
|
||||
nodeIndex: 1,
|
||||
lastNodeId: outputState.lastNodeId,
|
||||
})
|
||||
);
|
||||
actionStartPos = distance.moveFromTo(
|
||||
"collection",
|
||||
"node",
|
||||
outputState.getLastNodePos(),
|
||||
dims,
|
||||
position: dims.position,
|
||||
nodeId: `${dims.flipped}-trigger`,
|
||||
nodeIndex: 0,
|
||||
})
|
||||
);
|
||||
outputState.extend(
|
||||
helpers.makeConditionNodes(automation.condition, {
|
||||
...args,
|
||||
state,
|
||||
dims,
|
||||
position: distance.moveFromTo(
|
||||
"collection",
|
||||
"collection",
|
||||
outputState.getLastNodePos(),
|
||||
dims
|
||||
),
|
||||
nodeId: `${dims.flipped}-condition`,
|
||||
nodeIndex: 1,
|
||||
lastNodeId: outputState.lastNodeId,
|
||||
})
|
||||
);
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
outputState.extend(
|
||||
makeSequenceNodes(automation.action, {
|
||||
...args,
|
||||
state,
|
||||
dims,
|
||||
position: distance.moveFromTo(
|
||||
"collection",
|
||||
"node",
|
||||
outputState.getLastNodePos(),
|
||||
dims,
|
||||
true
|
||||
),
|
||||
position: actionStartPos,
|
||||
nodeId: `${dims.flipped}-action`,
|
||||
nodeIndex: 2,
|
||||
lastNodeId: outputState.lastNodeId,
|
||||
|
||||
@@ -8,6 +8,7 @@ import { DEFAULT_DIMS } from "./elements/constants";
|
||||
import { DAGGraphBoard } from "./board";
|
||||
import { AutomationTrigger } from "types/automations/triggers";
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
import { TriggerConditionNodeRow } from "./NodesRow";
|
||||
|
||||
export const DAGAutomationGraph: FC<{
|
||||
action: AutomationSequenceNode[];
|
||||
@@ -17,6 +18,7 @@ export const DAGAutomationGraph: FC<{
|
||||
onTriggerUpdate: (t: AutomationTrigger[]) => void;
|
||||
onConditionUpdate: (c: AutomationCondition[]) => void;
|
||||
isFlipped: boolean;
|
||||
useNodesRow: boolean;
|
||||
additionalControls?: ReactNode;
|
||||
}> = (props) => {
|
||||
const { namer } = useHA();
|
||||
@@ -37,6 +39,10 @@ export const DAGAutomationGraph: FC<{
|
||||
onUpdate: props.onTriggerUpdate as any,
|
||||
},
|
||||
});
|
||||
const dims = {
|
||||
...DEFAULT_DIMS,
|
||||
flipped: props.isFlipped,
|
||||
};
|
||||
const elementData = useAutomationNodes(
|
||||
{
|
||||
action: props.action,
|
||||
@@ -44,26 +50,34 @@ export const DAGAutomationGraph: FC<{
|
||||
trigger: props.trigger,
|
||||
},
|
||||
{
|
||||
dims: {
|
||||
...DEFAULT_DIMS,
|
||||
flipped: props.isFlipped,
|
||||
},
|
||||
dims,
|
||||
namer,
|
||||
openModal: setModalState,
|
||||
stateUpdater: updater,
|
||||
}
|
||||
},
|
||||
props.useNodesRow
|
||||
);
|
||||
return (
|
||||
<DAGGraphBoard
|
||||
modalState={modalState}
|
||||
closeModal={() => setModalState(undefined)}
|
||||
state={{
|
||||
ready: true,
|
||||
data: {
|
||||
elements: elementData,
|
||||
},
|
||||
}}
|
||||
additionalControls={props.additionalControls}
|
||||
/>
|
||||
<>
|
||||
{props.useNodesRow && (
|
||||
<TriggerConditionNodeRow
|
||||
trigger={props.trigger}
|
||||
condition={props.condition}
|
||||
stateUpdater={updater}
|
||||
sequenceNodeDims={dims.node}
|
||||
/>
|
||||
)}
|
||||
<DAGGraphBoard
|
||||
modalState={modalState}
|
||||
closeModal={() => setModalState(undefined)}
|
||||
state={{
|
||||
ready: true,
|
||||
data: {
|
||||
elements: elementData,
|
||||
},
|
||||
}}
|
||||
additionalControls={props.additionalControls}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -15,87 +15,89 @@ import { useConfirm } from "material-ui-confirm";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { useLang } from "services/lang";
|
||||
|
||||
export const CollectionNodeElement: FC<PropsWithChildren<CollectionNodeProps>> =
|
||||
({
|
||||
onAddNode,
|
||||
nodes,
|
||||
sequenceNode,
|
||||
height,
|
||||
width,
|
||||
flipped,
|
||||
collectionType,
|
||||
onDelete,
|
||||
title,
|
||||
children,
|
||||
}) => {
|
||||
const lang = useLang();
|
||||
const color = convertNodeTypeToSequenceNodeColor(collectionType);
|
||||
const nodeColor = useSequenceNodeColor(color);
|
||||
const confirm = useConfirm();
|
||||
const snackbr = useSnackbar();
|
||||
const trueTile = title ?? collectionType;
|
||||
export const CollectionNodeElement: FC<
|
||||
PropsWithChildren<CollectionNodeProps & { className?: string }>
|
||||
> = ({
|
||||
onAddNode,
|
||||
nodes,
|
||||
sequenceNode,
|
||||
height,
|
||||
width,
|
||||
flipped,
|
||||
collectionType,
|
||||
onDelete,
|
||||
title,
|
||||
children,
|
||||
className,
|
||||
}) => {
|
||||
const lang = useLang();
|
||||
const color = convertNodeTypeToSequenceNodeColor(collectionType);
|
||||
const nodeColor = useSequenceNodeColor(color);
|
||||
const confirm = useConfirm();
|
||||
const snackbr = useSnackbar();
|
||||
const trueTile = title ?? collectionType;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="collection-nodes--wrap"
|
||||
style={
|
||||
{
|
||||
"--node-color": nodeColor,
|
||||
"--node-height": `${height}px`,
|
||||
"--node-width": `${width}px`,
|
||||
} as any
|
||||
}
|
||||
>
|
||||
<div className="collection-nodes">
|
||||
{!!onDelete && (
|
||||
<ButtonIcon
|
||||
className="delete-icon"
|
||||
icon={<DeleteForeverIcon />}
|
||||
onClick={() => {
|
||||
confirm({
|
||||
description: `Are you sure you want to delete ${trueTile}?`,
|
||||
return (
|
||||
<div
|
||||
className={["collection-nodes--wrap", className ?? ""].join(" ")}
|
||||
style={
|
||||
{
|
||||
"--node-color": nodeColor,
|
||||
"--node-height": `${height}px`,
|
||||
"--node-width": `${width}px`,
|
||||
} as any
|
||||
}
|
||||
>
|
||||
<div className="collection-nodes">
|
||||
{!!onDelete && (
|
||||
<ButtonIcon
|
||||
className="delete-icon"
|
||||
icon={<DeleteForeverIcon />}
|
||||
onClick={() => {
|
||||
confirm({
|
||||
description: `Are you sure you want to delete ${trueTile}?`,
|
||||
})
|
||||
.then(() => {
|
||||
onDelete();
|
||||
snackbr.enqueueSnackbar(lang.get("DELETED"), {
|
||||
variant: "info",
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
onDelete();
|
||||
snackbr.enqueueSnackbar(lang.get("DELETED"), {
|
||||
.catch(() =>
|
||||
snackbr.enqueueSnackbar(
|
||||
lang.get("NOT_DELETED_THING", {
|
||||
item: trueTile,
|
||||
}),
|
||||
{
|
||||
variant: "info",
|
||||
});
|
||||
})
|
||||
.catch(() =>
|
||||
snackbr.enqueueSnackbar(
|
||||
lang.get("NOT_DELETED_THING", {
|
||||
item: trueTile,
|
||||
}),
|
||||
{
|
||||
variant: "info",
|
||||
}
|
||||
)
|
||||
);
|
||||
}}
|
||||
borderless
|
||||
color="secondary"
|
||||
}
|
||||
)
|
||||
);
|
||||
}}
|
||||
borderless
|
||||
color="secondary"
|
||||
/>
|
||||
)}
|
||||
<span className="collection-nodes--title">
|
||||
{prettyName(collectionType)}s
|
||||
</span>
|
||||
<div className="collection-nodes--inner">
|
||||
{nodes.map((n, i) => (
|
||||
<SequenceNodeElement
|
||||
key={i}
|
||||
color={color}
|
||||
flipped={flipped}
|
||||
{...n}
|
||||
{...sequenceNode}
|
||||
/>
|
||||
)}
|
||||
<span className="collection-nodes--title">
|
||||
{prettyName(collectionType)}s
|
||||
</span>
|
||||
<div className="collection-nodes--inner">
|
||||
{nodes.map((n, i) => (
|
||||
<SequenceNodeElement
|
||||
key={i}
|
||||
color={color}
|
||||
flipped={flipped}
|
||||
{...n}
|
||||
{...sequenceNode}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<ButtonIcon className="add" icon={<Add />} onClick={onAddNode} />
|
||||
{children}
|
||||
<span className="collection-nodes--total">
|
||||
{nodes.length} node{nodes.length !== 1 ? "s" : ""}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
<ButtonIcon className="add" icon={<Add />} onClick={onAddNode} />
|
||||
{children}
|
||||
<span className="collection-nodes--total">
|
||||
{nodes.length} node{nodes.length !== 1 ? "s" : ""}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -11,8 +11,6 @@
|
||||
width: var(--sequence-node-width);
|
||||
min-height: var(--sequence-node-height);
|
||||
min-width: var(--sequence-node-width);
|
||||
|
||||
/* outline: 1px dotted white; */
|
||||
}
|
||||
|
||||
.sequence-node.disabled .sequence-node--inner {
|
||||
|
||||
@@ -86,7 +86,6 @@ export const createDummyUpdater = (): DAGUpdaterInput<any> => ({
|
||||
data: [],
|
||||
onUpdate: console.warn,
|
||||
});
|
||||
// export const createScriptConditionFieldUpdater = (f: ScriptConditionField, )
|
||||
|
||||
export type DAGGraphUpdater = ReturnType<typeof createUpdater>;
|
||||
export type DAGGraphChooseUpdater = ReturnType<
|
||||
|
||||
@@ -188,16 +188,14 @@ export function InputAutoComplete<T extends Option>(
|
||||
const id = getID(option);
|
||||
|
||||
return (
|
||||
<>
|
||||
<SearchItem
|
||||
key={label + id}
|
||||
listProps={listProps}
|
||||
id={id}
|
||||
label={label}
|
||||
searchTerm={inputValue}
|
||||
onlyShowLabel={props.onlyShowLabel}
|
||||
/>
|
||||
</>
|
||||
<SearchItem
|
||||
key={label + id}
|
||||
listProps={listProps}
|
||||
id={id}
|
||||
label={label}
|
||||
searchTerm={inputValue}
|
||||
onlyShowLabel={props.onlyShowLabel}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
@@ -225,12 +223,13 @@ export function InputAutoComplete<T extends Option>(
|
||||
)}
|
||||
renderTags={(tagValue, getTagProps) => {
|
||||
const inner = (
|
||||
<div className="input-autocomplete--tags">
|
||||
<div className="input-autocomplete--tags" key={"inner"}>
|
||||
{tagValue.map((option, index) => {
|
||||
const label = getLabel(option);
|
||||
const id = getID(option);
|
||||
const tagProps = getTagProps({ index });
|
||||
tagProps.className += " input-autocomplete--chip";
|
||||
tagProps.key = tagProps.key ?? index;
|
||||
return (
|
||||
<Chip
|
||||
size="medium"
|
||||
@@ -258,7 +257,11 @@ export function InputAutoComplete<T extends Option>(
|
||||
}
|
||||
if (props.multiple) {
|
||||
return (
|
||||
<Badge badgeContent={tagValue.length} color="info">
|
||||
<Badge
|
||||
badgeContent={tagValue.length}
|
||||
color="info"
|
||||
key="badge-wrapper"
|
||||
>
|
||||
{inner}
|
||||
</Badge>
|
||||
);
|
||||
|
||||
@@ -15,6 +15,7 @@ const { make, componentMeta } = makeStory({
|
||||
<div
|
||||
style={{
|
||||
maxWidth: 200,
|
||||
margin: "5em",
|
||||
}}
|
||||
>
|
||||
<InputEntity
|
||||
|
||||
@@ -127,18 +127,16 @@ export const InputTime: FC<InputTimeProps> = (props) => {
|
||||
|
||||
return (
|
||||
<div className={["input-time", props.className ?? ""].join(" ")}>
|
||||
{/* <InputLabel >{props.label}</InputLabel> */}
|
||||
<div className="input-time--inner">
|
||||
{fields.map((name) => {
|
||||
{fields.map((name, index) => {
|
||||
const label = prettyName(
|
||||
lang.get(`TIME_UNITS_${name}`.toUpperCase())
|
||||
);
|
||||
return (
|
||||
<TextField
|
||||
key={name}
|
||||
key={`${name}-${index}`}
|
||||
variant="filled"
|
||||
label={label}
|
||||
defaultValue="00"
|
||||
InputProps={{
|
||||
disabled,
|
||||
type: "number",
|
||||
@@ -151,6 +149,7 @@ export const InputTime: FC<InputTimeProps> = (props) => {
|
||||
})}
|
||||
{!props.restrictEmpty && (
|
||||
<ButtonIcon
|
||||
key="disable-btn"
|
||||
onClick={() => setDisabled(!disabled)}
|
||||
icon={disabled ? <EditIcon /> : <CloseIcon />}
|
||||
/>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { useAutoMockAPI, useProfileMockAPI } from "./mock";
|
||||
import { createContext, useContext, useRef } from "react";
|
||||
import { makeProfileAPI } from "./profile";
|
||||
import { ApiState } from "./types";
|
||||
import { UserProfile } from "services/api/types";
|
||||
|
||||
const locationPrefixWeb = window.location.pathname.match(/(\/.+\/)web/i);
|
||||
const baseURL = new URL(
|
||||
@@ -33,3 +34,15 @@ const ApiStateContext = createContext<ApiState>({
|
||||
});
|
||||
export const ApiStateProvider = ApiStateContext.Provider;
|
||||
export const useApiState = () => useContext(ApiStateContext);
|
||||
export const useUserProfile = (): UserProfile => {
|
||||
const apiUserProfile = useApiState().userProfile;
|
||||
if (apiUserProfile.ready && apiUserProfile.ok) {
|
||||
return apiUserProfile.data;
|
||||
} else {
|
||||
return {
|
||||
lang: "eng",
|
||||
theme: "dark",
|
||||
flags: {},
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -112,6 +112,7 @@ export const useProfileMockAPI = (
|
||||
initialProfile: UserProfile = {
|
||||
lang: "eng",
|
||||
theme: "dark",
|
||||
flags: {},
|
||||
},
|
||||
makeRef = useRef,
|
||||
returnErrors: boolean = false
|
||||
|
||||
@@ -40,4 +40,8 @@ export interface ApiState {
|
||||
export type UserProfile = {
|
||||
theme: string;
|
||||
lang: string;
|
||||
flags: Partial<{
|
||||
useNodesRow: boolean;
|
||||
flipped: boolean;
|
||||
}>;
|
||||
};
|
||||
@@ -31,6 +31,7 @@
|
||||
"STATE": "State",
|
||||
"SEARCH": "Search",
|
||||
"FLIPP": "Flip",
|
||||
"FLIPP_GRAPH": "Flip Graph",
|
||||
"CANCEL": "Cancel",
|
||||
"CREATE": "Create",
|
||||
"OR": "Or",
|
||||
@@ -60,7 +61,7 @@
|
||||
"TIME_UNITS_HOURS": "hours",
|
||||
"TIME_UNITS_MINUTES": "minutes",
|
||||
"TIME_UNITS_SECONDS": "seconds",
|
||||
"TIME_UNITS_MILISECONDS": "milliseconds",
|
||||
"TIME_UNITS_MILLISECONDS": "milliseconds",
|
||||
|
||||
"TIMEOUT": "Timeout",
|
||||
"CONTINUTE_ON_TIMEOUT": "Continue on Timeout",
|
||||
@@ -179,5 +180,7 @@
|
||||
"HOW_MANY_TIMES": "How many times?",
|
||||
|
||||
"READONLY_MODE": "Read Only Mode",
|
||||
"READONLY_CANNOT_UPDATE": "Cannot update in readonly mode"
|
||||
"READONLY_CANNOT_UPDATE": "Cannot update in readonly mode",
|
||||
|
||||
"NODES_ROW": "Do not inlcude automation triggers & conditions in graph."
|
||||
}
|
||||
@@ -34,6 +34,7 @@
|
||||
"STATE": "Statut",
|
||||
"SEARCH": "Chercher",
|
||||
"FLIPP": "Retourner",
|
||||
"FLIPP_GRAPH": "Inverser le graphique",
|
||||
"CANCEL": "Annuler",
|
||||
"CREATE": "Créer",
|
||||
"OR": "Ou",
|
||||
@@ -70,7 +71,7 @@
|
||||
"TIME_UNITS_HOURS": "heures",
|
||||
"TIME_UNITS_MINUTES": "minutes",
|
||||
"TIME_UNITS_SECONDS": "secondes",
|
||||
"TIME_UNITS_MILISECONDS": "millisecondes",
|
||||
"TIME_UNITS_MILLISECONDS": "millisecondes",
|
||||
|
||||
"TIMEOUT": "Temps libre",
|
||||
"CONTINUTE_ON_TIMEOUT": "Continuer sur Timeout",
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
"STATE": "Stato",
|
||||
"SEARCH": "Cerca",
|
||||
"FLIPP": "Flip",
|
||||
"FLIPP_GRAPH": "Capovolgi il grafico",
|
||||
"CANCEL": "Cancella",
|
||||
"CREATE": "Crea",
|
||||
"OR": "Oppure",
|
||||
@@ -60,7 +61,7 @@
|
||||
"TIME_UNITS_HOURS": "ore",
|
||||
"TIME_UNITS_MINUTES": "minuti",
|
||||
"TIME_UNITS_SECONDS": "secondi",
|
||||
"TIME_UNITS_MILISECONDS": "millisecondi",
|
||||
"TIME_UNITS_MILLISECONDS": "millisecondi",
|
||||
|
||||
"TIMEOUT": "Tempo scaduto",
|
||||
"CONTINUTE_ON_TIMEOUT": "Continua su Timeout",
|
||||
|
||||
@@ -43,10 +43,6 @@ body,
|
||||
background: var(--mui-grey-400);
|
||||
}
|
||||
|
||||
* {
|
||||
transition: all 200ms ease-out;
|
||||
}
|
||||
|
||||
.column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
+502
-125
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user