From 2d5987bc74cc4bcbc287bab5ef372192a6673a20 Mon Sep 17 00:00:00 2001 From: foxriver76 Date: Sat, 2 Dec 2023 11:31:03 +0100 Subject: [PATCH] added property onLoaded to json config sendTo - closes #2241 --- README.md | 3 +++ .../JsonConfigComponent/ConfigSendto.tsx | 17 ++++++++++++++--- .../components/JsonConfigComponent/SCHEMA.md | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 82c214664..f39efd9dd 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,9 @@ The icons may not be reused in other projects without the proper flaticon licens ### **WORK IN PROGRESS** --> ## Changelog +### **WORK IN PROGRESS** +* (foxriver76) add property `onLoaded` to `sendTo` json config + ### 6.12.6 (2023-12-01) * (foxriver76) fixed JSON config file component if no initial value exists * (bluefox) added the creation of a state or of a device possibility to the context menu diff --git a/src/src/components/JsonConfigComponent/ConfigSendto.tsx b/src/src/components/JsonConfigComponent/ConfigSendto.tsx index 93abf89f4..67a340f48 100644 --- a/src/src/components/JsonConfigComponent/ConfigSendto.tsx +++ b/src/src/components/JsonConfigComponent/ConfigSendto.tsx @@ -126,6 +126,12 @@ function findNetworkAddressOfHost(obj: Record, localIp: string) { return hostIp; } +interface ConfigSendToSchema { + /** If the component should execute the sendTo command once initially too */ + onLoaded?: boolean; + [other: string]: any; +} + interface ConfigSendToProps extends ConfigGenericProps { socket: AdminConnection; themeType: string; @@ -133,7 +139,7 @@ interface ConfigSendToProps extends ConfigGenericProps { style: Record; className: string; data: Record; - schema: Record; + schema: ConfigSendToSchema; adapterName: string; instance:number; commandRunning: boolean; @@ -167,7 +173,12 @@ class ConfigSendto extends ConfigGeneric { return; } } - this.setState({ _error: '', _message: '', hostname }); + + await new Promise(resolve => { this.setState({ _error: '', _message: '', hostname }, resolve); }); + + if (this.props.schema.onLoaded) { + this._onClick(); + } } renderErrorDialog() { @@ -314,7 +325,7 @@ class ConfigSendto extends ConfigGeneric { />; } - renderItem(error: Error | undefined, disabled: boolean /* , defaultValue */) { + renderItem(error: Error | undefined, disabled: boolean) { const icon = this.getIcon(); return
diff --git a/src/src/components/JsonConfigComponent/SCHEMA.md b/src/src/components/JsonConfigComponent/SCHEMA.md index 586cca2c0..e52663c2f 100644 --- a/src/src/components/JsonConfigComponent/SCHEMA.md +++ b/src/src/components/JsonConfigComponent/SCHEMA.md @@ -178,6 +178,7 @@ Possible types: - `useNative` - if adapter returns a result with `native` attribute it will be used for configuration. If `saveConfig` is true, the user will be requested to save the configuration. - `showProcess` - Show spinner while request is in progress - `timeout` - timeout for request in ms. Default: none. + - `onLoaded` - execute the button logic once initially - `setState` - button that set instance's state - `id` - `system.adapter.myAdapter.%INSTANCE%.test`, you can use the placeholder `%INSTANCE%` to replace it with the current instance name