@squiz/resource-browser 3.2.1 → 3.2.3
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 +13 -0
- package/lib/Plugin/Plugin.js +4 -5
- package/lib/ResourceBrowserInlineButton/ResourceBrowserInlineButton.js +1 -1
- package/lib/ResourceBrowserInput/ResourceBrowserInput.d.ts +1 -1
- package/lib/ResourceBrowserInput/ResourceBrowserInput.js +1 -1
- package/lib/index.css +11 -20
- package/lib/types.d.ts +2 -1
- package/package.json +1 -1
- package/src/Plugin/Plugin.spec.tsx +47 -52
- package/src/Plugin/Plugin.stories.tsx +94 -0
- package/src/Plugin/Plugin.tsx +9 -14
- package/src/ResourceBrowserInlineButton/ResourceBrowserInlineButton.tsx +1 -1
- package/src/ResourceBrowserInput/ResourceBrowserInput.tsx +2 -2
- package/src/index.spec.tsx +1 -1
- package/src/types.ts +5 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 3.2.3
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- fe57830: fix for refresh token clering by other plugins
|
8
|
+
|
9
|
+
## 3.2.2
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- 168c317: Pass all preselected info to resolvers, dam resolve variant
|
14
|
+
- 168c317: Added optional extra fields to pass dam variant information
|
15
|
+
|
3
16
|
## 3.2.1
|
4
17
|
|
5
18
|
### Patch Changes
|
package/lib/Plugin/Plugin.js
CHANGED
@@ -9,11 +9,10 @@ const ResourceBrowserInput_1 = require("../ResourceBrowserInput/ResourceBrowserI
|
|
9
9
|
const ResourceBrowserInlineButton_1 = require("../ResourceBrowserInlineButton/ResourceBrowserInlineButton");
|
10
10
|
const AuthProvider_1 = require("../ResourceBrowserContext/AuthProvider");
|
11
11
|
const PluginRender = ({ render, inline, inlineType, ...props }) => {
|
12
|
-
if (render)
|
13
|
-
return (react_1.default.createElement(AuthProvider_1.AuthProvider, { authConfig: props.source }, inline && inlineType ? (react_1.default.createElement(ResourceBrowserInlineButton_1.ResourceBrowserInlineButton, { inlineType: inlineType, ...props })) : (react_1.default.createElement(ResourceBrowserInput_1.ResourceBrowserInput, { ...props }))));
|
14
|
-
}
|
15
|
-
else {
|
12
|
+
if (!render)
|
16
13
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
17
|
-
|
14
|
+
const requiresAuth = Boolean(props.source?.configuration?.authUrl);
|
15
|
+
const content = inline && inlineType ? react_1.default.createElement(ResourceBrowserInlineButton_1.ResourceBrowserInlineButton, { inlineType: inlineType, ...props }) : react_1.default.createElement(ResourceBrowserInput_1.ResourceBrowserInput, { ...props });
|
16
|
+
return requiresAuth ? react_1.default.createElement(AuthProvider_1.AuthProvider, { authConfig: props.source }, content) : content;
|
18
17
|
};
|
19
18
|
exports.PluginRender = PluginRender;
|
@@ -12,7 +12,7 @@ const ImageInline_1 = require("../Icons/ImageInline");
|
|
12
12
|
const LinkInline_1 = require("../Icons/LinkInline");
|
13
13
|
const ResourceBrowserInlineButton = ({ inlineType, modalTitle, allowedTypes, onChange, onRetry, value, useResource, isDisabled, plugin, pluginMode, searchEnabled, source, sources, isLoading, error, setSource, isModalOpen, onModalStateChange, }) => {
|
14
14
|
// If an error happens loading the resource the inline browser just opens without it as if no preselectedResource is provided
|
15
|
-
const { data: resource, isLoading: isResourceLoading } = useResource(value
|
15
|
+
const { data: resource, isLoading: isResourceLoading } = useResource(value || null, source);
|
16
16
|
const isImagePicker = inlineType === 'image';
|
17
17
|
return (react_1.default.createElement("div", { className: "inline-launch-button" },
|
18
18
|
react_1.default.createElement(resource_browser_ui_lib_1.ModalTrigger, { overlayTriggerState: {
|
@@ -5,7 +5,7 @@ export type ResourceBrowserInputProps = {
|
|
5
5
|
allowedTypes?: string[];
|
6
6
|
isDisabled?: boolean;
|
7
7
|
value: ResourceBrowserUnresolvedResource | null;
|
8
|
-
useResource(
|
8
|
+
useResource(reference: ResourceBrowserUnresolvedResource | null, source: ResourceBrowserSource | null): useResolveResourceResponse;
|
9
9
|
onChange(resource: ResourceBrowserResource | null): void;
|
10
10
|
onClear?(): void;
|
11
11
|
plugin: ResourceBrowserPlugin | null;
|
@@ -8,7 +8,7 @@ const react_1 = __importDefault(require("react"));
|
|
8
8
|
const MainContainer_1 = __importDefault(require("../MainContainer/MainContainer"));
|
9
9
|
const ResourcePicker_1 = require("../ResourcePicker/ResourcePicker");
|
10
10
|
const ResourceBrowserInput = ({ modalTitle, allowedTypes, onChange, value, useResource, isDisabled, onClear, plugin, pluginMode, searchEnabled, source, sources, isLoading, isOtherSourceValue, error, setSource, isModalOpen, onModalStateChange, }) => {
|
11
|
-
const { data: resource, error: resourceError, isLoading: isResourceLoading } = useResource(value
|
11
|
+
const { data: resource, error: resourceError, isLoading: isResourceLoading } = useResource(value || null, source);
|
12
12
|
const defaultOnClear = () => onChange(null);
|
13
13
|
const onClearFunction = onClear ?? defaultOnClear;
|
14
14
|
return (react_1.default.createElement(ResourcePicker_1.ResourcePicker, { resource: resource, plugin: plugin, allowedTypes: allowedTypes, error: resourceError || error, isLoading: isResourceLoading || isLoading, isOtherSourceValue: isOtherSourceValue, isDisabled: isDisabled, onClear: onClearFunction, isModalOpen: isModalOpen, onModalStateChange: onModalStateChange }, (onClose, titleProps) => (react_1.default.createElement(MainContainer_1.default, { selectedSource: source, sources: sources, preselectedResource: resource, plugin: plugin, pluginMode: pluginMode, searchEnabled: searchEnabled, title: modalTitle, titleAriaProps: titleProps, allowedTypes: allowedTypes, onSourceSelect: setSource, onClose: onClose, onChange: onChange }))));
|
package/lib/index.css
CHANGED
@@ -6127,20 +6127,22 @@
|
|
6127
6127
|
}
|
6128
6128
|
.squiz-rb-scope .image-info:not(.squiz-rb-plugin *) {
|
6129
6129
|
align-items: center;
|
6130
|
-
border-top: 1px solid #e0e0e0;
|
6131
6130
|
color: #707070;
|
6132
6131
|
display: flex;
|
6133
6132
|
flex-direction: column;
|
6134
|
-
height: calc(50vh - 60px);
|
6135
|
-
overflow-y: auto;
|
6136
6133
|
}
|
6137
6134
|
.squiz-rb-scope .image-info__image-container:not(.squiz-rb-plugin *) {
|
6138
6135
|
position: relative;
|
6139
6136
|
width: 250px;
|
6140
6137
|
height: 150px;
|
6141
|
-
|
6138
|
+
min-height: 150px;
|
6139
|
+
margin: 1.25rem 0;
|
6142
6140
|
background-color: #ededed;
|
6143
6141
|
}
|
6142
|
+
.squiz-rb-scope .image-info__divider:not(.squiz-rb-plugin *) {
|
6143
|
+
width: 100%;
|
6144
|
+
padding: 0 1.25rem;
|
6145
|
+
}
|
6144
6146
|
.squiz-rb-scope .checkered-bg:not(.squiz-rb-plugin *) {
|
6145
6147
|
--tw-bg-opacity: 1;
|
6146
6148
|
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
|
@@ -6186,10 +6188,13 @@
|
|
6186
6188
|
display: flex;
|
6187
6189
|
flex-direction: column;
|
6188
6190
|
margin: 1rem 0;
|
6191
|
+
width: 100%;
|
6192
|
+
padding: 0 1.25rem;
|
6189
6193
|
}
|
6190
6194
|
.squiz-rb-scope .image-info__details-item:not(.squiz-rb-plugin *) {
|
6191
6195
|
display: flex;
|
6192
6196
|
margin-bottom: 0.5rem;
|
6197
|
+
padding-left: 0.25rem;
|
6193
6198
|
}
|
6194
6199
|
.squiz-rb-scope .image-info__details-label:not(.squiz-rb-plugin *) {
|
6195
6200
|
color: #707070;
|
@@ -6201,7 +6206,8 @@
|
|
6201
6206
|
color: #3d3d3d;
|
6202
6207
|
}
|
6203
6208
|
.squiz-rb-scope .image-variant__list:not(.squiz-rb-plugin *) {
|
6204
|
-
width:
|
6209
|
+
width: 100%;
|
6210
|
+
padding: 0 1.25rem;
|
6205
6211
|
margin-bottom: 1rem;
|
6206
6212
|
}
|
6207
6213
|
.squiz-rb-scope .image-variant__item:not(.squiz-rb-plugin *) {
|
@@ -6257,21 +6263,6 @@
|
|
6257
6263
|
.squiz-rb-scope .image-info__loading:not(.squiz-rb-plugin *) {
|
6258
6264
|
margin-top: 80px;
|
6259
6265
|
}
|
6260
|
-
@media (min-width: 768px) {
|
6261
|
-
.squiz-rb-scope .image-info:not(.squiz-rb-plugin *) {
|
6262
|
-
height: calc(100vh - 60px);
|
6263
|
-
}
|
6264
|
-
}
|
6265
|
-
@media (min-width: 1024px) {
|
6266
|
-
.squiz-rb-scope .image-info:not(.squiz-rb-plugin *) {
|
6267
|
-
height: calc(100vh - 14rem);
|
6268
|
-
overflow-y: auto;
|
6269
|
-
}
|
6270
|
-
}
|
6271
|
-
.squiz-rb-scope .divider-container:not(.squiz-rb-plugin *) {
|
6272
|
-
padding: 0 1.25rem;
|
6273
|
-
width: 100%;
|
6274
|
-
}
|
6275
6266
|
.squiz-rb-scope .resource-picker:not(.squiz-rb-plugin *) {
|
6276
6267
|
display: grid;
|
6277
6268
|
grid-template-columns: 24px 1fr;
|
package/lib/types.d.ts
CHANGED
@@ -31,6 +31,7 @@ export type PluginLaunchMode = {
|
|
31
31
|
export type ResourceBrowserUnresolvedResource = {
|
32
32
|
sourceId: string;
|
33
33
|
resourceId: string;
|
34
|
+
[k: string]: unknown;
|
34
35
|
};
|
35
36
|
export type ResourceBrowserResource = {
|
36
37
|
id: string;
|
@@ -93,6 +94,6 @@ export interface ResourceBrowserPlugin {
|
|
93
94
|
/** Function to provde the the summary information to show what resource is currently selected */
|
94
95
|
renderSelectedResource: (resource: ResourceBrowserResource) => Promise<ResourceBrowserSelectedState>;
|
95
96
|
/** Function to resolve a resource and source id into a fully resolved output reference */
|
96
|
-
useResolveResource: (
|
97
|
+
useResolveResource: (resource: ResourceBrowserUnresolvedResource | null, source: ResourceBrowserSource | null) => useResolveResourceResponse;
|
97
98
|
}
|
98
99
|
export {};
|
package/package.json
CHANGED
@@ -2,10 +2,35 @@ import React from 'react';
|
|
2
2
|
import { render, waitFor } from '@testing-library/react';
|
3
3
|
|
4
4
|
import { PluginRender } from './Plugin';
|
5
|
+
import { ResourceBrowserPluginType } from '../types';
|
5
6
|
import * as RBI from '../ResourceBrowserInput/ResourceBrowserInput';
|
6
7
|
import * as RBInlineButton from '../ResourceBrowserInlineButton/ResourceBrowserInlineButton';
|
8
|
+
import * as AuthContext from '../ResourceBrowserContext/AuthProvider';
|
9
|
+
|
7
10
|
jest.spyOn(RBI, 'ResourceBrowserInput');
|
8
11
|
jest.spyOn(RBInlineButton, 'ResourceBrowserInlineButton');
|
12
|
+
jest.spyOn(AuthContext, 'AuthProvider');
|
13
|
+
|
14
|
+
const baseProps = {
|
15
|
+
type: null,
|
16
|
+
modalTitle: 'Asset picker',
|
17
|
+
value: null,
|
18
|
+
isOtherSourceValue: false,
|
19
|
+
onChange: jest.fn(),
|
20
|
+
onClear: jest.fn(),
|
21
|
+
useResource: () => ({ data: null, error: null, isLoading: false }),
|
22
|
+
plugin: null,
|
23
|
+
pluginMode: null,
|
24
|
+
searchEnabled: false,
|
25
|
+
source: null,
|
26
|
+
sources: [],
|
27
|
+
isLoading: false,
|
28
|
+
error: null,
|
29
|
+
setSource: jest.fn(),
|
30
|
+
isModalOpen: false,
|
31
|
+
onModalStateChange: jest.fn(),
|
32
|
+
onRetry: jest.fn(),
|
33
|
+
};
|
9
34
|
|
10
35
|
describe('Plugin', () => {
|
11
36
|
it('Does not render ResourceBrowserInput if render is false', async () => {
|
@@ -18,32 +43,7 @@ describe('Plugin', () => {
|
|
18
43
|
});
|
19
44
|
|
20
45
|
it('Does render ResourceBrowserInput if render is true', async () => {
|
21
|
-
const props =
|
22
|
-
type: null,
|
23
|
-
modalTitle: 'Asset picker',
|
24
|
-
value: null,
|
25
|
-
isOtherSourceValue: false,
|
26
|
-
onChange: jest.fn(),
|
27
|
-
onClear: jest.fn(),
|
28
|
-
useResource: () => {
|
29
|
-
return {
|
30
|
-
data: null,
|
31
|
-
error: null,
|
32
|
-
isLoading: false,
|
33
|
-
};
|
34
|
-
},
|
35
|
-
plugin: null,
|
36
|
-
pluginMode: null,
|
37
|
-
searchEnabled: false,
|
38
|
-
source: null,
|
39
|
-
sources: [],
|
40
|
-
isLoading: false,
|
41
|
-
error: null,
|
42
|
-
setSource: () => {},
|
43
|
-
isModalOpen: false,
|
44
|
-
onModalStateChange: () => {},
|
45
|
-
onRetry: () => {},
|
46
|
-
};
|
46
|
+
const props = baseProps;
|
47
47
|
render(<PluginRender render={true} inline={false} {...props} />);
|
48
48
|
|
49
49
|
await waitFor(() => {
|
@@ -52,36 +52,31 @@ describe('Plugin', () => {
|
|
52
52
|
});
|
53
53
|
|
54
54
|
it('Does render ResourceBrowserInlineButton if inline is true', async () => {
|
55
|
-
const props =
|
56
|
-
type: null,
|
57
|
-
modalTitle: 'Asset picker',
|
58
|
-
value: null,
|
59
|
-
isOtherSourceValue: false,
|
60
|
-
onChange: jest.fn(),
|
61
|
-
onClear: jest.fn(),
|
62
|
-
useResource: () => {
|
63
|
-
return {
|
64
|
-
data: null,
|
65
|
-
error: null,
|
66
|
-
isLoading: false,
|
67
|
-
};
|
68
|
-
},
|
69
|
-
plugin: null,
|
70
|
-
pluginMode: null,
|
71
|
-
searchEnabled: false,
|
72
|
-
source: null,
|
73
|
-
sources: [],
|
74
|
-
isLoading: false,
|
75
|
-
error: null,
|
76
|
-
setSource: () => {},
|
77
|
-
isModalOpen: false,
|
78
|
-
onModalStateChange: () => {},
|
79
|
-
onRetry: () => {},
|
80
|
-
};
|
55
|
+
const props = baseProps;
|
81
56
|
render(<PluginRender render={true} inline={true} inlineType="image" {...props} />);
|
82
57
|
|
83
58
|
await waitFor(() => {
|
84
59
|
expect(RBInlineButton.ResourceBrowserInlineButton).toHaveBeenCalledWith({ ...props, inlineType: 'image' }, {});
|
85
60
|
});
|
86
61
|
});
|
62
|
+
|
63
|
+
it('Wraps content in AuthProvider when source requires auth', async () => {
|
64
|
+
const sourceWithAuth = {
|
65
|
+
id: '123',
|
66
|
+
type: 'dam' as ResourceBrowserPluginType,
|
67
|
+
configuration: {
|
68
|
+
authUrl: 'https://example.com/auth',
|
69
|
+
redirectUrl: 'https://example.com/redirect',
|
70
|
+
clientId: 'abc123',
|
71
|
+
scope: 'scope1',
|
72
|
+
},
|
73
|
+
};
|
74
|
+
|
75
|
+
const props = { ...baseProps, source: sourceWithAuth };
|
76
|
+
render(<PluginRender render={true} inline={false} {...props} />);
|
77
|
+
|
78
|
+
await waitFor(() => {
|
79
|
+
expect(AuthContext.AuthProvider).toHaveBeenCalledWith({ authConfig: sourceWithAuth, children: expect.anything() }, {});
|
80
|
+
});
|
81
|
+
});
|
87
82
|
});
|
@@ -0,0 +1,94 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { StoryFn, Meta } from '@storybook/react';
|
3
|
+
import { PluginRender, PluginRenderType } from './Plugin';
|
4
|
+
|
5
|
+
export default {
|
6
|
+
title: 'Plugin renderer',
|
7
|
+
component: PluginRender,
|
8
|
+
} as Meta<typeof PluginRender>;
|
9
|
+
|
10
|
+
const noop = () => {};
|
11
|
+
|
12
|
+
const Template: StoryFn<PluginRenderType> = (args) => <PluginRender {...args} />;
|
13
|
+
|
14
|
+
export const WithoutAuth = Template.bind({});
|
15
|
+
WithoutAuth.args = {
|
16
|
+
render: true,
|
17
|
+
inline: false,
|
18
|
+
type: null,
|
19
|
+
modalTitle: 'Test Plugin (No Auth)',
|
20
|
+
onRetry: noop,
|
21
|
+
useResource: () => ({ data: null, error: null, isLoading: false }),
|
22
|
+
source: {
|
23
|
+
id: 'source-no-auth',
|
24
|
+
type: 'dummy',
|
25
|
+
configuration: {},
|
26
|
+
},
|
27
|
+
};
|
28
|
+
|
29
|
+
export const WithAuth = Template.bind({});
|
30
|
+
WithAuth.args = {
|
31
|
+
render: true,
|
32
|
+
inline: false,
|
33
|
+
type: null,
|
34
|
+
modalTitle: 'Test Plugin (With Auth)',
|
35
|
+
onRetry: noop,
|
36
|
+
useResource: () => ({ data: null, error: null, isLoading: false }),
|
37
|
+
source: {
|
38
|
+
id: 'source-with-auth',
|
39
|
+
type: 'dummy',
|
40
|
+
configuration: {
|
41
|
+
authUrl: 'https://example.com/auth',
|
42
|
+
redirectUrl: 'https://example.com/redirect',
|
43
|
+
clientId: 'client123',
|
44
|
+
scope: 'scope1 scope2',
|
45
|
+
},
|
46
|
+
},
|
47
|
+
};
|
48
|
+
|
49
|
+
export const InlineWithoutAuth = Template.bind({});
|
50
|
+
InlineWithoutAuth.args = {
|
51
|
+
render: true,
|
52
|
+
inline: true,
|
53
|
+
inlineType: 'image',
|
54
|
+
type: null,
|
55
|
+
modalTitle: 'Test Inline Plugin (No Auth)',
|
56
|
+
onRetry: noop,
|
57
|
+
useResource: () => ({ data: null, error: null, isLoading: false }),
|
58
|
+
source: {
|
59
|
+
id: 'inline-source-no-auth',
|
60
|
+
type: 'dummy',
|
61
|
+
configuration: {},
|
62
|
+
},
|
63
|
+
};
|
64
|
+
|
65
|
+
export const InlineWithAuth = Template.bind({});
|
66
|
+
InlineWithAuth.args = {
|
67
|
+
render: true,
|
68
|
+
inline: true,
|
69
|
+
inlineType: 'image',
|
70
|
+
type: null,
|
71
|
+
modalTitle: 'Test Inline Plugin (With Auth)',
|
72
|
+
onRetry: noop,
|
73
|
+
useResource: () => ({ data: null, error: null, isLoading: false }),
|
74
|
+
source: {
|
75
|
+
id: 'inline-source-with-auth',
|
76
|
+
type: 'dummy',
|
77
|
+
configuration: {
|
78
|
+
authUrl: 'https://example.com/auth',
|
79
|
+
redirectUrl: 'https://example.com/redirect',
|
80
|
+
clientId: 'client123',
|
81
|
+
scope: 'scope1 scope2',
|
82
|
+
},
|
83
|
+
},
|
84
|
+
};
|
85
|
+
|
86
|
+
export const NotRendered = Template.bind({});
|
87
|
+
NotRendered.args = {
|
88
|
+
render: false,
|
89
|
+
inline: false,
|
90
|
+
type: null,
|
91
|
+
modalTitle: 'Should Not Render',
|
92
|
+
onRetry: noop,
|
93
|
+
source: null,
|
94
|
+
};
|
package/src/Plugin/Plugin.tsx
CHANGED
@@ -2,7 +2,7 @@ import React from 'react';
|
|
2
2
|
import { ResourceBrowserInput, ResourceBrowserInputProps } from '../ResourceBrowserInput/ResourceBrowserInput';
|
3
3
|
import { ResourceBrowserInlineButton } from '../ResourceBrowserInlineButton/ResourceBrowserInlineButton';
|
4
4
|
import { AuthProvider } from '../ResourceBrowserContext/AuthProvider';
|
5
|
-
import { ResourceBrowserPluginType, InlineType } from '../types';
|
5
|
+
import { ResourceBrowserPluginType, InlineType, ResourceBrowserSourceWithConfig } from '../types';
|
6
6
|
|
7
7
|
/**
|
8
8
|
* This plugin component exsits to deal with React rules of Hooks stupidity.
|
@@ -19,17 +19,12 @@ export type PluginRenderType = ResourceBrowserInputProps & {
|
|
19
19
|
onRetry: () => void;
|
20
20
|
};
|
21
21
|
export const PluginRender = ({ render, inline, inlineType, ...props }: PluginRenderType) => {
|
22
|
-
if (render)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
</AuthProvider>
|
31
|
-
);
|
32
|
-
} else {
|
33
|
-
return <></>;
|
34
|
-
}
|
22
|
+
if (!render) return <></>;
|
23
|
+
|
24
|
+
const requiresAuth = Boolean((props.source as ResourceBrowserSourceWithConfig)?.configuration?.authUrl);
|
25
|
+
|
26
|
+
const content =
|
27
|
+
inline && inlineType ? <ResourceBrowserInlineButton inlineType={inlineType} {...props} /> : <ResourceBrowserInput {...props} />;
|
28
|
+
|
29
|
+
return requiresAuth ? <AuthProvider authConfig={props.source}>{content}</AuthProvider> : content;
|
35
30
|
};
|
@@ -33,7 +33,7 @@ export const ResourceBrowserInlineButton = ({
|
|
33
33
|
onModalStateChange,
|
34
34
|
}: ResourceBrowserInlineButtonProps) => {
|
35
35
|
// If an error happens loading the resource the inline browser just opens without it as if no preselectedResource is provided
|
36
|
-
const { data: resource, isLoading: isResourceLoading } = useResource(value
|
36
|
+
const { data: resource, isLoading: isResourceLoading } = useResource(value || null, source);
|
37
37
|
|
38
38
|
const isImagePicker = inlineType === 'image';
|
39
39
|
|
@@ -16,7 +16,7 @@ export type ResourceBrowserInputProps = {
|
|
16
16
|
allowedTypes?: string[];
|
17
17
|
isDisabled?: boolean;
|
18
18
|
value: ResourceBrowserUnresolvedResource | null;
|
19
|
-
useResource(
|
19
|
+
useResource(reference: ResourceBrowserUnresolvedResource | null, source: ResourceBrowserSource | null): useResolveResourceResponse;
|
20
20
|
onChange(resource: ResourceBrowserResource | null): void;
|
21
21
|
onClear?(): void;
|
22
22
|
plugin: ResourceBrowserPlugin | null;
|
@@ -52,7 +52,7 @@ export const ResourceBrowserInput = ({
|
|
52
52
|
isModalOpen,
|
53
53
|
onModalStateChange,
|
54
54
|
}: ResourceBrowserInputProps) => {
|
55
|
-
const { data: resource, error: resourceError, isLoading: isResourceLoading } = useResource(value
|
55
|
+
const { data: resource, error: resourceError, isLoading: isResourceLoading } = useResource(value || null, source);
|
56
56
|
|
57
57
|
const defaultOnClear = () => onChange(null);
|
58
58
|
const onClearFunction = onClear ?? defaultOnClear;
|
package/src/index.spec.tsx
CHANGED
@@ -222,7 +222,7 @@ describe('Resource browser input', () => {
|
|
222
222
|
});
|
223
223
|
|
224
224
|
await waitFor(() => {
|
225
|
-
expect(mockUseResolveResource).toHaveBeenCalledWith(resource
|
225
|
+
expect(mockUseResolveResource).toHaveBeenCalledWith(resource, calculateExpectedSource(source));
|
226
226
|
});
|
227
227
|
});
|
228
228
|
|
package/src/types.ts
CHANGED
@@ -43,6 +43,7 @@ export type PluginLaunchMode = {
|
|
43
43
|
export type ResourceBrowserUnresolvedResource = {
|
44
44
|
sourceId: string;
|
45
45
|
resourceId: string;
|
46
|
+
[k: string]: unknown; // Additional props as needed by the plugin type to resolve the asset
|
46
47
|
};
|
47
48
|
|
48
49
|
export type ResourceBrowserResource = {
|
@@ -120,5 +121,8 @@ export interface ResourceBrowserPlugin {
|
|
120
121
|
renderSelectedResource: (resource: ResourceBrowserResource) => Promise<ResourceBrowserSelectedState>;
|
121
122
|
|
122
123
|
/** Function to resolve a resource and source id into a fully resolved output reference */
|
123
|
-
useResolveResource: (
|
124
|
+
useResolveResource: (
|
125
|
+
resource: ResourceBrowserUnresolvedResource | null,
|
126
|
+
source: ResourceBrowserSource | null,
|
127
|
+
) => useResolveResourceResponse;
|
124
128
|
}
|