Make widget clickable + cleanup helperrs
This commit is contained in:
parent
944fa7558c
commit
cdeb3911c4
@ -1,4 +1,5 @@
|
||||
import useSWR from "swr";
|
||||
import { useContext } from "react";
|
||||
import { BiError } from "react-icons/bi";
|
||||
import { FaMemory, FaRegClock, FaThermometerHalf } from "react-icons/fa";
|
||||
import { FiCpu, FiHardDrive } from "react-icons/fi";
|
||||
@ -6,6 +7,8 @@ import { useTranslation } from "next-i18next";
|
||||
|
||||
import UsageBar from "../resources/usage-bar";
|
||||
|
||||
import { SettingsContext } from "utils/contexts/settings";
|
||||
|
||||
const cpuSensorLabels = ["cpu_thermal", "Core", "Tctl"];
|
||||
|
||||
function convertToFahrenheit(t) {
|
||||
@ -14,6 +17,7 @@ function convertToFahrenheit(t) {
|
||||
|
||||
export default function Widget({ options }) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const { settings } = useContext(SettingsContext);
|
||||
|
||||
const { data, error } = useSWR(
|
||||
`/api/widgets/glances?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`, {
|
||||
@ -93,7 +97,7 @@ export default function Widget({ options }) {
|
||||
: [data.fs.find((d) => d.mnt_point === options.disk)].filter((d) => d);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col max-w:full sm:basis-auto self-center grow-0 flex-wrap">
|
||||
<a href={options.url} target={settings.target ?? "_blank"} className="flex flex-col max-w:full sm:basis-auto self-center grow-0 flex-wrap">
|
||||
<div className="flex flex-row self-center flex-wrap justify-between">
|
||||
<div className="flex-none flex flex-row items-center mr-3 py-1.5">
|
||||
<FiCpu className="text-theme-800 dark:text-theme-200 w-5 h-5" />
|
||||
@ -218,6 +222,6 @@ export default function Widget({ options }) {
|
||||
{options.label && (
|
||||
<div className="pt-1 text-center text-theme-800 dark:text-theme-200 text-xs">{options.label}</div>
|
||||
)}
|
||||
</div>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
@ -5,8 +5,6 @@ import yaml from "js-yaml";
|
||||
|
||||
import checkAndCopyConfig, { substituteEnvironmentVars } from "utils/config/config";
|
||||
|
||||
const exemptWidgets = ["search"];
|
||||
|
||||
export async function widgetsFromConfig() {
|
||||
checkAndCopyConfig("widgets.yaml");
|
||||
|
||||
@ -32,15 +30,17 @@ export async function cleanWidgetGroups(widgets) {
|
||||
return widgets.map((widget, index) => {
|
||||
const sanitizedOptions = widget.options;
|
||||
const optionKeys = Object.keys(sanitizedOptions);
|
||||
if (!exemptWidgets.includes(widget.type)) {
|
||||
["url", "username", "password", "key"].forEach((pO) => {
|
||||
if (optionKeys.includes(pO)) {
|
||||
// allow URL in search
|
||||
if (widget.type !== "search" && pO !== "key") {
|
||||
delete sanitizedOptions[pO];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// delete private options from the sanitized options
|
||||
["username", "password", "key"].forEach((pO) => {
|
||||
if (optionKeys.includes(pO)) {
|
||||
delete sanitizedOptions[pO];
|
||||
}
|
||||
});
|
||||
|
||||
// delete url from the sanitized options if the widget is not a search or glances widgeth
|
||||
if (widget.type !== "search" && widget.type !== "glances" && optionKeys.includes("url")) {
|
||||
delete sanitizedOptions.url;
|
||||
}
|
||||
|
||||
return {
|
||||
@ -78,4 +78,4 @@ export async function getPrivateWidgetOptions(type, widgetIndex) {
|
||||
});
|
||||
|
||||
return (type !== undefined && widgetIndex !== undefined) ? privateOptions.find(o => o.type === type && o.options.index === parseInt(widgetIndex, 10))?.options : privateOptions;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user