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

[Security Solution] Security Assistant: adds the assistantEnabled feature flag #17

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
*/

import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui';
// eslint-disable-next-line @kbn/eslint/module_migration
import styled from 'styled-components';

import { sortBy } from 'lodash/fp';
import React, { useCallback, useMemo } from 'react';
// eslint-disable-next-line @kbn/eslint/module_migration
import styled from 'styled-components';

import type { PromptContext } from '../prompt_context/types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,25 @@ const SelectedPromptContextsComponent: React.FC<Props> = ({
);

useEffect(() => {
const abortController = new AbortController();

const fetchAccordionContent = async () => {
const newAccordionContent = await Promise.all(
selectedPromptContexts.map(async ({ getPromptContext, id }) => ({
[id]: await getPromptContext(),
}))
);

setAccordionContent(newAccordionContent.reduce((acc, curr) => ({ ...acc, ...curr }), {}));
if (!abortController.signal.aborted) {
setAccordionContent(newAccordionContent.reduce((acc, curr) => ({ ...acc, ...curr }), {}));
}
};

fetchAccordionContent();

return () => {
abortController.abort();
};
}, [selectedPromptContexts]);

if (isEmpty(promptContexts)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const defaultProps: Props = {
formatNumber,
getGroupByFieldsOnClick: jest.fn(),
ilmPhases,
isAssistantEnabled: true,
openCreateCaseFlyout: jest.fn(),
patternIndexNames,
patternRollups,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface Props {
groupByField1: string;
};
ilmPhases: string[];
isAssistantEnabled: boolean;
openCreateCaseFlyout: ({
comments,
headerContent,
Expand Down Expand Up @@ -69,6 +70,7 @@ const DataQualityDetailsComponent: React.FC<Props> = ({
formatNumber,
getGroupByFieldsOnClick,
ilmPhases,
isAssistantEnabled,
openCreateCaseFlyout,
patternIndexNames,
patternRollups,
Expand Down Expand Up @@ -105,6 +107,7 @@ const DataQualityDetailsComponent: React.FC<Props> = ({
formatNumber={formatNumber}
getGroupByFieldsOnClick={getGroupByFieldsOnClick}
ilmPhases={ilmPhases}
isAssistantEnabled={isAssistantEnabled}
openCreateCaseFlyout={openCreateCaseFlyout}
patterns={patterns}
theme={theme}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const defaultProps: Props = {
formatNumber,
getGroupByFieldsOnClick: jest.fn(),
ilmPhases,
isAssistantEnabled: true,
openCreateCaseFlyout: jest.fn(),
patternIndexNames,
patternRollups,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface Props {
groupByField1: string;
};
ilmPhases: string[];
isAssistantEnabled: boolean;
openCreateCaseFlyout: ({
comments,
headerContent,
Expand Down Expand Up @@ -69,6 +70,7 @@ const IndicesDetailsComponent: React.FC<Props> = ({
formatNumber,
getGroupByFieldsOnClick,
ilmPhases,
isAssistantEnabled,
openCreateCaseFlyout,
patternIndexNames,
patternRollups,
Expand All @@ -90,6 +92,7 @@ const IndicesDetailsComponent: React.FC<Props> = ({
getGroupByFieldsOnClick={getGroupByFieldsOnClick}
ilmPhases={ilmPhases}
indexNames={patternIndexNames[pattern]}
isAssistantEnabled={isAssistantEnabled}
openCreateCaseFlyout={openCreateCaseFlyout}
pattern={pattern}
patternRollup={patternRollups[pattern]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('IndexInvalidValues', () => {
formatNumber={formatNumber}
getGroupByFieldsOnClick={jest.fn()}
ilmPhases={[]}
isAssistantEnabled={true}
lastChecked={''}
openCreateCaseFlyout={jest.fn()}
patterns={[]}
Expand Down Expand Up @@ -63,6 +64,7 @@ describe('IndexInvalidValues', () => {
formatNumber={formatNumber}
getGroupByFieldsOnClick={jest.fn()}
ilmPhases={ilmPhases}
isAssistantEnabled={true}
lastChecked={''}
openCreateCaseFlyout={jest.fn()}
patterns={patterns}
Expand All @@ -88,6 +90,7 @@ describe('IndexInvalidValues', () => {
formatNumber={formatNumber}
getGroupByFieldsOnClick={jest.fn()}
ilmPhases={ilmPhases}
isAssistantEnabled={true}
lastChecked={''}
openCreateCaseFlyout={jest.fn()}
patterns={patterns}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface Props {
groupByField1: string;
};
ilmPhases: string[];
isAssistantEnabled: boolean;
lastChecked: string;
openCreateCaseFlyout: ({
comments,
Expand All @@ -60,6 +61,7 @@ const BodyComponent: React.FC<Props> = ({
formatNumber,
getGroupByFieldsOnClick,
ilmPhases,
isAssistantEnabled,
lastChecked,
openCreateCaseFlyout,
patterns,
Expand Down Expand Up @@ -112,6 +114,7 @@ const BodyComponent: React.FC<Props> = ({
formatNumber={formatNumber}
getGroupByFieldsOnClick={getGroupByFieldsOnClick}
ilmPhases={ilmPhases}
isAssistantEnabled={isAssistantEnabled}
openCreateCaseFlyout={openCreateCaseFlyout}
patterns={patterns}
patternIndexNames={patternIndexNames}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const defaultProps: Props = {
getGroupByFieldsOnClick: jest.fn(),
ilmPhase: 'hot',
indexName: 'auditbeat-custom-index-1',
isAssistantEnabled: true,
openCreateCaseFlyout: jest.fn(),
pattern,
patternRollup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface Props {
};
ilmPhase: IlmPhase | undefined;
indexName: string;
isAssistantEnabled: boolean;
openCreateCaseFlyout: ({
comments,
headerContent,
Expand All @@ -82,6 +83,7 @@ const IndexPropertiesComponent: React.FC<Props> = ({
getGroupByFieldsOnClick,
ilmPhase,
indexName,
isAssistantEnabled,
openCreateCaseFlyout,
pattern,
patternRollup,
Expand Down Expand Up @@ -143,6 +145,7 @@ const IndexPropertiesComponent: React.FC<Props> = ({
docsCount,
getGroupByFieldsOnClick,
ilmPhase,
isAssistantEnabled,
indexName,
onAddToNewCase,
partitionedFieldMetadata: partitionedFieldMetadata ?? EMPTY_METADATA,
Expand All @@ -161,6 +164,7 @@ const IndexPropertiesComponent: React.FC<Props> = ({
getGroupByFieldsOnClick,
ilmPhase,
indexName,
isAssistantEnabled,
onAddToNewCase,
partitionedFieldMetadata,
pattern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const defaultProps = {
getGroupByFieldsOnClick: jest.fn(),
ilmPhases: ['hot', 'warm', 'unmanaged'],
indexNames: undefined,
isAssistantEnabled: true,
openCreateCaseFlyout: jest.fn(),
patternRollup: undefined,
selectedIndex: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ interface Props {
};
ilmPhases: string[];
indexNames: string[] | undefined;
isAssistantEnabled: boolean;
openCreateCaseFlyout: ({
comments,
headerContent,
Expand Down Expand Up @@ -106,6 +107,7 @@ const PatternComponent: React.FC<Props> = ({
getGroupByFieldsOnClick,
indexNames,
ilmPhases,
isAssistantEnabled,
openCreateCaseFlyout,
pattern,
patternRollup,
Expand Down Expand Up @@ -150,6 +152,7 @@ const PatternComponent: React.FC<Props> = ({
getGroupByFieldsOnClick={getGroupByFieldsOnClick}
ilmPhase={ilmExplain != null ? getIlmPhase(ilmExplain[indexName]) : undefined}
indexName={indexName}
isAssistantEnabled={isAssistantEnabled}
openCreateCaseFlyout={openCreateCaseFlyout}
pattern={pattern}
patternRollup={patternRollup}
Expand All @@ -168,6 +171,7 @@ const PatternComponent: React.FC<Props> = ({
formatNumber,
getGroupByFieldsOnClick,
ilmExplain,
isAssistantEnabled,
itemIdToExpandedRowMap,
openCreateCaseFlyout,
pattern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe('helpers', () => {
getGroupByFieldsOnClick: jest.fn(),
ilmPhase: 'unmanaged',
indexName: 'auditbeat-custom-index-1',
isAssistantEnabled: true,
onAddToNewCase: jest.fn(),
partitionedFieldMetadata: mockPartitionedFieldMetadata,
pattern: 'auditbeat-*',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const getTabs = ({
getGroupByFieldsOnClick,
ilmPhase,
indexName,
isAssistantEnabled,
onAddToNewCase,
partitionedFieldMetadata,
pattern,
Expand Down Expand Up @@ -94,6 +95,7 @@ export const getTabs = ({
};
ilmPhase: IlmPhase | undefined;
indexName: string;
isAssistantEnabled: boolean;
onAddToNewCase: (markdownComments: string[]) => void;
partitionedFieldMetadata: PartitionedFieldMetadata;
pattern: string;
Expand All @@ -113,6 +115,7 @@ export const getTabs = ({
getGroupByFieldsOnClick={getGroupByFieldsOnClick}
ilmPhase={ilmPhase}
indexName={indexName}
isAssistantEnabled={isAssistantEnabled}
onAddToNewCase={onAddToNewCase}
partitionedFieldMetadata={partitionedFieldMetadata}
pattern={pattern}
Expand Down Expand Up @@ -140,6 +143,7 @@ export const getTabs = ({
formatNumber={formatNumber}
ilmPhase={ilmPhase}
indexName={indexName}
isAssistantEnabled={isAssistantEnabled}
onAddToNewCase={onAddToNewCase}
partitionedFieldMetadata={partitionedFieldMetadata}
patternDocsCount={patternDocsCount}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ interface Props {
formatNumber: (value: number | undefined) => string;
ilmPhase: IlmPhase | undefined;
indexName: string;
isAssistantEnabled: boolean;
onAddToNewCase: (markdownComments: string[]) => void;
partitionedFieldMetadata: PartitionedFieldMetadata;
patternDocsCount: number;
Expand All @@ -65,6 +66,7 @@ const IncompatibleTabComponent: React.FC<Props> = ({
formatNumber,
ilmPhase,
indexName,
isAssistantEnabled,
onAddToNewCase,
partitionedFieldMetadata,
patternDocsCount,
Expand Down Expand Up @@ -139,16 +141,18 @@ const IncompatibleTabComponent: React.FC<Props> = ({
</CopyToClipboardButton>
</EuiFlexItem>

<EuiFlexItem grow={false}>
<NewChat
category="data-quality-dashboard"
conversationId={DATA_QUALITY_DASHBOARD_CONVERSATION_ID}
description={DATA_QUALITY_PROMPT_CONTEXT_PILL(indexName)}
getPromptContext={getPromptContext}
suggestedUserPrompt={DATA_QUALITY_SUGGESTED_USER_PROMPT}
tooltip={DATA_QUALITY_PROMPT_CONTEXT_PILL_TOOLTIP}
/>
</EuiFlexItem>
{isAssistantEnabled && (
<EuiFlexItem grow={false}>
<NewChat
category="data-quality-dashboard"
conversationId={DATA_QUALITY_DASHBOARD_CONVERSATION_ID}
description={DATA_QUALITY_PROMPT_CONTEXT_PILL(indexName)}
getPromptContext={getPromptContext}
suggestedUserPrompt={DATA_QUALITY_SUGGESTED_USER_PROMPT}
tooltip={DATA_QUALITY_PROMPT_CONTEXT_PILL_TOOLTIP}
/>
</EuiFlexItem>
)}
</EuiFlexGroup>
</IncompatibleCallout>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface Props {
formatNumber: (value: number | undefined) => string;
ilmPhase: IlmPhase | undefined;
indexName: string;
isAssistantEnabled: boolean;
onAddToNewCase: (markdownComment: string[]) => void;
partitionedFieldMetadata: PartitionedFieldMetadata;
pattern: string;
Expand All @@ -48,6 +49,7 @@ const CalloutSummaryComponent: React.FC<Props> = ({
formatNumber,
ilmPhase,
indexName,
isAssistantEnabled,
onAddToNewCase,
partitionedFieldMetadata,
pattern,
Expand Down Expand Up @@ -132,16 +134,18 @@ const CalloutSummaryComponent: React.FC<Props> = ({
</CopyToClipboardButton>
</EuiFlexItem>

<EuiFlexItem grow={false}>
<NewChat
conversationId={DATA_QUALITY_DASHBOARD_CONVERSATION_ID}
category="data-quality-dashboard"
description={DATA_QUALITY_PROMPT_CONTEXT_PILL(indexName)}
getPromptContext={getPromptContext}
suggestedUserPrompt={DATA_QUALITY_SUGGESTED_USER_PROMPT}
tooltip={DATA_QUALITY_PROMPT_CONTEXT_PILL_TOOLTIP}
/>
</EuiFlexItem>
{isAssistantEnabled && (
<EuiFlexItem grow={false}>
<NewChat
conversationId={DATA_QUALITY_DASHBOARD_CONVERSATION_ID}
category="data-quality-dashboard"
description={DATA_QUALITY_PROMPT_CONTEXT_PILL(indexName)}
getPromptContext={getPromptContext}
suggestedUserPrompt={DATA_QUALITY_SUGGESTED_USER_PROMPT}
tooltip={DATA_QUALITY_PROMPT_CONTEXT_PILL_TOOLTIP}
/>
</EuiFlexItem>
)}
</EuiFlexGroup>

<EuiSpacer size="s" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface Props {
};
ilmPhase: IlmPhase | undefined;
indexName: string;
isAssistantEnabled: boolean;
onAddToNewCase: (markdownComments: string[]) => void;
partitionedFieldMetadata: PartitionedFieldMetadata;
pattern: string;
Expand All @@ -60,6 +61,7 @@ const SummaryTabComponent: React.FC<Props> = ({
getGroupByFieldsOnClick,
ilmPhase,
indexName,
isAssistantEnabled,
onAddToNewCase,
partitionedFieldMetadata,
pattern,
Expand All @@ -77,6 +79,7 @@ const SummaryTabComponent: React.FC<Props> = ({
docsCount={docsCount}
ilmPhase={ilmPhase}
indexName={indexName}
isAssistantEnabled={isAssistantEnabled}
onAddToNewCase={onAddToNewCase}
partitionedFieldMetadata={partitionedFieldMetadata}
pattern={pattern}
Expand Down
Loading