@squiz/resource-browser 1.32.1-alpha.14 → 1.32.1-alpha.16

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 (90) hide show
  1. package/jest.config.ts +12 -1
  2. package/lib/Hooks/useCategorisedSources.d.ts +14 -0
  3. package/lib/Hooks/useCategorisedSources.js +38 -0
  4. package/lib/Hooks/useChildResources.d.ts +19 -0
  5. package/lib/Hooks/useChildResources.js +35 -0
  6. package/lib/Hooks/useResourcePath.d.ts +16 -0
  7. package/lib/Hooks/useResourcePath.js +64 -0
  8. package/lib/Hooks/useSources.d.ts +16 -0
  9. package/lib/Hooks/useSources.js +29 -0
  10. package/lib/Icons/Icon.d.ts +7 -7
  11. package/lib/Icons/Icon.js +7 -9
  12. package/lib/Icons/MatrixResources/Audio.js +1 -1
  13. package/lib/Icons/MatrixResources/Excel.js +1 -1
  14. package/lib/Icons/MatrixResources/MatrixResourceMap.d.ts +6 -6
  15. package/lib/Icons/MatrixResources/MatrixResourceMap.js +6 -6
  16. package/lib/Icons/MatrixResources/Pdf.js +1 -1
  17. package/lib/Icons/MatrixResources/Powerpoint.js +1 -1
  18. package/lib/Icons/MatrixResources/Video.js +1 -1
  19. package/lib/Icons/MatrixResources/Word.js +1 -1
  20. package/lib/Modal/Modal.js +1 -1
  21. package/lib/PreviewPanel/PreviewModal.js +1 -1
  22. package/lib/PreviewPanel/PreviewPanel.d.ts +4 -6
  23. package/lib/PreviewPanel/PreviewPanel.js +11 -39
  24. package/lib/PreviewPanel/details/MatrixResource.d.ts +4 -9
  25. package/lib/PreviewPanel/details/MatrixResource.js +20 -16
  26. package/lib/ResourceBreadcrumb/ResourceBreadcrumb.d.ts +5 -5
  27. package/lib/ResourceBreadcrumb/ResourceBreadcrumb.js +3 -3
  28. package/lib/ResourceItem/ResourceItem.d.ts +6 -8
  29. package/lib/ResourceItem/ResourceItem.js +3 -3
  30. package/lib/ResourceList/ResourceList.d.ts +5 -4
  31. package/lib/ResourceList/ResourceList.js +3 -3
  32. package/lib/ResourcePickerContainer/ResourcePickerContainer.d.ts +4 -5
  33. package/lib/ResourcePickerContainer/ResourcePickerContainer.js +34 -89
  34. package/lib/SourceDropdown/SourceDropdown.d.ts +5 -5
  35. package/lib/SourceDropdown/SourceDropdown.js +19 -27
  36. package/lib/SourceList/SourceList.d.ts +4 -4
  37. package/lib/SourceList/SourceList.js +7 -5
  38. package/lib/index.css +6 -0
  39. package/lib/index.d.ts +6 -29
  40. package/lib/index.js +2 -3
  41. package/lib/uuid.js +1 -3
  42. package/package.json +3 -2
  43. package/src/Hooks/useCategorisedSources.spec.ts +39 -0
  44. package/src/Hooks/useCategorisedSources.ts +46 -0
  45. package/src/Hooks/useChildResources.spec.ts +49 -0
  46. package/src/Hooks/useChildResources.ts +43 -0
  47. package/src/Hooks/useResourcePath.spec.ts +124 -0
  48. package/src/Hooks/useResourcePath.ts +76 -0
  49. package/src/Hooks/useSources.spec.ts +33 -0
  50. package/src/Hooks/useSources.ts +33 -0
  51. package/src/Icons/Icon.stories.tsx +7 -7
  52. package/src/Icons/Icon.tsx +9 -14
  53. package/src/Icons/MatrixResources/Audio.tsx +1 -1
  54. package/src/Icons/MatrixResources/Excel.tsx +1 -1
  55. package/src/Icons/MatrixResources/MatrixResourceMap.ts +7 -7
  56. package/src/Icons/MatrixResources/Pdf.tsx +1 -1
  57. package/src/Icons/MatrixResources/Powerpoint.tsx +1 -1
  58. package/src/Icons/MatrixResources/Video.tsx +1 -1
  59. package/src/Icons/MatrixResources/Word.tsx +1 -1
  60. package/src/Modal/Modal.tsx +1 -1
  61. package/src/PreviewPanel/PreviewModal.tsx +1 -1
  62. package/src/PreviewPanel/PreviewPanel.spec.tsx +20 -62
  63. package/src/PreviewPanel/PreviewPanel.stories.tsx +16 -24
  64. package/src/PreviewPanel/PreviewPanel.tsx +15 -51
  65. package/src/PreviewPanel/details/MatrixResource.tsx +23 -19
  66. package/src/ResourceBreadcrumb/ResourceBreadcrumb.spec.tsx +13 -23
  67. package/src/ResourceBreadcrumb/ResourceBreadcrumb.stories.tsx +1 -1
  68. package/src/ResourceBreadcrumb/ResourceBreadcrumb.tsx +8 -9
  69. package/src/ResourceBreadcrumb/sample-hierarchy.json +15 -25
  70. package/src/ResourceItem/ResourceItem.tsx +10 -12
  71. package/src/ResourceList/ResourceList.spec.tsx +8 -53
  72. package/src/ResourceList/ResourceList.stories.tsx +2 -2
  73. package/src/ResourceList/ResourceList.tsx +12 -10
  74. package/src/ResourceList/sample-resources.json +551 -49
  75. package/src/ResourcePickerContainer/ResourcePickerContainer.spec.tsx +196 -315
  76. package/src/ResourcePickerContainer/ResourcePickerContainer.stories.tsx +7 -29
  77. package/src/ResourcePickerContainer/ResourcePickerContainer.tsx +63 -127
  78. package/src/SourceDropdown/SourceDropdown.spec.tsx +63 -60
  79. package/src/SourceDropdown/SourceDropdown.stories.tsx +4 -7
  80. package/src/SourceDropdown/SourceDropdown.tsx +34 -41
  81. package/src/SourceList/SourceList.spec.tsx +38 -32
  82. package/src/SourceList/SourceList.tsx +17 -19
  83. package/src/SourceList/sample-sources.json +186 -77
  84. package/src/__mocks__/MockModels.ts +30 -0
  85. package/src/__mocks__/StorybookHelpers.ts +46 -0
  86. package/src/index.stories.tsx +13 -38
  87. package/src/index.tsx +5 -29
  88. package/src/types.d.ts +71 -0
  89. package/src/uuid.ts +2 -4
  90. package/src/SourceDropdown/sample-sources.json +0 -110
