@griddo/ax 11.4.24 → 11.5.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/src/__tests__/components/Fields/ImageField/ImageField.test.tsx +52 -34
- package/src/api/folders.tsx +62 -0
- package/src/api/images.tsx +159 -1
- package/src/api/index.tsx +2 -0
- package/src/api/sites.tsx +1 -1
- package/src/components/Fields/ImageField/index.tsx +7 -6
- package/src/components/Fields/Wysiwyg/index.tsx +5 -3
- package/src/components/FileGallery/index.tsx +22 -16
- package/src/components/FileGallery/style.tsx +18 -4
- package/src/components/Gallery/FolderItem/index.tsx +39 -0
- package/src/components/Gallery/FolderItem/style.tsx +31 -0
- package/src/components/Gallery/GalleryPanel/DetailPanel/index.tsx +112 -237
- package/src/components/Gallery/GalleryPanel/DetailPanel/style.tsx +77 -61
- package/src/components/Gallery/GalleryPanel/index.tsx +37 -32
- package/src/components/Gallery/GalleryPanel/style.tsx +1 -0
- package/src/components/Gallery/index.tsx +267 -163
- package/src/components/Gallery/style.tsx +200 -135
- package/src/components/Loading/index.tsx +7 -2
- package/src/components/Loading/style.tsx +2 -2
- package/src/components/TableFilters/StateFilter/index.tsx +1 -1
- package/src/containers/FileDrive/actions.tsx +1 -2
- package/src/containers/FileDrive/interfaces.tsx +3 -3
- package/src/containers/Gallery/actions.tsx +359 -13
- package/src/containers/Gallery/constants.tsx +12 -0
- package/src/containers/Gallery/interfaces.tsx +44 -1
- package/src/containers/Gallery/reducer.tsx +27 -3
- package/src/containers/Sites/actions.tsx +2 -2
- package/src/containers/Users/actions.tsx +9 -6
- package/src/helpers/files.tsx +37 -1
- package/src/helpers/index.tsx +3 -1
- package/src/modules/App/Routing/NavMenu/NavItem/NavSubItem/style.tsx +7 -2
- package/src/modules/App/Routing/NavMenu/index.tsx +2 -1
- package/src/modules/FileDrive/FileFilters/SortBy/style.tsx +3 -0
- package/src/modules/FileDrive/FileModal/DetailPanel/UsageContent/index.tsx +1 -1
- package/src/modules/FileDrive/FolderTree/MenuItem/index.tsx +14 -10
- package/src/modules/FileDrive/FolderTree/MenuItem/style.tsx +8 -1
- package/src/modules/FileDrive/FolderTree/MenuList/index.tsx +9 -2
- package/src/modules/FileDrive/index.tsx +45 -28
- package/src/modules/FileDrive/style.tsx +7 -6
- package/src/modules/GlobalEditor/index.tsx +1 -1
- package/src/modules/MediaGallery/Breadcrumb/index.tsx +42 -0
- package/src/modules/MediaGallery/Breadcrumb/style.tsx +18 -0
- package/src/modules/MediaGallery/BulkGridHeader/GridHeader/index.tsx +37 -0
- package/src/modules/MediaGallery/BulkGridHeader/GridHeader/style.tsx +19 -0
- package/src/modules/MediaGallery/BulkGridHeader/index.tsx +35 -0
- package/src/modules/MediaGallery/BulkGridHeader/style.tsx +17 -0
- package/src/modules/MediaGallery/BulkListHeader/TableHeader/index.tsx +46 -0
- package/src/modules/MediaGallery/BulkListHeader/TableHeader/style.tsx +53 -0
- package/src/modules/MediaGallery/BulkListHeader/index.tsx +42 -0
- package/src/modules/MediaGallery/BulkListHeader/style.tsx +17 -0
- package/src/modules/MediaGallery/FolderItem/index.tsx +191 -0
- package/src/modules/MediaGallery/FolderItem/style.tsx +39 -0
- package/src/modules/MediaGallery/FolderTree/MenuItem/index.tsx +87 -0
- package/src/modules/MediaGallery/FolderTree/MenuItem/style.tsx +76 -0
- package/src/modules/MediaGallery/FolderTree/MenuList/index.tsx +34 -0
- package/src/modules/MediaGallery/FolderTree/index.tsx +62 -0
- package/src/modules/MediaGallery/FolderTree/style.tsx +49 -0
- package/src/modules/MediaGallery/GridItem/index.tsx +149 -0
- package/src/modules/MediaGallery/GridItem/style.tsx +74 -0
- package/src/modules/MediaGallery/ImageDragAndDrop/index.tsx +299 -0
- package/src/{components/Gallery/GalleryPanel/GalleryDragAndDrop → modules/MediaGallery/ImageDragAndDrop}/style.tsx +114 -33
- package/src/{components/Gallery/GalleryFilters → modules/MediaGallery/ImageFilters}/Orientation/style.tsx +2 -1
- package/src/{components/Gallery/GalleryFilters → modules/MediaGallery/ImageFilters}/SortBy/style.tsx +3 -0
- package/src/{components/Gallery/GalleryFilters → modules/MediaGallery/ImageFilters}/Type/style.tsx +1 -0
- package/src/modules/MediaGallery/ImageFilters/Usage/index.tsx +75 -0
- package/src/modules/MediaGallery/ImageFilters/Usage/style.tsx +30 -0
- package/src/modules/MediaGallery/ImageModal/DetailPanel/UsageContent/Item/index.tsx +35 -0
- package/src/modules/MediaGallery/ImageModal/DetailPanel/UsageContent/Item/style.tsx +43 -0
- package/src/modules/MediaGallery/ImageModal/DetailPanel/UsageContent/ItemGroup/index.tsx +44 -0
- package/src/modules/MediaGallery/ImageModal/DetailPanel/UsageContent/ItemGroup/style.tsx +34 -0
- package/src/modules/MediaGallery/ImageModal/DetailPanel/UsageContent/index.tsx +233 -0
- package/src/modules/MediaGallery/ImageModal/DetailPanel/UsageContent/style.tsx +21 -0
- package/src/modules/MediaGallery/ImageModal/DetailPanel/index.tsx +209 -0
- package/src/modules/MediaGallery/ImageModal/DetailPanel/style.tsx +81 -0
- package/src/modules/MediaGallery/ImageModal/index.tsx +168 -0
- package/src/modules/MediaGallery/ImageModal/style.tsx +106 -0
- package/src/modules/MediaGallery/ListItem/index.tsx +181 -0
- package/src/modules/MediaGallery/ListItem/style.tsx +100 -0
- package/src/modules/MediaGallery/UploadItem/index.tsx +32 -0
- package/src/modules/MediaGallery/UploadItem/style.tsx +42 -0
- package/src/modules/MediaGallery/atoms.tsx +196 -0
- package/src/{components/Gallery → modules/MediaGallery}/hooks.tsx +10 -4
- package/src/modules/MediaGallery/index.tsx +892 -0
- package/src/modules/MediaGallery/style.tsx +216 -0
- package/src/{components/Gallery → modules/MediaGallery}/utils.tsx +1 -1
- package/src/modules/StructuredData/Form/index.tsx +2 -2
- package/src/routes/multisite.tsx +24 -4
- package/src/routes/site.tsx +24 -4
- package/src/types/files.tsx +98 -0
- package/src/types/index.tsx +33 -91
- package/src/__tests__/components/Gallery/Gallery.test.tsx +0 -559
- package/src/__tests__/components/Gallery/GalleryFilters/Orientation/Orientation.test.tsx +0 -54
- package/src/__tests__/components/Gallery/GalleryFilters/SortBy/SortBy.test.tsx +0 -118
- package/src/__tests__/components/Gallery/GalleryFilters/Type/Type.test.tsx +0 -54
- package/src/__tests__/components/Gallery/GalleryPanel/DetailPanel/DetailPanel.test.tsx +0 -869
- package/src/__tests__/components/Gallery/GalleryPanel/GalleryDragAndDrop/GalleryDragAndDrop.test.tsx +0 -249
- package/src/__tests__/components/Gallery/GalleryPanel/GalleryPanel.test.tsx +0 -55
- package/src/components/Gallery/GalleryPanel/GalleryDragAndDrop/index.tsx +0 -239
- package/src/containers/FileDrive/utils.tsx +0 -37
- /package/src/{components/Gallery/GalleryFilters → modules/MediaGallery/ImageFilters}/Orientation/index.tsx +0 -0
- /package/src/{components/Gallery/GalleryFilters → modules/MediaGallery/ImageFilters}/SortBy/index.tsx +0 -0
- /package/src/{components/Gallery/GalleryFilters → modules/MediaGallery/ImageFilters}/Type/index.tsx +0 -0
package/src/__tests__/components/Gallery/GalleryPanel/GalleryDragAndDrop/GalleryDragAndDrop.test.tsx
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
import { ThemeProvider } from "styled-components";
|
|
4
|
-
import { render, cleanup, screen, fireEvent, act, waitFor } from "../../../../../../config/jest/test-utils";
|
|
5
|
-
import { mock } from "jest-mock-extended";
|
|
6
|
-
import configureStore from "redux-mock-store";
|
|
7
|
-
import "@testing-library/jest-dom";
|
|
8
|
-
import thunk from "redux-thunk";
|
|
9
|
-
|
|
10
|
-
import { parseTheme } from "@ax/helpers";
|
|
11
|
-
import GalleryDragAndDrop, {
|
|
12
|
-
IGalleryDragAndDropProps,
|
|
13
|
-
IDispatchProps,
|
|
14
|
-
} from "@ax/components/Gallery/GalleryPanel/GalleryDragAndDrop";
|
|
15
|
-
import globalTheme from "@ax/themes/theme.json";
|
|
16
|
-
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
cleanup();
|
|
19
|
-
jest.clearAllMocks();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const middlewares: any = [thunk];
|
|
23
|
-
const mockStore = configureStore(middlewares);
|
|
24
|
-
|
|
25
|
-
const defaultGalleryDDProps = mock<IGalleryDragAndDropProps>();
|
|
26
|
-
const defaultDispatchProps = mock<IDispatchProps>();
|
|
27
|
-
|
|
28
|
-
describe("GalleryDragAndDrop component rendering", () => {
|
|
29
|
-
it("should render the component", () => {
|
|
30
|
-
defaultGalleryDDProps.validFormats = ["png", "jpg"];
|
|
31
|
-
defaultGalleryDDProps.allowUpload = false;
|
|
32
|
-
const initialStore = {
|
|
33
|
-
gallery: {
|
|
34
|
-
isSaving: {
|
|
35
|
-
save: false,
|
|
36
|
-
saveAdd: false,
|
|
37
|
-
delete: false,
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const store = mockStore(initialStore);
|
|
43
|
-
|
|
44
|
-
const defaultProps = {
|
|
45
|
-
...defaultGalleryDDProps,
|
|
46
|
-
...defaultDispatchProps,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
render(
|
|
50
|
-
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
51
|
-
<GalleryDragAndDrop {...defaultProps} />
|
|
52
|
-
</ThemeProvider>,
|
|
53
|
-
{ store }
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
expect(screen.getByTestId("gallery-drag-drop-wrapper")).toBeTruthy();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("should render the component with the DragAndDrop", () => {
|
|
60
|
-
defaultGalleryDDProps.validFormats = ["png", "jpg"];
|
|
61
|
-
defaultGalleryDDProps.allowUpload = true;
|
|
62
|
-
const initialStore = {
|
|
63
|
-
gallery: {
|
|
64
|
-
isSaving: {
|
|
65
|
-
save: false,
|
|
66
|
-
saveAdd: false,
|
|
67
|
-
delete: false,
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const store = mockStore(initialStore);
|
|
73
|
-
|
|
74
|
-
const defaultProps = {
|
|
75
|
-
...defaultGalleryDDProps,
|
|
76
|
-
...defaultDispatchProps,
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
render(
|
|
80
|
-
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
81
|
-
<GalleryDragAndDrop {...defaultProps} />
|
|
82
|
-
</ThemeProvider>,
|
|
83
|
-
{ store }
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
expect(screen.getByTestId("gallery-drag-drop-wrapper")).toBeTruthy();
|
|
87
|
-
expect(screen.getAllByTestId("drag-drop-wrapper")).toBeTruthy();
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe("GalleryDragAndDrop component actions", () => {
|
|
92
|
-
it("should trigger the handleFileclick", () => {
|
|
93
|
-
defaultGalleryDDProps.validFormats = ["png", "jpg"];
|
|
94
|
-
defaultGalleryDDProps.allowUpload = true;
|
|
95
|
-
|
|
96
|
-
const initialStore = {
|
|
97
|
-
gallery: {
|
|
98
|
-
isSaving: {
|
|
99
|
-
save: false,
|
|
100
|
-
saveAdd: false,
|
|
101
|
-
delete: false,
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const clickInputSpy = jest.spyOn(HTMLInputElement.prototype, "click");
|
|
107
|
-
|
|
108
|
-
const store = mockStore(initialStore);
|
|
109
|
-
|
|
110
|
-
const defaultProps = {
|
|
111
|
-
...defaultGalleryDDProps,
|
|
112
|
-
...defaultDispatchProps,
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
render(
|
|
116
|
-
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
117
|
-
<GalleryDragAndDrop {...defaultProps} />
|
|
118
|
-
</ThemeProvider>,
|
|
119
|
-
{ store }
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
const buttonSelect = screen.getByTestId("button-line-inverse");
|
|
123
|
-
act(() => {
|
|
124
|
-
fireEvent.click(buttonSelect);
|
|
125
|
-
});
|
|
126
|
-
expect(clickInputSpy).toBeCalled();
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("should trigger the handleTryAgain", () => {
|
|
130
|
-
defaultGalleryDDProps.validFormats = ["png", "jpg"];
|
|
131
|
-
defaultGalleryDDProps.allowUpload = true;
|
|
132
|
-
|
|
133
|
-
const initialStore = {
|
|
134
|
-
gallery: {
|
|
135
|
-
isSaving: {
|
|
136
|
-
save: false,
|
|
137
|
-
saveAdd: false,
|
|
138
|
-
delete: false,
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const store = mockStore(initialStore);
|
|
144
|
-
|
|
145
|
-
const defaultProps = {
|
|
146
|
-
...defaultGalleryDDProps,
|
|
147
|
-
...defaultDispatchProps,
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
render(
|
|
151
|
-
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
152
|
-
<GalleryDragAndDrop {...defaultProps} />
|
|
153
|
-
</ThemeProvider>,
|
|
154
|
-
{ store }
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
const buttonTry = screen.getByText(/TRY AGAIN/i);
|
|
158
|
-
fireEvent.click(buttonTry);
|
|
159
|
-
expect(store.getActions()).toContainEqual({
|
|
160
|
-
payload: { errorMsg: "", isError: false, isUploading: false },
|
|
161
|
-
type: "gallery/SET_UPLOAD_ERROR",
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it("should trigger the DragAndDrop handleDragOver action", () => {
|
|
166
|
-
defaultGalleryDDProps.validFormats = ["png", "jpg"];
|
|
167
|
-
defaultGalleryDDProps.allowUpload = true;
|
|
168
|
-
|
|
169
|
-
const initialStore = {
|
|
170
|
-
gallery: {
|
|
171
|
-
isSaving: {
|
|
172
|
-
save: false,
|
|
173
|
-
saveAdd: false,
|
|
174
|
-
delete: false,
|
|
175
|
-
},
|
|
176
|
-
},
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
const store = mockStore(initialStore);
|
|
180
|
-
|
|
181
|
-
const defaultProps = {
|
|
182
|
-
...defaultGalleryDDProps,
|
|
183
|
-
...defaultDispatchProps,
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const galleryDragAndDropComponent = (
|
|
187
|
-
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
188
|
-
<GalleryDragAndDrop {...defaultProps} />
|
|
189
|
-
</ThemeProvider>
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
render(galleryDragAndDropComponent, { store });
|
|
193
|
-
|
|
194
|
-
expect(screen.getByTestId("gallery-drag-drop-wrapper")).toBeTruthy();
|
|
195
|
-
const dragDropComponent = screen.getAllByTestId("drag-drop-wrapper");
|
|
196
|
-
expect(dragDropComponent).toBeTruthy();
|
|
197
|
-
|
|
198
|
-
const dataTransfer = {
|
|
199
|
-
dropEffect: "",
|
|
200
|
-
};
|
|
201
|
-
fireEvent.dragOver(dragDropComponent[0], {
|
|
202
|
-
dataTransfer,
|
|
203
|
-
});
|
|
204
|
-
expect(dataTransfer.dropEffect).toBe("copy");
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it("should trigger the DragAndDrop handleDrop action", async () => {
|
|
208
|
-
defaultGalleryDDProps.validFormats = ["png", "jpg"];
|
|
209
|
-
defaultGalleryDDProps.allowUpload = true;
|
|
210
|
-
const refreshImagesMock = defaultGalleryDDProps.refreshImages as jest.MockedFunction<() => Promise<void>>;
|
|
211
|
-
|
|
212
|
-
const initialStore = {
|
|
213
|
-
gallery: {
|
|
214
|
-
isSaving: {
|
|
215
|
-
save: false,
|
|
216
|
-
saveAdd: false,
|
|
217
|
-
delete: false,
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
const store = mockStore(initialStore);
|
|
223
|
-
|
|
224
|
-
const defaultProps = {
|
|
225
|
-
...defaultGalleryDDProps,
|
|
226
|
-
...defaultDispatchProps,
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
const galleryDragAndDropComponent = (
|
|
230
|
-
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
231
|
-
<GalleryDragAndDrop {...defaultProps} />
|
|
232
|
-
</ThemeProvider>
|
|
233
|
-
);
|
|
234
|
-
|
|
235
|
-
render(galleryDragAndDropComponent, { store });
|
|
236
|
-
|
|
237
|
-
expect(screen.getByTestId("gallery-drag-drop-wrapper")).toBeTruthy();
|
|
238
|
-
const dragDropComponent = screen.getAllByTestId("drag-drop-wrapper");
|
|
239
|
-
expect(dragDropComponent).toBeTruthy();
|
|
240
|
-
|
|
241
|
-
fireEvent.drop(dragDropComponent[0], {
|
|
242
|
-
dataTransfer: {
|
|
243
|
-
files: [new File([""], "darthvader.png", { type: "png" })],
|
|
244
|
-
},
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
await waitFor(() => expect(refreshImagesMock).toHaveBeenCalled(), { timeout: 3100 });
|
|
248
|
-
});
|
|
249
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
import { ThemeProvider } from "styled-components";
|
|
4
|
-
import { render, cleanup, screen } from "../../../../../config/jest/test-utils";
|
|
5
|
-
import { mock } from "jest-mock-extended";
|
|
6
|
-
import "@testing-library/jest-dom";
|
|
7
|
-
import configureStore from "redux-mock-store";
|
|
8
|
-
import thunk from "redux-thunk";
|
|
9
|
-
|
|
10
|
-
import { parseTheme } from "@ax/helpers";
|
|
11
|
-
import GalleryPanel, { IGalleryPanelProps } from "@ax/components/Gallery/GalleryPanel";
|
|
12
|
-
import globalTheme from "@ax/themes/theme.json";
|
|
13
|
-
import { defaultStore } from "./../../../../__mocks__/store/GenericStore";
|
|
14
|
-
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
cleanup();
|
|
17
|
-
jest.clearAllMocks();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const middlewares: any = [thunk];
|
|
21
|
-
const mockStore = configureStore(middlewares);
|
|
22
|
-
|
|
23
|
-
const defaultProps = mock<IGalleryPanelProps>();
|
|
24
|
-
|
|
25
|
-
defaultProps.validFormats = ["png", "jpg"];
|
|
26
|
-
const setImageMocked = defaultProps.setImage as jest.MockedFunction<(imageData: any) => void>;
|
|
27
|
-
defaultProps.isGlobalTab = true;
|
|
28
|
-
defaultProps.site = 1;
|
|
29
|
-
defaultProps.selectedTab = "";
|
|
30
|
-
const refreshImagesMocked = defaultProps.refreshImages as jest.MockedFunction<() => Promise<void>>;
|
|
31
|
-
|
|
32
|
-
describe("GalleryPanel component rendering", () => {
|
|
33
|
-
it("should render the component", () => {
|
|
34
|
-
const initialStore = {
|
|
35
|
-
gallery: {
|
|
36
|
-
isSaving: {
|
|
37
|
-
save: false,
|
|
38
|
-
saveAdd: false,
|
|
39
|
-
delete: false,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
const store = mockStore({ ...defaultStore, ...initialStore });
|
|
44
|
-
|
|
45
|
-
render(
|
|
46
|
-
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
47
|
-
<GalleryPanel {...defaultProps} />
|
|
48
|
-
</ThemeProvider>,
|
|
49
|
-
{ store }
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
expect(screen.getByTestId("gallery-drag-drop-wrapper")).toBeTruthy();
|
|
53
|
-
expect(screen.getByTestId("detail-panel-wrapper")).toBeTruthy();
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import React, { memo, useEffect, useRef, useState } from "react";
|
|
2
|
-
import { connect } from "react-redux";
|
|
3
|
-
|
|
4
|
-
import { galleryActions } from "@ax/containers/Gallery";
|
|
5
|
-
import { IImage, IRootState } from "@ax/types";
|
|
6
|
-
import { Icon, DragAndDrop, ProgressBar } from "@ax/components";
|
|
7
|
-
|
|
8
|
-
import * as S from "./style";
|
|
9
|
-
|
|
10
|
-
const GalleryDragAndDrop = (props: IProps) => {
|
|
11
|
-
const {
|
|
12
|
-
isImageSelected,
|
|
13
|
-
validFormats,
|
|
14
|
-
site,
|
|
15
|
-
allowUpload,
|
|
16
|
-
refreshImages,
|
|
17
|
-
uploadError,
|
|
18
|
-
isUploading,
|
|
19
|
-
isSuccess,
|
|
20
|
-
isError,
|
|
21
|
-
errorMsg,
|
|
22
|
-
uploadImage,
|
|
23
|
-
selectImage,
|
|
24
|
-
visible,
|
|
25
|
-
resetGalleryState,
|
|
26
|
-
} = props;
|
|
27
|
-
const validExtensions = validFormats.map((format) => `.${format}`).join(",");
|
|
28
|
-
const videoFormats = ["mov", "mp4", "wmv", "avi", "webm", "mkv"];
|
|
29
|
-
const filesInputRef = useRef<HTMLInputElement>(null);
|
|
30
|
-
const filesButtonRef = useRef<HTMLButtonElement>(null);
|
|
31
|
-
const [inDropZone, setInDropZone] = useState(false);
|
|
32
|
-
const [dropDepth, setDropDepth] = useState(0);
|
|
33
|
-
const [uploadingState, setUploadingState] = useState({ total: 0, ready: 0 });
|
|
34
|
-
const [progress, setProgress] = useState(0);
|
|
35
|
-
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
resetGalleryState();
|
|
38
|
-
}, [resetGalleryState]);
|
|
39
|
-
|
|
40
|
-
const handleDragEnter = () => {
|
|
41
|
-
setDropDepth((depth) => depth + 1);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const handleDragLeave = () => {
|
|
45
|
-
setDropDepth((depth) => depth - 1);
|
|
46
|
-
if (dropDepth > 1) return;
|
|
47
|
-
setInDropZone(false);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const handleDragOver = (e: React.DragEvent<HTMLDivElement>) => {
|
|
51
|
-
e.dataTransfer.dropEffect = "copy";
|
|
52
|
-
setInDropZone(true);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const checkType = (type: string) => {
|
|
56
|
-
for (const i in validFormats) {
|
|
57
|
-
if (type.includes(validFormats[i])) return true;
|
|
58
|
-
}
|
|
59
|
-
return false;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const handleDrop = async (e: React.DragEvent<HTMLDivElement>) => {
|
|
63
|
-
const files = Array.from(e.dataTransfer.files);
|
|
64
|
-
await uploadFiles(files);
|
|
65
|
-
setDropDepth(0);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const handleFilesUpload = (e: any) => {
|
|
69
|
-
const files: File[] = Array.from(e.currentTarget.files);
|
|
70
|
-
uploadFiles(files);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const uploadFiles = async (files: File[]) => {
|
|
74
|
-
try {
|
|
75
|
-
if (!files.every((file) => checkType(file.type))) {
|
|
76
|
-
uploadError(true, "Invalid format");
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
setUploadingState({ total: files.length, ready: 0 });
|
|
81
|
-
let lastImage: IImage | undefined;
|
|
82
|
-
while (files.length) {
|
|
83
|
-
const file = files.shift();
|
|
84
|
-
lastImage = file && (await uploadImage(file, site, setProgress, visible));
|
|
85
|
-
setUploadingState((state) => ({ total: state.total, ready: state.ready + 1 }));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
setInDropZone(false);
|
|
89
|
-
setUploadingState({ total: 0, ready: 0 });
|
|
90
|
-
setTimeout(async () => {
|
|
91
|
-
refreshImages && (await refreshImages());
|
|
92
|
-
lastImage && selectImage(lastImage);
|
|
93
|
-
}, 3000);
|
|
94
|
-
} catch (error) {
|
|
95
|
-
console.log(error);
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const uploading = isUploading || uploadingState.total > uploadingState.ready;
|
|
100
|
-
const success = isSuccess && uploadingState.total === uploadingState.ready;
|
|
101
|
-
|
|
102
|
-
const handleTryAgain = () => {
|
|
103
|
-
uploadError(false);
|
|
104
|
-
setInDropZone(false);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const handleFileClick = () => {
|
|
108
|
-
filesInputRef && filesInputRef.current && filesInputRef.current.click();
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const errorWrapper = errorMsg ? <S.ErrorMsg>{errorMsg}</S.ErrorMsg> : null;
|
|
112
|
-
|
|
113
|
-
const renderDragAndDrop = () => (
|
|
114
|
-
<DragAndDrop
|
|
115
|
-
data-testid="drag-drop-wrapper"
|
|
116
|
-
onDrop={handleDrop}
|
|
117
|
-
onDragOver={handleDragOver}
|
|
118
|
-
onDragEnter={handleDragEnter}
|
|
119
|
-
onDragLeave={handleDragLeave}
|
|
120
|
-
validFormats={validFormats}
|
|
121
|
-
>
|
|
122
|
-
<S.StatusWrapper onDragEnter={handleDragEnter} onDragLeave={handleDragLeave}>
|
|
123
|
-
<S.DragStatus onDragEnter={handleDragEnter} onDragLeave={handleDragLeave}>
|
|
124
|
-
<S.DragIcon>
|
|
125
|
-
<Icon name="image" size="36" />
|
|
126
|
-
</S.DragIcon>
|
|
127
|
-
<S.DragTitle>Drag your file here</S.DragTitle>
|
|
128
|
-
<S.DragSubtitle>or</S.DragSubtitle>
|
|
129
|
-
<S.FilesInput type="file" ref={filesInputRef} multiple accept={validExtensions} onInput={handleFilesUpload} />
|
|
130
|
-
<S.FilesButton ref={filesButtonRef} type="button" buttonStyle="line" onClick={handleFileClick}>
|
|
131
|
-
Select files
|
|
132
|
-
</S.FilesButton>
|
|
133
|
-
<S.DragSubtitle>
|
|
134
|
-
Valid formats: {validFormats.filter((format) => !videoFormats.includes(format)).join(", ")} and videos.
|
|
135
|
-
</S.DragSubtitle>
|
|
136
|
-
<S.DragSubtitle>Max. size: 50MB</S.DragSubtitle>
|
|
137
|
-
</S.DragStatus>
|
|
138
|
-
<S.DragOverStatus onDragEnter={handleDragEnter} onDragLeave={handleDragLeave}>
|
|
139
|
-
<S.DragIcon>
|
|
140
|
-
<Icon name="success" size="36" />
|
|
141
|
-
</S.DragIcon>
|
|
142
|
-
<S.DragTitle>Drop your file</S.DragTitle>
|
|
143
|
-
<S.DragSubtitle>
|
|
144
|
-
Valid formats: {validFormats.filter((format) => !videoFormats.includes(format)).join(", ")} and videos.
|
|
145
|
-
</S.DragSubtitle>
|
|
146
|
-
<S.DragSubtitle>Max. size: 50MB</S.DragSubtitle>
|
|
147
|
-
</S.DragOverStatus>
|
|
148
|
-
</S.StatusWrapper>
|
|
149
|
-
</DragAndDrop>
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
const renderPlaceholder = () => (
|
|
153
|
-
<S.StatusWrapper>
|
|
154
|
-
<S.DragIcon>
|
|
155
|
-
<Icon name="image" size="36" />
|
|
156
|
-
</S.DragIcon>
|
|
157
|
-
<S.DragTitle>Select an image to see details</S.DragTitle>
|
|
158
|
-
</S.StatusWrapper>
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
return (
|
|
162
|
-
<S.Wrapper hidden={isImageSelected} data-testid="gallery-drag-drop-wrapper">
|
|
163
|
-
<S.DragAndDropWrapper inDropZone={inDropZone} uploading={uploading} success={success} error={isError}>
|
|
164
|
-
{allowUpload ? renderDragAndDrop() : renderPlaceholder()}
|
|
165
|
-
</S.DragAndDropWrapper>
|
|
166
|
-
<S.UploadingWrapper inDropZone={inDropZone} uploading={uploading} success={success} error={isError}>
|
|
167
|
-
<S.StatusWrapper>
|
|
168
|
-
<S.UploadingStatus>
|
|
169
|
-
<S.DragIcon>
|
|
170
|
-
<Icon name="image" size="36" />
|
|
171
|
-
</S.DragIcon>
|
|
172
|
-
<S.ProgressBar>
|
|
173
|
-
<ProgressBar percentage={progress} />
|
|
174
|
-
</S.ProgressBar>
|
|
175
|
-
<S.DragTitle>Uploading...</S.DragTitle>
|
|
176
|
-
</S.UploadingStatus>
|
|
177
|
-
<S.SuccessStatus>
|
|
178
|
-
<S.DragIcon>
|
|
179
|
-
<Icon name="success" size="36" />
|
|
180
|
-
</S.DragIcon>
|
|
181
|
-
<S.DragTitle>Image loaded!</S.DragTitle>
|
|
182
|
-
</S.SuccessStatus>
|
|
183
|
-
<S.ErrorStatus>
|
|
184
|
-
<S.DragIcon>
|
|
185
|
-
<Icon name="alert" size="36" />
|
|
186
|
-
</S.DragIcon>
|
|
187
|
-
<S.DragTitle>Error uploading image</S.DragTitle>
|
|
188
|
-
{errorWrapper}
|
|
189
|
-
<S.StyledButton type="button" buttonStyle="text" onClick={handleTryAgain}>
|
|
190
|
-
TRY AGAIN
|
|
191
|
-
</S.StyledButton>
|
|
192
|
-
</S.ErrorStatus>
|
|
193
|
-
</S.StatusWrapper>
|
|
194
|
-
</S.UploadingWrapper>
|
|
195
|
-
</S.Wrapper>
|
|
196
|
-
);
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
export interface IGalleryDragAndDropProps {
|
|
200
|
-
isImageSelected: boolean;
|
|
201
|
-
validFormats: string[];
|
|
202
|
-
site: number | "global";
|
|
203
|
-
allowUpload: boolean;
|
|
204
|
-
refreshImages?: () => Promise<void>;
|
|
205
|
-
isUploading: boolean;
|
|
206
|
-
isSuccess: boolean;
|
|
207
|
-
isError: boolean;
|
|
208
|
-
errorMsg: string;
|
|
209
|
-
visible?: boolean;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const mapStateToProps = (state: IRootState) => ({
|
|
213
|
-
isUploading: state.gallery.isUploading,
|
|
214
|
-
isSuccess: state.gallery.isSuccess,
|
|
215
|
-
isError: state.gallery.isError,
|
|
216
|
-
errorMsg: state.gallery.errorMsg,
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
export interface IDispatchProps {
|
|
220
|
-
selectImage(item: IImage | null): void;
|
|
221
|
-
uploadError: (error: boolean, msg?: string) => Promise<void>;
|
|
222
|
-
resetGalleryState: () => Promise<void>;
|
|
223
|
-
uploadImage: (
|
|
224
|
-
imageFiles: File | File[],
|
|
225
|
-
site: number | string,
|
|
226
|
-
setProgress?: (progress: number) => void,
|
|
227
|
-
visible?: boolean
|
|
228
|
-
) => Promise<IImage>;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const mapDispatchToProps = {
|
|
232
|
-
uploadError: galleryActions.uploadError,
|
|
233
|
-
uploadImage: galleryActions.uploadImage,
|
|
234
|
-
resetGalleryState: galleryActions.resetGalleryState,
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
type IProps = IGalleryDragAndDropProps & IDispatchProps;
|
|
238
|
-
|
|
239
|
-
export default connect(mapStateToProps, mapDispatchToProps)(memo(GalleryDragAndDrop));
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { IFolderTree } from "@ax/types";
|
|
2
|
-
|
|
3
|
-
const getPath = (tree: IFolderTree[], targetID: number): IFolderTree[] | undefined => {
|
|
4
|
-
for(const element of tree){
|
|
5
|
-
if (element.id === targetID) {
|
|
6
|
-
return [element];
|
|
7
|
-
}
|
|
8
|
-
if (element.children.length) {
|
|
9
|
-
const result = getPath(element.children, targetID);
|
|
10
|
-
if (result) {
|
|
11
|
-
result.unshift(element);
|
|
12
|
-
return result;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const getNewBreadcrumb = (tree: IFolderTree[], target: number | null) => {
|
|
19
|
-
if(!target) return [];
|
|
20
|
-
|
|
21
|
-
return getPath(tree, target) || [];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const updatePropertyById = (id: number, data: IFolderTree[], property: string, value: any) => {
|
|
25
|
-
for (let i = 0; i < data.length; i++) {
|
|
26
|
-
if (data[i].id === id) {
|
|
27
|
-
data[i] = { ...data[i], [property]: value };
|
|
28
|
-
}
|
|
29
|
-
if (data[i].children !== undefined && data[i].children.length > 0) {
|
|
30
|
-
data[i].children = updatePropertyById(id, data[i].children, property, value);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return data;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export { getNewBreadcrumb, updatePropertyById };
|
|
File without changes
|
|
File without changes
|
/package/src/{components/Gallery/GalleryFilters → modules/MediaGallery/ImageFilters}/Type/index.tsx
RENAMED
|
File without changes
|