@scality/data-browser-library 1.0.0-preview.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Editor.d.ts +12 -0
- package/dist/components/Editor.js +28 -0
- package/dist/components/__tests__/BucketList.test.d.ts +1 -0
- package/dist/components/__tests__/BucketList.test.js +225 -0
- package/dist/components/__tests__/BucketOverview.test.d.ts +1 -0
- package/dist/components/__tests__/BucketOverview.test.js +479 -0
- package/dist/components/__tests__/BucketPolicyPage.test.d.ts +1 -0
- package/dist/components/__tests__/BucketPolicyPage.test.js +213 -0
- package/dist/components/__tests__/CreateFolderButton.test.d.ts +1 -0
- package/dist/components/__tests__/CreateFolderButton.test.js +147 -0
- package/dist/components/__tests__/DeleteBucketButton.test.d.ts +1 -0
- package/dist/components/__tests__/DeleteBucketButton.test.js +272 -0
- package/dist/components/__tests__/DeleteObjectButton.test.d.ts +1 -0
- package/dist/components/__tests__/DeleteObjectButton.test.js +302 -0
- package/dist/components/__tests__/MetadataSearch.test.d.ts +1 -0
- package/dist/components/__tests__/MetadataSearch.test.js +201 -0
- package/dist/components/__tests__/ObjectList.test.d.ts +1 -0
- package/dist/components/__tests__/ObjectList.test.js +283 -0
- package/dist/components/__tests__/UploadButton.test.d.ts +1 -0
- package/dist/components/__tests__/UploadButton.test.js +144 -0
- package/dist/components/buckets/BucketDetails.d.ts +1 -0
- package/dist/components/buckets/BucketDetails.js +51 -0
- package/dist/components/buckets/BucketList.d.ts +12 -0
- package/dist/components/buckets/BucketList.js +136 -0
- package/dist/components/buckets/BucketLocation.d.ts +3 -0
- package/dist/components/buckets/BucketLocation.js +16 -0
- package/dist/components/buckets/BucketOverview.d.ts +14 -0
- package/dist/components/buckets/BucketOverview.js +209 -0
- package/dist/components/buckets/BucketPage.d.ts +2 -0
- package/dist/components/buckets/BucketPage.js +47 -0
- package/dist/components/buckets/BucketPolicyButton.d.ts +7 -0
- package/dist/components/buckets/BucketPolicyButton.js +18 -0
- package/dist/components/buckets/BucketPolicyPage.d.ts +1 -0
- package/dist/components/buckets/BucketPolicyPage.js +205 -0
- package/dist/components/buckets/DeleteBucketButton.d.ts +8 -0
- package/dist/components/buckets/DeleteBucketButton.js +78 -0
- package/dist/components/index.d.ts +12 -0
- package/dist/components/index.js +13 -0
- package/dist/components/layouts/BrowserPageLayout.d.ts +9 -0
- package/dist/components/layouts/BrowserPageLayout.js +46 -0
- package/dist/components/objects/CreateFolderButton.d.ts +29 -0
- package/dist/components/objects/CreateFolderButton.js +118 -0
- package/dist/components/objects/DeleteObjectButton.d.ts +8 -0
- package/dist/components/objects/DeleteObjectButton.js +191 -0
- package/dist/components/objects/ObjectDetails/ObjectMetadata.d.ts +2 -0
- package/dist/components/objects/ObjectDetails/ObjectMetadata.js +323 -0
- package/dist/components/objects/ObjectDetails/ObjectSummary.d.ts +3 -0
- package/dist/components/objects/ObjectDetails/ObjectSummary.js +193 -0
- package/dist/components/objects/ObjectDetails/ObjectTags.d.ts +3 -0
- package/dist/components/objects/ObjectDetails/ObjectTags.js +300 -0
- package/dist/components/objects/ObjectDetails/index.d.ts +9 -0
- package/dist/components/objects/ObjectDetails/index.js +49 -0
- package/dist/components/objects/ObjectList.d.ts +40 -0
- package/dist/components/objects/ObjectList.js +407 -0
- package/dist/components/objects/ObjectPage.d.ts +1 -0
- package/dist/components/objects/ObjectPage.js +43 -0
- package/dist/components/objects/UploadButton.d.ts +34 -0
- package/dist/components/objects/UploadButton.js +229 -0
- package/dist/components/providers/DataBrowserProvider.d.ts +20 -0
- package/dist/components/providers/DataBrowserProvider.js +42 -0
- package/dist/components/search/MetadataSearch.d.ts +5 -0
- package/dist/components/search/MetadataSearch.js +162 -0
- package/dist/components/search/SearchHints.d.ts +8 -0
- package/dist/components/search/SearchHints.js +21 -0
- package/dist/components/ui/DeleteObjectModalContent.d.ts +5 -0
- package/dist/components/ui/DeleteObjectModalContent.js +71 -0
- package/dist/components/ui/Search.elements.d.ts +17 -0
- package/dist/components/ui/Search.elements.js +59 -0
- package/dist/components/ui/Table.elements.d.ts +36 -0
- package/dist/components/ui/Table.elements.js +87 -0
- package/dist/config/factory.d.ts +52 -0
- package/dist/config/factory.js +70 -0
- package/dist/config/types.d.ts +46 -0
- package/dist/config/types.js +0 -0
- package/dist/hooks/__tests__/useIsBucketEmpty.test.d.ts +1 -0
- package/dist/hooks/__tests__/useIsBucketEmpty.test.js +122 -0
- package/dist/hooks/bucketConfiguration.d.ts +147 -0
- package/dist/hooks/bucketConfiguration.js +59 -0
- package/dist/hooks/bucketOperations.d.ts +36 -0
- package/dist/hooks/bucketOperations.js +12 -0
- package/dist/hooks/factories/__tests__/useCreateS3FunctionMutationHook.test.d.ts +1 -0
- package/dist/hooks/factories/__tests__/useCreateS3FunctionMutationHook.test.js +276 -0
- package/dist/hooks/factories/__tests__/useCreateS3InfiniteQueryHook.test.d.ts +1 -0
- package/dist/hooks/factories/__tests__/useCreateS3InfiniteQueryHook.test.js +259 -0
- package/dist/hooks/factories/__tests__/useCreateS3LoginHook.test.d.ts +1 -0
- package/dist/hooks/factories/__tests__/useCreateS3LoginHook.test.js +166 -0
- package/dist/hooks/factories/__tests__/useCreateS3MutationHook.test.d.ts +1 -0
- package/dist/hooks/factories/__tests__/useCreateS3MutationHook.test.js +200 -0
- package/dist/hooks/factories/__tests__/useCreateS3QueryHook.test.d.ts +1 -0
- package/dist/hooks/factories/__tests__/useCreateS3QueryHook.test.js +136 -0
- package/dist/hooks/factories/index.d.ts +18 -0
- package/dist/hooks/factories/index.js +5 -0
- package/dist/hooks/factories/useCreateS3InfiniteQueryHook.d.ts +13 -0
- package/dist/hooks/factories/useCreateS3InfiniteQueryHook.js +76 -0
- package/dist/hooks/factories/useCreateS3LoginHook.d.ts +8 -0
- package/dist/hooks/factories/useCreateS3LoginHook.js +22 -0
- package/dist/hooks/factories/useCreateS3MutationHook.d.ts +5 -0
- package/dist/hooks/factories/useCreateS3MutationHook.js +50 -0
- package/dist/hooks/factories/useCreateS3QueryHook.d.ts +3 -0
- package/dist/hooks/factories/useCreateS3QueryHook.js +30 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.js +8 -0
- package/dist/hooks/loginOperations.d.ts +21 -0
- package/dist/hooks/loginOperations.js +9 -0
- package/dist/hooks/objectOperations.d.ts +190 -0
- package/dist/hooks/objectOperations.js +66 -0
- package/dist/hooks/presignedOperations.d.ts +73 -0
- package/dist/hooks/presignedOperations.js +72 -0
- package/dist/hooks/useIsBucketEmpty.d.ts +7 -0
- package/dist/hooks/useIsBucketEmpty.js +36 -0
- package/dist/hooks/useLoginMutation.d.ts +21 -0
- package/dist/hooks/useLoginMutation.js +9 -0
- package/dist/hooks/useS3Client.d.ts +1 -0
- package/dist/hooks/useS3Client.js +13 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/schemas/bucketPolicySchema.json +321 -0
- package/dist/test/msw/handlers/deleteBucket.d.ts +1 -0
- package/dist/test/msw/handlers/deleteBucket.js +14 -0
- package/dist/test/msw/handlers/getBucketAcl.d.ts +1 -0
- package/dist/test/msw/handlers/getBucketAcl.js +96 -0
- package/dist/test/msw/handlers/getBucketLocation.d.ts +1 -0
- package/dist/test/msw/handlers/getBucketLocation.js +23 -0
- package/dist/test/msw/handlers/getBucketPolicy.d.ts +11 -0
- package/dist/test/msw/handlers/getBucketPolicy.js +72 -0
- package/dist/test/msw/handlers/headObject.d.ts +1 -0
- package/dist/test/msw/handlers/headObject.js +17 -0
- package/dist/test/msw/handlers/listBuckets.d.ts +1 -0
- package/dist/test/msw/handlers/listBuckets.js +24 -0
- package/dist/test/msw/handlers/listObjectVersions.d.ts +1 -0
- package/dist/test/msw/handlers/listObjectVersions.js +83 -0
- package/dist/test/msw/handlers/listObjects.d.ts +1 -0
- package/dist/test/msw/handlers/listObjects.js +66 -0
- package/dist/test/msw/handlers/objectLegalHold.d.ts +1 -0
- package/dist/test/msw/handlers/objectLegalHold.js +24 -0
- package/dist/test/msw/handlers/objectRetention.d.ts +1 -0
- package/dist/test/msw/handlers/objectRetention.js +27 -0
- package/dist/test/msw/handlers/putBucketAcl.d.ts +1 -0
- package/dist/test/msw/handlers/putBucketAcl.js +18 -0
- package/dist/test/msw/handlers/putObject.d.ts +1 -0
- package/dist/test/msw/handlers/putObject.js +16 -0
- package/dist/test/msw/handlers.d.ts +4 -0
- package/dist/test/msw/handlers.js +109 -0
- package/dist/test/msw/index.d.ts +2 -0
- package/dist/test/msw/index.js +3 -0
- package/dist/test/msw/server.d.ts +4 -0
- package/dist/test/msw/server.js +20 -0
- package/dist/test/msw/utils.d.ts +2 -0
- package/dist/test/msw/utils.js +13 -0
- package/dist/test/setup.d.ts +1 -0
- package/dist/test/setup.js +82 -0
- package/dist/test/testUtils.d.ts +82 -0
- package/dist/test/testUtils.js +236 -0
- package/dist/test/utils/errorHandling.test.d.ts +1 -0
- package/dist/test/utils/errorHandling.test.js +385 -0
- package/dist/types/index.d.ts +48 -0
- package/dist/types/index.js +0 -0
- package/dist/utils/deletion/index.d.ts +2 -0
- package/dist/utils/deletion/index.js +2 -0
- package/dist/utils/deletion/messages.d.ts +5 -0
- package/dist/utils/deletion/messages.js +29 -0
- package/dist/utils/deletion/types.d.ts +11 -0
- package/dist/utils/deletion/types.js +0 -0
- package/dist/utils/errorHandling.d.ts +54 -0
- package/dist/utils/errorHandling.js +79 -0
- package/dist/utils/hooks.d.ts +2 -0
- package/dist/utils/hooks.js +26 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/proxyMiddleware.d.ts +18 -0
- package/dist/utils/proxyMiddleware.js +56 -0
- package/dist/utils/s3Client.d.ts +5 -0
- package/dist/utils/s3Client.js +35 -0
- package/dist/utils/useFeatures.d.ts +1 -0
- package/dist/utils/useFeatures.js +7 -0
- package/package.json +79 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { AppContainer, Icon, Stack, TwoPanelLayout } from "@scality/core-ui";
|
|
3
|
+
import { fontSize } from "@scality/core-ui/dist/style/theme";
|
|
4
|
+
import "react";
|
|
5
|
+
import styled_components from "styled-components";
|
|
6
|
+
const HeadTitle = styled_components.div`
|
|
7
|
+
display: flex;
|
|
8
|
+
color: ${(props)=>props.theme.textSecondary};
|
|
9
|
+
font-size: ${fontSize.large};
|
|
10
|
+
align-items: center;
|
|
11
|
+
`;
|
|
12
|
+
const BrowserPageLayout = ({ title, leftPanel, rightPanel })=>/*#__PURE__*/ jsxs(AppContainer, {
|
|
13
|
+
children: [
|
|
14
|
+
/*#__PURE__*/ jsx(AppContainer.OverallSummary, {
|
|
15
|
+
children: /*#__PURE__*/ jsxs(Stack, {
|
|
16
|
+
children: [
|
|
17
|
+
/*#__PURE__*/ jsx(Icon, {
|
|
18
|
+
name: "Account",
|
|
19
|
+
size: "2x",
|
|
20
|
+
withWrapper: true
|
|
21
|
+
}),
|
|
22
|
+
/*#__PURE__*/ jsx(HeadTitle, {
|
|
23
|
+
children: title
|
|
24
|
+
})
|
|
25
|
+
]
|
|
26
|
+
})
|
|
27
|
+
}),
|
|
28
|
+
/*#__PURE__*/ jsx(AppContainer.MainContent, {
|
|
29
|
+
background: "backgroundLevel1",
|
|
30
|
+
children: /*#__PURE__*/ jsx(TwoPanelLayout, {
|
|
31
|
+
panelsRatio: "65-35",
|
|
32
|
+
leftPanel: {
|
|
33
|
+
children: /*#__PURE__*/ jsx(Fragment, {
|
|
34
|
+
children: leftPanel
|
|
35
|
+
})
|
|
36
|
+
},
|
|
37
|
+
rightPanel: {
|
|
38
|
+
children: /*#__PURE__*/ jsx(Fragment, {
|
|
39
|
+
children: rightPanel
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
]
|
|
45
|
+
});
|
|
46
|
+
export { BrowserPageLayout, HeadTitle };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface CreateFolderButtonProps {
|
|
3
|
+
/**
|
|
4
|
+
* The S3 bucket name where folder will be created
|
|
5
|
+
*/
|
|
6
|
+
bucket: string;
|
|
7
|
+
/**
|
|
8
|
+
* The prefix/path where folder will be created within the bucket
|
|
9
|
+
*/
|
|
10
|
+
prefix?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Button label text
|
|
13
|
+
*/
|
|
14
|
+
label?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Button variant
|
|
17
|
+
*/
|
|
18
|
+
variant?: "primary" | "secondary" | "outline";
|
|
19
|
+
/**
|
|
20
|
+
* Called when folder creation is successful
|
|
21
|
+
*/
|
|
22
|
+
onFolderSuccess?: (folderName: string) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Called when folder creation fails
|
|
25
|
+
*/
|
|
26
|
+
onFolderError?: (error: Error, folderName: string) => void;
|
|
27
|
+
}
|
|
28
|
+
export declare const CreateFolderButton: React.FC<CreateFolderButtonProps>;
|
|
29
|
+
export default CreateFolderButton;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useState } from "react";
|
|
3
|
+
import { Icon, InfoMessage, Modal, Stack, Wrap, spacing } from "@scality/core-ui";
|
|
4
|
+
import { Button, Input } from "@scality/core-ui/dist/next";
|
|
5
|
+
import { useCreateFolder } from "../../hooks/index.js";
|
|
6
|
+
import styled_components from "styled-components";
|
|
7
|
+
const Description = styled_components.div`
|
|
8
|
+
margin-top: ${spacing.r16};
|
|
9
|
+
width: 20.5rem;
|
|
10
|
+
`;
|
|
11
|
+
const CreateFolderButton = ({ bucket, prefix = "", label = "Folder", variant = "secondary", onFolderSuccess, onFolderError })=>{
|
|
12
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
13
|
+
const [folderName, setFolderName] = useState("");
|
|
14
|
+
const createFolderMutation = useCreateFolder();
|
|
15
|
+
const openModal = useCallback(()=>{
|
|
16
|
+
setIsModalOpen(true);
|
|
17
|
+
}, []);
|
|
18
|
+
const closeModal = useCallback(()=>{
|
|
19
|
+
setFolderName("");
|
|
20
|
+
setIsModalOpen(false);
|
|
21
|
+
}, []);
|
|
22
|
+
const handleSave = useCallback(()=>{
|
|
23
|
+
if (!folderName.trim()) return;
|
|
24
|
+
const folderKey = prefix ? `${prefix}/${folderName}/` : `${folderName}/`;
|
|
25
|
+
createFolderMutation.mutate({
|
|
26
|
+
Bucket: bucket,
|
|
27
|
+
Key: folderKey,
|
|
28
|
+
Body: ""
|
|
29
|
+
}, {
|
|
30
|
+
onSuccess: ()=>{
|
|
31
|
+
onFolderSuccess?.(folderName);
|
|
32
|
+
setFolderName("");
|
|
33
|
+
setIsModalOpen(false);
|
|
34
|
+
},
|
|
35
|
+
onError: (error)=>{
|
|
36
|
+
onFolderError?.(error, folderName);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}, [
|
|
40
|
+
folderName,
|
|
41
|
+
prefix,
|
|
42
|
+
bucket,
|
|
43
|
+
createFolderMutation,
|
|
44
|
+
onFolderSuccess,
|
|
45
|
+
onFolderError
|
|
46
|
+
]);
|
|
47
|
+
const handleChange = useCallback((e)=>{
|
|
48
|
+
setFolderName(e.target.value);
|
|
49
|
+
}, []);
|
|
50
|
+
const hasInvalidFormat = folderName.startsWith("/");
|
|
51
|
+
const isEmpty = "" === folderName.trim();
|
|
52
|
+
const isLoading = createFolderMutation.isPending;
|
|
53
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
54
|
+
children: [
|
|
55
|
+
/*#__PURE__*/ jsx(Button, {
|
|
56
|
+
icon: /*#__PURE__*/ jsx(Icon, {
|
|
57
|
+
name: "Create-add"
|
|
58
|
+
}),
|
|
59
|
+
label: label,
|
|
60
|
+
variant: variant,
|
|
61
|
+
onClick: openModal
|
|
62
|
+
}),
|
|
63
|
+
/*#__PURE__*/ jsxs(Modal, {
|
|
64
|
+
close: closeModal,
|
|
65
|
+
footer: /*#__PURE__*/ jsxs(Wrap, {
|
|
66
|
+
children: [
|
|
67
|
+
/*#__PURE__*/ jsx("p", {}),
|
|
68
|
+
/*#__PURE__*/ jsxs(Stack, {
|
|
69
|
+
children: [
|
|
70
|
+
/*#__PURE__*/ jsx(Button, {
|
|
71
|
+
variant: "outline",
|
|
72
|
+
onClick: closeModal,
|
|
73
|
+
label: "Cancel",
|
|
74
|
+
disabled: isLoading
|
|
75
|
+
}),
|
|
76
|
+
/*#__PURE__*/ jsx(Button, {
|
|
77
|
+
disabled: isLoading || isEmpty || hasInvalidFormat,
|
|
78
|
+
variant: "secondary",
|
|
79
|
+
onClick: handleSave,
|
|
80
|
+
label: "Save",
|
|
81
|
+
tooltip: hasInvalidFormat ? {
|
|
82
|
+
overlay: "The folder name is not valid."
|
|
83
|
+
} : void 0
|
|
84
|
+
})
|
|
85
|
+
]
|
|
86
|
+
})
|
|
87
|
+
]
|
|
88
|
+
}),
|
|
89
|
+
isOpen: isModalOpen,
|
|
90
|
+
title: "Create a folder",
|
|
91
|
+
children: [
|
|
92
|
+
/*#__PURE__*/ jsx(Input, {
|
|
93
|
+
id: "folder-name",
|
|
94
|
+
value: folderName,
|
|
95
|
+
placeholder: "New folder",
|
|
96
|
+
error: hasInvalidFormat ? "Folder name cannot start with '/'" : void 0,
|
|
97
|
+
onChange: handleChange,
|
|
98
|
+
autoFocus: true
|
|
99
|
+
}),
|
|
100
|
+
/*#__PURE__*/ jsx(Description, {
|
|
101
|
+
children: /*#__PURE__*/ jsx(InfoMessage, {
|
|
102
|
+
title: "Creating a folder",
|
|
103
|
+
content: /*#__PURE__*/ jsxs(Fragment, {
|
|
104
|
+
children: [
|
|
105
|
+
"Ensure the folder name does not begin with a slash. ",
|
|
106
|
+
/*#__PURE__*/ jsx("br", {}),
|
|
107
|
+
'When you create a folder, Data Browser creates an object with the above name appended by suffix "/" and that object is displayed as a folder in the Data Browser.'
|
|
108
|
+
]
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
]
|
|
113
|
+
})
|
|
114
|
+
]
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
const objects_CreateFolderButton = CreateFolderButton;
|
|
118
|
+
export { CreateFolderButton, objects_CreateFolderButton as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TableItem } from "./ObjectList";
|
|
2
|
+
export type Objects = TableItem[];
|
|
3
|
+
interface DeleteObjectButtonProps {
|
|
4
|
+
objects: Objects;
|
|
5
|
+
bucketName: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const DeleteObjectButton: React.FC<DeleteObjectButtonProps>;
|
|
8
|
+
export default DeleteObjectButton;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useState } from "react";
|
|
3
|
+
import { Banner, Icon, Modal, PrettyBytes, Stack, Text, Wrap, spacing, useToast } from "@scality/core-ui";
|
|
4
|
+
import { Box, Button } from "@scality/core-ui/dist/next";
|
|
5
|
+
import { useDeleteObjects, useGetBucketVersioning } from "../../hooks/index.js";
|
|
6
|
+
import { getDeletionMessages } from "../../utils/deletion/index.js";
|
|
7
|
+
import { DeleteObjectModalContent } from "../ui/DeleteObjectModalContent.js";
|
|
8
|
+
const Title = ({ objects, isCurrentSelectionPermanentlyDeleted })=>{
|
|
9
|
+
const foldersSize = objects.filter((object)=>"folder" === object.type).length;
|
|
10
|
+
const objectsSize = objects.length - foldersSize;
|
|
11
|
+
if (0 === objects.length) return null;
|
|
12
|
+
return /*#__PURE__*/ jsxs(Text, {
|
|
13
|
+
children: [
|
|
14
|
+
"Do you want to",
|
|
15
|
+
" ",
|
|
16
|
+
/*#__PURE__*/ jsxs("strong", {
|
|
17
|
+
children: [
|
|
18
|
+
" ",
|
|
19
|
+
isCurrentSelectionPermanentlyDeleted ? "permanently" : "",
|
|
20
|
+
" "
|
|
21
|
+
]
|
|
22
|
+
}),
|
|
23
|
+
" ",
|
|
24
|
+
"delete the selected",
|
|
25
|
+
" ",
|
|
26
|
+
objectsSize > 0 && /*#__PURE__*/ jsxs(Fragment, {
|
|
27
|
+
children: [
|
|
28
|
+
objectsSize,
|
|
29
|
+
" ",
|
|
30
|
+
isCurrentSelectionPermanentlyDeleted ? `object version${objectsSize > 1 ? "s" : ""}` : `object${objectsSize > 1 ? "s" : ""}`,
|
|
31
|
+
foldersSize > 0 && " and "
|
|
32
|
+
]
|
|
33
|
+
}),
|
|
34
|
+
foldersSize > 0 && /*#__PURE__*/ jsxs(Fragment, {
|
|
35
|
+
children: [
|
|
36
|
+
foldersSize,
|
|
37
|
+
" folder",
|
|
38
|
+
foldersSize > 1 ? "s" : ""
|
|
39
|
+
]
|
|
40
|
+
}),
|
|
41
|
+
"?"
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
const DeleteObjectButton = ({ objects, bucketName })=>{
|
|
46
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
47
|
+
const [selectedObjects, setSelectedObjects] = useState(objects);
|
|
48
|
+
const { data: versioningData } = useGetBucketVersioning({
|
|
49
|
+
Bucket: bucketName
|
|
50
|
+
});
|
|
51
|
+
const { mutate: deleteObjects, status: deleteObjectsStatus } = useDeleteObjects();
|
|
52
|
+
const { showToast } = useToast();
|
|
53
|
+
const isVersioningEnabled = versioningData?.Status === "Enabled";
|
|
54
|
+
const isCurrentSelectionPermanentlyDeleted = !isVersioningEnabled || selectedObjects.some((object)=>!!object.VersionId);
|
|
55
|
+
const { info: notificationText } = getDeletionMessages({
|
|
56
|
+
numberOfObjects: selectedObjects.length,
|
|
57
|
+
selectedObjectsAreSpecificVersions: isCurrentSelectionPermanentlyDeleted,
|
|
58
|
+
isBucketVersioned: isVersioningEnabled
|
|
59
|
+
});
|
|
60
|
+
const handleDeleteClick = useCallback(()=>{
|
|
61
|
+
setIsModalOpen(true);
|
|
62
|
+
}, []);
|
|
63
|
+
const cancel = useCallback(()=>{
|
|
64
|
+
setIsModalOpen(false);
|
|
65
|
+
}, []);
|
|
66
|
+
const deleteSelectedFiles = useCallback(()=>{
|
|
67
|
+
const objectsToDelete = selectedObjects.filter((object)=>"object" === object.type && object.Key).map((object)=>{
|
|
68
|
+
const deleteItem = {
|
|
69
|
+
Key: object.Key
|
|
70
|
+
};
|
|
71
|
+
if (object.VersionId && "string" == typeof object.VersionId) deleteItem.VersionId = object.VersionId;
|
|
72
|
+
return deleteItem;
|
|
73
|
+
});
|
|
74
|
+
const foldersToDelete = selectedObjects.filter((object)=>"folder" === object.type && object.Key).map((object)=>({
|
|
75
|
+
Key: object.Key
|
|
76
|
+
}));
|
|
77
|
+
deleteObjects({
|
|
78
|
+
Bucket: bucketName,
|
|
79
|
+
Delete: {
|
|
80
|
+
Objects: [
|
|
81
|
+
...objectsToDelete,
|
|
82
|
+
...foldersToDelete
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
}, {
|
|
86
|
+
onSuccess: ()=>{
|
|
87
|
+
showToast({
|
|
88
|
+
open: true,
|
|
89
|
+
message: "Objects deleted successfully",
|
|
90
|
+
status: "success"
|
|
91
|
+
});
|
|
92
|
+
setIsModalOpen(false);
|
|
93
|
+
},
|
|
94
|
+
onError: (error)=>{
|
|
95
|
+
showToast({
|
|
96
|
+
open: true,
|
|
97
|
+
message: error instanceof Error ? error.message : "Objects deleted failed",
|
|
98
|
+
status: "error"
|
|
99
|
+
});
|
|
100
|
+
setIsModalOpen(false);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}, [
|
|
104
|
+
bucketName,
|
|
105
|
+
selectedObjects,
|
|
106
|
+
deleteObjects,
|
|
107
|
+
showToast
|
|
108
|
+
]);
|
|
109
|
+
const totalSize = selectedObjects.reduce((acc, object)=>object.Size ? acc + object.Size : acc, 0);
|
|
110
|
+
useEffect(()=>{
|
|
111
|
+
setSelectedObjects(objects);
|
|
112
|
+
}, [
|
|
113
|
+
objects
|
|
114
|
+
]);
|
|
115
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
116
|
+
children: [
|
|
117
|
+
/*#__PURE__*/ jsx(Button, {
|
|
118
|
+
id: "object-list-delete-button",
|
|
119
|
+
icon: /*#__PURE__*/ jsx(Icon, {
|
|
120
|
+
name: "Delete"
|
|
121
|
+
}),
|
|
122
|
+
variant: "danger",
|
|
123
|
+
disabled: 0 === selectedObjects.length,
|
|
124
|
+
onClick: handleDeleteClick,
|
|
125
|
+
label: "Delete"
|
|
126
|
+
}),
|
|
127
|
+
/*#__PURE__*/ jsxs(Modal, {
|
|
128
|
+
close: cancel,
|
|
129
|
+
footer: /*#__PURE__*/ jsxs(Wrap, {
|
|
130
|
+
children: [
|
|
131
|
+
/*#__PURE__*/ jsx("p", {}),
|
|
132
|
+
/*#__PURE__*/ jsxs(Stack, {
|
|
133
|
+
children: [
|
|
134
|
+
/*#__PURE__*/ jsx(Button, {
|
|
135
|
+
id: "object-delete-cancel-button",
|
|
136
|
+
variant: "outline",
|
|
137
|
+
onClick: cancel,
|
|
138
|
+
label: "Cancel"
|
|
139
|
+
}),
|
|
140
|
+
/*#__PURE__*/ jsx(Button, {
|
|
141
|
+
isLoading: "pending" === deleteObjectsStatus,
|
|
142
|
+
id: "object-delete-delete-button",
|
|
143
|
+
variant: "danger",
|
|
144
|
+
onClick: deleteSelectedFiles,
|
|
145
|
+
disabled: 0 === selectedObjects.length,
|
|
146
|
+
label: "Delete"
|
|
147
|
+
})
|
|
148
|
+
]
|
|
149
|
+
})
|
|
150
|
+
]
|
|
151
|
+
}),
|
|
152
|
+
isOpen: isModalOpen,
|
|
153
|
+
title: "Confirmation",
|
|
154
|
+
children: [
|
|
155
|
+
/*#__PURE__*/ jsx(Box, {
|
|
156
|
+
children: /*#__PURE__*/ jsx(Title, {
|
|
157
|
+
objects: selectedObjects,
|
|
158
|
+
isCurrentSelectionPermanentlyDeleted: isCurrentSelectionPermanentlyDeleted
|
|
159
|
+
})
|
|
160
|
+
}),
|
|
161
|
+
/*#__PURE__*/ jsx(DeleteObjectModalContent, {
|
|
162
|
+
objects: selectedObjects,
|
|
163
|
+
onRemove: (key)=>{
|
|
164
|
+
setSelectedObjects(selectedObjects.filter((object)=>object.Key !== key));
|
|
165
|
+
}
|
|
166
|
+
}),
|
|
167
|
+
/*#__PURE__*/ jsxs(Box, {
|
|
168
|
+
mb: spacing.r12,
|
|
169
|
+
children: [
|
|
170
|
+
"Total: ",
|
|
171
|
+
PrettyBytes({
|
|
172
|
+
bytes: totalSize
|
|
173
|
+
})
|
|
174
|
+
]
|
|
175
|
+
}),
|
|
176
|
+
selectedObjects.length > 0 && notificationText && /*#__PURE__*/ jsx(Banner, {
|
|
177
|
+
variant: "base",
|
|
178
|
+
icon: /*#__PURE__*/ jsx(Icon, {
|
|
179
|
+
name: "Info-circle"
|
|
180
|
+
}),
|
|
181
|
+
children: /*#__PURE__*/ jsx("span", {
|
|
182
|
+
children: notificationText
|
|
183
|
+
})
|
|
184
|
+
})
|
|
185
|
+
]
|
|
186
|
+
})
|
|
187
|
+
]
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
const objects_DeleteObjectButton = DeleteObjectButton;
|
|
191
|
+
export { DeleteObjectButton, objects_DeleteObjectButton as default };
|