latest work
This commit is contained in:
1 parent
acb12e73e8
commit
b368be0ff4
8 files changed
+215
-12
No files matched your search
Vendored
+37
-10
@@ -2,7 +2,25 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"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",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
|
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
|
||||||
@@ -10,20 +28,29 @@
|
|||||||
"test",
|
"test",
|
||||||
"--runInBand",
|
"--runInBand",
|
||||||
"--no-cache",
|
"--no-cache",
|
||||||
"--watchAll=false"
|
"--watchAll"
|
||||||
],
|
],
|
||||||
"cwd": "${workspaceRoot}",
|
"cwd": "${workspaceRoot}",
|
||||||
"protocol": "inspector",
|
"protocol": "inspector",
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"internalConsoleOptions": "neverOpen",
|
"internalConsoleOptions": "neverOpen"
|
||||||
"env": {
|
|
||||||
"CI": "true"
|
|
||||||
},
|
},
|
||||||
"disableOptimisticBPs": true,
|
{
|
||||||
"jasmineExplorer.nodeArgv": [
|
"name": "Debug tests opened file",
|
||||||
"-r",
|
"type": "node",
|
||||||
"ts-node/register"
|
"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/chroma-js": "^2.1.3",
|
||||||
"@types/js-yaml": "^4.0.5",
|
"@types/js-yaml": "^4.0.5",
|
||||||
"ts-node": "^10.4.0"
|
"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 { AutomationEditor } from "components/AutomationEditor";
|
||||||
import { Button } from "components/Inputs/Button";
|
import { Button } from "components/Inputs/Button";
|
||||||
import { FC, useState } from "react";
|
import { FC, useState } from "react";
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export interface AutomationMetadata {
|
|||||||
description: string;
|
description: string;
|
||||||
trigger_variables?: Record<string, string>;
|
trigger_variables?: Record<string, string>;
|
||||||
mode: "single" | "restart" | "queued" | "parallel";
|
mode: "single" | "restart" | "queued" | "parallel";
|
||||||
|
tags: Record<string, string>;
|
||||||
}
|
}
|
||||||
export interface AutomationData {
|
export interface AutomationData {
|
||||||
metadata: AutomationMetadata;
|
metadata: AutomationMetadata;
|
||||||
|
|||||||
Reference in new issue
Block a user