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: pod deletion (#279) #464

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions src/api/pod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export async function receivePod(fdp: FdpStorage, podReference: string) {
return await fdp.personalStorage.getSharedInfo(podReference);
}

export function deletePod(fdp: FdpStorage, podName: string): Promise<void> {
return fdp.personalStorage.delete(podName);
}

export function getFdpPathByDirectory(directory: string): string {
if (directory === 'root') {
return '/';
Expand Down
16 changes: 14 additions & 2 deletions src/components/Modals/ConfirmDeleteModal/ConfirmDeleteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface ConfirmDeleteModalProps {
closeModal: () => void;
type: string;
name: string;
error?: string;
deleteHandler: () => void;
}

Expand All @@ -21,11 +22,16 @@ const ConfirmDeleteModal: FC<ConfirmDeleteModalProps> = ({
closeModal,
type,
name,
error,
deleteHandler,
}) => {
const [loading, setLoading] = useState(false);
const { intl } = useLocales();

useEffect(() => {
setLoading(false);
}, [error]);

useEffect(() => {
setLoading(false);
}, [showModal]);
Expand All @@ -39,8 +45,8 @@ const ConfirmDeleteModal: FC<ConfirmDeleteModalProps> = ({
}
}}
headerIcon={{
light: <DeleteLightIcon />,
dark: <DeleteDarkIcon />,
light: <DeleteLightIcon width="26" />,
dark: <DeleteDarkIcon width="26" />,
}}
headerTitle={intl.get('CONFIRM_DELETE')}
>
Expand All @@ -52,6 +58,12 @@ const ConfirmDeleteModal: FC<ConfirmDeleteModalProps> = ({
</p>
</div>

{!loading && error && (
<div className="my-2 text-color-status-negative-day text-xs text-center leading-none">
{error}
</div>
)}

{loading && (
<div className="mt-3">
<Spinner />
Expand Down
60 changes: 60 additions & 0 deletions src/components/Modals/PodDeleteModal/PodDeleteModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { useContext, useState } from 'react';
import { ConfirmDeleteModal } from '@components/Modals';
import { deletePod } from '@api/pod';
import { useLocales } from '@context/LocalesContext';
import { useFdpStorage } from '@context/FdpStorageContext';
import PodContext from '@context/PodContext';
import { useMatomo } from '@datapunt/matomo-tracker-react';

interface PodDeleteModalProps {
showModal: boolean;
refreshPods: () => void;
onClose: () => void;
onDelete: () => void;
}

const PodDeleteModal = ({
showModal,
refreshPods,
onClose,
onDelete,
}: PodDeleteModalProps) => {
const [errorMessage, setErrorMessage] = useState('');
const { trackEvent } = useMatomo();
const { intl } = useLocales();
const { fdpClientRef } = useFdpStorage();
const { activePod, setActivePod } = useContext(PodContext);

const handleDeletePod = async () => {
try {
setErrorMessage('');
await deletePod(fdpClientRef.current, activePod);
await new Promise((resolve) => setTimeout(resolve, 1000));
trackEvent({
category: 'Pod',
action: `Delete Pod`,
name: `Delete Pod: ${activePod}`,
documentTitle: 'Drive Page',
href: window.location.href,
});
setActivePod(null);
refreshPods();
onDelete();
} catch (e) {
setErrorMessage(intl.get('GENERIC_ERROR', { message: String(e) }));
}
};

return (
<ConfirmDeleteModal
showModal={showModal}
closeModal={onClose}
type="pod"
name={activePod}
deleteHandler={handleDeletePod}
error={errorMessage}
/>
);
};

export default PodDeleteModal;
4 changes: 2 additions & 2 deletions src/components/Modals/PreviewFileModal/PreviewFileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ const PreviewFileModal: FC<PreviewModalProps> = ({
className="cursor-pointer"
>
{theme === 'light' ? (
<DeleteLightIcon className="inline-block" />
<DeleteLightIcon className="inline-block" width="26" />
) : (
<DeleteDarkIcon className="inline-block" />
<DeleteDarkIcon className="inline-block" width="26" />
)}
</span>
</div>
Expand Down
34 changes: 33 additions & 1 deletion src/components/NavigationBars/DriveActionBar/DriveActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,26 @@ import ImportDarkIcon from '@media/UI/import-dark.svg';

import CreateFolderLightIcon from '@media/UI/create-folder-light.svg';
import CreateFolderDarkIcon from '@media/UI/create-folder-dark.svg';

import DeleteLightIcon from '@media/UI/delete-light.svg';
import DeleteDarkIcon from '@media/UI/delete-dark.svg';

import PodContext from '@context/PodContext';
import { UpdateDriveProps } from '@interfaces/handlers';
import { useLocales } from '@context/LocalesContext';
import PodDeleteModal from '@components/Modals/PodDeleteModal/PodDeleteModal';

const DriveActionBar: FC<UpdateDriveProps> = ({ updateDrive }) => {
export interface DriveActionBarProps extends UpdateDriveProps {
refreshPods: () => void;
}
const DriveActionBar = ({ refreshPods, updateDrive }: DriveActionBarProps) => {
const { theme } = useContext(ThemeContext);
const { activePod } = useContext(PodContext);

const [showUploadFileModal, setShowUploadFileModal] = useState(false);
const [showImportFileModal, setShowImportFileModal] = useState(false);
const [showCreateFolderModal, setShowCreateFolderModal] = useState(false);
const [showDeletePodModal, setShowDeletePodModal] = useState(false);

const { intl } = useLocales();

Expand Down Expand Up @@ -77,6 +86,20 @@ const DriveActionBar: FC<UpdateDriveProps> = ({ updateDrive }) => {
className="mx-1"
onClick={() => setShowCreateFolderModal(true)}
/>

<Button
type="button"
variant="primary"
icon={
theme === 'light' ? (
<DeleteLightIcon width="15" />
) : (
<DeleteDarkIcon width="15" />
)
}
className="mx-1"
onClick={() => setShowDeletePodModal(true)}
/>
</div>
)}
</div>
Expand Down Expand Up @@ -108,6 +131,15 @@ const DriveActionBar: FC<UpdateDriveProps> = ({ updateDrive }) => {
updateDrive={updateDrive}
/>
) : null}

{showDeletePodModal ? (
<PodDeleteModal
showModal={showDeletePodModal}
onClose={() => setShowDeletePodModal(false)}
onDelete={() => setShowDeletePodModal(false)}
refreshPods={refreshPods}
/>
) : null}
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ import ImportDarkIcon from '@media/UI/import-dark.svg';

import CreateFolderLightIcon from '@media/UI/create-folder-light.svg';
import CreateFolderDarkIcon from '@media/UI/create-folder-dark.svg';

import DeleteLightIcon from '@media/UI/delete-light.svg';
import DeleteDarkIcon from '@media/UI/delete-dark.svg';

import { UpdateDriveProps } from '@interfaces/handlers';
import { useLocales } from '@context/LocalesContext';
import PodDeleteModal from '@components/Modals/PodDeleteModal/PodDeleteModal';

export interface DriveActionBarMobileProps extends UpdateDriveProps {
refreshPods?: () => void;
Expand Down Expand Up @@ -60,6 +65,7 @@ const DriveActionBarMobile: FC<DriveActionBarMobileProps> = ({
const [showUploadFileModal, setShowUploadFileModal] = useState(false);
const [showImportFileModal, setShowImportFileModal] = useState(false);
const [showCreateFolderModal, setShowCreateFolderModal] = useState(false);
const [showDeletePodModal, setShowDeletePodModal] = useState(false);

const { intl } = useLocales();

Expand Down Expand Up @@ -94,6 +100,13 @@ const DriveActionBarMobile: FC<DriveActionBarMobileProps> = ({
<CreateFolderDarkIcon />,
() => setShowCreateFolderModal(true)
)}
{DriveActionBarItem(
theme,
intl.get('DELETE'),
<DeleteLightIcon width="15" />,
<DeleteDarkIcon width="15" />,
() => setShowDeletePodModal(true)
)}
</div>
{showCreatePodModal ? (
<CreatePodModal
Expand Down Expand Up @@ -125,6 +138,15 @@ const DriveActionBarMobile: FC<DriveActionBarMobileProps> = ({
updateDrive={updateDrive}
/>
) : null}

{showDeletePodModal && (
<PodDeleteModal
showModal={showDeletePodModal}
onClose={() => setShowDeletePodModal(false)}
onDelete={() => setShowDeletePodModal(false)}
refreshPods={refreshPods}
/>
)}
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/media/UI/delete-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/media/UI/delete-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/pages/drive/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ const Drive: FC = () => {
toggleView={handleToggleView}
toggleSort={handleToggleSort}
/>
<DriveActionBar updateDrive={handleUpdateDrive} />
<DriveActionBar
updateDrive={handleUpdateDrive}
refreshPods={handleFetchPods}
/>
{search.length > 0 ? (
<div className="flex justify-start items-center mt-10 mb-5">
<span>
Expand Down