latest work
This commit is contained in:
1 parent
acb12e73e8
commit
b368be0ff4
8 files changed
+228
-25
No files matched your search
Vendored
+39
-12
@@ -2,7 +2,25 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug CRA Tests",
|
||||
"name": "Debug Tests Single Run",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"env": {
|
||||
"CI": "true"
|
||||
},
|
||||
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
|
||||
"args": [
|
||||
"test",
|
||||
"--runInBand",
|
||||
"--no-cache"
|
||||
],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen"
|
||||
},
|
||||
{
|
||||
"name": "Debug tests watch mode",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
|
||||
@@ -10,20 +28,29 @@
|
||||
"test",
|
||||
"--runInBand",
|
||||
"--no-cache",
|
||||
"--watchAll=false"
|
||||
"--watchAll"
|
||||
],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen",
|
||||
"env": {
|
||||
"CI": "true"
|
||||
},
|
||||
"disableOptimisticBPs": true,
|
||||
"jasmineExplorer.nodeArgv": [
|
||||
"-r",
|
||||
"ts-node/register"
|
||||
]
|
||||
"internalConsoleOptions": "neverOpen"
|
||||
},
|
||||
{
|
||||
"name": "Debug tests opened file",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
|
||||
"args": [
|
||||
"test",
|
||||
"${fileBasenameNoExtension}",
|
||||
"--runInBand",
|
||||
"--no-cache",
|
||||
"--watchAll"
|
||||
],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -70,5 +70,9 @@
|
||||
"@types/chroma-js": "^2.1.3",
|
||||
"@types/js-yaml": "^4.0.5",
|
||||
"ts-node": "^10.4.0"
|
||||
}
|
||||
},
|
||||
"moduleDirectories": [
|
||||
"node_modules",
|
||||
"src"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
.automation-list-box {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { groupAutomations } from './AutomationListBox';
|
||||
import { AutomationData } from 'types/automations/index';
|
||||
|
||||
test('converting time to a string', () => {
|
||||
const automations: AutomationData[] = [
|
||||
{
|
||||
metadata: {
|
||||
id: '1',
|
||||
alias: '',
|
||||
description: '',
|
||||
mode: 'single',
|
||||
tags: {
|
||||
"Room": 'Living Room',
|
||||
"Type": 'Lights'
|
||||
}
|
||||
},
|
||||
sequence: [],
|
||||
trigger: [],
|
||||
},
|
||||
{
|
||||
metadata: {
|
||||
id: '2',
|
||||
alias: '',
|
||||
description: '',
|
||||
mode: 'single',
|
||||
tags: {
|
||||
"Room": 'Living Room',
|
||||
"Type": 'Climate'
|
||||
}
|
||||
},
|
||||
sequence: [],
|
||||
trigger: [],
|
||||
},
|
||||
{
|
||||
metadata: {
|
||||
id: '3',
|
||||
alias: '',
|
||||
description: '',
|
||||
mode: 'single',
|
||||
tags: {
|
||||
"Room": 'Kitchen',
|
||||
"Type": 'Climate'
|
||||
}
|
||||
},
|
||||
sequence: [],
|
||||
trigger: [],
|
||||
},
|
||||
];
|
||||
expect(groupAutomations(automations, [0, 1], ['Room', "Type"])).toBe({
|
||||
"Living Room": {
|
||||
"Lights": ["1"],
|
||||
"Climate": ["2"],
|
||||
},
|
||||
"Kitchen": {
|
||||
"Climate": ["3"],
|
||||
}
|
||||
})
|
||||
expect(groupAutomations(automations, [1, 0], ['Room', "Type"])).toBe({
|
||||
"Lights": {
|
||||
"Living Room": ['1'],
|
||||
},
|
||||
"Climate": {
|
||||
"Living Room": ['2'],
|
||||
"Kitchen": ['3']
|
||||
}
|
||||
})
|
||||
expect(groupAutomations(automations, [1], ['Room', "Type"])).toBe({
|
||||
"Lights": ['1'],
|
||||
"Climate": ['2', '3']
|
||||
})
|
||||
expect(groupAutomations(automations, [0], ['Room', "Type"])).toBe({
|
||||
"Living Room": ['1', '2'],
|
||||
"Kitchen": ['3']
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,93 @@
|
||||
import "./AutomationListBox.css";
|
||||
import { FC, useState } from 'react';
|
||||
import { AutomationData } from "types/automations";
|
||||
import InputMultiSelect from "components/Inputs/InputMultiSelect";
|
||||
import InputText from "components/Inputs/InputText";
|
||||
|
||||
|
||||
export type Props = {
|
||||
automations: AutomationData[];
|
||||
}
|
||||
|
||||
export const AutomationListBox: FC<Props> = ({
|
||||
automations
|
||||
}) => {
|
||||
|
||||
const tags = getTagList(automations);
|
||||
const [searchText, setSearchText] = useState('');
|
||||
const [selected, setSelected] = useState<number[]>([]);
|
||||
const filteredAutomations = filterAutomations(automations, searchText, selected, tags);
|
||||
|
||||
|
||||
return <div className="automation-list-box">
|
||||
<div className="automation-list-box--nav">
|
||||
<InputText
|
||||
label="Search"
|
||||
value={searchText}
|
||||
onChange={setSearchText}
|
||||
/>
|
||||
<InputMultiSelect
|
||||
label="Tags"
|
||||
selected={selected}
|
||||
onChange={setSelected}
|
||||
options={tags}
|
||||
/>
|
||||
</div>
|
||||
<div className="automation-list-box--body">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
const getTagList = (autos: AutomationData[]): string[] => autos
|
||||
.map(a => Object.keys(a.metadata.tags))
|
||||
.reduce((all, keys) => all.concat(keys))
|
||||
|
||||
const filterAutomations = (autos: AutomationData[], searchText: string, selected: number[], tags: string[]) => autos.filter(a => {
|
||||
if (searchText.length > 0) {
|
||||
if (
|
||||
!(
|
||||
a.metadata.description.toLocaleLowerCase().includes(searchText) ||
|
||||
a.metadata.alias.toLocaleLowerCase().includes(searchText)
|
||||
)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if (selected.length > 0) {
|
||||
for (const i of selected) {
|
||||
if (!a.metadata.tags[tags[i]]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
export type GroupedAutos = Record<string, GroupedAutos | string[]>;
|
||||
export const groupAutomations = (autos: AutomationData[], selected: number[], tags: string[]) => {
|
||||
const out: GroupedAutos = {};
|
||||
for (const a of autos) {
|
||||
let where = out;
|
||||
let tag: string = '';
|
||||
let lastKey: string | null = null;
|
||||
for (const i of selected) {
|
||||
tag = tags[i];
|
||||
if (lastKey !== null) {
|
||||
where = where[lastKey]
|
||||
}
|
||||
if (!where[a.metadata.tags[tag]]) {
|
||||
where[a.metadata.tags[tag]] = {}
|
||||
}
|
||||
lastKey = a.metadata.tags[tag]
|
||||
}
|
||||
if (tag) {
|
||||
if (!where[a.metadata.tags[tag]]) {
|
||||
where[a.metadata.tags[tag]] = []
|
||||
}
|
||||
where[a.metadata.tags[tag]].push(a.metadata.id)
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
File renamed without changes.
@@ -1,4 +1,4 @@
|
||||
import "./styles.css";
|
||||
import "./index.css";
|
||||
import { AutomationEditor } from "components/AutomationEditor";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import { FC, useState } from "react";
|
||||
|
||||
@@ -4,22 +4,23 @@ import { AutomationTrigger, TriggerType } from "./triggers";
|
||||
|
||||
|
||||
export interface AutomationMetadata {
|
||||
id: string;
|
||||
alias: string;
|
||||
description: string;
|
||||
trigger_variables?: Record<string, string>;
|
||||
mode: "single" | "restart" | "queued" | "parallel";
|
||||
id: string;
|
||||
alias: string;
|
||||
description: string;
|
||||
trigger_variables?: Record<string, string>;
|
||||
mode: "single" | "restart" | "queued" | "parallel";
|
||||
tags: Record<string, string>;
|
||||
}
|
||||
export interface AutomationData {
|
||||
metadata: AutomationMetadata;
|
||||
trigger: AutomationTrigger[];
|
||||
sequence: AutomationSequenceNode[];
|
||||
metadata: AutomationMetadata;
|
||||
trigger: AutomationTrigger[];
|
||||
sequence: AutomationSequenceNode[];
|
||||
}
|
||||
export type AutomationSequenceNode = AutomationAction | AutomationCondition;
|
||||
export type AutomationNodeMapping = {
|
||||
"trigger": AutomationTrigger;
|
||||
"action": AutomationAction;
|
||||
"condition": AutomationCondition;
|
||||
"trigger": AutomationTrigger;
|
||||
"action": AutomationAction;
|
||||
"condition": AutomationCondition;
|
||||
}
|
||||
export type AutomationNodeTypes = keyof AutomationNodeMapping | undefined;
|
||||
export type AutomationNode<N extends AutomationNodeTypes = any> =
|
||||
|
||||
Reference in new issue
Block a user