Logs Panel: Allow text selection without changing Log Details state (#96995)

* LogRows: allow text selection even without popover menu

* Add unit test
This commit is contained in:
Matias Chomicki
2024-12-10 09:18:50 -06:00
committed by GitHub
parent 2f6183f34e
commit e6a6b3e31a
2 changed files with 29 additions and 5 deletions
@@ -275,4 +275,26 @@ describe('Popover menu', () => {
expect(onClickFilterOutString).toHaveBeenCalledTimes(1);
expect(onClickFilterString).toHaveBeenCalledTimes(1);
});
describe('Interacting with log details', () => {
it('Allows text selection even if the popover menu is not available', async () => {
setup({
onClickFilterOutString: undefined,
onClickFilterString: undefined,
});
await userEvent.click(screen.getByText('log message 1'));
expect(screen.queryByText('Copy selection')).not.toBeInTheDocument();
expect(screen.queryByText(/details/)).not.toBeInTheDocument();
});
it('Displays Log Details if there is no text selection', async () => {
jest.spyOn(document, 'getSelection').mockReturnValue(null);
setup({
onClickFilterOutString: undefined,
onClickFilterString: undefined,
});
await userEvent.click(screen.getByText('log message 1'));
expect(screen.queryByText('Copy selection')).not.toBeInTheDocument();
expect(screen.getByText(/details/)).toBeInTheDocument();
});
});
});
@@ -115,13 +115,15 @@ class UnThemedLogRows extends PureComponent<Props, State> {
}
handleSelection = (e: MouseEvent<HTMLTableRowElement>, row: LogRowModel): boolean => {
if (this.popoverMenuSupported() === false) {
return false;
}
const selection = document.getSelection()?.toString();
if (!selection) {
return false;
}
if (this.popoverMenuSupported() === false) {
// This signals onRowClick inside LogRow to skip the event because the user is selecting text
return selection ? true : false;
}
if (!this.logRowsRef.current) {
return false;
}
@@ -247,7 +249,7 @@ class UnThemedLogRows extends PureComponent<Props, State> {
pinLineButtonTooltipTitle={this.props.pinLineButtonTooltipTitle}
pinned={this.props.pinnedRowId === row.uid || pinnedLogs?.some((logId) => logId === row.rowId)}
isFilterLabelActive={this.props.isFilterLabelActive}
handleTextSelection={this.popoverMenuSupported() ? this.handleSelection : undefined}
handleTextSelection={this.handleSelection}
{...rest}
/>
))}
@@ -270,7 +272,7 @@ class UnThemedLogRows extends PureComponent<Props, State> {
pinLineButtonTooltipTitle={this.props.pinLineButtonTooltipTitle}
pinned={this.props.pinnedRowId === row.uid || pinnedLogs?.some((logId) => logId === row.rowId)}
isFilterLabelActive={this.props.isFilterLabelActive}
handleTextSelection={this.popoverMenuSupported() ? this.handleSelection : undefined}
handleTextSelection={this.handleSelection}
{...rest}
/>
))}