Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(storage-browser): add react-router app, add StorageBrowser examples, add @aws-amplify/ui-test-utils #6468

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
"@aws-amplify/ui-docs",
"@aws-amplify/ui-e2e",
"@aws-amplify/ui-environments",
"@aws-amplify/ui-next-example",
"@aws-amplify/ui-next-pages-router-example",
"@aws-amplify/ui-next-app-router-example",
"@aws-amplify/ui-react-native-example",
"@aws-amplify/ui-react-router-example",
"@aws-amplify/ui-vue-example"
]
}
8 changes: 5 additions & 3 deletions .github/dependency-review/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
allow-licenses:
- '0BSD'
- 'Apache-2.0'
- 'Apache-2.0 AND MIT'
- 'BlueOak-1.0.0'
- 'BSL-1.0'
- 'BSD-1-Clause'
Expand All @@ -14,12 +13,10 @@ allow-licenses:
- 'CC-BY-3.0'
- 'CC-BY-4.0'
- 'CC0-1.0'
- 'CC0-1.0 AND MIT'
- 'curl'
- 'ISC'
- 'JSON'
- 'MIT'
- 'MIT AND Zlib'
- 'MPL-2.0'
- 'NTP'
- 'OFL-1.0'
Expand All @@ -36,3 +33,8 @@ allow-licenses:
- 'X11'
- 'zlib-acknowledgement'
- 'Zlib'
- 'Apache-2.0 AND MIT'
- 'CC0-1.0 AND MIT'
- 'MIT AND Zlib'
- 'ISC AND MIT'
- 'Apache-2.0 AND BSD-2-Clause AND CC0-1.0 AND ISC AND MIT'
5 changes: 3 additions & 2 deletions examples/next-app-router/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@aws-amplify/ui-next-app-example",
"name": "@aws-amplify/ui-next-app-router-example",
"version": "0.0.1",
"private": true,
"scripts": {
Expand All @@ -10,10 +10,11 @@
},
"dependencies": {
"@aws-amplify/ui-react": "^6.1.0",
"@aws-amplify/ui-react-storage": "^3.8.1",
"react": "^18.3.0",
"next": "^14.2.25",
"react-dom": "^18",
"react-icons": "^4.3.1"
"react-icons": "^5.5.0"
},
"devDependencies": {
"@types/node": "^14.14.31",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<div className="flex w-full flex-row">
<div className="flex-1 p-2">{children}</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use client';

import React from 'react';
import { useRouter, usePathname, useSearchParams } from 'next/navigation';

import { StorageBrowser } from '../storage-browser';

import '@aws-amplify/ui-react-storage/styles.css';

export default function Page() {
const router = useRouter();
const pathname = usePathname();
const params = useSearchParams();

const value = params.get('value');

const handleValueChange = React.useCallback(
(nextValue: any) => {
const nextParams = new URLSearchParams();
nextParams.set('value', JSON.stringify(nextValue));

router.push(`${pathname}?${nextParams.toString()}`);
},
[pathname, router]
);

return (
<StorageBrowser
// @ts-expect-error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, put explanations after expect-error.

onValueChange={handleValueChange}
value={value}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import {
createStorageBrowser,
defaultActionConfigs,
} from '@aws-amplify/ui-react-storage/browser';
import '@aws-amplify/ui-react-storage/styles.css';
import {
MockHandlers,
InitialValues,
} from '@aws-amplify/ui-test-utils/storage-browser';

export const PREFIXES = {
base: 'my-prefix/',
nested: 'my-nested-prefix/',
deeplyNested: 'my-deeply-nested-prefix/',
};

export const INITIAL_VALUES: InitialValues = {
locations: [
{
bucket: 'my-bucket',
id: crypto.randomUUID(),
permissions: ['delete', 'get', 'list', 'write'],
prefix: PREFIXES.base,
type: 'PREFIX',
},
],
locationItems: {
[PREFIXES.base]: [
{
id: crypto.randomUUID(),
key: `${PREFIXES.base}${PREFIXES.nested}`,
type: 'FOLDER',
},
],
[`${PREFIXES.base}${PREFIXES.nested}`]: [
{
id: crypto.randomUUID(),
key: `${PREFIXES.base}${PREFIXES.nested}${PREFIXES.deeplyNested}`,
type: 'FOLDER',
},
],
},
};

const handlers = new MockHandlers({ initialValues: INITIAL_VALUES });

export const { StorageBrowser } = createStorageBrowser({
actions: {
default: {
...defaultActionConfigs,
copy: {
...defaultActionConfigs.copy,
handler: handlers.copy,
},
createFolder: {
...defaultActionConfigs.createFolder,
handler: handlers.createFolder,
},
delete: {
...defaultActionConfigs.delete,
handler: handlers.delete,
},
download: handlers.download,
listLocationItems: handlers.listLocationItems,
upload: {
...defaultActionConfigs.upload,
handler: handlers.upload,
},
},
},
config: {
listLocations: handlers.listLocations,
region: '',
registerAuthListener: () => null,
getLocationCredentials: () =>
Promise.resolve({
credentials: {
accessKeyId: 'accessKeyId',
expiration: new Date(),
secretAccessKey: 'secretAccessKey',
sessionToken: 'sessionToken',
},
}),
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default function Layout({ children }: { children: React.ReactNode }) {

return (
<div {...theme.containerProps({ colorMode })}>
{/* Header */}
<Header>
Amplify UI RSC
<ThemeToggle initialValue={colorMode} />
Expand Down
4 changes: 2 additions & 2 deletions examples/next/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@aws-amplify/ui-next-example",
"name": "@aws-amplify/ui-next-pages-router-example",
"version": "0.0.1",
"private": true,
"scripts": {
Expand All @@ -22,7 +22,7 @@
"react": "^18.3.0",
"react-copy-to-clipboard": "^5.1.0",
"react-dom": "^18.3.0",
"react-icons": "^4.4.0",
"react-icons": "^5.5.0",
"react-map-gl": "7.0.23",
"swr": "^2.0.0"
},
Expand Down
1 change: 1 addition & 0 deletions examples/react-router/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_REACT_SCAN_ENABLED=TRUE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentionally comitted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goes question! Yes, it indicates what .env should look like for enabling react-scan

24 changes: 24 additions & 0 deletions examples/react-router/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
50 changes: 50 additions & 0 deletions examples/react-router/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
});
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react';

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
});
```
28 changes: 28 additions & 0 deletions examples/react-router/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js';
import globals from 'globals';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
);
1 change: 1 addition & 0 deletions examples/react-router/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions examples/react-router/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
33 changes: 33 additions & 0 deletions examples/react-router/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@aws-amplify/ui-react-router-example",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@aws-amplify/ui-react": "6.9.5",
"@aws-amplify/ui-react-storage": "3.9.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^7.1.3"
},
"devDependencies": {
"@eslint/js": "^9.17.0",
"@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5",
"@vitejs/plugin-react": "^4.3.4",
"eslint": "^9.17.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.16",
"globals": "^15.14.0",
"react-scan": "^0.1.3",
"typescript": "~5.6.2",
"typescript-eslint": "^8.18.2",
"vite": "^6.0.5"
}
}
Loading
Loading