Fix dynamic evaluation of UI config expressions

This commit is contained in:
Zaid Humaimidi committed 2024-04-22 14:14:12 -07:00
1 parent 5c4fc3263b
commit 756912eeb1
4 files changed
+24 -8

No files matched your search

+6 -2
View File
@@ -27,10 +27,14 @@ const component: ClosureComponent = (): Component => {
cx: "0.5em",
cy: "0.5em",
r: "0.4em",
fill: slice["color"],
fill: evaluateExpression(slice["color"], null),
}),
);
return m("span.overview-dot", dot, `${slice["label"]}`);
return m(
"span.overview-dot",
dot,
evaluateExpression(slice["label"], null),
);
}
}
return null;
+5 -1
View File
@@ -39,7 +39,11 @@ export const component: ClosureComponent = (): Component => {
for (const c of Object.values(conf)) {
cmps.push(
m.context({ device: dev.value[0], deviceQuery: dev }, c["type"], c),
m.context(
{ device: dev.value[0], deviceQuery: dev },
store.evaluateExpression(c["type"], null) as string,
c,
),
);
}
+9 -2
View File
@@ -26,7 +26,10 @@ const memoizedGetSortable = memoize((p) => {
const getDownloadUrl = memoize((filter, indexParameters) => {
const columns = {};
for (const p of indexParameters) columns[p.label] = stringify(p.parameter);
for (const p of indexParameters)
columns[store.evaluateExpression(p.label, null) as string] = stringify(
p.parameter,
);
return `api/devices.csv?${m.buildQueryString({
filter: stringify(filter),
columns: JSON.stringify(columns),
@@ -282,7 +285,11 @@ export const component: ClosureComponent = (): Component => {
};
const attrs = {};
attrs["attributes"] = attributes;
attrs["attributes"] = attributes.map((a) => ({
...a,
label: store.evaluateExpression(a.label, null),
type: store.evaluateExpression(a.type, null),
}));
attrs["data"] = devs.value;
attrs["total"] = count.value;
attrs["showMoreCallback"] = showMore;
+4 -3
View File
@@ -2,6 +2,7 @@ import { ClosureComponent, Component, Children } from "mithril";
import { m } from "./components.ts";
import { stringify } from "../lib/common/expression/parser.ts";
import memoize from "../lib/common/memoize.ts";
import * as store from "./store.ts";
const memoizedStringify = memoize(stringify);
@@ -24,9 +25,9 @@ function drawChart(chartData): Children {
legend.push(
m(".legend-line", [
m("span.color", {
style: `background-color: ${slice["color"]} !important;`,
style: `background-color: ${store.evaluateExpression(slice["color"], null)} !important;`,
}),
`${slice["label"]}: `,
`${store.evaluateExpression(slice["label"], null)}: `,
m(
"a",
{
@@ -57,7 +58,7 @@ function drawChart(chartData): Children {
paths.push(
m("path", {
d: sketch,
fill: slice["color"],
fill: store.evaluateExpression(slice["color"], null),
}),
);