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

Hotfix/2.2 #767

Closed
wants to merge 5 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ coverage
.DS_Store

build
build_ts
10 changes: 9 additions & 1 deletion src/react/actions/s3object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { LIST_OBJECT_VERSIONS_S3_TYPE } from '../utils/s3';
import type { Marker, ZenkoClient } from '../../types/zenko';
import { getClients } from '../utils/actions';
import { newSearchListing } from '.';
import { QueryClient } from 'react-query';

export const UPLOADING_OBJECT = 'Uploading object(s)';
export function listObjectsSuccess(
Expand Down Expand Up @@ -178,17 +179,22 @@ export function resetObjectMetadata(): ResetObjectMetadataAction {
type: 'RESET_OBJECT_METADATA',
};
}

export function createFolder(
bucketName: string,
prefixWithSlash: string,
folderName: string,
queryClient: QueryClient,
): ThunkStatePromisedAction {
return (dispatch, getState) => {
const { zenkoClient } = getClients(getState());
dispatch(networkStart('Creating folder'));
return zenkoClient
.createFolder(bucketName, prefixWithSlash, folderName)
.then(() => dispatch(listObjects(bucketName, prefixWithSlash)))
.then(() => {
queryClient.removeQueries(['objectVersions', bucketName]);
dispatch(listObjects(bucketName, prefixWithSlash));
})
.catch((error) => dispatch(handleAWSClientError(error)))
.catch((error) => dispatch(handleAWSError(error, 'byComponent')))
.finally(() => {
Expand Down Expand Up @@ -447,6 +453,7 @@ export function uploadFiles(
bucketName: string,
prefixWithSlash: string,
files: Array<File>,
queryClient: QueryClient,
): ThunkStatePromisedAction {
return (dispatch, getState) => {
const { zenkoClient } = getClients(getState());
Expand All @@ -455,6 +462,7 @@ export function uploadFiles(
return zenkoClient
.uploadObject(bucketName, prefixWithSlash, files)
.then(() => {
queryClient.removeQueries(['objectVersions', bucketName]);
dispatch(listObjects(bucketName, prefixWithSlash));
})
.catch((error) => {
Expand Down
10 changes: 9 additions & 1 deletion src/react/databrowser/objects/FolderCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { AppState } from '../../../types/state';
import { closeFolderCreateModal, createFolder } from '../../actions';
import { CustomModal as Modal } from '../../ui-elements/Modal';
import { addTrailingSlash } from '../../utils';
import { useQueryClient } from 'react-query';
export const Description = styled.div`
margin-top: ${spacing.sp16};
width: 20.5rem;
Expand All @@ -30,6 +31,8 @@ const FolderCreate = ({ bucketName, prefixWithSlash }: Props) => {
);
const dispatch: Dispatch<Action> = useDispatch();

const queryClient = useQueryClient();

if (!show) {
return null;
}
Expand All @@ -46,7 +49,12 @@ const FolderCreate = ({ bucketName, prefixWithSlash }: Props) => {

setFolderName('');
dispatch(
createFolder(bucketName, prefixWithSlash, addTrailingSlash(folderName)),
createFolder(
bucketName,
prefixWithSlash,
addTrailingSlash(folderName),
queryClient,
),
);
};

Expand Down
6 changes: 5 additions & 1 deletion src/react/databrowser/objects/ObjectUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { spacing } from '@scality/core-ui/dist/style/theme';
import styled from 'styled-components';
import { useDropzone } from 'react-dropzone';
import { usePrefixWithSlash } from '../../utils/hooks';
import { useQueryClient } from 'react-query';
const DropZone = styled.div`
flex: 1;
display: flex;
Expand Down Expand Up @@ -118,6 +119,7 @@ const ObjectUpload = ({ bucketName }: Props) => {
);
const dispatch: Dispatch<Action> = useDispatch();
const prefixWithSlash = usePrefixWithSlash();
const queryClient = useQueryClient();

const onDrop = (accepted, rejections) => {
if (accepted.length > 0) {
Expand Down Expand Up @@ -156,7 +158,9 @@ const ObjectUpload = ({ bucketName }: Props) => {

const upload = () => {
cleanFiles();
dispatch(uploadFiles(bucketName, prefixWithSlash, acceptedFiles));
dispatch(
uploadFiles(bucketName, prefixWithSlash, acceptedFiles, queryClient),
);
};

if (!show) {
Expand Down
5 changes: 2 additions & 3 deletions src/react/ui-elements/DeleteBucket/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ export const DeleteBucket = ({ bucketName }: DeleteBucketProps) => {
: 'Bucket is not empty'
}
overlayStyle={{
width: '9rem',
display: isBucketEmpty ? undefined : 'none',
display: isBucketEmpty ? 'none' : undefined,
}}
>
<Button
icon={<Icon name="Delete" />}
disabled={isBucketEmpty}
disabled={!isBucketEmpty}
variant="danger"
onClick={handleDeleteClick}
label="Delete Bucket"
Expand Down
5 changes: 3 additions & 2 deletions src/react/ui-elements/EmptyBucket/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export const EmptyBucket = ({ bucketName }: EmptyBucketProps) => {
refetchOnWindowFocus: false,
refetchOnMount: true,
refetchOnReconnect: false,
additionalDepsToUpdateQueryFn: [bucketName],
},
(data) => createDeleteObjectsData(data.DeleteMarkers, data.Versions),
);
Expand Down Expand Up @@ -209,12 +210,12 @@ export const EmptyBucket = ({ bucketName }: EmptyBucketProps) => {
}
overlayStyle={{
width: '9rem',
display: isBucketEmpty ? 'none' : undefined,
display: isBucketEmpty ? undefined : 'none',
}}
>
<Button
icon={<Icon name="Eraser" />}
disabled={!isBucketEmpty}
disabled={isBucketEmpty}
variant="danger"
onClick={handleEmptyClick}
label={EMPTY_CONFIRMATION_MODAL_TITLE}
Expand Down
9 changes: 7 additions & 2 deletions src/react/utils/IAMhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const useAwsPaginatedEntities = <
ENTITY,
TError,
MARKER_TYPE
>,
> & { additionalDepsToUpdateQueryFn?: unknown[] },
getEntitiesFromResult: (data: API_RESPONSE) => ENTITY[],
preventNextPagesRetrieval = false,
): AWS_PAGINATED_ENTITIES<ENTITY> => {
Expand Down Expand Up @@ -96,7 +96,7 @@ export const useAwsPaginatedEntities = <
>();
useEffect(() => {
ref.current = reactQueryOptions?.queryFn;
}, [token]);
}, [token, ...(reactQueryOptions.additionalDepsToUpdateQueryFn || [])]);
//--------------------------------------------------------------------

const {
Expand All @@ -116,16 +116,19 @@ export const useAwsPaginatedEntities = <
return ref.current?.(ctx, ctx.pageParam);
},
});

const pageIndex = data?.pageParams?.length || 0;
const entities =
data &&
data.pages &&
data.pages.flatMap((page) => getEntitiesFromResult(page));

useMemo(() => {
if (pageIndex === 0 || (pageIndex === 1 && internalStatus === 'success')) {
setFirstPageStatus(internalStatus);
}
}, [internalStatus, pageIndex]);

useMemo(() => {
if (
internalStatus === 'idle' ||
Expand Down Expand Up @@ -165,11 +168,13 @@ export const useAwsPaginatedEntities = <
firstPageStatus,
} as AWS_PAGINATED_ENTITIES<ENTITY>;
};

type AccessKeyObject = {
accessKey: string;
createdOn: string;
status: string;
};

export const useAccessKeyOutdatedStatus = (
accessKeyObject: AccessKeyObject,
) => {
Expand Down
10 changes: 4 additions & 6 deletions src/react/utils/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,10 @@ export const useCheckIfBucketEmpty = (bucketName: string) => {
);

const isBucketEmpty = object
? Boolean(
[
...(object.Versions ? object.Versions : []),
...(object.DeleteMarkers ? object.DeleteMarkers : []),
].length,
)
? ![
...(object.Versions ? object.Versions : []),
...(object.DeleteMarkers ? object.DeleteMarkers : []),
].length
: true;

return {
Expand Down
Loading