= ({
+ api,
+ haEntites,
+}) => {
+ const [isSaving, setIsSaving] = useState(false);
- if (!props.haEntites.ready) {
+ // handle bad states
+ if (!haEntites.ready || !api.state.automations.ready) {
return ...
;
}
- const tagsDB = useTagDB(
- props.configAutomations.data.map(({ metadata: { id }, tags }) => ({
- id,
- tags,
- })),
- props.onUpdateTags
- );
- const automations = consolidateAutomations(
- props.haEntites.collection.state,
- props.configAutomations.data.map(({ metadata }) => metadata),
- tagsDB
- );
+ if (!api.state.automations.ok) {
+ return (
+
+
Failed to load
+ {api.state.automations.error}
+
+ );
+ }
+
+ // alias
+ const configAutomations = api.state.automations.data.data;
+ const hassEntities = haEntites.collection.state;
return (
- {/*
*/}
+ {isSaving &&
}
+
{
+ setIsSaving(true);
+ await api.updateTags({
+ automation_id: aid,
+ tags: t,
+ });
+ setIsSaving(false);
+ }}
+ />
);
};
diff --git a/webapp/src/devUtils/example.stories.tsx b/webapp/src/devUtils/example.stories.tsx
new file mode 100644
index 0000000..dda96e5
--- /dev/null
+++ b/webapp/src/devUtils/example.stories.tsx
@@ -0,0 +1,11 @@
+import { makeStory } from "devUtils";
+
+const { make, componentMeta } = makeStory({
+ Component: () => Example
,
+ meta: {
+ title: "DevUtil",
+ },
+});
+
+export default componentMeta;
+export const Example = make({});
diff --git a/webapp/src/devUtils/index.tsx b/webapp/src/devUtils/index.tsx
new file mode 100644
index 0000000..9bcb442
--- /dev/null
+++ b/webapp/src/devUtils/index.tsx
@@ -0,0 +1,47 @@
+import "styles/root.css";
+import { ComponentMeta, ComponentStory } from "@storybook/react";
+import { Page } from "components/Page";
+import { ComponentProps, JSXElementConstructor } from "react";
+
+export type MakeStoryArgs<
+ T extends keyof JSX.IntrinsicElements | JSXElementConstructor
+> = {
+ Component: T;
+ BaseTemplate?: ComponentStory;
+ meta: Partial> & { title: string };
+};
+export const makeStory = <
+ T extends keyof JSX.IntrinsicElements | JSXElementConstructor
+>({
+ BaseTemplate,
+ Component,
+ meta,
+}: MakeStoryArgs) => {
+ const componentMeta: ComponentMeta = {
+ component: Component as any,
+ parameters: { actions: { argTypesRegex: "^on.*" } },
+ args: {},
+ ...meta,
+ };
+ const Template: ComponentStory = (args) => {
+ return (
+
+ {BaseTemplate ? : }
+
+ );
+ };
+
+ const make = (args: Partial>) => {
+ const Basic = Template.bind({});
+ Basic.args = {
+ ...Basic.args,
+ ...args,
+ };
+ return Basic;
+ };
+
+ return {
+ make,
+ componentMeta,
+ };
+};