Fix add widget behavior, widget types and view settings button menu item...

This commit is contained in:
Dan Hansen
2026-01-30 19:02:31 +00:00
parent b1e9b442ff
commit 6c49239675
51 changed files with 4999 additions and 174 deletions
+16 -5
View File
@@ -1,12 +1,21 @@
// Main views called from Home tab -> Canvas navigation header
// 'isCanvas' is used to detirmine which views contain widgets and their state
// Add seismic, remote, and deformation once ready to add additional widgets
export const DASHBOARD_TABS = [
{ value: "mydashboard", label: "My Dashboard" },
{ value: "gas", label: "Gas" },
{ value: "seismic", label: "Seismic" },
{ value: "remote", label: "Remote Sensing" },
{ value: "daily", label: "Daily Activity" },
{ value: "mydashboard", label: "My Dashboard", isCanvas: true },
{ value: "gas", label: "Gas", isCanvas: true },
{ value: "seismic", label: "Seismic", isCanvas: false },
{ value: "remote", label: "Remote Sensing", isCanvas: false },
{ value: "deformation", label: "Deformation", isCanvas: false },
{ value: "daily", label: "Daily Activity", isCanvas: false },
]
// Used to check if widget state needs to be initialized per view
// Set has O(1) lookup, trying it becuase it seems fast
export const DASHBOARD_CANVAS_VIEWS = new Set(
DASHBOARD_TABS.filter(t => t.isCanvas).map(t => t.value)
);
// Volcano views called from Volcano tab -> Canvas navigation header
export const VOLCANO_TABS = [
{ value: "volcanohome", label: "Volcano Home" },
@@ -19,6 +28,7 @@ export const VOLCANO_TABS = [
// Admin views called from Admin tab -> Canvas navigation header
export const ADMIN_TABS = [
{ value: "medataentry", label: "M&E Data Entry" },
{ value: "nvews", label: "NVEWS" },
{ value: "projectcollector", label: "Project Collector" },
{ value: "nasapplication", label: "NAS Application" },
{ value: "ivans", label: "IVANS" },
@@ -41,6 +51,7 @@ export const VIEW_LABELS = {
global: "Global Map",
regional: "Regional Map",
volcano: "Volcano",
deformation: "Deformation",
// Volcano navigation tabs
volcanohome: "Volcano Home",
@@ -0,0 +1,97 @@
export const WIDGET_INSPECTOR_REGISTRY = {
"gas_measurements": {
title: "Gas Measurements Settings",
defaultConfig: {
volcano_name: null,
site_name: null,
compound_name: [],
start_date: null,
end_date: null,
include_measurements: true,
include_personnel: false, // optional
},
// Option sources for this widget's fields (from /options endpoint)
optionSources: {
options: {
url: "/options", // relative to API_BASE
cacheKey: "options", // used by generic loader
},
sites: {
url: ({ draft }) => {
const v = draft?.volcano_name;
return v
? `/options/sites?volcano_name=${encodeURIComponent(v)}`
: "/options/sites";
},
cacheKey: ({ draft }) => `sites:${draft?.volcano_name ?? "all"}`,
dependsOn: ["volcano_name"]
},
},
// How to render + bind each config key
fields: [
{
key: "volcano_name",
label: "Volcano",
type: "select",
placeholder: "(all)",
optionsFrom: { source: "options", path: "volcano_name" },
clearOnChange: ["site_name"], // when volcano changes, clear site
},
{
key: "site_name",
label: "Site",
type: "select",
placeholder: "(all)",
optionsFrom: { source: "sites", path: "site_name" },
},
// Single Select Option
// {
// key: "compound",
// label: "Compound",
// type: "select",
// placeholder: "(all)",
// optionsFrom: { source: "options", path: "compound_name" },
// },
{
// Multiple Select Option
key: "compound_name",
label: "Compounds",
type: "checkbox",
placeholder: "(all)",
optionsFrom: { source: "options", path: "compound_name" },
},
{
key: "date_interval",
label: "Date Interval",
type: "dateRange",
startKey: "start_date",
endKey: "end_date",
minFrom: { source: "options", path: "date_min" },
maxFrom: { source: "options", path: "date_max" },
presets: [
{ label: "Use full range", startFrom: "date_min", endFrom: "date_max" },
{ label: "Clear", start: null, end: null, variant: "ghost" },
],
validate: (draft) => {
const s = draft.start_date;
const e = draft.end_date;
if (s && e && s > e) return "Start date must be on or before end date.";
return null;
},
},
],
// Optional: control exactly what gets submitted (prevents "junk" keys)
submitKeys: [
"volcano_name",
"site_name",
"compound_name",
"start_date",
"end_date",
"include_measurements",
"include_personnel",
],
},
};
+106
View File
@@ -0,0 +1,106 @@
// This file is intended to track default widget states as a baseline for any created widgets
import AlertLevel from "src/components/Canvas/CanvasComponents/AlertLevelWidget.jsx"
import GasWidget from "src/components/Canvas/CanvasComponents/GasWidget";
// Example widgets, returns actual baseline widget
export const WIDGET_REGISTRY = {
// ***************** My Dashboard Widgets *****************
alert_level: {
key: "alert_level",
label: "Alert Level",
kind: "real",
defaults: { w: 4, h: 7, minW: 4, minH: 7, maxW: 8, maxH: 14 },
category: "generic",
},
ivans: {
key: "ivans",
label: "IVANS",
kind: "placeholder",
placeholderTitle: "IVANS",
defaults: {w: 4, h: 7, minW: 4, minH: 5, maxW: 8, maxH: 12 },
category: "generic",
},
plume_heights: {
key: "plume_heights",
label: "Plume Heights",
kind: "placeholder",
placeholderTitle: "Plume Heights",
defaults: {w: 4, h: 7, minW: 4, minH: 5, maxW: 8, maxH: 12 },
category: "generic",
},
alert_level_changes: {
key: "alert_level_changes",
label: "Alert Level Changes",
kind: "placeholder",
placeholderTitle: "Alert Level Changes",
defaults: {w: 4, h: 7, minW: 4, minH: 5, maxW: 8, maxH: 12 },
category: "generic",
},
// ***************** Gas Widgets *****************
gas_measurements: {
key: "gas_measurements",
label: "Gas Measurements",
kind: "real",
defaults: {w: 4, h: 6, minW: 4, minH: 5, maxW: 8, maxH: 12 },
category: "gas",
// ~ defaultConfig is being moved to widgetInspectorRegistry
// defaultConfig: {
// // for later filters
// rangeDays: 30,
// compound: null,
// volcano: null,
// site: null,
// },
},
gas_so2: {
key: "gas_so2",
label: "SO₂",
kind: "placeholder",
placeholderTitle: "SO2",
defaults: {w: 4, h: 7, minW: 4, minH: 5, maxW: 8, maxH: 12 },
category: "gas",
},
// Add Additional Widgets to the Registry as they are generated
// Gas Widgets
// Seismic Widgets
// Remote Sensing Widgets
// Deformation Widgets
};
// Used to define components without adding .jsx to a .js registry file
export const WIDGET_COMPONENTS = {
alert_level: AlertLevel,
gas_measurements: GasWidget, // clicking CO2 renders the temp gas widget
};
// Which widgets show up in "Add Widget" for each view
// Make sure these match the keys inside the WIDGET_REGISTRY
export const VIEW_WIDGET_KEYS = {
mydashboard: [
"alert_level",
"gas_measurements",
"ivans",
"plume_heights",
"alert_level_changes"
],
gas: [
"gas_measurements",
"gas_so2",
],
seismic: ["alert_level"],
};
export const getWidgetsForView = (view) => {
const keys = VIEW_WIDGET_KEYS[view] ?? [];
return keys
.map((k) => WIDGET_REGISTRY[k])
.filter(Boolean);
};