UNPKG

@opendash/plugin-openware

Version:

open.WARE Plugin for open.DASH

64 lines 3.58 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import React from "react"; import { ReportCardList, ActionBar } from "./layout"; import { Loading, useUrlParam } from "opendash"; import { Report } from "./Report"; import { useReports, useFilter } from "./api"; import { Alert, Button, Modal, message } from "antd"; import { useTranslation, useBreadcrumb, useSource, AdminLayout, } from "opendash"; import reportTypes from "./reports"; export default function ReportingOverview() { var t = useTranslation(["openware", "opendash"])[0]; var stateRef = React.useRef(null); var source = useSource()[0]; var _a = React.useState(""), search = _a[0], setSearch = _a[1]; var _b = useUrlParam("create", false, "json"), create = _b[0], setCreate = _b[1]; var _c = React.useState("basic"), selectedType = _c[0], setType = _c[1]; var _d = useReports(), allReports = _d.result, reload = _d.reload; var reports = useFilter(allReports, source, search); var reportType = reportTypes.find(function (t) { return t.type === selectedType; }); useBreadcrumb("openware:reporting.label"); if (!source || !source.tag) { return (React.createElement(AdminLayout, null, React.createElement(Loading, null), React.createElement(Alert, { type: "info", message: t("openware:reporting.missing_location_message"), description: t("openware:reporting.missing_location_description"), style: { marginBottom: 24 } }))); } return (React.createElement(AdminLayout, null, React.createElement(ActionBar, __assign({}, { search: search, setSearch: setSearch }), React.createElement(Button, { type: "primary", onClick: function () { return setCreate(true); } }, t("openware:reporting.create.action"))), React.createElement(ReportCardList, { reports: reports }), React.createElement(Modal, { title: t("openware:reporting.create.title"), visible: create, onCancel: function () { return setCreate(false); }, width: 600, okButtonProps: { disabled: !stateRef.current }, onOk: function () { new Report({ type: selectedType, source: source.tag, params: stateRef.current(), }) .save() .then(function (report) { message.success(t("openware:reporting.create.success")); setCreate(false); reload(); var hide = message.loading(t("openware:reporting.download.start"), 0); report.download().then(function () { hide(); message.success(t("openware:reporting.download.success")); }, function () { message.error(t("openware:reporting.download.error")); }); }, function () { message.error(t("openware:reporting.create.error")); }); } }, React.createElement(reportType.Settings, { key: selectedType, onSave: function (cb) { return void (stateRef.current = cb); } })))); } //# sourceMappingURL=index.js.map