Skip to content

Commit e4e7c4a

Browse files
feat(storage-browser): add type docs, expose handlers, cleanup interfaces, refactor table content (#6473)
* chore(storage-browser): add type definitions and exports (#6409) * fix(storage-browser): address erroneous display text interfaces (#6418) * chore(storage-browser): add useResolveTableData (#6419) * docs(ui-react-storage): add actions doc (#6415) * fix(storage-browser): address interface issues in useAction (#6454) * fix(storage-browser): add DefaultHandlers interface and constant (#6464) * chore(storage-browser): add react-router app, add StorageBrowser examples, add @aws-amplify/ui-test-utils (#6468) * chore(storage-browser): refactor action view table resolution (#6470) * chore: bump react-router-example vite version (#6478) --------- Co-authored-by: AllanZhengYP <[email protected]>
1 parent aac174e commit e4e7c4a

File tree

164 files changed

+5441
-1796
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+5441
-1796
lines changed

.changeset/config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
"@aws-amplify/ui-docs",
1616
"@aws-amplify/ui-e2e",
1717
"@aws-amplify/ui-environments",
18-
"@aws-amplify/ui-next-example",
18+
"@aws-amplify/ui-next-pages-router-example",
19+
"@aws-amplify/ui-next-app-router-example",
1920
"@aws-amplify/ui-react-native-example",
21+
"@aws-amplify/ui-react-router-example",
2022
"@aws-amplify/ui-vue-example"
2123
]
2224
}

.changeset/nasty-brooms-compare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@aws-amplify/ui-react-storage": patch
3+
---
4+
5+
feat(storage-browser): add type docs, expose handlers, cleanup interfaces, refactor table content

.github/dependency-review/config.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
allow-licenses:
22
- '0BSD'
33
- 'Apache-2.0'
4-
- 'Apache-2.0 AND MIT'
54
- 'BlueOak-1.0.0'
65
- 'BSL-1.0'
76
- 'BSD-1-Clause'
@@ -14,12 +13,10 @@ allow-licenses:
1413
- 'CC-BY-3.0'
1514
- 'CC-BY-4.0'
1615
- 'CC0-1.0'
17-
- 'CC0-1.0 AND MIT'
1816
- 'curl'
1917
- 'ISC'
2018
- 'JSON'
2119
- 'MIT'
22-
- 'MIT AND Zlib'
2320
- 'MPL-2.0'
2421
- 'NTP'
2522
- 'OFL-1.0'
@@ -36,3 +33,8 @@ allow-licenses:
3633
- 'X11'
3734
- 'zlib-acknowledgement'
3835
- 'Zlib'
36+
- 'Apache-2.0 AND MIT'
37+
- 'CC0-1.0 AND MIT'
38+
- 'MIT AND Zlib'
39+
- 'ISC AND MIT'
40+
- 'Apache-2.0 AND BSD-2-Clause AND CC0-1.0 AND ISC AND MIT'

