@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.
- package/jest.config.ts +12 -1
- package/lib/Hooks/useCategorisedSources.d.ts +14 -0
- package/lib/Hooks/useCategorisedSources.js +38 -0
- package/lib/Hooks/useChildResources.d.ts +19 -0
- package/lib/Hooks/useChildResources.js +35 -0
- package/lib/Hooks/useResourcePath.d.ts +16 -0
- package/lib/Hooks/useResourcePath.js +64 -0
- package/lib/Hooks/useSources.d.ts +16 -0
- package/lib/Hooks/useSources.js +29 -0
- package/lib/Icons/Icon.d.ts +7 -7
- package/lib/Icons/Icon.js +7 -9
- package/lib/Icons/MatrixResources/Audio.js +1 -1
- package/lib/Icons/MatrixResources/Excel.js +1 -1
- package/lib/Icons/MatrixResources/MatrixResourceMap.d.ts +6 -6
- package/lib/Icons/MatrixResources/MatrixResourceMap.js +6 -6
- package/lib/Icons/MatrixResources/Pdf.js +1 -1
- package/lib/Icons/MatrixResources/Powerpoint.js +1 -1
- package/lib/Icons/MatrixResources/Video.js +1 -1
- package/lib/Icons/MatrixResources/Word.js +1 -1
- package/lib/Modal/Modal.js +1 -1
- package/lib/PreviewPanel/PreviewModal.js +1 -1
- package/lib/PreviewPanel/PreviewPanel.d.ts +4 -6
- package/lib/PreviewPanel/PreviewPanel.js +11 -39
- package/lib/PreviewPanel/details/MatrixResource.d.ts +4 -9
- package/lib/PreviewPanel/details/MatrixResource.js +20 -16
- package/lib/ResourceBreadcrumb/ResourceBreadcrumb.d.ts +5 -5
- package/lib/ResourceBreadcrumb/ResourceBreadcrumb.js +3 -3
- package/lib/ResourceItem/ResourceItem.d.ts +6 -8
- package/lib/ResourceItem/ResourceItem.js +3 -3
- package/lib/ResourceList/ResourceList.d.ts +5 -4
- package/lib/ResourceList/ResourceList.js +3 -3
- package/lib/ResourcePickerContainer/ResourcePickerContainer.d.ts +4 -5
- package/lib/ResourcePickerContainer/ResourcePickerContainer.js +34 -89
- package/lib/SourceDropdown/SourceDropdown.d.ts +5 -5
- package/lib/SourceDropdown/SourceDropdown.js +19 -27
- package/lib/SourceList/SourceList.d.ts +4 -4
- package/lib/SourceList/SourceList.js +7 -5
- package/lib/index.css +6 -0
- package/lib/index.d.ts +6 -29
- package/lib/index.js +2 -3
- package/lib/uuid.js +1 -3
- package/package.json +3 -2
- package/src/Hooks/useCategorisedSources.spec.ts +39 -0
- package/src/Hooks/useCategorisedSources.ts +46 -0
- package/src/Hooks/useChildResources.spec.ts +49 -0
- package/src/Hooks/useChildResources.ts +43 -0
- package/src/Hooks/useResourcePath.spec.ts +124 -0
- package/src/Hooks/useResourcePath.ts +76 -0
- package/src/Hooks/useSources.spec.ts +33 -0
- package/src/Hooks/useSources.ts +33 -0
- package/src/Icons/Icon.stories.tsx +7 -7
- package/src/Icons/Icon.tsx +9 -14
- package/src/Icons/MatrixResources/Audio.tsx +1 -1
- package/src/Icons/MatrixResources/Excel.tsx +1 -1
- package/src/Icons/MatrixResources/MatrixResourceMap.ts +7 -7
- package/src/Icons/MatrixResources/Pdf.tsx +1 -1
- package/src/Icons/MatrixResources/Powerpoint.tsx +1 -1
- package/src/Icons/MatrixResources/Video.tsx +1 -1
- package/src/Icons/MatrixResources/Word.tsx +1 -1
- package/src/Modal/Modal.tsx +1 -1
- package/src/PreviewPanel/PreviewModal.tsx +1 -1
- package/src/PreviewPanel/PreviewPanel.spec.tsx +20 -62
- package/src/PreviewPanel/PreviewPanel.stories.tsx +16 -24
- package/src/PreviewPanel/PreviewPanel.tsx +15 -51
- package/src/PreviewPanel/details/MatrixResource.tsx +23 -19
- package/src/ResourceBreadcrumb/ResourceBreadcrumb.spec.tsx +13 -23
- package/src/ResourceBreadcrumb/ResourceBreadcrumb.stories.tsx +1 -1
- package/src/ResourceBreadcrumb/ResourceBreadcrumb.tsx +8 -9
- package/src/ResourceBreadcrumb/sample-hierarchy.json +15 -25
- package/src/ResourceItem/ResourceItem.tsx +10 -12
- package/src/ResourceList/ResourceList.spec.tsx +8 -53
- package/src/ResourceList/ResourceList.stories.tsx +2 -2
- package/src/ResourceList/ResourceList.tsx +12 -10
- package/src/ResourceList/sample-resources.json +551 -49
- package/src/ResourcePickerContainer/ResourcePickerContainer.spec.tsx +196 -315
- package/src/ResourcePickerContainer/ResourcePickerContainer.stories.tsx +7 -29
- package/src/ResourcePickerContainer/ResourcePickerContainer.tsx +63 -127
- package/src/SourceDropdown/SourceDropdown.spec.tsx +63 -60
- package/src/SourceDropdown/SourceDropdown.stories.tsx +4 -7
- package/src/SourceDropdown/SourceDropdown.tsx +34 -41
- package/src/SourceList/SourceList.spec.tsx +38 -32
- package/src/SourceList/SourceList.tsx +17 -19
- package/src/SourceList/sample-sources.json +186 -77
- package/src/__mocks__/MockModels.ts +30 -0
- package/src/__mocks__/StorybookHelpers.ts +46 -0
- package/src/index.stories.tsx +13 -38
- package/src/index.tsx +5 -29
- package/src/types.d.ts +71 -0
- package/src/uuid.ts +2 -4
- 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
|
-
|
12
|
-
|
13
|
-
|
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(
|
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(
|
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={({
|
22
|
-
onResourceDrillDown={({
|
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 {
|
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: (
|
14
|
-
onResourceDrillDown: (
|
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((
|
55
|
+
resources.map((resource) => {
|
54
56
|
return (
|
55
57
|
<ResourceItem
|
56
|
-
key={
|
57
|
-
|
58
|
-
selected={
|
59
|
-
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}
|