@@ -2,61 +2,16 @@
2
2
  import React from 'react';
3
3
  import { screen, render, waitFor } from '@testing-library/react';
4
4
  import userEvent from '@testing-library/user-event';
5
-
5
+ import { mockResource } from '../__mocks__/MockModels';
6
6
  import { useOverlayTriggerState, OverlayTriggerState } from 'react-stately';
7
7
  import ResourceList from './ResourceList';
8
8
 
9
9
  const resources = [
10
- {
11
- id: {
12
- id: '1',
13
- source: '1',
14
- },
15
- type: 'page',
16
- selected: false,
17
- label: 'Resource 1',
18
- childCount: 0,
19
- },
20
- {
21
- id: {
22
- id: '2',
23
- source: '1',
24
- },
25
- type: 'page',
26
- selected: false,
27
- label: 'Resource 2',
28
- childCount: 0,
29
- },
30
- {
31
- id: {
32
- id: '3',
33
- source: '1',
34
- },
35
- type: 'folder',
36
- selected: false,
37
- label: 'Resource 3',
38
- childCount: 31,
39
- },
40
- {
41
- id: {
42
- id: '4',
43
- source: '1',
44
- },
45
- type: 'folder',
46
- selected: false,
47
- label: 'Resource 4',
48
- childCount: 55,
49
- },
50
- {
51
- id: {
52
- id: '5',
53
- source: '1',
54
- },
55
- type: 'docx',
56
- selected: false,
57
- label: 'Resource 5',
58
- childCount: 0,
59
- },
10
+ mockResource({ id: '1', type: { code: 'page', name: 'Page' }, name: 'Resource 1' }),
11
+ mockResource({ id: '2', type: { code: 'page', name: 'Page' }, name: 'Resource 2' }),
12
+ mockResource({ id: '3', type: { code: 'folder', name: 'Folder' }, name: 'Resource 3', childCount: 31 }),
13
+ mockResource({ id: '4', type: { code: 'folder', name: 'Folder' }, name: 'Resource 4', childCount: 55 }),
14
+ mockResource({ id: '5', type: { code: 'word_doc', name: 'MS Word Document' }, name: 'Resource 5' }),
60
15
  ];
