Logs: Add feature to tracking show context button click (#57074)

* report interaction on context open

* report interaction on context close_esc

* replace deprecated feature (KeyboardEvent.keyCode)

* update to report interaction on toggle context

* remove redundant if statement
This commit is contained in:
Gareth Dawson
2022-10-19 10:01:45 +01:00
committed by GitHub
parent 96660992f4
commit 20616eef8c
3 changed files with 16 additions and 9 deletions
@@ -96,7 +96,14 @@ class UnThemedLogRow extends PureComponent<Props, State> {
showDetails: false, showDetails: false,
}; };
toggleContext = () => { toggleContext = (method: string) => {
const { datasourceType, uid: logRowUid } = this.props.row;
reportInteraction('grafana_explore_logs_log_context_clicked', {
datasourceType,
logRowUid,
type: method,
});
this.props.toggleContextIsOpen?.(); this.props.toggleContextIsOpen?.();
this.setState((state) => { this.setState((state) => {
return { return {
@@ -20,7 +20,7 @@ interface LogRowContextProps {
errors?: LogRowContextQueryErrors; errors?: LogRowContextQueryErrors;
hasMoreContextRows?: HasMoreContextRows; hasMoreContextRows?: HasMoreContextRows;
logsSortOrder?: LogsSortOrder | null; logsSortOrder?: LogsSortOrder | null;
onOutsideClick: () => void; onOutsideClick: (method: string) => void;
onLoadMoreContext: () => void; onLoadMoreContext: () => void;
} }
@@ -290,21 +290,21 @@ export const LogRowContext: React.FunctionComponent<LogRowContextProps> = ({
}) => { }) => {
useEffect(() => { useEffect(() => {
const handleEscKeyDown = (e: KeyboardEvent): void => { const handleEscKeyDown = (e: KeyboardEvent): void => {
if (e.keyCode === 27) { if (e.key === 'Escape' || e.key === 'Esc') {
onOutsideClick(); onOutsideClick('close_esc');
} }
}; };
document.addEventListener('keydown', handleEscKeyDown, false); document.addEventListener('keydown', handleEscKeyDown, false);
return () => { return () => {
document.removeEventListener('keydown', handleEscKeyDown, false); document.removeEventListener('keydown', handleEscKeyDown, false);
}; };
}, [onOutsideClick]); }, [onOutsideClick, row]);
const { afterContext, beforeContext, title, top, actions, width } = useStyles2((theme) => const { afterContext, beforeContext, title, top, actions, width } = useStyles2((theme) =>
getLogRowContextStyles(theme, wrapLogMessage) getLogRowContextStyles(theme, wrapLogMessage)
); );
return ( return (
<ClickOutsideWrapper onClick={onOutsideClick}> <ClickOutsideWrapper onClick={() => onOutsideClick('close_outside_click')}>
{/* e.stopPropagation is necessary so the log details doesn't open when clicked on log line in context {/* e.stopPropagation is necessary so the log details doesn't open when clicked on log line in context
* and/or when context log line is being highlighted */} * and/or when context log line is being highlighted */}
<div onClick={(e) => e.stopPropagation()}> <div onClick={(e) => e.stopPropagation()}>
@@ -337,7 +337,7 @@ export const LogRowContext: React.FunctionComponent<LogRowContextProps> = ({
<div className={cx(title, width)}> <div className={cx(title, width)}>
<h5>Log context</h5> <h5>Log context</h5>
<div className={actions}> <div className={actions}>
<IconButton size="lg" name="times" onClick={onOutsideClick} /> <IconButton size="lg" name="times" onClick={() => onOutsideClick('close_button')} />
</div> </div>
</div> </div>
</div> </div>
@@ -27,7 +27,7 @@ interface Props extends Themeable2 {
scrollElement?: HTMLDivElement; scrollElement?: HTMLDivElement;
showContextToggle?: (row?: LogRowModel) => boolean; showContextToggle?: (row?: LogRowModel) => boolean;
getRows: () => LogRowModel[]; getRows: () => LogRowModel[];
onToggleContext: () => void; onToggleContext: (method: string) => void;
updateLimit?: () => void; updateLimit?: () => void;
logsSortOrder?: LogsSortOrder | null; logsSortOrder?: LogsSortOrder | null;
} }
@@ -122,7 +122,7 @@ class UnThemedLogRowMessage extends PureComponent<Props> {
onContextToggle = (e: React.SyntheticEvent<HTMLElement>) => { onContextToggle = (e: React.SyntheticEvent<HTMLElement>) => {
e.stopPropagation(); e.stopPropagation();
this.props.onToggleContext(); this.props.onToggleContext('open');
}; };
onShowContextClick = (e: React.SyntheticEvent<HTMLElement, Event>) => { onShowContextClick = (e: React.SyntheticEvent<HTMLElement, Event>) => {