-
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.
Add
history_window_start
and refactor new_terms_fields
- Loading branch information
1 parent
d79f204
commit 8f9cc18
Showing
23 changed files
with
238 additions
and
100 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
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/security_solution/public/common/utils/history_window.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,28 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Converts a history start string to a history size string by removing the 'now-' prefix. | ||
* | ||
* @param historyStart - History start string to convert. For example, "now-30d". | ||
* @returns Converted size string. For example, "30d". | ||
*/ | ||
export const convertHistoryStartToSize = (historyStart: string) => { | ||
if (historyStart.startsWith('now-')) { | ||
return historyStart.substring(4); | ||
} else { | ||
return historyStart; | ||
} | ||
}; | ||
|
||
/** | ||
* Converts a history size string to a history start string by adding the 'now-' prefix. | ||
* | ||
* @param historySize - History size string to convert. For example, "30d". | ||
* @returns Converted start string. For example, "now-30d". | ||
*/ | ||
export const convertHistorySizeToStart = (historySize: string) => `now-${historySize}`; |
24 changes: 24 additions & 0 deletions
24
...n_engine/rule_creation/components/history_window_start_edit/history_window_start_edit.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,24 @@ | ||
/* | ||
* 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 { ScheduleItemField } from '../schedule_item_field'; | ||
import { UseField } from '../../../../shared_imports'; | ||
|
||
const componentProps = { | ||
idAria: 'historyWindowSize', | ||
dataTestSubj: 'historyWindowSize', | ||
timeTypes: ['m', 'h', 'd'], | ||
}; | ||
|
||
interface HistoryWindowStartEditProps { | ||
path: string; | ||
} | ||
|
||
export function HistoryWindowStartEdit({ path }: HistoryWindowStartEditProps): JSX.Element { | ||
return <UseField path={path} component={ScheduleItemField} componentProps={componentProps} />; | ||
} |
8 changes: 8 additions & 0 deletions
8
...tion/public/detection_engine/rule_creation/components/history_window_start_edit/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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { HistoryWindowStartEdit } from './history_window_start_edit'; |
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
24 changes: 24 additions & 0 deletions
24
...detection_engine/rule_creation/components/new_terms_fields_edit/new_terms_fields_edit.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,24 @@ | ||
/* | ||
* 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, { useMemo } from 'react'; | ||
import type { DataViewFieldBase } from '@kbn/es-query'; | ||
import { UseField } from '../../../../shared_imports'; | ||
import { NewTermsFieldsEditField } from './new_terms_fields_edit_field'; | ||
|
||
interface NewTermsFieldsEditProps { | ||
path: string; | ||
browserFields: DataViewFieldBase[]; | ||
} | ||
|
||
export function NewTermsFieldsEdit({ path, browserFields }: NewTermsFieldsEditProps): JSX.Element { | ||
const componentProps = useMemo(() => ({ browserFields }), [browserFields]); | ||
|
||
return ( | ||
<UseField path={path} component={NewTermsFieldsEditField} componentProps={componentProps} /> | ||
); | ||
} |
42 changes: 42 additions & 0 deletions
42
...ion_engine/rule_creation/components/new_terms_fields_edit/new_terms_fields_edit_field.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,42 @@ | ||
/* | ||
* 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, { useMemo } from 'react'; | ||
|
||
import type { DataViewFieldBase } from '@kbn/es-query'; | ||
import type { FieldHook } from '../../../../shared_imports'; | ||
import { Field } from '../../../../shared_imports'; | ||
import { NEW_TERMS_FIELD_PLACEHOLDER } from './translations'; | ||
|
||
interface NewTermsFieldsProps { | ||
browserFields: DataViewFieldBase[]; | ||
field: FieldHook; | ||
} | ||
|
||
const FIELD_COMBO_BOX_WIDTH = 410; | ||
|
||
const fieldDescribedByIds = 'newTermsFieldEdit'; | ||
|
||
export const NewTermsFieldsEditFieldComponent: React.FC<NewTermsFieldsProps> = ({ | ||
browserFields, | ||
field, | ||
}: NewTermsFieldsProps) => { | ||
const fieldEuiFieldProps = useMemo( | ||
() => ({ | ||
fullWidth: true, | ||
noSuggestions: false, | ||
options: browserFields.map((browserField) => ({ label: browserField.name })), | ||
placeholder: NEW_TERMS_FIELD_PLACEHOLDER, | ||
onCreateOption: undefined, | ||
style: { width: `${FIELD_COMBO_BOX_WIDTH}px` }, | ||
}), | ||
[browserFields] | ||
); | ||
return <Field field={field} idAria={fieldDescribedByIds} euiFieldProps={fieldEuiFieldProps} />; | ||
}; | ||
|
||
export const NewTermsFieldsEditField = React.memo(NewTermsFieldsEditFieldComponent); |
8 changes: 8 additions & 0 deletions
8
...ty_solution/public/detection_engine/rule_creation/components/schedule_item_field/index.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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { ScheduleItemField } from './schedule_item_field'; |
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
File renamed without changes.
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
13 changes: 13 additions & 0 deletions
13
...ree_way_diff/final_edit/fields/history_window_start/history_window_start_edit_adapter.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,13 @@ | ||
/* | ||
* 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 { HistoryWindowStartEdit } from '../../../../../../../rule_creation/components/history_window_start_edit'; | ||
|
||
export function HistoryWindowStartEditAdapter(): JSX.Element { | ||
return <HistoryWindowStartEdit path="historyWindowSize" />; | ||
} |
Oops, something went wrong.