added saving for new

This commit is contained in:
ari committed 2022-07-29 14:56:26 -04:00
1 parent b4a9763ead
commit 644edb2ef6
10 files changed
+37 -8

No files matched your search

@@ -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 = {