@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
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ItemId, TreeData, TreeItem } from "@atlaskit/tree";
|
|
2
|
+
import { IFolderTree } from "@ax/types";
|
|
3
|
+
import { isEmptyObj } from "@ax/helpers";
|
|
4
|
+
|
|
5
|
+
const normalizeTree = (folders: IFolderTree[], tree: TreeData, hidden: number[]) => {
|
|
6
|
+
const normalized: TreeData = {
|
|
7
|
+
rootId: "root",
|
|
8
|
+
items: {
|
|
9
|
+
root: {
|
|
10
|
+
id: "root",
|
|
11
|
+
children: [],
|
|
12
|
+
hasChildren: true,
|
|
13
|
+
isExpanded: true,
|
|
14
|
+
isChildrenLoading: false,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const previousFolder: IFolderTree[] = [];
|
|
20
|
+
if (!isEmptyObj(tree.items)) {
|
|
21
|
+
previousFolder.push(...formatMenu(tree));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const isItemExpanded = (item: IFolderTree) => {
|
|
25
|
+
if (!item) return true;
|
|
26
|
+
return item.isExpanded;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const getElement = (item: IFolderTree, previousItem: IFolderTree) => {
|
|
30
|
+
normalized.items[item.id] = {
|
|
31
|
+
...item,
|
|
32
|
+
children: [],
|
|
33
|
+
isExpanded: isItemExpanded(previousItem),
|
|
34
|
+
};
|
|
35
|
+
if (item.children && item.children.length > 0) {
|
|
36
|
+
item.children.forEach((child: IFolderTree, index: number) => {
|
|
37
|
+
normalized.items[item.id].children.push(child.id);
|
|
38
|
+
getElement(child, previousItem?.children[index]);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
folders.forEach((item: IFolderTree, index: number) => {
|
|
44
|
+
const isHiddenItem = hidden.includes(item.id);
|
|
45
|
+
if (!isHiddenItem) {
|
|
46
|
+
normalized.items.root.children.push(item.id);
|
|
47
|
+
getElement(item, previousFolder[index]);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return normalized;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const getElementsFromTree = (tree: TreeData): TreeItem[] => {
|
|
55
|
+
const { items } = tree;
|
|
56
|
+
const elements: TreeItem[] = [];
|
|
57
|
+
for (const item of Object.values(items)) {
|
|
58
|
+
elements.push(item);
|
|
59
|
+
}
|
|
60
|
+
return elements;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const getChild = (child: ItemId, elements: any[]): IFolderTree => {
|
|
64
|
+
const element = elements.find((element: IFolderTree) => element.id === child);
|
|
65
|
+
const children = element?.children.map((child: ItemId) => getChild(child, elements));
|
|
66
|
+
return { ...element, children };
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const formatMenu = (tree: TreeData) => {
|
|
70
|
+
const elements: TreeItem[] = getElementsFromTree(tree);
|
|
71
|
+
|
|
72
|
+
const root: any = elements.find((element: TreeItem) => element.id === "root");
|
|
73
|
+
const formattedMenu = root.children.map((child: ItemId) => {
|
|
74
|
+
return getChild(child, elements);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return formattedMenu;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const formatItem = (item: any, tree: TreeData) => {
|
|
81
|
+
const elements = getElementsFromTree(tree);
|
|
82
|
+
|
|
83
|
+
const formattedItem: IFolderTree = {
|
|
84
|
+
...item,
|
|
85
|
+
children: item.children.map((child: ItemId) => getChild(child, elements)),
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return formattedItem;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export { normalizeTree, formatMenu, formatItem };
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { CheckField, Tooltip } from "@ax/components";
|
|
3
|
+
import { IActionMenuOption, ICheck, IFile } from "@ax/types";
|
|
4
|
+
import { formatBytes, getFormattedDateWithTimezone, trimText } from "@ax/helpers";
|
|
5
|
+
import { useModal } from "@ax/hooks";
|
|
6
|
+
|
|
7
|
+
import { getFileIcon } from "../helpers";
|
|
8
|
+
import { DeleteFileModal, MoveItemModal } from "../atoms";
|
|
9
|
+
|
|
10
|
+
import * as S from "./style";
|
|
11
|
+
|
|
12
|
+
const GridItem = (props: IProps) => {
|
|
13
|
+
const {
|
|
14
|
+
file,
|
|
15
|
+
isSelected,
|
|
16
|
+
currentFolderID,
|
|
17
|
+
isAllowedToDelete,
|
|
18
|
+
isAllowedToEdit,
|
|
19
|
+
isAllowedToMove,
|
|
20
|
+
onChange,
|
|
21
|
+
onClick,
|
|
22
|
+
onDelete,
|
|
23
|
+
onMove,
|
|
24
|
+
} = props;
|
|
25
|
+
const { id, fileName, fileType, sizeBytes, uploadDate, folder } = file;
|
|
26
|
+
|
|
27
|
+
const [selectedFolder, setSelectedFolder] = useState<number>(currentFolderID || 0);
|
|
28
|
+
const { isOpen: isDeleteOpen, toggleModal: toggleDeleteModal } = useModal();
|
|
29
|
+
const { isOpen: isMoveOpen, toggleModal: toggleMoveModal } = useModal();
|
|
30
|
+
|
|
31
|
+
const handleChange = (value: ICheck) => onChange(value);
|
|
32
|
+
const handleClick = () => onClick(file);
|
|
33
|
+
const handleCheckClick = (e: React.MouseEvent<HTMLDivElement>) => e.stopPropagation();
|
|
34
|
+
|
|
35
|
+
let menuOptions: IActionMenuOption[] = [];
|
|
36
|
+
|
|
37
|
+
if (isAllowedToEdit) {
|
|
38
|
+
menuOptions = [
|
|
39
|
+
{
|
|
40
|
+
label: "Edit",
|
|
41
|
+
icon: "edit",
|
|
42
|
+
action: () => onClick(file),
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
if (isAllowedToMove) {
|
|
47
|
+
menuOptions = [
|
|
48
|
+
...menuOptions,
|
|
49
|
+
{
|
|
50
|
+
label: "Move to...",
|
|
51
|
+
icon: "change",
|
|
52
|
+
action: () => toggleMoveModal(),
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (isAllowedToDelete) {
|
|
59
|
+
menuOptions = [
|
|
60
|
+
...menuOptions,
|
|
61
|
+
{
|
|
62
|
+
label: "Delete",
|
|
63
|
+
icon: "delete",
|
|
64
|
+
action: () => toggleDeleteModal(),
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const iconUrl = `/img/icons/${getFileIcon(fileType)}`;
|
|
70
|
+
|
|
71
|
+
const handleDeleteFile = () => {
|
|
72
|
+
onDelete(id);
|
|
73
|
+
isDeleteOpen && toggleDeleteModal();
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const handleMoveFile = () => {
|
|
77
|
+
if(folder !== selectedFolder) {
|
|
78
|
+
onMove(id, selectedFolder);
|
|
79
|
+
isMoveOpen && toggleMoveModal();
|
|
80
|
+
setSelectedFolder(0);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const handleModalClose = () => {
|
|
85
|
+
setSelectedFolder(0);
|
|
86
|
+
isMoveOpen && toggleMoveModal();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const mainDeleteModalAction = {
|
|
90
|
+
title: "Delete document",
|
|
91
|
+
onClick: () => handleDeleteFile(),
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const secondaryDeleteModalAction = { title: "Cancel", onClick: toggleDeleteModal };
|
|
95
|
+
|
|
96
|
+
const mainMoveModalAction = {
|
|
97
|
+
title: "Move",
|
|
98
|
+
onClick: () => handleMoveFile(),
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const secondaryMoveModalAction = { title: "Cancel", onClick: handleModalClose };
|
|
102
|
+
|
|
103
|
+
const FileTitle = () =>
|
|
104
|
+
fileName.length > 40 ? (
|
|
105
|
+
<Tooltip content={fileName}>
|
|
106
|
+
<S.Name>{trimText(fileName, 40)}</S.Name>
|
|
107
|
+
</Tooltip>
|
|
108
|
+
) : (
|
|
109
|
+
<S.Name>{fileName}</S.Name>
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<>
|
|
114
|
+
<S.Wrapper onClick={handleClick}>
|
|
115
|
+
<S.Header>
|
|
116
|
+
<S.CheckWrapper onClick={handleCheckClick}>
|
|
117
|
+
<CheckField name="check" value={id} checked={isSelected} onChange={handleChange} />
|
|
118
|
+
</S.CheckWrapper>
|
|
119
|
+
<S.IconWrapper>
|
|
120
|
+
<img src={iconUrl} alt={`${fileType} Icon`} />
|
|
121
|
+
</S.IconWrapper>
|
|
122
|
+
<S.StyledActionMenu icon="more" options={menuOptions} tooltip="File actions" />
|
|
123
|
+
</S.Header>
|
|
124
|
+
<FileTitle />
|
|
125
|
+
<S.Info>
|
|
126
|
+
<S.Tag>{getFormattedDateWithTimezone(uploadDate, "d MMM Y")}</S.Tag>
|
|
127
|
+
<S.Tag>{formatBytes(sizeBytes)}</S.Tag>
|
|
128
|
+
</S.Info>
|
|
129
|
+
</S.Wrapper>
|
|
130
|
+
{isDeleteOpen && (
|
|
131
|
+
<DeleteFileModal
|
|
132
|
+
isOpen={isDeleteOpen}
|
|
133
|
+
toggleModal={toggleDeleteModal}
|
|
134
|
+
mainModalAction={mainDeleteModalAction}
|
|
135
|
+
secondaryModalAction={secondaryDeleteModalAction}
|
|
136
|
+
title={fileName}
|
|
137
|
+
/>
|
|
138
|
+
)}
|
|
139
|
+
{isMoveOpen && (
|
|
140
|
+
<MoveItemModal
|
|
141
|
+
isOpen={isMoveOpen}
|
|
142
|
+
toggleModal={handleModalClose}
|
|
143
|
+
mainModalAction={mainMoveModalAction}
|
|
144
|
+
secondaryModalAction={secondaryMoveModalAction}
|
|
145
|
+
folder={selectedFolder}
|
|
146
|
+
setFolder={setSelectedFolder}
|
|
147
|
+
hideRoot={!folder}
|
|
148
|
+
/>
|
|
149
|
+
)}
|
|
150
|
+
</>
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
interface IProps {
|
|
155
|
+
file: IFile;
|
|
156
|
+
isSelected: boolean;
|
|
157
|
+
currentFolderID: number | null;
|
|
158
|
+
isAllowedToEdit: boolean;
|
|
159
|
+
isAllowedToDelete: boolean;
|
|
160
|
+
isAllowedToMove: boolean;
|
|
161
|
+
onChange(e: ICheck): void;
|
|
162
|
+
onClick(file: IFile): void;
|
|
163
|
+
onDelete(fileID: number): void;
|
|
164
|
+
onMove(fileID: number, folderID: number): void;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export default GridItem;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
import { ActionMenu } from "@ax/components";
|
|
3
|
+
|
|
4
|
+
const StyledActionMenu = styled(ActionMenu)`
|
|
5
|
+
opacity: 0;
|
|
6
|
+
width: 32px;
|
|
7
|
+
display: flex;
|
|
8
|
+
position: absolute;
|
|
9
|
+
right: ${(p) => p.theme.spacing.xxs};
|
|
10
|
+
top: ${(p) => p.theme.spacing.xs};
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
const Wrapper = styled.div`
|
|
14
|
+
position: relative;
|
|
15
|
+
background-color: ${(p) => p.theme.color.uiBackground02};
|
|
16
|
+
border: ${(p) => `1px solid ${p.theme.color.uiLine}`};
|
|
17
|
+
border-radius: ${p => p.theme.radii.s};
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
padding: ${(p) => p.theme.spacing.s};
|
|
21
|
+
width: 100%;
|
|
22
|
+
min-width: 220px;
|
|
23
|
+
max-width: 280px;
|
|
24
|
+
height: 154px;
|
|
25
|
+
margin-right: ${(p) => p.theme.spacing.s};
|
|
26
|
+
cursor: pointer;
|
|
27
|
+
&:hover {
|
|
28
|
+
background-color: ${(p) => p.theme.color.overlayHoverPrimary};
|
|
29
|
+
${StyledActionMenu} {
|
|
30
|
+
opacity: 1;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
const Header = styled.div`
|
|
36
|
+
display: flex;
|
|
37
|
+
margin-bottom: ${(p) => p.theme.spacing.xs};
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
const CheckWrapper = styled.div`
|
|
41
|
+
margin-right: ${(p) => p.theme.spacing.xs};
|
|
42
|
+
& > div {
|
|
43
|
+
width: ${(p) => p.theme.spacing.s};
|
|
44
|
+
}
|
|
45
|
+
label {
|
|
46
|
+
margin-bottom: 0;
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
const IconWrapper = styled.div`
|
|
51
|
+
width: 42px;
|
|
52
|
+
height: 40px;
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
const Name = styled.div`
|
|
56
|
+
${(p) => p.theme.textStyle.uiL};
|
|
57
|
+
color: ${(p) => p.theme.colors.textHighEmphasis};
|
|
58
|
+
margin-bottom: ${(p) => p.theme.spacing.xs};
|
|
59
|
+
word-break: break-word;
|
|
60
|
+
`;
|
|
61
|
+
|
|
62
|
+
const Info = styled.div`
|
|
63
|
+
display: flex;
|
|
64
|
+
margin-top: auto;
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
const Tag = styled.div`
|
|
68
|
+
${(p) => p.theme.textStyle.uiXS};
|
|
69
|
+
border: ${(p) => `1px solid ${p.theme.color.uiLine}`};
|
|
70
|
+
border-radius: 20px;
|
|
71
|
+
color: ${(p) => p.theme.colors.textMediumEmphasis};
|
|
72
|
+
padding: 2px 8px;
|
|
73
|
+
margin-right: ${(p) => p.theme.spacing.xxs};
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
export { Wrapper, Header, Name, Info, CheckWrapper, IconWrapper, StyledActionMenu, Tag };
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { CheckField, ElementsTooltip, Tooltip } from "@ax/components";
|
|
3
|
+
import { IActionMenuOption, ICheck, IFile } from "@ax/types";
|
|
4
|
+
import { formatBytes, getFormattedDateWithTimezone, trimText } from "@ax/helpers";
|
|
5
|
+
import { useModal, usePermission } from "@ax/hooks";
|
|
6
|
+
|
|
7
|
+
import { getFileIcon } from "../helpers";
|
|
8
|
+
import { DeleteFileModal, MoveItemModal } from "../atoms";
|
|
9
|
+
|
|
10
|
+
import * as S from "./style";
|
|
11
|
+
|
|
12
|
+
const ListItem = (props: IProps) => {
|
|
13
|
+
const {
|
|
14
|
+
file,
|
|
15
|
+
isSelected,
|
|
16
|
+
currentFolderID,
|
|
17
|
+
isAllowedToDelete,
|
|
18
|
+
isAllowedToEdit,
|
|
19
|
+
isAllowedToMove,
|
|
20
|
+
onChange,
|
|
21
|
+
onClick,
|
|
22
|
+
onDelete,
|
|
23
|
+
onMove,
|
|
24
|
+
} = props;
|
|
25
|
+
const { id, fileName, fileType, sizeBytes, uploadDate, tags, folder } = file;
|
|
26
|
+
|
|
27
|
+
const [selectedFolder, setSelectedFolder] = useState<number>(currentFolderID || 0);
|
|
28
|
+
const { isOpen: isDeleteOpen, toggleModal: toggleDeleteModal } = useModal();
|
|
29
|
+
const { isOpen: isMoveOpen, toggleModal: toggleMoveModal } = useModal();
|
|
30
|
+
|
|
31
|
+
const handleChange = (value: ICheck) => onChange(value);
|
|
32
|
+
const handleClick = () => onClick(file);
|
|
33
|
+
|
|
34
|
+
let menuOptions: IActionMenuOption[] = [];
|
|
35
|
+
|
|
36
|
+
if (isAllowedToEdit) {
|
|
37
|
+
menuOptions = [
|
|
38
|
+
{
|
|
39
|
+
label: "Edit",
|
|
40
|
+
icon: "edit",
|
|
41
|
+
action: () => onClick(file),
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
if (isAllowedToMove) {
|
|
46
|
+
menuOptions = [
|
|
47
|
+
...menuOptions,
|
|
48
|
+
{
|
|
49
|
+
label: "Move to...",
|
|
50
|
+
icon: "change",
|
|
51
|
+
action: () => toggleMoveModal(),
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (isAllowedToDelete) {
|
|
58
|
+
menuOptions = [
|
|
59
|
+
...menuOptions,
|
|
60
|
+
{
|
|
61
|
+
label: "Delete",
|
|
62
|
+
icon: "delete",
|
|
63
|
+
action: () => toggleDeleteModal(),
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const iconUrl = `/img/icons/${getFileIcon(fileType)}`;
|
|
69
|
+
|
|
70
|
+
const handleDeleteFile = () => {
|
|
71
|
+
onDelete(id);
|
|
72
|
+
isDeleteOpen && toggleDeleteModal();
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const handleMoveFile = () => {
|
|
76
|
+
if(folder !== selectedFolder) {
|
|
77
|
+
onMove(id, selectedFolder);
|
|
78
|
+
isMoveOpen && toggleMoveModal();
|
|
79
|
+
setSelectedFolder(0);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const handleModalClose = () => {
|
|
84
|
+
setSelectedFolder(0);
|
|
85
|
+
isMoveOpen && toggleMoveModal();
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const mainDeleteModalAction = {
|
|
89
|
+
title: "Delete document",
|
|
90
|
+
onClick: () => handleDeleteFile(),
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const secondaryDeleteModalAction = { title: "Cancel", onClick: toggleDeleteModal };
|
|
94
|
+
|
|
95
|
+
const mainMoveModalAction = {
|
|
96
|
+
title: "Move",
|
|
97
|
+
onClick: () => handleMoveFile(),
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const secondaryMoveModalAction = { title: "Cancel", onClick: handleModalClose };
|
|
101
|
+
|
|
102
|
+
const FileTitle = () =>
|
|
103
|
+
fileName.length > 50 ? <Tooltip content={fileName}>{trimText(fileName, 50)}</Tooltip> : <>{fileName}</>;
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<>
|
|
107
|
+
<S.ItemRow role="rowgroup" selected={isSelected}>
|
|
108
|
+
<S.CheckCell role="cell">
|
|
109
|
+
<CheckField name="check" value={id} checked={isSelected} onChange={handleChange} />
|
|
110
|
+
</S.CheckCell>
|
|
111
|
+
<S.IconCell role="cell" onClick={handleClick}>
|
|
112
|
+
<img src={iconUrl} alt={`${fileType} Icon`} />
|
|
113
|
+
</S.IconCell>
|
|
114
|
+
<S.NameCell role="cell" onClick={handleClick}>
|
|
115
|
+
<FileTitle />
|
|
116
|
+
</S.NameCell>
|
|
117
|
+
<S.TypeCell role="cell" onClick={handleClick}>
|
|
118
|
+
<S.FileType>{fileType}</S.FileType>
|
|
119
|
+
</S.TypeCell>
|
|
120
|
+
<S.SizeCell role="cell" onClick={handleClick}>
|
|
121
|
+
{formatBytes(sizeBytes)}
|
|
122
|
+
</S.SizeCell>
|
|
123
|
+
<S.UpdatedCell role="cell" onClick={handleClick}>
|
|
124
|
+
{getFormattedDateWithTimezone(uploadDate, "d MMM Y")}
|
|
125
|
+
</S.UpdatedCell>
|
|
126
|
+
<S.TagsCell role="cell" onClick={handleClick}>
|
|
127
|
+
{tags.length > 0 && (
|
|
128
|
+
<ElementsTooltip
|
|
129
|
+
elements={file.tags}
|
|
130
|
+
elementsPerRow={3}
|
|
131
|
+
defaultElements={3}
|
|
132
|
+
rounded={true}
|
|
133
|
+
defaultColor="#FFBB37"
|
|
134
|
+
prefix="#"
|
|
135
|
+
size="M"
|
|
136
|
+
/>
|
|
137
|
+
)}
|
|
138
|
+
</S.TagsCell>
|
|
139
|
+
<S.ActionsCell role="cell">
|
|
140
|
+
<S.StyledActionMenu icon="more" options={menuOptions} tooltip="File actions" />
|
|
141
|
+
</S.ActionsCell>
|
|
142
|
+
</S.ItemRow>
|
|
143
|
+
{isDeleteOpen && (
|
|
144
|
+
<DeleteFileModal
|
|
145
|
+
isOpen={isDeleteOpen}
|
|
146
|
+
toggleModal={toggleDeleteModal}
|
|
147
|
+
mainModalAction={mainDeleteModalAction}
|
|
148
|
+
secondaryModalAction={secondaryDeleteModalAction}
|
|
149
|
+
title={fileName}
|
|
150
|
+
/>
|
|
151
|
+
)}
|
|
152
|
+
{isMoveOpen && (
|
|
153
|
+
<MoveItemModal
|
|
154
|
+
isOpen={isMoveOpen}
|
|
155
|
+
toggleModal={handleModalClose}
|
|
156
|
+
mainModalAction={mainMoveModalAction}
|
|
157
|
+
secondaryModalAction={secondaryMoveModalAction}
|
|
158
|
+
folder={selectedFolder}
|
|
159
|
+
setFolder={setSelectedFolder}
|
|
160
|
+
hideRoot={!folder}
|
|
161
|
+
/>
|
|
162
|
+
)}
|
|
163
|
+
</>
|
|
164
|
+
);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
interface IProps {
|
|
168
|
+
file: IFile;
|
|
169
|
+
isSelected: boolean;
|
|
170
|
+
currentFolderID: number | null;
|
|
171
|
+
isAllowedToEdit: boolean;
|
|
172
|
+
isAllowedToDelete: boolean;
|
|
173
|
+
isAllowedToMove: boolean;
|
|
174
|
+
onChange(e: ICheck): void;
|
|
175
|
+
onClick(file: IFile): void;
|
|
176
|
+
onDelete(fileID: number): void;
|
|
177
|
+
onMove(fileID: number, folderID: number): void;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export default ListItem;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
import { ActionMenu } from "@ax/components";
|
|
3
|
+
import { Cell, Row } from "@ax/components/TableList/TableItem/style";
|
|
4
|
+
|
|
5
|
+
const StyledActionMenu = styled(ActionMenu)`
|
|
6
|
+
opacity: 0;
|
|
7
|
+
`;
|
|
8
|
+
|
|
9
|
+
const ItemRow = styled(Row)<{ global?: boolean }>`
|
|
10
|
+
&:hover {
|
|
11
|
+
${StyledActionMenu} {
|
|
12
|
+
opacity: 1;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
const CheckCell = styled(Cell)`
|
|
18
|
+
label {
|
|
19
|
+
margin-bottom: ${(p) => p.theme.spacing.s};
|
|
20
|
+
}
|
|
21
|
+
> div {
|
|
22
|
+
width: ${(p) => p.theme.spacing.s};
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
const IconCell = styled(Cell)`
|
|
27
|
+
padding: 8px 0;
|
|
28
|
+
img {
|
|
29
|
+
width: 34px;
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
const NameCell = styled(Cell)`
|
|
34
|
+
${(p) => p.theme.textStyle.uiL};
|
|
35
|
+
color: ${(p) => p.theme.colors.textHighEmphasis};
|
|
36
|
+
flex-grow: 1;
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
const TypeCell = styled(Cell)`
|
|
40
|
+
flex: 0 0 80px;
|
|
41
|
+
align-items: center;
|
|
42
|
+
text-transform: uppercase;
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
const FileType = styled.div`
|
|
46
|
+
${(p) => p.theme.textStyle.uiS};
|
|
47
|
+
color: ${(p) => p.theme.colors.textMediumEmphasis};
|
|
48
|
+
border: ${(p) => `1px solid ${p.theme.color.textMediumEmphasis}`};
|
|
49
|
+
border-radius: ${p => p.theme.radii.s};
|
|
50
|
+
padding: ${(p) => `0 ${p.theme.spacing.xxs}`};
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
const SizeCell = styled(Cell)`
|
|
54
|
+
${(p) => p.theme.textStyle.uiXS};
|
|
55
|
+
color: ${(p) => p.theme.colors.textMediumEmphasis};
|
|
56
|
+
flex: 0 0 80px;
|
|
57
|
+
align-items: center;
|
|
58
|
+
`;
|
|
59
|
+
|
|
60
|
+
const UpdatedCell = styled(Cell)`
|
|
61
|
+
${(p) => p.theme.textStyle.uiXS};
|
|
62
|
+
color: ${(p) => p.theme.colors.textMediumEmphasis};
|
|
63
|
+
flex: 0 0 120px;
|
|
64
|
+
align-items: center;
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
const TagsCell = styled(Cell)`
|
|
68
|
+
flex: 0 0 300px;
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
const ActionsCell = styled(Cell)`
|
|
72
|
+
flex: 0 0 70px;
|
|
73
|
+
text-align: center;
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
ItemRow,
|
|
78
|
+
StyledActionMenu,
|
|
79
|
+
CheckCell,
|
|
80
|
+
IconCell,
|
|
81
|
+
NameCell,
|
|
82
|
+
TypeCell,
|
|
83
|
+
FileType,
|
|
84
|
+
SizeCell,
|
|
85
|
+
UpdatedCell,
|
|
86
|
+
TagsCell,
|
|
87
|
+
ActionsCell,
|
|
88
|
+
};
|