Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up filter processing #476

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "es5"
}
36 changes: 18 additions & 18 deletions auto-entities.js

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.2.1",
"prettier": "3.4.2",
"rollup": "^3.8.1",
"rollup-plugin-typescript2": "^0.34.1",
"tslib": "^2.4.1",
Expand Down
5 changes: 4 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ export default {
plugins: [
nodeResolve(),
json(),
typescript(),
typescript({
clean: true,
}),
babel({
exclude: "node_modules/**",
babelHelpers: "bundled",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the previous behavior; specifying it explicitly prevents a build-time warning.

}),
!dev && terser({ format: { comments: false } }),
],
Expand Down
36 changes: 22 additions & 14 deletions src/editor/auto-entities-editor.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
import { LitElement, html, CSSResultArray, css } from "lit";
import { property, state, query } from "lit/decorators.js";
import { css, CSSResultArray, html, LitElement } from "lit";
import { property, query, state } from "lit/decorators.js";
import { AutoEntitiesConfig } from "../types";
import { loadHaForm } from "../helpers";
import {
filterGroupSchema,
filterGroupOptionsSchema,
cardOptionsSchema,
filter2form,
filterGroupOptionsSchema,
filterGroupSchema,
form2filter,
specialGroupSchema,
cardOptionsSchema,
sortSchema,
specialGroupSchema,
} from "./schema";

class AutoEntitiesEditor extends LitElement {
@state() _config: AutoEntitiesConfig;
@state()
_config: AutoEntitiesConfig;

@property() lovelace;
@property() hass;
@property()
lovelace;
@property()
hass;

@state() _selectedTab = 0;
@state() _cardGUIMode = true;
@state() _cardGUIModeAvailable = true;
@state()
_selectedTab = 0;
@state()
_cardGUIMode = true;
@state()
_cardGUIModeAvailable = true;

@query("hui-card-element-editor") private _cardEditorEl?;
@query("hui-card-element-editor")
private _cardEditorEl?;

setConfig(config) {
this._config = config;
Expand Down Expand Up @@ -258,7 +265,7 @@ class AutoEntitiesEditor extends LitElement {
}

_renderFilterEditor() {
if (this._config.filter?.template || this._config.entities)
if (this._config.filter?.template || this._config.entities) {
return html`
<div class="box">
<p>
Expand All @@ -267,6 +274,7 @@ class AutoEntitiesEditor extends LitElement {
<p>Please switch to the CODE EDITOR to access all options.</p>
</div>
`;
}

return html`
${this._config.filter.include.map(
Expand Down
6 changes: 4 additions & 2 deletions src/editor/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ const filterSchema = ([key, value], idx) => {
attributes: { object: {} },
};

if (!GUI_EDITOR_FILTERS.includes(key))
if (!GUI_EDITOR_FILTERS.includes(key)) {
return {
type: "Constant",
name: "Some filters are not shown",
value: "Please switch to the CODE EDITOR to access all options.",
};
}

return {
type: "grid",
Expand Down Expand Up @@ -100,8 +101,9 @@ export const filter2form = (group) => {
export const form2filter = (config, filter): Object => {
const data = {};
for (let i = 0; i <= config.filter.include.length + 1; i++) {
if (filter[`key_${i}`] !== undefined)
if (filter[`key_${i}`] !== undefined) {
data[filter[`key_${i}`]] = filter[`value_${i}`] ?? "";
}
}
if (filter.key_new !== undefined) {
data[filter.key_new] = "";
Expand Down
Loading