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 { 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<Props> = ({
|
||||
dims,
|
||||
automation: propsAutos,
|
||||
onUpdate: propsOnUpdate,
|
||||
tagDB,
|
||||
isNew,
|
||||
}) => {
|
||||
// state
|
||||
const {
|
||||
@@ -188,10 +191,16 @@ export const AutomationEditor: FC<Props> = ({
|
||||
Flip
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
className={"automation-editor--flow-wrapper--toolbar--edit-btn"}
|
||||
onClick={() => setInfoBox(!infoBoxOpen)}
|
||||
>
|
||||
Metadata <Edit />
|
||||
</Button>
|
||||
<Button
|
||||
className={"automation-editor--flow-wrapper--toolbar--save-btn"}
|
||||
onClick={save}
|
||||
disabled={state.status !== "changed"}
|
||||
disabled={state.status !== "changed" && !isNew}
|
||||
>
|
||||
Save <CheckMarkIcon color="#bf4" />
|
||||
</Button>
|
||||
|
||||
@@ -57,6 +57,7 @@ export const useAutomationDB = (
|
||||
state: "unregistered",
|
||||
tags: {},
|
||||
issue: "New Automation",
|
||||
isNew: true,
|
||||
},
|
||||
auto,
|
||||
]);
|
||||
|
||||
@@ -44,6 +44,7 @@ export const AutomationManagerLoaded: FC<
|
||||
automation={state.currentAutomation}
|
||||
onUpdate={state.editorUpdateAutomation}
|
||||
tagDB={state.tagsDB}
|
||||
isNew={state.currentAutomationIsNew}
|
||||
/>
|
||||
) : (
|
||||
<div>
|
||||
|
||||
@@ -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 });
|
||||
@@ -33,6 +33,7 @@ export const MetadataBox: FC<MetadataBoxProps> = (props) => {
|
||||
"automation-manager--metadatabox",
|
||||
props.isSelected ? "selected" : "",
|
||||
isMobile ? "mobile" : "",
|
||||
props.isNew ? "new" : "",
|
||||
].join(" ")}
|
||||
>
|
||||
<div
|
||||
@@ -58,14 +59,16 @@ export const MetadataBox: FC<MetadataBoxProps> = (props) => {
|
||||
placeholder="Title"
|
||||
value={props.title}
|
||||
onChange={props.onTitleUpdate}
|
||||
disabled={props.isNew}
|
||||
/>
|
||||
<InputTextView
|
||||
className="description"
|
||||
placeholder="Description"
|
||||
value={props.description}
|
||||
onChange={props.onDescriptionUpdate}
|
||||
disabled={props.isNew}
|
||||
/>
|
||||
<Tags automationId={props.id} tagsDB={props.tagsDB} />
|
||||
{!props.isNew && <Tags automationId={props.id} tagsDB={props.tagsDB} />}
|
||||
{props.issue ? (
|
||||
<Alert severity="warning" className="issue">
|
||||
{props.issue}
|
||||
|
||||
@@ -19,6 +19,7 @@ const { make, componentMeta } = makeStory({
|
||||
<AutomationManager
|
||||
api={useMockApiService(args.automations ?? [], !args.automations)}
|
||||
haEntities={useMockHAEntities(haEntities)}
|
||||
refreshAutomations={() => {}}
|
||||
onAutomationStateChange={(eid, on) => {
|
||||
if (!haEntities.loading && !haEntities.error) {
|
||||
setHAE({
|
||||
|
||||
@@ -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<AutomationManagerProps> = ({
|
||||
api,
|
||||
haEntities,
|
||||
onAutomationStateChange,
|
||||
refreshAutomations,
|
||||
}) => {
|
||||
const snackbr = useSnackbar();
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
@@ -71,12 +73,13 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
|
||||
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<AutomationManagerProps> = ({
|
||||
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<AutomationManagerProps> = ({
|
||||
),
|
||||
auto,
|
||||
});
|
||||
refreshAutomations();
|
||||
} else {
|
||||
snackbr.enqueueSnackbar(
|
||||
"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;
|
||||
tags: Record<string, string>;
|
||||
issue?: string;
|
||||
isNew?: boolean;
|
||||
};
|
||||
|
||||
export type AutomationManagerItem = {
|
||||
|
||||
@@ -11,6 +11,7 @@ export type InputTextViewProps = {
|
||||
onChange: (t: string) => void;
|
||||
initialViewMode?: boolean;
|
||||
placeholder?: string;
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
export const InputTextView: FC<PropsWithChildren<InputTextViewProps>> = (
|
||||
@@ -26,7 +27,10 @@ export const InputTextView: FC<PropsWithChildren<InputTextViewProps>> = (
|
||||
|
||||
if (viewMode) {
|
||||
return (
|
||||
<div className={className} onClick={() => setViewMode(false)}>
|
||||
<div
|
||||
className={className}
|
||||
onClick={() => !!props.disabled && setViewMode(false)}
|
||||
>
|
||||
{!!props.value ? (
|
||||
<span>{props.value}</span>
|
||||
) : (
|
||||
@@ -34,7 +38,9 @@ export const InputTextView: FC<PropsWithChildren<InputTextViewProps>> = (
|
||||
{props.placeholder}
|
||||
</span>
|
||||
)}
|
||||
<ModeEditOutlineOutlinedIcon className="input-text-view--edit" />
|
||||
{!props.disabled && (
|
||||
<ModeEditOutlineOutlinedIcon className="input-text-view--edit" />
|
||||
)}
|
||||
{props.children}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -10,6 +10,7 @@ export const AutomationRoute: FC<{ api: ApiService }> = ({ api }) => {
|
||||
<Page>
|
||||
<AutomationManager
|
||||
api={api}
|
||||
refreshAutomations={() => ha.callService("automation", "reload")}
|
||||
onAutomationStateChange={(eid, on) => {
|
||||
ha.callService(
|
||||
"automation",
|
||||
|
||||
Reference in new issue
Block a user