Skip to content

Commit

Permalink
ARTESCA-13337 - fix error edit lock setting
Browse files Browse the repository at this point in the history
  • Loading branch information
MonPote committed Sep 19, 2024
1 parent 1c4afa9 commit 594295f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 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 @@ -89,11 +89,10 @@ describe('Properties', () => {
<Properties
objectMetadata={{
...OBJECT_METADATA,
//@ts-expect-error fix this when you are working on it
lockStatus: 'LOCKED',

Check failure on line 92 in src/react/databrowser/objects/details/__tests__/Properties.test.tsx

View workflow job for this annotation

GitHub Actions / build-ui

Object literal may only specify known properties, and 'lockStatus' does not exist in type 'ObjectMetadata'.

Check failure on line 92 in src/react/databrowser/objects/details/__tests__/Properties.test.tsx

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'lockStatus' does not exist in type 'ObjectMetadata'.
objectRetention: {
mode: 'GOVERNANCE',
retainUntilDate: '2020-10-17 10:06:54',
retainUntilDate: new Date('2020-10-17 10:06:54'),
},
}}
/>,
Expand All @@ -120,11 +119,10 @@ describe('Properties', () => {
<Properties
objectMetadata={{
...OBJECT_METADATA,
//@ts-expect-error fix this when you are working on it
lockStatus: 'RELEASED',

Check failure on line 122 in src/react/databrowser/objects/details/__tests__/Properties.test.tsx

View workflow job for this annotation

GitHub Actions / build-ui

Object literal may only specify known properties, and 'lockStatus' does not exist in type 'ObjectMetadata'.

Check failure on line 122 in src/react/databrowser/objects/details/__tests__/Properties.test.tsx

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'lockStatus' does not exist in type 'ObjectMetadata'.
objectRetention: {
mode: 'GOVERNANCE',
retainUntilDate: '2020-10-17 10:06:54',
retainUntilDate: new Date('2020-10-17 10:06:54'),
},
}}
/>,
Expand All @@ -145,11 +143,10 @@ describe('Properties', () => {
<Properties
objectMetadata={{
...OBJECT_METADATA,
//@ts-expect-error fix this when you are working on it
lockStatus: 'LOCKED',

Check failure on line 146 in src/react/databrowser/objects/details/__tests__/Properties.test.tsx

View workflow job for this annotation

GitHub Actions / build-ui

Object literal may only specify known properties, and 'lockStatus' does not exist in type 'ObjectMetadata'.

Check failure on line 146 in src/react/databrowser/objects/details/__tests__/Properties.test.tsx

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'lockStatus' does not exist in type 'ObjectMetadata'.
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 +165,10 @@ describe('Properties', () => {
<Properties
objectMetadata={{
...OBJECT_METADATA,
//@ts-expect-error fix this when you are working on it
lockStatus: 'LOCKED',

Check failure on line 168 in src/react/databrowser/objects/details/__tests__/Properties.test.tsx

View workflow job for this annotation

GitHub Actions / build-ui

Object literal may only specify known properties, and 'lockStatus' does not exist in type 'ObjectMetadata'.

Check failure on line 168 in src/react/databrowser/objects/details/__tests__/Properties.test.tsx

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'lockStatus' does not exist in type 'ObjectMetadata'.
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 +207,10 @@ describe('Properties', () => {
<Properties
objectMetadata={{
...OBJECT_METADATA,
//@ts-expect-error fix this when you are working on it
lockStatus: 'LOCKED',

Check failure on line 210 in src/react/databrowser/objects/details/__tests__/Properties.test.tsx

View workflow job for this annotation

GitHub Actions / build-ui

Object literal may only specify known properties, and 'lockStatus' does not exist in type 'ObjectMetadata'.

Check failure on line 210 in src/react/databrowser/objects/details/__tests__/Properties.test.tsx

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'lockStatus' does not exist in type 'ObjectMetadata'.
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 +254,10 @@ describe('Properties', () => {
<Properties
objectMetadata={{
...OBJECT_METADATA,
//@ts-expect-error fix this when you are working on it
lockStatus: 'LOCKED',

Check failure on line 257 in src/react/databrowser/objects/details/__tests__/Properties.test.tsx

View workflow job for this annotation

GitHub Actions / build-ui

Object literal may only specify known properties, and 'lockStatus' does not exist in type 'ObjectMetadata'.

Check failure on line 257 in src/react/databrowser/objects/details/__tests__/Properties.test.tsx

View workflow job for this annotation

GitHub Actions / build

Object literal may only specify known properties, and 'lockStatus' does not exist in type 'ObjectMetadata'.
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 594295f

Please sign in to comment.