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-13337 - fix error edit lock setting #775

Merged
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
11 changes: 7 additions & 4 deletions src/react/databrowser/objects/ObjectLockSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ export default function ObjectLockSetting() {
useEffect(() => {
setValue('isRetentionEnabled', isDefaultRetentionEnabled);
setValue('retentionMode', defaultRetentionMode);
setValue('retentionUntilDate', defaultRetentionUntilDate);
setValue(
'retentionUntilDate',
DateTime.fromJSDate(defaultRetentionUntilDate).toFormat('yyyy-LL-dd'),
);
}, [
setValue,
isDefaultRetentionEnabled,
Expand Down Expand Up @@ -285,9 +288,9 @@ export default function ObjectLockSetting() {
type="date"
name="retention-until-date"
disabled={!isRetentionEnabled}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
onChange(e.target.value)
}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
onChange(e.target.value);
}}
value={retentionUntilDate}
min={minRetainUtilDate}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('ObjectLockSetting', () => {
bucketName: 'test-bucket',
objectRetention: {
mode: 'GOVERNANCE',
retainUntilDate: '2022-01-31 00:00:00"',
retainUntilDate: new Date('2022-01-31 00:00:00'),
},
},
},
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('ObjectLockSetting', () => {
bucketName: 'test-bucket',
objectRetention: {
mode: 'COMPLIANCE',
retainUntilDate: '2022-01-31 00:00:00"',
retainUntilDate: new Date('2022-01-31 00:00:00'),
},
},
},
Expand Down
77 changes: 34 additions & 43 deletions src/react/databrowser/objects/details/Properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Table, * as T from '../../../ui-elements/TableKeyValue2';
import { Clipboard } from '../../../ui-elements/Clipboard';
import MiddleEllipsis from '../../../ui-elements/MiddleEllipsis';
import type { ObjectMetadata } from '../../../../types/s3';
import type { ObjectEntity, ObjectMetadata } from '../../../../types/s3';
import {
FormattedDateTime,
Icon,
Expand Down Expand Up @@ -31,7 +31,7 @@ import {
} from '../../../ui-elements/Veeam/VeeamConstants';

type Props = {
objectMetadata: ObjectMetadata;
objectMetadata: ObjectMetadata & { lockStatus?: ObjectEntity['lockStatus'] };
};
const TruncatedValue = styled.div`
max-width: 18rem;
Expand Down Expand Up @@ -203,47 +203,38 @@ function Properties({ objectMetadata }: Props) {
<T.Key> Lock </T.Key>
<T.GroupValues>
<div>
{
//@ts-expect-error fix this when you are working on it
objectMetadata.lockStatus === 'LOCKED' && (
<>
Locked <Icon name="Lock" /> (
{objectMetadata.objectRetention.mode.toLowerCase()})
<br />
until{' '}
<FormattedDateTime
format="date-time-second"
value={
new Date(
objectMetadata.objectRetention.retainUntilDate,
)
}
/>
</>
)
}
{
//@ts-expect-error fix this when you are working on it
objectMetadata.lockStatus === 'RELEASED' && (
<>
Released <Icon name="Lock-open" />
<br />
since{' '}
<FormattedDateTime
format="date-time-second"
value={
new Date(
objectMetadata.objectRetention.retainUntilDate,
)
}
/>
</>
)
}
{
//@ts-expect-error fix this when you are working on it
objectMetadata.lockStatus === 'NONE' && 'No retention'
}
{objectMetadata.lockStatus === 'LOCKED' && (
<>
Locked <Icon name="Lock" /> (
{objectMetadata.objectRetention.mode.toLowerCase()})
<br />
until{' '}
<FormattedDateTime
format="date-time-second"
value={
new Date(
objectMetadata.objectRetention.retainUntilDate,
)
}
/>
</>
)}
{objectMetadata.lockStatus === 'RELEASED' && (
<>
Released <Icon name="Lock-open" />
<br />
since{' '}
<FormattedDateTime
format="date-time-second"
value={
new Date(
objectMetadata.objectRetention.retainUntilDate,
)
}
/>
</>
)}
{objectMetadata.lockStatus === 'NONE' && 'No retention'}
</div>
{isObjectLockEnabled && (
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import Properties from '../Properties';
import { getConfigOverlay } from '../../../../../js/mock/managementClientMSWHandlers';

const renderProperties = (
component: React.ReactNode = <Properties objectMetadata={OBJECT_METADATA} />,
component: React.ReactNode = (
<Properties objectMetadata={{ ...OBJECT_METADATA, lockStatus: 'NONE' }} />
),
state = {},
) => {
return renderWithRouterMatch(
Expand Down Expand Up @@ -89,11 +91,10 @@ describe('Properties', () => {
<Properties
objectMetadata={{
...OBJECT_METADATA,
//@ts-expect-error fix this when you are working on it
lockStatus: 'LOCKED',
objectRetention: {
mode: 'GOVERNANCE',
retainUntilDate: '2020-10-17 10:06:54',
retainUntilDate: new Date('2020-10-17 10:06:54'),
},
}}
/>,
Expand All @@ -120,11 +121,10 @@ describe('Properties', () => {
<Properties
objectMetadata={{
...OBJECT_METADATA,
//@ts-expect-error fix this when you are working on it
lockStatus: 'RELEASED',
objectRetention: {
mode: 'GOVERNANCE',
retainUntilDate: '2020-10-17 10:06:54',
retainUntilDate: new Date('2020-10-17 10:06:54'),
},
}}
/>,
Expand All @@ -145,11 +145,10 @@ describe('Properties', () => {
<Properties
objectMetadata={{
...OBJECT_METADATA,
//@ts-expect-error fix this when you are working on it
lockStatus: 'LOCKED',
objectRetention: {
mode: 'GOVERNANCE',
retainUntilDate: '2020-10-17 10:06:54',
retainUntilDate: new Date('2020-10-17 10:06:54'),
},
isLegalHoldEnabled: true,
}}
Expand All @@ -168,11 +167,10 @@ describe('Properties', () => {
<Properties
objectMetadata={{
...OBJECT_METADATA,
//@ts-expect-error fix this when you are working on it
lockStatus: 'LOCKED',
objectRetention: {
mode: 'GOVERNANCE',
retainUntilDate: '2020-10-17 10:06:54',
retainUntilDate: new Date('2020-10-17 10:06:54'),
},
isLegalHoldEnabled: true,
storageClass: 'europe25-myroom-cold',
Expand Down Expand Up @@ -211,11 +209,10 @@ describe('Properties', () => {
<Properties
objectMetadata={{
...OBJECT_METADATA,
//@ts-expect-error fix this when you are working on it
lockStatus: 'LOCKED',
objectRetention: {
mode: 'GOVERNANCE',
retainUntilDate: '2020-10-17 10:06:54',
retainUntilDate: new Date('2020-10-17 10:06:54'),
},
isLegalHoldEnabled: true,
storageClass: 'europe25-myroom-cold',
Expand Down Expand Up @@ -259,11 +256,10 @@ describe('Properties', () => {
<Properties
objectMetadata={{
...OBJECT_METADATA,
//@ts-expect-error fix this when you are working on it
lockStatus: 'LOCKED',
objectRetention: {
mode: 'GOVERNANCE',
retainUntilDate: '2020-10-17 10:06:54',
retainUntilDate: new Date('2020-10-17 10:06:54'),
},
isLegalHoldEnabled: true,
storageClass: 'europe25-myroom-cold',
Expand Down
9 changes: 5 additions & 4 deletions src/react/databrowser/objects/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import type { ObjectMetadata } from '../../../types/s3';
function getDefaultRetention(objectMetadata: ObjectMetadata | null) {
const isDefaultRetentionEnabled =
objectMetadata?.objectRetention !== undefined;

const defaultRetentionUntilDate =
objectMetadata?.objectRetention?.retainUntilDate.split(' ')[0] || '';
objectMetadata?.objectRetention?.retainUntilDate;
const defaultRetentionMode =
objectMetadata?.objectRetention?.mode || 'GOVERNANCE';
return {
Expand All @@ -17,7 +18,7 @@ function getDefaultRetention(objectMetadata: ObjectMetadata | null) {

// input date format yyyy-mm-dd hh:mm:ss "2017-05-15 09:24:15"
// get the min value for calendar picker in object retention setting, with yyyy-mm-dd as format
function getDefaultMinRetainUntilDate(d: string, mode: string): string {
function getDefaultMinRetainUntilDate(d: Date, mode: string): string {
const futureDate = DateTime.now()
.plus(
Duration.fromObject({
Expand All @@ -33,8 +34,8 @@ function getDefaultMinRetainUntilDate(d: string, mode: string): string {
// when we switch mode from "GOVERNANCE" to "COMPLIANCE", we should be able to keep the same previous retain date
const previousRetainUntilDate =
mode === 'GOVERNANCE'
? DateTime.fromSQL(d).toISODate()
: DateTime.fromSQL(d)
? DateTime.fromJSDate(d).toISODate()
: DateTime.fromJSDate(d)
.plus(
Duration.fromObject({
days: 1,
Expand Down
3 changes: 2 additions & 1 deletion src/react/locations/__tests__/LocationList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
import { INSTANCE_ID } from '../../actions/__tests__/utils/testUtil';
import { LocationsList } from '../LocationsList';

jest.setTimeout(30_000);

const server = setupServer(
getConfigOverlay(TEST_API_BASE_URL, INSTANCE_ID),
...getStorageConsumptionMetricsHandlers(
Expand All @@ -33,7 +35,6 @@ const server = setupServer(

describe('LocationList', () => {
beforeAll(() => {
jest.setTimeout(30_000);
mockOffsetSize(500, 100);
server.listen({ onUnhandledRequest: 'error' });
});
Expand Down
2 changes: 1 addition & 1 deletion src/types/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export type ObjectMetadata = {
readonly isLegalHoldEnabled?: boolean;
readonly objectRetention?: {
mode: RetentionMode;
retainUntilDate: string;
retainUntilDate: Date;
};
readonly metadata: MetadataItems;
readonly tags: Tags;
Expand Down
Loading