Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added property onLoaded to json config sendTo #2245

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading