Skip to content

Commit

Permalink
Remove DiffableAllFields type from field components
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaindik committed Sep 18, 2024
1 parent 6f9344e commit 3753f04
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import React from 'react';
import { EuiDescriptionList } from '@elastic/eui';
import { DataSourceType } from '../../../../../../../../../common/api/detection_engine';
import type { DiffableAllFields } from '../../../../../../../../../common/api/detection_engine';
import type { RuleDataSource } from '../../../../../../../../../common/api/detection_engine';
import { Index, DataViewId, DataViewIndexPattern } from '../../../../rule_definition_section';
import * as ruleDetailsI18n from '../../../../translations';
import { assertUnreachable } from '../../../../../../../../../common/utility_types';

interface DataSourceReadOnlyProps {
dataSource: DiffableAllFields['data_source'];
dataSource?: RuleDataSource;
}

export function DataSourceReadOnly({ dataSource }: DataSourceReadOnlyProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
import React from 'react';
import { EuiDescriptionList } from '@elastic/eui';
import * as ruleDetailsI18n from '../../../../translations';
import type { DiffableAllFields } from '../../../../../../../../../common/api/detection_engine';
import type { RuleDescription } from '../../../../../../../../../common/api/detection_engine';

interface RuleDescriptionProps {
description: DiffableAllFields['name'];
interface DescriptionProps {
description: RuleDescription;
}

function RuleDescription({ description }: RuleDescriptionProps) {
function Description({ description }: DescriptionProps) {
return <>{description}</>;
}

interface DescriptionReadOnlyProps {
description: DiffableAllFields['description'];
description: RuleDescription;
}

export function DescriptionReadOnly({ description }: DescriptionReadOnlyProps) {
Expand All @@ -28,7 +28,7 @@ export function DescriptionReadOnly({ description }: DescriptionReadOnlyProps) {
listItems={[
{
title: ruleDetailsI18n.DESCRIPTION_FIELD_LABEL,
description: <RuleDescription description={description} />,
description: <Description description={description} />,
},
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
import React from 'react';
import { EuiDescriptionList } from '@elastic/eui';
import type { EuiDescriptionListProps } from '@elastic/eui';
import type { DiffableAllFields } from '../../../../../../../../../common/api/detection_engine';
import type {
RuleDataSource,
RuleEqlQuery,
} from '../../../../../../../../../common/api/detection_engine';
import * as descriptionStepI18n from '../../../../../../../rule_creation_ui/components/description_step/translations';
import { Query, Filters } from '../../../../rule_definition_section';
import { getDataSourceProps, typeCheckFilters } from '../../../../helpers';

interface EqlQueryReadOnlyProps {
eqlQuery: DiffableAllFields['eql_query'];
dataSource: DiffableAllFields['data_source'];
eqlQuery: RuleEqlQuery;
dataSource?: RuleDataSource;
}

export function EqlQueryReadOnly({ eqlQuery, dataSource }: EqlQueryReadOnlyProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import React from 'react';
import { EuiDescriptionList } from '@elastic/eui';
import * as descriptionStepI18n from '../../../../../../../rule_creation_ui/components/description_step/translations';
import { Query } from '../../../../rule_definition_section';
import type { DiffableAllFields } from '../../../../../../../../../common/api/detection_engine';
import type { RuleEsqlQuery } from '../../../../../../../../../common/api/detection_engine';

interface EsqlQueryReadonlyProps {
esqlQuery: DiffableAllFields['esql_query'];
esqlQuery: RuleEsqlQuery;
}

export function EsqlQueryReadOnly({ esqlQuery }: EsqlQueryReadonlyProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import React from 'react';
import { KqlQueryType } from '../../../../../../../../../common/api/detection_engine';
import type {
DiffableAllFields,
DiffableRuleTypes,
RuleDataSource,
RuleKqlQuery,
} from '../../../../../../../../../common/api/detection_engine';
import { InlineKqlQueryReadOnly } from './inline_kql_query';
Expand All @@ -17,8 +18,8 @@ import { assertUnreachable } from '../../../../../../../../../common/utility_typ

interface KqlQueryReadOnlyProps {
kqlQuery: RuleKqlQuery;
dataSource: DiffableAllFields['data_source'];
ruleType: DiffableAllFields['type'];
dataSource?: RuleDataSource;
ruleType: DiffableRuleTypes;
}

export function KqlQueryReadOnly({ kqlQuery, dataSource, ruleType }: KqlQueryReadOnlyProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import React from 'react';
import { EuiDescriptionList } from '@elastic/eui';
import type { EuiDescriptionListProps } from '@elastic/eui';
import type {
DiffableAllFields,
InlineKqlQuery,
RuleDataSource,
} from '../../../../../../../../../common/api/detection_engine';
import { Query, Filters } from '../../../../rule_definition_section';
import * as ruleDetailsI18n from '../../../../translations';
Expand All @@ -25,7 +25,7 @@ const defaultI18nLabels = {

interface InlineQueryProps {
kqlQuery: InlineKqlQuery;
dataSource?: DiffableAllFields['data_source'];
dataSource?: RuleDataSource;
i18nLabels?: {
query: string;
language: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { EuiDescriptionList } from '@elastic/eui';
import type { EuiDescriptionListProps } from '@elastic/eui';
import type {
SavedKqlQuery,
DiffableRule,
DiffableAllFields,
RuleDataSource,
DiffableRuleTypes,
} from '../../../../../../../../../common/api/detection_engine';
import { Query, SavedQueryName, Filters } from '../../../../rule_definition_section';
import * as ruleDetailsI18n from '../../../../translations';
Expand All @@ -21,8 +21,8 @@ import { getDataSourceProps, getQueryLanguageLabel } from '../../../../helpers';

interface SavedQueryProps {
kqlQuery: SavedKqlQuery;
dataSource?: DiffableAllFields['data_source'];
ruleType: DiffableRule['type'];
dataSource?: RuleDataSource;
ruleType: DiffableRuleTypes;
}

export function SavedKqlQueryReadOnly({ kqlQuery, dataSource, ruleType }: SavedQueryProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import React from 'react';
import { EuiDescriptionList } from '@elastic/eui';
import { MachineLearningJobList } from '../../../../rule_definition_section';
import type { DiffableAllFields } from '../../../../../../../../../common/api/detection_engine';
import type { MachineLearningJobId } from '../../../../../../../../../common/api/detection_engine';
import * as ruleDetailsI18n from '../../../../translations';

interface MachineLearningJobIdProps {
machineLearningJobId: DiffableAllFields['machine_learning_job_id'];
machineLearningJobId: MachineLearningJobId;
}

export function MachineLearningJobIdReadOnly({ machineLearningJobId }: MachineLearningJobIdProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
import React from 'react';
import { EuiDescriptionList } from '@elastic/eui';
import * as ruleDetailsI18n from '../../../../translations';
import type { DiffableAllFields } from '../../../../../../../../../common/api/detection_engine';
import type { RuleName } from '../../../../../../../../../common/api/detection_engine';

interface RuleNameProps {
name: DiffableAllFields['name'];
interface NameProps {
name: RuleName;
}

function RuleName({ name }: RuleNameProps) {
function Name({ name }: NameProps) {
return <>{name}</>;
}

interface NameReadOnlyProps {
name: DiffableAllFields['name'];
name: RuleName;
}

export function NameReadOnly({ name }: NameReadOnlyProps) {
Expand All @@ -28,7 +28,7 @@ export function NameReadOnly({ name }: NameReadOnlyProps) {
listItems={[
{
title: ruleDetailsI18n.NAME_FIELD_LABEL,
description: <RuleName name={name} />,
description: <Name name={name} />,
},
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import React from 'react';
import { EuiDescriptionList } from '@elastic/eui';
import * as ruleDetailsI18n from '../../../../translations';
import type { DiffableAllFields } from '../../../../../../../../../common/api/detection_engine';
import type { RuleTagArray } from '../../../../../../../../../common/api/detection_engine';
import { Tags } from '../../../../rule_about_section';

interface TagsReadOnlyProps {
tags: DiffableAllFields['tags'];
tags: RuleTagArray;
}

export function TagsReadOnly({ tags }: TagsReadOnlyProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import React from 'react';
import type {
DiffableAllFields,
InlineKqlQuery,
RuleDataSource,
} from '../../../../../../../../../common/api/detection_engine';
import * as ruleDetailsI18n from '../../../../translations';
import * as descriptionStepI18n from '../../../../../../../rule_creation_ui/components/description_step/translations';
Expand All @@ -22,7 +22,7 @@ const i18nLabels = {

export interface ThreatQueryReadOnlyProps {
threatQuery: InlineKqlQuery;
dataSource: DiffableAllFields['data_source'];
dataSource?: RuleDataSource;
}

export const ThreatQueryReadOnly = ({ threatQuery, dataSource }: ThreatQueryReadOnlyProps) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import type { FieldFormatsStartCommon } from '@kbn/field-formats-plugin/common';
import { DataView } from '@kbn/data-views-plugin/common';
import { DataSourceType, KqlQueryType } from '../../../../../../../../common/api/detection_engine';
import type {
DiffableAllFields,
DataSourceDataView,
DataSourceIndexPatterns,
DiffableCommonFields,
DiffableCustomQueryFields,
DiffableEqlFields,
Expand All @@ -18,6 +19,8 @@ import type {
DiffableRule,
DiffableSavedQueryFields,
DiffableThreatMatchFields,
InlineKqlQuery,
RuleEqlQuery,
SavedKqlQuery,
} from '../../../../../../../../common/api/detection_engine';
import { DEFAULT_MAX_SIGNALS } from '../../../../../../../../common/constants';
Expand Down Expand Up @@ -59,7 +62,7 @@ export const savedQueryResponse = {
namespaces: ['default'],
};

export const inlineKqlQuery: DiffableAllFields['kql_query'] = {
export const inlineKqlQuery: InlineKqlQuery = {
type: KqlQueryType.inline_query,
query: 'event.action: "user_login" and source.ip: "192.168.1.100"',
language: 'kuery',
Expand All @@ -71,18 +74,18 @@ export const savedKqlQuery: SavedKqlQuery = {
saved_query_id: 'fake-saved-query-id',
};

export const eqlQuery: DiffableAllFields['eql_query'] = {
export const eqlQuery: RuleEqlQuery = {
query: 'process where process.name == "powershell.exe" and process.args : "* -EncodedCommand *"',
language: 'eql',
filters,
};

export const dataSourceWithIndexPatterns: DiffableAllFields['data_source'] = {
export const dataSourceWithIndexPatterns: DataSourceIndexPatterns = {
type: DataSourceType.index_patterns,
index_patterns: ['logs-*'],
};

export const dataSourceWithDataView: DiffableAllFields['data_source'] = {
export const dataSourceWithDataView: DataSourceDataView = {
type: DataSourceType.data_view,
data_view_id: 'logs-*',
};
Expand Down

0 comments on commit 3753f04

Please sign in to comment.