Skip to content

Commit

Permalink
ARTESCA-12108: Disable the version toogle for Veeam bucket and adding…
Browse files Browse the repository at this point in the history
… a tooltip of explaination
  • Loading branch information
ChengYanJin committed May 7, 2024
1 parent 8c89610 commit 9838dbd
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 30 deletions.
16 changes: 16 additions & 0 deletions src/js/mock/S3Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,22 @@ export const bucketInfoResponseVersioningDisabled: BucketInfo = {
ObjectLockEnabled: 'Disabled',
},
};

export const BucketWithObjectLockDisabled: BucketInfo = {
name: bucketName,
policy: false,
owner: ownerName,
aclGrantees: 0,
cors: false,
versioning: 'Disabled',
isVersioning: false,
public: false,
locationConstraint: '',
objectLockConfiguration: {
ObjectLockEnabled: 'Disabled',
},
};

export class MockS3Client implements S3ClientInterface {
listBucketsWithLocation() {
return Promise.resolve({
Expand Down
32 changes: 24 additions & 8 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 @@ -284,8 +297,11 @@ function Overview({ bucket, ingestionStates }: Props) {
</T.Value>
</T.Row>
<T.Row>
<T.Key> Versioning </T.Key>
<VersionningValue bucketInfo={bucketInfo} />
<T.Key id="versioningToggle-label"> Versioning </T.Key>
<VersionningValue
bucketInfo={bucketInfo}
isVeeamBucket={isVeeamBucket}
/>
</T.Row>
<T.Row>
<T.Key> Location </T.Key>
Expand Down
49 changes: 27 additions & 22 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 All @@ -9,6 +8,7 @@ import {
import userEvent from '@testing-library/user-event';
import Immutable from 'immutable';
import {
BucketWithObjectLockDisabled,
bucketInfoResponseNoVersioning,
bucketInfoResponseObjectLockDefaultRetention,
bucketInfoResponseObjectLockNoDefaultRetention,
Expand Down Expand Up @@ -195,17 +195,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.versioningToggle()).toBeDisabled();
});
//V
expect(versioningToggleItem).toHaveAttribute('disabled');
});
});

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

describe('Overview', () => {
Expand All @@ -322,22 +314,14 @@ describe('Overview', () => {
undefined,
{
...TEST_STATE,
...{ s3: { bucketInfo: bucketInfoResponseVersioningDisabled } },
...{ s3: { bucketInfo: BucketWithObjectLockDisabled } },
},
);

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

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

versioningToggleItem && fireEvent.click(versioningToggleItem);

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

it('should disable the versioning toggle for Veeam bucket', async () => {
//S
server.use(mockGetBucketTagging(bucketName));
//E
render(
<Overview
//@ts-expect-error fix this when you are working on it
bucket={{ name: bucketName }}
/>,
{
wrapper: NewWrapper('/', {
s3: { bucketInfo: BucketWithObjectLockDisabled },
}),
},
);
//V
await waitFor(() => {
expect(selectors.versioningToggle()).toBeDisabled();
});
});
});

0 comments on commit 9838dbd

Please sign in to comment.