@squiz/resource-browser 3.3.5 → 3.3.6
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/CHANGELOG.md +6 -0
- package/lib/index.js +9 -6
- package/package.json +1 -1
- package/src/index.tsx +9 -6
package/CHANGELOG.md
CHANGED
package/lib/index.js
CHANGED
@@ -71,25 +71,28 @@ const ResourceBrowser = (props) => {
|
|
71
71
|
}, [setSource, setMode]);
|
72
72
|
// If an existing resource is passed in auto select its source
|
73
73
|
(0, react_1.useEffect)(() => {
|
74
|
-
let
|
74
|
+
let newSource = null;
|
75
75
|
setError(null);
|
76
|
+
if (source !== null) {
|
77
|
+
return;
|
78
|
+
}
|
76
79
|
// If there is a provided value try to use its source
|
77
80
|
if (value) {
|
78
81
|
// Search the sources for it matching against the value.source property
|
79
|
-
|
82
|
+
newSource = sources.find((source) => source.id === value?.sourceId) || null;
|
80
83
|
// If the source is null and we arent loading the sources
|
81
|
-
if (
|
84
|
+
if (newSource === null && !isLoading) {
|
82
85
|
// Set an error as the passed in value's source wasnt returned by onRequestSources
|
83
86
|
setError(new Error('Unable to find resource source.'));
|
84
87
|
}
|
85
88
|
}
|
86
89
|
else if (sources?.length === 1 && !searchEnabled) {
|
87
90
|
// If only one source is passed and search is not enabled select it automatically
|
88
|
-
|
91
|
+
newSource = sources[0];
|
89
92
|
}
|
90
|
-
setSource(
|
93
|
+
setSource(newSource);
|
91
94
|
setMode(null); // Passed in resource will always use the default mode
|
92
|
-
}, [value, isLoading, sources,
|
95
|
+
}, [value, isLoading, sources, source]);
|
93
96
|
// The modal has some control over it own open/closed state (for WCAG reasons) so keep this in sync with our state
|
94
97
|
const handleModalStateChange = (0, react_1.useCallback)((isOpen) => {
|
95
98
|
setIsModalOpen(isOpen);
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
@@ -70,26 +70,29 @@ export const ResourceBrowser = (props: ResourceBrowserProps) => {
|
|
70
70
|
|
71
71
|
// If an existing resource is passed in auto select its source
|
72
72
|
useEffect(() => {
|
73
|
-
let
|
73
|
+
let newSource: ResourceBrowserSourceWithPlugin | null = null;
|
74
74
|
setError(null);
|
75
|
+
if (source !== null) {
|
76
|
+
return;
|
77
|
+
}
|
75
78
|
|
76
79
|
// If there is a provided value try to use its source
|
77
80
|
if (value) {
|
78
81
|
// Search the sources for it matching against the value.source property
|
79
|
-
|
82
|
+
newSource = sources.find((source) => source.id === value?.sourceId) || null;
|
80
83
|
// If the source is null and we arent loading the sources
|
81
|
-
if (
|
84
|
+
if (newSource === null && !isLoading) {
|
82
85
|
// Set an error as the passed in value's source wasnt returned by onRequestSources
|
83
86
|
setError(new Error('Unable to find resource source.'));
|
84
87
|
}
|
85
88
|
} else if (sources?.length === 1 && !searchEnabled) {
|
86
89
|
// If only one source is passed and search is not enabled select it automatically
|
87
|
-
|
90
|
+
newSource = sources[0];
|
88
91
|
}
|
89
92
|
|
90
|
-
setSource(
|
93
|
+
setSource(newSource);
|
91
94
|
setMode(null); // Passed in resource will always use the default mode
|
92
|
-
}, [value, isLoading, sources,
|
95
|
+
}, [value, isLoading, sources, source]);
|
93
96
|
|
94
97
|
// The modal has some control over it own open/closed state (for WCAG reasons) so keep this in sync with our state
|
95
98
|
const handleModalStateChange = useCallback(
|