diff --git a/package-lock.json b/package-lock.json index 2af8a855a..ba031da79 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4112,13 +4112,13 @@ "link": true }, "node_modules/@iobroker/dm-utils": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/@iobroker/dm-utils/-/dm-utils-0.5.0.tgz", - "integrity": "sha512-HdIggOyx8N4dOLPHTC9pE9iaKR8DKgcQjPrUNB/CGGYM0u3QzVUN2YoXKyM6Mgy8/o/PKPJ3bzv73qzi7CKFYw==", + "version": "0.6.5", + "resolved": "https://registry.npmjs.org/@iobroker/dm-utils/-/dm-utils-0.6.5.tgz", + "integrity": "sha512-xgYLC9mxx1NuFu7PgduEK2W78iDDWtmVGMi1R9lRGxwEZYjSUEOLu9K6CD/5s82hID99d/0JQN9RZQnJwK1FsQ==", "dev": true, "license": "MIT", "dependencies": { - "@iobroker/adapter-core": "^3.1.6" + "@iobroker/adapter-core": "^3.2.2" } }, "node_modules/@iobroker/eslint-config": { @@ -52844,7 +52844,7 @@ "@foxriver76/iob-component-lib": "^0.1.6", "@honkhonk/vite-plugin-svgr": "^1.1.0", "@iobroker/admin-component-easy-access": "^1.0.8", - "@iobroker/dm-utils": "^0.5.0", + "@iobroker/dm-utils": "^0.6.5", "@iobroker/socket-client": "^3.1.2", "@originjs/vite-plugin-commonjs": "^1.0.3", "@react-leaflet/core": "^2.1.0", @@ -52904,7 +52904,7 @@ }, "devDependencies": { "@craco/craco": "^7.1.0", - "@iobroker/dm-utils": "^0.5.0" + "@iobroker/dm-utils": "^0.6.5" } }, "packages/jsonConfig": { diff --git a/packages/admin/src-admin/package.json b/packages/admin/src-admin/package.json index 799285c7c..964bd3285 100644 --- a/packages/admin/src-admin/package.json +++ b/packages/admin/src-admin/package.json @@ -35,7 +35,7 @@ "@foxriver76/iob-component-lib": "^0.1.6", "@honkhonk/vite-plugin-svgr": "^1.1.0", "@iobroker/admin-component-easy-access": "^1.0.8", - "@iobroker/dm-utils": "^0.5.0", + "@iobroker/dm-utils": "^0.6.5", "@iobroker/socket-client": "^3.1.2", "@originjs/vite-plugin-commonjs": "^1.0.3", "@react-leaflet/core": "^2.1.0", @@ -100,4 +100,4 @@ ] ], "version": "7.3.2" -} \ No newline at end of file +} diff --git a/packages/dm-gui-components/package.json b/packages/dm-gui-components/package.json index 7ffa59c83..2b153b72a 100644 --- a/packages/dm-gui-components/package.json +++ b/packages/dm-gui-components/package.json @@ -53,6 +53,6 @@ }, "devDependencies": { "@craco/craco": "^7.1.0", - "@iobroker/dm-utils": "^0.5.0" + "@iobroker/dm-utils": "^0.6.5" } } diff --git a/packages/dm-gui-components/src/Communication.tsx b/packages/dm-gui-components/src/Communication.tsx index 656f7a017..684993055 100644 --- a/packages/dm-gui-components/src/Communication.tsx +++ b/packages/dm-gui-components/src/Communication.tsx @@ -36,8 +36,8 @@ import { type ThemeType, type IobTheme, I18n, + Icon, } from '@iobroker/adapter-react-v5'; -import { type ConfigItemPanel } from '@iobroker/json-config'; import type { ActionBase, ControlBase, @@ -45,6 +45,8 @@ import type { DeviceInfo, DeviceRefresh, InstanceDetails, + JsonFormSchema, + ActionButton, } from '@iobroker/dm-utils'; import { getTranslation } from './Utils'; @@ -70,12 +72,12 @@ export type CommunicationProps = { }; interface CommunicationForm { - title?: string | null | undefined; - label?: string | null | undefined; // same as title + title?: ioBroker.StringOrTranslated | null | undefined; + label?: ioBroker.StringOrTranslated | null | undefined; // same as title noTranslation?: boolean; // Do not translate title/label - schema?: ConfigItemPanel; + schema?: JsonFormSchema; data?: Record; - handleClose?: (data?: Record) => void; + buttons?: (ActionButton | 'apply' | 'cancel')[]; } interface InputAction extends ActionBase { @@ -96,7 +98,7 @@ export type CommunicationState = { message: string; handleClose: (confirmation?: boolean) => void; } | null; - form: CommunicationForm | null; + form: (CommunicationForm & { handleClose?: (data?: Record) => void }) | null; progress: { open: boolean; progress: number; @@ -144,7 +146,7 @@ interface DmActionResponse extends DmResponse { }; message?: string; confirm?: string; - form?: any; + form?: CommunicationForm; progress?: { open: boolean; progress: number; @@ -497,10 +499,57 @@ class Communication

); } + getOkButton(button?: ActionButton | 'apply' | 'cancel'): React.JSX.Element { + if (typeof button === 'string') { + button = undefined; + } + return ( + + ); + } + + getCancelButton(button?: ActionButton | 'apply' | 'cancel'): React.JSX.Element { + if (typeof button === 'string') { + button = undefined; + } + return ( + + ); + } + renderFormDialog(): React.JSX.Element | null { if (!this.state.form || !this.state.form.schema) { return null; } + let buttons: React.JSX.Element[]; + if (this.state.form.buttons) { + buttons = []; + this.state.form.buttons.forEach((button: ActionButton | 'apply' | 'cancel'): void => { + if (button === 'apply' || (button as ActionButton).type === 'apply') { + buttons.push(this.getOkButton(button)); + } else { + buttons.push(this.getCancelButton(button)); + } + }); + } else { + buttons = [this.getOkButton(), this.getCancelButton()]; + } return (

socket={this.props.socket as AdminConnection} onChange={(data: Record) => { console.log('handleFormChange', { data }); - const form: CommunicationForm | null | undefined = { ...this.state.form }; + const form: CommunicationForm & { handleClose?: (data?: Record) => void } = { + ...this.state.form, + }; if (form) { form.data = data; this.setState({ form }); @@ -536,25 +587,7 @@ class Communication

dateFormat={this.props.dateFormat} /> - - - - + {buttons}

); } diff --git a/packages/dm-gui-components/src/DeviceStatus.tsx b/packages/dm-gui-components/src/DeviceStatus.tsx index 4ff0ce59f..695a94e52 100644 --- a/packages/dm-gui-components/src/DeviceStatus.tsx +++ b/packages/dm-gui-components/src/DeviceStatus.tsx @@ -147,6 +147,7 @@ export default function DeviceStatus(params: DeviceStatusProps): React.JSX.Eleme
{status.battery === 'charging' ? : } {status.battery !== 'charging' ? ( + // @ts-expect-error fixed in dm-utils status.battery.includes('V') || status.battery.includes('mV') ? (

{status.battery}

) : (