added saving for new
This commit is contained in:
1 parent
b4a9763ead
commit
644edb2ef6
10 files changed
+37
-8
No files matched your search
@@ -19,18 +19,21 @@ import { DAGAutomationGraph } from "components/DAGGraph";
|
|||||||
import { InputList } from "components/Inputs/InputList";
|
import { InputList } from "components/Inputs/InputList";
|
||||||
import { InputTextView } from "components/Inputs/InputTextView";
|
import { InputTextView } from "components/Inputs/InputTextView";
|
||||||
import { ControlButton } from "react-flow-renderer";
|
import { ControlButton } from "react-flow-renderer";
|
||||||
|
import Edit from "@mui/icons-material/Edit";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
automation?: AutomationData;
|
automation?: AutomationData;
|
||||||
dims: DAGDims;
|
dims: DAGDims;
|
||||||
onUpdate: (auto: AutomationData) => void;
|
onUpdate: (auto: AutomationData) => void;
|
||||||
tagDB: TagDB;
|
tagDB: TagDB;
|
||||||
|
isNew?: boolean;
|
||||||
}
|
}
|
||||||
export const AutomationEditor: FC<Props> = ({
|
export const AutomationEditor: FC<Props> = ({
|
||||||
dims,
|
dims,
|
||||||
automation: propsAutos,
|
automation: propsAutos,
|
||||||
onUpdate: propsOnUpdate,
|
onUpdate: propsOnUpdate,
|
||||||
tagDB,
|
tagDB,
|
||||||
|
isNew,
|
||||||
}) => {
|
}) => {
|
||||||
// state
|
// state
|
||||||
const {
|
const {
|
||||||
@@ -188,10 +191,16 @@ export const AutomationEditor: FC<Props> = ({
|
|||||||
Flip
|
Flip
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
<Button
|
||||||
|
className={"automation-editor--flow-wrapper--toolbar--edit-btn"}
|
||||||
|
onClick={() => setInfoBox(!infoBoxOpen)}
|
||||||
|
>
|
||||||
|
Metadata <Edit />
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
className={"automation-editor--flow-wrapper--toolbar--save-btn"}
|
className={"automation-editor--flow-wrapper--toolbar--save-btn"}
|
||||||
onClick={save}
|
onClick={save}
|
||||||
disabled={state.status !== "changed"}
|
disabled={state.status !== "changed" && !isNew}
|
||||||
>
|
>
|
||||||
Save <CheckMarkIcon color="#bf4" />
|
Save <CheckMarkIcon color="#bf4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ export const useAutomationDB = (
|
|||||||
state: "unregistered",
|
state: "unregistered",
|
||||||
tags: {},
|
tags: {},
|
||||||
issue: "New Automation",
|
issue: "New Automation",
|
||||||
|
isNew: true,
|
||||||
},
|
},
|
||||||
auto,
|
auto,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ export const AutomationManagerLoaded: FC<
|
|||||||
automation={state.currentAutomation}
|
automation={state.currentAutomation}
|
||||||
onUpdate={state.editorUpdateAutomation}
|
onUpdate={state.editorUpdateAutomation}
|
||||||
tagDB={state.tagsDB}
|
tagDB={state.tagsDB}
|
||||||
|
isNew={state.currentAutomationIsNew}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -42,3 +42,4 @@ export const Basic = make({});
|
|||||||
export const IsSelected = make({ isSelected: true });
|
export const IsSelected = make({ isSelected: true });
|
||||||
export const InvalidState = make({ state: "unavailable" });
|
export const InvalidState = make({ state: "unavailable" });
|
||||||
export const WithIssue = make({ issue: "look at me" });
|
export const WithIssue = make({ issue: "look at me" });
|
||||||
|
export const NewAutomation = make({ isNew: true });
|
||||||
@@ -33,6 +33,7 @@ export const MetadataBox: FC<MetadataBoxProps> = (props) => {
|
|||||||
"automation-manager--metadatabox",
|
"automation-manager--metadatabox",
|
||||||
props.isSelected ? "selected" : "",
|
props.isSelected ? "selected" : "",
|
||||||
isMobile ? "mobile" : "",
|
isMobile ? "mobile" : "",
|
||||||
|
props.isNew ? "new" : "",
|
||||||
].join(" ")}
|
].join(" ")}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -58,14 +59,16 @@ export const MetadataBox: FC<MetadataBoxProps> = (props) => {
|
|||||||
placeholder="Title"
|
placeholder="Title"
|
||||||
value={props.title}
|
value={props.title}
|
||||||
onChange={props.onTitleUpdate}
|
onChange={props.onTitleUpdate}
|
||||||
|
disabled={props.isNew}
|
||||||
/>
|
/>
|
||||||
<InputTextView
|
<InputTextView
|
||||||
className="description"
|
className="description"
|
||||||
placeholder="Description"
|
placeholder="Description"
|
||||||
value={props.description}
|
value={props.description}
|
||||||
onChange={props.onDescriptionUpdate}
|
onChange={props.onDescriptionUpdate}
|
||||||
|
disabled={props.isNew}
|
||||||
/>
|
/>
|
||||||
<Tags automationId={props.id} tagsDB={props.tagsDB} />
|
{!props.isNew && <Tags automationId={props.id} tagsDB={props.tagsDB} />}
|
||||||
{props.issue ? (
|
{props.issue ? (
|
||||||
<Alert severity="warning" className="issue">
|
<Alert severity="warning" className="issue">
|
||||||
{props.issue}
|
{props.issue}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const { make, componentMeta } = makeStory({
|
|||||||
<AutomationManager
|
<AutomationManager
|
||||||
api={useMockApiService(args.automations ?? [], !args.automations)}
|
api={useMockApiService(args.automations ?? [], !args.automations)}
|
||||||
haEntities={useMockHAEntities(haEntities)}
|
haEntities={useMockHAEntities(haEntities)}
|
||||||
|
refreshAutomations={() => {}}
|
||||||
onAutomationStateChange={(eid, on) => {
|
onAutomationStateChange={(eid, on) => {
|
||||||
if (!haEntities.loading && !haEntities.error) {
|
if (!haEntities.loading && !haEntities.error) {
|
||||||
setHAE({
|
setHAE({
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { useSnackbar } from "notistack";
|
|||||||
|
|
||||||
export type AutomationManagerProps = {
|
export type AutomationManagerProps = {
|
||||||
onAutomationStateChange: (eid: string, on: boolean) => void;
|
onAutomationStateChange: (eid: string, on: boolean) => void;
|
||||||
|
refreshAutomations: () => void;
|
||||||
haEntities: HAEntitiesState;
|
haEntities: HAEntitiesState;
|
||||||
api: ApiService;
|
api: ApiService;
|
||||||
};
|
};
|
||||||
@@ -20,6 +21,7 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
|||||||
api,
|
api,
|
||||||
haEntities,
|
haEntities,
|
||||||
onAutomationStateChange,
|
onAutomationStateChange,
|
||||||
|
refreshAutomations,
|
||||||
}) => {
|
}) => {
|
||||||
const snackbr = useSnackbar();
|
const snackbr = useSnackbar();
|
||||||
const [isSaving, setIsSaving] = useState(false);
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
@@ -71,12 +73,13 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
|||||||
configAutomations={configAutomations.data}
|
configAutomations={configAutomations.data}
|
||||||
hassEntities={hassEntities}
|
hassEntities={hassEntities}
|
||||||
onAutomationStateChange={onAutomationStateChange}
|
onAutomationStateChange={onAutomationStateChange}
|
||||||
onAutomationAdd={(auto) =>
|
onAutomationAdd={async (auto) => {
|
||||||
api.updateAutomation({
|
await api.updateAutomation({
|
||||||
index: configAutomations.totalItems + 1,
|
index: configAutomations.totalItems + 1,
|
||||||
auto,
|
auto,
|
||||||
})
|
});
|
||||||
}
|
refreshAutomations();
|
||||||
|
}}
|
||||||
onAutomationDelete={(aid) => {
|
onAutomationDelete={(aid) => {
|
||||||
const index = configAutomations.data.findIndex(
|
const index = configAutomations.data.findIndex(
|
||||||
({ metadata }) => metadata.id === aid
|
({ metadata }) => metadata.id === aid
|
||||||
@@ -85,6 +88,7 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
|||||||
api.removeAutomation({
|
api.removeAutomation({
|
||||||
index,
|
index,
|
||||||
});
|
});
|
||||||
|
refreshAutomations();
|
||||||
} else {
|
} else {
|
||||||
snackbr.enqueueSnackbar(
|
snackbr.enqueueSnackbar(
|
||||||
"Failed to delete automation, this may be resolved by a refresh or reboot of Home Assistant",
|
"Failed to delete automation, this may be resolved by a refresh or reboot of Home Assistant",
|
||||||
@@ -105,6 +109,7 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
|||||||
),
|
),
|
||||||
auto,
|
auto,
|
||||||
});
|
});
|
||||||
|
refreshAutomations();
|
||||||
} else {
|
} else {
|
||||||
snackbr.enqueueSnackbar(
|
snackbr.enqueueSnackbar(
|
||||||
"Failed to update automation, this may be resolved by a refresh or reboot of Home Assistant.",
|
"Failed to update automation, this may be resolved by a refresh or reboot of Home Assistant.",
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export type AutomationManagerAuto = AutomationManagerAutoUpdatable & {
|
|||||||
entityId: string;
|
entityId: string;
|
||||||
tags: Record<string, string>;
|
tags: Record<string, string>;
|
||||||
issue?: string;
|
issue?: string;
|
||||||
|
isNew?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AutomationManagerItem = {
|
export type AutomationManagerItem = {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export type InputTextViewProps = {
|
|||||||
onChange: (t: string) => void;
|
onChange: (t: string) => void;
|
||||||
initialViewMode?: boolean;
|
initialViewMode?: boolean;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
|
disabled?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const InputTextView: FC<PropsWithChildren<InputTextViewProps>> = (
|
export const InputTextView: FC<PropsWithChildren<InputTextViewProps>> = (
|
||||||
@@ -26,7 +27,10 @@ export const InputTextView: FC<PropsWithChildren<InputTextViewProps>> = (
|
|||||||
|
|
||||||
if (viewMode) {
|
if (viewMode) {
|
||||||
return (
|
return (
|
||||||
<div className={className} onClick={() => setViewMode(false)}>
|
<div
|
||||||
|
className={className}
|
||||||
|
onClick={() => !!props.disabled && setViewMode(false)}
|
||||||
|
>
|
||||||
{!!props.value ? (
|
{!!props.value ? (
|
||||||
<span>{props.value}</span>
|
<span>{props.value}</span>
|
||||||
) : (
|
) : (
|
||||||
@@ -34,7 +38,9 @@ export const InputTextView: FC<PropsWithChildren<InputTextViewProps>> = (
|
|||||||
{props.placeholder}
|
{props.placeholder}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
<ModeEditOutlineOutlinedIcon className="input-text-view--edit" />
|
{!props.disabled && (
|
||||||
|
<ModeEditOutlineOutlinedIcon className="input-text-view--edit" />
|
||||||
|
)}
|
||||||
{props.children}
|
{props.children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export const AutomationRoute: FC<{ api: ApiService }> = ({ api }) => {
|
|||||||
<Page>
|
<Page>
|
||||||
<AutomationManager
|
<AutomationManager
|
||||||
api={api}
|
api={api}
|
||||||
|
refreshAutomations={() => ha.callService("automation", "reload")}
|
||||||
onAutomationStateChange={(eid, on) => {
|
onAutomationStateChange={(eid, on) => {
|
||||||
ha.callService(
|
ha.callService(
|
||||||
"automation",
|
"automation",
|
||||||
|
|||||||
Reference in new issue
Block a user