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