Skip to content

Commit ead86dc

Browse files
mohamedhamed-ahmedniros1
authored andcommitted
[Stream] UX Improvements Part 2 (#235049)
closes [Partitioning UX Improvements Part 2](elastic/streams-program#494) ## πŸ“ Summary This PR addresses the below UI changes: 1. Add expand/collapse column to the Partitioning table 2. Added table toolbar 3. Changed match document filter component selection style ## πŸŽ₯ Demo https://github.com/user-attachments/assets/3b15e2d3-50c7-4b90-936e-697e393fcc9f
1 parent 291d6ca commit ead86dc

File tree

12 files changed

+250
-217
lines changed

12 files changed

+250
-217
lines changed

β€Žx-pack/platform/plugins/shared/streams_app/public/components/data_management/schema_editor/flyout/sample_preview_table.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { Streams } from '@kbn/streams-schema';
1313
import { useKibana } from '../../../../hooks/use_kibana';
1414
import { getFormattedError } from '../../../../util/errors';
1515
import { useStreamsAppFetch } from '../../../../hooks/use_streams_app_fetch';
16-
import { PreviewTable } from '../../preview_table';
16+
import { PreviewTable } from '../../shared/preview_table';
1717
import { LoadingPanel } from '../../../loading_panel';
1818
import type { MappedSchemaField, SchemaField } from '../types';
1919
import { isSchemaFieldTyped } from '../types';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
export { PreviewFlyout } from './preview_flyout';
8+
export type { DataTableRecordWithIndex } from './preview_flyout';
9+
export { MemoPreviewTable } from './preview_table';
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type { DataTableRecord } from '@kbn/discover-utils';
1111
import useAsync from 'react-use/lib/useAsync';
1212
import type { DocViewsRegistry } from '@kbn/unified-doc-viewer';
1313
import { useKibana } from '../../../hooks/use_kibana';
14-
import { useSimulatorSelector } from './state_management/stream_enrichment_state_machine';
1514

1615
export const FLYOUT_WIDTH_KEY = 'streamsEnrichment:flyoutWidth';
1716

@@ -24,13 +23,14 @@ export const PreviewFlyout = ({
2423
hits,
2524
setExpandedDoc,
2625
docViewsRegistry,
26+
streamName,
2727
}: {
2828
currentDoc?: DataTableRecordWithIndex;
2929
hits: DataTableRecordWithIndex[];
3030
setExpandedDoc: (doc?: DataTableRecordWithIndex) => void;
3131
docViewsRegistry: DocViewsRegistry;
32+
streamName: string;
3233
}) => {
33-
const streamName = useSimulatorSelector((state) => state.context.streamName);
3434
const { core, dependencies } = useKibana();
3535
const { data } = dependencies.start;
3636

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,31 @@ import type {
1010
EuiDataGridRowHeightsOptions,
1111
EuiDataGridSorting,
1212
} from '@elastic/eui';
13-
import { EuiDataGrid, useEuiTheme } from '@elastic/eui';
13+
import {
14+
EuiAvatar,
15+
EuiButtonIcon,
16+
EuiDataGrid,
17+
EuiFlexGroup,
18+
EuiToolTip,
19+
useEuiTheme,
20+
} from '@elastic/eui';
1421
import { i18n } from '@kbn/i18n';
1522
import type { SampleDocument } from '@kbn/streams-schema';
1623
import React, { useMemo, useState, useCallback } from 'react';
1724
import { css } from '@emotion/css';
1825
import { recalcColumnWidths } from '../stream_detail_enrichment/utils';
19-
import type { SimulationContext } from '../stream_detail_enrichment/state_management/simulation_state_machine';
26+
import type {
27+
SampleDocumentWithUIAttributes,
28+
SimulationContext,
29+
} from '../stream_detail_enrichment/state_management/simulation_state_machine';
30+
import { DATA_SOURCES_I18N } from '../stream_detail_enrichment/data_sources_flyout/translations';
31+
import { useDataSourceSelectorById } from '../stream_detail_enrichment/state_management/data_source_state_machine';
32+
import type { EnrichmentDataSourceWithUIAttributes } from '../stream_detail_enrichment/types';
2033

2134
const emptyCell = <>&nbsp;</>;
2235

36+
export const MemoPreviewTable = React.memo(PreviewTable);
37+
2338
export function PreviewTable({
2439
documents,
2540
displayColumns,
@@ -32,7 +47,9 @@ export function PreviewTable({
3247
setVisibleColumns,
3348
columnOrderHint = [],
3449
selectedRowIndex,
35-
leadingControlColumns,
50+
showRowSourceAvatars = false,
51+
originalSamples,
52+
onRowSelected,
3653
}: {
3754
documents: SampleDocument[];
3855
displayColumns?: string[];
@@ -45,7 +62,9 @@ export function PreviewTable({
4562
sorting?: SimulationContext['previewColumnsSorting'];
4663
setSorting?: (sorting: SimulationContext['previewColumnsSorting']) => void;
4764
selectedRowIndex?: number;
48-
leadingControlColumns?: EuiDataGridControlColumn[];
65+
showRowSourceAvatars?: boolean;
66+
originalSamples?: SampleDocumentWithUIAttributes[];
67+
onRowSelected?: (rowIndex: number) => void;
4968
}) {
5069
const { euiTheme: theme } = useEuiTheme();
5170
// Determine canonical column order
@@ -117,6 +136,43 @@ export function PreviewTable({
117136

118137
const [columnWidths, setColumnWidths] = useState<Record<string, number | undefined>>({});
119138

139+
const leadingControlColumns: EuiDataGridControlColumn[] = useMemo(
140+
() => [
141+
{
142+
id: 'selection',
143+
width: showRowSourceAvatars ? 72 : 36,
144+
headerCellRender: () => null,
145+
rowCellRender: ({ rowIndex }) => {
146+
const originalSample = originalSamples?.[rowIndex];
147+
return (
148+
<EuiFlexGroup gutterSize="s">
149+
<EuiButtonIcon
150+
onClick={() => {
151+
if (onRowSelected) {
152+
onRowSelected(rowIndex);
153+
}
154+
}}
155+
aria-label={i18n.translate(
156+
'xpack.streams.resultPanel.euiDataGrid.preview.selectRowAriaLabel',
157+
{
158+
defaultMessage: 'Select row {rowIndex}',
159+
values: { rowIndex: rowIndex + 1 },
160+
}
161+
)}
162+
iconType={selectedRowIndex === rowIndex ? 'minimize' : 'expand'}
163+
color={selectedRowIndex === rowIndex ? 'primary' : 'text'}
164+
/>
165+
{showRowSourceAvatars && originalSample && (
166+
<RowSourceAvatar originalSample={originalSample} />
167+
)}
168+
</EuiFlexGroup>
169+
);
170+
},
171+
},
172+
],
173+
[onRowSelected, showRowSourceAvatars, selectedRowIndex, originalSamples]
174+
);
175+
120176
// Derive visibleColumns from canonical order
121177
const visibleColumns = useMemo(() => {
122178
if (displayColumns) {
@@ -213,3 +269,36 @@ export function PreviewTable({
213269
/>
214270
);
215271
}
272+
273+
function dataSourceTypeToI18nKey(type: EnrichmentDataSourceWithUIAttributes['type']) {
274+
switch (type) {
275+
case 'random-samples':
276+
return 'randomSamples';
277+
case 'kql-samples':
278+
return 'kqlDataSource';
279+
case 'custom-samples':
280+
return 'customSamples';
281+
}
282+
}
283+
284+
function RowSourceAvatar({ originalSample }: { originalSample: SampleDocumentWithUIAttributes }) {
285+
const dataSourceContext = useDataSourceSelectorById(
286+
originalSample.dataSourceId,
287+
(snapshot) => snapshot?.context
288+
);
289+
if (!dataSourceContext) {
290+
// If the data source context is not available, we cannot render the avatar
291+
return null;
292+
}
293+
const {
294+
uiAttributes: { color },
295+
dataSource: { type: dataSourceType, name: rawDataSourceName },
296+
} = dataSourceContext;
297+
const name =
298+
rawDataSourceName || DATA_SOURCES_I18N[dataSourceTypeToI18nKey(dataSourceType)].placeholderName;
299+
return (
300+
<EuiToolTip content={name}>
301+
<EuiAvatar size="s" color={color} initialsLength={1} name={name} />
302+
</EuiToolTip>
303+
);
304+
}

β€Žx-pack/platform/plugins/shared/streams_app/public/components/data_management/stream_detail_enrichment/data_sources_flyout/data_source_card.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { useDiscardConfirm } from '../../../../hooks/use_discard_confirm';
2727
import type { DataSourceActorRef } from '../state_management/data_source_state_machine';
2828
import { useDataSourceSelector } from '../state_management/data_source_state_machine';
2929
import { AssetImage } from '../../../asset_image';
30-
import { PreviewTable } from '../../preview_table';
30+
import { PreviewTable } from '../../shared/preview_table';
3131
import { DATA_SOURCES_I18N } from './translations';
3232

3333
interface DataSourceCardProps {

β€Žx-pack/platform/plugins/shared/streams_app/public/components/data_management/stream_detail_enrichment/processing_preview_table.tsxβ€Ž

Lines changed: 0 additions & 126 deletions
This file was deleted.

0 commit comments

Comments
Β (0)