@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
@@ -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 sampleSources from '../SourceList/sample-sources.json';
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
- return new Promise((resolve) => {
22
- setTimeout(resolve, 500, sampleSources);
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 { NodeIdentifier, Source, Resource, ResourceDetail, Hierarchy } from '../index';
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(id: NodeIdentifier): Promise<Resource[]>;
19
- onRequestResource(id: NodeIdentifier): Promise<ResourceDetail | null>;
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 [isSourceLoading, setIsSourceLoading] = useState<boolean>(false);
37
- const [isMainLoading, setIsMainLoading] = useState<boolean>(false);
38
- const [isSecondaryLoading, setIsSecondaryLoading] = useState<boolean>(false);
39
-
40
- const [currentNode, setCurrentNode] = useState<NodeIdentifier | null>(null);
41
- const [selectedId, setSelectedId] = useState<NodeIdentifier | null>(null);
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((node: NodeIdentifier, overlayProps: DOMAttributes<FocusableElement>) => {
53
+ const handleResourceSelected = useCallback((resource: Resource, overlayProps: DOMAttributes) => {
91
54
  setPreviewModalOverlayProps(overlayProps);
92
- setIsSecondaryLoading(true);
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 handleResourceDrillDown = useCallback(
104
- (node: NodeIdentifier, resetHierarchy?: boolean) => {
105
- setIsMainLoading(true);
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
- [resources, sources],
62
+ [setSource],
119
63
  );
120
64
 
121
65
  const handleReturnToRoot = useCallback(() => {
122
- setCurrentNode(null);
123
- setSelectedId(null);
124
- setResources([]);
125
- setHierarchy([]);
126
-
127
- setSelectedNodeDetails(null);
128
- }, []);
66
+ setSource(null);
67
+ }, [setSource]);
129
68
 
130
- const handleDetailSelect = useCallback((node: NodeIdentifier) => {
131
- onChange(node);
132
- onClose();
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
- setSelectedId(null);
78
+ setSelectedResource(null);
137
79
  }, []);
138
80
 
139
- // On load of component fetch the list of sources
81
+ // When the active node changes clear the selected resource
140
82
  useEffect(() => {
141
- setIsSourceLoading(true);
142
- onRequestSources().then((sources: Array<Source>) => {
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
- currentSource={hierarchy[0]?.id}
95
+ selectedSource={source}
158
96
  isLoading={isSourceLoading}
159
- onSourceSelect={handleResourceDrillDown}
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
- {currentNode === null && (
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={handleResourceSelected}
186
- onSourceDrillDown={handleResourceDrillDown}
130
+ onSourceSelect={handleSourceDrilldown}
131
+ onSourceDrillDown={handleSourceDrilldown}
187
132
  allowedTypes={allowedTypes}
188
133
  />
189
134
  )}
190
-
191
- {currentNode && (
192
- <>
193
- <ResourceBreadcrumb
194
- hierarchy={hierarchy}
195
- onBreadcrumbSelect={handleResourceDrillDown}
196
- onReturnToRoot={handleReturnToRoot}
197
- />
198
- <ResourceList
199
- previewModalState={previewModalState}
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
- node={selectedId}
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
- id: '1',
16
- source: '1',
15
+ id: '1',
16
+ type: {
17
+ code: 'site',
18
+ name: 'Site',
17
19
  },
18
- type: 'site',
19
- selected: false,
20
- label: 'Node 1',
20
+ name: 'Node 1',
21
21
  childCount: 21,
22
22
  },
23
23
  {
24
- id: {
25
- id: '2',
26
- source: '1',
24
+ id: '2',
25
+ type: {
26
+ code: 'site',
27
+ name: 'Site',
27
28
  },
28
- type: 'site',
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
- id: '1',
42
- source: '2',
39
+ id: '3',
40
+ type: {
41
+ code: 'site',
42
+ name: 'Site',
43
43
  },
44
- type: 'site',
45
- selected: false,
46
- label: 'Node 3',
44
+ name: 'Node 3',
47
45
  childCount: 15,
48
46
  },
49
47
  {
50
- id: {
51
- id: '2',
52
- source: '2',
48
+ id: '4',
49
+ type: {
50
+ code: 'site',
51
+ name: 'Site',
53
52
  },
54
- type: 'site',
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
- currentSource={null}
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
- currentSource={null}
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
- currentSource={{
103
- id: '2',
104
- source: '2',
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('current source Node 4');
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
- currentSource={null}
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: 'site Node 1' })).toBeTruthy();
134
- expect(screen.getByRole('button', { name: 'site Node 2' })).toBeTruthy();
135
- expect(screen.getByRole('button', { name: 'site Node 3' })).toBeTruthy();
136
- expect(screen.getByRole('button', { name: 'site Node 4' })).toBeTruthy();
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
- currentSource={null}
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: 'site Node 1' })).toBeTruthy();
161
- expect(screen.getByRole('button', { name: 'site Node 2' })).toBeTruthy();
162
- expect(screen.getByRole('button', { name: 'site Node 3' })).toBeTruthy();
163
- expect(screen.getByRole('button', { name: 'site Node 4' })).toBeTruthy();
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
- currentSource={null}
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: 'site Node 1' })).toBeTruthy();
202
- expect(screen.getByRole('button', { name: 'site Node 2' })).toBeTruthy();
203
- expect(screen.getByRole('button', { name: 'site Node 3' })).toBeTruthy();
204
- expect(screen.getByRole('button', { name: 'site Node 4' })).toBeTruthy();
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: 'site Node 1' })).toBeFalsy();
212
- expect(screen.queryByRole('button', { name: 'site Node 2' })).toBeFalsy();
213
- expect(screen.queryByRole('button', { name: 'site Node 3' })).toBeFalsy();
214
- expect(screen.queryByRole('button', { name: 'site Node 4' })).toBeFalsy();
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
- currentSource={null}
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
- currentSource={null}
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: 'site Node 1' }));
259
+ await user.click(screen.getByRole('button', { name: 'Site Node 1' }));
257
260
 
258
261
  await waitFor(() => {
259
- expect(onSourceSelect).toHaveBeenCalledWith({ id: '1', source: '1' }, true);
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 './sample-sources.json';
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, currentSource, isLoading }) => (
12
+ const Template: StoryFn<typeof SourceDropdown> = ({ sources, selectedSource, isLoading }) => (
13
13
  <SourceDropdown
14
14
  sources={sources}
15
- currentSource={currentSource}
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
- currentSource: {
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