@squiz/resource-browser 2.1.8-rc.0 → 2.1.10-rc.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/.storybook/preview-body.html +1 -0
- package/.storybook/preview-head.html +7 -10
- package/CHANGELOG.md +8 -0
- package/lib/Hooks/useSources.d.ts +1 -2
- package/lib/Hooks/useSources.js +2 -1
- package/lib/MainContainer/MainContainer.js +1 -1
- package/lib/index.css +326 -326
- package/package.json +3 -3
- package/postcss.config.js +19 -15
- package/src/Hooks/useSources.spec.ts +30 -1
- package/src/Hooks/useSources.ts +3 -2
- package/src/MainContainer/MainContainer.tsx +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@squiz/resource-browser",
|
3
|
-
"version": "2.1.
|
3
|
+
"version": "2.1.10-rc.0",
|
4
4
|
"main": "lib/index.js",
|
5
5
|
"types": "lib/index.d.ts",
|
6
6
|
"private": false,
|
@@ -23,7 +23,7 @@
|
|
23
23
|
"@react-types/shared": "^3.22.1",
|
24
24
|
"@squiz/dx-json-schema-lib": "^1.67.0",
|
25
25
|
"@squiz/generic-browser-lib": "^1.66.0",
|
26
|
-
"@squiz/resource-browser-ui-lib": "^0.8.
|
26
|
+
"@squiz/resource-browser-ui-lib": "^0.8.2-rc.0",
|
27
27
|
"clsx": "^2.1.0",
|
28
28
|
"expiry-map": "^2.0.0",
|
29
29
|
"p-memoize": "^4.0.4",
|
@@ -81,5 +81,5 @@
|
|
81
81
|
"volta": {
|
82
82
|
"node": "18.18.0"
|
83
83
|
},
|
84
|
-
"gitHead": "
|
84
|
+
"gitHead": "0799116e7501bb4eaa3c401be6304231d8910f75"
|
85
85
|
}
|
package/postcss.config.js
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
module.exports = {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
2
|
+
plugins: [
|
3
|
+
require('tailwindcss'),
|
4
|
+
require('autoprefixer'),
|
5
|
+
require('postcss-nested'),
|
6
|
+
require('postcss-prefix-selector')({
|
7
|
+
prefix: '.squiz-rb-scope',
|
8
|
+
transform(prefix, selector, prefixedSelector, filePath, rule) {
|
9
|
+
if (selector.match(/(squiz-gb-scope)/)) {
|
10
|
+
return selector;
|
11
|
+
}
|
12
|
+
if (selector.match(/(::)/)) {
|
13
|
+
const index = prefixedSelector.indexOf('::');
|
14
|
+
return `${prefixedSelector.slice(0, index)}:not(.squiz-rb-plugin *)${prefixedSelector.slice(index)}`;
|
15
|
+
}
|
16
|
+
return `${prefixedSelector}:not(.squiz-rb-plugin *)`;
|
17
|
+
},
|
18
|
+
includeFiles: ['./src/index.scss'],
|
19
|
+
}),
|
20
|
+
],
|
17
21
|
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { renderHook, waitFor } from '@testing-library/react';
|
2
2
|
import { mockSource, mockPlugin } from '../__mocks__/MockModels';
|
3
|
-
import { useSources } from './useSources';
|
3
|
+
import { useSources, UseSourcesProps } from './useSources';
|
4
4
|
|
5
5
|
describe('useSources', () => {
|
6
6
|
it('Should trigger and load the sources', async () => {
|
@@ -35,4 +35,33 @@ describe('useSources', () => {
|
|
35
35
|
expect(result.current.data).toEqual([sources[0]]);
|
36
36
|
expect(result.current.data.length).toEqual(1);
|
37
37
|
});
|
38
|
+
|
39
|
+
it('Should calculate the async key from the plugins type so it wont always change on re-renders', async () => {
|
40
|
+
const sources = [mockSource()];
|
41
|
+
const plugins = [mockPlugin()];
|
42
|
+
const onRequestSources = jest.fn().mockResolvedValue(sources);
|
43
|
+
const { rerender, result } = renderHook((props: UseSourcesProps) =>
|
44
|
+
useSources({ onRequestSources: props?.onRequestSources || onRequestSources, plugins: props?.plugins || plugins }),
|
45
|
+
);
|
46
|
+
|
47
|
+
expect(result.current.isLoading).toBe(true);
|
48
|
+
expect(result.current.error).toBe(null);
|
49
|
+
expect(result.current.data).toEqual([]);
|
50
|
+
|
51
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
52
|
+
expect(result.current.isLoading).toBe(false);
|
53
|
+
expect(result.current.data).toEqual(sources);
|
54
|
+
|
55
|
+
// Wont go back to loading data (plugin keys havent changed)
|
56
|
+
rerender({ onRequestSources, plugins: [mockPlugin()] });
|
57
|
+
expect(result.current.isLoading).toBe(false);
|
58
|
+
|
59
|
+
// Will go back to loading as change in keys
|
60
|
+
rerender({ onRequestSources, plugins: [mockPlugin(), mockPlugin({ type: 'matrix' })] });
|
61
|
+
expect(result.current.isLoading).toBe(true);
|
62
|
+
|
63
|
+
// Will go back to loading as change in keys (order change will cause reload)
|
64
|
+
rerender({ onRequestSources, plugins: [mockPlugin({ type: 'matrix' }), mockPlugin()] });
|
65
|
+
expect(result.current.isLoading).toBe(true);
|
66
|
+
});
|
38
67
|
});
|
package/src/Hooks/useSources.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ResourceBrowserSource, ResourceBrowserPlugin } from '../types';
|
2
2
|
import { useAsync } from '@squiz/generic-browser-lib';
|
3
3
|
|
4
|
-
type UseSourcesProps = {
|
4
|
+
export type UseSourcesProps = {
|
5
5
|
onRequestSources: () => Promise<ResourceBrowserSource[]>;
|
6
6
|
plugins: Array<ResourceBrowserPlugin>;
|
7
7
|
};
|
@@ -10,6 +10,7 @@ type UseSourcesProps = {
|
|
10
10
|
* Loads and caches the source list when a component using the hook is mounted.
|
11
11
|
*/
|
12
12
|
export const useSources = ({ onRequestSources, plugins }: UseSourcesProps) => {
|
13
|
+
const pluginsKey = plugins.reduce((acc, plugin) => acc + plugin.type, '');
|
13
14
|
return useAsync(
|
14
15
|
{
|
15
16
|
callback: () => {
|
@@ -36,6 +37,6 @@ export const useSources = ({ onRequestSources, plugins }: UseSourcesProps) => {
|
|
36
37
|
},
|
37
38
|
defaultValue: [] as ResourceBrowserSource[],
|
38
39
|
},
|
39
|
-
[
|
40
|
+
[onRequestSources, pluginsKey],
|
40
41
|
);
|
41
42
|
};
|
@@ -79,7 +79,7 @@ function MainContainer({
|
|
79
79
|
</svg>
|
80
80
|
</button>
|
81
81
|
</div>
|
82
|
-
<div className="border-t border-gray-300
|
82
|
+
<div className="squiz-rb-plugin border-t border-gray-300 overflow-y-hidden">
|
83
83
|
{plugin && selectedSource && SourceBrowser && (
|
84
84
|
<SourceBrowser
|
85
85
|
source={selectedSource}
|