Update frontend/src/pages/Repository.jsx
Browse files
frontend/src/pages/Repository.jsx
CHANGED
|
@@ -106,7 +106,7 @@ export default function Repository() {
|
|
| 106 |
const [uploadProductCategory, setUploadProductCategory] = useState('');
|
| 107 |
const [uploadSubCategory, setUploadSubCategory] = useState('');
|
| 108 |
const [isUploading, setIsUploading] = useState(false);
|
| 109 |
-
const [assets, setAssets] = useState(
|
| 110 |
const [isLoadingAssets, setIsLoadingAssets] = useState(false);
|
| 111 |
const [previewAsset, setPreviewAsset] = useState(null);
|
| 112 |
const [previewDialogOpen, setPreviewDialogOpen] = useState(false);
|
|
@@ -159,23 +159,32 @@ export default function Repository() {
|
|
| 159 |
const data = await response.json();
|
| 160 |
// Convert API response to match mockAssets format
|
| 161 |
// IMPORTANT: Keep IDs as strings to preserve precision for large CockroachDB IDs
|
| 162 |
-
const formattedAssets = data
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
setAssets(formattedAssets);
|
| 172 |
} else {
|
| 173 |
console.error('Failed to fetch assets');
|
| 174 |
-
//
|
|
|
|
| 175 |
}
|
| 176 |
} catch (error) {
|
| 177 |
console.error('Error fetching assets:', error);
|
| 178 |
-
//
|
|
|
|
| 179 |
} finally {
|
| 180 |
setIsLoadingAssets(false);
|
| 181 |
}
|
|
|
|
| 106 |
const [uploadProductCategory, setUploadProductCategory] = useState('');
|
| 107 |
const [uploadSubCategory, setUploadSubCategory] = useState('');
|
| 108 |
const [isUploading, setIsUploading] = useState(false);
|
| 109 |
+
const [assets, setAssets] = useState([]);
|
| 110 |
const [isLoadingAssets, setIsLoadingAssets] = useState(false);
|
| 111 |
const [previewAsset, setPreviewAsset] = useState(null);
|
| 112 |
const [previewDialogOpen, setPreviewDialogOpen] = useState(false);
|
|
|
|
| 159 |
const data = await response.json();
|
| 160 |
// Convert API response to match mockAssets format
|
| 161 |
// IMPORTANT: Keep IDs as strings to preserve precision for large CockroachDB IDs
|
| 162 |
+
const formattedAssets = data
|
| 163 |
+
.map(asset => ({
|
| 164 |
+
id: String(asset.id), // Explicitly convert to string to preserve precision
|
| 165 |
+
name: asset.name,
|
| 166 |
+
type: asset.file_type,
|
| 167 |
+
product: asset.product_category,
|
| 168 |
+
subCategory: asset.sub_category,
|
| 169 |
+
size: formatFileSize(asset.size),
|
| 170 |
+
date: asset.created_at ? new Date(asset.created_at).toISOString().split('T')[0] : new Date().toISOString().split('T')[0]
|
| 171 |
+
}))
|
| 172 |
+
.filter(asset => {
|
| 173 |
+
// Filter out mock assets (IDs starting with "999" or suspiciously small IDs)
|
| 174 |
+
const assetId = String(asset.id);
|
| 175 |
+
// Remove mock assets that don't exist in database
|
| 176 |
+
return !assetId.startsWith('999') && assetId !== '1' && assetId !== '2' && assetId !== '3';
|
| 177 |
+
});
|
| 178 |
setAssets(formattedAssets);
|
| 179 |
} else {
|
| 180 |
console.error('Failed to fetch assets');
|
| 181 |
+
// Set empty array on error (no mock data)
|
| 182 |
+
setAssets([]);
|
| 183 |
}
|
| 184 |
} catch (error) {
|
| 185 |
console.error('Error fetching assets:', error);
|
| 186 |
+
// Set empty array on error (no mock data)
|
| 187 |
+
setAssets([]);
|
| 188 |
} finally {
|
| 189 |
setIsLoadingAssets(false);
|
| 190 |
}
|