v1 of loaded manager
This commit is contained in:
1 parent
a9c3e9c890
commit
96617e7b0c
17 files changed
+295
-88
No files matched your search
@@ -1,22 +1,24 @@
|
||||
import { AutomationData } from 'types/automations';
|
||||
import { makeAutomationAPI } from './automations';
|
||||
import { AutomationData } from "types/automations";
|
||||
import { makeAutomationAPI } from "./automations";
|
||||
import { makeRemoteAPI } from "./base";
|
||||
import { useAPIService } from './core';
|
||||
import { useAPIService } from "./core";
|
||||
import { useMockAPI } from "./mock";
|
||||
import { useRef } from "react";
|
||||
|
||||
const locationPrefixWeb = window.location.pathname.match(/(\/.+\/)web/i);
|
||||
const baseURL = new URL(
|
||||
process.env.NODE_ENV === 'development' ?
|
||||
`http://${window.location.hostname}:8000` :
|
||||
window.location.origin + (!locationPrefixWeb ? '' : locationPrefixWeb[1])
|
||||
);
|
||||
export const wsURL = baseURL + "socket"
|
||||
export const remoteAutoAPI = makeRemoteAPI(
|
||||
baseURL + "automations"
|
||||
);
|
||||
export const useConnectedApiService = () => useAPIService(
|
||||
makeAutomationAPI(remoteAutoAPI)
|
||||
);
|
||||
export const useMockApiService = (initialAutos: AutomationData[]) => useAPIService(
|
||||
makeAutomationAPI(useMockAPI(initialAutos))
|
||||
process.env.NODE_ENV === "development"
|
||||
? `http://${window.location.hostname}:8000`
|
||||
: window.location.origin + (!locationPrefixWeb ? "" : locationPrefixWeb[1])
|
||||
);
|
||||
export const wsURL = baseURL + "socket";
|
||||
export const remoteAutoAPI = makeRemoteAPI(baseURL + "automations");
|
||||
export const useConnectedApiService = () =>
|
||||
useAPIService(makeAutomationAPI(remoteAutoAPI));
|
||||
export const useMockApiService = (
|
||||
initialAutos: AutomationData[],
|
||||
returnErrors: boolean = false
|
||||
) =>
|
||||
useAPIService(
|
||||
makeAutomationAPI(useMockAPI(initialAutos, useRef, returnErrors))
|
||||
);
|
||||
@@ -9,11 +9,18 @@ import {
|
||||
|
||||
export const useMockAPI = (
|
||||
initialAutos: AutomationData[] = [],
|
||||
makeRef = useRef
|
||||
makeRef = useRef,
|
||||
returnErrors: boolean = false
|
||||
): API => {
|
||||
const automationsRef = makeRef(initialAutos);
|
||||
return {
|
||||
async makeCall({ path, method = "POST", data = {} }) {
|
||||
if (returnErrors) {
|
||||
return {
|
||||
ok: false,
|
||||
error: "Test Error",
|
||||
};
|
||||
}
|
||||
// console.debug("[[mockCall]]", method, path, data);
|
||||
if (path === AUTOMTAION_LIST) {
|
||||
return {
|
||||
|
||||
@@ -2,12 +2,15 @@ import "./index.css";
|
||||
|
||||
import { FC, useState } from "react";
|
||||
import { MetadataBox } from "../MetadataBox";
|
||||
import { AutomationListAutoUpdatable, AutomationListItem } from "../types";
|
||||
import {
|
||||
AutomationManagerAutoUpdatable,
|
||||
AutomationManagerItem,
|
||||
} from "../types";
|
||||
import { TagDB } from "../TagDB";
|
||||
|
||||
export type ListBoxGroupProps = AutomationListItem & {
|
||||
export type ListBoxGroupProps = AutomationManagerItem & {
|
||||
onAutomationUpdate: (
|
||||
a: AutomationListAutoUpdatable,
|
||||
a: AutomationManagerAutoUpdatable,
|
||||
aid: string,
|
||||
eid: string
|
||||
) => void;
|
||||
@@ -103,7 +106,7 @@ export const ListBoxGroup: FC<ListBoxGroupProps> = ({
|
||||
);
|
||||
};
|
||||
|
||||
const countAutomations = (item: AutomationListItem): number => {
|
||||
const countAutomations = (item: AutomationManagerItem): number => {
|
||||
if (item.type === "items") {
|
||||
return item.data.length;
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
.automation-manager--editor {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
@@ -1,20 +1,24 @@
|
||||
import "./index.css";
|
||||
|
||||
import { AutomationEditor } from "components/AutomationEditor";
|
||||
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
||||
import { HassEntities } from "home-assistant-js-websocket";
|
||||
import { FC } from "react";
|
||||
import { FC, PropsWithChildren } from "react";
|
||||
import { AutomationData } from "types/automations";
|
||||
import { consolidateAutomations } from "../helpers";
|
||||
import { AutomationManagerSidebar } from "../Sidebar";
|
||||
import { useTagDB } from "../TagDB";
|
||||
import { useAutomationManagerState } from "./state";
|
||||
import Alert from "@mui/material/Alert";
|
||||
|
||||
export type AutomationManagerLoadedProps = {
|
||||
configAutomations: AutomationData[];
|
||||
hassEntities: HassEntities;
|
||||
onUpdateTags: (aid: string, tags: Record<string, string>) => void;
|
||||
};
|
||||
export const AutomationManagerLoaded: FC<AutomationManagerLoadedProps> = ({
|
||||
configAutomations,
|
||||
onUpdateTags,
|
||||
hassEntities,
|
||||
}) => {
|
||||
export const AutomationManagerLoaded: FC<
|
||||
PropsWithChildren<AutomationManagerLoadedProps>
|
||||
> = ({ configAutomations, onUpdateTags, hassEntities, children }) => {
|
||||
const state = useAutomationManagerState();
|
||||
const tagsDB = useTagDB(
|
||||
configAutomations.map(({ metadata: { id }, tags }) => ({
|
||||
@@ -29,6 +33,45 @@ export const AutomationManagerLoaded: FC<AutomationManagerLoadedProps> = ({
|
||||
configAutomations.map(({ metadata }) => metadata),
|
||||
tagsDB
|
||||
);
|
||||
const currentAutomation = configAutomations.filter(
|
||||
({ metadata: { id } }) => state.current === id
|
||||
);
|
||||
|
||||
return <></>;
|
||||
return (
|
||||
<div className="automation-manager">
|
||||
{children}
|
||||
<AutomationManagerSidebar
|
||||
automations={automations}
|
||||
tagsDB={tagsDB}
|
||||
selectedAutomationId={state.current}
|
||||
onSelectedAutomationId={state.setCurrent}
|
||||
onAutomationAdd={() => {}}
|
||||
onAutomationDelete={() => {}}
|
||||
onAutomationUpdate={() => {}}
|
||||
/>
|
||||
<div className="automation-manager--editor">
|
||||
{state.current !== null ? (
|
||||
currentAutomation.length > 0 ? (
|
||||
<AutomationEditor
|
||||
dims={{
|
||||
...DEFAULT_DIMS,
|
||||
flipped: true,
|
||||
}}
|
||||
automation={currentAutomation[0]}
|
||||
onUpdate={() => {}}
|
||||
tagDB={tagsDB}
|
||||
/>
|
||||
) : (
|
||||
<div>
|
||||
<Alert color="warning">
|
||||
Failed to find an automation on disk with id {state.current}.
|
||||
</Alert>
|
||||
</div>
|
||||
)
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -10,12 +10,12 @@ import SelectIcon from "@mui/icons-material/HighlightAltSharp";
|
||||
|
||||
import { InputTextView } from "components/Inputs/InputTextView";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { AutomationListAuto } from "../types";
|
||||
import { AutomationManagerAuto } from "../types";
|
||||
import { Tags } from "./Tags";
|
||||
import { TagDB } from "../TagDB";
|
||||
import useWindowSize from "utils/useWindowSize";
|
||||
|
||||
export type MetadataBoxProps = AutomationListAuto & {
|
||||
export type MetadataBoxProps = AutomationManagerAuto & {
|
||||
onDelete: () => void;
|
||||
onSelect: () => void;
|
||||
onStateUpdate: (s: "on" | "off") => void;
|
||||
|
||||
@@ -25,4 +25,25 @@
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.automation-manager--sidebar-box--bottom-buttons .hide-btn {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
.automation-manager--sidebar.hidden {
|
||||
width: 2.5em;
|
||||
}
|
||||
|
||||
.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 {
|
||||
width: 0;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.automation-manager--sidebar.hidden .automation-manager--sidebar-box--bottom-buttons .hide-btn {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { AutomationListSidebar } from ".";
|
||||
import { AutomationManagerSidebar } from ".";
|
||||
import { useTagDB } from "../TagDB";
|
||||
import { useState } from "react";
|
||||
import { AutomationListAuto } from "../types";
|
||||
import { AutomationManagerAuto } from "../types";
|
||||
|
||||
import { makeStory } from "devUtils";
|
||||
|
||||
@@ -9,7 +9,7 @@ const story = makeStory({
|
||||
meta: {
|
||||
title: "App/AutomationManager/Sidebar",
|
||||
},
|
||||
Component: AutomationListSidebar,
|
||||
Component: AutomationManagerSidebar,
|
||||
BaseTemplate: (args) => {
|
||||
const [automations, setAutomations] = useState(args.automations);
|
||||
const [selectedAutomationId, setSelAutoId] = useState(
|
||||
@@ -29,7 +29,7 @@ const story = makeStory({
|
||||
}
|
||||
};
|
||||
return (
|
||||
<AutomationListSidebar
|
||||
<AutomationManagerSidebar
|
||||
selectedAutomationId={selectedAutomationId}
|
||||
tagsDB={useTagDB(automations, (a, t) => onTagUpdate(t, a))}
|
||||
automations={automations}
|
||||
@@ -78,11 +78,13 @@ const story = makeStory({
|
||||
|
||||
export default story.componentMeta;
|
||||
|
||||
const make = (automations: AutomationListAuto[]) =>
|
||||
const make = (automations: AutomationManagerAuto[]) =>
|
||||
story.make({
|
||||
automations,
|
||||
});
|
||||
const makeAuto = (data: Partial<AutomationListAuto>): AutomationListAuto => {
|
||||
const makeAuto = (
|
||||
data: Partial<AutomationManagerAuto>
|
||||
): AutomationManagerAuto => {
|
||||
const id = `${Date.now()}_${Math.random().toString(26).slice(3, 6)}`;
|
||||
return {
|
||||
id,
|
||||
|
||||
@@ -2,6 +2,8 @@ import "./index.css";
|
||||
|
||||
import { FC, useState } from "react";
|
||||
|
||||
import ArrowIcon from "@mui/icons-material/ArrowBackIosNewOutlined";
|
||||
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import InputMultiSelect from "components/Inputs/InputMultiSelect";
|
||||
|
||||
@@ -9,15 +11,19 @@ import { ListBoxGroup } from "../ListBoxGroup";
|
||||
import { filterAutomations } from "../helpers";
|
||||
import { TagDB } from "../TagDB";
|
||||
import { convertGroupingToItems, makeGrouping } from "../automationGrouper";
|
||||
import { AutomationListAuto, AutomationListAutoUpdatable } from "../types";
|
||||
import {
|
||||
AutomationManagerAuto,
|
||||
AutomationManagerAutoUpdatable,
|
||||
} from "../types";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
|
||||
export type AutomationListSidebarProps = {
|
||||
export type AutomationManagerSidebarProps = {
|
||||
tagsDB: TagDB;
|
||||
automations: AutomationListAuto[];
|
||||
automations: AutomationManagerAuto[];
|
||||
selectedAutomationId: string | null;
|
||||
onAutomationUpdate: (
|
||||
a: AutomationListAutoUpdatable,
|
||||
a: AutomationManagerAutoUpdatable,
|
||||
aid: string,
|
||||
eid: string
|
||||
) => void;
|
||||
@@ -25,7 +31,7 @@ export type AutomationListSidebarProps = {
|
||||
onAutomationAdd: () => void;
|
||||
onSelectedAutomationId: (aid: string) => void;
|
||||
};
|
||||
export const AutomationListSidebar: FC<AutomationListSidebarProps> = ({
|
||||
export const AutomationManagerSidebar: FC<AutomationManagerSidebarProps> = ({
|
||||
automations,
|
||||
tagsDB,
|
||||
onAutomationAdd,
|
||||
@@ -35,6 +41,7 @@ export const AutomationListSidebar: FC<AutomationListSidebarProps> = ({
|
||||
}) => {
|
||||
const [searchText, setSearchText] = useState("");
|
||||
const [selectedTagIdx, setSelectedTagIdx] = useState<number[]>([]);
|
||||
const [isHidden, setHidden] = useState(false);
|
||||
|
||||
const tags = tagsDB.getTagNames([]);
|
||||
|
||||
@@ -56,7 +63,12 @@ export const AutomationListSidebar: FC<AutomationListSidebarProps> = ({
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="automation-manager--sidebar">
|
||||
<div
|
||||
className={[
|
||||
"automation-manager--sidebar",
|
||||
isHidden ? "hidden" : "shown",
|
||||
].join(" ")}
|
||||
>
|
||||
<div className="automation-manager--sidebar-box--nav">
|
||||
<InputText label="Search" value={searchText} onChange={setSearchText} />
|
||||
<InputMultiSelect
|
||||
@@ -80,9 +92,15 @@ export const AutomationListSidebar: FC<AutomationListSidebarProps> = ({
|
||||
))}
|
||||
</div>
|
||||
<div className="automation-manager--sidebar-box--bottom-buttons">
|
||||
<Button onClick={onAutomationAdd} color="primary">
|
||||
<Button onClick={onAutomationAdd} color="primary" className="add-btn">
|
||||
Add
|
||||
</Button>
|
||||
<ButtonIcon
|
||||
className="hide-btn"
|
||||
color="secondary"
|
||||
icon={<ArrowIcon />}
|
||||
onClick={() => setHidden(!isHidden)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
export type TagDB = ReturnType<typeof useTagDB>;
|
||||
export const useTagDB = (
|
||||
automations: Array<{
|
||||
@@ -7,6 +7,7 @@ export const useTagDB = (
|
||||
}>,
|
||||
onUpdate: (aid: string, tags: Record<string, string>) => void
|
||||
) => {
|
||||
const lastAuto = useRef(JSON.stringify(automations));
|
||||
const [{ automationTags, changed }, setState] = useState({
|
||||
automationTags: convertAutoListToMap(automations),
|
||||
changed: new Set<string>(),
|
||||
@@ -16,11 +17,16 @@ export const useTagDB = (
|
||||
const isModified = changed.size > 0;
|
||||
|
||||
useEffect(() => {
|
||||
console.log("updating...");
|
||||
setState({
|
||||
automationTags: convertAutoListToMap(automations),
|
||||
changed: new Set(),
|
||||
});
|
||||
const c = JSON.stringify(automations);
|
||||
if (lastAuto.current !== c) {
|
||||
lastAuto.current = c;
|
||||
console.log("updating...");
|
||||
|
||||
setState({
|
||||
automationTags: convertAutoListToMap(automations),
|
||||
changed: new Set(),
|
||||
});
|
||||
}
|
||||
}, [automations, setState]);
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { convertGroupingToItems, makeGrouping } from "./automationGrouper";
|
||||
import { bigMockAutoList, createMockAuto } from "utils/mocks";
|
||||
import { AutomationListAuto } from "./types";
|
||||
import { AutomationManagerAuto } from "./types";
|
||||
|
||||
const automations: AutomationListAuto[] = [
|
||||
const automations: AutomationManagerAuto[] = [
|
||||
createMockAuto({
|
||||
Room: "Living Room",
|
||||
Type: "Lights",
|
||||
@@ -22,7 +22,7 @@ const automations: AutomationListAuto[] = [
|
||||
Room: "Living Room",
|
||||
}),
|
||||
createMockAuto({}),
|
||||
].map<AutomationListAuto>((a) => ({
|
||||
].map<AutomationManagerAuto>((a) => ({
|
||||
title: a.metadata.alias ?? "",
|
||||
entityId: "automation." + a.metadata.id,
|
||||
description: a.metadata.description ?? "",
|
||||
@@ -32,7 +32,7 @@ const automations: AutomationListAuto[] = [
|
||||
isSelected: false,
|
||||
}));
|
||||
|
||||
const bigList = bigMockAutoList.map<AutomationListAuto>((a) => ({
|
||||
const bigList = bigMockAutoList.map<AutomationManagerAuto>((a) => ({
|
||||
entityId: "automation." + a.metadata.id,
|
||||
title: a.metadata.alias ?? "",
|
||||
description: a.metadata.description ?? "",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AutomationListAuto, AutomationListItem } from "./types";
|
||||
import { AutomationManagerAuto, AutomationManagerItem } from "./types";
|
||||
|
||||
const makeGrouper = () => {
|
||||
const groupIdNames: string[] = [];
|
||||
@@ -63,7 +63,7 @@ const makeGrouper = () => {
|
||||
|
||||
export type AutomationGrouping = ReturnType<typeof makeGrouping>;
|
||||
export const makeGrouping = (
|
||||
autos: AutomationListAuto[],
|
||||
autos: AutomationManagerAuto[],
|
||||
selectedTags: string[],
|
||||
selectedAutomationId: string | null
|
||||
) => {
|
||||
@@ -150,9 +150,9 @@ export const makeGrouping = (
|
||||
export const convertGroupingToItems = (
|
||||
currentGroupIdx: number,
|
||||
selectedAutomationId: string | null,
|
||||
autos: AutomationListAuto[],
|
||||
autos: AutomationManagerAuto[],
|
||||
grouping: AutomationGrouping
|
||||
): AutomationListItem => {
|
||||
): AutomationManagerItem => {
|
||||
const groupData = grouping.getData(currentGroupIdx);
|
||||
const automationIds = grouping.getAutomations(currentGroupIdx);
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { HassEntities } from "home-assistant-js-websocket";
|
||||
import { AutomationMetadata } from "types/automations";
|
||||
import { TagDB } from "./TagDB";
|
||||
import { AutomationListAuto } from "./types";
|
||||
import { AutomationManagerAuto } from "./types";
|
||||
|
||||
export const consolidateAutomations = (
|
||||
haEntities: HassEntities,
|
||||
configAutomationMetadatas: AutomationMetadata[],
|
||||
tagsDB: TagDB
|
||||
): AutomationListAuto[] => {
|
||||
): AutomationManagerAuto[] => {
|
||||
const configData: Record<string, AutomationMetadata> =
|
||||
configAutomationMetadatas.reduce(
|
||||
(all, n) => ({
|
||||
@@ -19,7 +19,7 @@ export const consolidateAutomations = (
|
||||
|
||||
const out = Object.entries(haEntities)
|
||||
.filter(([entityId, _]) => entityId.toLowerCase().startsWith("automation."))
|
||||
.map<AutomationListAuto>(([entityId, entityData]) => {
|
||||
.map<AutomationManagerAuto>(([entityId, entityData]) => {
|
||||
const autoId = entityData.attributes.id;
|
||||
let title = entityData.attributes.friendly_name ?? "";
|
||||
let description = "";
|
||||
@@ -64,9 +64,9 @@ export const consolidateAutomations = (
|
||||
};
|
||||
|
||||
export const filterAutomations = (
|
||||
autos: AutomationListAuto[],
|
||||
autos: AutomationManagerAuto[],
|
||||
searchText: string
|
||||
): AutomationListAuto[] =>
|
||||
): AutomationManagerAuto[] =>
|
||||
autos.filter((a) => {
|
||||
if (searchText.length > 0) {
|
||||
if (
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
.automation-manager {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
gap: 0.25em;
|
||||
}
|
||||
|
||||
.automation-manager.mobile, .automation-manager.error {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.automation-manager.loading .automation-manager--sidebar.loading {
|
||||
width: 25vh;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.automation-manager.loading .MuiSkeleton-root {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.automation-manager.loading .automation-manager--editor.loading {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
}
|
||||
@@ -1,12 +1,71 @@
|
||||
import { makeStory } from "devUtils";
|
||||
import { useMockApiService } from "apiService";
|
||||
import { AutomationManager } from ".";
|
||||
import {
|
||||
MockHAEntitiesProps,
|
||||
useMockHAEntities,
|
||||
} from "haService/HAEntities.mock";
|
||||
import { AutomationData } from "types/automations";
|
||||
import { createMockAuto } from "utils/mocks";
|
||||
|
||||
const { make, componentMeta } = makeStory({
|
||||
Component: AutomationManager,
|
||||
Component: (args: {
|
||||
automations?: AutomationData[];
|
||||
haProps: MockHAEntitiesProps;
|
||||
}) => (
|
||||
<AutomationManager
|
||||
api={useMockApiService(args.automations ?? [], !args.automations)}
|
||||
haEntites={useMockHAEntities(args.haProps)}
|
||||
/>
|
||||
),
|
||||
meta: {
|
||||
title: "App/AutomationManager",
|
||||
args: {
|
||||
automations: [],
|
||||
haProps: {
|
||||
loading: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default componentMeta;
|
||||
export const Basic = make({});
|
||||
export const Loading = make({});
|
||||
export const Errored = make({
|
||||
automations: undefined,
|
||||
haProps: {
|
||||
loading: false,
|
||||
entities: {},
|
||||
entitySource: {},
|
||||
},
|
||||
});
|
||||
export const Empty = make({
|
||||
automations: [],
|
||||
haProps: {
|
||||
loading: false,
|
||||
entities: {},
|
||||
entitySource: {},
|
||||
},
|
||||
});
|
||||
const auto1 = createMockAuto({
|
||||
type: "button",
|
||||
});
|
||||
export const One = make({
|
||||
automations: [auto1],
|
||||
haProps: {
|
||||
loading: false,
|
||||
entities: {
|
||||
[`automation.${auto1.metadata.id}`]: {
|
||||
entity_id: `automation.${auto1.metadata.id}`,
|
||||
attributes: {
|
||||
id: auto1.metadata.id,
|
||||
},
|
||||
context: { id: "", parent_id: null, user_id: null },
|
||||
last_changed: "",
|
||||
last_updated: "",
|
||||
state: "on",
|
||||
},
|
||||
},
|
||||
entitySource: {},
|
||||
},
|
||||
});
|
||||
@@ -1,8 +1,13 @@
|
||||
import "./index.css";
|
||||
|
||||
import { FC, useState } from "react";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
import Skeleton from "@mui/material/Skeleton";
|
||||
|
||||
import { ApiService } from "apiService/core";
|
||||
import { HAEntitiesState } from "haService/HAEntities";
|
||||
import { FC, useState } from "react";
|
||||
import { AutomationManagerLoaded } from "./Loaded";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
import { Alert } from "@mui/material";
|
||||
|
||||
export type AutomationManagerProps = {
|
||||
haEntites: HAEntitiesState;
|
||||
@@ -17,14 +22,26 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
|
||||
// handle bad states
|
||||
if (!haEntites.ready || !api.state.automations.ready) {
|
||||
return <div className="automation-manager loading">...</div>;
|
||||
return (
|
||||
<div className="automation-manager loading">
|
||||
<div className="automation-manager--sidebar loading">
|
||||
<Skeleton />
|
||||
</div>
|
||||
<div className="automation-manager--editor loading">
|
||||
<Skeleton />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!api.state.automations.ok) {
|
||||
return (
|
||||
<div className="automation-manager error">
|
||||
<h1>Failed to load</h1>
|
||||
{api.state.automations.error}
|
||||
<Alert color="error">
|
||||
Failed to load automations from <code>/config</code>
|
||||
</Alert>{" "}
|
||||
<br />
|
||||
<code>{api.state.automations.error}</code>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -33,20 +50,19 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
const configAutomations = api.state.automations.data.data;
|
||||
const hassEntities = haEntites.collection.state;
|
||||
return (
|
||||
<div className="automation-manager">
|
||||
<AutomationManagerLoaded
|
||||
configAutomations={configAutomations}
|
||||
hassEntities={hassEntities}
|
||||
onUpdateTags={async (aid, t) => {
|
||||
setIsSaving(true);
|
||||
await api.updateTags({
|
||||
automation_id: aid,
|
||||
tags: t,
|
||||
});
|
||||
setIsSaving(false);
|
||||
}}
|
||||
>
|
||||
{isSaving && <LinearProgress />}
|
||||
<AutomationManagerLoaded
|
||||
configAutomations={configAutomations}
|
||||
hassEntities={hassEntities}
|
||||
onUpdateTags={async (aid, t) => {
|
||||
setIsSaving(true);
|
||||
await api.updateTags({
|
||||
automation_id: aid,
|
||||
tags: t,
|
||||
});
|
||||
setIsSaving(false);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</AutomationManagerLoaded>
|
||||
);
|
||||
};
|
||||
@@ -1,25 +1,25 @@
|
||||
export type AutomationListAutoUpdatable = {
|
||||
export type AutomationManagerAutoUpdatable = {
|
||||
title: string;
|
||||
description: string;
|
||||
state: "on" | "off" | string;
|
||||
};
|
||||
export type AutomationListAuto = AutomationListAutoUpdatable & {
|
||||
export type AutomationManagerAuto = AutomationManagerAutoUpdatable & {
|
||||
id: string;
|
||||
entityId: string;
|
||||
tags: Record<string, string>;
|
||||
issue?: string;
|
||||
};
|
||||
|
||||
export type AutomationListItem = {
|
||||
export type AutomationManagerItem = {
|
||||
title: string;
|
||||
isSelected: boolean;
|
||||
} & (
|
||||
| {
|
||||
type: "group";
|
||||
data: Array<AutomationListItem>;
|
||||
data: Array<AutomationManagerItem>;
|
||||
}
|
||||
| {
|
||||
type: "items";
|
||||
data: Array<AutomationListAuto & { isSelected: boolean }>;
|
||||
data: Array<AutomationManagerAuto & { isSelected: boolean }>;
|
||||
}
|
||||
);
|
||||
Reference in new issue
Block a user