@iobroker/adapter-react-v5 7.5.0 → 7.5.2

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.
@@ -151,21 +151,31 @@ interface DragWrapperProps {
151
151
  children: JSX.Element | null;
152
152
  }
153
153
  interface ObjectCustomDialogProps {
154
- t: Translate;
155
- lang: ioBroker.Languages;
154
+ allVisibleObjects: boolean;
155
+ customsInstances: string[];
156
156
  expertMode?: boolean;
157
+ isFloatComma: boolean;
158
+ lang: ioBroker.Languages;
159
+ objectIDs: string[];
157
160
  objects: Record<string, ioBroker.Object>;
161
+ onClose: () => void;
162
+ reportChangedIds: (ids: string[]) => void;
158
163
  socket: Connection;
164
+ systemConfig: ioBroker.SystemConfigObject;
165
+ t: Translate;
159
166
  theme: IobTheme;
160
167
  themeName: ThemeName;
161
168
  themeType: ThemeType;
162
- customsInstances: string[];
163
- objectIDs: string[];
169
+ }
170
+ interface ObjectMoveRenameDialogProps {
171
+ childrenIds: string[];
172
+ expertMode: boolean;
173
+ id: string;
174
+ objectType: ioBroker.ObjectType | undefined;
164
175
  onClose: () => void;
165
- reportChangedIds: (ids: string[]) => void;
166
- isFloatComma: boolean;
167
- allVisibleObjects: boolean;
168
- systemConfig: ioBroker.SystemConfigObject;
176
+ socket: Connection;
177
+ t: Translate;
178
+ theme: IobTheme;
169
179
  }