61
16
 
62
17
  function ResourceListTestWrapper({
@@ -163,7 +118,7 @@ describe('ResourceList', () => {
163
118
 
164
119
  await waitFor(() => {
165
120
  // Provides the item that was clicked and an id reference to the button that was clicked
166
- expect(onResourceSelect).toHaveBeenCalledWith({ source: '1', id: '1' }, { id: expect.any(String) });
121
+ expect(onResourceSelect).toHaveBeenCalledWith(resources[0], { id: expect.any(String) });
167
122
  });
168
123
  });
169
124
 
@@ -190,7 +145,7 @@ describe('ResourceList', () => {
190
145
  user.click(screen.getByRole('button', { name: 'Drill down to Resource 3 children' }));
191
146
 
192
147
  await waitFor(() => {
193
- expect(onResourceDrillDown).toHaveBeenCalledWith({ source: '1', id: '3' });
148
+ expect(onResourceDrillDown).toHaveBeenCalledWith(resources[2]);
194
149
  });
195
150
  });
196
151
  });
@@ -18,8 +18,8 @@ const Template: StoryFn<typeof ResourceList> = ({ resources, isLoading, allowedT
18
18
  resources={resources}
19
19
  previewModalState={previewModalState}
20
20
  isLoading={isLoading}
21
- onResourceSelect={({ source, id }) => alert(`Resource Select: ${source} - ${id}`)}
22
- onResourceDrillDown={({ source, id }) => alert(`Child Drill Down: ${source} - ${id}`)}
21
+ onResourceSelect={({ id }) => alert(`Resource Select: ${id}`)}
22
+ onResourceDrillDown={({ id }) => alert(`Child Drill Down: ${id}`)}
23
23
  allowedTypes={allowedTypes}
24
24
  />
25
25
  );
@@ -3,20 +3,22 @@ import { OverlayTriggerState } from 'react-stately';
3
3
  import { DOMAttributes, FocusableElement } from '@react-types/shared';
4
4
 
5
5
  import ResourceItem from '../ResourceItem/ResourceItem';
6
- import { NodeIdentifier, Resource } from '../index';
6
+ import { Resource } from '../types';
7
7
  import { SkeletonListItem } from '../Skeleton/ListItem/SkeletonListItem';
8
8
 
9
9
  export interface ResourceListProps {
10
10
  resources: Array<Resource>;
11
+ selectedResource?: Resource | null;
11
12
  previewModalState: OverlayTriggerState;
12
13
  isLoading: boolean;
13
- onResourceSelect: (node: NodeIdentifier, overlayProps: DOMAttributes<FocusableElement>) => void;
14
- onResourceDrillDown: (node: NodeIdentifier) => void;
14
+ onResourceSelect: (resource: Resource, overlayProps: DOMAttributes<FocusableElement>) => void;
15
+ onResourceDrillDown: (resource: Resource) => void;
15
16
  allowedTypes?: string[] | undefined;
16
17
  }
17
18
 
18
19
  const ResourceList = function ({
19
20
  resources,
21
+ selectedResource,
20
22
  previewModalState,
21
23
  isLoading,
22
24
  onResourceSelect,
@@ -50,15 +52,15 @@ const ResourceList = function ({
50
52
  )}
51
53
 
52
54
  {!isLoading &&
53
- resources.map(({ type, id, selected, label, childCount }) => {
55
+ resources.map((resource) => {
54
56
  return (
55
57
  <ResourceItem
56
- key={`${id.source}-${id.id}`}
57
- id={id}
58
- selected={selected}
59
- label={label}
60
- type={type}
61
- childCount={childCount}
58
+ key={resource.id}
59
+ item={resource}
60
+ selected={resource.id == selectedResource?.id}
61
+ label={resource.name}
62
+ type={resource.type.code}
63
+ childCount={resource.childCount}
62
64
  previewModalState={previewModalState}
63
65
  onSelect={onResourceSelect}
64
66
  onDrillDown={onResourceDrillDown}