automation list box finidhed
This commit is contained in:
1 parent
afc67a17ec
commit
7ea923a050
5 files changed
+91
-9
No files matched your search
@@ -5,18 +5,24 @@
|
||||
}
|
||||
|
||||
.automation-list-box--body {
|
||||
overflow: scroll;
|
||||
overflow: auto;
|
||||
height: 100%;
|
||||
flex: 1;
|
||||
user-select: none;
|
||||
}
|
||||
.automation-list-box--body > * {
|
||||
padding-top: 0.5em;
|
||||
padding-bottom: 0.5em;
|
||||
}
|
||||
.automation-list-box--body--group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-left: 1em;
|
||||
border-radius: 10px;
|
||||
padding-bottom: 0.5em;
|
||||
border-width: 1px;
|
||||
border-bottom-style: solid ;
|
||||
border-color: white;
|
||||
user-select: none;
|
||||
}
|
||||
.automation-list-box--body--group > .automation-list-box--body--group {
|
||||
border-left-style: solid ;
|
||||
@@ -26,23 +32,67 @@
|
||||
}
|
||||
|
||||
.automation-list-box--body--group > b {
|
||||
width: 100%;
|
||||
cursor: pointer;
|
||||
padding: 0.1em;
|
||||
}
|
||||
.automation-list-box--body--group > b:hover {
|
||||
background-color: var(--secondary-accent);
|
||||
color: var(--secondary);
|
||||
}
|
||||
|
||||
.automation-list-box--body--item:hover {
|
||||
background-color: var(--primary-accent);
|
||||
color: var(--primary);
|
||||
}
|
||||
.automation-list-box--body--item:hover > .automation-list-box--body--item--tags > span {
|
||||
border-color: var(--primary);
|
||||
}
|
||||
.automation-list-box--body--item {
|
||||
padding-left: 1em;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: flex-start;
|
||||
gap: 1em;
|
||||
/* position: relative; */
|
||||
}
|
||||
.automation-list-box--body--item::before {
|
||||
content: "⊚ ";
|
||||
}
|
||||
.automation-list-box--body--item--title {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-left: 0.25em;
|
||||
}
|
||||
.automation-list-box--body--item--title > b {
|
||||
font-size: 1em;
|
||||
}
|
||||
.automation-list-box--body--item--title > span, .automation-list-box--body--item--title > b > span {
|
||||
font-size: 0.75em;
|
||||
}
|
||||
.automation-list-box--body--item > button {
|
||||
padding: 0.25em !important;
|
||||
margin: 0.5em !important;
|
||||
}
|
||||
.automation-list-box--body--item--tags {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
font-size: 0.75em;
|
||||
justify-content: left;
|
||||
align-items: flex-start;
|
||||
overflow: auto;
|
||||
max-height: 100%;
|
||||
gap: 0.25em;
|
||||
}
|
||||
.automation-list-box--body--item--tags > span {
|
||||
border-color: var(--primary-accent);
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
border-radius: 0.5em;
|
||||
padding: 0.1em 0.5em;
|
||||
}
|
||||
.automation-list-box--bottom {
|
||||
margin-top: 0.5em;
|
||||
margin-bottom: 0.5em;
|
||||
@@ -52,5 +102,7 @@
|
||||
align-items: center;
|
||||
}
|
||||
.automation-list-box--bottom > button {
|
||||
background-color: #070;
|
||||
color: var(--primary-accent);
|
||||
padding: 0.5em 2em;
|
||||
}
|
||||
@@ -31,7 +31,7 @@ export const FewAutos = Template.bind({})
|
||||
FewAutos.args = {
|
||||
...FewAutos.args,
|
||||
automations: [
|
||||
createMockAuto({ "Room": "Bathroom", "Type": "Lights" }),
|
||||
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" }),
|
||||
|
||||
@@ -4,18 +4,21 @@ import { AutomationData } from "types/automations";
|
||||
import InputMultiSelect from "components/Inputs/InputMultiSelect";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { TrashIcon } from "components/Icons";
|
||||
|
||||
|
||||
export type Props = {
|
||||
automations: AutomationData[];
|
||||
onSelectAutomation: (i: number) => void;
|
||||
onAdd: () => void;
|
||||
onRemove: () => void;
|
||||
}
|
||||
|
||||
export const AutomationListBox: FC<Props> = ({
|
||||
automations,
|
||||
onSelectAutomation,
|
||||
onAdd,
|
||||
onRemove,
|
||||
}) => {
|
||||
|
||||
const tags = getTagList(automations);
|
||||
@@ -39,7 +42,7 @@ export const AutomationListBox: FC<Props> = ({
|
||||
/>
|
||||
</div>
|
||||
<div className="automation-list-box--body">
|
||||
{convertGroupsToItems(groups, filteredAutomations, onSelectAutomation)}
|
||||
{convertGroupsToItems(groups, filteredAutomations, onSelectAutomation, onRemove)}
|
||||
</div>
|
||||
<div className="automation-list-box--bottom">
|
||||
<Button onClick={onAdd}>Add</Button>
|
||||
@@ -118,11 +121,34 @@ const convertGroupsToItems = (
|
||||
groups: any,
|
||||
autos: Array<[AutomationData, number]>,
|
||||
onSelectAutomation: (i: number) => void,
|
||||
onRemove: (i: number) => void,
|
||||
) => {
|
||||
if (Array.isArray(groups)) {
|
||||
return groups.map(i => <div key={i} className="automation-list-box--body--item" onClick={() => onSelectAutomation(autos[i][1])}>
|
||||
{autos[i][0].metadata.id} {autos[i][0].metadata.alias}
|
||||
</div>)
|
||||
return groups.map(i => {
|
||||
const [auto, autoIndex] = autos[i];
|
||||
return <div
|
||||
key={i}
|
||||
className="automation-list-box--body--item"
|
||||
title={`${auto.metadata.alias}\n ID=${auto.metadata.id}\n${auto.metadata.description}`}
|
||||
>
|
||||
<div
|
||||
className="automation-list-box--body--item--title"
|
||||
onClick={() => onSelectAutomation(autoIndex)}
|
||||
>
|
||||
<b>{auto.metadata.alias.slice(0, 15)} <span>({auto.metadata.id.slice(0, 5)})</span></b>
|
||||
<span>{auto.metadata.description.slice(0, 25)}</span>
|
||||
</div>
|
||||
<div
|
||||
className="automation-list-box--body--item--tags"
|
||||
onClick={() => onSelectAutomation(autoIndex)}
|
||||
>
|
||||
{Object.keys(auto.metadata.tags).map(tagName => <span key={tagName}>
|
||||
<b>{tagName}:</b> {auto.metadata.tags[tagName]}
|
||||
</span>)}
|
||||
</div>
|
||||
<Button onClick={() => onRemove(autoIndex)}><TrashIcon /></Button>
|
||||
</div>
|
||||
})
|
||||
} else {
|
||||
return Object.keys(groups).map(groupName => {
|
||||
return <AutomationListBoxGroup
|
||||
@@ -131,6 +157,7 @@ const convertGroupsToItems = (
|
||||
groups={groups[groupName]}
|
||||
autos={autos}
|
||||
onSelectAutomation={onSelectAutomation}
|
||||
onRemove={onRemove}
|
||||
/>
|
||||
})
|
||||
}
|
||||
@@ -142,15 +169,17 @@ const AutomationListBoxGroup: FC<{
|
||||
groups: any,
|
||||
autos: Array<[AutomationData, number]>,
|
||||
onSelectAutomation: (i: number) => void,
|
||||
onRemove: (i: number) => void;
|
||||
}> = ({
|
||||
groupName,
|
||||
groups,
|
||||
autos,
|
||||
onSelectAutomation,
|
||||
onRemove,
|
||||
}) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
return <div className="automation-list-box--body--group">
|
||||
<b onClick={() => setOpen(!open)}>{groupName} {!open ? "⊕" : "⊖"}</b>
|
||||
{open && convertGroupsToItems(groups, autos, onSelectAutomation)}
|
||||
{open && convertGroupsToItems(groups, autos, onSelectAutomation, onRemove)}
|
||||
</div>
|
||||
}
|
||||
@@ -171,6 +171,7 @@ export const useInputMultiSelectStyles = createAppUseStyles<{
|
||||
userSelect: 'none',
|
||||
overflow: 'hidden',
|
||||
width: "100%",
|
||||
zIndex: 10,
|
||||
})),
|
||||
arrow: (({ open }) => ({
|
||||
position: 'absolute',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { AutomationData } from 'types/automations';
|
||||
|
||||
export const createMockAuto = (tags: Record<string, string> = {}): AutomationData => ({
|
||||
metadata: {
|
||||
id: Math.random().toString(36).slice(2, 5),
|
||||
id: Math.random().toString(36).slice(2, 15),
|
||||
alias: "Random",
|
||||
description: "Example Metadata",
|
||||
trigger_variables: {
|
||||
|
||||
Reference in new issue
Block a user