Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datatable Embeddable Supports Ephemeral Sort #117742

Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,16 @@ export const createGridColumns = (
showHide: false,
showMoveLeft: false,
showMoveRight: false,
showSortAsc: isReadOnly
? false
: {
label: i18n.translate('xpack.lens.table.sort.ascLabel', {
defaultMessage: 'Sort ascending',
}),
},
showSortDesc: isReadOnly
? false
: {
label: i18n.translate('xpack.lens.table.sort.descLabel', {
defaultMessage: 'Sort descending',
}),
},
showSortAsc: {
label: i18n.translate('xpack.lens.table.sort.ascLabel', {
defaultMessage: 'Sort ascending',
}),
},
showSortDesc: {
label: i18n.translate('xpack.lens.table.sort.descLabel', {
defaultMessage: 'Sort descending',
}),
},
additional: additionalActions,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ export const DatatableComponent = (props: DatatableRenderProps) => {

const onEditAction = useCallback(
(data: LensSortAction['data'] | LensResizeAction['data'] | LensToggleAction['data']) => {
if (renderMode === 'edit') {
dispatchEvent({ name: 'edit', data });
}
dispatchEvent({ name: 'edit', data });
},
[dispatchEvent, renderMode]
);
Expand Down
28 changes: 27 additions & 1 deletion x-pack/plugins/lens/public/embeddable/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { UiActionsStart } from '../../../../../src/plugins/ui_actions/public';
import {
isLensBrushEvent,
isLensFilterEvent,
isLensEditEvent,
isLensTableRowContextMenuClickEvent,
LensBrushEvent,
LensFilterEvent,
Expand Down Expand Up @@ -432,7 +433,7 @@ export class Embeddable
return output;
}

handleEvent = (event: ExpressionRendererEvent) => {
handleEvent = async (event: ExpressionRendererEvent) => {
if (!this.deps.getTrigger || this.input.disableTriggers) {
return;
}
Expand Down Expand Up @@ -468,6 +469,31 @@ export class Embeddable
this.input.onTableRowClick(event.data as unknown as LensTableRowContextMenuEvent['data']);
}
}

// TODO - inject this from datatable_visualization/visualization
const onEditAction = (state, event) => {
switch (event.data.action) {
case 'sort':
return {
...state,
sorting: {
columnId: event.data.columnId,
direction: event.data.direction,
},
};
};
};
drewdaemon marked this conversation as resolved.
Show resolved Hide resolved

if (isLensEditEvent(event)) {
if (this.savedVis) {
const newSavedVis = JSON.parse(JSON.stringify(this.savedVis));
newSavedVis.state.visualization = onEditAction(this.savedVis.state.visualization, event);
const { ast, errors } = await this.deps.documentToExpression(newSavedVis);
this.errors = errors;
this.expression = ast ? toExpression(ast) : null;
this.reload();
}
}
};

async reload() {
Expand Down