Skip to content

Commit

Permalink
added property onLoaded to json config sendTo (#2245)
Browse files Browse the repository at this point in the history
- closes #2241
  • Loading branch information
foxriver76 authored Dec 2, 2023
1 parent 30b8f21 commit 5ecb91b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ The icons may not be reused in other projects without the proper flaticon licens
-->
## Changelog
### **WORK IN PROGRESS**
* (foxriver76) add property `onLoaded` to `sendTo` json config
* (foxriver76) fixed easy admin height

### 6.12.6 (2023-12-01)
Expand Down
17 changes: 14 additions & 3 deletions src/src/components/JsonConfigComponent/ConfigSendto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,20 @@ function findNetworkAddressOfHost(obj: Record<string, any>, 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;
themeName: string;
style: Record<string, any>;
className: string;
data: Record<string, any>;
schema: Record<string, any>;
schema: ConfigSendToSchema;
adapterName: string;
instance:number;
commandRunning: boolean;
Expand Down Expand Up @@ -167,7 +173,12 @@ class ConfigSendto extends ConfigGeneric<ConfigSendToProps, ConfigSendToState> {
return;
}
}
this.setState({ _error: '', _message: '', hostname });

await new Promise<void>(resolve => { this.setState({ _error: '', _message: '', hostname }, resolve); });

if (this.props.schema.onLoaded) {
this._onClick();
}
}

renderErrorDialog() {
Expand Down Expand Up @@ -314,7 +325,7 @@ class ConfigSendto extends ConfigGeneric<ConfigSendToProps, ConfigSendToState> {
/>;
}

renderItem(error: Error | undefined, disabled: boolean /* , defaultValue */) {
renderItem(error: Error | undefined, disabled: boolean) {
const icon = this.getIcon();

return <div className={this.props.classes.fullWidth}>
Expand Down
1 change: 1 addition & 0 deletions src/src/components/JsonConfigComponent/SCHEMA.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5ecb91b

Please sign in to comment.