@blaze-cms/plugin-media-ui 0.146.0-node18.1 → 0.146.0-rc-eagle-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.
Files changed (258) hide show
  1. package/CHANGELOG.md +13 -12
  2. package/lib/components/CardMedia/CardMedia.js +235 -244
  3. package/lib/components/CardMedia/CardMedia.js.map +1 -1
  4. package/lib/components/CardMedia/index.js +2 -3
  5. package/lib/components/CardMedia/index.js.map +1 -1
  6. package/lib/components/EditMediaFile/EditMediaFile.js +149 -115
  7. package/lib/components/EditMediaFile/EditMediaFile.js.map +1 -1
  8. package/lib/components/EditMediaFile/EditMediaFilePage.js +89 -97
  9. package/lib/components/EditMediaFile/EditMediaFilePage.js.map +1 -1
  10. package/lib/components/EditMediaFile/index.js +2 -3
  11. package/lib/components/EditMediaFile/index.js.map +1 -1
  12. package/lib/components/EditorAdapter/EditorAdapter.js +43 -22
  13. package/lib/components/EditorAdapter/EditorAdapter.js.map +1 -1
  14. package/lib/components/EditorAdapter/index.js +2 -3
  15. package/lib/components/EditorAdapter/index.js.map +1 -1
  16. package/lib/components/FileList/FilesListContext/index.js +3 -4
  17. package/lib/components/FileList/FilesListContext/index.js.map +1 -1
  18. package/lib/components/FileList/FilesListProvider/index.js +27 -29
  19. package/lib/components/FileList/FilesListProvider/index.js.map +1 -1
  20. package/lib/components/FileList/useFileList/index.js +3 -6
  21. package/lib/components/FileList/useFileList/index.js.map +1 -1
  22. package/lib/components/FileList/useGetFiles/getFiles.js +167 -185
  23. package/lib/components/FileList/useGetFiles/getFiles.js.map +1 -1
  24. package/lib/components/FileList/useGetFiles/index.js +2 -3
  25. package/lib/components/FileList/useGetFiles/index.js.map +1 -1
  26. package/lib/components/FileList/useGetFiles/useGetFiles.js +93 -133
  27. package/lib/components/FileList/useGetFiles/useGetFiles.js.map +1 -1
  28. package/lib/components/FileList/useGetFilesList/getCounters.js +10 -30
  29. package/lib/components/FileList/useGetFilesList/getCounters.js.map +1 -1
  30. package/lib/components/FileList/useGetFilesList/index.js +2 -3
  31. package/lib/components/FileList/useGetFilesList/index.js.map +1 -1
  32. package/lib/components/FileList/useGetFilesList/useGetFilesList.js +92 -110
  33. package/lib/components/FileList/useGetFilesList/useGetFilesList.js.map +1 -1
  34. package/lib/components/FilePreview/Actions/index.js +25 -38
  35. package/lib/components/FilePreview/Actions/index.js.map +1 -1
  36. package/lib/components/FilePreview/Image/Image.js +35 -24
  37. package/lib/components/FilePreview/Image/Image.js.map +1 -1
  38. package/lib/components/FilePreview/Image/RawImage.js +25 -27
  39. package/lib/components/FilePreview/Image/RawImage.js.map +1 -1
  40. package/lib/components/FilePreview/Image/imageSchema.js +10 -7
  41. package/lib/components/FilePreview/Image/imageSchema.js.map +1 -1
  42. package/lib/components/FilePreview/Image/index.js +1 -2
  43. package/lib/components/FilePreview/Image/index.js.map +1 -1
  44. package/lib/components/FilePreview/ModalContext.js +9 -0
  45. package/lib/components/FilePreview/ModalContext.js.map +1 -0
  46. package/lib/components/FilePreview/PDF/PDF.js +44 -31
  47. package/lib/components/FilePreview/PDF/PDF.js.map +1 -1
  48. package/lib/components/FilePreview/PDF/RawPDF.js +27 -29
  49. package/lib/components/FilePreview/PDF/RawPDF.js.map +1 -1
  50. package/lib/components/FilePreview/PDF/index.js +1 -2
  51. package/lib/components/FilePreview/PDF/index.js.map +1 -1
  52. package/lib/components/FilePreview/PDF/schema.js +3 -3
  53. package/lib/components/FilePreview/PDF/schema.js.map +1 -1
  54. package/lib/components/FilePreview/get-preview.js +12 -10
  55. package/lib/components/FilePreview/get-preview.js.map +1 -1
  56. package/lib/components/FilePreview/index.js +111 -58
  57. package/lib/components/FilePreview/index.js.map +1 -1
  58. package/lib/components/FilePreview/previewDefault/PreviewDefault.js +35 -23
  59. package/lib/components/FilePreview/previewDefault/PreviewDefault.js.map +1 -1
  60. package/lib/components/FilePreview/previewDefault/RawPreviewDefault.js +33 -27
  61. package/lib/components/FilePreview/previewDefault/RawPreviewDefault.js.map +1 -1
  62. package/lib/components/FilePreview/previewDefault/icons/DefaultIcon.js +120 -123
  63. package/lib/components/FilePreview/previewDefault/icons/DefaultIcon.js.map +1 -1
  64. package/lib/components/FilePreview/previewDefault/icons/index.js +2 -3
  65. package/lib/components/FilePreview/previewDefault/icons/index.js.map +1 -1
  66. package/lib/components/FilePreview/previewDefault/index.js +1 -2
  67. package/lib/components/FilePreview/previewDefault/index.js.map +1 -1
  68. package/lib/components/FilePreview/previewDefault/previewDefaultSchema.js +3 -3
  69. package/lib/components/FilePreview/previewDefault/previewDefaultSchema.js.map +1 -1
  70. package/lib/components/FilePreviewReadOnly/FileList.js +10 -12
  71. package/lib/components/FilePreviewReadOnly/FileList.js.map +1 -1
  72. package/lib/components/FilePreviewReadOnly/FilePreviewList.js +14 -20
  73. package/lib/components/FilePreviewReadOnly/FilePreviewList.js.map +1 -1
  74. package/lib/components/FilePreviewReadOnly/FilePreviewReadOnly.js +53 -98
  75. package/lib/components/FilePreviewReadOnly/FilePreviewReadOnly.js.map +1 -1
  76. package/lib/components/FilePreviewReadOnly/index.js +2 -3
  77. package/lib/components/FilePreviewReadOnly/index.js.map +1 -1
  78. package/lib/components/FilePreviewReadOnly/mappers/format-initial-value.js +7 -8
  79. package/lib/components/FilePreviewReadOnly/mappers/format-initial-value.js.map +1 -1
  80. package/lib/components/FilePreviewReadOnly/mappers/index.js +1 -2
  81. package/lib/components/FilePreviewReadOnly/mappers/index.js.map +1 -1
  82. package/lib/components/FileUploadAdapter/FileList.js +27 -39
  83. package/lib/components/FileUploadAdapter/FileList.js.map +1 -1
  84. package/lib/components/FileUploadAdapter/FilePreviewList.js +14 -20
  85. package/lib/components/FileUploadAdapter/FilePreviewList.js.map +1 -1
  86. package/lib/components/FileUploadAdapter/FileReorderList.js +18 -21
  87. package/lib/components/FileUploadAdapter/FileReorderList.js.map +1 -1
  88. package/lib/components/FileUploadAdapter/FileReorderListItem.js +20 -23
  89. package/lib/components/FileUploadAdapter/FileReorderListItem.js.map +1 -1
  90. package/lib/components/FileUploadAdapter/FileUploadAdapter.js +253 -341
  91. package/lib/components/FileUploadAdapter/FileUploadAdapter.js.map +1 -1
  92. package/lib/components/FileUploadAdapter/index.js +2 -3
  93. package/lib/components/FileUploadAdapter/index.js.map +1 -1
  94. package/lib/components/FileUploadAdapter/mappers/format-initial-value.js +7 -8
  95. package/lib/components/FileUploadAdapter/mappers/format-initial-value.js.map +1 -1
  96. package/lib/components/FileUploadAdapter/mappers/get-button-text.js +9 -6
  97. package/lib/components/FileUploadAdapter/mappers/get-button-text.js.map +1 -1
  98. package/lib/components/FileUploadAdapter/mappers/get-format.js +7 -13
  99. package/lib/components/FileUploadAdapter/mappers/get-format.js.map +1 -1
  100. package/lib/components/FileUploadAdapter/mappers/get-number-files-pending-to-fetch.js +6 -5
  101. package/lib/components/FileUploadAdapter/mappers/get-number-files-pending-to-fetch.js.map +1 -1
  102. package/lib/components/FileUploadAdapter/mappers/index.js +6 -7
  103. package/lib/components/FileUploadAdapter/mappers/index.js.map +1 -1
  104. package/lib/components/FileUploadAdapter/mappers/is-unselecting.js +2 -10
  105. package/lib/components/FileUploadAdapter/mappers/is-unselecting.js.map +1 -1
  106. package/lib/components/FileUploadAdapter/mappers/transform-to-array.js +2 -5
  107. package/lib/components/FileUploadAdapter/mappers/transform-to-array.js.map +1 -1
  108. package/lib/components/FileUploadAdapter/useLimit.js +4 -10
  109. package/lib/components/FileUploadAdapter/useLimit.js.map +1 -1
  110. package/lib/components/FileUploadModal/FileUploadModal.js +215 -146
  111. package/lib/components/FileUploadModal/FileUploadModal.js.map +1 -1
  112. package/lib/components/FileUploadModal/index.js +2 -3
  113. package/lib/components/FileUploadModal/index.js.map +1 -1
  114. package/lib/components/FilterPanel/FilterPanel.js +49 -151
  115. package/lib/components/FilterPanel/FilterPanel.js.map +1 -1
  116. package/lib/components/FilterPanel/MediaSearchFilter.js +41 -0
  117. package/lib/components/FilterPanel/MediaSearchFilter.js.map +1 -0
  118. package/lib/components/FilterPanel/index.js +2 -3
  119. package/lib/components/FilterPanel/index.js.map +1 -1
  120. package/lib/components/ListingContainer/Listing/Listing.js +58 -48
  121. package/lib/components/ListingContainer/Listing/Listing.js.map +1 -1
  122. package/lib/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +83 -96
  123. package/lib/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js.map +1 -1
  124. package/lib/components/ListingContainer/Listing/MediaListing/MediaFileList/index.js +2 -3
  125. package/lib/components/ListingContainer/Listing/MediaListing/MediaFileList/index.js.map +1 -1
  126. package/lib/components/ListingContainer/Listing/MediaListing/MediaListing.js +23 -26
  127. package/lib/components/ListingContainer/Listing/MediaListing/MediaListing.js.map +1 -1
  128. package/lib/components/ListingContainer/Listing/MediaListing/index.js +2 -3
  129. package/lib/components/ListingContainer/Listing/MediaListing/index.js.map +1 -1
  130. package/lib/components/ListingContainer/Listing/index.js +2 -3
  131. package/lib/components/ListingContainer/Listing/index.js.map +1 -1
  132. package/lib/components/ListingContainer/ListingContainer.js +74 -93
  133. package/lib/components/ListingContainer/ListingContainer.js.map +1 -1
  134. package/lib/components/ListingContainer/index.js +2 -3
  135. package/lib/components/ListingContainer/index.js.map +1 -1
  136. package/lib/components/ListingContainer/mappers/exist-previous.js +3 -10
  137. package/lib/components/ListingContainer/mappers/exist-previous.js.map +1 -1
  138. package/lib/components/ListingContainer/mappers/index.js +2 -3
  139. package/lib/components/ListingContainer/mappers/index.js.map +1 -1
  140. package/lib/components/MediaListing.js +15 -26
  141. package/lib/components/MediaListing.js.map +1 -1
  142. package/lib/constants.js +17 -17
  143. package/lib/constants.js.map +1 -1
  144. package/lib/icons/MediaLibraryIcon.js +17 -20
  145. package/lib/icons/MediaLibraryIcon.js.map +1 -1
  146. package/lib/icons/index.js +2 -3
  147. package/lib/icons/index.js.map +1 -1
  148. package/lib/index.js +67 -92
  149. package/lib/index.js.map +1 -1
  150. package/lib/utils/available-filters/available-filters.js +1 -2
  151. package/lib/utils/available-filters/available-filters.js.map +1 -1
  152. package/lib/utils/bustUrl.js +13 -0
  153. package/lib/utils/bustUrl.js.map +1 -0
  154. package/lib/utils/media-context/index.js +4 -5
  155. package/lib/utils/media-context/index.js.map +1 -1
  156. package/lib/utils/media-context/media-context.js +3 -4
  157. package/lib/utils/media-context/media-context.js.map +1 -1
  158. package/lib/utils/media-context/useMediaContext.js +2 -4
  159. package/lib/utils/media-context/useMediaContext.js.map +1 -1
  160. package/lib-es/components/CardMedia/CardMedia.js +109 -52
  161. package/lib-es/components/CardMedia/CardMedia.js.map +1 -1
  162. package/lib-es/components/EditMediaFile/EditMediaFile.js +109 -53
  163. package/lib-es/components/EditMediaFile/EditMediaFile.js.map +1 -1
  164. package/lib-es/components/EditMediaFile/EditMediaFilePage.js +45 -15
  165. package/lib-es/components/EditMediaFile/EditMediaFilePage.js.map +1 -1
  166. package/lib-es/components/EditorAdapter/EditorAdapter.js +26 -6
  167. package/lib-es/components/EditorAdapter/EditorAdapter.js.map +1 -1
  168. package/lib-es/components/FileList/useGetFiles/getFiles.js +6 -3
  169. package/lib-es/components/FileList/useGetFiles/getFiles.js.map +1 -1
  170. package/lib-es/components/FileList/useGetFiles/useGetFiles.js +7 -2
  171. package/lib-es/components/FileList/useGetFiles/useGetFiles.js.map +1 -1
  172. package/lib-es/components/FileList/useGetFilesList/useGetFilesList.js +4 -1
  173. package/lib-es/components/FileList/useGetFilesList/useGetFilesList.js.map +1 -1
  174. package/lib-es/components/FilePreview/Actions/index.js +2 -2
  175. package/lib-es/components/FilePreview/Actions/index.js.map +1 -1
  176. package/lib-es/components/FilePreview/Image/Image.js +16 -3
  177. package/lib-es/components/FilePreview/Image/Image.js.map +1 -1
  178. package/lib-es/components/FilePreview/Image/imageSchema.js +9 -5
  179. package/lib-es/components/FilePreview/Image/imageSchema.js.map +1 -1
  180. package/lib-es/components/FilePreview/ModalContext.js +3 -0
  181. package/lib-es/components/FilePreview/ModalContext.js.map +1 -0
  182. package/lib-es/components/FilePreview/PDF/PDF.js +19 -4
  183. package/lib-es/components/FilePreview/PDF/PDF.js.map +1 -1
  184. package/lib-es/components/FilePreview/PDF/schema.js +2 -1
  185. package/lib-es/components/FilePreview/PDF/schema.js.map +1 -1
  186. package/lib-es/components/FilePreview/index.js +72 -9
  187. package/lib-es/components/FilePreview/index.js.map +1 -1
  188. package/lib-es/components/FilePreview/previewDefault/PreviewDefault.js +18 -4
  189. package/lib-es/components/FilePreview/previewDefault/PreviewDefault.js.map +1 -1
  190. package/lib-es/components/FilePreview/previewDefault/RawPreviewDefault.js +12 -4
  191. package/lib-es/components/FilePreview/previewDefault/RawPreviewDefault.js.map +1 -1
  192. package/lib-es/components/FilePreview/previewDefault/previewDefaultSchema.js +2 -1
  193. package/lib-es/components/FilePreview/previewDefault/previewDefaultSchema.js.map +1 -1
  194. package/lib-es/components/FilePreviewReadOnly/FileList.js +2 -2
  195. package/lib-es/components/FilePreviewReadOnly/FileList.js.map +1 -1
  196. package/lib-es/components/FilePreviewReadOnly/FilePreviewReadOnly.js +14 -12
  197. package/lib-es/components/FilePreviewReadOnly/FilePreviewReadOnly.js.map +1 -1
  198. package/lib-es/components/FileUploadAdapter/FileUploadAdapter.js +78 -43
  199. package/lib-es/components/FileUploadAdapter/FileUploadAdapter.js.map +1 -1
  200. package/lib-es/components/FileUploadAdapter/mappers/get-button-text.js +5 -3
  201. package/lib-es/components/FileUploadAdapter/mappers/get-button-text.js.map +1 -1
  202. package/lib-es/components/FileUploadAdapter/mappers/get-number-files-pending-to-fetch.js +5 -4
  203. package/lib-es/components/FileUploadAdapter/mappers/get-number-files-pending-to-fetch.js.map +1 -1
  204. package/lib-es/components/FileUploadModal/FileUploadModal.js +157 -29
  205. package/lib-es/components/FileUploadModal/FileUploadModal.js.map +1 -1
  206. package/lib-es/components/FilterPanel/FilterPanel.js +43 -123
  207. package/lib-es/components/FilterPanel/FilterPanel.js.map +1 -1
  208. package/lib-es/components/FilterPanel/MediaSearchFilter.js +34 -0
  209. package/lib-es/components/FilterPanel/MediaSearchFilter.js.map +1 -0
  210. package/lib-es/components/ListingContainer/Listing/Listing.js +17 -5
  211. package/lib-es/components/ListingContainer/Listing/Listing.js.map +1 -1
  212. package/lib-es/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +21 -10
  213. package/lib-es/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js.map +1 -1
  214. package/lib-es/components/ListingContainer/Listing/MediaListing/MediaListing.js +12 -3
  215. package/lib-es/components/ListingContainer/Listing/MediaListing/MediaListing.js.map +1 -1
  216. package/lib-es/components/ListingContainer/ListingContainer.js +18 -6
  217. package/lib-es/components/ListingContainer/ListingContainer.js.map +1 -1
  218. package/lib-es/constants.js +3 -2
  219. package/lib-es/constants.js.map +1 -1
  220. package/lib-es/index.js +20 -4
  221. package/lib-es/index.js.map +1 -1
  222. package/lib-es/utils/bustUrl.js +7 -0
  223. package/lib-es/utils/bustUrl.js.map +1 -0
  224. package/package.json +20 -13
  225. package/src/components/CardMedia/CardMedia.js +131 -82
  226. package/src/components/EditMediaFile/EditMediaFile.js +123 -46
  227. package/src/components/EditMediaFile/EditMediaFilePage.js +41 -10
  228. package/src/components/EditorAdapter/EditorAdapter.js +31 -4
  229. package/src/components/FileList/useGetFiles/getFiles.js +12 -4
  230. package/src/components/FileList/useGetFiles/useGetFiles.js +3 -4
  231. package/src/components/FileList/useGetFilesList/useGetFilesList.js +2 -1
  232. package/src/components/FilePreview/Actions/index.js +25 -27
  233. package/src/components/FilePreview/Image/Image.js +15 -2
  234. package/src/components/FilePreview/Image/imageSchema.js +9 -5
  235. package/src/components/FilePreview/ModalContext.js +3 -0
  236. package/src/components/FilePreview/PDF/PDF.js +17 -4
  237. package/src/components/FilePreview/PDF/schema.js +2 -1
  238. package/src/components/FilePreview/index.js +69 -6
  239. package/src/components/FilePreview/previewDefault/PreviewDefault.js +16 -3
  240. package/src/components/FilePreview/previewDefault/RawPreviewDefault.js +17 -7
  241. package/src/components/FilePreview/previewDefault/previewDefaultSchema.js +2 -1
  242. package/src/components/FilePreviewReadOnly/FileList.js +1 -3
  243. package/src/components/FilePreviewReadOnly/FilePreviewReadOnly.js +17 -29
  244. package/src/components/FileUploadAdapter/FileUploadAdapter.js +66 -32
  245. package/src/components/FileUploadAdapter/mappers/get-button-text.js +4 -3
  246. package/src/components/FileUploadAdapter/mappers/get-number-files-pending-to-fetch.js +6 -4
  247. package/src/components/FileUploadModal/FileUploadModal.js +156 -45
  248. package/src/components/FilterPanel/FilterPanel.js +44 -129
  249. package/src/components/FilterPanel/MediaSearchFilter.js +32 -0
  250. package/src/components/ListingContainer/Listing/Listing.js +15 -5
  251. package/src/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +18 -7
  252. package/src/components/ListingContainer/Listing/MediaListing/MediaListing.js +10 -2
  253. package/src/components/ListingContainer/ListingContainer.js +17 -5
  254. package/src/constants.js +16 -2
  255. package/src/index.js +17 -14
  256. package/src/utils/bustUrl.js +6 -0
  257. package/babel.config.js +0 -3
  258. package/jest.config.js +0 -5
