feat: add modal dialog, paged results, scan status, and trend value table components
- Introduced ModalDialog component for displaying modal dialogs with accessibility features. - Added PagedResults component to handle pagination of items with customizable rendering. - Created ScanStatus component to display the status of a scan with elapsed time. - Implemented TrendValueTable component for displaying trend data in a paginated table format. - Added measurement utility functions for formatting and validating measurement values. - Included tests for measurement functions and trend series fetching logic to ensure correctness.
This commit is contained in:
1 parent
c19c77334f
commit
a8b6cd4061
23 files changed
+1479
-2157
No files matched your search
+2
-1
@@ -835,7 +835,8 @@ async function getTrendDisplayOptions(user) {
|
||||
}
|
||||
|
||||
async function fetchDisplayTrend(points, range, { maxSeries, defaultPresetDays }) {
|
||||
const trend = await fetchTrendSeries(pool, redis, points.slice(0, maxSeries), normalizeRange(range, defaultPresetDays));
|
||||
const displayedPoints = points.slice(0, maxSeries);
|
||||
const trend = await fetchTrendSeries(pool, redis, displayedPoints, normalizeRange(range, defaultPresetDays, displayedPoints.length));
|
||||
return { ...trend, requestedSeriesCount: points.length, maxSeries };
|
||||
}
|
||||
|
||||
|
||||
+27
-10
@@ -1,5 +1,6 @@
|
||||
import { AUTO_UNIT, DEFAULT_ANALOG_UNIT, resolveEngineeringUnit } from "../../../shared/engineering-units.mjs";
|
||||
import { LEGACY_DATUM_UTC, LEGACY_TREND_TIME_ZONE } from "../../../shared/trend-time.mjs";
|
||||
import { DEFAULT_TREND_ROWS, MIN_TREND_ROWS, maxTrendRowsForSeries } from "../../../shared/trend-preferences.mjs";
|
||||
|
||||
const META_PREFIX = "meta:isp:";
|
||||
export const LEGACY_POINT_LIMIT = 200;
|
||||
@@ -554,6 +555,7 @@ export async function fetchTrendSeries(pool, redis, points, range) {
|
||||
}, new Map());
|
||||
|
||||
const mergedRows = new Map();
|
||||
let rowLimitReached = false;
|
||||
|
||||
for (const [isp, pointDescriptors] of grouped.entries()) {
|
||||
const tableInfo = await describeTrendTable(pool, null, isp);
|
||||
@@ -562,8 +564,9 @@ export async function fetchTrendSeries(pool, redis, points, range) {
|
||||
}
|
||||
|
||||
if (tableInfo.storage === "narrow") {
|
||||
const placeholders = pointDescriptors.map(() => "?").join(", ");
|
||||
const limit = Math.max(pointDescriptors.length, (range.maxRows || 4000) * Math.max(1, pointDescriptors.length));
|
||||
const byIndex = new Map(pointDescriptors.map((point) => [point.pointIndex, point]));
|
||||
const placeholders = Array.from(byIndex, () => "?").join(", ");
|
||||
const limit = range.maxRows * byIndex.size;
|
||||
const [rows] = await pool.query(
|
||||
`
|
||||
SELECT datum, point_index, value
|
||||
@@ -573,16 +576,20 @@ export async function fetchTrendSeries(pool, redis, points, range) {
|
||||
ORDER BY datum DESC, id DESC
|
||||
LIMIT ?
|
||||
`,
|
||||
[...pointDescriptors.map((descriptor) => descriptor.pointIndex), range.from, range.to, limit]
|
||||
[...byIndex.keys(), range.from, range.to, limit + 1]
|
||||
);
|
||||
|
||||
if (rows.length > limit) {
|
||||
rows.pop();
|
||||
rowLimitReached = true;
|
||||
}
|
||||
rows.reverse().forEach((row) => {
|
||||
const timestamp = new Date(row.datum).toISOString();
|
||||
if (!mergedRows.has(timestamp)) {
|
||||
mergedRows.set(timestamp, { timestamp });
|
||||
}
|
||||
const target = mergedRows.get(timestamp);
|
||||
const descriptor = pointDescriptors.find((item) => item.pointIndex === Number(row.point_index));
|
||||
const descriptor = byIndex.get(Number(row.point_index));
|
||||
if (!descriptor) {
|
||||
return;
|
||||
}
|
||||
@@ -596,16 +603,20 @@ export async function fetchTrendSeries(pool, redis, points, range) {
|
||||
const columns = pointDescriptors
|
||||
.map((descriptor) => `\`Wert${descriptor.pointIndex}\``)
|
||||
.join(", ");
|
||||
const limit = range.maxRows || 4000;
|
||||
const limit = range.maxRows;
|
||||
|
||||
const [rows] = await pool.query(
|
||||
`SELECT ${LEGACY_DATUM_UTC} AS datum, ${columns} FROM \`${isp}\`
|
||||
WHERE datum BETWEEN DATE_SUB(?, INTERVAL 1 DAY) AND DATE_ADD(?, INTERVAL 1 DAY)
|
||||
AND ${LEGACY_DATUM_UTC} BETWEEN ? AND ?
|
||||
ORDER BY \`${isp}\`.datum DESC LIMIT ?`,
|
||||
[LEGACY_TREND_TIME_ZONE, range.from, range.to, LEGACY_TREND_TIME_ZONE, range.from, range.to, limit]
|
||||
[LEGACY_TREND_TIME_ZONE, range.from, range.to, LEGACY_TREND_TIME_ZONE, range.from, range.to, limit + 1]
|
||||
);
|
||||
|
||||
if (rows.length > limit) {
|
||||
rows.pop();
|
||||
rowLimitReached = true;
|
||||
}
|
||||
rows.reverse().forEach((row) => {
|
||||
const timestamp = new Date(row.datum).toISOString();
|
||||
|
||||
@@ -624,9 +635,13 @@ export async function fetchTrendSeries(pool, redis, points, range) {
|
||||
});
|
||||
}
|
||||
|
||||
const sortedRows = [...mergedRows.values()].sort((left, right) => left.timestamp.localeCompare(right.timestamp));
|
||||
return {
|
||||
series: descriptors,
|
||||
rows: [...mergedRows.values()].sort((left, right) => left.timestamp.localeCompare(right.timestamp)),
|
||||
rows: sortedRows.slice(-range.maxRows),
|
||||
effectiveMaxRows: range.maxRows,
|
||||
requestedMaxRows: range.requestedMaxRows,
|
||||
rowLimitReached: rowLimitReached || sortedRows.length > range.maxRows,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -714,9 +729,10 @@ export async function fetchLatestValues(pool, redis, points) {
|
||||
return values;
|
||||
}
|
||||
|
||||
export function normalizeRange(input = {}, defaultPresetDays = 1) {
|
||||
export function normalizeRange(input = {}, defaultPresetDays = 1, seriesCount = 1) {
|
||||
const presetDays = Number(input.presetDays || defaultPresetDays);
|
||||
const maxRows = Number(input.maxRows || 4000);
|
||||
const maxRows = Number(input.maxRows || DEFAULT_TREND_ROWS);
|
||||
const requestedMaxRows = Number.isFinite(maxRows) ? Math.trunc(maxRows) : DEFAULT_TREND_ROWS;
|
||||
const now = new Date();
|
||||
const to = input.to ? new Date(input.to) : now;
|
||||
const from = input.from ? new Date(input.from) : new Date(now.getTime() - presetDays * 24 * 60 * 60 * 1000);
|
||||
@@ -724,7 +740,8 @@ export function normalizeRange(input = {}, defaultPresetDays = 1) {
|
||||
return {
|
||||
from,
|
||||
to,
|
||||
maxRows: Number.isFinite(maxRows) ? Math.max(100, Math.min(maxRows, 10000)) : 4000,
|
||||
requestedMaxRows,
|
||||
maxRows: Math.max(MIN_TREND_ROWS, Math.min(requestedMaxRows, maxTrendRowsForSeries(seriesCount))),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user