Moved infobox to modal

This commit is contained in:
ari committed 2022-07-15 22:53:51 -04:00
1 parent 1719148c58
commit 0e4e4783fa
16 files changed
+222 -182

No files matched your search

@@ -1,31 +1,16 @@
.automation-editor--info-box {
height: 100%;
padding-left: 10px;
padding-right: 10px;
display: flex;
flex-direction: column;
justify-content: flex-start;
overflow: hidden;
position: relative;
align-items: center;
gap: 0.5em;
}
.automation-editor--info-box-inner {
height: 100%;
max-width: 95vw;
max-height: 90vh;
overflow: auto;
}
.automation-editor--info-box.show {
min-width: 20em;
}
.automation-editor--info-box.hide {
min-width: 1em;
}
.automation-editor--info-box.hide>.automation-editor--info-box-inner {
display: none;
}
.automation-editor--info-box--tags {
padding: 0.25em 0.75em 1em 0.75em;
border-color: var(--mui-grey-400);
@@ -1,40 +1,35 @@
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { makeTagDB } from "components/AutomationList/TagDB";
import { Page } from "components/Page";
import { useState } from "react";
import { AutoInfoBox } from "./AutoInfoBox";
import { defaultAutomation } from 'utils/defaults';
import { defaultAutomation } from "utils/defaults";
export default {
title: 'App/AutomationList/Editor/InfoBox',
title: "App/AutomationList/Editor/InfoBox",
component: AutoInfoBox,
parameters: { actions: { argTypesRegex: '^on.*' } },
parameters: { actions: { argTypesRegex: "^on.*" } },
args: {
tagDB: makeTagDB([
defaultAutomation("test")
])
}
tagDB: makeTagDB([defaultAutomation("test")]),
},
} as ComponentMeta<typeof AutoInfoBox>;
export const NoTags: ComponentStory<typeof AutoInfoBox> = args => {
const [[metadata, tags], setState] = useState([args.metadata, args.tags])
export const NoTags: ComponentStory<typeof AutoInfoBox> = (args) => {
const [[metadata, tags], setState] = useState([args.metadata, args.tags]);
return (
<Page>
<AutoInfoBox
{...args}
className=""
metadata={metadata}
tags={tags}
onUpdate={(m, t) => {
args.onUpdate(m, t)
setState([m, t])
args.onUpdate(m, t);
setState([m, t]);
}}
/>
</Page>
)
}
);
};
NoTags.args = {
...NoTags.args,
tags: [],
@@ -43,13 +38,13 @@ NoTags.args = {
alias: "Random",
description: "Example Metadata",
trigger_variables: {
'wowo': '!'
wowo: "!",
},
mode: 'single',
mode: "single",
},
}
};
export const SomeTags: ComponentStory<typeof AutoInfoBox> = NoTags.bind({})
export const SomeTags: ComponentStory<typeof AutoInfoBox> = NoTags.bind({});
SomeTags.args = {
...SomeTags.args,
tags: [
@@ -61,8 +56,8 @@ SomeTags.args = {
alias: "Bathroom Vent",
description: "Turn the vent when the humidity is high",
trigger_variables: {
'wowo': '!'
wowo: "!",
},
mode: 'single',
mode: "single",
},
}
};
@@ -9,7 +9,6 @@ import { TagDB } from "components/AutomationList/TagDB";
import { ButtonIcon } from "components/Icons/ButtonIcons";
interface Props {
className: string;
metadata: AutomationMetadata;
tags: Array<[string, string]>;
onUpdate: (m: AutomationMetadata, tags: Array<[string, string]>) => void;
@@ -20,7 +19,6 @@ export const AutoInfoBox: FC<Props> = ({
metadata,
tags,
onUpdate,
className,
children,
tagDB,
}) => {
@@ -97,7 +95,7 @@ export const AutoInfoBox: FC<Props> = ({
]);
// render
return (
<div className={`automation-editor--info-box ${className}`}>
<div className="automation-editor--info-box">
<div className="automation-editor--info-box-inner">
<InputText
label="ID"
@@ -50,6 +50,15 @@
white-space: break-word;
overflow: hidden;
text-overflow: ellipsis;
padding-bottom: 0.25em;
}
.automation-editor--flow-wrapper--toolbar .automation-editor--flow-wrapper--toolbar--title--text {
min-width: 5em;
}
.automation-editor--flow-wrapper--toolbar .automation-editor--flow-wrapper--toolbar--modes {
min-width: 6em;
}
.automation-editor--flow-wrapper--toolbar .automation-editor--flow-wrapper--toolbar--modes .MuiSelect-select {
@@ -64,7 +73,8 @@
left: -0.5em;
}
.automation-editor--flow-wrapper.changed>.automation-editor--flow-wrapper--toolbar button {
.automation-editor.changed .automation-editor--flow-wrapper--toolbar--save-btn,
.automation-editor--info-box--buttons.changed .automation-editor--flow-wrapper--toolbar--save-btn {
border-color: var(--mui-success-light);
color: var(--mui-success-light);
}
@@ -92,21 +102,6 @@
position: relative;
}
.automation-editor .automation-editor--info-box--icon {
position: absolute;
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 {
position: absolute;
left: 0;
@@ -127,4 +122,9 @@
top: 0;
left: 0;
width: 100%;
}
.automation-editor--info-box--buttons {
display: flex;
gap: 1em;
}
@@ -3,8 +3,9 @@ import Icon from "@mui/material/Icon";
import { CheckMarkIcon } from "components/Icons";
import { FC, useState } from "react";
import { AutomationData } from "types/automations";
import { Modal } from "components/Modal";
import { AutoInfoBox } from "./AutoInfoBox";
import { ButtonIcon } from "components/Icons/ButtonIcons";
import ModeEditOutlineTwoToneIcon from "@mui/icons-material/ModeEditOutlineTwoTone";
import { Button } from "components/Inputs/Button";
import { useAutomatioEditorState, EditorData } from "./state";
import { MiniFailure } from "types/validators/helper";
@@ -12,13 +13,12 @@ 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";
import { useCookies } from "react-cookie";
import { DAGDims } from "components/DAGGraph/elements/types";
import { DAGAutomationGraph } from "components/DAGGraph";
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
import { InputList } from "components/Inputs/InputList";
import { InputTextView } from "components/Inputs/InputTextView";
import { ControlButton } from "react-flow-renderer";
interface Props {
automation?: AutomationData;
@@ -43,7 +43,7 @@ export const AutomationEditor: FC<Props> = ({
save,
saveAndUpdate,
} = useAutomatioEditorState(propsAutos, propsOnUpdate);
const [closeInfo, setCloseInfo] = useState(false);
const [infoBoxOpen, setInfoBox] = useState(false);
const [
{ ckFlipped },
setCookies,
@@ -74,25 +74,34 @@ export const AutomationEditor: FC<Props> = ({
);
}
return (
<div className="automation-editor">
<div className={["automation-editor", state.status].join(" ")}>
{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>
<Modal open={infoBoxOpen}>
<AutoInfoBox
metadata={state.data.metadata}
tags={state.data.tags}
onUpdate={updateMetadata}
tagDB={tagDB}
>
<div
className={[
"automation-editor--info-box--buttons",
state.status,
].join(" ")}
>
<Button onClick={() => setInfoBox(false)}>Close</Button>
<Button
className={"automation-editor--flow-wrapper--toolbar--save-btn"}
onClick={save}
disabled={state.status !== "changed"}
>
Save <CheckMarkIcon color="#bf4" />
</Button>
</div>
</AutoInfoBox>
</Modal>
<div
className={["automation-editor--flow-wrapper", state.status].join(" ")}
@@ -156,6 +165,7 @@ export const AutomationEditor: FC<Props> = ({
]}
/>
<InputTextView
className="description"
value={state.data.metadata.description ?? ""}
placeholder="Description"
onChange={(description) =>
@@ -194,6 +204,11 @@ export const AutomationEditor: FC<Props> = ({
onTriggerUpdate={updateTrigger}
onConditionUpdate={updateCondition}
isFlipped={flipped}
additionalControls={
<ControlButton onClick={() => setInfoBox(!infoBoxOpen)}>
<ModeEditOutlineTwoToneIcon />
</ControlButton>
}
/>
</div>
</div>
@@ -177,9 +177,10 @@ export const AutomationListBoxItem: FC<{
onSave,
}) => {
// state
const [{ tags, isModified }, setState] = useState({
const [{ tags, isModified, alias }, setState] = useState({
isModified: false,
tags: Object.entries(auto.tags),
alias: auto.metadata.alias ?? "",
});
// effects
@@ -187,14 +188,22 @@ export const AutomationListBoxItem: FC<{
setState({
isModified: false,
tags: Object.entries(auto.tags),
alias: auto.metadata.alias ?? "",
});
}, [auto]);
// alias
const setAlias = (a: string) =>
setState({
isModified: true,
tags,
alias: a,
});
const setTags = (t: [string, string][]) =>
setState({
isModified: true,
tags: t,
alias,
});
// sub elements
let title = "BadAuto<<Missing Metadata>>";
@@ -215,10 +224,14 @@ export const AutomationListBoxItem: FC<{
onClick={() => onSelectAutomation(autoIndex)}
>
<MetadataBox
metadata={auto.metadata}
metadata={{
...auto.metadata,
alias,
}}
tags={tags}
tagsDB={tagsDB}
onUpdate={setTags}
onTagUpdate={setTags}
onAliasUpdate={setAlias}
/>
<div className="automation-list-box--body--item--buttons">
{isModified && (
@@ -229,6 +242,10 @@ export const AutomationListBoxItem: FC<{
onSave({
...auto,
tags: Object.fromEntries(tags),
metadata: {
...auto.metadata,
alias,
},
})
}
/>
@@ -7,6 +7,13 @@
.automation-list-box--body--item--title>b {
font-size: 1em;
display: flex;
align-items: center;
gap: 0.25em;
}
.automation-list-box--body--item--title .input-text-view span {
max-height: 1.5em;
}
.automation-list-box--body--item--title>span, .automation-list-box--body--item--title>b>span {
@@ -80,4 +87,15 @@
.automation-list-box--body--item--tags--item>.text .icon:hover svg {
fill: var(--mui-common-black);
}
.automation-list-box--body--item--tags--item .delete {
font-size: 1em;
color: var(--mui-error-light);
}
.automation-list-box--body--item--tags--item .delete:hover {
color: var(--mui-error-dark);
outline: 1px solid var(--mui-error-dark);
border-radius: 20px;
}
@@ -4,13 +4,16 @@ import { FC, useState } from "react";
import { AutomationMetadata } from "types/automations";
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
import { TagDB } from "./TagDB";
import DeleteIcon from "@mui/icons-material/ClearTwoTone";
import { InputTextView } from "components/Inputs/InputTextView";
export const MetadataBox: FC<{
metadata: AutomationMetadata;
onUpdate: (t: [string, string][]) => void;
onAliasUpdate: (t: string) => void;
onTagUpdate: (t: [string, string][]) => void;
tags: [string, string][];
tagsDB: TagDB;
}> = ({ tags, onUpdate, tagsDB, metadata }) => {
}> = ({ tags, onTagUpdate, onAliasUpdate, tagsDB, metadata }) => {
// state
const [newTag, setNewTag] = useState<
| {
@@ -30,9 +33,12 @@ export const MetadataBox: FC<{
if (metadata) {
title = (
<>
<b>
{String(metadata.alias ?? "").slice(0, 15)}{" "}
<span>({String(metadata.id).slice(0, 5)})</span>
<b className="text">
<InputTextView
value={metadata.alias ?? ""}
onChange={onAliasUpdate}
/>
<span>({String(metadata.id).slice(0, 10)})</span>
</b>
<span>{String(metadata.description ?? "").slice(0, 25)}</span>
</>
@@ -47,8 +53,14 @@ export const MetadataBox: FC<{
options={[tagOptions, tagsDB.getTagValues(tagName)]}
key={tagIndex}
value={[tagName, tagValue]}
onDelete={() =>
onTagUpdate([
...tags.slice(0, tagIndex),
...tags.slice(tagIndex + 1),
])
}
onChange={([newName, newValue]) =>
onUpdate([
onTagUpdate([
...tags.slice(0, tagIndex),
[newName, newValue],
...tags.slice(tagIndex + 1),
@@ -56,29 +68,34 @@ export const MetadataBox: FC<{
}
/>
))}
{newTag.on && (
{newTag.on ? (
<MetadataBoxTag
options={[tagOptions, tagsDB.getTagValues(newTag.name)]}
key="new"
value={[newTag.name, newTag.value]}
initialState={[true, true]}
initialState={true}
onChange={([name, value]) => {
if (name.trim() !== "" && value.trim() !== "") {
setNewTag({
on: false,
});
onUpdate([...tags, [name, value]]);
} else {
setNewTag({
on: true,
name,
value,
});
setNewTag({
on: true,
name,
value,
});
}}
onToggle={(em) => {
if (!em) {
if (newTag.name.trim() !== "" && newTag.value.trim() !== "") {
onTagUpdate(tags.concat([[newTag.name, newTag.value]]));
setNewTag({
on: false,
});
}
}
setNewTag({
on: false,
});
}}
/>
)}
{!newTag.on && (
) : (
<span
className="automation-list-box--body--item--tags--add"
onClick={() =>
@@ -101,16 +118,29 @@ export const MetadataBoxTag: FC<{
value: [string, string];
onChange: (t: [string, string]) => void;
options: [string[], string[]];
initialState?: [boolean, boolean];
initialState?: boolean;
onToggle?: (em: boolean) => void;
onDelete?: () => void;
}> = (props) => {
const [[editMode1, editMode2], setEditMode] = useState(
props.initialState ? props.initialState : [false, false]
const [editMode, setEditMode] = useState(
props.initialState ? props.initialState : false
);
const toggle1 = () => setEditMode([!editMode1, editMode2]);
const toggle2 = () => setEditMode([editMode1, !editMode2]);
const toggle = () => {
if (editMode) {
if (props.value[0].trim() === "" || props.value[1].trim() === "") {
props.onToggle && props.onToggle(true);
return setEditMode(true);
}
}
props.onToggle && props.onToggle(!editMode);
setEditMode(!editMode);
};
return (
<span className="automation-list-box--body--item--tags--item">
{editMode1 ? (
{props.onDelete && (
<DeleteIcon onClick={props.onDelete} className="delete" />
)}
{editMode ? (
<InputAutoComplete
multiple={false}
className="text"
@@ -118,17 +148,17 @@ export const MetadataBoxTag: FC<{
options={props.options[0]}
label=""
value={props.value[0]}
onEnter={toggle1}
onEnter={toggle}
onChange={(v) => props.onChange([v ?? "", props.value[1]])}
onlyShowLabel
endAdornment={<CheckMarkIcon className="icon" onClick={toggle1} />}
endAdornment={<CheckMarkIcon className="icon" onClick={toggle} />}
/>
) : (
<b className="text" onClick={toggle1}>
<b className="text" onClick={toggle}>
{props.value[0]}:
</b>
)}
{editMode2 ? (
{editMode ? (
<InputAutoComplete
multiple={false}
className="text"
@@ -136,13 +166,13 @@ export const MetadataBoxTag: FC<{
options={props.options[1]}
label=""
value={props.value[1]}
onEnter={toggle2}
onEnter={toggle}
onChange={(v) => props.onChange([props.value[0], v ?? ""])}
onlyShowLabel
endAdornment={<CheckMarkIcon className="icon" onClick={toggle2} />}
endAdornment={<CheckMarkIcon className="icon" onClick={toggle} />}
/>
) : (
<span className="text" onClick={toggle2}>
<span className="text" onClick={toggle}>
{props.value[1]}
</span>
)}
@@ -17,28 +17,6 @@
left: 0.25em;
}
.automation-list--root.mobile .automation-editor--info-box {
min-width: 100vw;
min-height: calc(100vh - 5em);
max-width: 100vw;
max-height: calc(100vh - 5em);
padding: 0;
}
.automation-list--root.mobile .automation-editor--info-box-inner {
margin-top: 2.5em;
padding-left: 0.5em;
padding-right: 0.5em;
margin-bottom: 2em;
}
.automation-list--root.mobile .automation-editor--info-box--icon {
left: 0.5em;
bottom: 0em;
background-color: var(--mui-common-black);
transform: rotate(90deg);
}
/* list hide */
.automation-list--root.mobile .automation-list--list.hide {
@@ -50,29 +28,11 @@
.automation-list--root.mobile .automation-list--list.hide .automation-list--list-hide {
transform: rotate(270deg);
position: fixed;
top: 0;
top: 0.5em;
z-index: 5;
}
/* info box hide */
.automation-list--root.mobile .automation-editor--info-box.hide {
width: 100vw;
min-height: 0;
max-height: 0;
}
.automation-list--root.mobile .automation-editor--info-box.hide .automation-editor--info-box--icon {
transform: rotate(270deg);
position: fixed;
top: 0em;
left: 0.25em;
z-index: 10;
}
.automation-list--root.mobile .automation-editor--flow-wrapper.unchanged>.automation-editor--flow-wrapper--toolbar {
height: 0;
opacity: 0;
overflow: hidden;
.automation-list--root.mobile .automation-editor--flow-wrapper>.automation-editor--flow-wrapper--toolbar .input-text-view,
.automation-list--root.mobile .automation-editor--flow-wrapper>.automation-editor--flow-wrapper--toolbar .id {
display: none;
}
+19 -10
View File
@@ -152,16 +152,22 @@ export const ConnectedAutomationList: FC<ConnectedAutomationListParams> = ({
dims,
}) => {
const { reloadAutomations } = useHA();
const [saving, setSaving] = useState(false);
const removeAutomation = async (args: any) => {
const resp = await methods.removeAutomation(args);
setSaving(true);
await reloadAutomations();
setSaving(false);
return resp;
};
const updateAutomation = async (args: any) => {
const resp = await methods.updateAutomation(args);
setSaving(true);
await reloadAutomations();
setSaving(false);
return resp;
};
if (!automations.ready) {
return (
<div className="automation-list--root loading">
@@ -176,15 +182,18 @@ export const ConnectedAutomationList: FC<ConnectedAutomationListParams> = ({
return <span>Error {automations.error}</span>;
}
return (
<AutomationList
dims={dims}
automations={automations.data}
onLoadMore={() => {}}
onAdd={(auto) =>
updateAutomation({ auto, index: automations.data.totalItems + 1 })
}
onRemove={(index) => removeAutomation({ index })}
onUpdate={(index, auto) => updateAutomation({ index, auto })}
/>
<>
{saving && <LinearProgress />}
<AutomationList
dims={dims}
automations={automations.data}
onLoadMore={() => {}}
onAdd={(auto) =>
updateAutomation({ auto, index: automations.data.totalItems + 1 })
}
onRemove={(index) => removeAutomation({ index })}
onUpdate={(index, auto) => updateAutomation({ index, auto })}
/>
</>
);
};
@@ -1,10 +1,7 @@
.dag-graphboard {
min-height: 100%;
min-width: 100%;
}
.dag-graphboard.loading {
position: relative;
min-height: 100%;
min-width: 100%;
}
.dag-graphboard.loading span {
@@ -22,6 +22,7 @@ export const DAGGraphBoardInner: FC<DAGGraphBoardProps> = ({
modalState,
state,
closeModal,
additionalControls,
}) => {
// render unready or errored states
if (!state.ready) {
@@ -69,7 +70,9 @@ export const DAGGraphBoardInner: FC<DAGGraphBoardProps> = ({
nodesDraggable={false}
{...elements}
>
<Controls showInteractive={false} showFitView />
<Controls showInteractive={false} showFitView>
{additionalControls}
</Controls>
</ReactFlow>
</>
);
@@ -21,6 +21,7 @@ export type DAGGraphBoardProps = {
state: DAGGraphBoardState;
modalState?: ModalState;
closeModal: () => void;
additionalControls?: ReactNode;
};
export type ModalState<
+4 -1
View File
@@ -1,4 +1,4 @@
import { FC, useState } from "react";
import { FC, useState, ReactNode } from "react";
import { AutomationSequenceNode } from "types/automations";
import { useHA } from "haService";
import { ModalState } from "./board/types";
@@ -17,7 +17,9 @@ export const DAGAutomationGraph: FC<{
onTriggerUpdate: (t: AutomationTrigger[]) => void;
onConditionUpdate: (c: AutomationCondition[]) => void;
isFlipped: boolean;
additionalControls?: ReactNode;
}> = (props) => {
console.log({ props });
const { namer } = useHA();
const [modalState, setModalState] =
useState<ModalState | undefined>(undefined);
@@ -62,6 +64,7 @@ export const DAGAutomationGraph: FC<{
elements: elementData,
},
}}
additionalControls={props.additionalControls}
/>
);
};
+11 -2
View File
@@ -1,9 +1,17 @@
.input-text-view {
width: 100%;
height: 100%;
max-height: 2em;
}
.input-text-view.view span {
height: 100%;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
word-wrap: break-word;
line-break: loose;
overflow-wrap: break-word;
}
.input-text-view.edit .MuiFilledInput-input {
padding-top: 0.5em;
padding-bottom: 0.5em;
@@ -38,4 +46,5 @@
.input-text-view.view .input-text-view--edit:hover {
transform: rotate(15deg);
cursor: pointer;
}
@@ -26,7 +26,7 @@ export const InputTextView: FC<InputTextViewProps> = (props) => {
return (
<div className={className} onClick={() => setViewMode(false)}>
{!!props.value ? (
props.value
<span>{props.value}</span>
) : (
<span className="input-text-view--placeholder">
{props.placeholder}