Skip to content

Commit

Permalink
Merge pull request #776 from scality/bugfix/ARTESCA-13337-cherry-pick
Browse files Browse the repository at this point in the history
Bugfix/artesca 13337 cherry pick
  • Loading branch information
xaf-scality committed Sep 20, 2024
2 parents 893185b + 70699f0 commit 97cd46c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 67 deletions.
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
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

0 comments on commit 97cd46c

Please sign in to comment.