Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RAM] Autocomplete #158454

Merged
Merged
Show file tree
Hide file tree
Changes from 85 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
2fb53d4
v1 automomplete
guskovaue May 25, 2023
33a479d
fix offset above message field
guskovaue May 28, 2023
7e67df9
v2 automomplete
guskovaue May 30, 2023
56d9391
rearrange functions in component
guskovaue May 30, 2023
3bb8aae
first version of autocomplete
guskovaue Jun 19, 2023
daceebe
Merge branch 'main' into RAM-158244-autocomplete-component-for-action…
guskovaue Jun 19, 2023
c22a5a8
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jun 19, 2023
b991478
temp
guskovaue Jun 20, 2023
d664d3e
fix algorithm for a case with a word in a middle
guskovaue Jun 22, 2023
9511db3
Merge branch 'RAM-158244-autocomplete-component-for-action-msg' of gi…
guskovaue Jun 22, 2023
a99d3a8
position of the auto-complete box
XavierM Jun 26, 2023
b7c26b5
use portal to simplify everything
XavierM Jun 28, 2023
49bcab6
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Jun 28, 2023
57d2913
add keyboard functionality
XavierM Jun 29, 2023
0e8318b
Merge branch 'RAM-158244-autocomplete-component-for-action-msg' of gi…
XavierM Jun 29, 2023
d019e42
show in the list full version of suggestions
guskovaue Jun 30, 2023
71b0ea1
make more beautiful
guskovaue Jun 30, 2023
d09da6a
highlight in the list written part
guskovaue Jun 30, 2023
df8af82
fix double words
guskovaue Jun 30, 2023
a82852c
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jun 30, 2023
fa4bfb7
fix outside click on autocomplete box
XavierM Jun 30, 2023
fb83c7a
Merge branch 'RAM-158244-autocomplete-component-for-action-msg' of gi…
XavierM Jun 30, 2023
cad56d1
calculate list height with matches
XavierM Jun 30, 2023
12be197
hide list when you click in the text area
guskovaue Jul 1, 2023
2873fd1
rewrite algorithm of filtering suggestions to include all possible op…
guskovaue Jul 3, 2023
b0f06f6
extract the function to lib file and write unit tests for it
guskovaue Jul 3, 2023
d75410f
stay focus on text area after picking a value
guskovaue Jul 3, 2023
7be48e6
add a little bit unit tests
guskovaue Jul 4, 2023
74f3317
wrap all handlers in useCallback
guskovaue Jul 4, 2023
08daed9
add experimental flag
guskovaue Jul 5, 2023
89ff260
return back add variable button
guskovaue Jul 5, 2023
612fa4f
fix focus test
guskovaue Jul 6, 2023
24096fe
fix the bug with editAction which move cursor to the end of testarea
guskovaue Jul 6, 2023
38326a6
delete deprecated variables
guskovaue Jul 6, 2023
1f1eaf5
fix warning disappeared bug
guskovaue Jul 10, 2023
c0ca732
fix unit test for email params tests
guskovaue Jul 11, 2023
c6d4542
Merge branch 'main' into RAM-158244-autocomplete-component-for-action…
guskovaue Jul 12, 2023
65d57ef
update limits for stackConnectors plugin
guskovaue Jul 12, 2023
3e4b5cc
share new component in right way
guskovaue Jul 14, 2023
ce08155
use coloring instruments from eui
guskovaue Jul 14, 2023
5524e1c
Revert "update limits for stackConnectors plugin"
guskovaue Jul 14, 2023
f0906d4
Merge branch 'main' into RAM-158244-autocomplete-component-for-action…
guskovaue Jul 14, 2023
abec1df
beautifier
guskovaue Jul 14, 2023
9dc1d82
Merge branch 'RAM-158244-autocomplete-component-for-action-msg' of gi…
guskovaue Jul 14, 2023
c709927
add kibana react plugin
guskovaue Jul 14, 2023
be52216
Merge branch 'main' into RAM-158244-autocomplete-component-for-action…
kibanamachine Jul 14, 2023
29f1618
do not directly export new component from taui
guskovaue Jul 17, 2023
7f061f5
Merge branch 'RAM-158244-autocomplete-component-for-action-msg' of gi…
guskovaue Jul 17, 2023
0498441
Merge branch 'main' into RAM-158244-autocomplete-component-for-action…
guskovaue Jul 17, 2023
7fec97b
raise limit for slack connector plugin
guskovaue Jul 17, 2023
21d9761
Merge branch 'RAM-158244-autocomplete-component-for-action-msg' of gi…
guskovaue Jul 17, 2023
82db434
Merge branch 'main' into RAM-158244-autocomplete-component-for-action…
guskovaue Aug 7, 2023
1267fa9
Merge branch 'main' into RAM-158244-autocomplete-component-for-action…
kibanamachine Aug 7, 2023
d229536
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Aug 7, 2023
8d86b43
move autocomplete component from trigger-ui to alerts-ui-shared
guskovaue Aug 18, 2023
49af14e
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Aug 18, 2023
c961071
move add message variables to alerts ui shares package
guskovaue Aug 21, 2023
f434159
Merge branch 'RAM-158244-autocomplete-component-for-action-msg' of gi…
guskovaue Aug 21, 2023
af52b1b
delete not used file and fix translations
guskovaue Aug 21, 2023
360be15
delete comments
guskovaue Aug 21, 2023
5d3215e
Merge branch 'main' into RAM-158244-autocomplete-component-for-action…
guskovaue Aug 21, 2023
d734a6f
delete not used imports
guskovaue Aug 21, 2023
11d32eb
fix translations
guskovaue Aug 21, 2023
116e372
delete not used imports
guskovaue Aug 22, 2023
3667c51
Merge branch 'main' into RAM-158244-autocomplete-component-for-action…
guskovaue Aug 23, 2023
fcbc1f9
get back old tar vertion
guskovaue Aug 24, 2023
5ed84e4
delete trailing comma in json file
guskovaue Aug 24, 2023
bbae0fd
rewrite condition for text area in more elegant way
guskovaue Aug 24, 2023
0702c3a
fix hook dependency and initial state
guskovaue Aug 24, 2023
af0e868
fix bug that menu goes up outside textarea
guskovaue Aug 24, 2023
90b181d
Merge branch 'main' of github.com:elastic/kibana into pr/158454
XavierM Aug 24, 2023
77b1606
cleanup
XavierM Aug 24, 2023
da83353
wrap style in useMemo
guskovaue Aug 25, 2023
d1bc817
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 25, 2023
58859e7
fix stack_connectors config
guskovaue Aug 25, 2023
ca19d59
Merge branch 'RAM-158244-autocomplete-component-for-action-msg' of gi…
guskovaue Aug 25, 2023
9265b39
Merge branch 'RAM-158244-autocomplete-component-for-action-msg' of gi…
XavierM Aug 25, 2023
9c73fd5
fix warning
guskovaue Aug 28, 2023
48f04b0
Merge branch 'main' into RAM-158244-autocomplete-component-for-action…
guskovaue Aug 28, 2023
d39a461
put functions out of inline
guskovaue Aug 30, 2023
130bd66
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Aug 30, 2023
6e762f6
fix experimental flag
guskovaue Aug 30, 2023
838f331
Merge branch 'RAM-158244-autocomplete-component-for-action-msg' of gi…
guskovaue Aug 30, 2023
7de1556
fix exposes plugin config test
guskovaue Aug 30, 2023
aecb69a
Merge branch 'main' into RAM-158244-autocomplete-component-for-action…
guskovaue Aug 30, 2023
4e57549
fix feature flag to be off at first + cleanup bug around scrolling
XavierM Aug 30, 2023
31484a4
Merge branch 'main' of github.com:elastic/kibana into RAM-158244-auto…
XavierM Aug 30, 2023
c50a06b
fix path
XavierM Aug 30, 2023
9550199
Merge branch 'main' into RAM-158244-autocomplete-component-for-action…
XavierM Aug 31, 2023
3399f66
Merge branch 'main' into RAM-158244-autocomplete-component-for-action…
kibanamachine Aug 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,7 @@
"suricata-sid-db": "^1.0.2",
"symbol-observable": "^1.2.0",
"tar": "^6.1.15",
"textarea-caret": "^3.1.0",
"tinycolor2": "1.4.1",
"tinygradient": "0.4.3",
"ts-easing": "^0.2.0",
Expand Down Expand Up @@ -1368,6 +1369,7 @@
"@types/tar": "^6.1.5",
"@types/tempy": "^0.2.0",
"@types/testing-library__jest-dom": "^5.14.7",
"@types/textarea-caret": "^3.0.1",
"@types/tinycolor2": "^1.4.1",
"@types/tough-cookie": "^4.0.2",
"@types/type-detect": "^4.0.1",
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-alerts-ui-shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
export { AlertLifecycleStatusBadge } from './src/alert_lifecycle_status_badge';
export type { AlertLifecycleStatusBadgeProps } from './src/alert_lifecycle_status_badge';
export { MaintenanceWindowCallout } from './src/maintenance_window_callout';
export { AddMessageVariables } from './src/add_message_variables';
1 change: 1 addition & 0 deletions packages/kbn-alerts-ui-shared/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-alerts-ui-shared'],
setupFilesAfterEnv: ['<rootDir>/packages/kbn-cases-components/setup_tests.ts'],
};
10 changes: 10 additions & 0 deletions packages/kbn-alerts-ui-shared/setup_tests.ts
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';
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
* 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.
* 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 { render, fireEvent, screen } from '@testing-library/react';
import { AddMessageVariables } from './add_message_variables';
import { AddMessageVariables } from '.';

