Skip to content

Commit 610c6af

Browse files
committed
FileManager: fix ts issues (ui.file_manager.common.ts, ui.file_manager.file_actions_button.ts, ui.file_manager.notification_manager.js, ui.file_manager.notification.progress_panel.js)
1 parent 34bfca5 commit 610c6af

17 files changed

+884
-673
lines changed

packages/devextreme/js/__internal/ui/file_manager/file_items_controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import {
1919
pathCombine,
2020
} from '@js/file_management/utils';
2121
import type { Properties as FileManagerProperties } from '@js/ui/file_manager';
22-
import { whenSome } from '@js/ui/file_manager/ui.file_manager.common';
2322
import type { FileManagerActions } from '@ts/ui/file_manager/ui.file_manager';
23+
import { whenSome } from '@ts/ui/file_manager/ui.file_manager.common';
2424

2525
const DEFAULT_ROOT_FILE_SYSTEM_ITEM_NAME = 'Files';
2626

@@ -945,7 +945,7 @@ export class FileItemsController {
945945

946946
if (!args.cancel) {
947947
deferred.resolve();
948-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-boolean-literal-compare
948+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-boolean-literal-compare
949949
} else if (args.cancel === true) {
950950
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
951951
return deferred.reject({
Lines changed: 94 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,111 @@
1-
import { when, Deferred } from '../../core/utils/deferred';
2-
import { extend } from '../../core/utils/extend';
3-
import { noop } from '../../core/utils/common';
4-
import { isFunction, isDefined } from '../../core/utils/type';
1+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2+
import { noop } from '@js/core/utils/common';
3+
import { Deferred, when } from '@js/core/utils/deferred';
4+
import { extend } from '@js/core/utils/extend';
5+
import { isDefined, isFunction } from '@js/core/utils/type';
56

6-
export const whenSome = function(arg, onSuccess, onError) {
7-
onSuccess = onSuccess || noop;
8-
onError = onError || noop;
7+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
8+
export const whenSome = (arg, onSuccess?, onError?) => {
9+
// eslint-disable-next-line no-param-reassign
10+
onSuccess = onSuccess || noop;
11+
// eslint-disable-next-line no-param-reassign
12+
onError = onError || noop;
913

10-
if(!Array.isArray(arg)) {
11-
arg = [ arg ];
12-
}
14+
if (!Array.isArray(arg)) {
15+
// eslint-disable-next-line no-param-reassign
16+
arg = [arg];
17+
}
1318

14-
const deferreds = arg.map((item, index) => {
15-
return when(item)
16-
.then(
17-
result => {
18-
isFunction(onSuccess) && onSuccess({ item, index, result });
19-
return result;
20-
},
21-
error => {
22-
if(!error) {
23-
error = { };
24-
}
25-
error.index = index;
26-
isFunction(onError) && onError(error);
27-
return new Deferred().resolve().promise();
28-
});
29-
});
19+
const deferreds = arg.map((item, index) => when(item).then(
20+
(result) => {
21+
if (isFunction(onSuccess)) {
22+
onSuccess({ item, index, result });
23+
}
24+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
25+
return result;
26+
},
27+
(error?) => {
28+
if (!error) {
29+
// eslint-disable-next-line no-param-reassign
30+
error = {};
31+
}
32+
error.index = index;
33+
if (isFunction(onError)) {
34+
onError(error);
35+
}
36+
// @ts-expect-error ts-error
37+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
38+
return new Deferred().resolve().promise();
39+
},
40+
));
3041

31-
return when.apply(null, deferreds);
42+
// eslint-disable-next-line prefer-spread
43+
return when.apply(null, deferreds);
3244
};
3345

34-
export const getDisplayFileSize = function(byteSize) {
35-
const sizesTitles = [ 'B', 'KB', 'MB', 'GB', 'TB' ];
36-
let index = 0;
37-
let displaySize = byteSize;
38-
while(displaySize >= 1024 && index <= sizesTitles.length - 1) {
39-
displaySize /= 1024;
40-
index++;
41-
}
42-
displaySize = Math.round(displaySize * 10) / 10;
43-
return `${displaySize} ${sizesTitles[index]}`;
46+
export const getDisplayFileSize = (byteSize): string => {
47+
const sizesTitles = ['B', 'KB', 'MB', 'GB', 'TB'];
48+
let index = 0;
49+
let displaySize = byteSize;
50+
while (displaySize >= 1024 && index <= sizesTitles.length - 1) {
51+
displaySize /= 1024;
52+
index += 1;
53+
}
54+
displaySize = Math.round(displaySize * 10) / 10;
55+
return `${displaySize} ${sizesTitles[index]}`;
4456
};
4557

46-
export const extendAttributes = function(targetObject, sourceObject, objectKeysArray) {
47-
objectKeysArray.forEach(objectKey => {
48-
extend(true, targetObject, isDefined(sourceObject[objectKey])
49-
? { [objectKey]: sourceObject[objectKey] }
50-
: {});
51-
});
52-
return targetObject;
58+
export const extendAttributes = (
59+
targetObject,
60+
sourceObject,
61+
objectKeysArray,
62+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
63+
) => {
64+
objectKeysArray.forEach((objectKey) => {
65+
extend(
66+
true,
67+
targetObject,
68+
isDefined(sourceObject[objectKey])
69+
? { [objectKey]: sourceObject[objectKey] }
70+
: {},
71+
);
72+
});
73+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
74+
return targetObject;
5375
};
5476

77+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
5578
export const findItemsByKeys = (itemInfos, keys) => {
56-
const itemMap = {};
57-
keys.forEach(key => {
58-
itemMap[key] = null;
59-
});
79+
const itemMap = {};
80+
keys.forEach((key): void => {
81+
itemMap[key] = null;
82+
});
6083

61-
itemInfos.forEach(itemInfo => {
62-
const key = itemInfo.fileItem.key;
63-
if(Object.prototype.hasOwnProperty.call(itemMap, key)) {
64-
itemMap[key] = itemInfo;
65-
}
66-
});
84+
itemInfos.forEach((itemInfo): void => {
85+
const { key } = itemInfo.fileItem;
86+
if (Object.prototype.hasOwnProperty.call(itemMap, key)) {
87+
itemMap[key] = itemInfo;
88+
}
89+
});
6790

68-
const result = [];
69-
keys.forEach(key => {
70-
const itemInfo = itemMap[key];
71-
if(itemInfo) {
72-
result.push(itemInfo);
73-
}
74-
});
91+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
92+
const result: any[] = [];
93+
keys.forEach((key): void => {
94+
const itemInfo = itemMap[key];
95+
if (itemInfo) {
96+
result.push(itemInfo);
97+
}
98+
});
7599

76-
return result;
100+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
101+
return result;
77102
};
78103

79-
export const getMapFromObject = function(object) {
80-
const keys = Object.keys(object);
81-
const values = [];
82-
keys.forEach(key => values.push(object[key]));
83-
return { keys, values };
104+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
105+
export const getMapFromObject = (object) => {
106+
const keys = Object.keys(object);
107+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
108+
const values: any[] = [];
109+
keys.forEach((key) => values.push(object[key]));
110+
return { keys, values };
84111
};

packages/devextreme/js/__internal/ui/file_manager/ui.file_manager.context_menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import type {
1111
ContextMenuShowingEvent,
1212
Properties as FileManagerProperties,
1313
} from '@js/ui/file_manager';
14-
import { extendAttributes } from '@js/ui/file_manager/ui.file_manager.common';
1514
import type { OptionChanged } from '@ts/core/widget/types';
1615
import type { WidgetProperties } from '@ts/core/widget/widget';
1716
import Widget from '@ts/core/widget/widget';
1817
import type { FileManagerCommandManager } from '@ts/ui/file_manager/ui.file_manager.command_manager';
18+
import { extendAttributes } from '@ts/ui/file_manager/ui.file_manager.common';
1919

2020
const FILEMANAGER_CONTEXT_MEMU_CLASS = 'dx-filemanager-context-menu';
2121

packages/devextreme/js/__internal/ui/file_manager/ui.file_manager.dialog.folder_chooser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import messageLocalization from '@js/common/core/localization/message';
33
import $, { type dxElementWrapper } from '@js/core/renderer';
44
import { extend } from '@js/core/utils/extend';
5-
import { getMapFromObject } from '@js/ui/file_manager/ui.file_manager.common';
5+
import { getMapFromObject } from '@ts/ui/file_manager/ui.file_manager.common';
66
import type { DialogOptions } from '@ts/ui/file_manager/ui.file_manager.dialog';
77
import FileManagerDialogBase from '@ts/ui/file_manager/ui.file_manager.dialog';
88
import FileManagerFilesTreeView from '@ts/ui/file_manager/ui.file_manager.files_tree_view';
Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,79 @@
1-
import $ from '../../core/renderer';
2-
import { extend } from '../../core/utils/extend';
3-
4-
import Widget from '../widget/ui.widget';
5-
import Button from '../button';
1+
import $ from '@js/core/renderer';
2+
import type { ClickEvent } from '@js/ui/button';
3+
import Button from '@js/ui/button';
4+
import type { OptionChanged } from '@ts/core/widget/types';
5+
import type { WidgetProperties } from '@ts/core/widget/widget';
6+
import Widget from '@ts/core/widget/widget';
67

78
const FILE_MANAGER_FILE_ACTIONS_BUTTON = 'dx-filemanager-file-actions-button';
89
const FILE_MANAGER_FILE_ACTIONS_BUTTON_ACTIVATED = 'dx-filemanager-file-actions-button-activated';
910
const ACTIVE_STATE_CLASS = 'dx-state-active';
1011

11-
class FileManagerFileActionsButton extends Widget {
12+
interface FileManagerFileActionsButtonOptions extends WidgetProperties {
13+
cssClass?: string;
14+
onClick?: (e: ClickEvent) => void;
15+
}
1216

13-
_initMarkup() {
14-
this._createClickAction();
17+
class FileManagerFileActionsButton extends Widget<FileManagerFileActionsButtonOptions> {
18+
_button?: Button;
1519

16-
const $button = $('<div>');
20+
_clickAction?: (e: Partial<ClickEvent>) => void;
1721

18-
this.$element()
19-
.append($button)
20-
.addClass(FILE_MANAGER_FILE_ACTIONS_BUTTON);
22+
_initMarkup(): void {
23+
this._createClickAction();
2124

22-
this._button = this._createComponent($button, Button, {
23-
icon: 'overflow',
24-
stylingMode: 'text',
25-
onClick: e => this._raiseClick(e)
26-
});
25+
const $button = $('<div>');
2726

28-
super._initMarkup();
29-
}
27+
this.$element().append($button).addClass(FILE_MANAGER_FILE_ACTIONS_BUTTON);
3028

31-
_createClickAction() {
32-
this._clickAction = this._createActionByOption('onClick');
33-
}
29+
this._button = this._createComponent($button, Button, {
30+
icon: 'overflow',
31+
stylingMode: 'text',
32+
onClick: (e): void => this._raiseClick(e),
33+
});
3434

35-
_raiseClick(e) {
36-
this._clickAction(e);
37-
}
35+
super._initMarkup();
36+
}
3837

39-
_getDefaultOptions() {
40-
return extend(super._getDefaultOptions(), {
41-
cssClass: '',
42-
onClick: null
43-
});
44-
}
38+
_createClickAction(): void {
39+
this._clickAction = this._createActionByOption('onClick');
40+
}
4541

46-
_optionChanged(args) {
47-
const name = args.name;
48-
49-
switch(name) {
50-
case 'cssClass':
51-
this.repaint();
52-
break;
53-
case 'onClick':
54-
this._createClickAction();
55-
break;
56-
default:
57-
super._optionChanged(args);
58-
}
59-
}
42+
_raiseClick(e: ClickEvent): void {
43+
this._clickAction?.(e);
44+
}
6045

61-
setActive(active) {
62-
this.$element().toggleClass(FILE_MANAGER_FILE_ACTIONS_BUTTON_ACTIVATED, active);
63-
setTimeout(() => this._button.$element().toggleClass(ACTIVE_STATE_CLASS, active));
64-
}
46+
_getDefaultOptions(): FileManagerFileActionsButtonOptions {
47+
return {
48+
...super._getDefaultOptions(),
49+
cssClass: '',
50+
onClick: undefined,
51+
};
52+
}
6553

54+
_optionChanged(args: OptionChanged<FileManagerFileActionsButtonOptions>): void {
55+
const { name } = args;
56+
57+
switch (name) {
58+
case 'cssClass':
59+
this.repaint();
60+
break;
61+
case 'onClick':
62+
this._createClickAction();
63+
break;
64+
default:
65+
super._optionChanged(args);
66+
}
67+
}
68+
69+
setActive(active: boolean): void {
70+
this.$element().toggleClass(
71+
FILE_MANAGER_FILE_ACTIONS_BUTTON_ACTIVATED,
72+
active,
73+
);
74+
// eslint-disable-next-line no-restricted-globals
75+
setTimeout(() => this._button?.$element().toggleClass(ACTIVE_STATE_CLASS, active));
76+
}
6677
}
6778

6879
export default FileManagerFileActionsButton;

packages/devextreme/js/__internal/ui/file_manager/ui.file_manager.file_uploader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import $ from '@js/core/renderer';
55
import { Deferred } from '@js/core/utils/deferred';
66
import { getInnerHeight, setHeight, setWidth } from '@js/core/utils/size';
77
import { hasWindow } from '@js/core/utils/window';
8-
import { whenSome } from '@js/ui/file_manager/ui.file_manager.common';
98
import FileUploader from '@js/ui/file_uploader';
109
import type { OptionChanged } from '@ts/core/widget/types';
1110
import type { WidgetProperties } from '@ts/core/widget/widget';
1211
import Widget from '@ts/core/widget/widget';
12+
import { whenSome } from '@ts/ui/file_manager/ui.file_manager.common';
1313

1414
const FILE_MANAGER_FILE_UPLOADER_CLASS = 'dx-filemanager-fileuploader';
1515
const FILE_MANAGER_FILE_UPLOADER_DROPZONE_PLACEHOLDER_CLASS = 'dx-filemanager-fileuploader-dropzone-placeholder';

packages/devextreme/js/__internal/ui/file_manager/ui.file_manager.files_tree_view.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import { Deferred } from '@js/core/utils/deferred';
66
import { getImageContainer } from '@js/core/utils/icon';
77
import { isNumeric } from '@js/core/utils/type';
88
import { hasWindow } from '@js/core/utils/window';
9-
import FileManagerFileActionsButton from '@js/ui/file_manager/ui.file_manager.file_actions_button';
109
import TreeViewSearch from '@js/ui/tree_view';
1110
import type { WidgetProperties } from '@ts/core/widget/widget';
1211
import Widget from '@ts/core/widget/widget';
1312
import type FileManagerContextMenu from '@ts/ui/file_manager/ui.file_manager.context_menu';
13+
import FileManagerFileActionsButton from '@ts/ui/file_manager/ui.file_manager.file_actions_button';
1414

1515
const FILE_MANAGER_DIRS_TREE_CLASS = 'dx-filemanager-dirs-tree';
1616
const FILE_MANAGER_DIRS_TREE_FOCUSED_ITEM_CLASS = 'dx-filemanager-focused-item';

0 commit comments

Comments
 (0)