From 7c3d46893a3daf58d37b203c63dc9f7988697805 Mon Sep 17 00:00:00 2001 From: goodmice Date: Fri, 15 Apr 2022 17:17:34 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B4=D0=B0=D1=88=D0=B1=D0=BE=D1=80=D0=B4=20=D1=81=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=BE=D0=BC=20=D0=BF=D0=B0=D1=80?= =?UTF-8?q?=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=BE=D0=B2=20=D0=9D=D0=9D=D0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/widgets/BaseWidget.tsx | 67 +++++ .../widgets/WidgetSettingsWindow.tsx | 65 +++++ src/components/widgets/index.ts | 5 + .../Telemetry/DashboardNNB/AddGroupWindow.jsx | 18 ++ .../DashboardNNB/AddWidgetWindow.jsx | 52 ++++ src/pages/Telemetry/DashboardNNB/index.jsx | 255 ++++++++++++++++++ src/pages/Telemetry/index.jsx | 6 + src/styles/dashboard_nnb.less | 29 ++ src/styles/widgets/base.less | 56 ++++ src/utils/index.ts | 7 +- src/utils/storage.ts | 56 ++-- 11 files changed, 591 insertions(+), 25 deletions(-) create mode 100644 src/components/widgets/BaseWidget.tsx create mode 100644 src/components/widgets/WidgetSettingsWindow.tsx create mode 100644 src/components/widgets/index.ts create mode 100644 src/pages/Telemetry/DashboardNNB/AddGroupWindow.jsx create mode 100644 src/pages/Telemetry/DashboardNNB/AddWidgetWindow.jsx create mode 100644 src/pages/Telemetry/DashboardNNB/index.jsx create mode 100644 src/styles/dashboard_nnb.less create mode 100644 src/styles/widgets/base.less diff --git a/src/components/widgets/BaseWidget.tsx b/src/components/widgets/BaseWidget.tsx new file mode 100644 index 0000000..c17ff10 --- /dev/null +++ b/src/components/widgets/BaseWidget.tsx @@ -0,0 +1,67 @@ +import { Button } from 'antd' +import { memo, ReactNode, useMemo } from 'react' +import { CloseOutlined, SettingOutlined } from '@ant-design/icons' + +import '@styles/widgets/base.less' + +export type WidgetSettings = { + id?: number, + unit?: string, + label?: string, + formatter?: ((v: T) => ReactNode) | null, + defaultValue?: ReactNode, + + labelColor?: string, + valueColor?: string, + backgroundColor?: string, + unitColor?: string, +} + +export const defaultSettings: WidgetSettings = { + unit: '----', + label: 'Виджет', + formatter: v => isNaN(v) ? v : parseFloat(v).toFixed(2), + + labelColor: '#000000', + valueColor: '#000000', + backgroundColor: '#f6f6f6', + unitColor: '#a0a0a0', +} + +export type BaseWidgetProps = WidgetSettings & { + value: T, + onRemove: (settings: WidgetSettings) => void, + onEdit: (settings: WidgetSettings) => void, +} + +export const BaseWidget = memo(({ value, onRemove, onEdit, ...settings }) => { + const sets = useMemo(() => ({ ...defaultSettings, ...settings }), [settings]) + + return ( +
+
+
+
+
+ {(sets.formatter === null ? value : sets.formatter?.(value)) ?? sets.defaultValue ?? '----'} +
+
{sets.unit}
+ + ) +}) + +export default BaseWidget diff --git a/src/components/widgets/WidgetSettingsWindow.tsx b/src/components/widgets/WidgetSettingsWindow.tsx new file mode 100644 index 0000000..16b70be --- /dev/null +++ b/src/components/widgets/WidgetSettingsWindow.tsx @@ -0,0 +1,65 @@ +import { memo, useEffect } from 'react' +import { Form, Input, Modal, ModalProps } from 'antd' + +import { WidgetSettings } from './BaseWidget' + +export type WidgetSettingsWindowProps = ModalProps & { + settings: WidgetSettings + onEdit: (settings: WidgetSettings) => void +} + +const { Item } = Form + +export const WidgetSettingsWindow = memo(({ settings, onEdit, ...other }) => { + const [form] = Form.useForm() + + useEffect(() => { + if (settings) form.setFieldsValue(settings) + }, [form, settings]) + + return ( + + Настройка виджета {settings?.label ? `"${settings?.label}"` : ''} + (id: {settings?.id}) + + )} + onOk={form.submit} + getContainer={false} + > +
+ + + + + + + + + + + + + + + + + + + +
+
+ ) +}) + +export default WidgetSettingsWindow diff --git a/src/components/widgets/index.ts b/src/components/widgets/index.ts new file mode 100644 index 0000000..c73bcc7 --- /dev/null +++ b/src/components/widgets/index.ts @@ -0,0 +1,5 @@ +export { WidgetSettingsWindow } from './WidgetSettingsWindow' +export { BaseWidget } from './BaseWidget' + +export type { WidgetSettingsWindowProps } from './WidgetSettingsWindow' +export type { WidgetSettings, BaseWidgetProps } from './BaseWidget' diff --git a/src/pages/Telemetry/DashboardNNB/AddGroupWindow.jsx b/src/pages/Telemetry/DashboardNNB/AddGroupWindow.jsx new file mode 100644 index 0000000..96ce88e --- /dev/null +++ b/src/pages/Telemetry/DashboardNNB/AddGroupWindow.jsx @@ -0,0 +1,18 @@ +import { PlusOutlined } from '@ant-design/icons' +import { Form, Input } from 'antd' +import { memo } from 'react' + +import Poprompt from '@components/selectors/Poprompt' + +const addGroupRules = [{ required: true, message: 'Пожалуйста, введите название группы' }] +const addGroupButtonProps = { type: 'link', className: 'add_group', icon: } + +export const AddGroupWindow = memo(({ addGroup, initialValue = 'Новая группа' }) => ( + + + + + +)) + +export default AddGroupWindow diff --git a/src/pages/Telemetry/DashboardNNB/AddWidgetWindow.jsx b/src/pages/Telemetry/DashboardNNB/AddWidgetWindow.jsx new file mode 100644 index 0000000..1cd15cd --- /dev/null +++ b/src/pages/Telemetry/DashboardNNB/AddWidgetWindow.jsx @@ -0,0 +1,52 @@ +import { PlusOutlined } from '@ant-design/icons' +import { Form, Select } from 'antd' +import { memo, useCallback, useMemo } from 'react' + +import Poprompt from '@components/selectors/Poprompt' + +export const createWidgetId = (witsRecord, dt = false) => `${witsRecord.recordId}_${witsRecord.itemId}` + (dt ? `_${Date.now()}` : '') + +export const makeWidgetFromWits = (witsRecord) => ({ + id: createWidgetId(witsRecord, true), + witsId: witsRecord.longMnemonic.toLowerCase(), + recordId: witsRecord.recordId, + unit: witsRecord.metricUnits, + label: witsRecord.longMnemonic, +}) + +const addWidgetRules = [{ required: true, message: 'Пожалуйста, выберите виджет' }] +const addWidgetButtonProps = { type: 'link', className: 'add_group', icon: } + +export const AddWidgetWindow = memo(({ witsInfo, onAdded }) => { + const options = useMemo(() => witsInfo?.map((witsRecord) => ({ + label: `Record #${witsRecord.recordId}: ${witsRecord.longMnemonic}`, + value: createWidgetId(witsRecord), + })) ?? [], [witsInfo]) + + const onFormFinish = useCallback((value) => { + if (!value?.widget) return + const record = witsInfo.find((witsRecord) => createWidgetId(witsRecord) === value.widget) + if (record) + onAdded?.(makeWidgetFromWits(record)) + }, [onAdded, witsInfo]) + + return ( + + +