Skip to content

Commit

Permalink
[Index Management] Fix globalMaxRetention display error in data reten…
Browse files Browse the repository at this point in the history
…tion modal
  • Loading branch information
viajes7 committed Oct 29, 2024
1 parent 686b021 commit 4b672e3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { getLifecycleValue } from './data_streams';
import { deserializeGlobalMaxRetention, getLifecycleValue } from './data_streams';

describe('Data stream helpers', () => {
describe('getLifecycleValue', () => {
Expand Down Expand Up @@ -45,4 +45,18 @@ describe('Data stream helpers', () => {
).toBe('5 days');
});
});

describe('deserializeGlobalMaxRetention', () => {
it('if globalMaxRetention is undefined', () => {
expect(deserializeGlobalMaxRetention(undefined)).toEqual({});
});

it('split globalMaxRetention size and units ', () => {
expect(deserializeGlobalMaxRetention('1000h')).toEqual({
size: '1000',
unit: 'h',
unitText: 'hours',
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,18 @@ export const isDSLWithILMIndices = (dataStream?: DataStream | null) => {

return;
};

export const deserializeGlobalMaxRetention = (globalMaxRetention?: string) => {
if (!globalMaxRetention) {
return {};
}

const { size, unit } = splitSizeAndUnits(globalMaxRetention);
const unitText = timeUnits.find((item) => item.value === unit)?.text;

return {
size,
unit,
unitText,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { getIndexListUri } from '../../../../services/routing';
import { documentationService } from '../../../../services/documentation';
import { splitSizeAndUnits, DataStream } from '../../../../../../common';
import { timeUnits } from '../../../../constants/time_units';
import { isDSLWithILMIndices } from '../../../../lib/data_streams';
import { deserializeGlobalMaxRetention, isDSLWithILMIndices } from '../../../../lib/data_streams';
import { useAppContext } from '../../../../app_context';
import { UnitField } from '../../../../components/shared';
import { updateDataRetention } from '../../../../services/api';
Expand Down Expand Up @@ -214,6 +214,7 @@ export const EditDataRetentionModal: React.FunctionComponent<Props> = ({
const { history } = useAppContext();
const dslWithIlmIndices = isDSLWithILMIndices(dataStream);
const { size, unit } = splitSizeAndUnits(lifecycle?.data_retention as string);
const globalMaxRetention = deserializeGlobalMaxRetention(lifecycle?.globalMaxRetention);
const {
services: { notificationService },
config: { enableTogglingDataRetention, enableProjectLevelRetentionChecks },
Expand Down Expand Up @@ -331,8 +332,11 @@ export const EditDataRetentionModal: React.FunctionComponent<Props> = ({
<>
<FormattedMessage
id="xpack.idxMgmt.dataStreamsDetailsPanel.editDataRetentionModal.modalTitleText"
defaultMessage="Maximum data retention period is {maxRetention} days"
values={{ maxRetention: lifecycle?.globalMaxRetention.slice(0, -1) }}
defaultMessage="Maximum data retention period is {maxRetention} {unitText}"
values={{
maxRetention: globalMaxRetention.size,
unitText: globalMaxRetention.unitText,
}}
/>
<EuiSpacer />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { i18n } from '@kbn/i18n';
import { splitSizeAndUnits } from '../../../../../../common';
import { deserializeGlobalMaxRetention } from '../../../../lib/data_streams';

const convertToMinutes = (value: string) => {
const { size, unit } = splitSizeAndUnits(value);
Expand Down Expand Up @@ -46,14 +47,19 @@ export const isBiggerThanGlobalMaxRetention = (
return undefined;
}

const { size, unitText } = deserializeGlobalMaxRetention(globalMaxRetention);
return isRetentionBiggerThan(`${retentionValue}${retentionTimeUnit}`, globalMaxRetention)
? {
message: i18n.translate(
'xpack.idxMgmt.dataStreamsDetailsPanel.editDataRetentionModal.dataRetentionFieldMaxError',
{
defaultMessage: 'Maximum data retention period on this project is {maxRetention} days.',
defaultMessage:
'Maximum data retention period on this project is {maxRetention} {unitText}.',
// Remove the unit from the globalMaxRetention value
values: { maxRetention: globalMaxRetention.slice(0, -1) },
values: {
maxRetention: size,
unitText,
},
}
),
}
Expand Down

0 comments on commit 4b672e3

Please sign in to comment.