@ossy/storage 3.0.8 → 3.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ossy/storage",
3
3
  "description": "Analytics module — workspace analytics for website traffic",
4
- "version": "3.0.8",
4
+ "version": "3.4.0",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
7
7
  "module": "./src/index.js",
@@ -30,5 +30,5 @@
30
30
  "ramda": "*",
31
31
  "react": "*"
32
32
  },
33
- "gitHead": "980b380c9dee0de78ef3ebabe86efcec1c223a9a"
33
+ "gitHead": "d36b69444268d172bc3e8e1dc77e67afc63f8650"
34
34
  }
@@ -10,7 +10,7 @@ import {
10
10
  last,
11
11
  } from 'ramda'
12
12
  import { Text, Overlay, Switch, DropZone, Breadcrumbs, Guide, DelayedRender, useDocumentTitle, View, Button, ContextMenu, Dropdown, Page, Tags, useLocale, preloadStorageIcons } from '@ossy/design-system'
13
- import { useActivePath, ResourcePanel, ResourceList, ResourceDialogMove, useSelectedResourceId } from '@ossy/resources'
13
+ import { useActivePath, ResourcePanel, ResourceList, ResourceGrid, ResourceDialogMove, useSelectedResourceId } from '@ossy/resources'
14
14
  import { useRouter, useSearchParams } from '@ossy/router-react'
15
15
 
