@squiz/resource-browser 1.32.1-alpha.14 → 1.32.1-alpha.16
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/jest.config.ts +12 -1
- package/lib/Hooks/useCategorisedSources.d.ts +14 -0
- package/lib/Hooks/useCategorisedSources.js +38 -0
- package/lib/Hooks/useChildResources.d.ts +19 -0
- package/lib/Hooks/useChildResources.js +35 -0
- package/lib/Hooks/useResourcePath.d.ts +16 -0
- package/lib/Hooks/useResourcePath.js +64 -0
- package/lib/Hooks/useSources.d.ts +16 -0
- package/lib/Hooks/useSources.js +29 -0
- package/lib/Icons/Icon.d.ts +7 -7
- package/lib/Icons/Icon.js +7 -9
- package/lib/Icons/MatrixResources/Audio.js +1 -1
- package/lib/Icons/MatrixResources/Excel.js +1 -1
- package/lib/Icons/MatrixResources/MatrixResourceMap.d.ts +6 -6
- package/lib/Icons/MatrixResources/MatrixResourceMap.js +6 -6
- package/lib/Icons/MatrixResources/Pdf.js +1 -1
- package/lib/Icons/MatrixResources/Powerpoint.js +1 -1
- package/lib/Icons/MatrixResources/Video.js +1 -1
- package/lib/Icons/MatrixResources/Word.js +1 -1
- package/lib/Modal/Modal.js +1 -1
- package/lib/PreviewPanel/PreviewModal.js +1 -1
- package/lib/PreviewPanel/PreviewPanel.d.ts +4 -6
- package/lib/PreviewPanel/PreviewPanel.js +11 -39
- package/lib/PreviewPanel/details/MatrixResource.d.ts +4 -9
- package/lib/PreviewPanel/details/MatrixResource.js +20 -16
- package/lib/ResourceBreadcrumb/ResourceBreadcrumb.d.ts +5 -5
- package/lib/ResourceBreadcrumb/ResourceBreadcrumb.js +3 -3
- package/lib/ResourceItem/ResourceItem.d.ts +6 -8
- package/lib/ResourceItem/ResourceItem.js +3 -3
- package/lib/ResourceList/ResourceList.d.ts +5 -4
- package/lib/ResourceList/ResourceList.js +3 -3
- package/lib/ResourcePickerContainer/ResourcePickerContainer.d.ts +4 -5
- package/lib/ResourcePickerContainer/ResourcePickerContainer.js +34 -89
- package/lib/SourceDropdown/SourceDropdown.d.ts +5 -5
- package/lib/SourceDropdown/SourceDropdown.js +19 -27
- package/lib/SourceList/SourceList.d.ts +4 -4
- package/lib/SourceList/SourceList.js +7 -5
- package/lib/index.css +6 -0
- package/lib/index.d.ts +6 -29
- package/lib/index.js +2 -3
- package/lib/uuid.js +1 -3
- package/package.json +3 -2
- package/src/Hooks/useCategorisedSources.spec.ts +39 -0
- package/src/Hooks/useCategorisedSources.ts +46 -0
- package/src/Hooks/useChildResources.spec.ts +49 -0
- package/src/Hooks/useChildResources.ts +43 -0
- package/src/Hooks/useResourcePath.spec.ts +124 -0
- package/src/Hooks/useResourcePath.ts +76 -0
- package/src/Hooks/useSources.spec.ts +33 -0
- package/src/Hooks/useSources.ts +33 -0
- package/src/Icons/Icon.stories.tsx +7 -7
- package/src/Icons/Icon.tsx +9 -14
- package/src/Icons/MatrixResources/Audio.tsx +1 -1
- package/src/Icons/MatrixResources/Excel.tsx +1 -1
- package/src/Icons/MatrixResources/MatrixResourceMap.ts +7 -7
- package/src/Icons/MatrixResources/Pdf.tsx +1 -1
- package/src/Icons/MatrixResources/Powerpoint.tsx +1 -1
- package/src/Icons/MatrixResources/Video.tsx +1 -1
- package/src/Icons/MatrixResources/Word.tsx +1 -1
- package/src/Modal/Modal.tsx +1 -1
- package/src/PreviewPanel/PreviewModal.tsx +1 -1
- package/src/PreviewPanel/PreviewPanel.spec.tsx +20 -62
- package/src/PreviewPanel/PreviewPanel.stories.tsx +16 -24
- package/src/PreviewPanel/PreviewPanel.tsx +15 -51
- package/src/PreviewPanel/details/MatrixResource.tsx +23 -19
- package/src/ResourceBreadcrumb/ResourceBreadcrumb.spec.tsx +13 -23
- package/src/ResourceBreadcrumb/ResourceBreadcrumb.stories.tsx +1 -1
- package/src/ResourceBreadcrumb/ResourceBreadcrumb.tsx +8 -9
- package/src/ResourceBreadcrumb/sample-hierarchy.json +15 -25
- package/src/ResourceItem/ResourceItem.tsx +10 -12
- package/src/ResourceList/ResourceList.spec.tsx +8 -53
- package/src/ResourceList/ResourceList.stories.tsx +2 -2
- package/src/ResourceList/ResourceList.tsx +12 -10
- package/src/ResourceList/sample-resources.json +551 -49
- package/src/ResourcePickerContainer/ResourcePickerContainer.spec.tsx +196 -315
- package/src/ResourcePickerContainer/ResourcePickerContainer.stories.tsx +7 -29
- package/src/ResourcePickerContainer/ResourcePickerContainer.tsx +63 -127
- package/src/SourceDropdown/SourceDropdown.spec.tsx +63 -60
- package/src/SourceDropdown/SourceDropdown.stories.tsx +4 -7
- package/src/SourceDropdown/SourceDropdown.tsx +34 -41
- package/src/SourceList/SourceList.spec.tsx +38 -32
- package/src/SourceList/SourceList.tsx +17 -19
- package/src/SourceList/sample-sources.json +186 -77
- package/src/__mocks__/MockModels.ts +30 -0
- package/src/__mocks__/StorybookHelpers.ts +46 -0
- package/src/index.stories.tsx +13 -38
- package/src/index.tsx +5 -29
- package/src/types.d.ts +71 -0
- package/src/uuid.ts +2 -4
- package/src/SourceDropdown/sample-sources.json +0 -110
@@ -0,0 +1,46 @@
|
|
1
|
+
import sampleSources from '../SourceList/sample-sources.json';
|
2
|
+
import { HydratedResourceReference, Resource, Source } from '../types';
|
3
|
+
import sampleResources from '../ResourceList/sample-resources.json';
|
4
|
+
|
5
|
+
type CreateCallbacksProps = Partial<{
|
6
|
+
delay: number;
|
7
|
+
sourceIsLoading: boolean;
|
8
|
+
resourceIsLoading: boolean;
|
9
|
+
}>;
|
10
|
+
|
11
|
+
export const createResourceBrowserCallbacks = ({
|
12
|
+
delay = 500,
|
13
|
+
sourceIsLoading = false,
|
14
|
+
resourceIsLoading = false,
|
15
|
+
}: CreateCallbacksProps = {}) => {
|
16
|
+
return {
|
17
|
+
onRequestSources: () => {
|
18
|
+
return new Promise((resolve) => {
|
19
|
+
if (!sourceIsLoading) {
|
20
|
+
setTimeout(resolve, delay, sampleSources);
|
21
|
+
}
|
22
|
+
});
|
23
|
+
},
|
24
|
+
onRequestChildren: (source: Source, resource: Resource | null) => {
|
25
|
+
return new Promise((resolve) => {
|
26
|
+
if (!resourceIsLoading) {
|
27
|
+
const children = resource ? (((resource as any)?._children || []) as Resource[]) : sampleResources;
|
28
|
+
|
29
|
+
setTimeout(resolve, delay, children);
|
30
|
+
}
|
31
|
+
});
|
32
|
+
},
|
33
|
+
onRequestResource: () => {
|
34
|
+
return new Promise((resolve) => {
|
35
|
+
if (!resourceIsLoading) {
|
36
|
+
setTimeout(resolve, delay, sampleResources[0]);
|
37
|
+
}
|
38
|
+
});
|
39
|
+
},
|
40
|
+
onChange: ({ resource, source }: HydratedResourceReference) => {
|
41
|
+
alert(
|
42
|
+
`Resource Browser has selected resource #${resource.id} (${resource.name}) from source #${source.id} (${source.name}).`,
|
43
|
+
);
|
44
|
+
},
|
45
|
+
};
|
46
|
+
};
|
package/src/index.stories.tsx
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
import { StoryFn, Meta } from '@storybook/react';
|
2
|
-
|
3
|
-
import
|
4
|
-
import sampleSources from './SourceList/sample-sources.json';
|
5
|
-
import sampleResources from './ResourceList/sample-resources.json';
|
2
|
+
import RelatedAssetPicker from './index';
|
3
|
+
import { createResourceBrowserCallbacks } from './__mocks__/StorybookHelpers';
|
6
4
|
|
7
5
|
export default {
|
8
6
|
title: 'RelatedAssetPicker',
|
@@ -10,41 +8,19 @@ export default {
|
|
10
8
|
} as Meta<typeof RelatedAssetPicker>;
|
11
9
|
|
12
10
|
const Template: StoryFn<typeof RelatedAssetPicker> = (props) => {
|
13
|
-
const { sourceIsLoading, resourceIsLoading
|
11
|
+
const { sourceIsLoading, resourceIsLoading } = props;
|
12
|
+
const { onRequestSources, onRequestChildren, onRequestResource, onChange } = createResourceBrowserCallbacks({
|
13
|
+
sourceIsLoading: !!sourceIsLoading,
|
14
|
+
resourceIsLoading: !!resourceIsLoading,
|
15
|
+
});
|
16
|
+
|
14
17
|
return (
|
15
18
|
<RelatedAssetPicker
|
16
19
|
{...props}
|
17
|
-
onRequestSources={
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
22
|
-
});
|
23
|
-
}}
|
24
|
-
onRequestChildren={() => {
|
25
|
-
return new Promise((resolve) => {
|
26
|
-
if (!resourceIsLoading) {
|
27
|
-
setTimeout(resolve, 500, sampleResources);
|
28
|
-
}
|
29
|
-
});
|
30
|
-
}}
|
31
|
-
onRequestResource={() => {
|
32
|
-
return new Promise((resolve) => {
|
33
|
-
if (!detailsIsLoading) {
|
34
|
-
setTimeout(resolve, 500, {
|
35
|
-
type: 'page',
|
36
|
-
name: 'Products',
|
37
|
-
properties: new Map([
|
38
|
-
['assetId', '12345'],
|
39
|
-
['status', 'UnderConstruction'],
|
40
|
-
]),
|
41
|
-
});
|
42
|
-
}
|
43
|
-
});
|
44
|
-
}}
|
45
|
-
onChange={(nodeId: NodeIdentifier) => {
|
46
|
-
alert(`Resource Browser has selected ${nodeId.source} ${nodeId.id}`);
|
47
|
-
}}
|
20
|
+
onRequestSources={onRequestSources}
|
21
|
+
onRequestChildren={onRequestChildren}
|
22
|
+
onRequestResource={onRequestResource}
|
23
|
+
onChange={onChange}
|
48
24
|
/>
|
49
25
|
);
|
50
26
|
};
|
@@ -65,6 +41,5 @@ Primary.args = {
|
|
65
41
|
modalTitle: 'Asset Picker',
|
66
42
|
sourceIsLoading: false,
|
67
43
|
resourceIsLoading: false,
|
68
|
-
|
69
|
-
allowedTypes: ['site', 'image'],
|
44
|
+
allowedTypes: ['site', 'image', 'physical_file'],
|
70
45
|
};
|
package/src/index.tsx
CHANGED
@@ -1,31 +1,9 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
|
3
|
-
// import { ResourceBrowserInternalContext } from './InternalContext/InternalContext';
|
4
2
|
import ModalTrigger from './Modal/ModalTrigger';
|
5
3
|
import ResourcePickerContainer from './ResourcePickerContainer/ResourcePickerContainer';
|
4
|
+
import { HydratedResourceReference, Resource, ResourceReference, Source } from './types';
|
6
5
|
|
7
|
-
export type
|
8
|
-
export type ResourceDetail = {
|
9
|
-
type: string;
|
10
|
-
name: string;
|
11
|
-
properties: Map<string, any>;
|
12
|
-
};
|
13
|
-
export type Resource = {
|
14
|
-
id: NodeIdentifier;
|
15
|
-
type: string;
|
16
|
-
selected: boolean;
|
17
|
-
label: string;
|
18
|
-
childCount: number;
|
19
|
-
};
|
20
|
-
export type Source = {
|
21
|
-
id: string;
|
22
|
-
name: string;
|
23
|
-
nodes: Array<Resource>;
|
24
|
-
};
|
25
|
-
export type Hierarchy = {
|
26
|
-
id: NodeIdentifier;
|
27
|
-
label: string;
|
28
|
-
};
|
6
|
+
export type { HydratedResourceReference, Resource, ResourceReference, Source };
|
29
7
|
|
30
8
|
export default function ComponentEditorContentBrowser({
|
31
9
|
showButtonLabel,
|
@@ -35,7 +13,6 @@ export default function ComponentEditorContentBrowser({
|
|
35
13
|
allowedTypes,
|
36
14
|
onRequestSources,
|
37
15
|
onRequestChildren,
|
38
|
-
onRequestResource,
|
39
16
|
onChange,
|
40
17
|
}: {
|
41
18
|
showButtonLabel?: boolean;
|
@@ -44,9 +21,9 @@ export default function ComponentEditorContentBrowser({
|
|
44
21
|
modalTitle: string;
|
45
22
|
allowedTypes: string[] | undefined;
|
46
23
|
onRequestSources: () => Promise<Source[]>;
|
47
|
-
onRequestChildren(
|
48
|
-
onRequestResource(
|
49
|
-
onChange(resource:
|
24
|
+
onRequestChildren(source: Source, resource: Resource | null): Promise<Resource[]>;
|
25
|
+
onRequestResource(reference: ResourceReference): Promise<Resource | null>;
|
26
|
+
onChange(resource: HydratedResourceReference | null): void;
|
50
27
|
}) {
|
51
28
|
const showLabel = showButtonLabel || false;
|
52
29
|
|
@@ -61,7 +38,6 @@ export default function ComponentEditorContentBrowser({
|
|
61
38
|
onClose={onClose}
|
62
39
|
onRequestSources={onRequestSources}
|
63
40
|
onRequestChildren={onRequestChildren}
|
64
|
-
onRequestResource={onRequestResource}
|
65
41
|
onChange={onChange}
|
66
42
|
/>
|
67
43
|
)}
|
package/src/types.d.ts
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
import { SquizImageType } from '@squiz/dx-json-schema-lib';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Represents a resource that has been picked from a source.
|
5
|
+
*/
|
6
|
+
export type Resource = {
|
7
|
+
id: string;
|
8
|
+
name: string;
|
9
|
+
type: {
|
10
|
+
code: string;
|
11
|
+
name: string;
|
12
|
+
};
|
13
|
+
status: {
|
14
|
+
code: string;
|
15
|
+
name: string;
|
16
|
+
};
|
17
|
+
url: string;
|
18
|
+
urls: string[];
|
19
|
+
childCount: number;
|
20
|
+
squizImage?: SquizImageType['__shape__'];
|
21
|
+
};
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Represents a system that resources can be picked from.
|
25
|
+
* Optionally, may indicate a list of "nodes" that can be used to scope the source to a subset of its resources.
|
26
|
+
*/
|
27
|
+
export type Source = {
|
28
|
+
id: string;
|
29
|
+
name: string;
|
30
|
+
nodes: Resource[];
|
31
|
+
};
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Represents a source that has been optionally scoped to one of its "nodes".
|
35
|
+
*/
|
36
|
+
export type ScopedSource = {
|
37
|
+
source: Source;
|
38
|
+
resource: Resource | null;
|
39
|
+
};
|
40
|
+
|
41
|
+
/**
|
42
|
+
* A non-hydrated resource reference.
|
43
|
+
*/
|
44
|
+
export type ResourceReference = { source: string; resource: string };
|
45
|
+
|
46
|
+
/**
|
47
|
+
* A hydrated resource reference.
|
48
|
+
*/
|
49
|
+
export type HydratedResourceReference = { source: Source; resource: Resource };
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Represents the hierarchy within the asset picker.
|
53
|
+
* Within the picker T will be ScopedSource|Resource.
|
54
|
+
* ScopedSource will be the first item in the array, Resource will be every other item.
|
55
|
+
*/
|
56
|
+
export type Hierarchy<T> = Array<{
|
57
|
+
key: string;
|
58
|
+
label: string;
|
59
|
+
node: T;
|
60
|
+
}>;
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Augments a type so that all properties are optional.
|
64
|
+
*/
|
65
|
+
type DeepPartial<T> = {
|
66
|
+
[P in keyof T]?: T[P] extends Array<infer U>
|
67
|
+
? Array<DeepPartial<U>>
|
68
|
+
: T[P] extends ReadonlyArray<infer U>
|
69
|
+
? ReadonlyArray<DeepPartial<U>>
|
70
|
+
: DeepPartial<T[P]>;
|
71
|
+
};
|
package/src/uuid.ts
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2
|
-
// @ts-nocheck
|
3
1
|
export default function uuid(): string {
|
4
|
-
return
|
5
|
-
(c ^ (window.crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16),
|
2
|
+
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) =>
|
3
|
+
(Number(c) ^ (window.crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (Number(c) / 4)))).toString(16),
|
6
4
|
);
|
7
5
|
}
|
@@ -1,110 +0,0 @@
|
|
1
|
-
[
|
2
|
-
{
|
3
|
-
"id": "1",
|
4
|
-
"name": "Acme corporate system",
|
5
|
-
"nodes": [
|
6
|
-
{
|
7
|
-
"id": {
|
8
|
-
"id": "1",
|
9
|
-
"source": "1"
|
10
|
-
},
|
11
|
-
"type": "site",
|
12
|
-
"selected": false,
|
13
|
-
"label": "HandyHomes Website very long wrapping name",
|
14
|
-
"childCount": 21
|
15
|
-
},
|
16
|
-
{
|
17
|
-
"id": {
|
18
|
-
"id": "2",
|
19
|
-
"source": "1"
|
20
|
-
},
|
21
|
-
"type": "site",
|
22
|
-
"selected": false,
|
23
|
-
"label": "Another Website",
|
24
|
-
"childCount": 13
|
25
|
-
}
|
26
|
-
]
|
27
|
-
},
|
28
|
-
{
|
29
|
-
"id": "2",
|
30
|
-
"name": "Acme internal system",
|
31
|
-
"nodes": [
|
32
|
-
{
|
33
|
-
"id": {
|
34
|
-
"id": "1",
|
35
|
-
"source": "2"
|
36
|
-
},
|
37
|
-
"type": "site",
|
38
|
-
"selected": false,
|
39
|
-
"label": "Intranet Website",
|
40
|
-
"childCount": 15
|
41
|
-
},
|
42
|
-
{
|
43
|
-
"id": {
|
44
|
-
"id": "2",
|
45
|
-
"source": "2"
|
46
|
-
},
|
47
|
-
"type": "site",
|
48
|
-
"selected": false,
|
49
|
-
"label": "Social Website",
|
50
|
-
"childCount": 10
|
51
|
-
}
|
52
|
-
]
|
53
|
-
},
|
54
|
-
{
|
55
|
-
"id": "3",
|
56
|
-
"name": "Other system",
|
57
|
-
"nodes": [
|
58
|
-
{
|
59
|
-
"id": {
|
60
|
-
"id": "1",
|
61
|
-
"source": "3"
|
62
|
-
},
|
63
|
-
"type": "folder",
|
64
|
-
"selected": false,
|
65
|
-
"label": "Digital asset manager",
|
66
|
-
"childCount": 0
|
67
|
-
},
|
68
|
-
{
|
69
|
-
"id": {
|
70
|
-
"id": "2",
|
71
|
-
"source": "3"
|
72
|
-
},
|
73
|
-
"type": "image",
|
74
|
-
"selected": false,
|
75
|
-
"label": "Unsplash image library",
|
76
|
-
"childCount": 0
|
77
|
-
},
|
78
|
-
{
|
79
|
-
"id": {
|
80
|
-
"id": "3",
|
81
|
-
"source": "3"
|
82
|
-
},
|
83
|
-
"type": "image",
|
84
|
-
"selected": false,
|
85
|
-
"label": "Unsplash image library",
|
86
|
-
"childCount": 0
|
87
|
-
},
|
88
|
-
{
|
89
|
-
"id": {
|
90
|
-
"id": "4",
|
91
|
-
"source": "3"
|
92
|
-
},
|
93
|
-
"type": "image",
|
94
|
-
"selected": false,
|
95
|
-
"label": "Unsplash image library",
|
96
|
-
"childCount": 0
|
97
|
-
},
|
98
|
-
{
|
99
|
-
"id": {
|
100
|
-
"id": "5",
|
101
|
-
"source": "3"
|
102
|
-
},
|
103
|
-
"type": "image",
|
104
|
-
"selected": false,
|
105
|
-
"label": "Unsplash image library",
|
106
|
-
"childCount": 0
|
107
|
-
}
|
108
|
-
]
|
109
|
-
}
|
110
|
-
]
|