-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ce6eaa
commit 0a1c401
Showing
19 changed files
with
247 additions
and
430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
x-pack/plugins/security_solution/public/detections/components/rules/rule_info/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { CreatedBy, UpdatedBy } from '.'; | ||
import { render } from '@testing-library/react'; | ||
import { TestProviders } from '../../../../common/mock'; | ||
|
||
describe('Rule related info', () => { | ||
describe('<CreatedBy />', () => { | ||
it('should render created correctly when by and date are passed', () => { | ||
const { getByTestId } = render( | ||
<TestProviders> | ||
<CreatedBy | ||
id="id" | ||
createdBy="test" | ||
createdAt="2023-01-01T22:01:00.000Z" | ||
data-test-subj="createdBy" | ||
/> | ||
</TestProviders> | ||
); | ||
expect(getByTestId('createdBy')).toHaveTextContent( | ||
'Created by: test on Jan 1, 2023 @ 22:01:00.000' | ||
); | ||
}); | ||
|
||
it('should render created unknown when created by is not available', () => { | ||
const { getByTestId } = render( | ||
<TestProviders> | ||
<CreatedBy id="id" createdAt="2023-01-01T22:01:00.000Z" data-test-subj="createdBy" /> | ||
</TestProviders> | ||
); | ||
expect(getByTestId('createdBy')).toHaveTextContent( | ||
'Created by: Unknown on Jan 1, 2023 @ 22:01:00.000' | ||
); | ||
}); | ||
}); | ||
describe('<UpdatedBy />', () => { | ||
it('should render updated by correctly when by and date are passed', () => { | ||
const { getByTestId } = render( | ||
<TestProviders> | ||
<UpdatedBy | ||
id="id" | ||
updatedBy="test" | ||
updatedAt="2023-01-01T22:01:00.000Z" | ||
data-test-subj="updatedBy" | ||
/> | ||
</TestProviders> | ||
); | ||
expect(getByTestId('updatedBy')).toHaveTextContent( | ||
'Updated by: test on Jan 1, 2023 @ 22:01:00.000' | ||
); | ||
}); | ||
|
||
it('should render updated by correctly when updated by is not available', () => { | ||
const { getByTestId } = render( | ||
<TestProviders> | ||
<UpdatedBy id="id" updatedAt="2023-01-01T22:01:00.000Z" data-test-subj="updatedBy" /> | ||
</TestProviders> | ||
); | ||
expect(getByTestId('updatedBy')).toHaveTextContent( | ||
'Updated by: Unknown on Jan 1, 2023 @ 22:01:00.000' | ||
); | ||
}); | ||
}); | ||
}); |
79 changes: 79 additions & 0 deletions
79
x-pack/plugins/security_solution/public/detections/components/rules/rule_info/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { UNKNOWN_TEXT } from './translations'; | ||
import { FormattedDate } from '../../../../common/components/formatted_date'; | ||
|
||
interface CreatedByProps { | ||
id: string; | ||
createdBy?: string; | ||
createdAt?: string; | ||
['data-test-subj']?: string; | ||
} | ||
|
||
/** | ||
* Created by and created at text that are shown on rule details | ||
*/ | ||
export const CreatedBy: React.FC<CreatedByProps> = ({ | ||
id, | ||
createdBy, | ||
createdAt, | ||
'data-test-subj': dataTestSubj, | ||
}) => { | ||
return ( | ||
<div data-test-subj={dataTestSubj}> | ||
<FormattedMessage | ||
id={id} | ||
defaultMessage="Created by: {by} on {date}" | ||
values={{ | ||
by: createdBy ?? UNKNOWN_TEXT, | ||
date: ( | ||
<FormattedDate value={createdAt ?? new Date().toISOString()} fieldName="createdAt" /> | ||
), | ||
}} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
CreatedBy.displayName = 'CreatedBy'; | ||
|
||
interface UpdatedByProps { | ||
id: string; | ||
updatedBy?: string; | ||
updatedAt?: string; | ||
['data-test-subj']?: string; | ||
} | ||
|
||
/** | ||
* Updated by and updated at text that are shown on rule details | ||
*/ | ||
export const UpdatedBy: React.FC<UpdatedByProps> = ({ | ||
id, | ||
updatedBy, | ||
updatedAt, | ||
'data-test-subj': dataTestSubj, | ||
}) => { | ||
return ( | ||
<div data-test-subj={dataTestSubj}> | ||
<FormattedMessage | ||
id={id} | ||
defaultMessage="Updated by: {by} on {date}" | ||
values={{ | ||
by: updatedBy ?? UNKNOWN_TEXT, | ||
date: ( | ||
<FormattedDate value={updatedAt ?? new Date().toISOString()} fieldName="updatedAt" /> | ||
), | ||
}} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
UpdatedBy.displayName = 'UpdatedBy'; |
15 changes: 15 additions & 0 deletions
15
...ck/plugins/security_solution/public/detections/components/rules/rule_info/translations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const UNKNOWN_TEXT = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.ruleInfo.UnknownText', | ||
{ | ||
defaultMessage: 'Unknown', | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.