Skip to content

Commit

Permalink
Merge branch 'main' into 118774-import-export-connectors-with-rules
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Feb 6, 2023
2 parents eb6dfe5 + b4a5086 commit 6dac771
Show file tree
Hide file tree
Showing 64 changed files with 1,577 additions and 247 deletions.
14 changes: 11 additions & 3 deletions examples/guided_onboarding_example/public/components/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
EuiText,
EuiTitle,
EuiSelectOption,
EuiFlexGrid,
} from '@elastic/eui';
import type { GuideState, GuideStepIds, GuideId, GuideStep } from '@kbn/guided-onboarding';
import type { GuidedOnboardingPluginStart } from '@kbn/guided-onboarding-plugin/public';
Expand All @@ -34,7 +35,14 @@ interface MainProps {
notifications: CoreStart['notifications'];
}

const exampleGuideIds: GuideId[] = ['search', 'siem', 'kubernetes', 'testGuide'];
const exampleGuideIds: GuideId[] = [
'appSearch',
'websiteSearch',
'databaseSearch',
'siem',
'kubernetes',
'testGuide',
];
const selectOptions: EuiSelectOption[] = exampleGuideIds.map((guideId) => ({
value: guideId,
text: guideId,
Expand Down Expand Up @@ -211,7 +219,7 @@ export const Main = (props: MainProps) => {
</h3>
</EuiText>
<EuiSpacer />
<EuiFlexGroup>
<EuiFlexGrid columns={3}>
{exampleGuideIds.map((guideId) => {
const guideState = guidesState?.find((guide) => guide.guideId === guideId);
return (
Expand Down Expand Up @@ -255,7 +263,7 @@ export const Main = (props: MainProps) => {
</EuiFlexItem>
);
})}
</EuiFlexGroup>
</EuiFlexGrid>
<EuiSpacer />
<EuiHorizontalRule />
<EuiText>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"@dnd-kit/utilities": "^2.0.0",
"@elastic/apm-rum": "^5.12.0",
"@elastic/apm-rum-react": "^1.4.2",
"@elastic/charts": "51.3.0",
"@elastic/charts": "52.0.0",
"@elastic/datemath": "5.0.3",
"@elastic/elasticsearch": "npm:@elastic/[email protected]",
"@elastic/ems-client": "8.4.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es-query/src/kuery/node_types/wildcard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function escapeRegExp(str: string) {

// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters
function escapeQueryString(str: string) {
return str.replace(/[+-=&|><!(){}[\]^"~*?:\\/]/g, '\\$&'); // $& means the whole matched string
return str.replace(/[+\-=&|><!(){}[\]^"~*?:\\/]/g, '\\$&'); // $& means the whole matched string
}

export function isNode(node: KueryNode): node is KqlWildcardNode {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const guideCards: GuideCardConstants[] = [
title: i18n.translate('guidedOnboardingPackage.gettingStarted.cards.appSearch.title', {
defaultMessage: 'Build an application on top of Elasticsearch',
}),
guideId: 'search',
guideId: 'appSearch',
telemetryId: 'onboarding--search--application',
order: 1,
},
Expand All @@ -42,7 +42,7 @@ export const guideCards: GuideCardConstants[] = [
title: i18n.translate('guidedOnboardingPackage.gettingStarted.cards.websiteSearch.title', {
defaultMessage: 'Add search to my website',
}),
guideId: 'search',
guideId: 'websiteSearch',
telemetryId: 'onboarding--search--website',
order: 4,
},
Expand All @@ -51,7 +51,7 @@ export const guideCards: GuideCardConstants[] = [
title: i18n.translate('guidedOnboardingPackage.gettingStarted.cards.databaseSearch.title', {
defaultMessage: 'Search across databases and business systems',
}),
guideId: 'search',
guideId: 'databaseSearch',
telemetryId: 'onboarding--search--database',
order: 7,
},
Expand Down
8 changes: 7 additions & 1 deletion packages/kbn-guided-onboarding/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
* Side Public License, v 1.
*/

export type GuideId = 'kubernetes' | 'siem' | 'search' | 'testGuide';
export type GuideId =
| 'kubernetes'
| 'siem'
| 'appSearch'
| 'websiteSearch'
| 'databaseSearch'
| 'testGuide';

type KubernetesStepIds = 'add_data' | 'view_dashboard' | 'tour_observability';
type SiemStepIds = 'add_data' | 'rules' | 'alertsCases';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const FieldComponent: React.FC<FieldProps> = ({
placeholder,
selectedField,
acceptsCustomOptions = false,
showMappingConflicts = false,
}): JSX.Element => {
const {
isInvalid,
Expand All @@ -44,6 +45,7 @@ export const FieldComponent: React.FC<FieldProps> = ({
isRequired,
selectedField,
fieldInputWidth,
showMappingConflicts,
onChange,
});

Expand All @@ -68,6 +70,7 @@ export const FieldComponent: React.FC<FieldProps> = ({
values: { searchValuePlaceholder: '{searchValue}' },
})}
fullWidth
renderOption={renderFields}
/>
);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/kbn-securitysolution-autocomplete/src/field/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { DataViewBase, DataViewFieldBase } from '@kbn/es-query';
import { FieldConflictsInfo } from '@kbn/securitysolution-list-utils';
import { GetGenericComboBoxPropsReturn } from '../get_generic_combo_box_props';

export interface FieldProps extends FieldBaseProps {
Expand All @@ -15,13 +16,15 @@ export interface FieldProps extends FieldBaseProps {
isLoading: boolean;
placeholder: string;
acceptsCustomOptions?: boolean;
showMappingConflicts?: boolean;
}
export interface FieldBaseProps {
indexPattern: DataViewBase | undefined;
fieldTypeFilter?: string[];
isRequired?: boolean;
selectedField?: DataViewFieldBase | undefined;
fieldInputWidth?: number;
showMappingConflicts?: boolean;
onChange: (a: DataViewFieldBase[]) => void;
}

Expand All @@ -32,6 +35,7 @@ export interface ComboBoxFields {

export interface GetFieldComboBoxPropsReturn extends GetGenericComboBoxPropsReturn {
disabledLabelTooltipTexts: { [label: string]: string };
mappingConflictsTooltipInfo: { [label: string]: FieldConflictsInfo[] };
}

export interface DataViewField extends DataViewFieldBase {
Expand Down
78 changes: 76 additions & 2 deletions packages/kbn-securitysolution-autocomplete/src/field/use_field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@
*/
import React from 'react';
import { useCallback, useMemo, useState } from 'react';
import { EuiComboBoxOptionOption, EuiToolTip } from '@elastic/eui';
import {
EuiComboBoxOptionOption,
EuiIcon,
EuiSpacer,
EuiToolTip,
useEuiPaddingSize,
} from '@elastic/eui';
import { DataViewBase, DataViewFieldBase } from '@kbn/es-query';

import { FieldConflictsInfo, getMappingConflictsInfo } from '@kbn/securitysolution-list-utils';
import { getGenericComboBoxProps } from '../get_generic_combo_box_props';
import * as i18n from '../translations';
import {
ComboBoxFields,
DataViewField,
Expand Down Expand Up @@ -72,6 +80,22 @@ const getDisabledLabelTooltipTexts = (fields: ComboBoxFields) => {
);
return disabledLabelTooltipTexts;
};

const getMappingConflictsTooltipInfo = (fields: ComboBoxFields) => {
const mappingConflictsTooltipInfo = fields.availableFields.reduce(
(acc: { [label: string]: FieldConflictsInfo[] }, field: DataViewField) => {
const conflictsInfo = getMappingConflictsInfo(field);
if (!conflictsInfo) {
return acc;
}
acc[field.name] = conflictsInfo;
return acc;
},
{}
);
return mappingConflictsTooltipInfo;
};

const getComboBoxProps = (fields: ComboBoxFields): GetFieldComboBoxPropsReturn => {
const { availableFields, selectedFields } = fields;

Expand All @@ -81,9 +105,11 @@ const getComboBoxProps = (fields: ComboBoxFields): GetFieldComboBoxPropsReturn =
selectedOptions: selectedFields,
});
const disabledLabelTooltipTexts = getDisabledLabelTooltipTexts(fields);
const mappingConflictsTooltipInfo = getMappingConflictsTooltipInfo(fields);
return {
...genericProps,
disabledLabelTooltipTexts,
mappingConflictsTooltipInfo,
};
};

Expand All @@ -93,11 +119,13 @@ export const useField = ({
isRequired,
selectedField,
fieldInputWidth,
showMappingConflicts,
onChange,
}: FieldBaseProps) => {
const [touched, setIsTouched] = useState(false);

const [customOption, setCustomOption] = useState<DataViewFieldBase | null>(null);
const sPaddingSize = useEuiPaddingSize('s');

const { availableFields, selectedFields } = useMemo(() => {
const indexPatternsToUse =
Expand All @@ -107,7 +135,13 @@ export const useField = ({
return getComboBoxFields(indexPatternsToUse, selectedField, fieldTypeFilter);
}, [indexPattern, fieldTypeFilter, selectedField, customOption]);

const { comboOptions, labels, selectedComboOptions, disabledLabelTooltipTexts } = useMemo(
const {
comboOptions,
labels,
selectedComboOptions,
disabledLabelTooltipTexts,
mappingConflictsTooltipInfo,
} = useMemo(
() => getComboBoxProps({ availableFields, selectedFields }),
[availableFields, selectedFields]
);
Expand Down Expand Up @@ -168,6 +202,46 @@ export const useField = ({
</EuiToolTip>
);
}

const conflictsInfo = mappingConflictsTooltipInfo[label];
if (showMappingConflicts && conflictsInfo) {
const tooltipContent = (
<>
{i18n.FIELD_CONFLICT_INDICES_WARNING_DESCRIPTION}
{conflictsInfo.map((info) => {
const groupDetails = info.groupedIndices.map(
({ name, count }) =>
`${count > 1 ? i18n.CONFLICT_MULTIPLE_INDEX_DESCRIPTION(name, count) : name}`
);
return (
<>
<EuiSpacer size="s" />
{`${
info.totalIndexCount > 1
? i18n.CONFLICT_MULTIPLE_INDEX_DESCRIPTION(info.type, info.totalIndexCount)
: info.type
}: ${groupDetails.join(', ')}`}
</>
);
})}
</>
);
return (
<EuiToolTip position="bottom" content={tooltipContent}>
<>
{label}
<EuiIcon
tabIndex={0}
type="alert"
title={i18n.FIELD_CONFLICT_INDICES_WARNING_TITLE}
size="s"
css={{ marginLeft: `${sPaddingSize}` }}
/>
</>
</EuiToolTip>
);
}

return label;
};
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ export const SEE_DOCUMENTATION = i18n.translate('autocomplete.seeDocumentation',
defaultMessage: 'See Documentation',
});

export const FIELD_CONFLICT_INDICES_WARNING_TITLE = i18n.translate(
'autocomplete.conflictIndicesWarning.title',
{
defaultMessage: 'Mapping Conflict',
}
);

export const FIELD_CONFLICT_INDICES_WARNING_DESCRIPTION = i18n.translate(
'autocomplete.conflictIndicesWarning.description',
{
defaultMessage: 'This field is defined as several types across different indices.',
}
);

export const CONFLICT_MULTIPLE_INDEX_DESCRIPTION = (name: string, count: number): string =>
i18n.translate('autocomplete.conflictIndicesWarning.index.description', {
defaultMessage: '{name} ({count} indices)',
values: { count, name },
});

// eslint-disable-next-line import/no-default-export
export default {
LOADING,
Expand Down
Loading

0 comments on commit 6dac771

Please sign in to comment.