170
180
  interface ObjectBrowserValueProps {
171
181
  /** State type */
@@ -258,6 +268,7 @@ export interface ObjectBrowserProps {
258
268
  /** Allow selection of non-objects (virtual branches) */
259
269
  allowNonObjects?: boolean;
260
270
  objectCustomDialog?: React.FC<ObjectCustomDialogProps>;
271
+ objectMoveRenameDialog?: React.FC<ObjectMoveRenameDialogProps>;
261
272
  objectAddBoolean?: boolean;
262
273
  objectEditBoolean?: boolean;
263
274
  objectStatesView?: boolean;
@@ -384,11 +395,8 @@ interface ObjectBrowserState {
384
395
  aliasMenu: string;
385
396
  /** Show rename dialog */
386
397
  showRenameDialog: {
387
- value: string;
388
398
  id: string;
389
- extended: boolean;
390
- renameAllChildren: boolean;
391
- hasChildren: boolean;
399
+ childrenIds: string[];
392
400
  } | null;
393
401
  }
394
402
  export declare class ObjectBrowserClass extends Component<ObjectBrowserProps, ObjectBrowserState> {
@@ -550,8 +558,6 @@ export declare class ObjectBrowserClass extends Component<ObjectBrowserProps, Ob
550
558
  */
551
559
  private _exportObjects;
552
560
  renderExportDialog(): JSX.Element | null;
553
- static calculateNewId(oldId: string, newId: string, id: string): string;
554
- renameObject(oldId: string, newId: string, withChildren: boolean): Promise<void>;
555
561
  renderRenameDialog(): JSX.Element | null;
556
562
  private handleJsonUpload;
557
563
  toolTipObjectCreating: () => JSX.Element[] | string;
@@ -2217,7 +2217,7 @@ export class ObjectBrowserClass extends Component {
2217
2217
  props.socket
2218
2218
  .getState(`system.adapter.${this.defaultHistory}.alive`)
2219
2219
  .then(state => {
2220
- if (!state || !state.val) {
2220
+ if (!state?.val) {
2221
2221
  this.defaultHistory = '';
2222
2222
  }
2223
2223
  })
@@ -2248,8 +2248,8 @@ export class ObjectBrowserClass extends Component {
2248
2248
  this.setState({ loaded: true, updating: false, columnsForAdmin }, () => this.expandAllSelected(() => this.onAfterSelect()));
2249
2249
  }
2250
2250
  }
2251
- catch (e1) {
2252
- this.showError(e1);
2251
+ catch (error) {
2252
+ this.showError(error);
2253
2253
  }
2254
2254
  }
2255
2255
  /**
@@ -3367,138 +3367,12 @@ export class ObjectBrowserClass extends Component {
3367
3367
  ")"),
3368
3368
  React.createElement(Button, { color: "grey", variant: "contained", onClick: () => this.setState({ showExportDialog: false, showAllExportOptions: false }), startIcon: React.createElement(IconClose, null) }, this.props.t('ra_Cancel')))));
3369
3369
  }
3370
- static calculateNewId(oldId, newId, id) {
3371
- // find common name
3372
- const oldParts = oldId.split('.');
3373
- const newParts = newId.split('.');
3374
- let i = 0;
3375
- while (oldParts[i] === newParts[i]) {
3376
- i++;
3377
- }
3378
- const parts = id.split('.');
3379
- parts.splice(0, i + 1);
3380
- return `${newId}.${parts.join('.')}`;
3381
- }
3382
- async renameObject(oldId, newId, withChildren) {
3383
- if (oldId === newId) {
3384
- return;
3385
- }
3386
- let obj;
3387
- try {
3388
- obj = await this.props.socket.getObject(oldId);
3389
- }
3390
- catch {
3391
- // ignore
3392
- }
3393
- let state;
3394
- if (obj?.type === 'state') {
3395
- state = await this.props.socket.getState(oldId);
3396
- }
3397
- if (withChildren) {
3398
- const children = Object.keys(this.objects).filter(id => id.startsWith(`${oldId}.`));
3399
- for (const id of children) {
3400
- const nid = ObjectBrowserClass.calculateNewId(oldId, newId, id);
3401
- // calculate new id
3402
- await this.renameObject(id, nid, false);
3403
- }
3404
- }
3405
- if (obj) {
3406
- await this.props.socket.setObject(newId, obj);
3407
- if (state) {
3408
- await this.props.socket.setState(newId, state);
3409
- }
3410
- await this.props.socket.delObject(oldId);
3411
- }
3412
- }
3413
3370
  renderRenameDialog() {
3414
3371
  if (!this.state.showRenameDialog) {
3415
3372
  return null;
3416
3373
  }
3417
- let newID;
3418
- let notExtendedPossible = true;
3419
- const parts = this.state.showRenameDialog.id.split('.');
3420
- if (this.state.showRenameDialog.extended) {
3421
- newID = `${parts[0]}.${parts[1]}.${this.state.showRenameDialog.value}`;
3422
- parts.pop();
3423
- const parentId = parts.join('.');
3424
- const newParts = newID.split('.');
3425
- newParts.splice(parentId.length);
3426
- if (newParts.join('.') !== parentId) {
3427
- notExtendedPossible = false;
3428
- }
3429
- }
3430
- else {
3431
- parts.pop();
3432
- newID = `${parts.join('.')}.${this.state.showRenameDialog.value}`;
3433
- }
3434
- return (React.createElement(Dialog, { open: !0, maxWidth: "md", fullWidth: true, onClose: () => this.setState({ showRenameDialog: null }) },
3435
- React.createElement(DialogTitle, null, this.props.t('ra_Rename object')),
3436
- React.createElement(DialogContent, null,
3437
- React.createElement(TextField, { value: this.state.showRenameDialog.value, onChange: e => {
3438
- const value = e.target.value
3439
- .replace(Utils.FORBIDDEN_CHARS, '_')
3440
- .replace(/\s/g, '_')
3441
- .replace(/,/g, '_')
3442
- .replace(/__/g, '_')
3443
- .replace(/__/g, '_');
3444
- if (!this.state.showRenameDialog.extended && value.includes('.')) {
3445
- this.setState({
3446
- showRenameDialog: {
3447
- ...this.state.showRenameDialog,
3448
- value: e.target.value.replace(/\./g, '_'),
3449
- },
3450
- });
3451
- }
3452
- else {
3453
- this.setState({
3454
- showRenameDialog: { ...this.state.showRenameDialog, value },
3455
- });
3456
- }
3457
- }, variant: "standard", fullWidth: true, label: this.props.t('ra_New object ID'), helperText: `${this.props.t('ra_New object ID')}: ${newID}` }),
3458
- this.props.expertMode ? (React.createElement(FormControlLabel, { control: React.createElement(Checkbox, { disabled: !notExtendedPossible, checked: this.state.showRenameDialog.extended, onChange: () => {
3459
- if (this.state.showRenameDialog.extended) {
3460
- const parts = this.state.showRenameDialog.value.split('.');
3461
- this.setState({
3462
- showRenameDialog: {
3463
- ...this.state.showRenameDialog,
3464
- value: parts.pop(),
3465
- extended: false,
3466
- },
3467
- });
3468
- }
3469
- else {
3470
- const parts = this.state.showRenameDialog.id.split('.');
3471
- parts.shift(); // remove "javascript"
3472
- parts.shift(); // remove "0"
3473
- parts.pop(); // remove the last part
3474
- this.setState({
3475
- showRenameDialog: {
3476
- ...this.state.showRenameDialog,
3477
- value: `${parts.join('.')}.${this.state.showRenameDialog.value}`,
3478
- extended: true,
3479
- },
3480
- });
3481
- }
3482
- } }), label: this.props.t('ra_Edit full path') })) : null,
3483
- this.state.showRenameDialog.hasChildren ? (React.createElement(FormControlLabel, { control: React.createElement(Checkbox, { checked: this.state.showRenameDialog.renameAllChildren, onChange: () => {
3484
- this.setState({
3485
- showRenameDialog: {
3486
- ...this.state.showRenameDialog,
3487
- renameAllChildren: !this.state.showRenameDialog.renameAllChildren,
3488
- },
3489
- });
3490
- } }), label: this.props.t('ra_Rename all children') })) : null),
3491
- React.createElement(DialogActions, null,
3492
- React.createElement(Button, { disabled: !this.state.showRenameDialog.value ||
3493
- this.state.showRenameDialog.value.endsWith('.') ||
3494
- newID === this.state.showRenameDialog.id, color: "primary", variant: "contained", onClick: async () => {
3495
- await this.renameObject(this.state.showRenameDialog.id, newID, this.state.showRenameDialog.hasChildren &&
3496
- this.state.showRenameDialog.renameAllChildren);
3497
- this.setState({ showRenameDialog: null });
3498
- } }, newID !== this.state.showRenameDialog.id && this.objects[newID]
3499
- ? this.props.t('ra_Replace')
3500
- : this.props.t('ra_Rename')),
3501
- React.createElement(Button, { variant: "contained", color: "grey", onClick: () => this.setState({ showRenameDialog: null }), startIcon: React.createElement(IconClose, null) }, this.props.t('ra_Cancel')))));
3374
+ const ObjectMoveRenameDialog = this.props.objectMoveRenameDialog;
3375
+ return (React.createElement(ObjectMoveRenameDialog, { expertMode: this.props.expertMode, onClose: () => this.setState({ showRenameDialog: null }), id: this.state.showRenameDialog.id, childrenIds: this.state.showRenameDialog.childrenIds, theme: this.props.theme, socket: this.props.socket, t: this.props.t, objectType: this.objects[this.state.showRenameDialog.id]?.type }));
3502
3376
  }
3503
3377
  handleJsonUpload(evt) {
3504
3378
  const target = evt.target;
@@ -5978,22 +5852,22 @@ export class ObjectBrowserClass extends Component {
5978
5852
  RENAME: {
5979
5853
  key: '8',
5980
5854
  visibility: !!(!this.props.notEditable &&
5855
+ this.props.objectMoveRenameDialog &&
5981
5856
  !item.data.id.startsWith('system.') &&
5982
5857
  item.data.id.split('.').length > 2 &&
5983
5858
  (this.props.expertMode ||
5984
5859
  item.data.id.startsWith('javascript.0.') ||
5985
5860
  item.data.id.startsWith('0_userdata.0.'))),
5986
5861
  icon: React.createElement(DriveFileRenameOutline, null),
5987
- label: this.props.t('ra_Rename'),
5862
+ label: this.props.t('ra_Rename_Move_Copy'),
5988
5863
  onClick: () => {
5864
+ const ids = Object.keys(this.objects);
5865
+ const parentId = `${item.data.id}.`;
5989
5866
  this.setState({
5990
5867
  showContextMenu: null,
5991
5868
  showRenameDialog: {
5992
5869
  id: item.data.id,
5993
- value: item.data.id.split('.').pop(),
5994
- extended: false,
5995
- hasChildren: !!item.children?.length,
5996
- renameAllChildren: true,
5870
+ childrenIds: ids.filter(id => id.startsWith(parentId)),
5997
5871
  },
5998
5872
  });
5999
5873
  },