@squiz/resource-browser 1.32.1-alpha.28 → 1.32.1-alpha.30
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/lib/Modal/ModalTrigger.d.ts +2 -1
- package/lib/Modal/ModalTrigger.js +5 -4
- package/lib/PreviewPanel/PreviewPanel.d.ts +0 -1
- package/lib/PreviewPanel/details/MatrixResource.d.ts +0 -1
- package/lib/PreviewPanel/details/MatrixResource.js +2 -17
- package/lib/ResourceBreadcrumb/ResourceBreadcrumb.d.ts +0 -1
- package/lib/ResourceError/ResourceError.d.ts +0 -1
- package/lib/ResourceItem/ResourceItem.d.ts +0 -1
- package/lib/ResourceItem/ResourceItem.js +7 -6
- package/lib/ResourceList/ResourceList.d.ts +0 -1
- package/lib/ResourcePickerContainer/ResourcePickerContainer.d.ts +0 -1
- package/lib/ResourcePickerContainer/ResourcePickerContainer.js +4 -4
- package/lib/Skeleton/List/SkeletonList.d.ts +0 -1
- package/lib/Skeleton/ListItem/SkeletonListItem.d.ts +0 -1
- package/lib/Skeleton/ListItem/SkeletonListItem.js +1 -1
- package/lib/SourceDropdown/SourceDropdown.d.ts +0 -1
- package/lib/SourceDropdown/SourceDropdown.js +5 -5
- package/lib/SourceList/SourceList.d.ts +0 -1
- package/lib/Spinner/Spinner.d.ts +1 -1
- package/lib/Spinner/Spinner.js +1 -1
- package/lib/StatusIndicator/StatusIndicator.d.ts +6 -0
- package/lib/StatusIndicator/StatusIndicator.js +26 -0
- package/lib/index.css +187 -23
- package/lib/index.d.ts +2 -5
- package/lib/index.js +9 -3
- package/package.json +5 -3
- package/src/Icons/Icon.stories.tsx +5 -0
- package/src/Modal/Modal.spec.tsx +25 -0
- package/src/Modal/ModalTrigger.tsx +14 -2
- package/src/PreviewPanel/details/MatrixResource.tsx +2 -22
- package/src/ResourceError/ResourceError.spec.tsx +0 -4
- package/src/ResourceItem/ResourceItem.spec.tsx +0 -4
- package/src/ResourceItem/ResourceItem.tsx +9 -7
- package/src/ResourcePicker/ResetButton.tsx +14 -0
- package/src/ResourcePicker/ResourcePicker.spec.tsx +81 -0
- package/src/ResourcePicker/ResourcePicker.stories.tsx +62 -0
- package/src/ResourcePicker/ResourcePicker.tsx +55 -0
- package/src/ResourcePicker/States/Error.tsx +12 -0
- package/src/ResourcePicker/States/Loading.tsx +9 -0
- package/src/ResourcePicker/States/Selected.tsx +51 -0
- package/src/ResourcePicker/mock-image-resource.json +51 -0
- package/src/ResourcePicker/mock-resource.json +15 -0
- package/src/ResourcePicker/resource-picker.scss +13 -0
- package/src/ResourcePickerContainer/ResourcePickerContainer.stories.tsx +1 -1
- package/src/ResourcePickerContainer/ResourcePickerContainer.tsx +4 -4
- package/src/Skeleton/ListItem/SkeletonListItem.tsx +1 -1
- package/src/Skeleton/_skeleton.scss +15 -0
- package/src/SourceDropdown/SourceDropdown.tsx +5 -7
- package/src/Spinner/Spinner.stories.tsx +2 -2
- package/src/Spinner/Spinner.tsx +2 -2
- package/src/Spinner/_spinner.scss +8 -5
- package/src/StatusIndicator/StatusIndicator.stories.tsx +83 -0
- package/src/StatusIndicator/StatusIndicator.tsx +35 -0
- package/src/index.scss +15 -0
- package/src/index.spec.tsx +44 -0
- package/src/index.stories.tsx +15 -17
- package/src/index.tsx +41 -20
- package/src/types.d.ts +5 -4
@@ -0,0 +1,44 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { render, screen } from '@testing-library/react';
|
3
|
+
import RelatedAssetPicker from './index';
|
4
|
+
|
5
|
+
const mockRequestSources = jest.fn();
|
6
|
+
const mockRequestChildren = jest.fn();
|
7
|
+
const mockRequestResource = jest.fn();
|
8
|
+
const mockChange = jest.fn();
|
9
|
+
|
10
|
+
const defaultProps: any = {
|
11
|
+
modalTitle: 'Asset Picker',
|
12
|
+
allowedTypes: ['site', 'image', 'physical_file'],
|
13
|
+
onRequestSources: mockRequestSources,
|
14
|
+
onRequestChildren: mockRequestChildren,
|
15
|
+
onRequestResource: mockRequestResource,
|
16
|
+
onChange: mockChange,
|
17
|
+
};
|
18
|
+
|
19
|
+
describe('Related Asset Picker', () => {
|
20
|
+
it('should render the related asset picker with the default label', () => {
|
21
|
+
render(<RelatedAssetPicker {...defaultProps} />);
|
22
|
+
const pickerLabel = screen.getByText('Choose asset');
|
23
|
+
|
24
|
+
expect(pickerLabel).toBeInTheDocument();
|
25
|
+
});
|
26
|
+
|
27
|
+
it('should display the generic asset picking icon', () => {
|
28
|
+
render(<RelatedAssetPicker {...defaultProps} />);
|
29
|
+
const pickerLabel = screen.getByText('Choose asset');
|
30
|
+
const pickerIcon = screen.getByTestId('AdsClickRoundedIcon');
|
31
|
+
|
32
|
+
expect(pickerLabel).toBeInTheDocument();
|
33
|
+
expect(pickerIcon).toBeInTheDocument();
|
34
|
+
});
|
35
|
+
|
36
|
+
it('should display the image icon when only images are allowed', () => {
|
37
|
+
render(<RelatedAssetPicker {...defaultProps} allowedTypes={['image']} />);
|
38
|
+
const pickerLabel = screen.getByText('Choose image');
|
39
|
+
const pickerIcon = screen.getByTestId('PhotoLibraryRoundedIcon');
|
40
|
+
|
41
|
+
expect(pickerLabel).toBeInTheDocument();
|
42
|
+
expect(pickerIcon).toBeInTheDocument();
|
43
|
+
});
|
44
|
+
});
|
package/src/index.stories.tsx
CHANGED
@@ -16,32 +16,30 @@ const Template: StoryFn<typeof RelatedAssetPicker> = (props) => {
|
|
16
16
|
});
|
17
17
|
|
18
18
|
return (
|
19
|
-
<
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
<div className="w-[400px] m-3">
|
20
|
+
<RelatedAssetPicker
|
21
|
+
{...props}
|
22
|
+
onRequestSources={onRequestSources}
|
23
|
+
onRequestChildren={onRequestChildren}
|
24
|
+
onRequestResource={onRequestResource}
|
25
|
+
onChange={onChange}
|
26
|
+
/>
|
27
|
+
</div>
|
26
28
|
);
|
27
29
|
};
|
28
30
|
|
29
31
|
export const Primary = Template.bind({});
|
30
32
|
|
31
33
|
Primary.args = {
|
32
|
-
showButtonLabel: false,
|
33
|
-
buttonLabel: 'Open related asset picker',
|
34
|
-
buttonIcon: (
|
35
|
-
<svg width="30" height="30" viewBox="0 0 61 61" fill="none" xmlns="http://www.w3.org/2000/svg">
|
36
|
-
<path
|
37
|
-
d="M29.1 48C24.3 47.75 20.25 45.9 16.95 42.45C13.65 39 12 34.85 12 30C12 25 13.75 20.75 17.25 17.25C20.75 13.75 25 12 30 12C34.85 12 39 13.65 42.45 16.95C45.9 20.25 47.75 24.3 48 29.1L41.7 27.225C41.05 24.525 39.65 22.3125 37.5 20.5875C35.35 18.8625 32.85 18 30 18C26.7 18 23.875 19.175 21.525 21.525C19.175 23.875 18 26.7 18 30C18 32.85 18.8625 35.35 20.5875 37.5C22.3125 39.65 24.525 41.05 27.225 41.7L29.1 48ZM30 60C25.85 60 21.95 59.2125 18.3 57.6375C14.65 56.0625 11.475 53.925 8.775 51.225C6.075 48.525 3.9375 45.35 2.3625 41.7C0.7875 38.05 0 34.15 0 30C0 25.85 0.7875 21.95 2.3625 18.3C3.9375 14.65 6.075 11.475 8.775 8.775C11.475 6.075 14.65 3.9375 18.3 2.3625C21.95 0.7875 25.85 0 30 0C34.15 0 38.05 0.7875 41.7 2.3625C45.35 3.9375 48.525 6.075 51.225 8.775C53.925 11.475 56.0625 14.65 57.6375 18.3C59.2125 21.95 60 25.85 60 30V31.35C60 31.8 59.95 32.25 59.85 32.7L54 30.9V30C54 23.3 51.675 17.625 47.025 12.975C42.375 8.325 36.7 6 30 6C23.3 6 17.625 8.325 12.975 12.975C8.325 17.625 6 23.3 6 30C6 36.7 8.325 42.375 12.975 47.025C17.625 51.675 23.3 54 30 54H30.9L32.7 59.85C32.25 59.95 31.8 60 31.35 60H30ZM54.525 60.45L42.75 48.675L40.5 55.5C40.25 56.2 39.775 56.5375 39.075 56.5125C38.375 56.4875 37.9 56.125 37.65 55.425L30.825 32.7C30.625 32.15 30.75 31.65 31.2 31.2C31.65 30.75 32.15 30.625 32.7 30.825L55.425 37.65C56.125 37.9 56.4875 38.375 56.5125 39.075C56.5375 39.775 56.2 40.25 55.5 40.5L48.675 42.75L60.45 54.525C60.75 54.825 60.9 55.175 60.9 55.575C60.9 55.975 60.75 56.325 60.45 56.625L56.625 60.45C56.325 60.75 55.975 60.9 55.575 60.9C55.175 60.9 54.825 60.75 54.525 60.45Z"
|
38
|
-
fill="#BABABA"
|
39
|
-
/>
|
40
|
-
</svg>
|
41
|
-
),
|
42
34
|
modalTitle: 'Asset Picker',
|
43
35
|
sourceIsLoading: false,
|
44
36
|
resourceIsLoading: false,
|
45
37
|
error: '',
|
46
38
|
allowedTypes: ['site', 'image', 'physical_file'],
|
47
39
|
};
|
40
|
+
|
41
|
+
export const ImagesOnly = Template.bind({});
|
42
|
+
|
43
|
+
ImagesOnly.args = {
|
44
|
+
allowedTypes: ['image'],
|
45
|
+
};
|
package/src/index.tsx
CHANGED
@@ -2,46 +2,67 @@ import React from 'react';
|
|
2
2
|
import ModalTrigger from './Modal/ModalTrigger';
|
3
3
|
import ResourcePickerContainer from './ResourcePickerContainer/ResourcePickerContainer';
|
4
4
|
import { HydratedResourceReference, Resource, ResourceReference, Source } from './types';
|
5
|
+
import AdsClickRoundedIcon from '@mui/icons-material/AdsClickRounded';
|
6
|
+
import AddCircleOutlineRoundedIcon from '@mui/icons-material/AddCircleOutlineRounded';
|
7
|
+
import PhotoLibraryRoundedIcon from '@mui/icons-material/PhotoLibraryRounded';
|
8
|
+
import clsx from 'clsx';
|
9
|
+
// import { LoadingState, ErrorState, SelectedState } from './ResourcePicker/ResourcePicker';
|
5
10
|
|
6
11
|
export type { HydratedResourceReference, Resource, ResourceReference, Source };
|
7
12
|
|
8
13
|
export default function ComponentEditorContentBrowser({
|
9
|
-
showButtonLabel,
|
10
|
-
buttonLabel,
|
11
|
-
buttonIcon,
|
12
14
|
modalTitle,
|
13
15
|
allowedTypes,
|
14
16
|
onRequestSources,
|
15
17
|
onRequestChildren,
|
16
18
|
onChange,
|
19
|
+
isDisabled,
|
17
20
|
}: {
|
18
|
-
showButtonLabel?: boolean;
|
19
|
-
buttonLabel: string;
|
20
|
-
buttonIcon: React.ReactNode;
|
21
21
|
modalTitle: string;
|
22
22
|
allowedTypes: string[] | undefined;
|
23
23
|
onRequestSources: () => Promise<Source[]>;
|
24
24
|
onRequestChildren(source: Source, resource: Resource | null): Promise<Resource[]>;
|
25
25
|
onRequestResource(reference: ResourceReference): Promise<Resource | null>;
|
26
26
|
onChange(resource: HydratedResourceReference | null): void;
|
27
|
+
isDisabled?: boolean;
|
27
28
|
}) {
|
28
|
-
const
|
29
|
-
|
29
|
+
const isImagePicker = allowedTypes && allowedTypes.length === 1 && allowedTypes.includes('image');
|
30
30
|
return (
|
31
31
|
<div className="squiz-rb-scope">
|
32
|
-
<
|
33
|
-
{
|
34
|
-
<
|
35
|
-
|
36
|
-
|
37
|
-
allowedTypes={allowedTypes}
|
38
|
-
onClose={onClose}
|
39
|
-
onRequestSources={onRequestSources}
|
40
|
-
onRequestChildren={onRequestChildren}
|
41
|
-
onChange={onChange}
|
42
|
-
/>
|
32
|
+
<div className={clsx('resource-picker', isDisabled && 'bg-gray-300')}>
|
33
|
+
{isImagePicker ? (
|
34
|
+
<PhotoLibraryRoundedIcon aria-hidden className="w-6 h-6" />
|
35
|
+
) : (
|
36
|
+
<AdsClickRoundedIcon aria-hidden className="w-6 h-6" />
|
43
37
|
)}
|
44
|
-
|
38
|
+
|
39
|
+
<ModalTrigger
|
40
|
+
showLabel={true}
|
41
|
+
label={isImagePicker ? `Choose image` : `Choose asset`}
|
42
|
+
icon={<AddCircleOutlineRoundedIcon aria-hidden className="!w-4 !h-4" />}
|
43
|
+
isDisabled={isDisabled}
|
44
|
+
>
|
45
|
+
{(onClose, titleProps) => (
|
46
|
+
<ResourcePickerContainer
|
47
|
+
title={modalTitle}
|
48
|
+
titleAriaProps={titleProps}
|
49
|
+
allowedTypes={allowedTypes}
|
50
|
+
onClose={onClose}
|
51
|
+
onRequestSources={onRequestSources}
|
52
|
+
onRequestChildren={onRequestChildren}
|
53
|
+
onChange={onChange}
|
54
|
+
/>
|
55
|
+
)}
|
56
|
+
</ModalTrigger>
|
57
|
+
{/* TODO: Add all these states in - examples of them can be found in the Resource Picker story and corresponding file /ResourcePicker/ResourcePicker.tsx */}
|
58
|
+
{/* <div className="resource-picker-info">
|
59
|
+
<div className="resource-picker-info__layout">
|
60
|
+
{isLoading && <LoadingState />}
|
61
|
+
{isError && <ErrorState />}
|
62
|
+
{resource !== null && <SelectedState resource={resource} />}
|
63
|
+
</div>
|
64
|
+
</div> */}
|
65
|
+
</div>
|
45
66
|
</div>
|
46
67
|
);
|
47
68
|
}
|
package/src/types.d.ts
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
import { SquizImageType } from '@squiz/dx-json-schema-lib';
|
2
2
|
|
3
|
+
export type Status = {
|
4
|
+
code: string;
|
5
|
+
name: string;
|
6
|
+
};
|
3
7
|
/**
|
4
8
|
* Represents a resource that has been picked from a source.
|
5
9
|
*/
|
@@ -10,10 +14,7 @@ export type Resource = {
|
|
10
14
|
code: string;
|
11
15
|
name: string;
|
12
16
|
};
|
13
|
-
status:
|
14
|
-
code: string;
|
15
|
-
name: string;
|
16
|
-
};
|
17
|
+
status: Status;
|
17
18
|
url: string;
|
18
19
|
urls: string[];
|
19
20
|
childCount: number;
|