@iobroker/json-config 6.17.12 → 6.17.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/package.json +27 -27
  2. package/src/JsonConfig.tsx +0 -710
  3. package/src/JsonConfigComponent/ChipInput.tsx +0 -752
  4. package/src/JsonConfigComponent/ConfigAccordion.tsx +0 -278
  5. package/src/JsonConfigComponent/ConfigAlive.tsx +0 -74
  6. package/src/JsonConfigComponent/ConfigAutocomplete.tsx +0 -108
  7. package/src/JsonConfigComponent/ConfigAutocompleteSendTo.tsx +0 -183
  8. package/src/JsonConfigComponent/ConfigCRON.jsx +0 -101
  9. package/src/JsonConfigComponent/ConfigCertCollection.tsx +0 -102
  10. package/src/JsonConfigComponent/ConfigCertificateSelect.tsx +0 -92
  11. package/src/JsonConfigComponent/ConfigCertificates.tsx +0 -202
  12. package/src/JsonConfigComponent/ConfigCheckLicense.jsx +0 -662
  13. package/src/JsonConfigComponent/ConfigCheckbox.tsx +0 -67
  14. package/src/JsonConfigComponent/ConfigChip.jsx +0 -81
  15. package/src/JsonConfigComponent/ConfigColor.tsx +0 -86
  16. package/src/JsonConfigComponent/ConfigCoordinates.tsx +0 -234
  17. package/src/JsonConfigComponent/ConfigCustom.tsx +0 -246
  18. package/src/JsonConfigComponent/ConfigDatePicker.tsx +0 -48
  19. package/src/JsonConfigComponent/ConfigDeviceManager.tsx +0 -33
  20. package/src/JsonConfigComponent/ConfigFile.jsx +0 -181
  21. package/src/JsonConfigComponent/ConfigFileSelector.jsx +0 -520
  22. package/src/JsonConfigComponent/ConfigFunc.jsx +0 -90
  23. package/src/JsonConfigComponent/ConfigGeneric.tsx +0 -1027
  24. package/src/JsonConfigComponent/ConfigIP.jsx +0 -96
  25. package/src/JsonConfigComponent/ConfigImageSendTo.jsx +0 -79
  26. package/src/JsonConfigComponent/ConfigImageUpload.jsx +0 -114
  27. package/src/JsonConfigComponent/ConfigInstanceSelect.jsx +0 -172
  28. package/src/JsonConfigComponent/ConfigInterface.jsx +0 -112
  29. package/src/JsonConfigComponent/ConfigJsonEditor.jsx +0 -103
  30. package/src/JsonConfigComponent/ConfigLanguage.tsx +0 -153
  31. package/src/JsonConfigComponent/ConfigLicense.jsx +0 -148
  32. package/src/JsonConfigComponent/ConfigNumber.tsx +0 -207
  33. package/src/JsonConfigComponent/ConfigObjectId.jsx +0 -113
  34. package/src/JsonConfigComponent/ConfigPanel.tsx +0 -360
  35. package/src/JsonConfigComponent/ConfigPassword.jsx +0 -160
  36. package/src/JsonConfigComponent/ConfigPattern.jsx +0 -50
  37. package/src/JsonConfigComponent/ConfigPort.tsx +0 -232
  38. package/src/JsonConfigComponent/ConfigRoom.jsx +0 -90
  39. package/src/JsonConfigComponent/ConfigSelect.jsx +0 -124
  40. package/src/JsonConfigComponent/ConfigSelectSendTo.tsx +0 -251
  41. package/src/JsonConfigComponent/ConfigSendto.tsx +0 -340
  42. package/src/JsonConfigComponent/ConfigSetState.jsx +0 -116
  43. package/src/JsonConfigComponent/ConfigSlider.jsx +0 -97
  44. package/src/JsonConfigComponent/ConfigStaticDivider.jsx +0 -51
  45. package/src/JsonConfigComponent/ConfigStaticHeader.jsx +0 -63
  46. package/src/JsonConfigComponent/ConfigStaticImage.jsx +0 -48
  47. package/src/JsonConfigComponent/ConfigStaticText.jsx +0 -72
  48. package/src/JsonConfigComponent/ConfigTable.tsx +0 -1040
  49. package/src/JsonConfigComponent/ConfigTabs.tsx +0 -150
  50. package/src/JsonConfigComponent/ConfigText.tsx +0 -188
  51. package/src/JsonConfigComponent/ConfigTextSendTo.tsx +0 -102
  52. package/src/JsonConfigComponent/ConfigTimePicker.tsx +0 -63
  53. package/src/JsonConfigComponent/ConfigTopic.jsx +0 -78
  54. package/src/JsonConfigComponent/ConfigUUID.tsx +0 -55
  55. package/src/JsonConfigComponent/ConfigUser.jsx +0 -104
  56. package/src/JsonConfigComponent/index.tsx +0 -435
  57. package/src/JsonConfigComponent/wrapper/Components/CustomModal.jsx +0 -145
  58. package/src/JsonConfigComponent/wrapper/Components/Editor.jsx +0 -65
  59. package/src/Utils.jsx +0 -1683
  60. package/src/index.tsx +0 -14
  61. package/src/types.d.ts +0 -372
