Skip to content

Commit

Permalink
UI fixes (#13246)
Browse files Browse the repository at this point in the history
* Fix bad data in stats

* Add support for changes dialog when leaving without saving config editor

* Fix scrolling into view
  • Loading branch information
NickM-27 authored Aug 21, 2024
1 parent d96f76c commit 1c7ee5f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
37 changes: 37 additions & 0 deletions web/src/pages/ConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,49 @@ function ConfigEditor() {
};
});

// monitoring state

const [hasChanges, setHasChanges] = useState(false);

useEffect(() => {
if (!config || !modelRef.current) {
return;
}

modelRef.current.onDidChangeContent(() => {
if (modelRef.current?.getValue() != config) {
setHasChanges(true);
} else {
setHasChanges(false);
}
});
}, [config]);

useEffect(() => {
if (config && modelRef.current) {
modelRef.current.setValue(config);
setHasChanges(false);
}
}, [config]);

useEffect(() => {
let listener: ((e: BeforeUnloadEvent) => void) | undefined;
if (hasChanges) {
listener = (e) => {
e.preventDefault();
e.returnValue = true;
return "Exit without saving?";
};
window.addEventListener("beforeunload", listener);
}

return () => {
if (listener) {
window.removeEventListener("beforeunload", listener);
}
};
}, [hasChanges]);

if (!config) {
return <ActivityIndicator />;
}
Expand Down
1 change: 1 addition & 0 deletions web/src/pages/Logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ function Logs() {
key={item}
className={`flex items-center justify-between gap-2 ${logService == item ? "" : "text-muted-foreground"}`}
value={item}
data-nav-item={item}
aria-label={`Select ${item}`}
>
<div className="capitalize">{item}</div>
Expand Down
16 changes: 10 additions & 6 deletions web/src/views/system/GeneralMetrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default function GeneralMetrics({
series[key] = { name: key, data: [] };
}

const data = stats.cpu_usages[detStats.pid.toString()].cpu;
const data = stats.cpu_usages[detStats.pid.toString()]?.cpu;

if (data != undefined) {
series[key].data.push({
Expand Down Expand Up @@ -304,7 +304,7 @@ export default function GeneralMetrics({
series[key] = { name: key, data: [] };
}

const data = stats.cpu_usages[procStats.pid.toString()].cpu;
const data = stats.cpu_usages[procStats.pid.toString()]?.cpu;

if (data != undefined) {
series[key].data.push({
Expand Down Expand Up @@ -338,10 +338,14 @@ export default function GeneralMetrics({
series[key] = { name: key, data: [] };
}

series[key].data.push({
x: statsIdx + 1,
y: stats.cpu_usages[procStats.pid.toString()].mem,
});
const data = stats.cpu_usages[procStats.pid.toString()]?.mem;

if (data) {
series[key].data.push({
x: statsIdx + 1,
y: data,
});
}
}
});
});
Expand Down

0 comments on commit 1c7ee5f

Please sign in to comment.