-
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.
## Summary Solves this issue: #161763 This PR introduces autocomplete for mustache variables for email connector(next PR will add it to all connectors) under the feature flag. We decided keep old solution with button with all searchable options as well. How to test: Create an email connector in kibana.yml: xpack.actions.preconfigured: maildev: name: 'email: maildev' actionTypeId: '.email' config: from: 'guskova@example.com' host: 'localhost' port: '1025' How it should work: You start writing in Message window {{ and mustache variable name. And you should see autocomplete popup with all possible options to choose. When you click somewhere else, popup should disappeared. https://github.com/elastic/kibana/assets/26089545/061016a6-b8ca-497b-9bed-b8b012d31a95 e options to choose. When you click somewhere else, popup should disappeared. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Xavier Mouligneau <xavier.mouligneau@elastic.co>
- Loading branch information
1 parent
a6aa865
commit 0af40a3
Showing
37 changed files
with
890 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import '@testing-library/jest-dom'; |
File renamed without changes.
7 changes: 4 additions & 3 deletions
7
...components/add_message_variables.test.tsx → .../src/add_message_variables/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
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
23 changes: 12 additions & 11 deletions
23
...ic/application/components/translations.js → ...src/add_message_variables/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
34 changes: 34 additions & 0 deletions
34
packages/kbn-alerts-ui-shared/src/add_message_variables/truncated_text.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,34 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { css } from '@emotion/react'; | ||
import { EuiText } from '@elastic/eui'; | ||
|
||
const LINE_CLAMP = 2; | ||
|
||
const styles = { | ||
truncatedText: css` | ||
text-overflow: ellipsis; | ||
display: -webkit-box; | ||
-webkit-line-clamp: ${LINE_CLAMP}; | ||
-webkit-box-orient: vertical; | ||
overflow: hidden; | ||
word-break: break-word; | ||
`, | ||
}; | ||
|
||
const TruncatedTextComponent: React.FC<{ text: string }> = ({ text }) => ( | ||
<EuiText size="xs" color="subdued" css={styles.truncatedText}> | ||
{text} | ||
</EuiText> | ||
); | ||
|
||
TruncatedTextComponent.displayName = 'TruncatedText'; | ||
|
||
export const TruncatedText = React.memo(TruncatedTextComponent); |
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
52 changes: 52 additions & 0 deletions
52
x-pack/plugins/stack_connectors/common/experimental_features.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,52 @@ | ||
/* | ||
* 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 type ExperimentalFeatures = typeof allowedExperimentalValues; | ||
|
||
/** | ||
* A list of allowed values that can be used in `xpack.stack_connectors.enableExperimental`. | ||
* This object is then used to validate and parse the value entered. | ||
*/ | ||
export const allowedExperimentalValues = Object.freeze({ | ||
isMustacheAutocompleteOn: false, | ||
}); | ||
|
||
type ExperimentalConfigKeys = Array<keyof ExperimentalFeatures>; | ||
type Mutable<T> = { -readonly [P in keyof T]: T[P] }; | ||
|
||
const InvalidExperimentalValue = class extends Error {}; | ||
const allowedKeys = Object.keys(allowedExperimentalValues) as Readonly<ExperimentalConfigKeys>; | ||
|
||
/** | ||
* Parses the string value used in `xpack.stack_connectors.enableExperimental` kibana configuration, | ||
* which should be a string of values delimited by a comma (`,`) | ||
* | ||
* @param configValue | ||
* @throws InvalidExperimentalValue | ||
*/ | ||
export const parseExperimentalConfigValue = (configValue: string[]): ExperimentalFeatures => { | ||
const enabledFeatures: Mutable<Partial<ExperimentalFeatures>> = {}; | ||
|
||
for (const value of configValue) { | ||
if (!isValidExperimentalValue(value)) { | ||
throw new InvalidExperimentalValue(`[${value}] is not valid.`); | ||
} | ||
// @ts-expect-error ts upgrade v4.7.4 | ||
enabledFeatures[value as keyof ExperimentalFeatures] = true; | ||
} | ||
|
||
return { | ||
...allowedExperimentalValues, | ||
...enabledFeatures, | ||
}; | ||
}; | ||
|
||
export const isValidExperimentalValue = (value: string): boolean => { | ||
return allowedKeys.includes(value as keyof ExperimentalFeatures); | ||
}; | ||
|
||
export const getExperimentalAllowedValues = (): string[] => [...allowedKeys]; |
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,10 @@ | ||
/* | ||
* 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 interface StackConnectorsConfigType { | ||
enableExperimental: string[]; | ||
} |
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
30 changes: 30 additions & 0 deletions
30
x-pack/plugins/stack_connectors/public/common/experimental_features_service.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,30 @@ | ||
/* | ||
* 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 { ExperimentalFeatures } from '../../common/experimental_features'; | ||
|
||
export class ExperimentalFeaturesService { | ||
private static experimentalFeatures?: ExperimentalFeatures; | ||
|
||
public static init({ experimentalFeatures }: { experimentalFeatures: ExperimentalFeatures }) { | ||
this.experimentalFeatures = experimentalFeatures; | ||
} | ||
|
||
public static get(): ExperimentalFeatures { | ||
if (!this.experimentalFeatures) { | ||
this.throwUninitializedError(); | ||
} | ||
|
||
return this.experimentalFeatures; | ||
} | ||
|
||
private static throwUninitializedError(): never { | ||
throw new Error( | ||
'Experimental features services not initialized - are you trying to import this module from outside of the stack connectors?' | ||
); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
x-pack/plugins/stack_connectors/public/common/get_experimental_features.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,27 @@ | ||
/* | ||
* 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 { | ||
ExperimentalFeatures, | ||
isValidExperimentalValue, | ||
getExperimentalAllowedValues, | ||
} from '../../common/experimental_features'; | ||
import { ExperimentalFeaturesService } from './experimental_features_service'; | ||
|
||
const allowedExperimentalValueKeys = getExperimentalAllowedValues(); | ||
|
||
export const getIsExperimentalFeatureEnabled = (feature: keyof ExperimentalFeatures): boolean => { | ||
if (!isValidExperimentalValue(feature)) { | ||
throw new Error( | ||
`Invalid enable value ${feature}. Allowed values are: ${allowedExperimentalValueKeys.join( | ||
', ' | ||
)}` | ||
); | ||
} | ||
|
||
return ExperimentalFeaturesService.get()[feature]; | ||
}; |
Oops, something went wrong.