@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
@@ -1,10 +1,7 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { StoryFn, Meta } from '@storybook/react';
|
3
|
-
|
4
|
-
import { NodeIdentifier } from '../index';
|
5
3
|
import ResourcePickerContainer from './ResourcePickerContainer';
|
6
|
-
import
|
7
|
-
import sampleResources from '../ResourceList/sample-resources.json';
|
4
|
+
import { createResourceBrowserCallbacks } from '../__mocks__/StorybookHelpers';
|
8
5
|
|
9
6
|
export default {
|
10
7
|
title: 'Resource Picker',
|
@@ -12,36 +9,17 @@ export default {
|
|
12
9
|
} as Meta<typeof ResourcePickerContainer>;
|
13
10
|
|
14
11
|
const Template: StoryFn<typeof ResourcePickerContainer> = ({ title }) => {
|
12
|
+
const { onRequestSources, onRequestChildren, onRequestResource, onChange } = createResourceBrowserCallbacks();
|
13
|
+
|
15
14
|
return (
|
16
15
|
<ResourcePickerContainer
|
17
16
|
title={title}
|
18
17
|
titleAriaProps={{}}
|
19
18
|
allowedTypes={undefined}
|
20
|
-
onRequestSources={
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
}}
|
25
|
-
onRequestChildren={() => {
|
26
|
-
return new Promise((resolve) => {
|
27
|
-
setTimeout(resolve, 500, sampleResources);
|
28
|
-
});
|
29
|
-
}}
|
30
|
-
onRequestResource={() => {
|
31
|
-
return new Promise((resolve) => {
|
32
|
-
setTimeout(resolve, 500, {
|
33
|
-
type: 'page',
|
34
|
-
name: 'Products',
|
35
|
-
properties: new Map([
|
36
|
-
['assetId', '12345'],
|
37
|
-
['status', 'UnderConstruction'],
|
38
|
-
]),
|
39
|
-
});
|
40
|
-
});
|
41
|
-
}}
|
42
|
-
onChange={(nodeId: NodeIdentifier) => {
|
43
|
-
alert(`Resource Browser has selected ${nodeId.source} ${nodeId.id}`);
|
44
|
-
}}
|
19
|
+
onRequestSources={onRequestSources}
|
20
|
+
onRequestChildren={onRequestChildren}
|
21
|
+
onRequestResource={onRequestResource}
|
22
|
+
onChange={onChange}
|
45
23
|
onClose={() => {
|
46
24
|
alert('Resource Browser closed');
|
47
25
|
}}
|
@@ -8,16 +8,18 @@ import ResourceBreadcrumb from '../ResourceBreadcrumb/ResourceBreadcrumb';
|
|
8
8
|
import PreviewPanel from '../PreviewPanel/PreviewPanel';
|
9
9
|
import SourceDropdown from '../SourceDropdown/SourceDropdown';
|
10
10
|
|
11
|
-
import {
|
11
|
+
import { Source, Resource, HydratedResourceReference, ScopedSource } from '../types';
|
12
|
+
import { useResourcePath } from '../Hooks/useResourcePath';
|
13
|
+
import { useChildResources } from '../Hooks/useChildResources';
|
14
|
+
import { useSources } from '../Hooks/useSources';
|
12
15
|
|
13
16
|
interface ResourcePickerContainerProps {
|
14
17
|
title: string;
|
15
18
|
titleAriaProps: DOMAttributes<FocusableElement>;
|
16
19
|
allowedTypes: string[] | undefined;
|
17
20
|
onRequestSources: () => Promise<Source[]>;
|
18
|
-
onRequestChildren(
|
19
|
-
|
20
|
-
onChange(resource: NodeIdentifier | null): void;
|
21
|
+
onRequestChildren(source: Source, resource: Resource | null): Promise<Resource[]>;
|
22
|
+
onChange(resource: HydratedResourceReference | null): void;
|
21
23
|
onClose: () => void;
|
22
24
|
}
|
23
25
|
|
@@ -27,123 +29,59 @@ function ResourcePickerContainer({
|
|
27
29
|
allowedTypes,
|
28
30
|
onRequestSources,
|
29
31
|
onRequestChildren,
|
30
|
-
onRequestResource,
|
31
32
|
onChange,
|
32
33
|
onClose,
|
33
34
|
}: ResourcePickerContainerProps) {
|
34
35
|
const previewModalState = useOverlayTriggerState({});
|
36
|
+
const [selectedResource, setSelectedResource] = useState<Resource | null>(null);
|
37
|
+
const [previewModalOverlayProps, setPreviewModalOverlayProps] = useState<DOMAttributes>({});
|
38
|
+
const { source, currentResource, hierarchy, setSource, push, popUntil } = useResourcePath();
|
39
|
+
const { isLoading: isSourceLoading, sources } = useSources({ onRequestSources });
|
40
|
+
const { isLoading: isResourcesLoading, resources } = useChildResources({
|
41
|
+
source,
|
42
|
+
currentResource,
|
43
|
+
onRequestChildren,
|
44
|
+
});
|
35
45
|
|
36
|
-
const
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
const [previewModalOverlayProps, setPreviewModalOverlayProps] = useState<DOMAttributes<FocusableElement>>({});
|
43
|
-
const [hierarchy, setHierarchy] = useState<Array<Hierarchy>>([]);
|
44
|
-
|
45
|
-
const [sources, setSources] = useState<Array<Source>>([]);
|
46
|
-
const [resources, setResources] = useState<Array<Resource>>([]);
|
47
|
-
const [selectedNodeDetails, setSelectedNodeDetails] = useState<ResourceDetail | null>(null);
|
48
|
-
|
49
|
-
const adjustHierarchy = (node: NodeIdentifier, resetHierarchy: boolean) => {
|
50
|
-
const isInHierarchy = hierarchy.find((hNode) => hNode.id === node);
|
51
|
-
let newHierarchy: Array<Hierarchy> = [];
|
52
|
-
|
53
|
-
// If the node is already in the hierarchy we need to 'jump' back to it
|
54
|
-
if (isInHierarchy) {
|
55
|
-
let reachedNode = false;
|
56
|
-
// Read though the hierarchy and add any nodes before and including the current to the array
|
57
|
-
hierarchy.forEach((hNode) => {
|
58
|
-
if (reachedNode === false) {
|
59
|
-
newHierarchy.push(hNode);
|
60
|
-
if (hNode.id === node) {
|
61
|
-
reachedNode = true;
|
62
|
-
}
|
63
|
-
}
|
64
|
-
});
|
65
|
-
} else {
|
66
|
-
let label: string = resources.find((resource) => resource.id === node)?.label || '';
|
67
|
-
|
68
|
-
// Might be a source
|
69
|
-
if (!label) {
|
70
|
-
const source = sources.find((source) => source.id === node.source);
|
71
|
-
if (source) {
|
72
|
-
label = source.nodes.find((resource) => resource.id === node)?.label || '';
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
// If we are jumping to a complete other spot and the container knows it, it can request a complete reset
|
77
|
-
if (!resetHierarchy) {
|
78
|
-
newHierarchy = hierarchy.slice();
|
79
|
-
}
|
80
|
-
|
81
|
-
newHierarchy.push({
|
82
|
-
id: node,
|
83
|
-
label,
|
84
|
-
});
|
85
|
-
}
|
86
|
-
|
87
|
-
setHierarchy(newHierarchy);
|
88
|
-
};
|
46
|
+
const handleResourceDrillDown = useCallback(
|
47
|
+
(resource: Resource) => {
|
48
|
+
push(resource);
|
49
|
+
},
|
50
|
+
[push],
|
51
|
+
);
|
89
52
|
|
90
|
-
const handleResourceSelected = useCallback((
|
53
|
+
const handleResourceSelected = useCallback((resource: Resource, overlayProps: DOMAttributes) => {
|
91
54
|
setPreviewModalOverlayProps(overlayProps);
|
92
|
-
|
93
|
-
setSelectedId(node);
|
94
|
-
|
95
|
-
setSelectedNodeDetails(null);
|
96
|
-
|
97
|
-
onRequestResource(node).then((detail: ResourceDetail | null) => {
|
98
|
-
setSelectedNodeDetails(detail);
|
99
|
-
setIsSecondaryLoading(false);
|
100
|
-
});
|
55
|
+
setSelectedResource(resource);
|
101
56
|
}, []);
|
102
57
|
|
103
|
-
const
|
104
|
-
(
|
105
|
-
|
106
|
-
setCurrentNode(node);
|
107
|
-
adjustHierarchy(node, resetHierarchy || false);
|
108
|
-
|
109
|
-
setSelectedId(null);
|
110
|
-
setSelectedNodeDetails(null);
|
111
|
-
setResources([]);
|
112
|
-
|
113
|
-
onRequestChildren(node).then((resources: Array<Resource>) => {
|
114
|
-
setResources(resources);
|
115
|
-
setIsMainLoading(false);
|
116
|
-
});
|
58
|
+
const handleSourceDrilldown = useCallback(
|
59
|
+
(source: ScopedSource) => {
|
60
|
+
setSource(source);
|
117
61
|
},
|
118
|
-
[
|
62
|
+
[setSource],
|
119
63
|
);
|
120
64
|
|
121
65
|
const handleReturnToRoot = useCallback(() => {
|
122
|
-
|
123
|
-
|
124
|
-
setResources([]);
|
125
|
-
setHierarchy([]);
|
126
|
-
|
127
|
-
setSelectedNodeDetails(null);
|
128
|
-
}, []);
|
66
|
+
setSource(null);
|
67
|
+
}, [setSource]);
|
129
68
|
|
130
|
-
const handleDetailSelect = useCallback(
|
131
|
-
|
132
|
-
|
133
|
-
|
69
|
+
const handleDetailSelect = useCallback(
|
70
|
+
(resource: Resource) => {
|
71
|
+
onChange({ resource, source: source?.source as Source });
|
72
|
+
onClose();
|
73
|
+
},
|
74
|
+
[source],
|
75
|
+
);
|
134
76
|
|
135
77
|
const handleDetailClose = useCallback(() => {
|
136
|
-
|
78
|
+
setSelectedResource(null);
|
137
79
|
}, []);
|
138
80
|
|
139
|
-
//
|
81
|
+
// When the active node changes clear the selected resource
|
140
82
|
useEffect(() => {
|
141
|
-
|
142
|
-
|
143
|
-
setSources(sources);
|
144
|
-
setIsSourceLoading(false);
|
145
|
-
});
|
146
|
-
}, []);
|
83
|
+
setSelectedResource(null);
|
84
|
+
}, [hierarchy]);
|
147
85
|
|
148
86
|
return (
|
149
87
|
<div className="relative flex flex-col h-full">
|
@@ -154,9 +92,9 @@ function ResourcePickerContainer({
|
|
154
92
|
<div className="px-3 border-l border-grey-300 w-300px">
|
155
93
|
<SourceDropdown
|
156
94
|
sources={sources}
|
157
|
-
|
95
|
+
selectedSource={source}
|
158
96
|
isLoading={isSourceLoading}
|
159
|
-
onSourceSelect={
|
97
|
+
onSourceSelect={handleSourceDrilldown}
|
160
98
|
onRootSelect={handleReturnToRoot}
|
161
99
|
/>
|
162
100
|
</div>
|
@@ -177,40 +115,38 @@ function ResourcePickerContainer({
|
|
177
115
|
<div className="flex border-t border-grey-300 h-[calc(100%-92px)]">
|
178
116
|
<div className="overflow-y-scroll flex-1 grow-[3] border-r border-gray-300">
|
179
117
|
<h3 className="sr-only">Resource List</h3>
|
180
|
-
{
|
118
|
+
{hierarchy.length > 0 && (
|
119
|
+
<ResourceBreadcrumb
|
120
|
+
hierarchy={hierarchy}
|
121
|
+
onBreadcrumbSelect={popUntil}
|
122
|
+
onReturnToRoot={handleReturnToRoot}
|
123
|
+
/>
|
124
|
+
)}
|
125
|
+
{!source && (
|
181
126
|
<SourceList
|
182
127
|
sources={sources}
|
183
128
|
previewModalState={previewModalState}
|
184
129
|
isLoading={isSourceLoading}
|
185
|
-
onSourceSelect={
|
186
|
-
onSourceDrillDown={
|
130
|
+
onSourceSelect={handleSourceDrilldown}
|
131
|
+
onSourceDrillDown={handleSourceDrilldown}
|
187
132
|
allowedTypes={allowedTypes}
|
188
133
|
/>
|
189
134
|
)}
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
resources={resources}
|
201
|
-
isLoading={isMainLoading}
|
202
|
-
onResourceSelect={handleResourceSelected}
|
203
|
-
onResourceDrillDown={handleResourceDrillDown}
|
204
|
-
allowedTypes={allowedTypes}
|
205
|
-
/>
|
206
|
-
</>
|
135
|
+
{source && (
|
136
|
+
<ResourceList
|
137
|
+
previewModalState={previewModalState}
|
138
|
+
resources={resources}
|
139
|
+
selectedResource={selectedResource}
|
140
|
+
isLoading={isResourcesLoading}
|
141
|
+
onResourceSelect={handleResourceSelected}
|
142
|
+
onResourceDrillDown={handleResourceDrillDown}
|
143
|
+
allowedTypes={allowedTypes}
|
144
|
+
/>
|
207
145
|
)}
|
208
146
|
</div>
|
209
147
|
<PreviewPanel
|
210
|
-
|
211
|
-
resourceDetail={selectedNodeDetails}
|
148
|
+
resource={selectedResource}
|
212
149
|
modalState={previewModalState}
|
213
|
-
isLoading={isSecondaryLoading}
|
214
150
|
previewModalOverlayProps={previewModalOverlayProps}
|
215
151
|
allowedTypes={allowedTypes}
|
216
152
|
onSelect={handleDetailSelect}
|
@@ -2,62 +2,59 @@
|
|
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
|
-
|
6
5
|
import SourceDropdown from './SourceDropdown';
|
6
|
+
import { Source } from '../types';
|
7
|
+
import { mockScopedSource, mockSource } from '../__mocks__/MockModels';
|
7
8
|
|
8
|
-
const sources = [
|
9
|
-
{
|
9
|
+
const sources: Source[] = [
|
10
|
+
mockSource({
|
10
11
|
id: '1',
|
11
12
|
name: 'Source 1',
|
12
13
|
nodes: [
|
13
14
|
{
|
14
|
-
id:
|
15
|
-
|
16
|
-
|
15
|
+
id: '1',
|
16
|
+
type: {
|
17
|
+
code: 'site',
|
18
|
+
name: 'Site',
|
17
19
|
},
|
18
|
-
|
19
|
-
selected: false,
|
20
|
-
label: 'Node 1',
|
20
|
+
name: 'Node 1',
|
21
21
|
childCount: 21,
|
22
22
|
},
|
23
23
|
{
|
24
|
-
id:
|
25
|
-
|
26
|
-
|
24
|
+
id: '2',
|
25
|
+
type: {
|
26
|
+
code: 'site',
|
27
|
+
name: 'Site',
|
27
28
|
},
|
28
|
-
|
29
|
-
selected: false,
|
30
|
-
label: 'Node 2',
|
29
|
+
name: 'Node 2',
|
31
30
|
childCount: 13,
|
32
31
|
},
|
33
32
|
],
|
34
|
-
},
|
35
|
-
{
|
33
|
+
}),
|
34
|
+
mockSource({
|
36
35
|
id: '2',
|
37
36
|
name: 'Source 2',
|
38
37
|
nodes: [
|
39
38
|
{
|
40
|
-
id:
|
41
|
-
|
42
|
-
|
39
|
+
id: '3',
|
40
|
+
type: {
|
41
|
+
code: 'site',
|
42
|
+
name: 'Site',
|
43
43
|
},
|
44
|
-
|
45
|
-
selected: false,
|
46
|
-
label: 'Node 3',
|
44
|
+
name: 'Node 3',
|
47
45
|
childCount: 15,
|
48
46
|
},
|
49
47
|
{
|
50
|
-
id:
|
51
|
-
|
52
|
-
|
48
|
+
id: '4',
|
49
|
+
type: {
|
50
|
+
code: 'site',
|
51
|
+
name: 'Site',
|
53
52
|
},
|
54
|
-
|
55
|
-
selected: false,
|
56
|
-
label: 'Node 4',
|
53
|
+
name: 'Node 4',
|
57
54
|
childCount: 10,
|
58
55
|
},
|
59
56
|
],
|
60
|
-
},
|
57
|
+
}),
|
61
58
|
];
|
62
59
|
|
63
60
|
describe('SourceDropdown', () => {
|
@@ -65,7 +62,7 @@ describe('SourceDropdown', () => {
|
|
65
62
|
render(
|
66
63
|
<SourceDropdown
|
67
64
|
sources={sources}
|
68
|
-
|
65
|
+
selectedSource={null}
|
69
66
|
isLoading={false}
|
70
67
|
onRootSelect={() => {}}
|
71
68
|
onSourceSelect={() => {}}
|
@@ -83,7 +80,7 @@ describe('SourceDropdown', () => {
|
|
83
80
|
render(
|
84
81
|
<SourceDropdown
|
85
82
|
sources={sources}
|
86
|
-
|
83
|
+
selectedSource={null}
|
87
84
|
isLoading={true}
|
88
85
|
onRootSelect={() => {}}
|
89
86
|
onSourceSelect={() => {}}
|
@@ -99,10 +96,14 @@ describe('SourceDropdown', () => {
|
|
99
96
|
render(
|
100
97
|
<SourceDropdown
|
101
98
|
sources={sources}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
99
|
+
selectedSource={mockScopedSource({
|
100
|
+
source: {
|
101
|
+
name: 'Active source',
|
102
|
+
},
|
103
|
+
resource: {
|
104
|
+
name: 'Active scoped resource',
|
105
|
+
},
|
106
|
+
})}
|
106
107
|
isLoading={false}
|
107
108
|
onRootSelect={() => {}}
|
108
109
|
onSourceSelect={() => {}}
|
@@ -110,7 +111,9 @@ describe('SourceDropdown', () => {
|
|
110
111
|
);
|
111
112
|
|
112
113
|
await waitFor(() => {
|
113
|
-
expect(screen.getByRole('button', { name: 'Source quick select' })).toHaveTextContent(
|
114
|
+
expect(screen.getByRole('button', { name: 'Source quick select' })).toHaveTextContent(
|
115
|
+
'current source Active scoped resource',
|
116
|
+
);
|
114
117
|
});
|
115
118
|
});
|
116
119
|
|
@@ -118,7 +121,7 @@ describe('SourceDropdown', () => {
|
|
118
121
|
render(
|
119
122
|
<SourceDropdown
|
120
123
|
sources={sources}
|
121
|
-
|
124
|
+
selectedSource={null}
|
122
125
|
isLoading={false}
|
123
126
|
onRootSelect={() => {}}
|
124
127
|
onSourceSelect={() => {}}
|
@@ -130,10 +133,10 @@ describe('SourceDropdown', () => {
|
|
130
133
|
|
131
134
|
await waitFor(() => {
|
132
135
|
expect(screen.getByRole('button', { name: 'All available sources' })).toBeTruthy();
|
133
|
-
expect(screen.getByRole('button', { name: '
|
134
|
-
expect(screen.getByRole('button', { name: '
|
135
|
-
expect(screen.getByRole('button', { name: '
|
136
|
-
expect(screen.getByRole('button', { name: '
|
136
|
+
expect(screen.getByRole('button', { name: 'Site Node 1' })).toBeTruthy();
|
137
|
+
expect(screen.getByRole('button', { name: 'Site Node 2' })).toBeTruthy();
|
138
|
+
expect(screen.getByRole('button', { name: 'Site Node 3' })).toBeTruthy();
|
139
|
+
expect(screen.getByRole('button', { name: 'Site Node 4' })).toBeTruthy();
|
137
140
|
});
|
138
141
|
});
|
139
142
|
|
@@ -142,7 +145,7 @@ describe('SourceDropdown', () => {
|
|
142
145
|
<div>
|
143
146
|
<SourceDropdown
|
144
147
|
sources={sources}
|
145
|
-
|
148
|
+
selectedSource={null}
|
146
149
|
isLoading={false}
|
147
150
|
onRootSelect={() => {}}
|
148
151
|
onSourceSelect={() => {}}
|
@@ -157,10 +160,10 @@ describe('SourceDropdown', () => {
|
|
157
160
|
|
158
161
|
await waitFor(() => {
|
159
162
|
expect(screen.getByRole('button', { name: 'All available sources' })).toBeTruthy();
|
160
|
-
expect(screen.getByRole('button', { name: '
|
161
|
-
expect(screen.getByRole('button', { name: '
|
162
|
-
expect(screen.getByRole('button', { name: '
|
163
|
-
expect(screen.getByRole('button', { name: '
|
163
|
+
expect(screen.getByRole('button', { name: 'Site Node 1' })).toBeTruthy();
|
164
|
+
expect(screen.getByRole('button', { name: 'Site Node 2' })).toBeTruthy();
|
165
|
+
expect(screen.getByRole('button', { name: 'Site Node 3' })).toBeTruthy();
|
166
|
+
expect(screen.getByRole('button', { name: 'Site Node 4' })).toBeTruthy();
|
164
167
|
});
|
165
168
|
|
166
169
|
user.type(buttonDropdown, '{tab}');
|
@@ -183,7 +186,7 @@ describe('SourceDropdown', () => {
|
|
183
186
|
<div>
|
184
187
|
<SourceDropdown
|
185
188
|
sources={sources}
|
186
|
-
|
189
|
+
selectedSource={null}
|
187
190
|
isLoading={false}
|
188
191
|
onRootSelect={() => {}}
|
189
192
|
onSourceSelect={() => {}}
|
@@ -198,20 +201,20 @@ describe('SourceDropdown', () => {
|
|
198
201
|
|
199
202
|
await waitFor(() => {
|
200
203
|
expect(screen.getByRole('button', { name: 'All available sources' })).toBeTruthy();
|
201
|
-
expect(screen.getByRole('button', { name: '
|
202
|
-
expect(screen.getByRole('button', { name: '
|
203
|
-
expect(screen.getByRole('button', { name: '
|
204
|
-
expect(screen.getByRole('button', { name: '
|
204
|
+
expect(screen.getByRole('button', { name: 'Site Node 1' })).toBeTruthy();
|
205
|
+
expect(screen.getByRole('button', { name: 'Site Node 2' })).toBeTruthy();
|
206
|
+
expect(screen.getByRole('button', { name: 'Site Node 3' })).toBeTruthy();
|
207
|
+
expect(screen.getByRole('button', { name: 'Site Node 4' })).toBeTruthy();
|
205
208
|
});
|
206
209
|
|
207
210
|
user.type(buttonDropdown, '{escape}');
|
208
211
|
|
209
212
|
await waitFor(() => {
|
210
213
|
expect(screen.queryByRole('button', { name: 'All available sources' })).toBeFalsy();
|
211
|
-
expect(screen.queryByRole('button', { name: '
|
212
|
-
expect(screen.queryByRole('button', { name: '
|
213
|
-
expect(screen.queryByRole('button', { name: '
|
214
|
-
expect(screen.queryByRole('button', { name: '
|
214
|
+
expect(screen.queryByRole('button', { name: 'Site Node 1' })).toBeFalsy();
|
215
|
+
expect(screen.queryByRole('button', { name: 'Site Node 2' })).toBeFalsy();
|
216
|
+
expect(screen.queryByRole('button', { name: 'Site Node 3' })).toBeFalsy();
|
217
|
+
expect(screen.queryByRole('button', { name: 'Site Node 4' })).toBeFalsy();
|
215
218
|
});
|
216
219
|
});
|
217
220
|
|
@@ -221,7 +224,7 @@ describe('SourceDropdown', () => {
|
|
221
224
|
render(
|
222
225
|
<SourceDropdown
|
223
226
|
sources={sources}
|
224
|
-
|
227
|
+
selectedSource={null}
|
225
228
|
isLoading={false}
|
226
229
|
onRootSelect={onRootSelect}
|
227
230
|
onSourceSelect={() => {}}
|
@@ -244,7 +247,7 @@ describe('SourceDropdown', () => {
|
|
244
247
|
render(
|
245
248
|
<SourceDropdown
|
246
249
|
sources={sources}
|
247
|
-
|
250
|
+
selectedSource={null}
|
248
251
|
isLoading={false}
|
249
252
|
onRootSelect={() => {}}
|
250
253
|
onSourceSelect={onSourceSelect}
|
@@ -253,10 +256,10 @@ describe('SourceDropdown', () => {
|
|
253
256
|
|
254
257
|
const user = userEvent.setup();
|
255
258
|
await user.click(screen.getByRole('button', { name: 'Source quick select' }));
|
256
|
-
await user.click(screen.getByRole('button', { name: '
|
259
|
+
await user.click(screen.getByRole('button', { name: 'Site Node 1' }));
|
257
260
|
|
258
261
|
await waitFor(() => {
|
259
|
-
expect(onSourceSelect).toHaveBeenCalledWith({
|
262
|
+
expect(onSourceSelect).toHaveBeenCalledWith({ source: sources[0], resource: sources[0].nodes[0] });
|
260
263
|
expect(screen.queryByRole('button', { name: 'All available sources' })).toBeFalsy();
|
261
264
|
});
|
262
265
|
});
|
@@ -2,17 +2,17 @@ import React from 'react';
|
|
2
2
|
import { StoryFn, Meta } from '@storybook/react';
|
3
3
|
|
4
4
|
import SourceDropdown from './SourceDropdown';
|
5
|
-
import sampleSources from '
|
5
|
+
import sampleSources from '../SourceList/sample-sources.json';
|
6
6
|
|
7
7
|
export default {
|
8
8
|
title: 'Source Dropdown',
|
9
9
|
component: SourceDropdown,
|
10
10
|
} as Meta<typeof SourceDropdown>;
|
11
11
|
|
12
|
-
const Template: StoryFn<typeof SourceDropdown> = ({ sources,
|
12
|
+
const Template: StoryFn<typeof SourceDropdown> = ({ sources, selectedSource, isLoading }) => (
|
13
13
|
<SourceDropdown
|
14
14
|
sources={sources}
|
15
|
-
|
15
|
+
selectedSource={selectedSource}
|
16
16
|
isLoading={isLoading}
|
17
17
|
onSourceSelect={({ source, id }) => alert(`Source Select: ${source} - ${id}`)}
|
18
18
|
onRootSelect={() => alert(`Root Select`)}
|
@@ -22,10 +22,7 @@ const Template: StoryFn<typeof SourceDropdown> = ({ sources, currentSource, isLo
|
|
22
22
|
export const Primary = Template.bind({});
|
23
23
|
Primary.args = {
|
24
24
|
sources: sampleSources,
|
25
|
-
|
26
|
-
id: '1',
|
27
|
-
source: '1',
|
28
|
-
},
|
25
|
+
selectedSource: { source: sampleSources[0], resource: sampleSources[0].nodes[0] },
|
29
26
|
isLoading: false,
|
30
27
|
};
|
31
28
|
|