@squiz/resource-browser 3.3.4 → 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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.3.6
4
+
5
+ ### Patch Changes
6
+
7
+ - bd748ea: Better support for AssetBank resources
8
+
9
+ ## 3.3.5
10
+
11
+ ### Patch Changes
12
+
13
+ - 856a08e: Support AssetBank resources
14
+
3
15
  ## 3.3.4
4
16
 
5
17
  ### Patch Changes
@@ -17,6 +17,8 @@ const useAuth = (authConfig) => {
17
17
  catch {
18
18
  setAuthToken(null);
19
19
  setIsAuthenticated(false);
20
+ // Clear cookies associated with invalidated tokens
21
+ (0, authUtils_1.logout)();
20
22
  throw new Error('Session expired. Please log in again.');
21
23
  }
22
24
  }, [authConfig]);
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 source = null;
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
- source = sources.find((source) => source.id === value?.sourceId) || null;
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 (source === null && !isLoading) {
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
- source = sources[0];
91
+ newSource = sources[0];
89
92
  }
90
- setSource(source);
93
+ setSource(newSource);
91
94
  setMode(null); // Passed in resource will always use the default mode
92
- }, [value, isLoading, sources, setSource, setError]);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/resource-browser",
3
- "version": "3.3.4",
3
+ "version": "3.3.6",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "private": false,
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-console */
2
2
  import { useState, useCallback, useEffect } from 'react';
3
3
  import { AuthenticationConfiguration } from '../types';
4
- import { getCookieValue, refreshAccessToken as refreshTokenUtil } from '../utils/authUtils';
4
+ import { getCookieValue, refreshAccessToken as refreshTokenUtil, logout } from '../utils/authUtils';
5
5
 
6
6
  export const useAuth = (authConfig: AuthenticationConfiguration | undefined) => {
7
7
  const [authToken, setAuthToken] = useState<string | null>(getCookieValue('authToken'));
@@ -16,6 +16,8 @@ export const useAuth = (authConfig: AuthenticationConfiguration | undefined) =>
16
16
  } catch {
17
17
  setAuthToken(null);
18
18
  setIsAuthenticated(false);
19
+ // Clear cookies associated with invalidated tokens
20
+ logout();
19
21
  throw new Error('Session expired. Please log in again.');
20
22
  }
21
23
  }, [authConfig]);
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 source: ResourceBrowserSourceWithPlugin | null = null;
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
- source = sources.find((source) => source.id === value?.sourceId) || null;
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 (source === null && !isLoading) {
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
- source = sources[0];
90
+ newSource = sources[0];
88
91
  }
89
92
 
90
- setSource(source);
93
+ setSource(newSource);
91
94
  setMode(null); // Passed in resource will always use the default mode
92
- }, [value, isLoading, sources, setSource, setError]);
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(