|
| 1 | +import React, { useState } from 'react'; |
| 2 | +import { Amplify } from 'aws-amplify'; |
| 3 | + |
| 4 | +import { |
| 5 | + Flex, |
| 6 | + View, |
| 7 | + SelectField, |
| 8 | + Text, |
| 9 | + Alert, |
| 10 | + Tabs, |
| 11 | +} from '@aws-amplify/ui-react'; |
| 12 | +import { StorageBrowser } from '@aws-amplify/ui-react-storage'; |
| 13 | +import { |
| 14 | + createStorageBrowser, |
| 15 | + createAmplifyAuthAdapter, |
| 16 | +} from '@aws-amplify/ui-react-storage/browser'; |
| 17 | +import config from './aws-exports'; |
| 18 | + |
| 19 | +import '@aws-amplify/ui-react-storage/styles.css'; |
| 20 | + |
| 21 | +Amplify.configure(config); |
| 22 | + |
| 23 | +// Create StorageBrowser with composition API |
| 24 | +const { StorageBrowser: ComposableStorageBrowser } = createStorageBrowser({ |
| 25 | + config: createAmplifyAuthAdapter(), |
| 26 | +}); |
| 27 | + |
| 28 | +function PaginationCompositionTest() { |
| 29 | + const [globalPageSize, setGlobalPageSize] = useState<number>(100); |
| 30 | + const [locationsPageSize, setLocationsPageSize] = useState<number>(25); |
| 31 | + const [detailPageSize, setDetailPageSize] = useState<number>(50); |
| 32 | + const [uploadPageSize, setUploadPageSize] = useState<number>(30); |
| 33 | + const [copyPageSize, setCopyPageSize] = useState<number>(20); |
| 34 | + const [deletePageSize, setDeletePageSize] = useState<number>(15); |
| 35 | + const [downloadPageSize, setDownloadPageSize] = useState<number>(25); |
| 36 | + const [showAlert, setShowAlert] = useState(true); |
| 37 | + |
| 38 | + const pageSizeOptions = [ |
| 39 | + { value: 10, label: '10 items' }, |
| 40 | + { value: 20, label: '20 items' }, |
| 41 | + { value: 25, label: '25 items' }, |
| 42 | + { value: 30, label: '30 items' }, |
| 43 | + { value: 50, label: '50 items' }, |
| 44 | + { value: 100, label: '100 items' }, |
| 45 | + { value: 200, label: '200 items' }, |
| 46 | + ]; |
| 47 | + |
| 48 | + return ( |
| 49 | + <Flex direction="column" width="100vw" height="100vh" padding="xl"> |
| 50 | + {showAlert && ( |
| 51 | + <Alert |
| 52 | + variation="info" |
| 53 | + isDismissible |
| 54 | + onDismiss={() => setShowAlert(false)} |
| 55 | + marginBlockEnd="medium" |
| 56 | + > |
| 57 | + <Text> |
| 58 | + <strong>🧪 StorageBrowser Per-View Pagination Test</strong> |
| 59 | + <br /> |
| 60 | + Testing per-view pageSize configuration. Each view can override the |
| 61 | + global pageSize. LocationsView: {locationsPageSize}, |
| 62 | + LocationDetailView: {detailPageSize}, UploadView: {uploadPageSize}, |
| 63 | + CopyView: {copyPageSize}, DeleteView: {deletePageSize}, |
| 64 | + DownloadView: {downloadPageSize}, Global: {globalPageSize} items. |
| 65 | + </Text> |
| 66 | + </Alert> |
| 67 | + )} |
| 68 | + |
| 69 | + <Flex |
| 70 | + justifyContent="space-between" |
| 71 | + alignItems="center" |
| 72 | + marginBlockEnd="xl" |
| 73 | + wrap="wrap" |
| 74 | + gap="medium" |
| 75 | + > |
| 76 | + <Text fontSize="xl" fontWeight="bold"> |
| 77 | + Per-View Pagination Configuration |
| 78 | + </Text> |
| 79 | + |
| 80 | + <Flex alignItems="center" gap="large" wrap="wrap"> |
| 81 | + <Flex alignItems="center" gap="small"> |
| 82 | + <Text fontWeight="bold">Global:</Text> |
| 83 | + <SelectField |
| 84 | + label="" |
| 85 | + value={globalPageSize.toString()} |
| 86 | + onChange={(e) => setGlobalPageSize(parseInt(e.target.value))} |
| 87 | + width="100px" |
| 88 | + > |
| 89 | + {pageSizeOptions.map(({ value, label }) => ( |
| 90 | + <option key={value} value={value}> |
| 91 | + {label} |
| 92 | + </option> |
| 93 | + ))} |
| 94 | + </SelectField> |
| 95 | + </Flex> |
| 96 | + |
| 97 | + <Flex alignItems="center" gap="small"> |
| 98 | + <Text fontWeight="bold">Locations:</Text> |
| 99 | + <SelectField |
| 100 | + label="" |
| 101 | + value={locationsPageSize.toString()} |
| 102 | + onChange={(e) => setLocationsPageSize(parseInt(e.target.value))} |
| 103 | + width="100px" |
| 104 | + > |
| 105 | + {pageSizeOptions.map(({ value, label }) => ( |
| 106 | + <option key={value} value={value}> |
| 107 | + {label} |
| 108 | + </option> |
| 109 | + ))} |
| 110 | + </SelectField> |
| 111 | + </Flex> |
| 112 | + |
| 113 | + <Flex alignItems="center" gap="small"> |
| 114 | + <Text fontWeight="bold">Detail:</Text> |
| 115 | + <SelectField |
| 116 | + label="" |
| 117 | + value={detailPageSize.toString()} |
| 118 | + onChange={(e) => setDetailPageSize(parseInt(e.target.value))} |
| 119 | + width="100px" |
| 120 | + > |
| 121 | + {pageSizeOptions.map(({ value, label }) => ( |
| 122 | + <option key={value} value={value}> |
| 123 | + {label} |
| 124 | + </option> |
| 125 | + ))} |
| 126 | + </SelectField> |
| 127 | + </Flex> |
| 128 | + |
| 129 | + <Flex alignItems="center" gap="small"> |
| 130 | + <Text fontWeight="bold">Upload:</Text> |
| 131 | + <SelectField |
| 132 | + label="" |
| 133 | + value={uploadPageSize.toString()} |
| 134 | + onChange={(e) => setUploadPageSize(parseInt(e.target.value))} |
| 135 | + width="100px" |
| 136 | + > |
| 137 | + {pageSizeOptions.map(({ value, label }) => ( |
| 138 | + <option key={value} value={value}> |
| 139 | + {label} |
| 140 | + </option> |
| 141 | + ))} |
| 142 | + </SelectField> |
| 143 | + </Flex> |
| 144 | + |
| 145 | + <Flex alignItems="center" gap="small"> |
| 146 | + <Text fontWeight="bold">Copy:</Text> |
| 147 | + <SelectField |
| 148 | + label="" |
| 149 | + value={copyPageSize.toString()} |
| 150 | + onChange={(e) => setCopyPageSize(parseInt(e.target.value))} |
| 151 | + width="100px" |
| 152 | + > |
| 153 | + {pageSizeOptions.map(({ value, label }) => ( |
| 154 | + <option key={value} value={value}> |
| 155 | + {label} |
| 156 | + </option> |
| 157 | + ))} |
| 158 | + </SelectField> |
| 159 | + </Flex> |
| 160 | + |
| 161 | + <Flex alignItems="center" gap="small"> |
| 162 | + <Text fontWeight="bold">Delete:</Text> |
| 163 | + <SelectField |
| 164 | + label="" |
| 165 | + value={deletePageSize.toString()} |
| 166 | + onChange={(e) => setDeletePageSize(parseInt(e.target.value))} |
| 167 | + width="100px" |
| 168 | + > |
| 169 | + {pageSizeOptions.map(({ value, label }) => ( |
| 170 | + <option key={value} value={value}> |
| 171 | + {label} |
| 172 | + </option> |
| 173 | + ))} |
| 174 | + </SelectField> |
| 175 | + </Flex> |
| 176 | + |
| 177 | + <Flex alignItems="center" gap="small"> |
| 178 | + <Text fontWeight="bold">Download:</Text> |
| 179 | + <SelectField |
| 180 | + label="" |
| 181 | + value={downloadPageSize.toString()} |
| 182 | + onChange={(e) => setDownloadPageSize(parseInt(e.target.value))} |
| 183 | + width="100px" |
| 184 | + > |
| 185 | + {pageSizeOptions.map(({ value, label }) => ( |
| 186 | + <option key={value} value={value}> |
| 187 | + {label} |
| 188 | + </option> |
| 189 | + ))} |
| 190 | + </SelectField> |
| 191 | + </Flex> |
| 192 | + </Flex> |
| 193 | + </Flex> |
| 194 | + |
| 195 | + <Tabs |
| 196 | + defaultValue="composition" |
| 197 | + items={[ |
| 198 | + { |
| 199 | + label: 'Composition Mode', |
| 200 | + value: 'composition', |
| 201 | + content: ( |
| 202 | + <View height="100%" overflow="auto"> |
| 203 | + <ComposableStorageBrowser.Provider |
| 204 | + key={`${globalPageSize}-${locationsPageSize}-${detailPageSize}-${uploadPageSize}-${copyPageSize}-${deletePageSize}-${downloadPageSize}`} |
| 205 | + pageSize={globalPageSize} |
| 206 | + > |
| 207 | + <ComposableStorageBrowser.LocationsView |
| 208 | + pageSize={locationsPageSize} |
| 209 | + /> |
| 210 | + <ComposableStorageBrowser.LocationDetailView |
| 211 | + pageSize={detailPageSize} |
| 212 | + /> |
| 213 | + <ComposableStorageBrowser.UploadView |
| 214 | + pageSize={uploadPageSize} |
| 215 | + /> |
| 216 | + <ComposableStorageBrowser.CopyView pageSize={copyPageSize} /> |
| 217 | + <ComposableStorageBrowser.DeleteView |
| 218 | + pageSize={deletePageSize} |
| 219 | + /> |
| 220 | + <ComposableStorageBrowser.DownloadView |
| 221 | + pageSize={downloadPageSize} |
| 222 | + /> |
| 223 | + </ComposableStorageBrowser.Provider> |
| 224 | + </View> |
| 225 | + ), |
| 226 | + }, |
| 227 | + { |
| 228 | + label: 'Standard Mode', |
| 229 | + value: 'standard', |
| 230 | + content: ( |
| 231 | + <View height="600px" overflow="auto"> |
| 232 | + <StorageBrowser |
| 233 | + key={globalPageSize} |
| 234 | + pageSize={globalPageSize} |
| 235 | + displayText={{ |
| 236 | + LocationsView: { |
| 237 | + title: `Standard StorageBrowser - ${globalPageSize} items per page (all views)`, |
| 238 | + }, |
| 239 | + }} |
| 240 | + /> |
| 241 | + </View> |
| 242 | + ), |
| 243 | + }, |
| 244 | + ]} |
| 245 | + /> |
| 246 | + </Flex> |
| 247 | + ); |
| 248 | +} |
| 249 | + |
| 250 | +export default PaginationCompositionTest; |
0 commit comments