Skip to content
Draft
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
@@ -0,0 +1,20 @@
/*
* 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 React from 'react';
import { EuiBadge } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

export function DisabledBadge() {
return (
<EuiBadge color="subdued">
{i18n.translate('xpack.streams.streamDetailRouting.disabled', {
defaultMessage: 'Disabled',
})}
</EuiBadge>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ export { PreviewFlyout } from './preview_flyout';
export type { DataTableRecordWithIndex } from './preview_flyout';
export { MemoPreviewTable } from './preview_table';
export { ConditionPanel, ConditionDisplay, EditableConditionPanel } from './condition_display';
export { VerticalRule } from './vertical_rule';
export { DisabledBadge } from './disabled_badge';
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 React from 'react';
import styled from '@emotion/styled';
import { useEuiTheme } from '@elastic/eui';

export function VerticalRule() {
const { euiTheme } = useEuiTheme();

const CentralizedContainer = styled.div`
display: flex;
align-items: center;
padding: 0 ${euiTheme.size.xs};
`;

const Border = styled.div`
height: 20px;
border-right: ${euiTheme.border.thin};
`;

return (
<CentralizedContainer>
<Border />
</CentralizedContainer>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function ChildStreamList({ availableStreams }: { availableStreams: string
previewSuggestion,
acceptSuggestion,
rejectSuggestion,
updateSuggestion,
} = useReviewSuggestionsForm();

const { currentRuleId, definition, routing } = routingSnapshot.context;
Expand Down Expand Up @@ -233,6 +234,7 @@ export function ChildStreamList({ availableStreams }: { availableStreams: string
rejectSuggestion={rejectSuggestion}
resetForm={resetForm}
suggestions={suggestions}
updateSuggestion={updateSuggestion}
/>
)
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,34 @@ export const EditRoutingRuleControls = ({
);
};

export const EditSuggestedRuleControls = ({ onSave }: { onSave?: () => void }) => {
const routingSnapshot = useStreamsRoutingSelector((snapshot) => snapshot);
const { cancelChanges, saveEditedSuggestion } = useStreamRoutingEvents();

const canSave = routingSnapshot.can({ type: 'suggestion.saveSuggestion' });
const hasPrivileges = routingSnapshot.context.definition.privileges.manage;

const handleUpdate = () => {
if (onSave) {
onSave();
}
saveEditedSuggestion();
};

return (
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center" wrap>
<EuiFlexItem grow={false}>
<CancelButton onClick={cancelChanges} />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<PrivilegesTooltip hasPrivileges={hasPrivileges}>
<UpdateButton isLoading={false} isDisabled={!canSave} onClick={handleUpdate} />
</PrivilegesTooltip>
</EuiFlexItem>
</EuiFlexGroup>
);
};

const RemoveButton = ({
isDisabled,
onDelete,
Expand Down Expand Up @@ -125,8 +153,8 @@ const SaveButton = (props: EuiButtonPropsForButton) => (

const UpdateButton = (props: EuiButtonPropsForButton) => (
<EuiButton data-test-subj="streamsAppStreamDetailRoutingUpdateButton" size="s" fill {...props}>
{i18n.translate('xpack.streams.streamDetailRouting.change', {
defaultMessage: 'Change routing',
{i18n.translate('xpack.streams.streamDetailRouting.update', {
defaultMessage: 'Update',
})}
</EuiButton>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,10 @@ import { i18n } from '@kbn/i18n';
import { isDescendantOf, isRoutingEnabled } from '@kbn/streams-schema';
import { css } from '@emotion/css';
import { css as cssReact } from '@emotion/react';
import styled from '@emotion/styled';
import { useStreamsAppRouter } from '../../../hooks/use_streams_app_router';
import { ConditionPanel } from '../shared';
import { ConditionPanel, VerticalRule } from '../shared';
import type { RoutingDefinitionWithUIAttributes } from './types';

function VerticalRule() {
const { euiTheme } = useEuiTheme();
const CentralizedContainer = styled.div`
display: flex;
align-items: center;
padding: 0 ${euiTheme.size.xs};
`;

const Border = styled.div`
height: 20px;
border-right: ${euiTheme.border.thin};
`;

return (
<CentralizedContainer>
<Border />
</CentralizedContainer>
);
}
import { DisabledBadge } from '../shared';

export function IdleRoutingStreamEntry({
availableStreams,
Expand Down Expand Up @@ -143,11 +123,7 @@ export function IdleRoutingStreamEntry({
>
{!isRoutingEnabled(routingRule.status) && (
<>
<EuiBadge color="subdued">
{i18n.translate('xpack.streams.streamDetailRouting.disabled', {
defaultMessage: 'Disabled',
})}
</EuiBadge>
<DisabledBadge />
<VerticalRule />
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
EuiFlexItem,
EuiPanel,
EuiResizableContainer,
useIsWithinBreakpoints,
} from '@elastic/eui';
import { css } from '@emotion/css';
import type { Streams } from '@kbn/streams-schema';
Expand Down Expand Up @@ -107,7 +106,6 @@ export function StreamDetailRoutingImpl() {
});

const availableStreams = streamsListFetch.value?.streams.map((stream) => stream.name) ?? [];
const isVerticalLayout = useIsWithinBreakpoints(['xs', 's']);

return (
<EuiFlexItem
Expand All @@ -133,7 +131,7 @@ export function StreamDetailRoutingImpl() {
`}
paddingSize="none"
>
<EuiResizableContainer direction={isVerticalLayout ? 'vertical' : 'horizontal'}>
<EuiResizableContainer>
{(EuiResizablePanel, EuiResizableButton) => (
<>
<EuiResizablePanel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export function PreviewPanel() {
content = <EditingPanel />;
} else if (
routingSnapshot.matches({ ready: 'creatingNewRule' }) ||
routingSnapshot.matches({ ready: 'reviewSuggestedRule' })
routingSnapshot.matches({ ready: 'reviewSuggestedRule' }) ||
routingSnapshot.matches({ ready: 'editingSuggestedRule' })
) {
content = <SamplePreviewPanel enableActions />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ export function CreateStreamConfirmationModal({
forkStream({
destination: partition.name,
where: partition.condition,
}).then(() => onSuccess())
}).then((result) => {
if (result.success) {
onSuccess();
}
})
}
fill
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
import {
useStreamSamplesSelector,
useStreamsRoutingSelector,
useStreamRoutingEvents,
} from '../state_management/stream_routing_state_machine';
import { CreateStreamConfirmationModal } from './create_stream_confirmation_modal';
import type { AIFeatures } from '../../../../hooks/use_ai_features';
Expand All @@ -32,6 +33,7 @@ export interface ReviewSuggestionsFormProps
| 'previewSuggestion'
| 'acceptSuggestion'
| 'rejectSuggestion'
| 'updateSuggestion'
> {
suggestions: PartitionSuggestion[];
onRegenerate: (connectorId: string) => void;
Expand All @@ -48,29 +50,55 @@ export function ReviewSuggestionsForm({
previewSuggestion,
acceptSuggestion,
rejectSuggestion,
updateSuggestion,
onRegenerate,
}: ReviewSuggestionsFormProps) {
const ruleUnderReview = useStreamsRoutingSelector((snapshot) =>
snapshot.matches({ ready: 'reviewSuggestedRule' }) ? snapshot.context.suggestedRuleId : null
);
const editingSuggestion = useStreamsRoutingSelector((snapshot) =>
snapshot.matches({ ready: 'editingSuggestedRule' }) ? snapshot.context.editedSuggestion : null
);

// For the confirmation modal, use edited suggestion if available, otherwise find by name
const partitionForModal =
editingSuggestion || suggestions.find(({ name }) => name === ruleUnderReview)!;

const selectedPreviewName = useStreamSamplesSelector(
({ context }) =>
context.selectedPreview &&
context.selectedPreview.type === 'suggestion' &&
context.selectedPreview.name
);

const { editSuggestion } = useStreamRoutingEvents();
const routingSnapshot = useStreamsRoutingSelector((snapshot) => snapshot);

const handleSave = () => {
const currentEditingIndex = routingSnapshot.context.editingSuggestionIndex;
const currentEditedSuggestion = routingSnapshot.context.editedSuggestion;

if (currentEditingIndex !== null && currentEditedSuggestion) {
updateSuggestion(currentEditingIndex, currentEditedSuggestion);
}
};

return (
<>
{ruleUnderReview && (
{ruleUnderReview && partitionForModal && (
<CreateStreamConfirmationModal
partition={suggestions.find(({ name }) => name === ruleUnderReview)!}
onSuccess={() =>
acceptSuggestion(suggestions.findIndex(({ name }) => name === ruleUnderReview)!)
}
partition={partitionForModal}
onSuccess={() => {
acceptSuggestion(
editingSuggestion
? routingSnapshot.context.editingSuggestionIndex!
: suggestions.findIndex(({ name }) => name === ruleUnderReview)!
);
}}
/>
)}
<EuiCallOut
iconType="sparkles"
title={i18n.translate(
'xpack.streams.reviewSuggestionsForm.euiCallOut.reviewPartitioningSuggestionsLabel',
{ defaultMessage: 'Review partitioning suggestions' }
Expand All @@ -95,8 +123,11 @@ export function ReviewSuggestionsForm({
<SuggestedStreamPanel
definition={definition}
partition={partition}
index={index}
onPreview={(toggle) => previewSuggestion(index, toggle)}
onDismiss={() => rejectSuggestion(index, selectedPreviewName === partition.name)}
onEdit={editSuggestion}
onSave={handleSave}
/>
<EuiSpacer size="s" />
</NestedView>
Expand Down
Loading