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

[_]: feat/Add prevention value for usage when photos endpoint is deleted #1091

Merged
merged 2 commits into from
Apr 18, 2024
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
38 changes: 29 additions & 9 deletions src/app/drive/services/usage.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { UsageResponse } from '@internxt/sdk/dist/drive/storage/types';
import { SdkFactory } from '../../core/factory/sdk';
import errorService from '../../core/services/error.service';

export interface UsageDetailsProps {
drive: number;
Expand All @@ -11,10 +12,15 @@ export async function fetchUsage(): Promise<UsageResponse> {
const storageClient = SdkFactory.getInstance().createStorageClient();
const photosClient = await SdkFactory.getInstance().createPhotosClient();

const [driveUsage, { usage: photosUsage }] = await Promise.all([
storageClient.spaceUsage(),
photosClient.photos.getUsage(),
]);
let photosUsage = 0;
const driveUsage = await storageClient.spaceUsage();

try {
const { usage } = await photosClient.photos.getUsage();
photosUsage = usage;
} catch (error) {
errorService.reportError(error);
}

driveUsage.total += photosUsage;

Expand All @@ -25,14 +31,28 @@ async function getUsageDetails(): Promise<UsageDetailsProps> {
const storageClient = SdkFactory.getInstance().createStorageClient();
const photosClient = await SdkFactory.getInstance().createPhotosClient();

const [{ drive, backups }, { usage: photosUsage }] = await Promise.all([
storageClient.spaceUsage(),
photosClient.photos.getUsage(),
]);
let drive = 0;
let backups = 0;
let photos = 0;

try {
const { drive: storageDrive, backups: storageBackups } = await storageClient.spaceUsage();
drive = storageDrive;
backups = storageBackups;
} catch (error) {
errorService.reportError(error);
}

try {
const { usage } = await photosClient.photos.getUsage();
photos = usage;
} catch (error) {
errorService.reportError(error);
}

return {
drive,
photos: photosUsage,
photos,
backups,
};
}
Expand Down
15 changes: 7 additions & 8 deletions src/app/photos/components/Preview.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { CaretLeft, DownloadSimple, Share, Trash, X } from '@phosphor-icons/react';
import { useState, useEffect, Fragment } from 'react';
import { Transition } from '@headlessui/react';
import { useDispatch, useSelector } from 'react-redux';
import { getPhotoBlob, getPhotoPreview } from 'app/network/download';
import { RootState } from '../../store';
import { photosSlice, PhotosState } from '../../store/slices/photos';
import useIdle from '../../core/hooks/useIdle';
import { PhotosItemType } from '@internxt/sdk/dist/photos';
import { CaretLeft, DownloadSimple, Share, X } from '@phosphor-icons/react';
import * as Sentry from '@sentry/react';
import { useTranslationContext } from 'app/i18n/provider/TranslationProvider';
import { getPhotoBlob, getPhotoPreview } from 'app/network/download';
import { Fragment, useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import useIdle from '../../core/hooks/useIdle';
import { RootState } from '../../store';
import { PhotosState, photosSlice } from '../../store/slices/photos';

export default function Preview({
onDownloadClick,
Expand Down Expand Up @@ -210,7 +210,6 @@ function Toolbar({
<div className="flex">
<TopIcon Target={DownloadSimple} onClick={onDownloadClick} />
<TopIcon Target={Share} onClick={onShareClick} />
<TopIcon Target={Trash} onClick={onDeleteClick} />
</div>
</div>
</Transition>
Expand Down
11 changes: 2 additions & 9 deletions src/app/photos/components/Toolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DownloadSimple, Share, X } from '@phosphor-icons/react';
import { useTranslationContext } from 'app/i18n/provider/TranslationProvider';
import { HTMLAttributes } from 'react';
import { PlacesType } from 'react-tooltip';
import { useTranslationContext } from 'app/i18n/provider/TranslationProvider';
import { DownloadSimple, Share, Trash, X } from '@phosphor-icons/react';
import TooltipElement from '../../shared/components/Tooltip/Tooltip';

const createToolTipsProps = (id: string, content: string, place: PlacesType): HTMLAttributes<HTMLElement> => ({
Expand Down Expand Up @@ -55,13 +55,6 @@ export default function Toolbar({
toolTipProps={createToolTipsProps('photos-share-tooltip', translate('actions.share'), 'bottom')}
/>
<TooltipElement id={'photos-share-tooltip'} className="z-40" />
<Icon
Target={Trash}
onClick={onDeleteClick}
dataTest="photos-delete-selected"
toolTipProps={createToolTipsProps('photos-delete-tooltip', translate('actions.delete'), 'bottom')}
/>
<TooltipElement id={'photos-delete-tooltip'} className="z-40" />
</div>
</div>
);
Expand Down
Loading