Skip to content

Commit 84900b0

Browse files
refactor selector
1 parent 08b6975 commit 84900b0

File tree

6 files changed

+14
-35
lines changed

6 files changed

+14
-35
lines changed

x-pack/platform/plugins/shared/streams_app/public/components/data_management/management_bottom_bar/index.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
import React from 'react';
99
import { EuiButton, EuiButtonEmpty, EuiFlexGroup, EuiToolTip, EuiBottomBar } from '@elastic/eui';
1010
import { i18n } from '@kbn/i18n';
11-
import type { StreamType } from '../../../telemetry/types';
1211
import { useDiscardConfirm } from '../../../hooks/use_discard_confirm';
13-
import { selectStreamTypeForTelemetry } from '../stream_detail_enrichment/state_management/stream_enrichment_state_machine/selectors';
12+
import { selectStreamType } from '../stream_detail_enrichment/state_management/stream_enrichment_state_machine/selectors';
1413
import { useStreamEnrichmentSelector } from '../stream_detail_enrichment/state_management/stream_enrichment_state_machine';
1514

1615
interface ManagementBottomBarProps {
@@ -32,9 +31,7 @@ export function ManagementBottomBar({
3231
onCancel,
3332
onConfirm,
3433
}: ManagementBottomBarProps) {
35-
const streamType: StreamType = useStreamEnrichmentSelector((snapshot) =>
36-
selectStreamTypeForTelemetry(snapshot.context)
37-
);
34+
const streamType = useStreamEnrichmentSelector((snapshot) => selectStreamType(snapshot.context));
3835

3936
const handleCancel = useDiscardConfirm(onCancel, {
4037
title: discardUnsavedChangesTitle,

x-pack/platform/plugins/shared/streams_app/public/components/data_management/shared/condition_editor.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
import type { RoutingStatus } from '@kbn/streams-schema';
2727
import React, { useMemo } from 'react';
2828
import useToggle from 'react-use/lib/useToggle';
29-
import type { StreamType } from '../../../telemetry/types';
3029
import {
3130
alwaysToEmptyEquals,
3231
conditionNeedsValueField,
@@ -37,7 +36,7 @@ import type { Suggestion } from './autocomplete_selector';
3736
import { AutocompleteSelector } from './autocomplete_selector';
3837
import { OperatorSelector } from './operator_selector';
3938
import { useStreamEnrichmentSelector } from '../stream_detail_enrichment/state_management/stream_enrichment_state_machine';
40-
import { selectStreamTypeForTelemetry } from '../stream_detail_enrichment/state_management/stream_enrichment_state_machine/selectors';
39+
import { selectStreamType } from '../stream_detail_enrichment/state_management/stream_enrichment_state_machine/selectors';
4140

4241
export interface ConditionEditorProps {
4342
condition: Condition;
@@ -132,9 +131,7 @@ function FilterConditionForm(props: {
132131
}) {
133132
const { condition, disabled, onConditionChange, fieldSuggestions, valueSuggestions } = props;
134133

135-
const streamType: StreamType = useStreamEnrichmentSelector((snapshot) =>
136-
selectStreamTypeForTelemetry(snapshot.context)
137-
);
134+
const streamType = useStreamEnrichmentSelector((snapshot) => selectStreamType(snapshot.context));
138135

139136
const operator = useMemo(() => {
140137
return getFilterOperator(condition);

x-pack/platform/plugins/shared/streams_app/public/components/data_management/stream_detail_enrichment/create_step_button.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ import {
1717
import React from 'react';
1818
import useToggle from 'react-use/lib/useToggle';
1919
import { i18n } from '@kbn/i18n';
20-
import type { StreamType } from '../../../telemetry/types';
2120
import {
2221
useStreamEnrichmentEvents,
2322
useStreamEnrichmentSelector,
2423
} from './state_management/stream_enrichment_state_machine';
25-
import { selectStreamTypeForTelemetry } from './state_management/stream_enrichment_state_machine/selectors';
24+
import { selectStreamType } from './state_management/stream_enrichment_state_machine/selectors';
2625

2726
const createConditionText = i18n.translate(
2827
'xpack.streams.streamDetailView.managementTab.enrichment.createConditionButtonText',
@@ -69,9 +68,7 @@ export const CreateStepButton: React.FC<AddStepProps> = ({
6968
(state) => state.can({ type: 'step.addProcessor' }) || state.can({ type: 'step.addCondition' })
7069
);
7170

72-
const streamType: StreamType = useStreamEnrichmentSelector((snapshot) =>
73-
selectStreamTypeForTelemetry(snapshot.context)
74-
);
71+
const streamType = useStreamEnrichmentSelector((snapshot) => selectStreamType(snapshot.context));
7572

7673
const [isPopoverOpen, togglePopover] = useToggle(false);
7774

x-pack/platform/plugins/shared/streams_app/public/components/data_management/stream_detail_enrichment/state_management/stream_enrichment_state_machine/selectors.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import { createSelector } from 'reselect';
99
import { isActionBlock } from '@kbn/streamlang';
10-
import { Streams } from '@kbn/streams-schema';
10+
import { getStreamTypeFromDefinition } from '../../../../../util/get_stream_type_from_definition';
1111
import type { StreamEnrichmentContextType } from './types';
1212
import { isStepUnderEdit } from '../steps_state_machine';
1313
import type { StreamType } from '../../../../../telemetry/types';
@@ -58,17 +58,9 @@ export const selectWhetherAnyProcessorBeforePersisted = createSelector(
5858
}
5959
);
6060

61-
export const selectStreamTypeForTelemetry = createSelector(
61+
export const selectStreamType = createSelector(
6262
[(context: StreamEnrichmentContextType) => context.definition],
6363
(definition): StreamType => {
64-
if (Streams.WiredStream.GetResponse.is(definition)) {
65-
return 'wired';
66-
}
67-
68-
if (Streams.ClassicStream.GetResponse.is(definition)) {
69-
return 'classic';
70-
}
71-
72-
return 'unknown';
64+
return getStreamTypeFromDefinition(definition.stream);
7365
}
7466
);

x-pack/platform/plugins/shared/streams_app/public/components/data_management/stream_detail_enrichment/steps/blocks/action/index.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import React, { useEffect, useRef } from 'react';
1010
import { EuiPanel, useEuiTheme } from '@elastic/eui';
1111
import { useFirstMountState } from 'react-use/lib/useFirstMountState';
1212
import { css } from '@emotion/react';
13-
import type { StreamType } from '../../../../../../telemetry/types';
1413
import {
1514
useSimulatorSelector,
1615
useStreamEnrichmentSelector,
@@ -21,7 +20,7 @@ import type { ProcessorMetrics } from '../../../state_management/simulation_stat
2120
import { ActionBlockEditor } from './editor';
2221
import { ActionBlockListItem } from './list_item';
2322
import { getStepPanelColour } from '../../../utils';
24-
import { selectStreamTypeForTelemetry } from '../../../state_management/stream_enrichment_state_machine/selectors';
23+
import { selectStreamType } from '../../../state_management/stream_enrichment_state_machine/selectors';
2524

2625
export type ActionBlockProps = StepConfigurationProps & {
2726
processorMetrics?: ProcessorMetrics;
@@ -34,9 +33,7 @@ export function ActionBlock(props: StepConfigurationProps) {
3433

3534
const simulation = useSimulatorSelector((snapshot) => snapshot.context.simulation);
3635

37-
const streamType: StreamType = useStreamEnrichmentSelector((snapshot) =>
38-
selectStreamTypeForTelemetry(snapshot.context)
39-
);
36+
const streamType = useStreamEnrichmentSelector((snapshot) => selectStreamType(snapshot.context));
4037

4138
const panelColour = getStepPanelColour(level);
4239

x-pack/platform/plugins/shared/streams_app/public/components/data_management/stream_detail_enrichment/steps/blocks/where/configuration.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import type { SubmitHandler } from 'react-hook-form';
2222
import { useForm, FormProvider, useController } from 'react-hook-form';
2323
import type { DeepPartial } from 'utility-types';
2424
import { useSelector } from '@xstate5/react';
25-
import type { StreamType } from '../../../../../../telemetry/types';
2625
import { useDiscardConfirm } from '../../../../../../hooks/use_discard_confirm';
2726
import {
2827
useStreamEnrichmentSelector,
@@ -35,7 +34,7 @@ import {
3534
} from '../../../utils';
3635
import { discardChangesPromptOptions, deleteConditionPromptOptions } from './prompt_options';
3736
import { ProcessorConditionEditorWrapper } from '../../../processor_condition_editor';
38-
import { selectStreamTypeForTelemetry } from '../../../state_management/stream_enrichment_state_machine/selectors';
37+
import { selectStreamType } from '../../../state_management/stream_enrichment_state_machine/selectors';
3938

4039
interface WhereBlockConfigurationProps {
4140
stepRef: StreamEnrichmentContextType['stepRefs'][number];
@@ -51,8 +50,8 @@ export const WhereBlockConfiguration = forwardRef<HTMLDivElement, WhereBlockConf
5150
const canDelete = useSelector(stepRef, (snapshot) => snapshot.can({ type: 'step.delete' }));
5251
const canSave = useSelector(stepRef, (snapshot) => snapshot.can({ type: 'step.save' }));
5352

54-
const streamType: StreamType = useStreamEnrichmentSelector((snapshot) =>
55-
selectStreamTypeForTelemetry(snapshot.context)
53+
const streamType = useStreamEnrichmentSelector((snapshot) =>
54+
selectStreamType(snapshot.context)
5655
);
5756

5857
const [defaultValues] = useState(() =>

0 commit comments

Comments
 (0)