diff --git a/webapp/src/components/AutomationList/AutomationMetadataBox.tsx b/webapp/src/components/AutomationList/AutomationMetadataBox.tsx index b3afab6..5982997 100644 --- a/webapp/src/components/AutomationList/AutomationMetadataBox.tsx +++ b/webapp/src/components/AutomationList/AutomationMetadataBox.tsx @@ -6,7 +6,6 @@ import { InputAutoComplete } from "components/Inputs/InputAutoComplete"; import { TagDB } from "./TagDB"; import DeleteIcon from "@mui/icons-material/ClearTwoTone"; import { InputTextView } from "components/Inputs/InputTextView"; -import { useHAEntities } from "haService/HAEntities"; export const MetadataBox: FC<{ metadata: AutomationMetadata; diff --git a/webapp/src/components/AutomationListV2/ListBoxGroup/index.tsx b/webapp/src/components/AutomationListV2/ListBoxGroup/index.tsx index e318d16..3a9a012 100644 --- a/webapp/src/components/AutomationListV2/ListBoxGroup/index.tsx +++ b/webapp/src/components/AutomationListV2/ListBoxGroup/index.tsx @@ -3,6 +3,7 @@ import "./index.css"; import { FC, useState } from "react"; import { MetadataBox } from "../MetadataBox"; import { AutomationListAutoUpdatable, AutomationListItem } from "../types"; +import { TagDB } from "../TagDB"; export type ListBoxGroupProps = AutomationListItem & { onTagUpdate: (t: Record, aid: string) => void; @@ -14,6 +15,7 @@ export type ListBoxGroupProps = AutomationListItem & { onAutomationDelete: (aid: string) => void; onSelect: (aid: string) => void; initialOpenState?: boolean; + tagsDB: TagDB; }; export const ListBoxGroup: FC = ({ title, @@ -21,6 +23,7 @@ export const ListBoxGroup: FC = ({ data, isSelected, initialOpenState, + tagsDB, ...events }) => { const [open, setOpen] = useState(initialOpenState ?? false); @@ -58,6 +61,7 @@ export const ListBoxGroup: FC = ({ events.onAutomationDelete(auto.id)} onSelect={() => events.onSelect(auto.id)} onTagUpdate={(t) => events.onTagUpdate(t, auto.id)} @@ -94,7 +98,7 @@ export const ListBoxGroup: FC = ({ /> )) : data.map((group, i) => ( - + ))} diff --git a/webapp/src/components/AutomationListV2/MetadataBox/Tags.tsx b/webapp/src/components/AutomationListV2/MetadataBox/Tags.tsx index 9a9acc1..c37a649 100644 --- a/webapp/src/components/AutomationListV2/MetadataBox/Tags.tsx +++ b/webapp/src/components/AutomationListV2/MetadataBox/Tags.tsx @@ -1,17 +1,90 @@ -import { FC } from "react"; +import { FC, ReactNode, useState } from "react"; import DeleteIcon from "@mui/icons-material/ClearTwoTone"; +import EditIcon from "@mui/icons-material/EditOutlined"; import { cleanUpUndefined } from "utils/helpers"; +import { Modal } from "components/Modal"; +import { Button } from "components/Inputs/Button"; +import InputAutoText from "components/Inputs/InputAutoText"; + +import { TagDB } from "../TagDB"; export type TagsProps = { tags: Record; onUpdate: (t: Record) => void; + tagsDB: TagDB; }; -export const Tags: FC = ({ tags, onUpdate }) => { +export type TagModalState = + | { + open: false; + } + | { + open: true; + tag: [string, string]; + isNew: boolean; + }; + +export const Tags: FC = ({ tags, onUpdate, tagsDB }) => { + const [modalState, setModal] = useState({ open: false }); + + let innerModal: ReactNode = <>; + if (modalState.open) { + const validTag = + modalState.tag[0].trim().length > 0 && + modalState.tag[1].trim().length > 0; + innerModal = ( +
+ + setModal({ + ...modalState, + tag: [v ?? "", modalState.tag[1]], + }) + } + /> + + setModal({ + ...modalState, + tag: [modalState.tag[0], v ?? ""], + }) + } + /> +
+ + +
+
+ ); + } + return (
+ {innerModal} {Object.entries(tags).map(([tagName, tagValue]) => ( = ({ tags, onUpdate }) => { } className="delete-tag" /> - {tagName}: {tagValue} + + setModal({ + open: true, + isNew: false, + tag: [tagName, tagValue], + }) + } + > + {tagName}: {tagValue} + ))} - {}}> + + setModal({ + open: true, + isNew: true, + tag: ["", ""], + }) + } + > +
diff --git a/webapp/src/components/AutomationListV2/MetadataBox/index.css b/webapp/src/components/AutomationListV2/MetadataBox/index.css index 51256ac..7b866b7 100644 --- a/webapp/src/components/AutomationListV2/MetadataBox/index.css +++ b/webapp/src/components/AutomationListV2/MetadataBox/index.css @@ -115,4 +115,38 @@ color: var(--mui-error-light); outline: 1px solid var(--mui-error-dark); border-radius: 20px; +} + +.automation-list--metadatabox .metadatabox--tags .tag .inner { + font-size: 1em; + display: flex; + justify-content: center; + align-items: center; + cursor: text; + user-select: none; +} + +.automation-list--metadatabox .metadatabox--tags .tag .inner .edit-icon { + height: 0.7em; + width: 0.7em; + padding: 0.15em; +} + + +.metadatabox--tags--modal { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + gap: 0.25em; +} + +.metadatabox--tags--modal .input-autotext { + min-width: calc(max(10em, 100%)); +} + +.metadatabox--tags--modal .buttons { + display: flex; + gap: 0.5em; + justify-content: space-evenly; } \ No newline at end of file diff --git a/webapp/src/components/AutomationListV2/MetadataBox/index.stories.tsx b/webapp/src/components/AutomationListV2/MetadataBox/index.stories.tsx index 6403add..2acae86 100644 --- a/webapp/src/components/AutomationListV2/MetadataBox/index.stories.tsx +++ b/webapp/src/components/AutomationListV2/MetadataBox/index.stories.tsx @@ -2,6 +2,7 @@ import "styles/root.css"; import { ComponentMeta, ComponentStory } from "@storybook/react"; import { Page } from "components/Page"; import { MetadataBox } from "."; +import { makeTagDB } from "../TagDB"; export default { title: "App/AutomationList/MetadataBox", @@ -22,7 +23,7 @@ export default { const Template: ComponentStory = (args) => { return ( - + ); }; diff --git a/webapp/src/components/AutomationListV2/MetadataBox/index.tsx b/webapp/src/components/AutomationListV2/MetadataBox/index.tsx index 485352d..0b0db38 100644 --- a/webapp/src/components/AutomationListV2/MetadataBox/index.tsx +++ b/webapp/src/components/AutomationListV2/MetadataBox/index.tsx @@ -9,9 +9,9 @@ import SelectIcon from "@mui/icons-material/HighlightAltSharp"; import { InputTextView } from "components/Inputs/InputTextView"; import { ButtonIcon } from "components/Icons/ButtonIcons"; -import { cleanUpUndefined } from "utils/helpers"; import { AutomationListAuto } from "../types"; import { Tags } from "./Tags"; +import { TagDB } from "../TagDB"; export type MetadataBoxProps = AutomationListAuto & { onDelete: () => void; @@ -20,6 +20,7 @@ export type MetadataBoxProps = AutomationListAuto & { onTagUpdate: (t: Record) => void; onTitleUpdate: (t: string) => void; onDescriptionUpdate: (t: string) => void; + tagsDB: TagDB; }; export const MetadataBox: FC = (props) => { const isValidState = ["on", "off"].includes(props.state); @@ -57,7 +58,11 @@ export const MetadataBox: FC = (props) => { value={props.description} onChange={props.onDescriptionUpdate} /> - + {props.issue ? ( {props.issue} diff --git a/webapp/src/components/AutomationListV2/index.tsx b/webapp/src/components/AutomationListV2/index.tsx index 0a0b01f..720d318 100644 --- a/webapp/src/components/AutomationListV2/index.tsx +++ b/webapp/src/components/AutomationListV2/index.tsx @@ -84,6 +84,7 @@ export const AutomationList: FC = ({ key={i} onSelect={setSelectedAutomationId} {...events} + tagsDB={tagsDB} initialOpenState={true} /> ))} diff --git a/webapp/src/components/Inputs/Button.tsx b/webapp/src/components/Inputs/Button.tsx index cd3201e..e3cd24e 100644 --- a/webapp/src/components/Inputs/Button.tsx +++ b/webapp/src/components/Inputs/Button.tsx @@ -1,5 +1,5 @@ import { FC, ReactNode } from "react"; -import MuiButton from "@mui/material/Button"; +import MuiButton, { ButtonProps as MuiButtonProps } from "@mui/material/Button"; export const Button: FC<{ className?: string; @@ -7,6 +7,7 @@ export const Button: FC<{ disabled?: boolean; children?: ReactNode; onClick?: () => void; + color?: MuiButtonProps["color"]; }> = (props) => { return ( ); }; diff --git a/webapp/src/components/Inputs/InputAutoText.stories.tsx b/webapp/src/components/Inputs/InputAutoText.stories.tsx new file mode 100644 index 0000000..809c922 --- /dev/null +++ b/webapp/src/components/Inputs/InputAutoText.stories.tsx @@ -0,0 +1,29 @@ +import { ComponentMeta, ComponentStory } from "@storybook/react"; +import { Page } from "components/Page"; +import InputAutoText from "./InputAutoText"; + +export default { + title: "Inputs/InputAutoText", + component: InputAutoText, + parameters: { actions: { argTypesRegex: "^on.*" } }, + args: { + label: "Something", + value: "", + options: ["test", "usa", "canada"], + }, +} as ComponentMeta; + +const Template: ComponentStory = (args) => { + return ( + + + + ); +}; + +export const Basic = Template.bind({}); +export const WithError = Template.bind({}); +WithError.args = { + ...WithError.args, + error: "Oh no!", +}; diff --git a/webapp/src/components/Inputs/InputAutoText.tsx b/webapp/src/components/Inputs/InputAutoText.tsx index eaf445c..322f684 100644 --- a/webapp/src/components/Inputs/InputAutoText.tsx +++ b/webapp/src/components/Inputs/InputAutoText.tsx @@ -11,14 +11,12 @@ export interface InputAutoTextProps { required?: boolean; endAdornment?: ReactNode; onChange: (v: string) => void; - onEnter?: () => void; } export default function InputAutoText({ value = "", label, options = [], onChange, - onEnter = () => {}, className, required, endAdornment, @@ -27,9 +25,10 @@ export default function InputAutoText({ return ( onChange(v === null ? "" : v)} renderInput={(params) => ( { - if (e.key === "Enter") { - onEnter(); - } + ...params.InputProps, + endAdornment: ( + <> + {endAdornment} {params.InputProps.endAdornment} + + ), }} onChange={(e) => { e.preventDefault();