describe('AddMessageVariables', () => {
test('it renders variables and filter bar', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* 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.
* 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, { useMemo, useState } from 'react';
Expand All @@ -23,7 +24,7 @@ import {
} from '@elastic/eui';
import { ActionVariable } from '@kbn/alerting-plugin/common';
import './add_message_variables.scss';
import { TruncatedText } from '../../common/truncated_text';
import { TruncatedText } from './truncated_text';
import * as i18n from './translations';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,70 +1,71 @@
/*
* 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.
* 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 { i18n } from '@kbn/i18n';

export const LOADING_VARIABLES = i18n.translate(
'xpack.triggersActionsUI.components.addMessageVariables.loadingMessage',
'alertsUIShared.components.addMessageVariables.loadingMessage',
{
defaultMessage: 'Loading variables',
}
);

export const NO_VARIABLES_FOUND = i18n.translate(
'xpack.triggersActionsUI.components.addMessageVariables.noVariablesFound',
'alertsUIShared.components.addMessageVariables.noVariablesFound',
{
defaultMessage: 'No variables found',
}
);

export const NO_VARIABLES_AVAILABLE = i18n.translate(
'xpack.triggersActionsUI.components.addMessageVariables.noVariablesAvailable',
'alertsUIShared.components.addMessageVariables.noVariablesAvailable',
{
defaultMessage: 'No variables available',
}
);

export const DEPRECATED_VARIABLES_ARE_SHOWN = i18n.translate(
'xpack.triggersActionsUI.components.addMessageVariables.deprecatedVariablesAreShown',
'alertsUIShared.components.addMessageVariables.deprecatedVariablesAreShown',
{
defaultMessage: 'Deprecated variables are shown',
}
);

export const DEPRECATED_VARIABLES_ARE_HIDDEN = i18n.translate(
'xpack.triggersActionsUI.components.addMessageVariables.deprecatedVariablesAreHidden',
'alertsUIShared.components.addMessageVariables.deprecatedVariablesAreHidden',
{
defaultMessage: 'Deprecated variables are hidden',
}
);

export const HIDE = i18n.translate(
'xpack.triggersActionsUI.components.addMessageVariables.hideDeprecatedVariables',
'alertsUIShared.components.addMessageVariables.hideDeprecatedVariables',
{
defaultMessage: 'Hide',
}
);

export const SHOW_ALL = i18n.translate(
'xpack.triggersActionsUI.components.addMessageVariables.showAllDeprecatedVariables',
'alertsUIShared.components.addMessageVariables.showAllDeprecatedVariables',
{
defaultMessage: 'Show all',
}
);

export const ADD_VARIABLE_POPOVER_BUTTON = i18n.translate(
'xpack.triggersActionsUI.components.addMessageVariables.addVariablePopoverButton',
'alertsUIShared.components.addMessageVariables.addVariablePopoverButton',
{
defaultMessage: 'Add variable',
}
);

export const ADD_VARIABLE_TITLE = i18n.translate(
'xpack.triggersActionsUI.components.addMessageVariables.addRuleVariableTitle',
'alertsUIShared.components.addMessageVariables.addRuleVariableTitle',
{
defaultMessage: 'Add variable',
}
Expand Down
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);
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ describe('MaintenanceWindowCallout', () => {
{ wrapper: TestProviders }
);

// @ts-expect-error Jest types are incomplete in packages
expect(await findByText('Maintenance window is running')).toBeInTheDocument();
expect(fetchActiveMaintenanceWindowsMock).toHaveBeenCalledTimes(1);
});
Expand All @@ -119,7 +118,7 @@ describe('MaintenanceWindowCallout', () => {
const { container } = render(<MaintenanceWindowCallout kibanaServices={kibanaServicesMock} />, {
wrapper: TestProviders,
});
// @ts-expect-error Jest types are incomplete in packages

expect(container).toBeEmptyDOMElement();
expect(fetchActiveMaintenanceWindowsMock).toHaveBeenCalledTimes(1);
});
Expand All @@ -130,7 +129,7 @@ describe('MaintenanceWindowCallout', () => {
const { container } = render(<MaintenanceWindowCallout kibanaServices={kibanaServicesMock} />, {
wrapper: TestProviders,
});
// @ts-expect-error Jest types are incomplete in packages

expect(container).toBeEmptyDOMElement();
expect(fetchActiveMaintenanceWindowsMock).toHaveBeenCalledTimes(1);
});
Expand Down Expand Up @@ -192,7 +191,7 @@ describe('MaintenanceWindowCallout', () => {
const { container } = render(<MaintenanceWindowCallout kibanaServices={servicesMock} />, {
wrapper: TestProviders,
});
// @ts-expect-error Jest types are incomplete in packages

expect(container).toBeEmptyDOMElement();
});

Expand All @@ -213,7 +212,7 @@ describe('MaintenanceWindowCallout', () => {
const { findByText } = render(<MaintenanceWindowCallout kibanaServices={servicesMock} />, {
wrapper: TestProviders,
});
// @ts-expect-error Jest types are incomplete in packages

expect(await findByText('Maintenance window is running')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.securitySolution.prebuiltRulesPackageVersion (string)',
'xpack.snapshot_restore.slm_ui.enabled (boolean)',
'xpack.snapshot_restore.ui.enabled (boolean)',
'xpack.stack_connectors.enableExperimental (array)',
'xpack.trigger_actions_ui.enableExperimental (array)',
'xpack.trigger_actions_ui.enableGeoTrackingThresholdAlert (boolean)',
'xpack.upgrade_assistant.featureSet.migrateSystemIndices (boolean)',
Expand Down
52 changes: 52 additions & 0 deletions x-pack/plugins/stack_connectors/common/experimental_features.ts
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({
isMustacheAutocompleteOff: 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];
10 changes: 10 additions & 0 deletions x-pack/plugins/stack_connectors/common/types.ts
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[];
}
1 change: 1 addition & 0 deletions x-pack/plugins/stack_connectors/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"requiredPlugins": [
"actions",
"esUiShared",
"kibanaReact",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this plugin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to recall why I added it without success. Seems I do not need it. Removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERROR in ./public/connector_types/email/email_params.tsx

  | │ Module not found: Error: import [@kbn/kibana-react-plugin/public] references a public export of the [kibanaReact] bundle, but that bundle is not in the "requiredPlugins" or "requiredBundles" list in the plugin manifest [/dev/shm/builds/kb-n2-16-spot-46e986621280fcc4/elastic/kibana-pull-request/kibana/x-pack/plugins/stack_connectors/kibana.jsonc]
  | │ @ ./public/connector_types/email/email_params.tsx 13:0-60 35:6-15
  | │ @ ./public/connector_types/email/email.tsx
  | │ @ ./public/connector_types/email/index.ts
  | │ @ ./public/connector_types/index.ts
  | │ @ ./public/plugin.ts
  | │ @ ./public/index.ts

Added back.

"triggersActionsUi"
],
"extraPublicDirs": [
Expand Down
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?'
);
}
}
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];
};
Loading