diff --git a/webapp/src/components/AutomationEditor/AutoInfoBox.tsx b/webapp/src/components/AutomationEditor/AutoInfoBox.tsx index afd6111..db80ffe 100644 --- a/webapp/src/components/AutomationEditor/AutoInfoBox.tsx +++ b/webapp/src/components/AutomationEditor/AutoInfoBox.tsx @@ -2,11 +2,12 @@ import "./AutoInfoBox.css"; import { AutomationMetadata } from "types/automations"; import { InputList } from "components/Inputs/InputList"; import InputText from "components/Inputs/InputText"; -import { FC, ReactNode, useRef, useState } from 'react'; +import { FC, ReactNode, useRef, useState } from "react"; import { AddIcon, TrashIcon } from "components/Icons"; -import { Button } from "components/Inputs/Button"; import InputAutoText from "components/Inputs/InputAutoText"; import { TagDB } from "components/AutomationList/TagDB"; +import from "@mui/material/IconButton"; +import { ButtonIcon } from "components/Icons/ButtonIcons"; interface Props { className: string; @@ -25,122 +26,154 @@ export const AutoInfoBox: FC = ({ tagDB, }) => { // state - const [newTag, setNewTag] = useState<[string, string]>(["", ""]) - const [[errorIndex, error], _setError] = useState<[number | 'new', string]>([-1, ""]); + const [newTag, setNewTag] = useState<[string, string]>(["", ""]); + const [[errorIndex, error], _setError] = useState<[number | "new", string]>([ + -1, + "", + ]); const errorTimeoutId = useRef(-1); // aliases const foundNewTagNames = tagDB.getTagNames(tags.map(([n, _]) => n)); - const setError = (index: number | 'new', msg: string) => { - _setError([index, msg]) + const setError = (index: number | "new", msg: string) => { + _setError([index, msg]); if (errorTimeoutId.current >= 0) { window.clearTimeout(errorTimeoutId.current); } errorTimeoutId.current = window.setTimeout(() => _setError([-1, ""]), 5000); - } - const onUpdateMetadata = (k: K) => (update: AutomationMetadata[K]) => onUpdate({ - ...metadata, - [k]: update - }, tags); + }; + const onUpdateMetadata = + (k: K) => + (update: AutomationMetadata[K]) => + onUpdate( + { + ...metadata, + [k]: update, + }, + tags + ); const validTagName = (newName: string): string | undefined => { if (newName.length <= 0) { - return "Name must be at least 1 character long" + return "Name must be at least 1 character long"; } // eslint-disable-next-line for (const [name, _] of tags) { if (name.trim() === newName.trim()) { - return `The tag '${name}' already exists` + return `The tag '${name}' already exists`; } } - } + }; const updateTagName = (newName: string, tagIndex: number) => { const error = validTagName(newName); if (error) { - return setError(tagIndex, error) + return setError(tagIndex, error); } onUpdate(metadata, [ ...tags.slice(0, tagIndex), [newName, tags[tagIndex][1]], ...tags.slice(tagIndex + 1), - ]) - } - const onUpdateTags = (tagValue: string, tagIndex: number) => onUpdate(metadata, [ - ...tags.slice(0, tagIndex), - [tags[tagIndex][0], tagValue], - ...tags.slice(tagIndex + 1), - ]) + ]); + }; + const onUpdateTags = (tagValue: string, tagIndex: number) => + onUpdate(metadata, [ + ...tags.slice(0, tagIndex), + [tags[tagIndex][0], tagValue], + ...tags.slice(tagIndex + 1), + ]); const addNewTag = () => { const error = validTagName(newTag[0]); if (error) { - return setError('new', error) + return setError("new", error); } - onUpdate(metadata, tags.concat([ - newTag.map(x => x.trim()) as [string, string] - ])); - setNewTag(['', '']); - } - const onRemoveTag = (tagIndex: number) => onUpdate(metadata, [ - ...tags.slice(0, tagIndex), - ...tags.slice(tagIndex + 1), - ]) + onUpdate( + metadata, + tags.concat([newTag.map((x) => x.trim()) as [string, string]]) + ); + setNewTag(["", ""]); + }; + const onRemoveTag = (tagIndex: number) => + onUpdate(metadata, [ + ...tags.slice(0, tagIndex), + ...tags.slice(tagIndex + 1), + ]); // render - return
-
- - - - -
-

Tags

-
- {tags.map(([tagName, tagValue], tagIndex) =>
+ return ( +
+
+ + + + +
+

Tags

+
+ {tags.map(([tagName, tagValue], tagIndex) => ( +
+ updateTagName(v, tagIndex)} + options={foundNewTagNames} + error={errorIndex === tagIndex ? error : undefined} + /> + onUpdateTags(v, tagIndex)} + options={tagDB.getTagValues(tagName)} + error={errorIndex === tagIndex ? error : undefined} + /> + onRemoveTag(tagIndex)} + icon={} + /> +
+ ))} +
+
+
updateTagName(v, tagIndex)} + onChange={(v) => setNewTag([v, newTag[1]])} options={foundNewTagNames} - error={errorIndex === tagIndex ? error : undefined} + error={errorIndex === "new" ? error : undefined} /> onUpdateTags(v, tagIndex)} - options={tagDB.getTagValues(tagName)} - error={errorIndex === tagIndex ? error : undefined} + onChange={(v) => setNewTag([newTag[0], v])} + options={tagDB.getTagValues(newTag[0])} + error={errorIndex === "new" ? error : undefined} /> - -
)} -
-
-
- setNewTag([v, newTag[1]])} - options={foundNewTagNames} - error={errorIndex === 'new' ? error : undefined} - /> - setNewTag([newTag[0], v])} - options={tagDB.getTagValues(newTag[0])} - error={errorIndex === 'new' ? error : undefined} - /> - + } + /> +
+ {children}
- {children} -
-} + ); +}; diff --git a/webapp/src/components/AutomationEditor/index.css b/webapp/src/components/AutomationEditor/index.css index 068539d..b412e4e 100644 --- a/webapp/src/components/AutomationEditor/index.css +++ b/webapp/src/components/AutomationEditor/index.css @@ -61,16 +61,19 @@ position: relative; } -.automation-editor--info-box--icon { +.automation-editor .automation-editor--info-box--icon { position: absolute; - right: 0em; - bottom: 0.5em; + left: 0.25em; + bottom: 0em; z-index: 10; + max-width: 1.5em; + max-height: 1.5em; } .automation-editor--info-box.hide>.automation-editor--info-box--icon { transform: rotate(180deg); z-index: 2; + left: 0.1em; } .automation-editor.loading .mock-list { diff --git a/webapp/src/components/AutomationEditor/index.tsx b/webapp/src/components/AutomationEditor/index.tsx index b57fd5f..49b81de 100644 --- a/webapp/src/components/AutomationEditor/index.tsx +++ b/webapp/src/components/AutomationEditor/index.tsx @@ -1,19 +1,20 @@ import "./index.css"; -import Icon from '@mui/material/Icon'; -import { ArrowIcon, CheckMarkIcon } from "components/Icons"; +import Icon from "@mui/material/Icon"; +import { CheckMarkIcon } from "components/Icons"; import { FC, useEffect, useState } from "react"; import { AutomationData } from "types/automations"; import { AutoInfoBox } from "./AutoInfoBox"; import { ButtonIcon } from "components/Icons/ButtonIcons"; import { Button } from "components/Inputs/Button"; -import { useAutomatioEditorState, EditorData } from './state'; +import { useAutomatioEditorState, EditorData } from "./state"; import { SafeDAGAutomationFlow } from "components/DAGFlow/safe"; import { DAGAutomationFlowDims } from "components/DAGFlow/types"; -import { MiniFailure } from 'types/validators/helper'; +import { MiniFailure } from "types/validators/helper"; import InputYaml from "components/Inputs/InputYaml"; import { TagDB } from "components/AutomationList/TagDB"; import Skeleton from "@mui/material/Skeleton"; import LinearProgress from "@mui/material/LinearProgress"; +import { ArrowBack } from "@mui/icons-material"; interface Props { automation?: AutomationData; @@ -44,129 +45,166 @@ export const AutomationEditor: FC = ({ // effect useEffect(() => { if (dims.flipped !== flipped) { - setFlipped(dims.flipped) + setFlipped(dims.flipped); } // eslint-disable-next-line - }, [dims.flipped]) + }, [dims.flipped]); // render - if (state.status === 'loading') { - return
- - - -
- } - if (state.status === 'invalid') { - return - } - return
- {state.status === 'saving' && } - - setCloseInfo(!closeInfo)} - title={closeInfo ? "Show Metadata" : "Hide Metadata"} - Icon={ArrowIcon} - /> - - -
-
- {!dims.flipped && } - + if (state.status === "loading") { + return ( +
+ + +
- -
-
-} + ); + } + return ( +
+ {state.status === "saving" && ( + + )} + + setCloseInfo(!closeInfo)} + title={closeInfo ? "Show Metadata" : "Hide Metadata"} + color="success" + icon={} + /> + +
+
+ {!dims.flipped && ( + + )} + +
+ +
+
+ ); +}; export const ValidationBox: FC<{ - failures: MiniFailure[] - validate: (d: any) => MiniFailure[] | null, - data: EditorData, - onSave: (d: EditorData) => void, -}> = props => { - + failures: MiniFailure[]; + validate: (d: any) => MiniFailure[] | null; + data: EditorData; + onSave: (d: EditorData) => void; +}> = (props) => { const [{ failures, data }, setState] = useState({ failures: props.failures, data: props.data, }); - const makeSave = (k: K) => (d: EditorData[K]) => { - const newData = { - ...data, - [k]: d, - } - const newFails = props.validate(newData); - if (newFails) { - setState({ - failures: newFails, - data: newData, - }) - } else { - setState({ - failures: [], - data: newData, - }) - } - } + const makeSave = + (k: K) => + (d: EditorData[K]) => { + const newData = { + ...data, + [k]: d, + }; + const newFails = props.validate(newData); + if (newFails) { + setState({ + failures: newFails, + data: newData, + }); + } else { + setState({ + failures: [], + data: newData, + }); + } + }; - return
-
    - {failures.map((f, i) => <> -
  • - {f.path}: -
      - {f.message.map((m, j) =>
    • - {m} -
    • )} -
    -
  • - )} -
- Please correct the automation file manually and then continue! - - - - - - -
-} \ No newline at end of file + return ( +
+
    + {failures.map((f, i) => ( + <> +
  • + {f.path}: +
      + {f.message.map((m, j) => ( +
    • {m}
    • + ))} +
    +
  • + + ))} +
+ + Please correct the automation file manually and then continue! + + + + + + + +
+ ); +}; diff --git a/webapp/src/components/AutomationList/AutomationListBox.tsx b/webapp/src/components/AutomationList/AutomationListBox.tsx index 138ac36..d90325a 100644 --- a/webapp/src/components/AutomationList/AutomationListBox.tsx +++ b/webapp/src/components/AutomationList/AutomationListBox.tsx @@ -1,5 +1,5 @@ import "./AutomationListBox.css"; -import { FC, useState } from 'react'; +import { FC, useState } from "react"; import { AutomationData } from "types/automations"; import InputMultiSelect from "components/Inputs/InputMultiSelect"; import InputText from "components/Inputs/InputText"; @@ -8,126 +8,135 @@ import { makeGrouping } from "./automationGrouper"; import { AutomationListBoxGroup } from "./AutomationListBoxGroup"; import { useCookies } from "react-cookie"; - export type Props = { - automations: AutomationData[]; - selected: number; - onSelectAutomation: (i: number) => void; - onRemove: (i: number) => void; - onAdd: () => void; -} + automations: AutomationData[]; + selected: number; + onSelectAutomation: (i: number) => void; + onRemove: (i: number) => void; + onAdd: () => void; +}; const useAutomationListBoxState = () => { - const [ - cookies, - setCookies, - // eslint-disable-next-line - _ - ] = useCookies(['albSearchText', 'albSelected']); - let initialSelected = []; - try { - initialSelected = JSON.parse(cookies.albSelected) - if (!Array.isArray(initialSelected)) { - initialSelected = [initialSelected] - } - initialSelected = initialSelected.map(Number) - // eslint-disable-next-line - } catch (_) { } - const [searchText, setSearchText] = useState(cookies.albSearchText ?? ""); - const [selectedTagIdx, setSelectedTagIdx] = useState(initialSelected); - - return { - searchText, - setSearchText(v: string) { - setSearchText(v) - setCookies('albSearchText', v) - }, - setSelectedTagIdx(n: number[]) { - setSelectedTagIdx(n) - setCookies('albSelected', JSON.stringify(n)) - }, - selectedTagIdx, + const [ + cookies, + setCookies, + // eslint-disable-next-line + _, + ] = useCookies(["albSearchText", "albSelected"]); + let initialSelected = []; + try { + initialSelected = JSON.parse(cookies.albSelected); + if (!Array.isArray(initialSelected)) { + initialSelected = [initialSelected]; } -} + initialSelected = initialSelected.map(Number); + // eslint-disable-next-line + } catch (_) {} + const [searchText, setSearchText] = useState(cookies.albSearchText ?? ""); + const [selectedTagIdx, setSelectedTagIdx] = + useState(initialSelected); + + return { + searchText, + setSearchText(v: string) { + setSearchText(v); + setCookies("albSearchText", v); + }, + setSelectedTagIdx(n: number[]) { + setSelectedTagIdx(n); + setCookies("albSelected", JSON.stringify(n)); + }, + selectedTagIdx, + }; +}; export const AutomationListBox: FC = ({ - automations, - selected, - onSelectAutomation, - onAdd, - onRemove, + automations, + selected, + onSelectAutomation, + onAdd, + onRemove, }) => { + const tags = getTagList(automations); + const { searchText, setSearchText, selectedTagIdx, setSelectedTagIdx } = + useAutomationListBoxState(); + const filteredAutomations = filterAutomations( + automations, + searchText.toLowerCase() + ); + const grouping = makeGrouping( + filteredAutomations.map(([a, _]) => a), + selectedTagIdx.map((i) => tags[i]), + selected + ); - const tags = getTagList(automations); - const { - searchText, - setSearchText, - selectedTagIdx, - setSelectedTagIdx, - } = useAutomationListBoxState(); - const filteredAutomations = filterAutomations(automations, searchText.toLowerCase(), selectedTagIdx, tags); - const grouping = makeGrouping( - filteredAutomations.map(([a, _]) => a), - selectedTagIdx.map(i => tags[i]), - selected, - ) - - return
-
- - -
-
- -
-
- - Showing Automations: {filteredAutomations.length} out of {automations.length} -
+ return ( +
+
+ + +
+
+ +
+
+ + + Showing Automations: {filteredAutomations.length} out of{" "} + {automations.length} + +
-} + ); +}; - -export const getTagList = (autos: AutomationData[]): string[] => Object.keys(autos - .map(a => Object.keys(a.tags)) - .reduce((all: any, keys) => { +export const getTagList = (autos: AutomationData[]): string[] => + Object.keys( + autos + .map((a) => Object.keys(a.tags)) + .reduce((all: any, keys) => { for (const k of keys) { - all[k] = 1 + all[k] = 1; } return all; - }, {})) + }, {}) + ); -const filterAutomations = (autos: AutomationData[], searchText: string, selected: number[], tags: string[]): Array<[AutomationData, number]> => autos.map<[AutomationData, number]>((a, i) => [a, i]).filter(([a, i]) => { - if (!a.metadata) { - return true - } - if (searchText.length > 0) { +const filterAutomations = ( + autos: AutomationData[], + searchText: string +): Array<[AutomationData, number]> => + autos + .map<[AutomationData, number]>((a, i) => [a, i]) + .filter(([a, i]) => { + if (!a.metadata) { + return true; + } + if (searchText.length > 0) { if ( - !( - (a.metadata.description ?? "").toLocaleLowerCase().includes(searchText) || - (a.metadata.alias ?? "").toLocaleLowerCase().includes(searchText) - ) + !( + (a.metadata.description ?? "") + .toLocaleLowerCase() + .includes(searchText) || + (a.metadata.alias ?? "").toLocaleLowerCase().includes(searchText) + ) ) { - return false + return false; } - } - return true -}) + } + return true; + }); diff --git a/webapp/src/components/AutomationList/AutomationListBoxGroup.tsx b/webapp/src/components/AutomationList/AutomationListBoxGroup.tsx index f2a48b4..976e1a1 100644 --- a/webapp/src/components/AutomationList/AutomationListBoxGroup.tsx +++ b/webapp/src/components/AutomationList/AutomationListBoxGroup.tsx @@ -1,141 +1,166 @@ - import { TrashIcon } from "components/Icons"; -import { Button } from "components/Inputs/Button"; import { MetadataBox } from "./AutomationMetadataBox"; import { AutomationData } from "types/automations"; import { AutomationGrouping } from "./automationGrouper"; import { FC, useState } from "react"; +import { ButtonIcon } from "components/Icons/ButtonIcons"; export type AutomationListBoxEvents = { - onSelectAutomation: (i: number) => void, - onRemove: (i: number) => void, -} + onSelectAutomation: (i: number) => void; + onRemove: (i: number) => void; +}; export type AutomationListBoxGroups = { - grouping: AutomationGrouping, - currentNode: number, -} + grouping: AutomationGrouping; + currentNode: number; +}; export type AutomationListBoxProps = { - events: AutomationListBoxEvents, - groups: AutomationListBoxGroups, - autos: Array<[AutomationData, number]>, - selectedAutomationIdx: number, + events: AutomationListBoxEvents; + groups: AutomationListBoxGroups; + autos: Array<[AutomationData, number]>; + selectedAutomationIdx: number; }; export type AutomationListBoxGroupProps = { - events: AutomationListBoxEvents, - grouping: AutomationGrouping, - autos: Array<[AutomationData, number]>, - selectedAutomationIdx: number, -} + events: AutomationListBoxEvents; + grouping: AutomationGrouping; + autos: Array<[AutomationData, number]>; + selectedAutomationIdx: number; +}; export const AutomationListBoxGroup: FC = ({ - events, grouping, autos, selectedAutomationIdx, + events, + grouping, + autos, + selectedAutomationIdx, }) => { - if (grouping.top.length === 1) { - return <> - {convertGroupsToItems(autos, { - grouping, currentNode: grouping.top[0], - }, events, selectedAutomationIdx)} - - } else { - return <> - {grouping.top.map(groupIdx => )} - - } -} - -export const convertGroupsToItems = ( - autos: Array<[AutomationData, number]>, - { grouping, currentNode }: AutomationListBoxGroups, - events: AutomationListBoxEvents, - selectedAutomationIdx: number, -) => { - const automations = grouping.getAutomations(currentNode); - if (automations.length > 0) { - return automations.map(autoIndex => - - ) - } - const subgroups = grouping.getSubGroups(currentNode); - if (subgroups.length > 0) { - return subgroups.map(groupIdx => + {convertGroupsToItems( + autos, + { + grouping, + currentNode: grouping.top[0], + }, + events, + selectedAutomationIdx + )} + + ); + } else { + return ( + <> + {grouping.top.map((groupIdx) => ( + ) - } - return <> -} + /> + ))} + + ); + } +}; + +export const convertGroupsToItems = ( + autos: Array<[AutomationData, number]>, + { grouping, currentNode }: AutomationListBoxGroups, + events: AutomationListBoxEvents, + selectedAutomationIdx: number +) => { + const automations = grouping.getAutomations(currentNode); + if (automations.length > 0) { + return automations.map((autoIndex) => ( + + )); + } + const subgroups = grouping.getSubGroups(currentNode); + if (subgroups.length > 0) { + return subgroups.map((groupIdx) => ( + + )); + } + return <>; +}; export const AutomationListBoxGroupItem: FC<{ - events: AutomationListBoxEvents, - groups: AutomationListBoxGroups, - autos: Array<[AutomationData, number]>, - selectedAutomationIdx: number, -}> = ({ - autos, groups, events, selectedAutomationIdx, -}) => { - const groupData = groups.grouping.getData(groups.currentNode); - const automations = groups.grouping.getAutomations(groups.currentNode); - const [open, setOpen] = useState(false); - const isOther = groupData.isOther; - const openIcon = !open ? "⊕" : "⊖"; - const total = isOther ? - {automations.length} automation{automations.length !== 1 ? 's' : ''} {groupData.isOther ? "" : "(untagged)"} - : <> - return
- setOpen(!open)}>{groupData.name} {openIcon} {total} - {open && convertGroupsToItems(autos, groups, events, selectedAutomationIdx)} -
- } - + events: AutomationListBoxEvents; + groups: AutomationListBoxGroups; + autos: Array<[AutomationData, number]>; + selectedAutomationIdx: number; +}> = ({ autos, groups, events, selectedAutomationIdx }) => { + const groupData = groups.grouping.getData(groups.currentNode); + const automations = groups.grouping.getAutomations(groups.currentNode); + const [open, setOpen] = useState(false); + const isOther = groupData.isOther; + const openIcon = !open ? "⊕" : "⊖"; + const total = isOther ? ( + + {automations.length} automation{automations.length !== 1 ? "s" : ""}{" "} + {groupData.isOther ? "" : "(untagged)"} + + ) : ( + <> + ); + return ( +
+ setOpen(!open)}> + {groupData.name} {openIcon} {total} + + {open && + convertGroupsToItems(autos, groups, events, selectedAutomationIdx)} +
+ ); +}; export const AutomationListBoxItem: FC<{ - auto: [AutomationData, number], - isSelected: boolean, - events: AutomationListBoxEvents, + auto: [AutomationData, number]; + isSelected: boolean; + events: AutomationListBoxEvents; }> = ({ - events: { - onRemove, - onSelectAutomation, - }, - auto: [ - auto, autoIndex - ], - isSelected, + events: { onRemove, onSelectAutomation }, + auto: [auto, autoIndex], + isSelected, }) => { - let title = "BadAuto<>" - if (auto.metadata) { - title = `Name = ${auto.metadata.alias}\nID = ${auto.metadata.id}\nDescription = ${auto.metadata.description}` - } - return
onSelectAutomation(autoIndex)} - > - - -
- } \ No newline at end of file + let title = "BadAuto<>"; + if (auto.metadata) { + title = `Name = ${auto.metadata.alias}\nID = ${auto.metadata.id}\nDescription = ${auto.metadata.description}`; + } + return ( +
onSelectAutomation(autoIndex)} + > + + onRemove(autoIndex)} icon={} /> +
+ ); +}; diff --git a/webapp/src/components/AutomationList/index.css b/webapp/src/components/AutomationList/index.css index 248334e..57ee8a6 100644 --- a/webapp/src/components/AutomationList/index.css +++ b/webapp/src/components/AutomationList/index.css @@ -50,6 +50,7 @@ .automation-list--list.hide>.automation-list--list-hide { transform: rotate(180deg); + left: 0; } /* list children: normal */ @@ -58,8 +59,10 @@ border-width: 1px; } -.automation-list--list-hide { +.automation-list--list .automation-list--list-hide { position: absolute; - bottom: 0.5em; - right: 0.5em; + bottom: 0em; + left: 0.5em; + max-width: 1.5em; + max-height: 1.5em; } \ No newline at end of file diff --git a/webapp/src/components/AutomationList/index.mobile.css b/webapp/src/components/AutomationList/index.mobile.css index ba5b3e7..eb76370 100644 --- a/webapp/src/components/AutomationList/index.mobile.css +++ b/webapp/src/components/AutomationList/index.mobile.css @@ -14,7 +14,7 @@ .automation-list--root.mobile .automation-list--list-hide { transform: rotate(90deg); - left: 1.25em; + left: 0.25em; } .automation-list--root.mobile .automation-editor--info-box { @@ -33,7 +33,7 @@ } .automation-list--root.mobile .automation-editor--info-box--icon { - left: 1.25em; + left: 0.5em; bottom: 0em; background-color: var(--primary); transform: rotate(90deg); @@ -50,8 +50,8 @@ .automation-list--root.mobile .automation-list--list.hide .automation-list--list-hide { transform: rotate(270deg); position: fixed; - top: 0.75em; - z-index: 20; + top: 0; + z-index: 5; } /* info box hide */ @@ -64,9 +64,9 @@ .automation-list--root.mobile .automation-editor--info-box.hide .automation-editor--info-box--icon { transform: rotate(270deg); position: fixed; - top: 0.75em; - background-color: var(--green-opaque); - z-index: 30; + top: 0em; + left: 0.25em; + z-index: 10; } diff --git a/webapp/src/components/AutomationList/index.tsx b/webapp/src/components/AutomationList/index.tsx index b224fed..f166b72 100644 --- a/webapp/src/components/AutomationList/index.tsx +++ b/webapp/src/components/AutomationList/index.tsx @@ -4,7 +4,6 @@ import { AutomationEditor } from "components/AutomationEditor"; import { FC, ReactNode, useState } from "react"; import { AutomationData } from "types/automations"; import { defaultAutomation } from "utils/defaults"; -import { ArrowIcon } from "components/Icons"; import { ButtonIcon } from "components/Icons/ButtonIcons"; import { ApiService } from "apiService/core"; import { AutomationListBox } from "./AutomationListBox"; @@ -15,6 +14,7 @@ import LinearProgress from "@mui/material/LinearProgress"; import CircularProgress from "@mui/material/CircularProgress"; import { useCookies } from "react-cookie"; import { useHA } from "haService"; +import { ArrowBack } from "@mui/icons-material"; interface AutomationListParams { automations: AutomationData[]; @@ -97,7 +97,7 @@ export const AutomationList: FC = ({ setHideList(!hideList)} className="automation-list--list-hide" - Icon={ArrowIcon} + icon={} />
diff --git a/webapp/src/components/DeviceEditor/index.tsx b/webapp/src/components/DeviceEditor/index.tsx index 24c45fd..d2651ec 100644 --- a/webapp/src/components/DeviceEditor/index.tsx +++ b/webapp/src/components/DeviceEditor/index.tsx @@ -39,11 +39,13 @@ export function DeviceEditor({ return ( <> setState({ device_id: device_id ?? "" })} /> ({ )} {caps?.extra_fields && ( ; -} -const useButtonIconStyles = createAppUseStyles(theme => ({ - buttonIcon: { - borderRadius: "100%", - borderWidth: 1, - borderStyle: "groove", - padding: "0.25em", - "&:hover": { - backgroundColor: theme.secondaryAccent, - cursor: 'pointer', - } - } -})) - - -export const ButtonIcon: FC = ({ - Icon, - className, - ...props -}) => +export const ButtonIcon: FC<{ + icon: ReactNode; + onClick?: () => void; + className?: string; + title?: string; + disabled?: boolean; + color?: IconButtonTypeMap["props"]["color"]; +}> = (props) => { + return ( + + {props.icon} + + ); +}; diff --git a/webapp/src/components/Icons/index.stories.tsx b/webapp/src/components/Icons/index.stories.tsx index be3cba7..01beec4 100644 --- a/webapp/src/components/Icons/index.stories.tsx +++ b/webapp/src/components/Icons/index.stories.tsx @@ -1,41 +1,50 @@ import { ComponentStory } from "@storybook/react"; import { IconBase } from "./base"; -import { PencilIcon, CheckMarkIcon, TrashIcon, InfoIcon, ArrowIcon, AddIcon, ZoomIcon, GearIcon } from "."; +import { + PencilIcon, + CheckMarkIcon, + TrashIcon, + InfoIcon, + ArrowIcon, + AddIcon, + ZoomIcon, + GearIcon, +} from "."; import { ButtonIcon } from "./ButtonIcons"; import { Page } from "components/Page"; export default { - title: 'Icons', + title: "Icons", component: IconBase, }; - export const IconList: ComponentStory = (args) => { - - return - - - - - - - - -} + return ( + + + + + + + + + + ); +}; IconList.args = { size: 2, - color: 'red' -} - + color: "red", +}; export const ButtonIconExample: ComponentStory = (args) => { - - return - - -} + return ( + + } /> + + ); +}; ButtonIconExample.args = { size: 2, - color: 'red' -} + color: "red", +}; diff --git a/webapp/src/components/Inputs/Button.tsx b/webapp/src/components/Inputs/Button.tsx index eb3aa53..cd3201e 100644 --- a/webapp/src/components/Inputs/Button.tsx +++ b/webapp/src/components/Inputs/Button.tsx @@ -1,7 +1,21 @@ -import { ButtonHTMLAttributes, FC } from "react"; -import { useButtonStyles } from "./styles"; +import { FC, ReactNode } from "react"; +import MuiButton from "@mui/material/Button"; -export const Button: FC> = props => { - const { classes } = useButtonStyles({}); - return
); diff --git a/webapp/src/components/Inputs/InputNumber.css b/webapp/src/components/Inputs/InputNumber.css new file mode 100644 index 0000000..a4d43af --- /dev/null +++ b/webapp/src/components/Inputs/InputNumber.css @@ -0,0 +1,3 @@ +.input-number .MuiButtonBase-root.icon-button[type="button"].icon-button { + border-style: none; +} \ No newline at end of file diff --git a/webapp/src/components/Inputs/InputNumber.tsx b/webapp/src/components/Inputs/InputNumber.tsx index 300992e..cb7076f 100644 --- a/webapp/src/components/Inputs/InputNumber.tsx +++ b/webapp/src/components/Inputs/InputNumber.tsx @@ -1,9 +1,10 @@ +import "./InputNumber.css"; import Close from "@mui/icons-material/Close"; import TextField from "@mui/material/TextField"; -import IconButton from "@mui/material/IconButton"; import InputAdornment from "@mui/material/InputAdornment"; import Edit from "@mui/icons-material/Edit"; import { ReactNode } from "react"; +import { ButtonIcon } from "components/Icons/ButtonIcons"; export interface Props { label: string | JSX.Element; @@ -57,7 +58,7 @@ export default function InputNumber({ value={value} onChange={(e) => onChange(Number(e.target.value ?? 0))} disabled={disabled} - className={className} + className={["input-number", className ?? ""].join(" ")} placeholder={placeholder} required={required} fullWidth @@ -67,9 +68,10 @@ export default function InputNumber({ endAdornment ) : ( - onChange(disabled ? 0 : undefined)}> - {disabled ? : } - + onChange(disabled ? 0 : undefined)} + icon={disabled ? : } + /> ), inputProps: { diff --git a/webapp/src/components/Inputs/InputTime.css b/webapp/src/components/Inputs/InputTime.css index da1b367..916b2f7 100644 --- a/webapp/src/components/Inputs/InputTime.css +++ b/webapp/src/components/Inputs/InputTime.css @@ -2,6 +2,12 @@ display: flex; gap: 0; flex-direction: row; + justify-content: center; + align-items: center; +} + +.input-time>.input-time--inner>.icon-button { + border: none; } .input-time>.input-time--inner>.MuiFormControl-root { diff --git a/webapp/src/components/Inputs/InputTime.tsx b/webapp/src/components/Inputs/InputTime.tsx index 7c1dea7..7196735 100644 --- a/webapp/src/components/Inputs/InputTime.tsx +++ b/webapp/src/components/Inputs/InputTime.tsx @@ -1,20 +1,24 @@ import "./InputTime.css"; import { useState, useEffect, FC } from "react"; -import TextField from '@mui/material/TextField'; -import EditIcon from '@mui/icons-material/Edit'; +import TextField from "@mui/material/TextField"; +import EditIcon from "@mui/icons-material/Edit"; import CloseIcon from "@mui/icons-material/Close"; -import IconButton from "@mui/material/IconButton" import { AutomationTime, AutomationTimeObject } from "types/automations/common"; -import { convertAutomationTimeToTimeObject, convertObjectToAutomationTimeString, convertAutomationTimeToTimeString } from 'utils/time'; +import { + convertAutomationTimeToTimeObject, + convertObjectToAutomationTimeString, + convertAutomationTimeToTimeString, +} from "utils/time"; import { prettyName } from "utils/formatting"; +import { ButtonIcon } from "components/Icons/ButtonIcons"; // constants const fields: Array = [ - 'hours', - 'minutes', - 'seconds', - 'milliseconds' -] + "hours", + "minutes", + "seconds", + "milliseconds", +]; export interface Props { label: string; value?: AutomationTime; @@ -22,73 +26,73 @@ export interface Props { className?: string; } export const InputTime: FC = (props) => { - - // state - const [disabled, setDisabled] = useState(!props.value) - const [displayValue, setDisplayValue] = useState(convertAutomationTimeToTimeObject(props.value)) + const [disabled, setDisabled] = useState(!props.value); + const [displayValue, setDisplayValue] = useState( + convertAutomationTimeToTimeObject(props.value) + ); // process display input const updateOne = (k: keyof AutomationTimeObject) => (v: string) => { if (Number(v) < 0) { setDisplayValue({ ...displayValue, - [k]: 0 - }) + [k]: 0, + }); } else if (k === "hours") { setDisplayValue({ ...displayValue, - [k]: Number(v) - }) + [k]: Number(v), + }); } else if (k === "minutes") { let minutes = Number(v); - let { hours = 0 } = displayValue + let { hours = 0 } = displayValue; if (minutes > 59) { - const additonalHours = Math.floor(minutes / 60) - hours += additonalHours - minutes = minutes - additonalHours * 60 + const additonalHours = Math.floor(minutes / 60); + hours += additonalHours; + minutes = minutes - additonalHours * 60; } setDisplayValue({ ...displayValue, minutes, hours, - }) + }); } else if (k === "seconds") { let seconds = Number(v); - let { hours = 0, minutes = 0 } = displayValue + let { hours = 0, minutes = 0 } = displayValue; if (seconds > 59) { - const additonalHours = Math.floor(seconds / (60 * 60)) - hours += additonalHours - seconds = seconds - additonalHours * 60 + const additonalHours = Math.floor(seconds / (60 * 60)); + hours += additonalHours; + seconds = seconds - additonalHours * 60; } if (seconds > 59) { - const additionalMinutes = Math.floor(seconds / 60) - minutes += additionalMinutes - seconds = seconds - additionalMinutes * 60 + const additionalMinutes = Math.floor(seconds / 60); + minutes += additionalMinutes; + seconds = seconds - additionalMinutes * 60; } setDisplayValue({ ...displayValue, minutes, hours, seconds, - }) + }); } else if (k === "milliseconds") { let milliseconds = Number(v); - let { hours = 0, minutes = 0, seconds = 0 } = displayValue + let { hours = 0, minutes = 0, seconds = 0 } = displayValue; if (milliseconds > 1000) { - const additonalHours = Math.floor(milliseconds / (60 * 60 * 1000)) - hours += additonalHours - milliseconds = milliseconds - additonalHours * 60 * 60 * 1000 + const additonalHours = Math.floor(milliseconds / (60 * 60 * 1000)); + hours += additonalHours; + milliseconds = milliseconds - additonalHours * 60 * 60 * 1000; } if (milliseconds > 1000) { - const additionalMinutes = Math.floor(milliseconds / (60 * 1000)) - minutes += additionalMinutes - milliseconds = milliseconds - additionalMinutes * 60 * 1000 + const additionalMinutes = Math.floor(milliseconds / (60 * 1000)); + minutes += additionalMinutes; + milliseconds = milliseconds - additionalMinutes * 60 * 1000; } if (milliseconds > 1000) { - const additionalSeconds = Math.floor(milliseconds / 1000) - seconds += additionalSeconds - milliseconds = milliseconds - additionalSeconds * 1000 + const additionalSeconds = Math.floor(milliseconds / 1000); + seconds += additionalSeconds; + milliseconds = milliseconds - additionalSeconds * 1000; } setDisplayValue({ ...displayValue, @@ -96,50 +100,51 @@ export const InputTime: FC = (props) => { hours, seconds, milliseconds, - }) + }); } - } - + }; // effect useEffect(() => { if (disabled && !props.value) { - return + return; } if (disabled) { - props.onChange(undefined) + props.onChange(undefined); } else { const pVal = convertAutomationTimeToTimeString(props.value); const cVal = convertObjectToAutomationTimeString(displayValue); if (pVal !== cVal) { - props.onChange(displayValue) + props.onChange(displayValue); } } // eslint-disable-next-line - }, [disabled, displayValue]) + }, [disabled, displayValue]); - - return
- {/* {props.label} */} -
- {fields.map(name => - updateOne(name)(e.target.value)} + return ( +
+ {/* {props.label} */} +
+ {fields.map((name) => ( + updateOne(name)(e.target.value)} + /> + ))} + setDisabled(!disabled)} + icon={disabled ? : } /> - )} - setDisabled(!disabled)}> - {disabled ? : } - +
-
-} + ); +}; diff --git a/webapp/src/components/Inputs/InputYaml.css b/webapp/src/components/Inputs/InputYaml.css index 8ab62ef..974124f 100644 --- a/webapp/src/components/Inputs/InputYaml.css +++ b/webapp/src/components/Inputs/InputYaml.css @@ -25,8 +25,8 @@ .input-yaml .MuiInputAdornment-positionEnd { position: absolute; - right: 0; - top: 55%; + right: 0.5em; + top: 3.5em; } .input-yaml .input-yaml--placeholder { @@ -34,4 +34,8 @@ left: 2em; top: 2.5em; color: var(--primary-accent); +} + +.input-yaml .MuiButtonBase-root.icon-button[type="button"].icon-button { + border-style: none; } \ No newline at end of file diff --git a/webapp/src/components/Inputs/InputYaml.tsx b/webapp/src/components/Inputs/InputYaml.tsx index c68f195..49d7f56 100644 --- a/webapp/src/components/Inputs/InputYaml.tsx +++ b/webapp/src/components/Inputs/InputYaml.tsx @@ -5,8 +5,10 @@ import { useEffect, useState, ReactNode } from "react"; import CodeMirror from "@uiw/react-codemirror"; import FormControl from "@mui/material/FormControl"; import InputLabel from "@mui/material/InputLabel"; -import { FormHelperText, IconButton, InputAdornment } from "@mui/material"; +import FormHelperText from "@mui/material/FormHelperText"; +import InputAdornment from "@mui/material/InputAdornment"; import { Save } from "@mui/icons-material"; +import { ButtonIcon } from "components/Icons/ButtonIcons"; export interface Props { label: string; @@ -94,15 +96,16 @@ export default function InputYaml({ {!!text ? "" : placeholder} - onSave()} title={!!error ? "Invalid YAML" : hasChanged ? "Save" : ""} - > - - + icon={ + + } + /> {endAdornment} diff --git a/webapp/src/components/Modal/index.css b/webapp/src/components/Modal/index.css new file mode 100644 index 0000000..0c841f2 --- /dev/null +++ b/webapp/src/components/Modal/index.css @@ -0,0 +1,17 @@ +.modal--root { + display: flex; + justify-content: center; + align-items: center; + z-index: 10; + position: fixed; + height: 100vh; + width: 100vw; + top: 0; + left: 0; +} + +.modal--root>div { + max-width: fit-content; + min-width: 100px; + padding: 0.25em; +} \ No newline at end of file diff --git a/webapp/src/components/Modal/index.tsx b/webapp/src/components/Modal/index.tsx index b326a8b..32081d9 100644 --- a/webapp/src/components/Modal/index.tsx +++ b/webapp/src/components/Modal/index.tsx @@ -1,5 +1,7 @@ +import "./index.css"; +import Paper from "@mui/material/Paper"; +import MuiModal from "@mui/material/Modal"; import { FC, ReactNode } from "react"; -import { createAppUseStyles } from "styles/theme"; export interface ModalStyleProps { open: boolean; @@ -7,55 +9,12 @@ export interface ModalStyleProps { export interface Props extends ModalStyleProps { children: ReactNode; } -const useModalStyle = createAppUseStyles(theme => ({ - root: ({ open }) => ({ - display: open ? 'flex' : 'none', - justifyContent: 'center', - alignItems: 'center', - zIndex: open ? 10 : -1, - position: 'fixed', - height: '100vh', - width: '100vw', - top: 0, - left: 0, - }), - background: { - zIndex: 5, - position: 'absolute', - height: '100vh', - width: '100vw', - top: 0, - left: 0, - backgroundColor: theme.secondaryOpaque, - }, - inner: { - zIndex: 10, - maxWidth: '80vw', - maxHeight: '90vh', - minHeight: 'min-content', - minWidth: '100px', - padding: '15px', - display: 'flex', - flexDirection: 'column', - backgroundColor: theme.primary, - borderSize: '1px', - borderStyle: 'solid', - borderColor: theme.primaryAccent, - borderRadius: '10px', - color: theme.primaryAccent, - overflow: "auto", - resize: "auto", - } -})); -export const Modal: FC = ({ - children, - ...props -}) => { - const { classes } = useModalStyle(props); - return
-
-
- {children} -
-
-} +export const Modal: FC = ({ children, ...props }) => { + return ( + +
+ {children} +
+
+ ); +}; diff --git a/webapp/src/components/Page/index.tsx b/webapp/src/components/Page/index.tsx index 0fd4fb0..b870b26 100644 --- a/webapp/src/components/Page/index.tsx +++ b/webapp/src/components/Page/index.tsx @@ -1,80 +1,97 @@ import "./index.css"; -import { createRef, FC, ReactNode, useEffect, useRef } from 'react'; -import { createTheme, ThemeProvider, useTheme } from '@mui/material/styles'; +import { createRef, FC, ReactNode, useEffect, useRef } from "react"; +import { createTheme, ThemeProvider, useTheme } from "@mui/material/styles"; import { VersionBox } from "components/VersionBox"; -import { SnackbarKey, SnackbarProvider, useSnackbar } from 'notistack'; -import { Button } from "@mui/material"; -import { useHAConnection } from 'haService/connection'; +import { SnackbarKey, SnackbarProvider, useSnackbar } from "notistack"; +import Button from "@mui/material/Button"; +import { useHAConnection } from "haService/connection"; const theme = createTheme({ - palette: { - mode: 'dark' - }, + palette: { + mode: "dark", + }, }); export const InternalPage: FC<{ - children: ReactNode + children: ReactNode; }> = ({ children }) => { - const conn = useHAConnection(); - const theme = useTheme(); - const snackbar = useSnackbar(); - const snackbarKeyHAConKey = useRef(null); + const conn = useHAConnection(); + const theme = useTheme(); + const snackbar = useSnackbar(); + const snackbarKeyHAConKey = useRef(null); - useEffect(() => { - if (conn.status === 'error') { - if (snackbarKeyHAConKey.current) { - snackbar.closeSnackbar(snackbarKeyHAConKey.current) - } - snackbarKeyHAConKey.current = snackbar.enqueueSnackbar(`Failed to connect to homeassistant due to "${JSON.stringify(conn.error)}"`, { - "variant": "error", - "persist": true, - }) - } else if (conn.status === 'loading') { - if (snackbarKeyHAConKey.current) { - snackbar.closeSnackbar(snackbarKeyHAConKey.current) - } - snackbarKeyHAConKey.current = snackbar.enqueueSnackbar(`Connecting to websocket...`, { - "variant": "info", - }) - } else if (conn.status === "loaded") { - if (snackbarKeyHAConKey.current) { - snackbar.closeSnackbar(snackbarKeyHAConKey.current) - } - snackbarKeyHAConKey.current = snackbar.enqueueSnackbar(`Connected to HA!`, { - "variant": "success", - }) + useEffect(() => { + if (conn.status === "error") { + if (snackbarKeyHAConKey.current) { + snackbar.closeSnackbar(snackbarKeyHAConKey.current); + } + snackbarKeyHAConKey.current = snackbar.enqueueSnackbar( + `Failed to connect to homeassistant due to "${JSON.stringify( + conn.error + )}"`, + { + variant: "error", + persist: true, } - }, [conn, snackbar]) + ); + } else if (conn.status === "loading") { + if (snackbarKeyHAConKey.current) { + snackbar.closeSnackbar(snackbarKeyHAConKey.current); + } + snackbarKeyHAConKey.current = snackbar.enqueueSnackbar( + `Connecting to websocket...`, + { + variant: "info", + } + ); + } else if (conn.status === "loaded") { + if (snackbarKeyHAConKey.current) { + snackbar.closeSnackbar(snackbarKeyHAConKey.current); + } + snackbarKeyHAConKey.current = snackbar.enqueueSnackbar( + `Connected to HA!`, + { + variant: "success", + } + ); + } + }, [conn, snackbar]); - return
- - {children} + }} + > + + {children}
-} + ); +}; export const Page: FC<{ - children: ReactNode + children: ReactNode; }> = ({ children }) => { - const notistackRef = createRef(); - const onClickDismiss = (key: SnackbarKey) => () => { - notistackRef.current.closeSnackbar(key); - } - return - } - dense preventDuplicate - > - - {children} - - + const notistackRef = createRef(); + const onClickDismiss = (key: SnackbarKey) => () => { + notistackRef.current.closeSnackbar(key); + }; + return ( + + } + dense + preventDuplicate + > + {children} + -} \ No newline at end of file + ); +}; diff --git a/webapp/src/components/ServiceEditor/ServiceEditorField.css b/webapp/src/components/ServiceEditor/ServiceEditorField.css index 1c1fac7..c3c901c 100644 --- a/webapp/src/components/ServiceEditor/ServiceEditorField.css +++ b/webapp/src/components/ServiceEditor/ServiceEditorField.css @@ -16,4 +16,8 @@ white-space: nowrap; width: 100%; max-width: 100%; +} + +.service-editor--field .service-editor--field--remove.icon-button.MuiButtonBase-root.icon-button[type="button"] { + border-style: none; } \ No newline at end of file diff --git a/webapp/src/components/ServiceEditor/ServiceEditorField.tsx b/webapp/src/components/ServiceEditor/ServiceEditorField.tsx index 00f9bd6..7190e86 100644 --- a/webapp/src/components/ServiceEditor/ServiceEditorField.tsx +++ b/webapp/src/components/ServiceEditor/ServiceEditorField.tsx @@ -3,7 +3,6 @@ import { FC, useRef } from "react"; import { ServiceEditorOption } from "./options"; import InputText from "components/Inputs/InputText"; import InputNumber from "components/Inputs/InputNumber"; -import { IconButton } from "@mui/material"; import { RemoveCircle } from "@mui/icons-material"; import { InputAutoComplete, Option } from "components/Inputs/InputAutoComplete"; import { prettyName } from "utils/formatting"; @@ -12,6 +11,7 @@ import { SelectorNumber, SelectorText } from "haService/fieldTypes"; import InputYaml from "components/Inputs/InputYaml"; import { useSnackbar } from "notistack"; import { InputEntity } from "components/Inputs/InputEntities"; +import { ButtonIcon } from "components/Icons/ButtonIcons"; export type ServiceEditorFieldProps = { option: ServiceEditorOption; @@ -34,13 +34,12 @@ export const ServiceEditorField: FC = ({ const removeIcon = !onRemove ? ( <> ) : ( - - - + icon={} + /> ); example = option.data.example ? `Example: ${option.data.example}` : ""; const prop = { diff --git a/webapp/src/haService/HAEntities.ts b/webapp/src/haService/HAEntities.ts index c039ffc..772846d 100644 --- a/webapp/src/haService/HAEntities.ts +++ b/webapp/src/haService/HAEntities.ts @@ -132,7 +132,7 @@ export const useHAEntities = () => { label: entities.collection.state[key].attributes.friendly_name ?? key, domain: key.split(".")[0] ?? "n/a", integration: entitySource.ready - ? entitySource.collection.state[key].domain ?? "n/a" + ? (entitySource.collection.state[key] ?? {}).domain ?? "n/a" : "...", })); },