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

ARTESCA-12290 ARTESCA-12108 ARTESCA-12369 #754

Merged
merged 3 commits into from
May 28, 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
1 change: 1 addition & 0 deletions src/js/mock/S3Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const bucketInfoResponseVersioningDisabled: BucketInfo = {
ObjectLockEnabled: 'Disabled',
},
};

export class MockS3Client implements S3ClientInterface {
listBucketsWithLocation() {
return Promise.resolve({
Expand Down
23 changes: 20 additions & 3 deletions src/js/mock/S3ClientMSWHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,21 @@ export function mockBucketOperations(
slowdown = false,
forceFailure = false,
isVeeamTagged = false,
isObjectLockEnabled = true,
}: {
location?: string | ((bucketName: string) => string);
isVersioningEnabled?: boolean | ((bucketName: string) => boolean);
slowdown?: boolean;
forceFailure?: boolean;
isVeeamTagged?: boolean | ((bucketName: string) => boolean);
isObjectLockEnabled?: boolean;
} = {
location: '',
isVersioningEnabled: false,
slowdown: false,
forceFailure: false,
isVeeamTagged: false,
isObjectLockEnabled: true,
},
) {
return rest.get(
Expand Down Expand Up @@ -152,14 +155,28 @@ export function mockBucketOperations(
}

if (req.url.searchParams.has('object-lock')) {
return res(
ctx.xml(`
if (isObjectLockEnabled) {
return res(
ctx.xml(`
<?xml version="1.0" encoding="UTF-8"?>
<ObjectLockConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<ObjectLockEnabled>Enabled</ObjectLockEnabled>
</ObjectLockConfiguration>
`),
);
);
} else {
return res(
ctx.status(404),
ctx.xml(
`<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>ObjectLockConfigurationNotFoundError</Code>
<Resource></Resource>
<RequestId>771ff09e6b408a3e5ed8</RequestId>
</Error>`,
),
);
}
}

if (req.url.searchParams.has('tagging')) {
Expand Down
4 changes: 4 additions & 0 deletions src/react/account/AwsPaginatedResourceTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ const AwsPaginatedResourceTable = <ENTITY, PREPARED_ENTITY = ENTITY>({
value={search}
placeholder={'Search'}
disableToggle
onReset={() => {
queryParams.delete(SEARCH_QUERY_PARAM);
history.push(`${match.url}?${queryParams.toString()}`);
}}
onChange={(evt: ChangeEvent<HTMLInputElement>) => {
setSearch(evt.target.value);
}}
Expand Down
10 changes: 5 additions & 5 deletions src/react/databrowser/buckets/BucketCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ function BucketCreate() {
}) => {
clearServerError();
let lName = locationName;

const location = accountsLocationsAndEndpoints?.locations.find(
(location) => location.name === locationName,
);
if (
isAsyncNotification &&
//@ts-expect-error fix this when you are working on it
locations &&
//@ts-expect-error fix this when you are working on it
isIngestLocation(locations[locationName], capabilities)
location &&
isIngestLocation(location, capabilities)
) {
lName = `${locationName}:ingest`;
}
Expand Down
30 changes: 23 additions & 7 deletions src/react/databrowser/buckets/details/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ const workflowAttachedError = (count: number, bucketName: string) => (
</div>
);

function VersionningValue({ bucketInfo }: { bucketInfo: BucketInfo }) {
function VersionningValue({
bucketInfo,
isVeeamBucket,
}: {
bucketInfo: BucketInfo;
isVeeamBucket: boolean;
}) {
const dispatch = useDispatch();
const accountsLocationsEndpointsAdapter =
useAccountsLocationsEndpointsAdapter();
Expand All @@ -114,6 +120,11 @@ function VersionningValue({ bucketInfo }: { bucketInfo: BucketInfo }) {
},
});
};
const isVersioningToggleDisabled =
locationsStatus === 'idle' ||
locationsStatus === 'loading' ||
isBucketHostedOnAzureOrGCP ||
isVeeamBucket;

return (
<T.Value>
Expand All @@ -130,15 +141,17 @@ function VersionningValue({ bucketInfo }: { bucketInfo: BucketInfo }) {
Enabling versioning is not possible due to the bucket being
hosted on Google Cloud.
</>
) : isVeeamBucket ? (
<>
Enabling versioning is not possible due to the bucket being
managed by Veeam.
</>
) : null
}
>
<Toggle
disabled={
locationsStatus === 'idle' ||
locationsStatus === 'loading' ||
isBucketHostedOnAzureOrGCP
}
id="versioningToggle"
disabled={isVersioningToggleDisabled}
toggle={bucketInfo.isVersioning}
label={
bucketInfo.versioning === 'Enabled'
Expand Down Expand Up @@ -285,7 +298,10 @@ function Overview({ bucket, ingestionStates }: Props) {
</T.Row>
<T.Row>
<T.Key> Versioning </T.Key>
<VersionningValue bucketInfo={bucketInfo} />
<VersionningValue
bucketInfo={bucketInfo}
isVeeamBucket={isVeeamBucket}
/>
</T.Row>
<T.Row>
<T.Key> Location </T.Key>
Expand Down
71 changes: 42 additions & 29 deletions src/react/databrowser/buckets/details/__tests__/Overview.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
fireEvent,
render,
screen,
waitFor,
Expand Down Expand Up @@ -195,17 +194,8 @@ describe('Overview', () => {
);
await waitForElementToBeRemoved(() => screen.getByText(/loading/i));
await waitFor(() => {
expect(
screen.getByRole('checkbox', {
name: /inactive/i,
}),
).toBeInTheDocument();
});
const versioningToggleItem = screen.getByRole('checkbox', {
name: /inactive/i,
expect(selectors.inActiveVersioningToggle()).toHaveAttribute('disabled');
});
//V
expect(versioningToggleItem).toHaveAttribute('disabled');
});
});

Expand Down Expand Up @@ -302,6 +292,8 @@ const selectors = {
screen.getByRole('generic', {
name: /indicate if object lock is enabled/i,
}),
inActiveVersioningToggle: () =>
screen.getByRole('checkbox', { name: /inactive/i }),
};

describe('Overview', () => {
Expand All @@ -312,32 +304,23 @@ describe('Overview', () => {
useUpdateBucketVersioningMock(req.body);
return res(ctx.status(200));
}),
mockBucketOperations({
isVersioningEnabled: false,
isObjectLockEnabled: false,
}),
);

renderWithRouterMatch(
render(
<Overview
//@ts-expect-error fix this when you are working on it
bucket={BUCKET}
bucket={{ name: bucketName }}
/>,
undefined,
{
...TEST_STATE,
...{ s3: { bucketInfo: bucketInfoResponseVersioningDisabled } },
},
{ wrapper: NewWrapper() },
);

const versioningToggleItem = screen
.getByRole('checkbox', {
name: /inactive/i,
})
.querySelector('input');

await waitFor(() => {
expect(versioningToggleItem).toBeInTheDocument();
expect(selectors.inActiveVersioningToggle()).toBeEnabled();
});

versioningToggleItem && fireEvent.click(versioningToggleItem);

await userEvent.click(selectors.inActiveVersioningToggle());
await waitFor(() => {
expect(useUpdateBucketVersioningMock).toHaveBeenCalledWith(mockResponse);
});
Expand Down Expand Up @@ -411,4 +394,34 @@ describe('Overview', () => {
expect(selectors.bucketTaggingErorToastQuery()).toBe(null);
});
});

it('should disable the versioning toggle for Veeam bucket', async () => {
//S
server.use(
mockBucketOperations({
isVersioningEnabled: false,
isVeeamTagged: true,
isObjectLockEnabled: false,
}),
);
//E
render(
<Overview
//@ts-expect-error fix this when you are working on it
bucket={{ name: bucketName }}
/>,
{ wrapper: NewWrapper() },
);
//V
await waitFor(() => {
expect(selectors.inActiveVersioningToggle()).toBeInTheDocument();
});

// toBeDisabled() works only with the following element, but not with label.
// https://html.spec.whatwg.org/multipage/semantics-other.html#disabled-elements
// https://github.com/testing-library/jest-dom/blob/e8c8b13c6de2a0ccffaa6539809c8c11f141beca/src/to-be-disabled.js#L71
await waitFor(() => {
expect(selectors.inActiveVersioningToggle()).toHaveAttribute('disabled');
});
});
});
Loading