upping limits of display
This commit is contained in:
1 parent
e769a8e798
commit
6b465219a9
6 files changed
+243
-156
No files matched your search
@@ -1,42 +1,40 @@
|
||||
import { useState } from "react";
|
||||
import { ApiState } from "./types";
|
||||
import { AutomationAPI } from './automations';
|
||||
import { AutomationAPI } from "./automations";
|
||||
|
||||
|
||||
|
||||
export const useDefaultApiState = () => useState<ApiState>({
|
||||
automations: { ready: false },
|
||||
});
|
||||
export const useDefaultApiState = () =>
|
||||
useState<ApiState>({
|
||||
automations: { ready: false },
|
||||
});
|
||||
|
||||
export const makeReloadAutomations = (
|
||||
automationAPI: AutomationAPI,
|
||||
state: ApiState,
|
||||
setState: (s: ApiState) => void,
|
||||
setState: (s: ApiState) => void
|
||||
) => {
|
||||
const reload = async () => {
|
||||
let params = { offset: 0, limit: 100 };
|
||||
let params = { offset: 0, limit: 10000 };
|
||||
if (state.automations.ready && state.automations.ok) {
|
||||
params = state.automations.data.params
|
||||
params = state.automations.data.params;
|
||||
}
|
||||
const resp = await automationAPI.list(params);
|
||||
setState({
|
||||
...state, automations: {
|
||||
...state,
|
||||
automations: {
|
||||
ready: true,
|
||||
...resp,
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
const wrapCall = <
|
||||
Call extends (a: any) => Promise<any>
|
||||
>(fcn: Call) => {
|
||||
};
|
||||
const wrapCall = <Call extends (a: any) => Promise<any>>(fcn: Call) => {
|
||||
return async (args: Parameters<Call>[0]): Promise<ReturnType<Call>> => {
|
||||
const resp = await fcn(args);
|
||||
await reload();
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
return {
|
||||
reload,
|
||||
wrapCall,
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -5,6 +5,7 @@ import { AutomationList } from ".";
|
||||
import { bigMockAutoList } from "utils/mocks";
|
||||
import { Page } from "components/Page";
|
||||
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
||||
import { AutomationData } from "types/automations";
|
||||
|
||||
export default {
|
||||
title: "App/AutomationList",
|
||||
@@ -16,12 +17,15 @@ export default {
|
||||
} as ComponentMeta<typeof AutomationList>;
|
||||
|
||||
const Template: ComponentStory<typeof AutomationList> = (args) => {
|
||||
const [autos, setAutos] = useState(args.automations);
|
||||
const [autos, setAutos] = useState(args.automations.data);
|
||||
return (
|
||||
<Page>
|
||||
<AutomationList
|
||||
{...args}
|
||||
automations={autos}
|
||||
automations={{
|
||||
...args.automations,
|
||||
data: autos,
|
||||
}}
|
||||
onAdd={(a) => {
|
||||
args.onAdd(a);
|
||||
setAutos([...autos, a]);
|
||||
@@ -39,107 +43,115 @@ const Template: ComponentStory<typeof AutomationList> = (args) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const EmptyStart = Template.bind({});
|
||||
EmptyStart.args = {
|
||||
...EmptyStart.args,
|
||||
automations: [],
|
||||
const make = (autos: AutomationData[]) => {
|
||||
const NewTemp = Template.bind({});
|
||||
NewTemp.args = {
|
||||
...NewTemp.args,
|
||||
automations: {
|
||||
data: autos,
|
||||
params: {
|
||||
offset: 0,
|
||||
limit: 100,
|
||||
},
|
||||
totalItems: autos.length,
|
||||
},
|
||||
};
|
||||
|
||||
return NewTemp;
|
||||
};
|
||||
|
||||
export const FewAutos = Template.bind({});
|
||||
FewAutos.args = {
|
||||
...FewAutos.args,
|
||||
automations: bigMockAutoList,
|
||||
};
|
||||
export const EmptyStart = make([]);
|
||||
|
||||
export const BadAutmations = Template.bind({});
|
||||
BadAutmations.args = {
|
||||
...BadAutmations.args,
|
||||
automations: [
|
||||
{
|
||||
metadata: {
|
||||
alias: "Set Thermostat to 76 at 8am",
|
||||
description: "",
|
||||
mode: "single",
|
||||
} as any,
|
||||
trigger: [
|
||||
{
|
||||
at: "08:00:00",
|
||||
platform: "time",
|
||||
export const FewAutos = make(bigMockAutoList);
|
||||
|
||||
export const BadAutmations = make([
|
||||
{
|
||||
metadata: {
|
||||
alias: "Set Thermostat to 76 at 8am",
|
||||
description: "",
|
||||
mode: "single",
|
||||
} as any,
|
||||
trigger: [
|
||||
{
|
||||
at: "08:00:00",
|
||||
platform: "time",
|
||||
},
|
||||
],
|
||||
condition: [
|
||||
{
|
||||
condition: "state",
|
||||
entity_id: "climate.thermostat",
|
||||
state: "cool",
|
||||
},
|
||||
],
|
||||
sequence: [
|
||||
{
|
||||
data: {
|
||||
temperature: 76,
|
||||
},
|
||||
],
|
||||
condition: [
|
||||
{
|
||||
condition: "state",
|
||||
service: "climate.set_temperature",
|
||||
target: {
|
||||
entity_id: "climate.thermostat",
|
||||
state: "cool",
|
||||
},
|
||||
],
|
||||
sequence: [
|
||||
{
|
||||
data: {
|
||||
temperature: 76,
|
||||
},
|
||||
service: "climate.set_temperature",
|
||||
target: {
|
||||
entity_id: "climate.thermostat",
|
||||
},
|
||||
},
|
||||
],
|
||||
tags: {},
|
||||
},
|
||||
{
|
||||
condition: [],
|
||||
tags: {},
|
||||
metadata: {
|
||||
id: "Bad Choose Sequence",
|
||||
alias: "Bad Choose",
|
||||
description: "Example Metadata",
|
||||
trigger_variables: {
|
||||
wowo: "!",
|
||||
},
|
||||
mode: "single",
|
||||
},
|
||||
trigger: [],
|
||||
sequence: [
|
||||
{
|
||||
choose: {},
|
||||
},
|
||||
] as any,
|
||||
},
|
||||
{
|
||||
condition: [],
|
||||
tags: {},
|
||||
metadata: {
|
||||
id: "random",
|
||||
alias: "Bad Trigger",
|
||||
description: "Example Metadata",
|
||||
trigger_variables: {
|
||||
wowo: "!",
|
||||
},
|
||||
mode: "single",
|
||||
],
|
||||
tags: {},
|
||||
},
|
||||
{
|
||||
condition: [],
|
||||
tags: {},
|
||||
metadata: {
|
||||
id: "Bad Choose Sequence",
|
||||
alias: "Bad Choose",
|
||||
description: "Example Metadata",
|
||||
trigger_variables: {
|
||||
wowo: "!",
|
||||
},
|
||||
trigger: ["haha I am a string"] as any,
|
||||
sequence: [],
|
||||
mode: "single",
|
||||
},
|
||||
{
|
||||
condition: [],
|
||||
tags: {},
|
||||
metadata: {} as any,
|
||||
trigger: [],
|
||||
sequence: [],
|
||||
trigger: [],
|
||||
sequence: [
|
||||
{
|
||||
choose: {},
|
||||
},
|
||||
] as any,
|
||||
},
|
||||
{
|
||||
condition: [],
|
||||
tags: {},
|
||||
metadata: {
|
||||
id: "random",
|
||||
alias: "Bad Trigger",
|
||||
description: "Example Metadata",
|
||||
trigger_variables: {
|
||||
wowo: "!",
|
||||
},
|
||||
mode: "single",
|
||||
},
|
||||
],
|
||||
};
|
||||
trigger: ["haha I am a string"] as any,
|
||||
sequence: [],
|
||||
},
|
||||
{
|
||||
condition: [],
|
||||
tags: {},
|
||||
metadata: {} as any,
|
||||
trigger: [],
|
||||
sequence: [],
|
||||
},
|
||||
]);
|
||||
|
||||
export const FewAutosWithSlowLoader: ComponentStory<typeof AutomationList> = (
|
||||
args
|
||||
) => {
|
||||
const [autos, setAutos] = useState(args.automations);
|
||||
const [autos, setAutos] = useState(args.automations.data);
|
||||
return (
|
||||
<Page>
|
||||
<AutomationList
|
||||
{...args}
|
||||
automations={autos}
|
||||
automations={{
|
||||
...args.automations,
|
||||
data: autos,
|
||||
}}
|
||||
onAdd={(a) => {
|
||||
window.setTimeout(() => {
|
||||
args.onAdd(a);
|
||||
@@ -164,5 +176,12 @@ export const FewAutosWithSlowLoader: ComponentStory<typeof AutomationList> = (
|
||||
};
|
||||
FewAutosWithSlowLoader.args = {
|
||||
...FewAutosWithSlowLoader.args,
|
||||
automations: bigMockAutoList,
|
||||
automations: {
|
||||
data: bigMockAutoList,
|
||||
params: {
|
||||
limit: 100,
|
||||
offset: 0,
|
||||
},
|
||||
totalItems: 100,
|
||||
},
|
||||
};
|
||||
@@ -65,8 +65,20 @@
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.automation-list-box--bottom>button {
|
||||
background-color: #070;
|
||||
color: var(--mui-grey-400);
|
||||
.automation-list-box--bottom>.automation-list-box--bottom--add {
|
||||
background-color: var(--mui-primary-main);
|
||||
color: var(--mui-primary-contrastText);
|
||||
padding: 0.5em 2em;
|
||||
}
|
||||
|
||||
.automation-list-box--bottom>.automation-list-box--bottom--add:hover {
|
||||
color: var(--mui-primary-light);
|
||||
}
|
||||
|
||||
.automation-list-box--bottom--load svg {
|
||||
color: var(--mui-primary-main);
|
||||
}
|
||||
|
||||
.automation-list-box--bottom--load.less svg {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { createMockAuto } from "utils/mocks";
|
||||
import { Page } from "components/Page";
|
||||
import { CookiesProvider } from "react-cookie";
|
||||
import { makeTagDB } from "./TagDB";
|
||||
import { AutomationData } from "types/automations";
|
||||
|
||||
export default {
|
||||
title: "App/AutomationList/Box",
|
||||
@@ -20,7 +21,7 @@ const Template: ComponentStory<typeof AutomationListBox> = (args) => {
|
||||
<CookiesProvider>
|
||||
<AutomationListBox
|
||||
{...args}
|
||||
tagsDB={makeTagDB(args.automations)}
|
||||
tagsDB={makeTagDB(args.automations.data)}
|
||||
automations={args.automations}
|
||||
selected={selected}
|
||||
onSelectAutomation={(i) => {
|
||||
@@ -33,41 +34,46 @@ const Template: ComponentStory<typeof AutomationListBox> = (args) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const EmptyStart = Template.bind({});
|
||||
EmptyStart.args = {
|
||||
...EmptyStart.args,
|
||||
automations: [],
|
||||
const make = (autos: AutomationData[]) => {
|
||||
const NewTemp = Template.bind({});
|
||||
NewTemp.args = {
|
||||
...NewTemp.args,
|
||||
automations: {
|
||||
data: autos,
|
||||
params: {
|
||||
offset: 0,
|
||||
limit: 100,
|
||||
},
|
||||
totalItems: autos.length,
|
||||
},
|
||||
};
|
||||
|
||||
return NewTemp;
|
||||
};
|
||||
|
||||
export const FewAutos = Template.bind({});
|
||||
FewAutos.args = {
|
||||
...FewAutos.args,
|
||||
automations: [
|
||||
createMockAuto({
|
||||
Room: "Bathroom",
|
||||
Type: "Lights",
|
||||
NewDevice: "Yes",
|
||||
Remote: "No",
|
||||
Floor: "1",
|
||||
}),
|
||||
createMockAuto({ Room: "Bathroom", Type: "Climate" }),
|
||||
createMockAuto({ Room: "Living Room", Type: "Climate" }),
|
||||
createMockAuto({ Type: "Climate" }),
|
||||
createMockAuto({ Type: "Lights", Routine: "Myself" }),
|
||||
createMockAuto({ Routine: "DNS", Type: "SSL" }),
|
||||
createMockAuto({ Room: "Bedroom", Type: "Lights", Routine: "Baby" }),
|
||||
createMockAuto({ Room: "Office", Type: "Lights" }),
|
||||
createMockAuto({ Room: "Office" }),
|
||||
createMockAuto(),
|
||||
],
|
||||
};
|
||||
export const EmptyStart = make([]);
|
||||
|
||||
export const OneAuto = Template.bind({});
|
||||
OneAuto.args = {
|
||||
...OneAuto.args,
|
||||
automations: [
|
||||
createMockAuto({
|
||||
Type: "Climate",
|
||||
}),
|
||||
],
|
||||
};
|
||||
export const FewAutos = make([
|
||||
createMockAuto({
|
||||
Room: "Bathroom",
|
||||
Type: "Lights",
|
||||
NewDevice: "Yes",
|
||||
Remote: "No",
|
||||
Floor: "1",
|
||||
}),
|
||||
createMockAuto({ Room: "Bathroom", Type: "Climate" }),
|
||||
createMockAuto({ Room: "Living Room", Type: "Climate" }),
|
||||
createMockAuto({ Type: "Climate" }),
|
||||
createMockAuto({ Type: "Lights", Routine: "Myself" }),
|
||||
createMockAuto({ Routine: "DNS", Type: "SSL" }),
|
||||
createMockAuto({ Room: "Bedroom", Type: "Lights", Routine: "Baby" }),
|
||||
createMockAuto({ Room: "Office", Type: "Lights" }),
|
||||
createMockAuto({ Room: "Office" }),
|
||||
createMockAuto(),
|
||||
]);
|
||||
|
||||
export const OneAuto = make([
|
||||
createMockAuto({
|
||||
Type: "Climate",
|
||||
}),
|
||||
]);
|
||||
@@ -8,14 +8,20 @@ import { makeGrouping } from "./automationGrouper";
|
||||
import { AutomationListBoxGroup } from "./AutomationListBoxGroup";
|
||||
import { useCookies } from "react-cookie";
|
||||
import { TagDB } from "components/AutomationList/TagDB";
|
||||
// import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
// import ReadMoreOutlinedIcon from "@mui/icons-material/ReadMoreOutlined";
|
||||
import { ListData, ListParams } from "apiService/types";
|
||||
import Chip from "@mui/material/Chip";
|
||||
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
|
||||
|
||||
export type AutomationListBoxProps = {
|
||||
automations: AutomationData[];
|
||||
automations: ListData<AutomationData>;
|
||||
selected: number;
|
||||
onSelectAutomation: (i: number) => void;
|
||||
onRemove: (i: number) => void;
|
||||
onAdd: () => void;
|
||||
onUpdate: (a: AutomationData, i: number) => void;
|
||||
onLoadMore: (p: ListParams) => void;
|
||||
tagsDB: TagDB;
|
||||
};
|
||||
|
||||
@@ -54,11 +60,16 @@ const useAutomationListBoxState = () => {
|
||||
};
|
||||
|
||||
export const AutomationListBox: FC<AutomationListBoxProps> = ({
|
||||
automations,
|
||||
automations: {
|
||||
data: automations,
|
||||
params: autoParams,
|
||||
totalItems: totalAutomations,
|
||||
},
|
||||
selected,
|
||||
onSelectAutomation,
|
||||
onAdd,
|
||||
onRemove,
|
||||
onLoadMore,
|
||||
tagsDB,
|
||||
onUpdate,
|
||||
}) => {
|
||||
@@ -101,11 +112,44 @@ export const AutomationListBox: FC<AutomationListBoxProps> = ({
|
||||
/>
|
||||
</div>
|
||||
<div className="automation-list-box--bottom">
|
||||
<Button onClick={onAdd}>Add</Button>
|
||||
<span>
|
||||
Showing Automations: {filteredAutomations.length} out of{" "}
|
||||
{automations.length}
|
||||
</span>
|
||||
<Button className="automation-list-box--bottom--add" onClick={onAdd}>
|
||||
Add
|
||||
</Button>
|
||||
{automations.length < totalAutomations ? (
|
||||
<>
|
||||
<Chip
|
||||
label={`Only loaded ${automations.length} out of ${totalAutomations}`}
|
||||
variant="outlined"
|
||||
color="warning"
|
||||
icon={<InfoOutlinedIcon />}
|
||||
onClick={() =>
|
||||
window.open(
|
||||
"https://github.com/asosnovsky/Shortumation/issues/78",
|
||||
"_blank"
|
||||
)
|
||||
}
|
||||
/>
|
||||
<small>support for more is not yet implemented</small>
|
||||
</>
|
||||
) : (
|
||||
""
|
||||
)}
|
||||
{/* {autoParams.offset > 0 && (
|
||||
<ButtonIcon
|
||||
borderless
|
||||
className="automation-list-box--bottom--load less"
|
||||
icon={<ReadMoreOutlinedIcon />}
|
||||
onClick={() => onLoadMore()}
|
||||
/>
|
||||
)} */}
|
||||
{/* {filteredAutomations.length} out of {totalAutomations} */}
|
||||
{/* {autoParams.offset + automations.length < totalAutomations && (
|
||||
<ButtonIcon
|
||||
borderless
|
||||
className="automation-list-box--bottom--load more"
|
||||
icon={<ReadMoreOutlinedIcon />}
|
||||
/>
|
||||
)} */}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -16,12 +16,14 @@ import { useHA } from "haService";
|
||||
import { ArrowBack } from "@mui/icons-material";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { DAGDims } from "components/DAGGraph/elements/types";
|
||||
import { ListData, ListParams } from "apiService/types";
|
||||
|
||||
interface AutomationListParams {
|
||||
automations: AutomationData[];
|
||||
automations: ListData<AutomationData>;
|
||||
onUpdate: (i: number, auto: AutomationData) => void;
|
||||
onAdd: (auto: AutomationData) => void;
|
||||
onRemove: (i: number) => void;
|
||||
onLoadMore: (p: ListParams) => void;
|
||||
dims: DAGDims;
|
||||
children?: ReactNode;
|
||||
}
|
||||
@@ -54,6 +56,7 @@ export const useAutomationListState = () => {
|
||||
|
||||
export const AutomationList: FC<AutomationListParams> = ({
|
||||
automations,
|
||||
onLoadMore,
|
||||
onUpdate,
|
||||
onAdd,
|
||||
onRemove,
|
||||
@@ -67,8 +70,11 @@ export const AutomationList: FC<AutomationListParams> = ({
|
||||
const { isMobile } = useWindowSize();
|
||||
const firstRender = useRef(true);
|
||||
// alias
|
||||
const currentAuto = automations.length > 0 ? automations[current] : null;
|
||||
const tagDB = makeTagDB(automations);
|
||||
const currentAuto =
|
||||
automations.data.length > 0
|
||||
? automations.data[current - automations.params.offset]
|
||||
: null;
|
||||
const tagDB = makeTagDB(automations.data);
|
||||
// effect
|
||||
useEffect(() => {
|
||||
if (firstRender.current) {
|
||||
@@ -92,7 +98,7 @@ export const AutomationList: FC<AutomationListParams> = ({
|
||||
onUpdate={(a, i) => onUpdate(i, a)}
|
||||
onAdd={() => {
|
||||
onAdd(defaultAutomation(String(Date.now())));
|
||||
setCurrent(automations.length);
|
||||
setCurrent(automations.data.length);
|
||||
if (isMobile) {
|
||||
setHideList(true);
|
||||
}
|
||||
@@ -103,6 +109,7 @@ export const AutomationList: FC<AutomationListParams> = ({
|
||||
setHideList(true);
|
||||
}
|
||||
}}
|
||||
onLoadMore={onLoadMore}
|
||||
selected={current}
|
||||
onRemove={onRemove}
|
||||
tagsDB={tagDB}
|
||||
@@ -171,7 +178,8 @@ export const ConnectedAutomationList: FC<ConnectedAutomationListParams> = ({
|
||||
return (
|
||||
<AutomationList
|
||||
dims={dims}
|
||||
automations={automations.data.data}
|
||||
automations={automations.data}
|
||||
onLoadMore={() => {}}
|
||||
onAdd={(auto) =>
|
||||
updateAutomation({ auto, index: automations.data.totalItems + 1 })
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user