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

[Discover][UnifiedDataTable] Enable drag&drop for grid columns #197832

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 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 @@ -41,13 +41,17 @@
}

.euiDataGridHeaderCell {
align-items: start;
align-items: center;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To align with the "graggable" state of the header column which is in a portal and we can't override it there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can keep the original styles and have this work for dragging by adding this to our EuiDataGridColumn defs:

displayHeaderCellProps: { className: `unifiedDataTable__headerCell` }

Then we can remove these nested styles including euiDataGridHeaderCell__popover and euiDataGridHeaderCell__draggableIcon, and use a single global style:

.euiDataGridHeaderCell.unifiedDataTable__headerCell {
  align-items: start;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, thanks! Updated via 7946301


.euiPopover[class*='euiDataGridHeaderCell__popover'] {
align-self: center;
}
}

.euiDataGridHeaderCell__draggableIcon {
align-self: center;
}

.euiDataGrid--bordersHorizontal .euiDataGridHeader {
border-top: none;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1354,5 +1354,26 @@ describe('UnifiedDataTable', () => {
},
EXTENDED_JEST_TIMEOUT
);

it(
'should have columnVisibility configuration',
async () => {
const component = await getComponent({
...getProps(),
columns: ['message'],
});
expect(component.find(EuiDataGrid).last().prop('columnVisibility')).toMatchInlineSnapshot(`
Object {
"canDragAndDropColumns": true,
"setVisibleColumns": [Function],
"visibleColumns": Array [
"@timestamp",
"message",
],
}
`);
},
EXTENDED_JEST_TIMEOUT
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ export const UnifiedDataTable = ({
const schemaDetectors = useMemo(() => getSchemaDetectors(), []);
const columnsVisibility = useMemo(
() => ({
canDragAndDropColumns: true,
visibleColumns,
setVisibleColumns: (newColumns: string[]) => {
const dontModifyColumns = !shouldPrependTimeFieldColumn(newColumns);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

it('should not show reset width button for auto width column', async () => {
await unifiedFieldList.clickFieldListItemAdd('@message');
await header.waitUntilLoadingHasFinished();
await discover.waitUntilSearchingHasFinished();
expect(await dataGrid.resetColumnWidthExists('@message')).to.be(false);
});

it('should show reset width button for absolute width column, and allow resetting to auto width', async () => {
await unifiedFieldList.clickFieldListItemAdd('@message');
await header.waitUntilLoadingHasFinished();
await discover.waitUntilSearchingHasFinished();
await testResizeColumn('@message');
});

Expand Down
20 changes: 18 additions & 2 deletions test/functional/services/data_grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,25 @@ export class DataGridService extends FtrService {
public async resizeColumn(field: string, delta: number) {
const header = await this.getHeaderElement(field);
const originalWidth = (await header.getSize()).width;
const resizer = await header.findByCssSelector(
this.testSubjects.getCssSelector('dataGridColumnResizer')
const headerDraggableColumns = await this.find.allByCssSelector(
'[data-test-subj="euiDataGridHeaderDroppable"] > div'
);
// searching for a common parent of the field column header and its resizer
const fieldHeader: WebElementWrapper | null | undefined = (
await Promise.all(
headerDraggableColumns.map(async (column) => {
const hasFieldColumn =
(await column.findAllByCssSelector(`[data-gridcell-column-id="${field}"]`)).length > 0;
return hasFieldColumn ? column : null;
})
)
).find(Boolean);
const resizer = await fieldHeader?.findByTestSubject('dataGridColumnResizer');

if (!fieldHeader || !resizer) {
throw new Error(`Unable to find column resizer for field ${field}`);
}
Comment on lines +105 to +122
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, maybe we should ask EUI for a test subj on the draggable wrappers as a followup 😅


await this.browser.dragAndDrop({ location: resizer }, { location: { x: delta, y: 0 } });
return { originalWidth, newWidth: (await header.getSize()).width };
}
Expand Down