@@ -1,16 +1,41 @@
1
1
  import React from 'react';
2
2
  import DraftEditor from '@blaze-react/drafteditor';
3
3
  import PropTypes from 'prop-types';
4
+ import Tooltip from '@blaze-react/tooltip';
4
5
 
5
- const DraftEditorAdapter = ({ id, value, onChange, error, validationMessage, label, ...props }) => (
6
+ const customStyleMap = {
7
+ SUPERSCRIPT: {
8
+ fontSize: '0.75em',
9
+ verticalAlign: 'super'
10
+ },
11
+ SUBSCRIPT: {
12
+ fontSize: '0.75em',
13
+ verticalAlign: 'sub'
14
+ }
15
+ };
16
+
17
+ const DraftEditorAdapter = ({
18
+ id,
19
+ value,
20
+ onChange,
21
+ error,
22
+ validationMessage,
23
+ label,
24
+ tooltip,
25
+ ...props
26
+ }) => (
6
27
  <div className="form-field form-field--full-width">
7
- <label>{label}</label>
28
+ <label>
29
+ <Tooltip tooltipContent={tooltip} />
30
+ </label>
8
31
  <DraftEditor
9
32
  name={id}
10
33
  value={value}
11
34
  onChange={onChange}
12
35
  error={error}
13
36
  validationMessage={validationMessage}
37
+ tooltip={{ tooltipContent: tooltip }}
38
+ customStyleMap={customStyleMap}
14
39
  />
15
40
  </div>
16
41
  );
@@ -21,12 +46,14 @@ DraftEditorAdapter.propTypes = {
21
46
  onChange: PropTypes.func.isRequired,
22
47
  error: PropTypes.bool,
23
48
  validationMessage: PropTypes.string,
24
- label: PropTypes.string.isRequired
49
+ label: PropTypes.string.isRequired,
50
+ tooltip: PropTypes.string
25
51
  };
26
52
 
27
53
  DraftEditorAdapter.defaultProps = {
28
54
  error: false,
29
- validationMessage: undefined
55
+ validationMessage: undefined,
56
+ tooltip: ''
30
57
  };
31
58
 
32
59
  export default DraftEditorAdapter;
@@ -1,7 +1,15 @@
1
1
  import { getQuery } from '@blaze-cms/admin-ui-utils';
2
2
  import { ALL, INVALID_STORE_KEY_VALUES } from '../../../constants';
3
3
 
4
- const getFromSearch = async ({ searchTerm, offset, limit, where, client, fileStores = [] }) => {
4
+ const getFromSearch = async ({
5
+ searchTerm,
6
+ offset,
7
+ limit,
8
+ where,
9
+ client,
10
+ fileStores = [],
11
+ esFilters = []
12
+ }) => {
5
13
  const allTypesMatches = [
6
14
  {
7
15
  match: { type: 'image' }
@@ -19,7 +27,7 @@ const getFromSearch = async ({ searchTerm, offset, limit, where, client, fileSto
19
27
  }
20
28
  ];
21
29
  const match = !where.type || where.type === ALL ? allTypesMatches : matchSpecificType;
22
- const mustMatch = [];
30
+ const mustMatch = [...esFilters];
23
31
 
24
32
  if (searchTerm) {
25
33
  mustMatch.push({
@@ -160,7 +168,7 @@ const getFromSearch = async ({ searchTerm, offset, limit, where, client, fileSto
160
168
  return { files, all, image, video, text };
161
169
  };
162
170
 
163
- const getFiles = ({ offset, limit, where, searchTerm, fileStores }, client) =>
164
- getFromSearch({ searchTerm, offset, limit, where, client, fileStores });
171
+ const getFiles = ({ searchTerm, offset, limit, where, esFilters, fileStores }, client) =>
172
+ getFromSearch({ searchTerm, offset, limit, where, esFilters, client, fileStores });
165
173
 
166
174
  export default getFiles;
@@ -29,8 +29,8 @@ function useGetFiles() {
29
29
 
30
30
  useEffect(
31
31
  () => {
32
- const { offset, limit, where, sort, searchTerm, isSearch } = queryParams;
33
- const newFilter = JSON.stringify(where);
32
+ const { offset, limit, where, sort, searchTerm, isSearch, esFilters } = queryParams;
33
+ const newFilter = JSON.stringify({ where, esFilters });
34
34
  const isNewFilterSet = newFilter !== previousFilter;
35
35
  const isNewOffsetSet = previousOffset !== null && offset !== previousOffset;
36
36
  const isNewSearchTermSet = searchTerm && previousSearchTerm !== searchTerm;
@@ -41,9 +41,8 @@ function useGetFiles() {
41
41
  if (data.files.length) {
42
42
  setData({ files: [] });
43
43
  }
44
-
45
44
  const { files, total, all, image, video, text } = await getFiles(
46
- { offset, limit, where, sort, searchTerm, isSearch, fileStores },
45
+ { offset, limit, where, sort, searchTerm, isSearch, esFilters, fileStores },
47
46
  client
48
47
  );
49
48
  setData({ files, total, all, image, video, text });
@@ -137,8 +137,9 @@ function useGetFilesList() {
137
137
  const setQueryParams = params => {
138
138
  const isNewSearchTerm = params.isSearch && previousSearchTerm !== params.searchTerm;
139
139
  const hasDeletedSearchTerm = previousSearchTerm && params.searchTerm === null;
140
- const newFilter = JSON.stringify(params.where);
140
+ const newFilter = JSON.stringify({ where: params.where, esFilters: params.esFilters });
141
141
  const isNewFilter = newFilter !== previousFilter;
142
+
142
143
  const shouldClearList = hasDeletedSearchTerm || isNewFilter || isNewSearchTerm;
143
144
  shouldClearList ? clearList(params) : setParams(params);
144
145
  setCurrentFilter(newFilter);
@@ -7,34 +7,32 @@ const Actions = ({ file }) => {
7
7
  const [, extension] = file.mimetype.split('/');
8
8
 
9
9
  return (
10
- <>
11
- <div className="FilePreviewItem__info__actions">
12
- <div className="FilePreviewItem__info__actions FilePreviewItem__info__actions--media-type">
13
- <i className="FilePreviewItem__info__actionsIcon material-icons">insert_photo</i>{' '}
14
- <span>{extension}</span>
15
- </div>
16
- <div>
17
- {handleEditModal && (
18
- <div
19
- data-testid={`open-media-library-${file.id}`}
20
- className="FilePreviewItem__info__actionsIcon material-icons edit"
21
- aria-hidden="true"
22
- onClick={() => handleEditModal(file)}>
23
- <i className="fas fa-pen fa-xs" />
24
- </div>
25
- )}
26
- {onUnselectFile && (
27
- <div
28
- data-testid={`unselect-${file.id}`}
29
- className="FilePreviewItem__info__actionsIcon material-icons delete"
30
- aria-hidden="true"
31
- onClick={() => onUnselectFile([file.id])}>
32
- <i className="fas fa-trash fa-xs" />
33
- </div>
34
- )}
35
- </div>
10
+ <div className="FilePreviewItem__info__actions">
11
+ <div className="FilePreviewItem__info__actions FilePreviewItem__info__actions--media-type">
12
+ <i className="FilePreviewItem__info__actionsIcon material-icons">insert_photo</i>{' '}
13
+ <span>{extension}</span>
36
14
  </div>
37
- </>
15
+ <div>
16
+ {handleEditModal && (
17
+ <div
18
+ data-testid={`open-media-library-${file.id}`}
19
+ className="FilePreviewItem__info__actionsIcon material-icons edit"
20
+ aria-hidden="true"
21
+ onClick={() => handleEditModal(file)}>
22
+ <i className="fas fa-pen fa-xs" />
23
+ </div>
24
+ )}
25
+ {onUnselectFile && (
26
+ <div
27
+ data-testid={`unselect-${file.id}`}
28
+ className="FilePreviewItem__info__actionsIcon material-icons delete"
29
+ aria-hidden="true"
30
+ onClick={() => onUnselectFile([file.id])}>
31
+ <i className="fas fa-trash fa-xs" />
32
+ </div>
33
+ )}
34
+ </div>
35
+ </div>
38
36
  );
39
37
  };
40
38
 
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
+ import Button from '@blaze-react/button';
3
4
 
4
- const Image = ({ url, name, children }) => (
5
+ const Image = ({ url, name, children, handleChangeFile, showChangeButton }) => (
5
6
  <div className="preview">
6
7
  <div className="preview__file preview__file--image">
7
8
  <img src={url} alt={name} />
@@ -12,6 +13,11 @@ const Image = ({ url, name, children }) => (
12
13
  Original
13
14
  </a>
14
15
  </p>
16
+ {showChangeButton && (
17
+ <div className="preview__change-button">
18
+ <Button onClick={handleChangeFile}>Change file</Button>
19
+ </div>
20
+ )}
15
21
  </div>
16
22
  </div>
17
23
  {children}
@@ -21,7 +27,14 @@ const Image = ({ url, name, children }) => (
21
27
  Image.propTypes = {
22
28
  url: PropTypes.string.isRequired,
23
29
  name: PropTypes.string.isRequired,
24
- children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired
30
+ children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
31
+ handleChangeFile: PropTypes.func,
32
+ showChangeButton: PropTypes.bool
33
+ };
34
+
35
+ Image.defaultProps = {
36
+ handleChangeFile: () => {},
37
+ showChangeButton: false
25
38
  };
26
39
 
27
40
  export { Image };
@@ -23,27 +23,31 @@ const imageSchema = {
23
23
  showInForm: true,
24
24
  label: 'Alt text',
25
25
  formFieldType: 'text',
26
- formPriority: 3.0
26
+ formPriority: 3.0,
27
+ isDataPropery: true
27
28
  },
28
29
  caption: {
29
30
  type: 'string',
30
31
  showInForm: true,
31
32
  formFieldType: 'text',
32
- formPriority: 4.0
33
+ formPriority: 4.0,
34
+ isDataPropery: true
33
35
  },
34
36
  credits: {
35
37
  type: 'string',
36
38
  showInForm: true,
37
39
  formFieldType: 'text',
38
- formPriority: 5.0
40
+ formPriority: 5.0,
41
+ isDataPropery: true
39
42
  },
40
43
  hrefUrl: {
41
44
  type: 'string',
42
45
  format: 'uri-template',
43
- label: 'url',
46
+ label: 'Image hyperlink',
44
47
  showInForm: true,
45
48
  formFieldType: 'text',
46
- description: 'Url format is not valid'
49
+ description: 'Url format is not valid',
50
+ isDataPropery: true
47
51
  }
48
52
  },
49
53
  required: ['name']
@@ -0,0 +1,3 @@
1
+ import { createContext } from 'react';
2
+
3
+ export const ModalContext = createContext(false);
@@ -1,10 +1,11 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
+ import Button from '@blaze-react/button';
3
4
 
4
- const PDF = ({ mimetype, url, name, children }) => (
5
- <div className="preview">
5
+ const PDF = ({ mimetype, url, name, children, handleChangeFile, showChangeButton }) => (
6
+ <div className="preview" key={`pdf-${url}`}>
6
7
  <div className="preview__file preview__file--pdf">
7
- <object data={url} type={mimetype} className="preview__file--pdf">
8
+ <object key={url} data={url} type={mimetype} className="preview__file--pdf">
8
9
  <p>
9
10
  <a href={url} rel="noopener noreferrer" target="_blank">
10
11
  Download {name}
@@ -18,6 +19,11 @@ const PDF = ({ mimetype, url, name, children }) => (
18
19
  Original
19
20
  </a>
20
21
  </p>
22
+ {showChangeButton && (
23
+ <div className="preview__change-button">
24
+ <Button onClick={handleChangeFile}>Change file</Button>
25
+ </div>
26
+ )}
21
27
  </div>
22
28
  </div>
23
29
  {children}
@@ -28,7 +34,14 @@ PDF.propTypes = {
28
34
  mimetype: PropTypes.string.isRequired,
29
35
  url: PropTypes.string.isRequired,
30
36
  name: PropTypes.string.isRequired,
31
- children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired
37
+ children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
38
+ handleChangeFile: PropTypes.func,
39
+ showChangeButton: PropTypes.bool
40
+ };
41
+
42
+ PDF.defaultProps = {
43
+ handleChangeFile: () => {},
44
+ showChangeButton: false
32
45
  };
33
46
 
34
47
  export { PDF };
@@ -11,7 +11,8 @@ const PDFSchema = {
11
11
  caption: {
12
12
  type: 'string',
13
13
  showInForm: true,
14
- formFieldType: 'text'
14
+ formFieldType: 'text',
15
+ isDataPropery: true
15
16
  }
16
17
  },
17
18
  required: ['name']
@@ -1,13 +1,62 @@
1
1
  import React from 'react';
2
2
  import { FormBuilder } from '@blaze-cms/react-form-builder';
3
3
  import PropTypes from 'prop-types';
4
+ import { useQuery } from '@apollo/client';
5
+ import { getQuery, getDynamicQuery } from '@blaze-cms/admin-ui-utils';
4
6
  import { getPreview } from './get-preview';
7
+ import { FILE_DEFAULT_PROPS } from '../../constants';
5
8
 
6
- const FilePreview = ({ file, handleFormChange, displayForm, previewType, children }) => {
7
- const { name, url, mimetype, data, store } = file;
9
+ const FilePreview = ({
10
+ file,
11
+ handleFormChange,
12
+ displayForm,
13
+ previewType,
14
+ children,
15
+ handleChangeFile,
16
+ showChangeButton,
17
+ disableFilePreview
18
+ }) => {
19
+ const {
20
+ data: schemaData = {
21
+ getEntitySchemas: [
22
+ {
23
+ properties: {},
24
+ actions: {
25
+ get: 'getFile'
26
+ }
27
+ }
28
+ ]
29
+ },
30
+ loading: schemaLoading
31
+ } = useQuery(getQuery('GET_ENTITY_SCHEMA'), {
32
+ variables: { identifier: 'file' }
33
+ });
34
+
35
+ const [fileSchema] = schemaData && schemaData.getEntitySchemas ? schemaData.getEntitySchemas : [];
36
+
37
+ const fileQuery = getDynamicQuery('DATA_QUERY')(fileSchema, file.id, null, FILE_DEFAULT_PROPS);
38
+ const { loading, data: { entityData: fileData } = {} } = useQuery(fileQuery, {
39
+ variables: { id: file.id },
40
+ fetchPolicy: 'cache-and-network',
41
+ skip: !fileSchema || !fileSchema.id
42
+ });
43
+
44
+ if (!fileSchema || schemaLoading || loading) return null;
45
+
46
+ const { name, url, mimetype, data, store, updated } = fileData;
47
+ const bustUrl = (srcUrl, version) => {
48
+ if (!srcUrl) return srcUrl;
49
+ const sep = srcUrl.includes('?') ? '&' : '?';
50
+ return `${srcUrl}${sep}v=${version || Date.now()}`;
51
+ };
52
+ const displayUrl = bustUrl(url, updated);
8
53
  const [Preview, schema] = getPreview({ mimetype, previewType });
9
54
  const shouldRenderForm = schema && displayForm;
10
55
 
56
+ const { properties } = fileSchema;
57
+ const { name: nameProp, storeKey: storeKeyProp, ...restProperties } = properties;
58
+ Object.assign(schema.formSchema.properties, restProperties);
59
+
11
60
  if (shouldRenderForm && store) {
12
61
  const { defaultStore = {}, storeOptions = [] } = store;
13
62
  if (schema.formSchema.properties.storeKey) {
@@ -19,11 +68,19 @@ const FilePreview = ({ file, handleFormChange, displayForm, previewType, childre
19
68
  }
20
69
  }
21
70
 
22
- const formBuilderData = { values: { ...file, ...data } };
71
+ const formBuilderData = { values: { ...data, ...fileData } };
23
72
 
24
73
  return (
25
74
  <>
26
- <Preview mimetype={mimetype} url={url} name={name} {...data} file={file}>
75
+ <Preview
76
+ mimetype={mimetype}
77
+ url={displayUrl}
78
+ name={name}
79
+ {...data}
80
+ file={file}
81
+ handleChangeFile={handleChangeFile}
82
+ disableFilePreview={disableFilePreview}
83
+ showChangeButton={showChangeButton}>
27
84
  {shouldRenderForm && (
28
85
  <div className="preview__details">
29
86
  <div className="preview__filename">{file.filename}</div>
@@ -50,10 +107,13 @@ FilePreview.propTypes = {
50
107
  file: PropTypes.object.isRequired,
51
108
  fileName: PropTypes.string,
52
109
  handleFormChange: PropTypes.func,
110
+ handleChangeFile: PropTypes.func,
53
111
  displayForm: PropTypes.bool,
54
112
  handlers: PropTypes.object,
55
113
  previewType: PropTypes.oneOf(Object.keys(FilePreview.availablePreviewTypes)),
56
- children: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string])
114
+ children: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),
115
+ showChangeButton: PropTypes.bool,
116
+ disableFilePreview: PropTypes.bool
57
117
  };
58
118
 
59
119
  FilePreview.defaultProps = {
@@ -62,7 +122,10 @@ FilePreview.defaultProps = {
62
122
  handlers: {},
63
123
  previewType: FilePreview.availablePreviewTypes.card,
64
124
  handleFormChange: () => {},
65
- children: []
125
+ handleChangeFile: () => {},
126
+ children: [],
127
+ showChangeButton: false,
128
+ disableFilePreview: true
66
129
  };
67
130
 
68
131
  export default FilePreview;
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
+ import Button from '@blaze-react/button';
3
4
  import { DefaultIcon } from './icons';
4
5
 
5
- const PreviewDefault = ({ url, name, children }) => (
6
- <div className="preview">
6
+ const PreviewDefault = ({ url, name, children, handleChangeFile, showChangeButton }) => (
7
+ <div className="preview" key={`default-${url}`}>
7
8
  <div className="preview__file preview__file--default">
8
9
  <div className="preview__file--icon">
9
10
  <DefaultIcon />
@@ -16,6 +17,11 @@ const PreviewDefault = ({ url, name, children }) => (
16
17
  Original
17
18
  </a>
18
19
  </p>
20
+ {showChangeButton && (
21
+ <div className="preview__change-button">
22
+ <Button onClick={handleChangeFile}>Change file</Button>
23
+ </div>
24
+ )}
19
25
  </div>
20
26
  </div>
21
27
  {children}
@@ -25,7 +31,14 @@ const PreviewDefault = ({ url, name, children }) => (
25
31
  PreviewDefault.propTypes = {
26
32
  url: PropTypes.string.isRequired,
27
33
  name: PropTypes.string.isRequired,
28
- children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired
34
+ children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
35
+ handleChangeFile: PropTypes.func,
36
+ showChangeButton: PropTypes.bool
37
+ };
38
+
39
+ PreviewDefault.defaultProps = {
40
+ handleChangeFile: () => {},
41
+ showChangeButton: false
29
42
  };
30
43
 
31
44
  export { PreviewDefault };
@@ -2,24 +2,34 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import Actions from '../Actions';
4
4
 
5
- const RawPreviewDefault = ({ url, name, file }) => (
5
+ const RawPreviewDefault = ({ url, name, file, disableFilePreview }) => (
6
6
  <div className="FilePreview">
7
- <div className="FilePreviewItem">
8
- <div className="FilePreviewItem__wrapper">
9
- <img className="FilePreviewItem__wrapper__default" src={url} alt={name} />
7
+ {!disableFilePreview ? (
8
+ <div className="FilePreviewItem">
9
+ <div className="FilePreviewItem__wrapper">
10
+ <img className="FilePreviewItem__wrapper__default" src={url} alt={name} />
11
+ </div>
12
+ <div className="FilePreviewItem__info">
13
+ <p className="FilePreviewItem__info__fileName">{name}</p>
14
+ <Actions file={file} />
15
+ </div>
10
16
  </div>
17
+ ) : (
11
18
  <div className="FilePreviewItem__info">
12
- <p className="FilePreviewItem__info__fileName">{name}</p>
19
+ <p className="FilePreviewItem__info__fileName FilePreviewItem__info--disablePreview">
20
+ {name}
21
+ </p>
13
22
  <Actions file={file} />
14
23
  </div>
15
- </div>
24
+ )}
16
25
  </div>
17
26
  );
18
27
 
19
28
  RawPreviewDefault.propTypes = {
20
29
  url: PropTypes.string.isRequired,
21
30
  name: PropTypes.string.isRequired,
22
- file: PropTypes.object.isRequired
31
+ file: PropTypes.object.isRequired,
32
+ disableFilePreview: PropTypes.bool.isRequired
23
33
  };
24
34
 
25
35
  export { RawPreviewDefault };
@@ -15,7 +15,8 @@ const previewDefaultSchema = {
15
15
  label: 'url',
16
16
  showInForm: true,
17
17
  formFieldType: 'text',
18
- description: 'Url format is not valid'
18
+ description: 'Url format is not valid',
19
+ isDataPropery: true
19
20
  }
20
21
  },
21
22
  required: ['name']
@@ -3,9 +3,7 @@ import PropTypes from 'prop-types';
3
3
  import FilePreviewList from './FilePreviewList';
4
4
 
5
5
  const FileList = ({ selectedFiles, children }) => (
6
- <>
7
- <FilePreviewList selectedFiles={selectedFiles}>{children}</FilePreviewList>
8
- </>
6
+ <FilePreviewList selectedFiles={selectedFiles}>{children}</FilePreviewList>
9
7
  );
10
8
 
11
9
  FileList.propTypes = {
@@ -11,49 +11,37 @@ const FilePreviewReadOnly = ({ label, id, type, value }) => {
11
11
  const client = useApolloClient();
12
12
 
13
13
  const getFiles = async (offset, ids) => {
14
- const {
15
- data: { files: newFiles }
16
- } = await client.query({
14
+ if (!ids.length) return [];
15
+ const { data: { files = [] } = {} } = await client.query({
17
16
  query: getQuery('GET_FILES'),
18
17
  variables: {
19
18
  offset,
20
19
  where: {
21
- id: {
22
- _in: ids
23
- }
20
+ id: { _in: ids }
24
21
  }
25
22
  },
26
- skip: !initialValue.length,
27
23
  fetchPolicy: 'network-only'
28
24
  });
29
- return newFiles;
25
+ return files;
30
26
  };
31
27
 
32
- useEffect(
33
- () => {
34
- (async () => {
35
- const files = await getFiles(0, initialValue);
36
- const orderedFiles = orderFiles(files, initialValue);
37
- setSelectedFiles(orderedFiles);
38
- })();
39
- },
40
- [] //eslint-disable-line
41
- );
42
-
43
28
  const orderFiles = (files, ids) =>
44
29
  ids.map(currentId => files.find(({ id: fileId }) => fileId === currentId)).filter(Boolean);
45
30
 
31
+ useEffect(() => {
32
+ (async () => {
33
+ const files = await getFiles(0, initialValue);
34
+ const orderedFiles = orderFiles(files, initialValue);
35
+ setSelectedFiles(orderedFiles);
36
+ })();
37
+ // eslint-disable-next-line react-hooks/exhaustive-deps
38
+ }, []);
39
+
46
40
  return (
47
- <>
48
- <div className="form-field form-field--button">
49
- <label>{label}</label>
50
- {selectedFiles && (
51
- <>
52
- <FileList selectedFiles={selectedFiles} />
53
- </>
54
- )}
55
- </div>
56
- </>
41
+ <div className="form-field form-field--button">
42
+ <label htmlFor={id}>{label}</label>
43
+ {selectedFiles.length > 0 && <FileList selectedFiles={selectedFiles} />}
44
+ </div>
57
45
  );
58
46
  };
59
47