Skip to content

Commit b4f5b9b

Browse files
authored
Add mocking for file preview (#6679)
* Add mocking for file preview * Fix file preview custom example * Update next config domains * Update mock comment
1 parent c31ce9b commit b4f5b9b

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

docs/next.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ function createRemarkMdxFrontmatterPlugin(options = {}) {
2525
}
2626

2727
module.exports = withNextPluginPreval({
28+
images: {
29+
domains: ['images.unsplash.com'],
30+
},
2831
env: {
2932
BRANCH,
3033
SITE_URL: process.env.SITE_URL,
@@ -205,6 +208,15 @@ module.exports = withNextPluginPreval({
205208
},
206209

207210
webpack(config) {
211+
// Add alias to mock storage-internal for storage browser examples
212+
config.resolve.alias = {
213+
...config.resolve.alias,
214+
'@aws-amplify/storage/internals': path.resolve(
215+
__dirname,
216+
'src/pages/[platform]/connected-components/storage/storage-browser/examples/mockStorageInternal.ts'
217+
),
218+
};
219+
208220
const defaultRehypePlugins = [
209221
// This is a custom plugin that removes lines that end in `// IGNORE`
210222
// This allows us to include code necessary for an example to run

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import Image from 'next/image';
33
import { createStorageBrowser } from '@aws-amplify/ui-react-storage/browser';
44
import { mockConfig } from './mockConfig'; // IGNORE
5+
import { defaultActions } from './defaultActions'; // IGNORE
56

67
const CustomImageRenderer = ({ fileData, url }: any) => (
78
<div style={{ border: '3px solid gray' }}>
@@ -31,6 +32,7 @@ const CustomAudioRenderer = ({ fileData, url }: any) => (
3132

3233
const { StorageBrowser } = createStorageBrowser({
3334
config: mockConfig, // IGNORE
35+
actions: { default: defaultActions }, // IGNORE
3436
filePreview: {
3537
fileTypeResolver: (properties) => {
3638
if (properties.key.endsWith('txt')) return 'text';

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,21 @@ export const defaultActions: CreateStorageBrowserInput['actions']['default'] = {
135135
items: [
136136
{
137137
id: uniqueId(),
138-
key: `${props.prefix}test-file.txt`,
138+
key: `${props.prefix}image-1.jpg`,
139139
lastModified: new Date(),
140140
size: 1008,
141141
type: 'FILE' as const,
142142
},
143143
{
144144
id: uniqueId(),
145-
key: `${props.prefix}test-file2.txt`,
145+
key: `${props.prefix}image-2.jpg`,
146146
lastModified: new Date(),
147147
size: 23456,
148148
type: 'FILE' as const,
149149
},
150150
{
151151
id: uniqueId(),
152-
key: `${props.prefix}test-file3.txt`,
152+
key: `${props.prefix}image-3.jpg`,
153153
lastModified: new Date(),
154154
size: 43456,
155155
type: 'FILE' as const,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Mock implementation of storage-internal getUrl function for documentation examples
2+
export const getUrl = async ({ path }: { path: string }) => {
3+
const filename = path.split('/').pop() || '';
4+
5+
let url: string;
6+
7+
switch (filename) {
8+
case 'image-1.jpg':
9+
url =
10+
'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=2000&h=1333&q=80';
11+
break;
12+
case 'sample.mp4':
13+
url =
14+
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4';
15+
break;
16+
case 'image-3.jpg':
17+
url =
18+
'https://images.unsplash.com/photo-1472214103451-9374bd1c798e?w=2000&h=1333&q=80';
19+
break;
20+
default:
21+
url =
22+
'https://images.unsplash.com/photo-1518837695005-2083093ee35b?w=800&h=600&q=80';
23+
}
24+
25+
const result = { url };
26+
return result;
27+
};
28+
29+
export const copy = () => Promise.resolve();
30+
export const getDataAccess = () => Promise.resolve();
31+
export const list = () => Promise.resolve();
32+
export const listCallerAccessGrants = () => Promise.resolve();
33+
export const listPaths = () => Promise.resolve();
34+
export const remove = () => Promise.resolve();
35+
export const uploadData = () => Promise.resolve();
36+
export const StorageValidationErrorCode = {};
37+
export const assertValidationError = () => {};
38+
export const validationErrorMap = {};

0 commit comments

Comments
 (0)