Skip to content

Commit

Permalink
Translate appendInformationToField helper
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Mar 18, 2020
1 parent 2bc1fa5 commit e08ab39
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ describe('appendInformationToField', () => {
});
expect(res).toEqual('my value (updated at 2020-03-13T08:34:53.450Z by Elastic Test User)');
});

test('add mode', () => {
const res = appendInformationToField({
value: 'my value',
user: 'Elastic Test User',
date: '2020-03-13T08:34:53.450Z',
mode: 'add',
});
expect(res).toEqual('my value (added at 2020-03-13T08:34:53.450Z by Elastic Test User)');
});
});

describe('transformComments', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { Incident } from './lib/types';

import * as transformers from './transformers';
import * as i18n from './translations';

export const normalizeMapping = (supportedFields: string[], mapping: MapEntry[]): MapEntry[] => {
// Prevent prototype pollution and remove unsupported fields
Expand Down Expand Up @@ -96,10 +97,9 @@ export const appendInformationToField = ({
date,
mode = 'create',
}: AppendInformationFieldArgs): string => {
const action = mode === 'create' ? 'created at' : 'updated at';
return appendField({
value,
suffix: `(${action} ${date} by ${user})`,
suffix: i18n.FIELD_INFORMATION(mode, date, user),
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const informationCreated = ({
user,
...rest
}: TransformerArgs): TransformerArgs => ({
value: i18n.FIELD_INFORMATION('create', value, date, user),
value: `${value} ${i18n.FIELD_INFORMATION('create', date, user)}`,
...rest,
});

Expand All @@ -23,7 +23,7 @@ export const informationUpdated = ({
user,
...rest
}: TransformerArgs): TransformerArgs => ({
value: i18n.FIELD_INFORMATION('update', value, date, user),
value: `${value} ${i18n.FIELD_INFORMATION('update', date, user)}`,
...rest,
});

Expand All @@ -33,7 +33,7 @@ export const informationAdded = ({
user,
...rest
}: TransformerArgs): TransformerArgs => ({
value: i18n.FIELD_INFORMATION('add', value, date, user),
value: `${value} ${i18n.FIELD_INFORMATION('add', date, user)}`,
...rest,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,29 @@ export const UNEXPECTED_STATUS = (status: number) =>

export const FIELD_INFORMATION = (
mode: string,
value: string,
date: string | undefined,
user: string | undefined
) => {
switch (mode) {
case 'create':
return i18n.translate('xpack.actions.builtin.servicenow.informationCreated', {
values: { value, date, user },
defaultMessage: '{value} (created at {date} by {user})',
values: { date, user },
defaultMessage: '(created at {date} by {user})',
});
case 'update':
return i18n.translate('xpack.actions.builtin.servicenow.informationUpdated', {
values: { value, date, user },
defaultMessage: '{value} (updated at {date} by {user})',
values: { date, user },
defaultMessage: '(updated at {date} by {user})',
});
case 'add':
return i18n.translate('xpack.actions.builtin.servicenow.informationAdded', {
values: { value, date, user },
defaultMessage: '{value} (added at {date} by {user})',
values: { date, user },
defaultMessage: '(added at {date} by {user})',
});
default:
return i18n.translate('xpack.actions.builtin.servicenow.informationDefault', {
values: { value, date, user },
defaultMessage: '{value} (created at {date} by {user})',
values: { date, user },
defaultMessage: '(created at {date} by {user})',
});
}
};

0 comments on commit e08ab39

Please sign in to comment.