@blaze-cms/plugin-media-ui 0.121.0 → 0.123.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/lib/components/FileList/useGetFiles/getFiles.js +58 -144
- package/lib/components/FileList/useGetFiles/getFiles.js.map +1 -1
- package/lib/components/FileList/useGetFiles/useGetFiles.js +4 -3
- package/lib/components/FileList/useGetFiles/useGetFiles.js.map +1 -1
- package/lib/components/FileList/useGetFilesList/useGetFilesList.js +22 -23
- package/lib/components/FileList/useGetFilesList/useGetFilesList.js.map +1 -1
- package/lib/components/FilterPanel/FilterPanel.js +5 -19
- package/lib/components/FilterPanel/FilterPanel.js.map +1 -1
- package/lib/components/ListingContainer/ListingContainer.js +54 -6
- package/lib/components/ListingContainer/ListingContainer.js.map +1 -1
- package/lib/constants.js +1 -1
- package/lib/constants.js.map +1 -1
- package/lib-es/components/FileList/useGetFiles/getFiles.js +30 -82
- package/lib-es/components/FileList/useGetFiles/getFiles.js.map +1 -1
- package/lib-es/components/FileList/useGetFiles/useGetFiles.js +4 -3
- package/lib-es/components/FileList/useGetFiles/useGetFiles.js.map +1 -1
- package/lib-es/components/FileList/useGetFilesList/useGetFilesList.js +20 -21
- package/lib-es/components/FileList/useGetFilesList/useGetFilesList.js.map +1 -1
- package/lib-es/components/FilterPanel/FilterPanel.js +5 -15
- package/lib-es/components/FilterPanel/FilterPanel.js.map +1 -1
- package/lib-es/components/ListingContainer/ListingContainer.js +30 -2
- package/lib-es/components/ListingContainer/ListingContainer.js.map +1 -1
- package/lib-es/constants.js +1 -1
- package/lib-es/constants.js.map +1 -1
- package/package.json +3 -3
- package/src/components/FileList/useGetFiles/getFiles.js +27 -62
- package/src/components/FileList/useGetFiles/useGetFiles.js +5 -4
- package/src/components/FileList/useGetFilesList/useGetFilesList.js +16 -24
- package/src/components/FilterPanel/FilterPanel.js +9 -11
- package/src/components/ListingContainer/ListingContainer.js +18 -2
- package/src/constants.js +1 -1
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
2
|
import differenceWith from 'lodash.differencewith';
|
|
3
3
|
import isEqual from 'lodash.isequal';
|
|
4
|
-
import { useApolloClient } from '@apollo/client';
|
|
5
4
|
import useGetFiles from '../useGetFiles';
|
|
6
|
-
import getCounters from './getCounters';
|
|
7
5
|
|
|
8
6
|
function useGetFilesList() {
|
|
9
7
|
const [
|
|
@@ -19,13 +17,12 @@ function useGetFilesList() {
|
|
|
19
17
|
const [currentResults, setCurrentResults] = useState([]);
|
|
20
18
|
const [allResults, setAllResults] = useState([]);
|
|
21
19
|
const [currentFilter, setCurrentFilter] = useState(null);
|
|
22
|
-
const [allFilesCounter, setAllFilesCounter] = useState(
|
|
20
|
+
const [allFilesCounter, setAllFilesCounter] = useState({ all: 0, text: 0, image: 0, video: 0 });
|
|
23
21
|
const [counters, setCounters] = useState(null);
|
|
24
|
-
const client = useApolloClient();
|
|
25
22
|
|
|
26
23
|
useEffect(
|
|
27
24
|
() => {
|
|
28
|
-
if (
|
|
25
|
+
if (all && image && video && text) {
|
|
29
26
|
setCounters({
|
|
30
27
|
all: all.total,
|
|
31
28
|
image: image.total,
|
|
@@ -34,17 +31,11 @@ function useGetFilesList() {
|
|
|
34
31
|
});
|
|
35
32
|
}
|
|
36
33
|
},
|
|
37
|
-
[
|
|
34
|
+
[all, image, video, text]
|
|
38
35
|
);
|
|
39
36
|
|
|
40
37
|
useEffect(
|
|
41
38
|
() => {
|
|
42
|
-
if (counters === null) {
|
|
43
|
-
getCounters(client).then(initialCounter => {
|
|
44
|
-
setCounters(initialCounter);
|
|
45
|
-
setAllFilesCounter(initialCounter);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
39
|
if (!currentFilter && previousFilter) {
|
|
49
40
|
setCurrentFilter(previousFilter);
|
|
50
41
|
}
|
|
@@ -56,17 +47,13 @@ function useGetFilesList() {
|
|
|
56
47
|
}
|
|
57
48
|
|
|
58
49
|
const isContentDifferent = !!differenceWith(results, currentResults, isEqual).length;
|
|
59
|
-
|
|
60
50
|
if (isContentDifferent) {
|
|
61
51
|
setAllResults([...allResults, ...results]);
|
|
62
52
|
setCurrentResults(results);
|
|
63
53
|
}
|
|
64
54
|
|
|
65
55
|
const shouldSetContentIfListIsVoid =
|
|
66
|
-
!isContentDifferent &&
|
|
67
|
-
!allResults.length &&
|
|
68
|
-
results.length &&
|
|
69
|
-
allFilesCounter[currentFilter] !== 0;
|
|
56
|
+
!isContentDifferent && !allResults.length && results.length;
|
|
70
57
|
|
|
71
58
|
if (shouldSetContentIfListIsVoid) {
|
|
72
59
|
setAllResults(results);
|
|
@@ -149,31 +136,36 @@ function useGetFilesList() {
|
|
|
149
136
|
const setQueryParams = params => {
|
|
150
137
|
const isNewSearchTerm = params.isSearch && previousSearchTerm !== params.searchTerm;
|
|
151
138
|
const hasDeletedSearchTerm = previousSearchTerm && params.searchTerm === null;
|
|
152
|
-
const
|
|
139
|
+
const newFilter = JSON.stringify(params.where);
|
|
140
|
+
const isNewFilter = newFilter !== previousFilter;
|
|
153
141
|
const shouldClearList = hasDeletedSearchTerm || isNewFilter || isNewSearchTerm;
|
|
154
142
|
shouldClearList ? clearList(params) : setParams(params);
|
|
155
|
-
setCurrentFilter(
|
|
143
|
+
setCurrentFilter(newFilter);
|
|
156
144
|
};
|
|
157
145
|
|
|
158
146
|
const parsedQueryParams = {
|
|
159
147
|
...queryParams,
|
|
160
|
-
where:
|
|
148
|
+
where: { ...queryParams.where }
|
|
161
149
|
};
|
|
162
150
|
|
|
151
|
+
if (parsedQueryParams.where.type === 'all') delete parsedQueryParams.where.type;
|
|
152
|
+
|
|
163
153
|
return [
|
|
164
154
|
{
|
|
165
155
|
queryParams: parsedQueryParams,
|
|
166
156
|
loading,
|
|
167
157
|
data: {
|
|
168
158
|
files: allResults,
|
|
169
|
-
all: counters ? counters.all : 0,
|
|
170
|
-
images: counters ? counters.image : 0,
|
|
171
|
-
videos: counters ? counters.video : 0,
|
|
172
|
-
documents: counters ? counters.text : 0
|
|
159
|
+
all: counters ? formatCounterNumber(counters.all) : 0,
|
|
160
|
+
images: counters ? formatCounterNumber(counters.image) : 0,
|
|
161
|
+
videos: counters ? formatCounterNumber(counters.video) : 0,
|
|
162
|
+
documents: counters ? formatCounterNumber(counters.text) : 0
|
|
173
163
|
}
|
|
174
164
|
},
|
|
175
165
|
{ setQueryParams, clearList, removeFile, addNewFile, updateFile }
|
|
176
166
|
];
|
|
177
167
|
}
|
|
178
168
|
|
|
169
|
+
const formatCounterNumber = n => (n === 10000 ? '10000+' : n);
|
|
170
|
+
|
|
179
171
|
export default useGetFilesList;
|
|
@@ -4,22 +4,17 @@ import React, { useState, useEffect } from 'react';
|
|
|
4
4
|
import { SearchBar } from '@blaze-cms/plugin-search-ui';
|
|
5
5
|
import classnames from 'classnames';
|
|
6
6
|
import Select from '@blaze-react/select';
|
|
7
|
-
import { getQuery } from '@blaze-cms/admin-ui-utils';
|
|
8
|
-
import { useQuery } from '@apollo/client';
|
|
9
7
|
import { useMediaContext, MediaContext } from '../../utils/media-context';
|
|
10
8
|
import useFileList from '../FileList/useFileList';
|
|
11
9
|
|
|
12
10
|
const FilterPanel = () => {
|
|
13
11
|
const [searchTerm, setSearchTerm] = useState('');
|
|
14
|
-
const { filters, selectedFilter, changeSelectedFilter } = useMediaContext(
|
|
12
|
+
const { filters, selectedFilter, changeSelectedFilter, fileStores } = useMediaContext(
|
|
13
|
+
MediaContext
|
|
14
|
+
);
|
|
15
15
|
const { queryParams, data } = useFileList();
|
|
16
16
|
const [active, setActive] = useState(filters[0].id);
|
|
17
17
|
|
|
18
|
-
const fileStoresType = getQuery('GET_FILE_STORES');
|
|
19
|
-
const { data: { getFileStores: storeType = [] } = {} } = useQuery(fileStoresType, {
|
|
20
|
-
variables: { visibleInAdmin: true }
|
|
21
|
-
});
|
|
22
|
-
|
|
23
18
|
useEffect(
|
|
24
19
|
() => {
|
|
25
20
|
if (queryParams.searchTerm === null) {
|
|
@@ -91,8 +86,7 @@ const FilterPanel = () => {
|
|
|
91
86
|
return acc;
|
|
92
87
|
}, {});
|
|
93
88
|
const activeBarSegment = classnames('filter-panel__barWrapper--active', activeSegements);
|
|
94
|
-
|
|
95
|
-
const storeOptions = (storeType || []).map(type => [type.key, type.name]);
|
|
89
|
+
const storeOptions = (fileStores || []).map(type => [type.key, type.name]);
|
|
96
90
|
|
|
97
91
|
return (
|
|
98
92
|
<div className="filter-panel">
|
|
@@ -119,7 +113,11 @@ const FilterPanel = () => {
|
|
|
119
113
|
</div>
|
|
120
114
|
<div className="filter-panel__searchBarWrapper">
|
|
121
115
|
<div className="select__wrapper">
|
|
122
|
-
<Select
|
|
116
|
+
<Select
|
|
117
|
+
options={storeOptions}
|
|
118
|
+
onChange={onSelectFilter}
|
|
119
|
+
selected={selectedFilter.storeKey}
|
|
120
|
+
/>
|
|
123
121
|
</div>
|
|
124
122
|
<SearchBar
|
|
125
123
|
search={() =>
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
+
import { useQuery } from '@apollo/client';
|
|
4
|
+
import { getQuery } from '@blaze-cms/admin-ui-utils';
|
|
3
5
|
import Listing from './Listing';
|
|
4
6
|
import { availableFilters } from '../../utils/available-filters/available-filters';
|
|
5
7
|
import { MediaContextProvider } from '../../utils/media-context';
|
|
@@ -12,9 +14,16 @@ const ListingContainer = ({ handleSelectedFiles, maxItems, filesSelected }) => {
|
|
|
12
14
|
const [selectedFilter, setSelectedFilter] = useState({
|
|
13
15
|
filter: 'all',
|
|
14
16
|
isSearch: false,
|
|
15
|
-
searchTerm: null
|
|
17
|
+
searchTerm: null,
|
|
18
|
+
storeKey: null
|
|
16
19
|
});
|
|
17
20
|
|
|
21
|
+
const fileStoresType = getQuery('GET_FILE_STORES');
|
|
22
|
+
const { loading, data: { getFileStores: fileStores = [] } = {} } = useQuery(fileStoresType, {
|
|
23
|
+
variables: { visibleInAdmin: true }
|
|
24
|
+
});
|
|
25
|
+
if (loading) return null;
|
|
26
|
+
|
|
18
27
|
const getSelectedFiles = ({ id }) => {
|
|
19
28
|
const existPreviousFile = existPrevious(selectedFiles, id);
|
|
20
29
|
|
|
@@ -33,11 +42,18 @@ const ListingContainer = ({ handleSelectedFiles, maxItems, filesSelected }) => {
|
|
|
33
42
|
|
|
34
43
|
const handleDisplayFileUploadModal = param => setDisplayFileUploadModal(param);
|
|
35
44
|
|
|
45
|
+
const defaultFileStore = (fileStores.find(({ isDefault }) => isDefault) || {}).key;
|
|
46
|
+
|
|
36
47
|
return (
|
|
37
48
|
<MediaContextProvider
|
|
38
49
|
value={{
|
|
50
|
+
fileStores,
|
|
51
|
+
defaultFileStore,
|
|
39
52
|
changeSelectedFilter: value => setSelectedFilter(value),
|
|
40
|
-
selectedFilter
|
|
53
|
+
selectedFilter: {
|
|
54
|
+
...selectedFilter,
|
|
55
|
+
storeKey: selectedFilter.storeKey || defaultFileStore
|
|
56
|
+
},
|
|
41
57
|
selectedFiles,
|
|
42
58
|
getSelectedFiles,
|
|
43
59
|
filters: availableFilters,
|
package/src/constants.js
CHANGED
|
@@ -22,7 +22,7 @@ const STORE_KEY = 'storeKey';
|
|
|
22
22
|
const NAME = 'name';
|
|
23
23
|
|
|
24
24
|
const ALL = 'all';
|
|
25
|
-
const INVALID_STORE_KEY_VALUES = ['', 'Please Choose...'];
|
|
25
|
+
const INVALID_STORE_KEY_VALUES = [null, '', 'Please Choose...'];
|
|
26
26
|
const PREVIEW = 'Preview';
|
|
27
27
|
const REORDER = 'Reorder';
|
|
28
28
|
const IMAGES = 'Images';
|