@@ -1,150 +0,0 @@
1
- import React from 'react';
2
- import { withStyles } from '@mui/styles';
3
-
4
- import { Tabs, Tab } from '@mui/material';
5
-
6
- import type { ConfigItemTabs } from '#JC/types';
7
- import ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';
8
- import ConfigPanel from './ConfigPanel';
9
- import {bool} from "prop-types";
10
-
11
- const styles: Record<string, any> = {
12
- tabs: {
13
- height: '100%',
14
- width: '100%',
15
- },
16
- panel: {
17
- height: 'calc(100% - 48px)',
18
- width: '100%',
19
- display: 'block',
20
- },
21
- };
22
-
23
- interface ConfigTabsProps extends ConfigGenericProps {
24
- schema: ConfigItemTabs;
25
- dialogName?: string;
26
- }
27
-
28
- interface ConfigTabsState extends ConfigGenericState {
29
- tab?: string;
30
- }
31
-
32
- class ConfigTabs extends ConfigGeneric<ConfigTabsProps, ConfigTabsState> {
33
- constructor(props: ConfigTabsProps) {
34
- super(props);
35
-
36
- let tab = ((window as any)._localStorage as Storage || window.localStorage).getItem(`${this.props.dialogName || 'App'}.${this.props.adapterName}`) || Object.keys(this.props.schema.items)[0];
37
- if (!Object.keys(this.props.schema.items).includes(tab)) {
38
- tab = Object.keys(this.props.schema.items)[0];
39
- }
40
- Object.assign(this.state, { tab });
41
- }
42
-
43
- render() {
44
- const items = this.props.schema.items;
45
-
46
- return <div className={this.props.classes.tabs}>
47
- <Tabs
48
- variant="scrollable"
49
- scrollButtons="auto"
50
- style={this.props.schema.tabsStyle}
51
- value={this.state.tab}
52
- onChange={(e, tab) => {
53
- ((window as any)._localStorage as Storage || window.localStorage).setItem(`${this.props.dialogName || 'App'}.${this.props.adapterName}`, tab);
54
- this.setState({ tab });
55
- }}
56
- >
57
- {Object.keys(items).map(name => {
58
- let disabled: boolean;
59
- if (this.props.custom) {
60
- const hidden = this.executeCustom(
61
- items[name].hidden,
62
- this.props.data,
63
- this.props.customObj,
64
- this.props.instanceObj,
65
- this.props.index,
66
- this.props.globalData,
67
- );
68
- if (hidden) {
69
- return null;
70
- }
71
- disabled = this.executeCustom(
72
- items[name].disabled,
73
- this.props.data,
74
- this.props.customObj,
75
- this.props.instanceObj,
76
- this.props.index,
77
- this.props.globalData,
78
- ) as boolean;
79
- } else {
80
- const hidden: boolean = this.execute(
81
- items[name].hidden,
82
- false,
83
- this.props.data,
84
- this.props.index,
85
- this.props.globalData,
86
- ) as boolean;
87
- if (hidden) {
88
- return null;
89
- }
90
- disabled = this.execute(
91
- items[name].disabled,
92
- false,
93
- this.props.data,
94
- this.props.index,
95
- this.props.globalData,
96
- ) as boolean;
97
- }
98
- return <Tab
99
- wrapped
100
- disabled={disabled}
101
- key={name}
102
- value={name}
103
- iconPosition={this.props.schema.iconPosition || 'start'}
104
- icon={this.getIcon(items[name].icon)}
105
- label={this.getText(items[name].label)}
106
- />;
107
- })}
108
- </Tabs>
109
- <ConfigPanel
110
- isParentTab
111
- changed={this.props.changed}
112
- key={this.state.tab}
113
- index={1001}
114
- arrayIndex={this.props.arrayIndex}
115
- globalData={this.props.globalData}
116
- onCommandRunning={this.props.onCommandRunning}
117
- commandRunning={this.props.commandRunning}
118
- className={this.props.classes.panel}
119
- socket={this.props.socket}
120
- adapterName={this.props.adapterName}
121
- instance={this.props.instance}
122
- common={this.props.common}
123
- customs={this.props.customs}
124
- alive={this.props.alive}
125
- themeType={this.props.themeType}
126
- themeName={this.props.themeName}
127
- data={this.props.data}
128
- originalData={this.props.originalData}
129
- systemConfig={this.props.systemConfig}
130
- onError={this.props.onError}
131
- onChange={this.props.onChange}
132
- multiEdit={this.props.multiEdit}
133
- dateFormat={this.props.dateFormat}
134
- isFloatComma={this.props.isFloatComma}
135
- // disabled={disabled}
136
- imagePrefix={this.props.imagePrefix}
137
- changeLanguage={this.props.changeLanguage}
138
- forceUpdate={this.props.forceUpdate}
139
- registerOnForceUpdate={this.props.registerOnForceUpdate}
140
- customObj={this.props.customObj}
141
- instanceObj={this.props.instanceObj}
142
- custom={this.props.custom}
143
- schema={items[this.state.tab]}
144
- table={this.props.table}
145
- />
146
- </div>;
147
- }
148
- }
149
-
150
- export default withStyles(styles)(ConfigTabs);
@@ -1,188 +0,0 @@
1
- import React from 'react';
2
- import { withStyles } from '@mui/styles';
3
-
4
- import {
5
- Autocomplete,
6
- TextField,
7
- TextareaAutosize, InputAdornment, IconButton,
8
- } from '@mui/material';
9
-
10
- import {
11
- Close as CloseIcon,
12
- } from '@mui/icons-material';
13
-
14
- import { I18n } from '@iobroker/adapter-react-v5';
15
-
16
- import type { ConfigItemText } from '#JC/types';
17
- import ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';
18
-
19
- const styles: Record<string, any> = {
20
- indeterminate: {
21
- opacity: 0.5,
22
- },
23
- label: {
24
- width: '100%',
25
- fontSize: 16,
26
- },
27
- helper: {
28
- width: '100%',
29
- fontSize: 12,
30
- },
31
- error: {
32
- width: '100%',
33
- fontSize: 12,
34
- color: '#FF0000',
35
- },
36
- };
37
-
38
- interface ConfigTextProps extends ConfigGenericProps {
39
- schema: ConfigItemText;
40
- }
41
-
42
- interface ConfigTextState extends ConfigGenericState {
43
- oldValue?: string;
44
- }
45
-
46
- class ConfigText extends ConfigGeneric<ConfigTextProps, ConfigTextState> {
47
- private updateTimeout: ReturnType<typeof setTimeout> | null = null;
48
-
49
- componentDidMount() {
50
- super.componentDidMount();
51
- let value = ConfigGeneric.getValue(this.props.data, this.props.attr);
52
-
53
- if (Array.isArray(value) && this.props.multiEdit) {
54
- value = ConfigGeneric.DIFFERENT_VALUE;
55
- this.setState({ value, oldValue: value });
56
- return;
57
- }
58
-
59
- this.setState({ value, oldValue: value });
60
- }
61
-
62
- static getDerivedStateFromProps(props: ConfigTextProps, state: ConfigTextState) {
63
- if (props.multiEdit && state.value === ConfigGeneric.DIFFERENT_VALUE) {
64
- return ConfigGeneric.DIFFERENT_VALUE;
65
- }
66
-
67
- let value = ConfigGeneric.getValue(props.data, props.attr);
68
-
69
- if (value !== null && value !== undefined) {
70
- value = value.toString();
71
- }
72
-
73
- if (value === null || value === undefined || (value !== state.value && value !== state.oldValue)) {
74
- return { value };
75
- }
76
- return null;
77
- }
78
-
79
- renderItem(error?: boolean, disabled?: boolean) {
80
- const isIndeterminate = Array.isArray(this.state.value) || this.state.value === ConfigGeneric.DIFFERENT_VALUE;
81
-
82
- if (this.state.oldValue !== null && this.state.oldValue !== undefined) {
83
- this.updateTimeout && clearTimeout(this.updateTimeout);
84
- this.updateTimeout = setTimeout(() => {
85
- this.updateTimeout = null;
86
- this.setState({ oldValue: null });
87
- }, 30);
88
- } else if (this.updateTimeout) {
89
- clearTimeout(this.updateTimeout);
90
- this.updateTimeout = null;
91
- }
92
-
93
- if (isIndeterminate) {
94
- const autoCompleteOptions = ConfigGeneric.getValue(this.props.data, this.props.attr);
95
- const arr = [...autoCompleteOptions].map(item => ({ label: item.toString(), value: item }));
96
- arr.unshift({ label: I18n.t(ConfigGeneric.DIFFERENT_LABEL), value: ConfigGeneric.DIFFERENT_VALUE });
97
-
98
- return <Autocomplete
99
- className={this.props.classes.indeterminate}
100
- fullWidth
101
- value={arr[0]}
102
- // getOptionSelected={(option, value) => option.label === value.label}
103
- onChange={(_, value) => {
104
- const val = value ? value.value : '';
105
- this.onChange(this.props.attr, val, () => {
106
- this.setState({ value: val, oldValue: val });
107
- });
108
- }}
109
- options={arr}
110
- getOptionLabel={option => option.label}
111
- renderInput={params => <TextField
112
- variant="standard"
113
- {...params}
114
- error={!!error}
115
- placeholder={this.getText(this.props.schema.placeholder)}
116
- inputProps={{
117
- ...params.inputProps,
118
- maxLength: this.props.schema.maxLength || this.props.schema.max || undefined,
119
- readOnly: this.props.schema.readOnly || false,
120
- }}
121
- label={this.getText(this.props.schema.label)}
122
- helperText={this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation)}
123
- disabled={!!disabled}
124
- />}
125
- />;
126
- }
127
- if (this.props.schema.minRows > 1) {
128
- const helper = this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation);
129
- return <div style={{ width: '100%' }}>
130
- {this.props.schema.label ? <div className={this.props.classes.label}>{this.getText(this.props.schema.label)}</div> : null}
131
- <TextareaAutosize
132
- // variant="standard"
133
- style={{
134
- width: '100%',
135
- resize: 'vertical',
136
- backgroundColor: this.props.themeType === 'dark' ? '#363636' : '#cccccc',
137
- color: this.props.themeType === 'dark' ? '#fff' : '#111',
138
- }}
139
- minRows={this.props.schema.minRows}
140
- maxRows={this.props.schema.maxRows}
141
- value={this.state.value === null || this.state.value === undefined ? '' : this.state.value}
142
- disabled={!!disabled}
143
- readOnly={this.props.schema.readOnly || false}
144
- onChange={e => {
145
- const value = e.target.value;
146
- this.setState({ value, oldValue: this.state.value }, () =>
147
- this.onChange(this.props.attr, value || ''));
148
- }}
149
- placeholder={this.getText(this.props.schema.placeholder)}
150
- />
151
- {helper || error ? <div className={error ? this.props.classes.error : this.props.classes.helper}>{error || helper}</div> : null}
152
- </div>;
153
- }
154
- return <TextField
155
- variant="standard"
156
- fullWidth
157
- value={this.state.value === null || this.state.value === undefined ? '' : this.state.value}
158
- error={!!error}
159
- disabled={!!disabled}
160
- inputProps={{
161
- maxLength: this.props.schema.maxLength || this.props.schema.max || undefined,
162
- readOnly: this.props.schema.readOnly || false,
163
- }}
164
- // eslint-disable-next-line react/jsx-no-duplicate-props
165
- InputProps={{
166
- endAdornment: this.state.value && !this.props.schema.noClearButton ? <InputAdornment position="end">
167
- <IconButton
168
- size="small"
169
- onClick={() => this.setState({ value: '', oldValue: this.state.value }, () =>
170
- this.onChange(this.props.attr, ''))}
171
- >
172
- <CloseIcon />
173
- </IconButton>
174
- </InputAdornment> : null,
175
- }}
176
- onChange={e => {
177
- const value = e.target.value;
178
- this.setState({ value, oldValue: this.state.value }, () =>
179
- this.onChange(this.props.attr, value));
180
- }}
181
- placeholder={this.getText(this.props.schema.placeholder)}
182
- label={this.getText(this.props.schema.label)}
183
- helperText={this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation)}
184
- />;
185
- }
186
- }
187
-
188
- export default withStyles(styles)(ConfigText);
@@ -1,102 +0,0 @@
1
- import React from 'react';
2
- import { withStyles } from '@mui/styles';
3
-
4
- import {
5
- TextField,
6
- IconButton,
7
- } from '@mui/material';
8
-
9
- import { IconCopy, Utils } from '@iobroker/adapter-react-v5';
10
-
11
- import type { ConfigItemSendTo } from '#JC/types';
12
- import ConfigGeneric, {type ConfigGenericProps, type ConfigGenericState} from './ConfigGeneric';
13
-
14
- const styles: Record<string, any> = {
15
- fullWidth: {
16
- width: '100%',
17
- },
18
- };
19
-
20
- interface ConfigTextSendToProps extends ConfigGenericProps {
21
- schema: ConfigItemSendTo;
22
- }
23
-
24
- interface ConfigTextSendToState extends ConfigGenericState {
25
- text?: string;
26
- context?: string;
27
- }
28
-
29
- class ConfigTextSendTo extends ConfigGeneric<ConfigTextSendToProps, ConfigTextSendToState> {
30
- componentDidMount() {
31
- super.componentDidMount();
32
-
33
- this.askInstance();
34
- }
35
-
36
- askInstance() {
37
- if (this.props.alive) {
38
- let data: Record<string, any> | undefined = this.props.schema.data;
39
- if (data === undefined && this.props.schema.jsonData) {
40
- const dataStr: string = this.getPattern(this.props.schema.jsonData);
41
- try {
42
- data = JSON.parse(dataStr);
43
- } catch (e) {
44
- console.error(`Cannot parse json data: ${dataStr}`);
45
- }
46
- }
47
-
48
- if (data === undefined) {
49
- data = null;
50
- }
51
-
52
- this.props.socket.sendTo(`${this.props.adapterName}.${this.props.instance}`, this.props.schema.command || 'send', data)
53
- .then(text => this.setState({ text: text || '', context: this.getContext() }));
54
- }
55
- }
56
-
57
- getContext() {
58
- const context: Record<string, any> = {};
59
- if (Array.isArray(this.props.schema.alsoDependsOn)) {
60
- this.props.schema.alsoDependsOn.forEach(attr =>
61
- context[attr] = ConfigGeneric.getValue(this.props.data, attr));
62
- }
63
- return JSON.stringify(context);
64
- }
65
-
66
- renderItem(/* error, disabled, defaultValue */) {
67
- if (this.state.text === undefined) {
68
- return null;
69
- }
70
-
71
- if (this.props.alive) {
72
- const context = this.getContext();
73
- if (context !== this.state.context) {
74
- setTimeout(() => this.askInstance(), 300);
75
- }
76
- }
77
-
78
- if (this.props.schema.container === 'text') {
79
- return <TextField
80
- variant="standard"
81
- fullWidth
82
- InputProps={{
83
- endAdornment: this.props.schema.copyToClipboard ? <IconButton
84
- size="small"
85
- onClick={() => {
86
- Utils.copyToClipboard(this.state.text);
87
- window.alert('Copied');
88
- }}
89
- >
90
- <IconCopy />
91
- </IconButton> : undefined,
92
- }}
93
- value={this.state.text}
94
- label={this.getText(this.props.schema.label)}
95
- helperText={this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation)}
96
- />;
97
- }
98
- return <div className={this.props.classes.fullWidth}>{this.state.text}</div>;
99
- }
100
- }
101
-
102
- export default withStyles(styles)(ConfigTextSendTo);
@@ -1,63 +0,0 @@
1
- import React from 'react';
2
-
3
- import { TimePicker } from '@mui/x-date-pickers';
4
-
5
- import type { ConfigItemTimePicker } from '#JC/types';
6
- import ConfigGeneric, { type ConfigGenericProps } from './ConfigGeneric';
7
-
8
- interface ConfigTimePickerProps extends ConfigGenericProps {
9
- schema: ConfigItemTimePicker;
10
- dialogName?: string;
11
- }
12
-
13
- export default class ConfigTimePicker extends ConfigGeneric<ConfigTimePickerProps> {
14
- componentDidMount() {
15
- super.componentDidMount();
16
- const value = ConfigGeneric.getValue(this.props.data, this.props.attr);
17
- this.setState({ value });
18
- }
19
-
20
- renderItem(_error: unknown, disabled: boolean) {
21
- // the format could be 'HH:mm:ss' or 'HH:mm'
22
- const shortFormat = this.props.schema.returnFormat !== 'HH:mm:ss';
23
-
24
- const value: never = new Date(Date.parse(`Thu, 01 Jan 1970 ${this.state.value || '00:00:00'}`)) as never;
25
-
26
- return <TimePicker
27
- sx={theme => ({
28
- width: '100%',
29
- borderBottom: `1px solid ${theme.palette.text.primary}`,
30
- '& fieldset': {
31
- display: 'none',
32
- },
33
- '& input': {
34
- padding: `${theme.spacing(1.5)} 0 4px 0`,
35
- },
36
- '& .MuiInputAdornment-root': {
37
- marginLeft: 0,
38
- marginTop: 1, // it is already in spaces
39
- },
40
- '& label': {
41
- transform: 'translate(0px, -9px) scale(0.75)',
42
- },
43
- })}
44
- ampm={this.props.systemConfig.dateFormat.includes('/')}
45
- timeSteps={this.props.schema.timeSteps || this.props.schema.timesteps || { hours: 1, minutes: 5, seconds: 5 }}
46
- format={this.props.schema.format || 'HH:mm:ss'}
47
- disabled={!!disabled}
48
- value={value}
49
- onChange={(newValue: Date) => {
50
- let strValue = newValue.toTimeString();
51
- strValue = (newValue as any) instanceof Date ? (newValue as Date).toTimeString().split(' ')[0] : newValue.toTimeString();
52
- if (shortFormat) {
53
- strValue = strValue.split(':').slice(0, 2).join(':');
54
- }
55
-
56
- this.setState({ value: strValue }, () =>
57
- this.onChange(this.props.attr, this.state.value));
58
- }}
59
- views={this.props.schema.views || ['hours', 'minutes', 'seconds']}
60
- label={this.getText(this.props.schema.label)}
61
- />;
62
- }
63
- }
@@ -1,78 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { withStyles } from '@mui/styles';
4
-
5
- import { TextField } from '@mui/material';
6
-
7
- import ConfigGeneric from './ConfigGeneric';
8
-
9
- const styles = () => ({
10
- fullWidth: {
11
- width: '100%',
12
- },
13
- icon: {
14
- width: 16,
15
- height: 16,
16
- marginRight: 8,
17
- },
18
- });
19
-
20
- function convertID2Topic(id, prefix, namespace) {
21
- let topic;
22
- if (namespace && id.substring(0, namespace.length) === namespace) {
23
- topic = id.substring(namespace.length + 1);
24
- } else {
25
- topic = id;
26
- }
27
- topic = topic.replace(/\./g, '/').replace(/_/g, ' ');
28
- return topic;
29
- }
30
-
31
- class ConfigTopic extends ConfigGeneric {
32
- componentDidMount() {
33
- super.componentDidMount();
34
- const value = ConfigGeneric.getValue(this.props.data, this.props.attr);
35
- if (!value && this.props.customObj && this.props.customObj._id) {
36
- const topic = convertID2Topic(this.props.customObj._id, null, `${this.props.adapterName}.${this.props.instance}`);
37
- this.setState({ value: topic });
38
- } else {
39
- this.setState({ value: value || '' });
40
- }
41
- }
42
-
43
- renderItem(error, disabled /* , defaultValue */) {
44
- return <TextField
45
- variant="standard"
46
- fullWidth
47
- inputProps={{ maxLength: this.props.schema.maxLength || this.props.schema.max || undefined }}
48
- value={this.state.value}
49
- error={!!error}
50
- disabled={disabled}
51
- placeholder={this.getText(this.props.schema.placeholder)}
52
- label={this.getText(this.props.schema.label)}
53
- helperText={this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation)}
54
- onChange={e => {
55
- const value = e.target.value;
56
- this.setState({ value }, () =>
57
- this.onChange(this.props.attr, value));
58
- }}
59
- />;
60
- }
61
- }
62
-
63
- ConfigTopic.propTypes = {
64
- socket: PropTypes.object.isRequired,
65
- themeType: PropTypes.string,
66
- themeName: PropTypes.string,
67
- style: PropTypes.object,
68
- className: PropTypes.string,
69
- data: PropTypes.object.isRequired,
70
- schema: PropTypes.object,
71
- onError: PropTypes.func,
72
- onChange: PropTypes.func,
73
- adapterName: PropTypes.string,
74
- instance: PropTypes.number,
75
- customObj: PropTypes.object,
76
- };
77
-
78
- export default withStyles(styles)(ConfigTopic);
@@ -1,55 +0,0 @@
1
- import React from 'react';
2
-
3
- import {
4
- TextField,
5
- IconButton,
6
- } from '@mui/material';
7
-
8
- import { ContentCopy as IconCopy } from '@mui/icons-material';
9
-
10
- import { Utils, I18n } from '@iobroker/adapter-react-v5';
11
-
12
- import type { ConfigItemUUID } from '#JC/types';
13
- import ConfigGeneric, {type ConfigGenericProps, type ConfigGenericState} from './ConfigGeneric';
14
-
15
- interface ConfigUUIDProps extends ConfigGenericProps {
16
- schema: ConfigItemUUID;
17
- }
18
-
19
- interface ConfigUUIDState extends ConfigGenericState {
20
- uuid?: string;
21
- }
22
-
23
- class ConfigUUID extends ConfigGeneric<ConfigUUIDProps, ConfigUUIDState> {
24
- async componentDidMount() {
25
- super.componentDidMount();
26
-
27
- const uuidObj = await this.props.socket.getObject('system.meta.uuid');
28
- this.setState({ uuid: uuidObj?.native?.uuid || 'unknown' });
29
- }
30
-
31
- renderItem(error: unknown, disabled: boolean) {
32
- return <TextField
33
- variant="standard"
34
- fullWidth
35
- error={!!error}
36
- disabled={!!disabled}
37
- inputProps={{ readOnly: true }}
38
- // eslint-disable-next-line react/jsx-no-duplicate-props
39
- InputProps={{
40
- endAdornment: <IconButton onClick={() => {
41
- Utils.copyToClipboard(this.state.uuid);
42
- window.alert(I18n.t('ra_Copied %s', this.state.uuid));
43
- }}
44
- >
45
- <IconCopy />
46
- </IconButton>,
47
- }}
48
- value={this.state.uuid || ''}
49
- label={this.getText(this.props.schema.label) || I18n.t('ra_Serial number (UUID)')}
50
- helperText={this.renderHelp(this.props.schema.help, this.props.schema.helpLink, this.props.schema.noTranslation)}
51
- />;
52
- }
53
- }
54
-
55
- export default ConfigUUID;