UNPKG

@opendash/plugin-openware

Version:

open.WARE Plugin for open.DASH

155 lines 9.82 kB
import * as React from "react"; import { Steps, Tabs, Divider, Button, Input, Table, Checkbox, Select, } from "antd"; import { useImmerState, useTranslation, DataItemValueMultiSelect, DataItemHistoryOptionsPicker, DataExplorerDescription, useSource, useOpenDashServices, useUrlParam, } from "opendash"; export var Settings = function (_a) { var onSave = _a.onSave; var _b, _c; var t = useTranslation(["openware", "opendash"])[0]; var _d = useUrlParam("tab", 0, "json"), step = _d[0], setStep = _d[1]; var source = useSource()[0]; var _e = useImmerState({ _items: [ ["demo.video.energieverbraucha", 0], ["demo.video.energieverbrauchc", 0], ["demo.video.energieverbrauchb", 0], ], _time: { start: Date.now() - 1000 * 60 * 60 * 1, end: Date.now(), }, title: "", description: "", start: 0, end: 0, items: [], }), state = _e[0], updateState = _e[1]; onSave(function () { return state; }); var items = useItems(state); React.useEffect(function () { updateState(function (draft) { draft.items = state._items.map(function (_a, index) { var id = _a[0], valueDimension = _a[1]; var _b, _c, _d, _e, _f, _g, _h; return ({ index: index, id: id, user: (_b = source) === null || _b === void 0 ? void 0 : _b.tag, valueDimension: valueDimension, label: ((_d = (_c = items) === null || _c === void 0 ? void 0 : _c[id]) === null || _d === void 0 ? void 0 : _d.name) + " - " + ((_h = (_g = (_f = (_e = items) === null || _e === void 0 ? void 0 : _e[id]) === null || _f === void 0 ? void 0 : _f.valueTypes) === null || _g === void 0 ? void 0 : _g[valueDimension]) === null || _h === void 0 ? void 0 : _h.name), interval: "3600000", canSum: false, showData: true, showChart: true, }); }); }); }, [(_b = state) === null || _b === void 0 ? void 0 : _b._items]); React.useEffect(function () { updateState(function (draft) { draft.start = state._time.start; draft.end = state._time.end; }); }, [(_c = state) === null || _c === void 0 ? void 0 : _c._time]); return (React.createElement(React.Fragment, null, React.createElement(Steps, { current: step, onChange: setStep }, React.createElement(Steps.Step, { title: t("openware:reporting.types.basic.items_title"), subTitle: t("opendash:data_explorer.step_0_subtitle", { count: state._items.length, }), status: step !== 0 && state._items.length === 0 ? "error" : undefined }), React.createElement(Steps.Step, { title: t("openware:reporting.types.basic.time_title") }), React.createElement(Steps.Step, { title: t("openware:reporting.types.basic.settings_title") })), React.createElement(Divider, null), React.createElement(Tabs, { activeKey: step.toString(), renderTabBar: function () { return React.createElement(React.Fragment, null); } }, React.createElement(Tabs.TabPane, { tab: t("openware:reporting.types.basic.items_title"), key: "0" }, React.createElement(DataExplorerDescription, { children: t("openware:reporting.types.basic.items_description") }), React.createElement(DataItemValueMultiSelect, { value: state._items, style: { width: "100%" }, onChange: function (nextValue) { updateState(function (draft) { draft._items = nextValue; }); } })), React.createElement(Tabs.TabPane, { tab: t("openware:reporting.types.basic.time_title"), key: "1" }, React.createElement(DataExplorerDescription, { children: t("openware:reporting.types.basic.time_description") }), React.createElement(DataItemHistoryOptionsPicker, { value: state._time, onChange: function (value) { updateState(function (draft) { return void (draft._time = value); }); } }), React.createElement("br", null), React.createElement("br", null)), React.createElement(Tabs.TabPane, { tab: t("openware:reporting.types.basic.settings_title"), key: "2" }, React.createElement(DataExplorerDescription, { children: t("openware:reporting.types.basic.settings_description") }), React.createElement(Input, { style: { marginBottom: 24 }, placeholder: t("openware:reporting.types.basic.title"), value: state.title, onChange: function (event) { var value = event.target.value; updateState(function (draft) { return void (draft.title = value); }); } }), React.createElement(Input, { style: { marginBottom: 24 }, placeholder: t("openware:reporting.types.basic.description"), value: state.description, onChange: function (event) { var value = event.target.value; updateState(function (draft) { return void (draft.description = value); }); } }), React.createElement(DataExplorerDescription, { children: t("openware:reporting.types.basic.settings_items_description") }), React.createElement(Table // size="small" , { // size="small" dataSource: state.items, rowKey: "index", columns: [ { title: t("openware:reporting.types.basic.settings_table_label"), dataIndex: "label", key: "label", }, { title: t("openware:reporting.types.basic.settings_table_showData"), dataIndex: "showData", key: "showData", render: function (value, row) { return (React.createElement(Checkbox, { checked: value, onChange: function (event) { var value = event.target.checked; updateState(function (draft) { draft.items[row.index].showData = value; }); } })); }, }, { title: t("openware:reporting.types.basic.settings_table_showChart"), dataIndex: "showChart", key: "showChart", render: function (value, row) { return (React.createElement(Checkbox, { checked: value, onChange: function (event) { var value = event.target.checked; updateState(function (draft) { draft.items[row.index].showChart = value; }); } })); }, }, { title: t("openware:reporting.types.basic.settings_table_interval"), dataIndex: "interval", key: "interval", render: function (value, row) { return (React.createElement(Select, { value: value, onChange: function (value) { updateState(function (draft) { draft.items[row.index].showChart = value; }); } }, React.createElement(Select.Option, { key: "900000" }, t("openware:reporting.types.basic.interval_15min")), React.createElement(Select.Option, { key: "3600000" }, t("openware:reporting.types.basic.interval_1h")), React.createElement(Select.Option, { key: "86400000" }, t("openware:reporting.types.basic.interval_1d")), React.createElement(Select.Option, { key: "604800000" }, t("openware:reporting.types.basic.interval_7d")))); }, }, ] }))), React.createElement("div", null, React.createElement(Button, { type: "default", disabled: step <= 0, onClick: function (e) { return setStep(step - 1); }, children: t("opendash:ui.back") }), React.createElement(Button, { type: "primary", disabled: step >= 2, onClick: function (e) { return setStep(step + 1); }, style: { float: "right" }, children: t("opendash:ui.next") })))); }; // DO NOT COPY this function, it may break at any time function useItems(state) { var _a; var DataService = useOpenDashServices().DataService; return React.useMemo(function () { return Object.fromEntries(state._items.map(function (_a) { var id = _a[0]; return [id, DataService._getOrThrowSync(id)]; })); }, [(_a = state) === null || _a === void 0 ? void 0 : _a._items]); } //# sourceMappingURL=basic.js.map