@griddo/ax 10.2.25 → 10.3.0
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.
- package/package.json +2 -2
- package/public/img/icons/excel.png +0 -0
- package/public/img/icons/pdf.png +0 -0
- package/public/img/icons/word.png +0 -0
- package/public/img/icons/zip.png +0 -0
- package/src/GlobalStore.tsx +3 -0
- package/src/__mocks__/store/GenericStore.ts +3 -0
- package/src/__tests__/components/Fields/FileField/FileField.test.tsx +34 -8
- package/src/__tests__/components/Gallery/GalleryPanel/GalleryDragAndDrop/GalleryDragAndDrop.test.tsx +1 -1
- package/src/api/files.tsx +171 -1
- package/src/api/users.tsx +5 -2
- package/src/components/ActionMenu/index.tsx +5 -13
- package/src/components/BackFolder/index.tsx +28 -0
- package/src/components/BackFolder/style.tsx +33 -0
- package/src/components/BulkSelectionOptions/index.tsx +4 -8
- package/src/components/Button/index.tsx +8 -3
- package/src/components/Button/style.tsx +5 -3
- package/src/components/ElementsTooltip/index.tsx +22 -7
- package/src/components/ElementsTooltip/style.tsx +2 -2
- package/src/components/Fields/FileField/index.tsx +7 -7
- package/src/components/Fields/TextField/index.tsx +3 -0
- package/src/components/FileGallery/FolderItem/index.tsx +39 -0
- package/src/components/FileGallery/FolderItem/style.tsx +31 -0
- package/src/components/FileGallery/GalleryPanel/DetailPanel/index.tsx +164 -0
- package/src/components/FileGallery/GalleryPanel/DetailPanel/style.tsx +113 -0
- package/src/components/FileGallery/GalleryPanel/index.tsx +42 -0
- package/src/components/FileGallery/GalleryPanel/style.tsx +7 -0
- package/src/components/FileGallery/GridItem/index.tsx +47 -0
- package/src/components/FileGallery/GridItem/style.tsx +51 -0
- package/src/components/FileGallery/index.tsx +304 -0
- package/src/components/FileGallery/style.tsx +173 -0
- package/src/components/FileGallery/utils.tsx +19 -0
- package/src/components/Gallery/GalleryPanel/GalleryDragAndDrop/index.tsx +4 -6
- package/src/components/Icon/components/Back.js +10 -0
- package/src/components/Icon/components/ClosePanel.js +12 -0
- package/src/components/Icon/components/NewFolder.js +10 -0
- package/src/components/Icon/components/OpenPanel.js +12 -0
- package/src/components/Icon/svgs/Back.svg +3 -0
- package/src/components/Icon/svgs/Close_panel.svg +3 -0
- package/src/components/Icon/svgs/New-folder.svg +3 -0
- package/src/components/Icon/svgs/Open_panel.svg +3 -0
- package/src/components/Modal/index.tsx +7 -5
- package/src/components/Modal/style.tsx +6 -6
- package/src/components/ProgressBar/index.tsx +3 -2
- package/src/components/ProgressBar/style.tsx +5 -3
- package/src/components/TableList/index.tsx +3 -2
- package/src/components/TableList/style.tsx +4 -0
- package/src/components/Toast/style.tsx +2 -2
- package/src/components/index.tsx +4 -0
- package/src/containers/FileDrive/actions.tsx +386 -0
- package/src/containers/FileDrive/constants.tsx +24 -0
- package/src/containers/FileDrive/index.tsx +7 -0
- package/src/containers/FileDrive/interfaces.tsx +59 -0
- package/src/containers/FileDrive/reducer.tsx +57 -0
- package/src/containers/FileDrive/utils.tsx +37 -0
- package/src/containers/Gallery/actions.tsx +1 -1
- package/src/containers/Gallery/interfaces.tsx +1 -1
- package/src/helpers/index.tsx +2 -0
- package/src/helpers/objects.tsx +6 -0
- package/src/modules/FileDrive/Breadcrumb/index.tsx +42 -0
- package/src/modules/FileDrive/Breadcrumb/style.tsx +18 -0
- package/src/modules/FileDrive/BulkGridHeader/GridHeader/index.tsx +37 -0
- package/src/modules/FileDrive/BulkGridHeader/GridHeader/style.tsx +19 -0
- package/src/modules/FileDrive/BulkGridHeader/index.tsx +35 -0
- package/src/modules/FileDrive/BulkGridHeader/style.tsx +17 -0
- package/src/modules/FileDrive/BulkListHeader/TableHeader/index.tsx +42 -0
- package/src/modules/FileDrive/BulkListHeader/TableHeader/style.tsx +53 -0
- package/src/modules/FileDrive/BulkListHeader/index.tsx +35 -0
- package/src/modules/FileDrive/BulkListHeader/style.tsx +17 -0
- package/src/modules/FileDrive/FileDragAndDrop/index.tsx +249 -0
- package/src/{components/Fields/FileField → modules/FileDrive}/FileDragAndDrop/style.tsx +50 -9
- package/src/modules/FileDrive/FileModal/DetailPanel/index.tsx +170 -0
- package/src/modules/FileDrive/FileModal/DetailPanel/style.tsx +81 -0
- package/src/modules/FileDrive/FileModal/index.tsx +129 -0
- package/src/modules/FileDrive/FileModal/style.tsx +112 -0
- package/src/modules/FileDrive/FolderItem/index.tsx +180 -0
- package/src/modules/FileDrive/FolderItem/style.tsx +39 -0
- package/src/modules/FileDrive/FolderTree/index.tsx +108 -0
- package/src/modules/FileDrive/FolderTree/style.tsx +69 -0
- package/src/modules/FileDrive/FolderTree/utils.tsx +91 -0
- package/src/modules/FileDrive/GridItem/index.tsx +167 -0
- package/src/modules/FileDrive/GridItem/style.tsx +76 -0
- package/src/modules/FileDrive/ListItem/index.tsx +180 -0
- package/src/modules/FileDrive/ListItem/style.tsx +88 -0
- package/src/modules/FileDrive/atoms.tsx +173 -0
- package/src/modules/FileDrive/helpers.tsx +19 -0
- package/src/modules/FileDrive/index.tsx +670 -0
- package/src/modules/FileDrive/style.tsx +145 -0
- package/src/modules/Sites/SitesList/index.tsx +0 -3
- package/src/routes/multisite.tsx +9 -0
- package/src/routes/site.tsx +9 -0
- package/src/types/index.tsx +63 -0
- package/src/components/Fields/FileField/FileDragAndDrop/index.tsx +0 -188
- package/src/components/Fields/FileField/store.tsx +0 -61
|
@@ -26,11 +26,11 @@ const getHeight = (size: string | undefined) => {
|
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
export const ModalOverlay = styled.div
|
|
29
|
+
export const ModalOverlay = styled.div<{ isChild?: boolean }>`
|
|
30
30
|
position: fixed;
|
|
31
31
|
top: 0;
|
|
32
32
|
left: 0;
|
|
33
|
-
z-index:
|
|
33
|
+
z-index: ${(p) => (p.isChild ? "1260" : "1240")};
|
|
34
34
|
width: 100vw;
|
|
35
35
|
height: 100vh;
|
|
36
36
|
background: ${(p) => p.theme.color.overlay};
|
|
@@ -39,11 +39,11 @@ export const ModalOverlay = styled.div`
|
|
|
39
39
|
}
|
|
40
40
|
`;
|
|
41
41
|
|
|
42
|
-
export const ModalWrapper = styled.div
|
|
42
|
+
export const ModalWrapper = styled.div<{ isChild?: boolean }>`
|
|
43
43
|
position: fixed;
|
|
44
44
|
top: 0;
|
|
45
45
|
left: 0;
|
|
46
|
-
z-index: 1250;
|
|
46
|
+
z-index: ${(p) => (p.isChild ? "1270" : "1250")};
|
|
47
47
|
width: 100%;
|
|
48
48
|
height: 100%;
|
|
49
49
|
overflow-x: hidden;
|
|
@@ -51,7 +51,7 @@ export const ModalWrapper = styled.div`
|
|
|
51
51
|
outline: 0;
|
|
52
52
|
`;
|
|
53
53
|
|
|
54
|
-
export const Modal = styled.div<{ size
|
|
54
|
+
export const Modal = styled.div<{ size?: string; height?: number }>`
|
|
55
55
|
z-index: 100;
|
|
56
56
|
display: flex;
|
|
57
57
|
flex-flow: column nowrap;
|
|
@@ -60,7 +60,7 @@ export const Modal = styled.div<{ size: string | undefined }>`
|
|
|
60
60
|
margin: auto;
|
|
61
61
|
border-radius: 4px;
|
|
62
62
|
width: ${(p) => getWidth(p.size)};
|
|
63
|
-
height: ${(p) => getHeight(p.size)};
|
|
63
|
+
height: ${(p) => (p.height ? `${p.height}px` : getHeight(p.size))};
|
|
64
64
|
box-shadow: ${(p) => p.theme.shadow.shadowXL};
|
|
65
65
|
top: 50%;
|
|
66
66
|
transform: translateY(-50%);
|
|
@@ -3,7 +3,7 @@ import React from "react";
|
|
|
3
3
|
import * as S from "./style";
|
|
4
4
|
|
|
5
5
|
const ProgressBar = (props: IProgressBarProps): JSX.Element => {
|
|
6
|
-
const { percentage } = props;
|
|
6
|
+
const { percentage, inverse = false } = props;
|
|
7
7
|
|
|
8
8
|
const percentageLimits = (min: number, value: number, max: number) => {
|
|
9
9
|
return Math.min(Math.max(min, value), max);
|
|
@@ -11,13 +11,14 @@ const ProgressBar = (props: IProgressBarProps): JSX.Element => {
|
|
|
11
11
|
|
|
12
12
|
return (
|
|
13
13
|
<S.Tracker data-testid="progressbar-tracker">
|
|
14
|
-
<S.ProgressInTracker percentage={percentageLimits(0, percentage, 100)} />
|
|
14
|
+
<S.ProgressInTracker percentage={percentageLimits(0, percentage, 100)} inverse={inverse} />
|
|
15
15
|
</S.Tracker>
|
|
16
16
|
);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
export interface IProgressBarProps {
|
|
20
20
|
percentage: number;
|
|
21
|
+
inverse?: boolean;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export default ProgressBar;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import styled from "styled-components";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const Tracker = styled.div`
|
|
4
4
|
height: ${p => p.theme.spacing.xxs};
|
|
5
5
|
width: 100%;
|
|
6
6
|
border-radius: 2px;
|
|
7
7
|
background-color: #e6e7f8;
|
|
8
8
|
`;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
background-color: ${p => p.theme.color.interactive01};
|
|
10
|
+
const ProgressInTracker = styled.div<{ percentage: number; inverse: boolean }>`
|
|
11
|
+
background-color: ${p => p.inverse ? p.theme.color.interactiveInverse : p.theme.color.interactive01};
|
|
12
12
|
border-radius: 2px;
|
|
13
13
|
height: 100%;
|
|
14
14
|
width: ${p => p.percentage}%;
|
|
15
15
|
`;
|
|
16
|
+
|
|
17
|
+
export { Tracker, ProgressInTracker }
|
|
@@ -6,7 +6,7 @@ import { Loading, Pagination } from "@ax/components";
|
|
|
6
6
|
import * as S from "./style";
|
|
7
7
|
|
|
8
8
|
const TableList = (props: ITableListProps): JSX.Element => {
|
|
9
|
-
const { tableHeader, children, pagination, isLoading, onScroll, hasFixedHeader, tableRef } = props;
|
|
9
|
+
const { tableHeader, children, pagination, isLoading, onScroll, hasFixedHeader, tableRef, className } = props;
|
|
10
10
|
|
|
11
11
|
const showPagination = pagination && pagination.totalItems > pagination.itemsPerPage;
|
|
12
12
|
|
|
@@ -17,7 +17,7 @@ const TableList = (props: ITableListProps): JSX.Element => {
|
|
|
17
17
|
<S.TableHeader hasFixedHeader={hasFixedHeader} data-testid="table-list-header">
|
|
18
18
|
{tableHeader}
|
|
19
19
|
</S.TableHeader>
|
|
20
|
-
{isLoading ? <Loading /> : <S.TableBody data-testid="table-body">{children}</S.TableBody>}
|
|
20
|
+
{isLoading ? <Loading /> : <S.TableBody data-testid="table-body" className={className}>{children}</S.TableBody>}
|
|
21
21
|
</>
|
|
22
22
|
</S.Table>
|
|
23
23
|
<S.PaginationWrapper>
|
|
@@ -46,6 +46,7 @@ export interface ITableListProps {
|
|
|
46
46
|
onScroll?: any;
|
|
47
47
|
hasFixedHeader?: boolean;
|
|
48
48
|
tableRef?: any;
|
|
49
|
+
className?: string;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
export default connect(mapStateToProps, null)(TableList);
|
|
@@ -9,7 +9,7 @@ const Wrapper = styled.div<{ isEditor: boolean }>`
|
|
|
9
9
|
align-items: center;
|
|
10
10
|
border-radius: 4px;
|
|
11
11
|
position: fixed;
|
|
12
|
-
z-index:
|
|
12
|
+
z-index: 2000;
|
|
13
13
|
bottom: ${(p) => p.theme.spacing.m};
|
|
14
14
|
left: ${(p) => (p.isEditor ? `calc(${p.theme.spacing.m} * 1)` : `calc(${p.theme.spacing.m} * 4)`)};
|
|
15
15
|
padding-left: ${(p) => p.theme.spacing.m};
|
|
@@ -68,4 +68,4 @@ const Buttons = styled.div`
|
|
|
68
68
|
align-items: center;
|
|
69
69
|
`;
|
|
70
70
|
|
|
71
|
-
export { Wrapper, Text, ButtonWrapper, Buttons }
|
|
71
|
+
export { Wrapper, Text, ButtonWrapper, Buttons }
|
package/src/components/index.tsx
CHANGED
|
@@ -55,6 +55,7 @@ import {
|
|
|
55
55
|
|
|
56
56
|
import ActionMenu from "./ActionMenu";
|
|
57
57
|
import Avatar from "./Avatar";
|
|
58
|
+
import BackFolder from "./BackFolder";
|
|
58
59
|
import Breadcrumb from "./Breadcrumb";
|
|
59
60
|
import Browser from "./Browser";
|
|
60
61
|
import BrowserContent from "./BrowserContent";
|
|
@@ -69,6 +70,7 @@ import ErrorCenter from "./ErrorCenter";
|
|
|
69
70
|
import ErrorToast from "./ErrorToast";
|
|
70
71
|
import FieldContainer from "./FieldContainer";
|
|
71
72
|
import FieldsBehavior from "./FieldsBehavior";
|
|
73
|
+
import FileGallery from "./FileGallery";
|
|
72
74
|
import Flag from "./Flag";
|
|
73
75
|
import FloatingMenu from "./FloatingMenu";
|
|
74
76
|
import FloatingPanel from "./FloatingPanel";
|
|
@@ -160,6 +162,7 @@ export {
|
|
|
160
162
|
// Components
|
|
161
163
|
ActionMenu,
|
|
162
164
|
Avatar,
|
|
165
|
+
BackFolder,
|
|
163
166
|
Breadcrumb,
|
|
164
167
|
Browser,
|
|
165
168
|
BrowserContent,
|
|
@@ -174,6 +177,7 @@ export {
|
|
|
174
177
|
ErrorToast,
|
|
175
178
|
FieldContainer,
|
|
176
179
|
FieldsBehavior,
|
|
180
|
+
FileGallery,
|
|
177
181
|
Flag,
|
|
178
182
|
FloatingMenu,
|
|
179
183
|
FloatingPanel,
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { Dispatch } from "redux";
|
|
2
|
+
import { IFile, IFilesFolder, IFolder, IFolderTree, IGetFolderParams } from "@ax/types";
|
|
3
|
+
import { files } from "@ax/api";
|
|
4
|
+
import { handleRequest, isReqOk } from "@ax/helpers";
|
|
5
|
+
import { appActions } from "@ax/containers/App";
|
|
6
|
+
import {
|
|
7
|
+
SET_BREADCRUMB,
|
|
8
|
+
SET_CURRENT_FOLDER,
|
|
9
|
+
SET_CURRENT_FOLDER_CONTENT,
|
|
10
|
+
SET_DISPLAY_MODE,
|
|
11
|
+
SET_FOLDERS_TREE,
|
|
12
|
+
SET_IS_UPLOADING,
|
|
13
|
+
SET_SELECTED_TAB,
|
|
14
|
+
SET_UPLOAD_ERROR,
|
|
15
|
+
SET_UPLOAD_SUCCESS,
|
|
16
|
+
} from "./constants";
|
|
17
|
+
import {
|
|
18
|
+
ISetBreadcrumb,
|
|
19
|
+
ISetCurrentFolder,
|
|
20
|
+
ISetCurrentFolderContent,
|
|
21
|
+
ISetDisplayMode,
|
|
22
|
+
ISetFoldersTree,
|
|
23
|
+
ISetIsUploading,
|
|
24
|
+
ISetSelectedTab,
|
|
25
|
+
ISetUploadError,
|
|
26
|
+
ISetUploadSuccess,
|
|
27
|
+
} from "./interfaces";
|
|
28
|
+
import { getNewBreadcrumb } from "./utils";
|
|
29
|
+
|
|
30
|
+
function setCurrentFolderContent(currentFolderContent: IFilesFolder | null): ISetCurrentFolderContent {
|
|
31
|
+
return { type: SET_CURRENT_FOLDER_CONTENT, payload: { currentFolderContent } };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function setCurrentFolder(currentFolderID: number | null): ISetCurrentFolder {
|
|
35
|
+
return { type: SET_CURRENT_FOLDER, payload: { currentFolderID } };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function setBreadcrumb(breadcrumb: IFolderTree[]): ISetBreadcrumb {
|
|
39
|
+
return { type: SET_BREADCRUMB, payload: { breadcrumb } };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function setFoldersTree(foldersTree: IFolderTree[]): ISetFoldersTree {
|
|
43
|
+
return { type: SET_FOLDERS_TREE, payload: { foldersTree } };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function setIsUploading(isUploading: boolean): ISetIsUploading {
|
|
47
|
+
return { type: SET_IS_UPLOADING, payload: { isUploading } };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function setUploadSuccess(isSuccess: boolean): ISetUploadSuccess {
|
|
51
|
+
return { type: SET_UPLOAD_SUCCESS, payload: { isUploading: false, isSuccess } };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function setUploadError(isError: boolean, errorMsg = ""): ISetUploadError {
|
|
55
|
+
return { type: SET_UPLOAD_ERROR, payload: { isUploading: false, isError, errorMsg } };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function setDisplayMode(displayMode: "grid" | "list"): ISetDisplayMode {
|
|
59
|
+
return { type: SET_DISPLAY_MODE, payload: { displayMode } };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function setSelectedTab(selectedTab: "local" | "global"): ISetSelectedTab {
|
|
63
|
+
return { type: SET_SELECTED_TAB, payload: { selectedTab } };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getFolderContent(params: IGetFolderParams): (dispatch: Dispatch, getState: any) => Promise<void> {
|
|
67
|
+
return async (dispatch, getState) => {
|
|
68
|
+
try {
|
|
69
|
+
const { folderID, loading } = params;
|
|
70
|
+
const responseActions = {
|
|
71
|
+
handleSuccess: (data: IFilesFolder) => {
|
|
72
|
+
dispatch(setCurrentFolderContent(data));
|
|
73
|
+
updateBreadcrumb(folderID)(dispatch, getState);
|
|
74
|
+
dispatch(setUploadSuccess(false));
|
|
75
|
+
},
|
|
76
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
77
|
+
};
|
|
78
|
+
const callback = async () => files.getFolderContent(params);
|
|
79
|
+
|
|
80
|
+
const setLoading = loading ? [appActions.setIsLoading] : [];
|
|
81
|
+
|
|
82
|
+
await handleRequest(callback, responseActions, setLoading)(dispatch);
|
|
83
|
+
} catch (e) {
|
|
84
|
+
console.log(e);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function getFoldersTree(siteID: number | "global"): (dispatch: Dispatch) => Promise<void> {
|
|
90
|
+
return async (dispatch) => {
|
|
91
|
+
try {
|
|
92
|
+
const responseActions = {
|
|
93
|
+
handleSuccess: (data: IFolderTree[]) => dispatch(setFoldersTree(data)),
|
|
94
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
95
|
+
};
|
|
96
|
+
const callback = async () => files.getFoldersTree(siteID);
|
|
97
|
+
|
|
98
|
+
await handleRequest(callback, responseActions, [])(dispatch);
|
|
99
|
+
} catch (e) {
|
|
100
|
+
console.log(e);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function updateCurrentFolder(currentFolderID: number | null): (dispatch: Dispatch) => void {
|
|
106
|
+
return async (dispatch) => {
|
|
107
|
+
try {
|
|
108
|
+
dispatch(setCurrentFolder(currentFolderID));
|
|
109
|
+
} catch (e) {
|
|
110
|
+
console.log("Error", e);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function updateBreadcrumb(folderID: number | null): (dispatch: Dispatch, getState: any) => void {
|
|
116
|
+
return (dispatch, getState) => {
|
|
117
|
+
const {
|
|
118
|
+
fileDrive: { foldersTree },
|
|
119
|
+
} = getState();
|
|
120
|
+
|
|
121
|
+
const newBreadcrumb = getNewBreadcrumb(foldersTree, folderID);
|
|
122
|
+
dispatch(setBreadcrumb(newBreadcrumb));
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function createNewFolder(data: {
|
|
127
|
+
folderName: string;
|
|
128
|
+
site: number | "global";
|
|
129
|
+
parentId?: number;
|
|
130
|
+
}): (dispatch: Dispatch, getState: any) => Promise<boolean> {
|
|
131
|
+
return async (dispatch, getState) => {
|
|
132
|
+
try {
|
|
133
|
+
const responseActions = {
|
|
134
|
+
handleSuccess: async () => {
|
|
135
|
+
await getFoldersTree(data.site)(dispatch);
|
|
136
|
+
await getFolderContent({ siteID: data.site, folderID: data.parentId || null })(dispatch, getState);
|
|
137
|
+
},
|
|
138
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
139
|
+
};
|
|
140
|
+
const callback = async () => files.createFolder(data);
|
|
141
|
+
|
|
142
|
+
return await handleRequest(callback, responseActions, [appActions.setIsSaving])(dispatch);
|
|
143
|
+
} catch (e) {
|
|
144
|
+
console.log(e);
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function updateFolder(
|
|
151
|
+
folderID: number,
|
|
152
|
+
data: { parentId: number; folderName: string },
|
|
153
|
+
siteID: number | "global"
|
|
154
|
+
): (dispatch: Dispatch, getState: any) => Promise<boolean> {
|
|
155
|
+
return async (dispatch, getState) => {
|
|
156
|
+
try {
|
|
157
|
+
const {
|
|
158
|
+
fileDrive: { currentFolderID },
|
|
159
|
+
} = getState();
|
|
160
|
+
|
|
161
|
+
const responseActions = {
|
|
162
|
+
handleSuccess: async () => {
|
|
163
|
+
await getFolderContent({ siteID, folderID: currentFolderID })(dispatch, getState);
|
|
164
|
+
await getFoldersTree(siteID)(dispatch);
|
|
165
|
+
},
|
|
166
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
167
|
+
};
|
|
168
|
+
const callback = async () => files.updateFolder(folderID, data);
|
|
169
|
+
|
|
170
|
+
return await handleRequest(callback, responseActions, [])(dispatch);
|
|
171
|
+
} catch (e) {
|
|
172
|
+
console.log(e);
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function deleteFolder(folder: IFolder): (dispatch: Dispatch, getState: any) => Promise<boolean> {
|
|
179
|
+
return async (dispatch, getState) => {
|
|
180
|
+
try {
|
|
181
|
+
const responseActions = {
|
|
182
|
+
handleSuccess: async () => {
|
|
183
|
+
await getFoldersTree(folder.site || "global")(dispatch);
|
|
184
|
+
await getFolderContent({ siteID: folder.site || "global", folderID: folder.parentId })(dispatch, getState);
|
|
185
|
+
},
|
|
186
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
187
|
+
};
|
|
188
|
+
const callback = async () => files.deleteFolder(folder.id);
|
|
189
|
+
|
|
190
|
+
return await handleRequest(callback, responseActions, [])(dispatch);
|
|
191
|
+
} catch (e) {
|
|
192
|
+
console.log(e);
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function uploadFile(
|
|
199
|
+
docFiles: File | File[],
|
|
200
|
+
folderID: number | null,
|
|
201
|
+
siteID: number | "global"
|
|
202
|
+
): (dispatch: Dispatch) => Promise<IFile | null> {
|
|
203
|
+
return async (dispatch) => {
|
|
204
|
+
try {
|
|
205
|
+
dispatch(setIsUploading(true));
|
|
206
|
+
|
|
207
|
+
const filesArr = Array.isArray(docFiles) ? docFiles : [docFiles];
|
|
208
|
+
const uploadPromises = filesArr.map(async (file: File) => {
|
|
209
|
+
const form = new FormData();
|
|
210
|
+
form.append("file", file);
|
|
211
|
+
form.append("site", JSON.stringify(siteID));
|
|
212
|
+
folderID && form.append("folder", JSON.stringify(folderID));
|
|
213
|
+
const uploadedFile = await files.uploadFile(form);
|
|
214
|
+
return { ...uploadedFile, file };
|
|
215
|
+
});
|
|
216
|
+
const results = await Promise.all(uploadPromises);
|
|
217
|
+
const lastUploadedFile = results.reduce((lastResult, result) =>
|
|
218
|
+
result.data.id > lastResult.data.id ? result : lastResult
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
if (isReqOk(lastUploadedFile?.status)) {
|
|
222
|
+
dispatch(setIsUploading(false));
|
|
223
|
+
dispatch(setUploadSuccess(true));
|
|
224
|
+
return lastUploadedFile.data;
|
|
225
|
+
} else {
|
|
226
|
+
dispatch(setUploadError(true, "Error uploading file"));
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
} catch (e) {
|
|
230
|
+
console.log(e);
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function uploadError(error: boolean, msg?: string): (dispatch: Dispatch) => Promise<void> {
|
|
237
|
+
return async (dispatch) => {
|
|
238
|
+
dispatch(setUploadError(error, msg));
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function updateFile(
|
|
243
|
+
fileID: number,
|
|
244
|
+
data: { title: string; alt: string; tags: string[] },
|
|
245
|
+
siteID: number | "global",
|
|
246
|
+
loading = true
|
|
247
|
+
): (dispatch: Dispatch, getState: any) => Promise<boolean> {
|
|
248
|
+
return async (dispatch, getState) => {
|
|
249
|
+
try {
|
|
250
|
+
const {
|
|
251
|
+
fileDrive: { currentFolderID },
|
|
252
|
+
} = getState();
|
|
253
|
+
|
|
254
|
+
const responseActions = {
|
|
255
|
+
handleSuccess: async () => {
|
|
256
|
+
await getFolderContent({ siteID, folderID: currentFolderID, loading })(dispatch, getState);
|
|
257
|
+
},
|
|
258
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
259
|
+
};
|
|
260
|
+
const callback = async () => files.updateFile(fileID, data);
|
|
261
|
+
|
|
262
|
+
return await handleRequest(callback, responseActions, [appActions.setIsSaving])(dispatch);
|
|
263
|
+
} catch (e) {
|
|
264
|
+
console.log(e);
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function deleteFile(
|
|
271
|
+
fileID: number | number[],
|
|
272
|
+
siteID: number | "global"
|
|
273
|
+
): (dispatch: Dispatch, getState: any) => Promise<boolean> {
|
|
274
|
+
return async (dispatch, getState) => {
|
|
275
|
+
try {
|
|
276
|
+
const {
|
|
277
|
+
fileDrive: { currentFolderID },
|
|
278
|
+
} = getState();
|
|
279
|
+
|
|
280
|
+
const responseActions = {
|
|
281
|
+
handleSuccess: async () => {
|
|
282
|
+
await getFolderContent({ siteID, folderID: currentFolderID })(dispatch, getState);
|
|
283
|
+
},
|
|
284
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
285
|
+
};
|
|
286
|
+
const callback = async () => (Array.isArray(fileID) ? files.deleteFilesBulk(fileID) : files.deleteFile(fileID));
|
|
287
|
+
|
|
288
|
+
return await handleRequest(callback, responseActions, [])(dispatch);
|
|
289
|
+
} catch (e) {
|
|
290
|
+
console.log(e);
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function moveFile(
|
|
297
|
+
fileID: number | number[],
|
|
298
|
+
folderID: number,
|
|
299
|
+
siteID: number | "global"
|
|
300
|
+
): (dispatch: Dispatch, getState: any) => Promise<boolean> {
|
|
301
|
+
return async (dispatch, getState) => {
|
|
302
|
+
try {
|
|
303
|
+
const {
|
|
304
|
+
fileDrive: { currentFolderID },
|
|
305
|
+
} = getState();
|
|
306
|
+
|
|
307
|
+
const responseActions = {
|
|
308
|
+
handleSuccess: async () => {
|
|
309
|
+
await getFolderContent({ siteID, folderID: currentFolderID })(dispatch, getState);
|
|
310
|
+
},
|
|
311
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
312
|
+
};
|
|
313
|
+
const callback = async () =>
|
|
314
|
+
Array.isArray(fileID) ? files.moveFilesBulk(fileID, folderID) : files.moveFile(fileID, folderID);
|
|
315
|
+
|
|
316
|
+
return await handleRequest(callback, responseActions, [])(dispatch);
|
|
317
|
+
} catch (e) {
|
|
318
|
+
console.log(e);
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function updateDisplayMode(displayMode: "grid" | "list"): (dispatch: Dispatch) => Promise<void> {
|
|
325
|
+
return async (dispatch) => {
|
|
326
|
+
dispatch(setDisplayMode(displayMode));
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function updateTab(tab: "local" | "global"): (dispatch: Dispatch) => Promise<void> {
|
|
331
|
+
return async (dispatch) => {
|
|
332
|
+
dispatch(setSelectedTab(tab));
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function replaceFile(
|
|
337
|
+
docFile: File,
|
|
338
|
+
fileID: number,
|
|
339
|
+
keepUrl: boolean,
|
|
340
|
+
siteID: number | "global"
|
|
341
|
+
): (dispatch: Dispatch, getState: any) => Promise<IFile | null> {
|
|
342
|
+
return async (dispatch, getState) => {
|
|
343
|
+
try {
|
|
344
|
+
dispatch(setIsUploading(true));
|
|
345
|
+
|
|
346
|
+
const {
|
|
347
|
+
fileDrive: { currentFolderID },
|
|
348
|
+
} = getState();
|
|
349
|
+
|
|
350
|
+
const form = new FormData();
|
|
351
|
+
form.append("file", docFile);
|
|
352
|
+
|
|
353
|
+
const result = await files.replaceFile(form, fileID, keepUrl);
|
|
354
|
+
if (isReqOk(result.status)) {
|
|
355
|
+
dispatch(setIsUploading(false));
|
|
356
|
+
dispatch(setUploadSuccess(true));
|
|
357
|
+
await getFolderContent({ siteID, folderID: currentFolderID })(dispatch, getState);
|
|
358
|
+
return result.data;
|
|
359
|
+
} else {
|
|
360
|
+
dispatch(setUploadError(true, "Error uploading file"));
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
} catch (e) {
|
|
364
|
+
console.log(e);
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export {
|
|
371
|
+
getFolderContent,
|
|
372
|
+
updateCurrentFolder,
|
|
373
|
+
getFoldersTree,
|
|
374
|
+
updateBreadcrumb,
|
|
375
|
+
createNewFolder,
|
|
376
|
+
updateFolder,
|
|
377
|
+
deleteFolder,
|
|
378
|
+
uploadFile,
|
|
379
|
+
uploadError,
|
|
380
|
+
updateFile,
|
|
381
|
+
deleteFile,
|
|
382
|
+
moveFile,
|
|
383
|
+
updateDisplayMode,
|
|
384
|
+
updateTab,
|
|
385
|
+
replaceFile,
|
|
386
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const NAME = "fileDrive";
|
|
2
|
+
|
|
3
|
+
const SET_CURRENT_FOLDER_CONTENT = `${NAME}/SET_CURRENT_FOLDER_CONTENT`;
|
|
4
|
+
const SET_CURRENT_FOLDER = `${NAME}/SET_CURRENT_FOLDER`;
|
|
5
|
+
const SET_BREADCRUMB = `${NAME}/SET_BREADCRUMB`;
|
|
6
|
+
const SET_FOLDERS_TREE = `${NAME}/SET_FOLDERS_TREE`;
|
|
7
|
+
const SET_IS_UPLOADING = `${NAME}/SET_IS_UPLOADING`;
|
|
8
|
+
const SET_UPLOAD_SUCCESS = `${NAME}/SET_UPLOAD_SUCCESS`;
|
|
9
|
+
const SET_UPLOAD_ERROR = `${NAME}/SET_UPLOAD_ERROR`;
|
|
10
|
+
const SET_DISPLAY_MODE = `${NAME}/SET_DISPLAY_MODE`;
|
|
11
|
+
const SET_SELECTED_TAB = `${NAME}/SET_SELECTED_TAB`;
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
NAME,
|
|
15
|
+
SET_CURRENT_FOLDER_CONTENT,
|
|
16
|
+
SET_CURRENT_FOLDER,
|
|
17
|
+
SET_BREADCRUMB,
|
|
18
|
+
SET_FOLDERS_TREE,
|
|
19
|
+
SET_IS_UPLOADING,
|
|
20
|
+
SET_UPLOAD_ERROR,
|
|
21
|
+
SET_UPLOAD_SUCCESS,
|
|
22
|
+
SET_DISPLAY_MODE,
|
|
23
|
+
SET_SELECTED_TAB,
|
|
24
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { IFilesFolder, IFolder, IFolderTree } from "@ax/types";
|
|
2
|
+
import {
|
|
3
|
+
SET_BREADCRUMB,
|
|
4
|
+
SET_CURRENT_FOLDER,
|
|
5
|
+
SET_CURRENT_FOLDER_CONTENT,
|
|
6
|
+
SET_DISPLAY_MODE,
|
|
7
|
+
SET_FOLDERS_TREE,
|
|
8
|
+
SET_IS_UPLOADING,
|
|
9
|
+
SET_SELECTED_TAB,
|
|
10
|
+
SET_UPLOAD_ERROR,
|
|
11
|
+
SET_UPLOAD_SUCCESS,
|
|
12
|
+
} from "./constants";
|
|
13
|
+
|
|
14
|
+
export interface ISetCurrentFolderContent {
|
|
15
|
+
type: typeof SET_CURRENT_FOLDER_CONTENT;
|
|
16
|
+
payload: { currentFolderContent: IFilesFolder | null };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ISetCurrentFolder {
|
|
20
|
+
type: typeof SET_CURRENT_FOLDER;
|
|
21
|
+
payload: { currentFolderID: number | null };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ISetBreadcrumb {
|
|
25
|
+
type: typeof SET_BREADCRUMB;
|
|
26
|
+
payload: { breadcrumb: IFolderTree[] };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ISetFoldersTree {
|
|
30
|
+
type: typeof SET_FOLDERS_TREE;
|
|
31
|
+
payload: { foldersTree: IFolderTree[] };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ISetIsUploading {
|
|
35
|
+
type: typeof SET_IS_UPLOADING;
|
|
36
|
+
payload: { isUploading: boolean };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ISetUploadSuccess {
|
|
40
|
+
type: typeof SET_UPLOAD_SUCCESS;
|
|
41
|
+
payload: { isUploading: boolean; isSuccess: boolean };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ISetUploadError {
|
|
45
|
+
type: typeof SET_UPLOAD_ERROR;
|
|
46
|
+
payload: { isUploading: boolean; isError: boolean; errorMsg: string };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ISetDisplayMode {
|
|
50
|
+
type: typeof SET_DISPLAY_MODE;
|
|
51
|
+
payload: { displayMode: "grid" | "list" };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ISetSelectedTab {
|
|
55
|
+
type: typeof SET_SELECTED_TAB;
|
|
56
|
+
payload: { selectedTab: "local" | "global" };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type FileDriveActionsCreators = ISetCurrentFolderContent;
|