Skip to content
Merged
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
Expand Up @@ -50,6 +50,7 @@ import type { DocViewFilterFn } from '@kbn/unified-doc-viewer/types';
import { AdditionalFieldGroups } from '@kbn/unified-field-list';
import { useDataGridInTableSearch } from '@kbn/data-grid-in-table-search';
import { useThrottleFn } from '@kbn/react-hooks';
import { getDataViewFieldOrCreateFromColumnMeta } from '@kbn/data-view-utils';
import { DATA_GRID_DENSITY_STYLE_MAP, useDataGridDensity } from '../hooks/use_data_grid_density';
import {
UnifiedDataTableSettings,
Expand Down Expand Up @@ -819,21 +820,28 @@ export const UnifiedDataTable = ({
[displayedRows]
);

const cellActionsFields = useMemo<UseDataGridColumnsCellActionsProps['fields']>(
() =>
cellActionsTriggerId
? visibleColumns.map(
(columnName) =>
dataView.getFieldByName(columnName)?.toSpec() ?? {
name: '',
type: '',
aggregatable: false,
searchable: false,
}
)
: undefined,
[cellActionsTriggerId, visibleColumns, dataView]
);
const cellActionsFields = useMemo<UseDataGridColumnsCellActionsProps['fields']>(() => {
if (!cellActionsTriggerId) {
return undefined;
}

return visibleColumns.map((columnName) => {
const field = getDataViewFieldOrCreateFromColumnMeta({
dataView,
fieldName: columnName,
columnMeta: columnsMeta?.[columnName],
});
return (
field?.toSpec() ?? {
name: '',
type: '',
aggregatable: false,
searchable: false,
}
);
});
}, [cellActionsTriggerId, visibleColumns, dataView, columnsMeta]);

const allCellActionsMetadata = useMemo(
() => ({ dataViewId: dataView.id, ...(cellActionsMetadata ?? {}) }),
[dataView, cellActionsMetadata]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
type DiscoverCellActionExecutionContext,
} from '../types';
import { createContextAwarenessMocks } from '../__mocks__';
import { DataViewField } from '@kbn/data-views-plugin/common';

let mockUuid = 0;

Expand Down Expand Up @@ -237,12 +236,12 @@ describe('createCellAction', () => {
...context,
data: [
{
field: new DataViewField({
name: 'test',
type: 'string',
aggregatable: true,
searchable: true,
}),
field: {
name: '',
type: '',
aggregatable: false,
searchable: false,
},
},
],
metadata: { instanceId: 'test', dataView: dataViewWithTimefieldMock },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ export const createCellAction = (
return false;
}

const field = data[0]?.field;
const fieldSpec = data[0]?.field;
const field = fieldSpec?.name ? metadata.dataView?.fields.create(fieldSpec) : undefined;

if (!field || !metadata.dataView?.getFieldByName(field.name)) {
if (!field) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await checkAlert('Another example data source action executed');
});

it('should render additional cell actions for computed columns', async () => {
const state = kbnRison.encode({
dataSource: { type: 'esql' },
query: {
esql: 'from my-example-logs | sort @timestamp desc | eval foo = "bar"',
},
columns: ['foo'],
});
await PageObjects.common.navigateToActualUrl('discover', `?_a=${state}`, {
ensureCurrentUrl: false,
});
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.discover.waitUntilSearchingHasFinished();
await dataGrid.clickCellExpandButton(0, { columnName: 'foo' });
await dataGrid.clickCellExpandPopoverAction('example-data-source-action');
await checkAlert('Example data source action executed');
});

it('should not render incompatible cell action for message column', async () => {
const state = kbnRison.encode({
dataSource: { type: 'esql' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await checkAlert('Another example data source action executed');
});

it('should render additional cell actions for computed columns', async () => {
const state = kbnRison.encode({
dataSource: { type: 'esql' },
query: {
esql: 'from my-example-logs | sort @timestamp desc | eval foo = "bar"',
},
columns: ['foo'],
});
await PageObjects.common.navigateToActualUrl('discover', `?_a=${state}`, {
ensureCurrentUrl: false,
});
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.discover.waitUntilSearchingHasFinished();
await dataGrid.clickCellExpandButton(0, { columnName: 'foo' });
await dataGrid.clickCellExpandPopoverAction('example-data-source-action');
await checkAlert('Example data source action executed');
});

it('should not render incompatible cell action for message column', async () => {
const state = kbnRison.encode({
dataSource: { type: 'esql' },
Expand Down