Files
factorio-clusterio/plugins/inventory_sync/web/index.jsx
T
Hornwitser 0c74aef68e Hide unauthorized web interface controls
Hide or disable controls in the web interface that the user for the
control connection it's connected as don't have the requisite
permissions to use.
2021-09-20 00:54:43 +02:00

49 lines
1.1 KiB
React

import React, { useContext, useEffect, useState } from "react";
import { libPlugin } from "@clusterio/lib";
import { PageLayout, ControlContext } from "@clusterio/web_ui";
import info from "../info";
import "./index.css";
function InventoryPage() {
let control = useContext(ControlContext);
let [statsData, updateStatsData] = useState();
useEffect(() => {
(async () => {
// Get statistics
updateStatsData(await info.messages.databaseStats.send(control, {}));
})();
}, []);
return <PageLayout nav={[{ name: "Inventory sync" }]}>
<h2>Inventory sync</h2>
{statsData && <>
<p>Database size: {Math.round(statsData.database_size / 1000)}kB</p>
<p>Database entries: {statsData.database_entries}</p>
<p>Largest entry is {statsData.largest_entry.name} with {(statsData.largest_entry.size / 1000)}kB</p>
</>}
</PageLayout>;
}
export class WebPlugin extends libPlugin.BaseWebPlugin {
async init() {
this.pages = [
{
path: "/inventory",
sidebarName: "Inventory sync",
permission: "inventory_sync.inventory.view",
content: <InventoryPage />,
},
];
}
onMasterConnectionEvent(event) {
if (event === "connect") {
}
}
}