16
16
  const Path = ({ path, ...props }) => (
@@ -33,6 +33,11 @@ const Overlays = {
33
33
  MoveResource: 'MoveResource'
34
34
  }
35
35
 
36
+ const ViewMode = {
37
+ List: 'list',
38
+ Grid: 'grid',
39
+ }
40
+
36
41
  export const ResourcesPage = () => {
37
42
  const router = useRouter()
38
43
  const searchParams = useSearchParams()
@@ -40,6 +45,9 @@ export const ResourcesPage = () => {
40
45
  const sdk = useSdk()
41
46
  const { data: workspace = {} } = sdk.read(GetWorkspace)
42
47
  const [overlay, setOverlay] = useState(Overlays.None)
48
+ const [viewMode, setViewMode] = useState(ViewMode.List)
49
+ const [addMenuOpen, setAddMenuOpen] = useState(false)
50
+ const [addMenuPosition, setAddMenuPosition] = useState(null)
43
51
  const { selectedResourceId, setSelectedResourceId, clearSelectedResourceId } = useSelectedResourceId()
44
52
  const activePath = useActivePath()
45
53
  const lastSuccessfulResourcesRef = useRef([])
@@ -142,6 +150,45 @@ export const ResourcesPage = () => {
142
150
 
143
151
  }
144
152
 
153
+ const openCreateFolder = useCallback(() => {
154
+ setIsCreatingFolder(true)
155
+ setNewFolderName(t('storage.resources.newFolderDefault'))
156
+ }, [t])
157
+
158
+ const handleAddMenuOpenChange = useCallback((open) => {
159
+ setAddMenuOpen(open)
160
+ if (!open) setAddMenuPosition(null)
161
+ }, [])
162
+
163
+ const handleAddTriggerClick = useCallback(() => {
164
+ setAddMenuPosition(null)
165
+ }, [])
166
+
167
+ const handleDropZoneContextMenu = useCallback((event) => {
168
+ event.preventDefault()
169
+ setAddMenuPosition({ top: event.clientY, left: event.clientX })
170
+ setAddMenuOpen(true)
171
+ }, [])
172
+
173
+ const addMenu = (
174
+ <View inset="xs" surface="primary" roundness="s">
175
+ <ContextMenu roundness="s" surface="primary">
176
+ <ContextMenu.Item
177
+ prefix="folder-add"
178
+ onClick={openCreateFolder}
179
+ >
180
+ {t('storage.resources.createFolder')}
181
+ </ContextMenu.Item>
182
+ <ContextMenu.Item
183
+ prefix="software-upload"
184
+ href={router.getHref(`@upload-media?location=${activePath}`)}
185
+ >
186
+ {t('storage.resources.uploadFile')}
187
+ </ContextMenu.Item>
188
+ </ContextMenu>
189
+ </View>
190
+ )
191
+
145
192
  const getActivePath = () => pipe(
146
193
  split('/'),
147
194
  filter(identity),
@@ -182,7 +229,6 @@ export const ResourcesPage = () => {
182
229
  <ContextMenu.Item
183
230
  prefix="mail-forward"
184
231
  href={storageHomeHref(`location=${activePath}${resource.name}`)}
185
- onClick={event => { event.stopPropagation() }}
186
232
  key="details"
187
233
  >
188
234
  Open
@@ -192,10 +238,7 @@ export const ResourcesPage = () => {
192
238
  variant="command-danger"
193
239
  prefix="trash-empty"
194
240
  key="remove"
195
- onClick={event => {
196
- event.stopPropagation()
197
- onRemoveResource(resource)
198
- }}
241
+ onClick={() => onRemoveResource(resource)}
199
242
  >{t('storage.resources.contextRemove')}
200
243
  </ContextMenu.Item>
201
244
  ]
@@ -210,22 +253,17 @@ export const ResourcesPage = () => {
210
253
  <ContextMenu.Item
211
254
  key="details"
212
255
  prefix="details-more"
213
- onClick={event => {
214
- event.stopPropagation()
215
- setSelectedResourceId(resource.id)}
216
- }
256
+ onClick={() => setSelectedResourceId(resource.id)}
217
257
  >
218
258
  View
219
259
  </ContextMenu.Item>,
220
260
  <ContextMenu.Item
221
- key="details"
261
+ key="move"
222
262
  prefix="details-more"
223
- onClick={event => {
224
- event.stopPropagation()
263
+ onClick={() => {
225
264
  setSelectedResourceId(resource.id)
226
265
  setOverlay(Overlays.MoveResource)
227
- }
228
- }
266
+ }}
229
267
  >
230
268
  {t('storage.resources.move')}
231
269
  </ContextMenu.Item>,
@@ -234,10 +272,7 @@ export const ResourcesPage = () => {
234
272
  key="remove"
235
273
  variant="command-danger"
236
274
  prefix="trash-empty"
237
- onClick={event => {
238
- event.stopPropagation()
239
- onRemoveResource(resource)
240
- }}
275
+ onClick={() => onRemoveResource(resource)}
241
276
  >Remove
242
277
  </ContextMenu.Item>
243
278
  ]
@@ -310,33 +345,59 @@ export const ResourcesPage = () => {
310
345
  { activePath !== '/' && getActivePath() }
311
346
  </Breadcrumbs>
312
347
 
313
- <Dropdown trigger={<Button prefix="add" variant="command" style={{ height: '32px' }} label="storage.resources.add" />}>
314
- <View inset="xs" surface="primary" roundness="s">
315
- <ContextMenu roundness="s" surface="primary">
316
- <ContextMenu.Item
317
- prefix="folder-add"
318
- onClick={() => {
319
- setIsCreatingFolder(true)
320
- setNewFolderName(t('storage.resources.newFolderDefault'))
321
- }}
322
- >
323
- {t('storage.resources.createFolder')}
324
- </ContextMenu.Item>
325
- <ContextMenu.Item
326
- prefix="software-upload"
327
- href={router.getHref(`@upload-media?location=${activePath}`)}
328
- >
329
- {t('storage.resources.uploadFile')}
330
- </ContextMenu.Item>
331
- </ContextMenu>
332
- </View>
333
- </Dropdown>
348
+ <View layout="row" gap="xs" alignItems="center" style={{ flexShrink: 0 }}>
349
+ <Dropdown
350
+ trigger={(
351
+ <Button
352
+ prefix={viewMode === ViewMode.Grid ? 'layout-grid' : 'layout-list'}
353
+ variant="command"
354
+ aria-label={t('storage.resources.layout')}
355
+ style={{ height: '32px' }}
356
+ />
357
+ )}
358
+ >
359
+ <View inset="xs" surface="primary" roundness="s">
360
+ <ContextMenu roundness="s" surface="primary">
361
+ <ContextMenu.Item
362
+ prefix="layout-list"
363
+ suffix={viewMode === ViewMode.List ? 'check' : undefined}
364
+ onClick={() => setViewMode(ViewMode.List)}
365
+ >
366
+ {t('storage.resources.viewList')}
367
+ </ContextMenu.Item>
368
+ <ContextMenu.Item
369
+ prefix="layout-grid"
370
+ suffix={viewMode === ViewMode.Grid ? 'check' : undefined}
371
+ onClick={() => setViewMode(ViewMode.Grid)}
372
+ >
373
+ {t('storage.resources.viewGrid')}
374
+ </ContextMenu.Item>
375
+ </ContextMenu>
376
+ </View>
377
+ </Dropdown>
378
+ <Dropdown
379
+ trigger={(
380
+ <Button
381
+ prefix="add"
382
+ variant="command"
383
+ style={{ height: '32px' }}
384
+ label="storage.resources.add"
385
+ onClick={handleAddTriggerClick}
386
+ />
387
+ )}
388
+ open={addMenuOpen}
389
+ onOpenChange={handleAddMenuOpenChange}
390
+ position={addMenuPosition}
391
+ >
392
+ {addMenu}
393
+ </Dropdown>
394
+ </View>
334
395
 
335
396
  </View.Item>
336
397
 
337
398
  <View.Item fill data-scrollbar="hide" style={{ overflowY: 'auto', minHeight: 0 }}>
338
399
  <DropZone onFilesDrop={onUploadFiles(activePath)}>
339
- <View style={{ minHeight: '100%' }}>
400
+ <View style={{ minHeight: '100%' }} onContextMenu={handleDropZoneContextMenu}>
340
401
  <Switch on={resourcesListStatus}>
341
402
 
342
403
  <Switch.Case match={[ResourcesListStatus.Error]}>
@@ -352,41 +413,60 @@ export const ResourcesPage = () => {
352
413
 
353
414
  <Switch.Case match={[ResourcesListStatus.Loading]}>
354
415
  <DelayedRender>
355
- {[1, 2, 3].map(n => (
356
- <View.Item key={n}>
357
- <div
358
- className="inset-m cursor-pointer sans-serif d-flex align-center justify-between"
359
- style={{ height: '56px', }}
360
- >
361
- <div className="d-flex align-center">
362
- <span
363
- className="inline-m"
364
- style={{
365
- width: '24px',
366
- height: '24px',
367
- flexShrink: 0,
368
- background: 'hsl(0, 0%, 50%)',
369
- borderRadius: '16px'
370
- }}
371
- />
372
- <span
416
+ {viewMode === ViewMode.Grid
417
+ ? (
418
+ <View layout="row-wrap" gap="m" inset="m">
419
+ {[1, 2, 3, 4, 5, 6].map(n => (
420
+ <View
421
+ key={n}
373
422
  style={{
374
- width: '300px',
375
- height: '18px',
423
+ width: 160,
424
+ height: 160,
376
425
  background: 'hsl(0, 0%, 50%)',
377
- borderRadius: '16px'
426
+ borderRadius: 'var(--roundness-m, 12px)',
427
+ opacity: 0.35,
378
428
  }}
379
429
  />
430
+ ))}
431
+ </View>
432
+ )
433
+ : [1, 2, 3].map(n => (
434
+ <View.Item key={n}>
435
+ <div
436
+ className="inset-m cursor-pointer sans-serif d-flex align-center justify-between"
437
+ style={{ height: '56px', }}
438
+ >
439
+ <div className="d-flex align-center">
440
+ <span
441
+ className="inline-m"
442
+ style={{
443
+ width: '24px',
444
+ height: '24px',
445
+ flexShrink: 0,
446
+ background: 'hsl(0, 0%, 50%)',
447
+ borderRadius: '16px'
448
+ }}
449
+ />
450
+ <span
451
+ style={{
452
+ width: '300px',
453
+ height: '18px',
454
+ background: 'hsl(0, 0%, 50%)',
455
+ borderRadius: '16px'
456
+ }}
457
+ />
458
+ </div>
380
459
  </div>
381
- </div>
382
- </View.Item>
383
- ))}
460
+ </View.Item>
461
+ ))}
384
462
  </DelayedRender>
385
463
  </Switch.Case>
386
464
 
387
465
  <Switch.Case match={[ResourcesListStatus.Empty]}>
388
466
  {isCreatingFolder
389
- ? <ResourceList resources={[]} inlineFolder={inlineFolder} />
467
+ ? (viewMode === ViewMode.Grid
468
+ ? <ResourceGrid resources={[]} inlineFolder={inlineFolder} />
469
+ : <ResourceList resources={[]} inlineFolder={inlineFolder} />)
390
470
  : (
391
471
  <Guide
392
472
  data-region="content"
@@ -401,7 +481,9 @@ export const ResourcesPage = () => {
401
481
  </Switch.Case>
402
482
 
403
483
  <Switch.Case match={[ResourcesListStatus.Success]}>
404
- <ResourceList resources={filterResources} inlineFolder={inlineFolder} />
484
+ {viewMode === ViewMode.Grid
485
+ ? <ResourceGrid resources={filterResources} inlineFolder={inlineFolder} />
486
+ : <ResourceList resources={filterResources} inlineFolder={inlineFolder} />}
405
487
  </Switch.Case>
406
488
 
407
489
  </Switch>
@@ -19,5 +19,8 @@
19
19
  "storage.resources.cancel": "Cancel",
20
20
  "storage.resources.remove": "Remove",
21
21
  "storage.resources.move": "Move",
22
- "storage.resources.contextRemove": "Remove"
22
+ "storage.resources.contextRemove": "Remove",
23
+ "storage.resources.layout": "Layout",
24
+ "storage.resources.viewList": "List view",
25
+ "storage.resources.viewGrid": "Grid view"
23
26
  }
@@ -19,5 +19,8 @@
19
19
  "storage.resources.cancel": "Avbryt",
20
20
  "storage.resources.remove": "Ta bort",
21
21
  "storage.resources.move": "Flytta",
22
- "storage.resources.contextRemove": "Ta bort"
22
+ "storage.resources.contextRemove": "Ta bort",
23
+ "storage.resources.layout": "Layout",
24
+ "storage.resources.viewList": "Listvy",
25
+ "storage.resources.viewGrid": "Rutnätsvy"
23
26
  }