Skip to content
Open
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
110 changes: 75 additions & 35 deletions src/app/drive/components/ItemDetailsDialog/ItemDetailsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { STORAGE_KEYS } from 'services/storage-keys';
import { DriveItemData, DriveItemDetails, ItemDetailsProps } from 'app/drive/types';
import newStorageService from 'app/drive/services/new-storage.service';
import errorService from 'services/error.service';
import { FolderStatsResponse } from '@internxt/sdk/dist/drive/storage/types';
import { ItemType } from '@internxt/sdk/dist/workspaces/types';
import ItemDetailsSkeleton from './components/ItemDetailsSkeleton';
import { AdvancedSharedItem } from 'app/share/types';
import { useSelector } from 'react-redux';
Expand Down Expand Up @@ -56,13 +58,27 @@ const ItemsDetails = ({ item, translate }: { item: ItemDetailsProps; translate:
);
};

const calculateItemSize = (
item: DriveItemDetails,
folderStats: FolderStatsResponse | undefined,
): string | undefined => {
if (!item.isFolder) {
return bytesToString(item.size);
}
if (folderStats?.totalSize !== undefined) {
return bytesToString(folderStats.totalSize, false);
}
return undefined;
};

/**
* Return all the details of the item selected
* The data is:
* - Name
* - Shared
* - Size (only for files)
* - Size (for files and folders)
* - Type (only for files)
* - Number of files (only for folders)
* - Uploaded
* - Modified
* - Uploaded by
Expand Down Expand Up @@ -117,62 +133,86 @@ const ItemDetailsDialog = ({
}, 300);
};

function formateDate(dateString: string) {
const formateDate = (dateString: string) => {
return dateService.formatDefaultDate(dateString, translate);
}
};

function handleButtonItemClick() {
const handleButtonItemClick = () => {
onDetailsButtonClicked(item as AdvancedSharedItem);
onClose();
}
};

const MAX_DISPLAYABLE_FILE_COUNT = 1000;

const formatFileCount = (count: number | undefined) => {
if (count === undefined) return undefined;
if (count > MAX_DISPLAYABLE_FILE_COUNT) return translate('modals.itemDetailsModal.fileCountMoreThan1000');
return translate('modals.itemDetailsModal.fileCount', { count });
};

const getFolderStats = (item: DriveItemDetails, itemUuid: string) => {
return item.isFolder ? newStorageService.getFolderStats(itemUuid) : undefined;
};

const getItemLocation = async (
item: DriveItemDetails,
itemType: ItemType,
itemUuid: string,
itemFolderUuid: string,
token: string | undefined,
) => {
if (!isWorkspaceSelected) {
const ancestors = await newStorageService.getFolderAncestors(itemFolderUuid);
return getLocation(item, ancestors as unknown as DriveItemData[]);
}

const itemCreatorUuid = item.user?.uuid;
const isUserOwner = itemCreatorUuid && user?.uuid === itemCreatorUuid;

if (item.view === 'Drive' || (item.view === 'Shared' && isUserOwner)) {
const ancestors = await newStorageService.getFolderAncestorsInWorkspace(
workspaceSelected.workspace.id,
itemType,
itemUuid,
token,
);
return getLocation(item, ancestors as unknown as DriveItemData[]);
}

return '/Shared';
};

async function getDetailsData(
const getDetailsData = async (
item: DriveItemDetails,
isShared: string,
uploaded: string,
modified: string,
email: string,
) {
const itemType = item.isFolder ? 'folder' : 'file';
) => {
const itemType: ItemType = item.isFolder ? 'folder' : 'file';
const itemUuid = item.uuid;
const itemFolderUuid = item.isFolder ? itemUuid : item.folderUuid;
const itemCreatorUuid = item.user?.uuid;
const isUserOwner = (itemCreatorUuid && user && user.uuid === itemCreatorUuid) || false;
const storageKey = item.isFolder ? STORAGE_KEYS.FOLDER_ACCESS_TOKEN : STORAGE_KEYS.FILE_ACCESS_TOKEN;
const token = localStorageService.get(storageKey) || undefined;

let location = '';
const [location, folderStats] = await Promise.all([
getItemLocation(item, itemType, itemUuid, itemFolderUuid, token),
getFolderStats(item, itemUuid),
]);
const size = calculateItemSize(item, folderStats);

if (isWorkspaceSelected) {
if (item.view === 'Drive' || (item.view === 'Shared' && isUserOwner)) {
const ancestors = await newStorageService.getFolderAncestorsInWorkspace(
workspaceSelected.workspace.id,
itemType,
itemUuid,
token,
);
location = getLocation(item, ancestors as unknown as DriveItemData[]);
} else {
location = '/Shared';
}
} else {
const ancestors = await newStorageService.getFolderAncestors(itemFolderUuid);
location = getLocation(item, ancestors as unknown as DriveItemData[]);
}

const details: ItemDetailsProps = {
return {
name: item.name,
shared: isShared,
type: item.isFolder ? undefined : item.type,
size: item.isFolder ? undefined : bytesToString(item.size),
uploaded: uploaded,
modified: modified,
numberOfFiles: item.isFolder ? formatFileCount(folderStats?.fileCount) : undefined,
size,
uploaded,
modified,
uploadedBy: item.user?.email ?? item.userEmail ?? email,
location,
};

return details;
}
};

return (
<Modal className="p-0" isOpen={isOpen} onClose={onClose}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ const ItemDetailsSkeleton = ({
shared: '',
...(!isFolder && {
type: '',
size: '',
}),
...(isFolder && {
numberOfFiles: '',
}),
size: '',
uploaded: '',
modified: '',
uploadedBy: '',
Expand Down
20 changes: 20 additions & 0 deletions src/app/drive/services/new-storage.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,24 @@ describe('newStorageService', () => {
expect(mockGetFolderContentByUuid).toHaveBeenCalledWith(params);
});
});

describe('Get Folder Statistics', () => {
test('When requesting folder statistics, then it returns file count and total size', async () => {
const mockUuid = 'test-folder-uuid';
const mockStatsResponse = {
fileCount: 42,
totalSize: 1024000,
};
const mockGetFolderStats = vi.fn().mockResolvedValue(mockStatsResponse);
const mockStorageClient = { getFolderStats: mockGetFolderStats };
(SdkFactory.getNewApiInstance as Mock).mockReturnValue({
createNewStorageClient: () => mockStorageClient,
});

const result = await newStorageService.getFolderStats(mockUuid);

expect(mockGetFolderStats).toHaveBeenCalledWith(mockUuid);
expect(result).toEqual(mockStatsResponse);
});
});
});
7 changes: 7 additions & 0 deletions src/app/drive/services/new-storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
FolderAncestor,
FolderMeta,
FolderAncestorWorkspace,
FolderStatsResponse,
} from '@internxt/sdk/dist/drive/storage/types';
import { SdkFactory } from 'app/core/factory/sdk';
import { RequestCanceler } from '@internxt/sdk/dist/shared/http/types';
Expand Down Expand Up @@ -37,6 +38,11 @@ export async function getFolderMeta(uuid: string, workspaceId?: string, resource
return storageClient.getFolderMeta(uuid, workspaceId, resourcesToken);
}

export async function getFolderStats(uuid: string): Promise<FolderStatsResponse> {
const storageClient = SdkFactory.getNewApiInstance().createNewStorageClient();
return storageClient.getFolderStats(uuid);
}

export async function checkDuplicatedFiles(
folderUuid: string,
filesList: FileStructure[],
Expand Down Expand Up @@ -92,6 +98,7 @@ const newStorageService = {
getFolderAncestors,
getFolderAncestorsInWorkspace,
getFolderMeta,
getFolderStats,
checkDuplicatedFiles,
checkDuplicatedFolders,
getFolderContentByUuid,
Expand Down
3 changes: 3 additions & 0 deletions src/app/drive/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface DriveFolderData {
uuid: string;
type?: string;
user?: UserResumeData;
expiresAt?: string;
}

export interface DriveFolderMetadataPayload {
Expand Down Expand Up @@ -63,6 +64,7 @@ export interface DriveFileData {
sharings?: { type: string; id: string }[];
uuid: string;
user?: UserResumeData;
expiresAt?: string;
}

interface Thumbnail {
Expand Down Expand Up @@ -169,4 +171,5 @@ export type ItemDetailsProps = {
shared: string;
type?: string;
size?: string;
numberOfFiles?: string;
};
37 changes: 34 additions & 3 deletions src/app/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -789,9 +789,13 @@
"uploadedBy": "Hochgeladen von",
"shared": "Freigegeben",
"size": "Größe",
"numberOfFiles": "Anzahl der Dateien",
"modified": "Geändert",
"Ort": "Ort"
}
"location": "Ort"
},
"fileCount_one": "{{count}} Datei",
"fileCount_other": "{{count}} Dateien",
"fileCountMoreThan1000": "Mehr als 1000 Dateien"
},
"versionHistory": {
"title": "Versionsverlauf",
Expand Down Expand Up @@ -1198,6 +1202,32 @@
"item-menu": {
"restore": "Wiederherstellen",
"delete-permanently": "Lösche dauerhaft"
},
"autoDelete": {
"inDays_one": "In {{count}} Tag",
"inDays_other": "In {{count}} Tagen"
},
"automaticDisposal": {
"badge": "Neues Update",
"title": "Automatische Papierkorb-Entsorgung",
"close": "Schließen",
"description": "Alle in den Papierkorb verschobenen Elemente werden nun\nautomatisch dauerhaft gelöscht nach:",
"freeUsers": {
"duration": "2 Tage",
"label": "für kostenlose Benutzer"
},
"essentialUsers": {
"duration": "7 Tage",
"label": "für Essential-Benutzer"
},
"premiumUsers": {
"duration": "15 Tage",
"label": "für Premium-Benutzer"
},
"ultimateUsers": {
"duration": "30 Tage",
"label": "für Ultimate-Benutzer"
}
}
},
"tasks": {
Expand Down Expand Up @@ -1470,7 +1500,8 @@
"name": "Name",
"modified": "Modifiziert",
"size": "Größe",
"actions": "Aktionen"
"actions": "Aktionen",
"autoDelete": "Automatisches Löschen"
}
},
"viewMode": {
Expand Down
35 changes: 33 additions & 2 deletions src/app/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -886,9 +886,13 @@
"uploadedBy": "Uploaded by",
"shared": "Shared",
"size": "Size",
"numberOfFiles": "Number of files",
"modified": "Modified",
"location": "Location"
}
},
"fileCount_one": "{{count}} file",
"fileCount_other": "{{count}} files",
"fileCountMoreThan1000": "1000+ files"
},
"versionHistory": {
"title": "Version history",
Expand Down Expand Up @@ -1283,6 +1287,32 @@
"item-menu": {
"restore": "Restore",
"delete-permanently": "Delete permanently"
},
"autoDelete": {
"inDays_one": "In {{count}} day",
"inDays_other": "In {{count}} days"
},
"automaticDisposal": {
"badge": "New update",
"title": "Automatic Trash disposal",
"close": "Close",
"description": "Now all the items moved to Trash will be\npermanently deleted automatically after:",
"freeUsers": {
"duration": "2 days",
"label": "for free users"
},
"essentialUsers": {
"duration": "7 days",
"label": "for essential users"
},
"premiumUsers": {
"duration": "15 days",
"label": "for premium users"
},
"ultimateUsers": {
"duration": "30 days",
"label": "for ultimate users"
}
}
},
"tasks": {
Expand Down Expand Up @@ -1552,7 +1582,8 @@
"name": "Name",
"modified": "Modified",
"size": "Size",
"actions": "Actions"
"actions": "Actions",
"autoDelete": "Auto-delete"
}
},
"viewMode": {
Expand Down
Loading
Loading