docs/src/pages/[platform]/connected-components/storage/storage-browser/examples/Composed.tsx

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,13 @@ function LocationsView() {
3939

4040
const { LocationActionView } = StorageBrowser;
4141

42-
function MyLocationActionView({
43-
type,
44-
onExit,
45-
}: {
46-
type?: string;
47-
onExit: () => void;
48-
}) {
49-
let DialogContent = null;
50-
if (!type) return DialogContent;
42+
function MyLocationActionView() {
43+
const state = useView('LocationDetail');
44+
const onExit = () => {
45+
state.onActionSelect('');
46+
};
5147

52-
switch (type) {
48+
switch (state.actionType) {
5349
case 'copy':
5450
return <ComposedCopyView onExit={onExit} />;
5551
case 'createFolder':
@@ -65,30 +61,25 @@ function MyLocationActionView({
6561

6662
function MyStorageBrowser() {
6763
const state = useView('LocationDetail');
68-
const [currentAction, setCurrentAction] = React.useState<string>();
6964
const ref = React.useRef<HTMLDialogElement>(null);
7065

66+
React.useEffect(() => {
67+
if (state.actionType) {
68+
ref.current?.showModal();
69+
} else {
70+
ref.current?.close();
71+
}
72+
}, [state.actionType]);
73+
7174
if (!state.location.current) {
7275
return <LocationsView />;
7376
}
7477

7578
return (
7679
<>
77-
<StorageBrowser.LocationDetailView
78-
key={currentAction}
79-
onActionSelect={(action) => {
80-
setCurrentAction(action);
81-
ref.current?.showModal();
82-
}}
83-
/>
80+
<StorageBrowser.LocationDetailView />
8481
<dialog ref={ref}>
85-
<MyLocationActionView
86-
type={currentAction}
87-
onExit={() => {
88-
setCurrentAction(undefined);
89-
ref.current?.close();
90-
}}
91-
/>
82+
<MyLocationActionView />
9283
</dialog>
9384
</>
9485
);

docs/src/pages/[platform]/connected-components/storage/storage-browser/examples/Custom.tsx

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@ import { CustomCreateFolderView } from './CustomCreateFolderView';
66
import { CustomUploadView } from './CustomUploadView';
77
import { CustomLocationsView } from './CustomLocationsView';
88

9-
function MyLocationActionView({
10-
type,
11-
onExit,
12-
}: {
13-
type?: string;
14-
onExit: () => void;
15-
}) {
16-
let DialogContent = null;
17-
if (!type) return DialogContent;
9+
function MyLocationActionView() {
10+
const state = useView('LocationDetail');
11+
const onExit = () => {
12+
state.onActionSelect('');
13+
};
1814

19-
switch (type) {
15+
switch (state.actionType) {
2016
case 'copy':
2117
return <CustomCopyView onExit={onExit} />;
2218
case 'createFolder':
@@ -32,31 +28,16 @@ function MyLocationActionView({
3228

3329
function MyStorageBrowser() {
3430
const state = useView('LocationDetail');
35-
const [currentAction, setCurrentAction] = React.useState<string>();
3631

3732
if (!state.location.current) {
3833
return <CustomLocationsView />;
3934
}
4035

41-
if (currentAction) {
42-
return (
43-
<MyLocationActionView
44-
type={currentAction}
45-
onExit={() => {
46-
setCurrentAction(undefined);
47-
}}
48-
/>
49-
);
36+
if (state.actionType) {
37+
return <MyLocationActionView />;
5038
}
5139

52-
return (
53-
<StorageBrowser.LocationDetailView
54-
key={currentAction}
55-
onActionSelect={(action) => {
56-
setCurrentAction(action);
57-
}}
58-
/>
59-
);
40+
return <StorageBrowser.LocationDetailView />;
6041
}
6142

6243
export default function Example() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import React from 'react';
2+
import { createStorageBrowser } from '@aws-amplify/ui-react-storage/browser';
3+
import { Button, Flex, Link, StepperField, Text } from '@aws-amplify/ui-react';
4+
import { generateUrlHandler } from './generateUrlHandler';
5+
import { mockConfig } from './mockConfig'; // IGNORE
6+
import { defaultActions } from './defaultActions'; // IGNORE
7+
8+
const { StorageBrowser, useAction, useView } = createStorageBrowser({
9+
actions: {
10+
default: defaultActions, // IGNORE
11+
custom: {
12+
generateUrl: {
13+
actionListItem: {
14+
icon: 'download',
15+
label: 'Generate Download Links',
16+
disable: (selected) => !selected?.length,
17+
},
18+
handler: generateUrlHandler,
19+
viewName: 'GenerateUrlView',
20+
},
21+
},
22+
},
23+
config: mockConfig, // IGNORE
24+
});
25+
26+
const GenerateUrlView = () => {
27+
const [duration, setDuration] = React.useState(60);
28+
29+
const { onActionExit, fileDataItems } = useView('LocationDetail');
30+
31+
const items = React.useMemo(
32+
() =>
33+
!fileDataItems
34+
? []
35+
: fileDataItems.map((item) => ({ ...item, duration })),
36+
[fileDataItems, duration]
37+
);
38+
39+
const [
40+
// Execution status and result of each task. The status includes 'CANCELED', 'FAILED', 'COMPLETE', 'OVERWRITE_PREVENTED', 'QUEUED', 'PENDING'.
41+
{ tasks },
42+
// Start executing the action against the provided `items`.
43+
handleGenerate,
44+
] = useAction(
45+
// Name of the action.
46+
'generateUrl',
47+
// List of action inputs.
48+
{ items }
49+
);
50+
51+
return (
52+
<Flex direction="column">
53+
<Button onClick={onActionExit}>Exit</Button>
54+
<StepperField
55+
label="Duration"
56+
step={15}
57+
value={duration}
58+
min={15}
59+
max={300}
60+
onStepChange={setDuration}
61+
/>
62+
<Button onClick={() => handleGenerate()}>Start</Button>
63+
{!tasks
64+
? null
65+
: tasks.map(({ data, status, value }) => {
66+
return (
67+
<Flex direction="row" key={data.fileKey}>
68+
<Text>{data.fileKey}</Text>
69+
{value?.link ? <Link href={value.link}>link</Link> : null}
70+
<Text>{status}</Text>
71+
</Flex>
72+
);
73+
})}
74+
</Flex>
75+
);
76+
};
77+
78+
function MyStorageBrowser() {
79+
const state = useView('LocationDetail');
80+
81+
if (!state.location.current) {
82+
return <StorageBrowser.LocationsView />;
83+
} else if (state.actionType === 'generateUrl') {
84+
return <GenerateUrlView />;
85+
} else if (state.actionType) {
86+
return <StorageBrowser.LocationActionView />;
87+
} else {
88+
return <StorageBrowser.LocationDetailView />;
89+
}
90+
}
91+
92+
export default function Example() {
93+
return (
94+
<StorageBrowser.Provider>
95+
<MyStorageBrowser />
96+
</StorageBrowser.Provider>
97+
);
98+
}

docs/src/pages/[platform]/connected-components/storage/storage-browser/examples/defaultActions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { CreateStorageBrowserInput } from '@aws-amplify/ui-react-storage/dist/types/components/StorageBrowser';
21
import {
3-
DeleteHandler,
2+
CreateStorageBrowserInput,
43
DeleteHandlerOutput,
54
UploadHandlerOutput,
6-
} from '@aws-amplify/ui-react-storage/dist/types/components/StorageBrowser/actions';
5+
} from '@aws-amplify/ui-react-storage/browser';
76
import uniqueId from 'lodash/uniqueId';
87

98
export const defaultActions: CreateStorageBrowserInput['actions']['default'] = {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { ActionHandler } from '@aws-amplify/ui-react-storage/browser';
2+
3+
type GenerateLink = ActionHandler<
4+
{ duration: number; fileKey: string },
5+
{ link: string }
6+
>;
7+
8+
export const generateUrlHandler: GenerateLink = ({ data }) => {
9+
const asyncExecution = async () => {
10+
try {
11+
console.log('get url', data.key);
12+
const result = {
13+
status: 'COMPLETE' as const,
14+
value: {
15+
link: URL.createObjectURL(new Blob([`mock file for ${data.key}`])),
16+
},
17+
};
18+
return result;
19+
} catch (error) {
20+
const message = 'Unable to generate link';
21+
return {
22+
status: 'FAILED' as const,
23+
message,
24+
error,
25+
};
26+
}
27+
};
28+
29+
return { result: asyncExecution() };
30+
};

docs/src/pages/[platform]/connected-components/storage/storage-browser/examples/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export { default as DisplayText } from './DisplayText';
77
export { default as Theming } from './Theming';
88
export { default as Icons } from './Icons';
99
export { default as Default } from './Default';
10+
export { default as GenerateUrlViewComposed } from './GenerateUrlViewComposed';

0 commit comments

Comments
 (0)