upd: docs updated. add: widget resorce iconChildren param added. upd: config file default options added.pull/3420/head
parent
986a18170c
commit
90094c9bbe
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,45 @@
|
||||
import useSWR from "swr";
|
||||
import { FaNetworkWired, FaAngleUp, FaAngleDown } from "react-icons/fa";
|
||||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import Resource from "../widget/resource";
|
||||
import Error from "../widget/error";
|
||||
|
||||
export default function Network({ options, refresh = 5000 }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { data, error } = useSWR(`/api/widgets/resources?type=network${(options.network || options.network !== 'default') ? `&interfaceName=${options.network}` : '' }`, {
|
||||
refreshInterval: refresh,
|
||||
});
|
||||
|
||||
if (error || data?.error) {
|
||||
return <Error />;
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<Resource
|
||||
icon={FaNetworkWired}
|
||||
value="-"
|
||||
label={<FaAngleUp/>}
|
||||
expandedValue="-"
|
||||
expandedLabel={<FaAngleDown/>}
|
||||
percentage="0"
|
||||
expanded="true"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Resource
|
||||
icon={FaNetworkWired}
|
||||
value={t('common.bbytes', { value: data?.network?.tx_bytes })}
|
||||
label={<FaAngleUp/>}
|
||||
expandedValue={t('common.bbytes', { value: data?.network?.rx_bytes })}
|
||||
expandedLabel={<FaAngleDown/>}
|
||||
percentage="0"
|
||||
expanded="true"
|
||||
iconChildren={<span class="bg-theme-100 text-theme-800 text-xs font-medium px-1 py-1 mt-1 rounded dark:bg-theme-700 dark:text-gray-300 text-center">{data.interface}</span>}
|
||||
/>
|
||||
);
|
||||
}
|
Loading…
Reference in new issue