diff --git a/webapp/src/components/AutomationEditor/index.tsx b/webapp/src/components/AutomationEditor/index.tsx index a4a4186..f07a8b7 100644 --- a/webapp/src/components/AutomationEditor/index.tsx +++ b/webapp/src/components/AutomationEditor/index.tsx @@ -19,18 +19,21 @@ import { DAGAutomationGraph } from "components/DAGGraph"; import { InputList } from "components/Inputs/InputList"; import { InputTextView } from "components/Inputs/InputTextView"; import { ControlButton } from "react-flow-renderer"; +import Edit from "@mui/icons-material/Edit"; interface Props { automation?: AutomationData; dims: DAGDims; onUpdate: (auto: AutomationData) => void; tagDB: TagDB; + isNew?: boolean; } export const AutomationEditor: FC = ({ dims, automation: propsAutos, onUpdate: propsOnUpdate, tagDB, + isNew, }) => { // state const { @@ -188,10 +191,16 @@ export const AutomationEditor: FC = ({ Flip )} + diff --git a/webapp/src/components/AutomationManager/Loaded/automationDB.ts b/webapp/src/components/AutomationManager/Loaded/automationDB.ts index 005eb7a..cb07db8 100644 --- a/webapp/src/components/AutomationManager/Loaded/automationDB.ts +++ b/webapp/src/components/AutomationManager/Loaded/automationDB.ts @@ -57,6 +57,7 @@ export const useAutomationDB = ( state: "unregistered", tags: {}, issue: "New Automation", + isNew: true, }, auto, ]); diff --git a/webapp/src/components/AutomationManager/Loaded/index.tsx b/webapp/src/components/AutomationManager/Loaded/index.tsx index 0baa80d..5eba3e5 100644 --- a/webapp/src/components/AutomationManager/Loaded/index.tsx +++ b/webapp/src/components/AutomationManager/Loaded/index.tsx @@ -44,6 +44,7 @@ export const AutomationManagerLoaded: FC< automation={state.currentAutomation} onUpdate={state.editorUpdateAutomation} tagDB={state.tagsDB} + isNew={state.currentAutomationIsNew} /> ) : (
diff --git a/webapp/src/components/AutomationManager/MetadataBox/index.stories.tsx b/webapp/src/components/AutomationManager/MetadataBox/index.stories.tsx index 6a61d78..ee05dc0 100644 --- a/webapp/src/components/AutomationManager/MetadataBox/index.stories.tsx +++ b/webapp/src/components/AutomationManager/MetadataBox/index.stories.tsx @@ -42,3 +42,4 @@ export const Basic = make({}); export const IsSelected = make({ isSelected: true }); export const InvalidState = make({ state: "unavailable" }); export const WithIssue = make({ issue: "look at me" }); +export const NewAutomation = make({ isNew: true }); diff --git a/webapp/src/components/AutomationManager/MetadataBox/index.tsx b/webapp/src/components/AutomationManager/MetadataBox/index.tsx index 94e78b1..b49c12d 100644 --- a/webapp/src/components/AutomationManager/MetadataBox/index.tsx +++ b/webapp/src/components/AutomationManager/MetadataBox/index.tsx @@ -33,6 +33,7 @@ export const MetadataBox: FC = (props) => { "automation-manager--metadatabox", props.isSelected ? "selected" : "", isMobile ? "mobile" : "", + props.isNew ? "new" : "", ].join(" ")} >
= (props) => { placeholder="Title" value={props.title} onChange={props.onTitleUpdate} + disabled={props.isNew} /> - + {!props.isNew && } {props.issue ? ( {props.issue} diff --git a/webapp/src/components/AutomationManager/index.stories.tsx b/webapp/src/components/AutomationManager/index.stories.tsx index 127c250..3724cc0 100644 --- a/webapp/src/components/AutomationManager/index.stories.tsx +++ b/webapp/src/components/AutomationManager/index.stories.tsx @@ -19,6 +19,7 @@ const { make, componentMeta } = makeStory({ {}} onAutomationStateChange={(eid, on) => { if (!haEntities.loading && !haEntities.error) { setHAE({ diff --git a/webapp/src/components/AutomationManager/index.tsx b/webapp/src/components/AutomationManager/index.tsx index 053be2c..ef26096 100644 --- a/webapp/src/components/AutomationManager/index.tsx +++ b/webapp/src/components/AutomationManager/index.tsx @@ -12,6 +12,7 @@ import { useSnackbar } from "notistack"; export type AutomationManagerProps = { onAutomationStateChange: (eid: string, on: boolean) => void; + refreshAutomations: () => void; haEntities: HAEntitiesState; api: ApiService; }; @@ -20,6 +21,7 @@ export const AutomationManager: FC = ({ api, haEntities, onAutomationStateChange, + refreshAutomations, }) => { const snackbr = useSnackbar(); const [isSaving, setIsSaving] = useState(false); @@ -71,12 +73,13 @@ export const AutomationManager: FC = ({ configAutomations={configAutomations.data} hassEntities={hassEntities} onAutomationStateChange={onAutomationStateChange} - onAutomationAdd={(auto) => - api.updateAutomation({ + onAutomationAdd={async (auto) => { + await api.updateAutomation({ index: configAutomations.totalItems + 1, auto, - }) - } + }); + refreshAutomations(); + }} onAutomationDelete={(aid) => { const index = configAutomations.data.findIndex( ({ metadata }) => metadata.id === aid @@ -85,6 +88,7 @@ export const AutomationManager: FC = ({ api.removeAutomation({ index, }); + refreshAutomations(); } else { snackbr.enqueueSnackbar( "Failed to delete automation, this may be resolved by a refresh or reboot of Home Assistant", @@ -105,6 +109,7 @@ export const AutomationManager: FC = ({ ), auto, }); + refreshAutomations(); } else { snackbr.enqueueSnackbar( "Failed to update automation, this may be resolved by a refresh or reboot of Home Assistant.", diff --git a/webapp/src/components/AutomationManager/types.ts b/webapp/src/components/AutomationManager/types.ts index 92b4299..fdb9cf0 100644 --- a/webapp/src/components/AutomationManager/types.ts +++ b/webapp/src/components/AutomationManager/types.ts @@ -8,6 +8,7 @@ export type AutomationManagerAuto = AutomationManagerAutoUpdatable & { entityId: string; tags: Record; issue?: string; + isNew?: boolean; }; export type AutomationManagerItem = { diff --git a/webapp/src/components/Inputs/InputTextView.tsx b/webapp/src/components/Inputs/InputTextView.tsx index 672af06..5665c66 100644 --- a/webapp/src/components/Inputs/InputTextView.tsx +++ b/webapp/src/components/Inputs/InputTextView.tsx @@ -11,6 +11,7 @@ export type InputTextViewProps = { onChange: (t: string) => void; initialViewMode?: boolean; placeholder?: string; + disabled?: boolean; }; export const InputTextView: FC> = ( @@ -26,7 +27,10 @@ export const InputTextView: FC> = ( if (viewMode) { return ( -
setViewMode(false)}> +
!!props.disabled && setViewMode(false)} + > {!!props.value ? ( {props.value} ) : ( @@ -34,7 +38,9 @@ export const InputTextView: FC> = ( {props.placeholder} )} - + {!props.disabled && ( + + )} {props.children}
); diff --git a/webapp/src/routes/automation.tsx b/webapp/src/routes/automation.tsx index 82ac37e..c73a73a 100644 --- a/webapp/src/routes/automation.tsx +++ b/webapp/src/routes/automation.tsx @@ -10,6 +10,7 @@ export const AutomationRoute: FC<{ api: ApiService }> = ({ api }) => { ha.callService("automation", "reload")} onAutomationStateChange={(eid, on) => { ha.callService( "automation",