Skip to content

Commit

Permalink
Track engagement of new selection syntax (#26839)
Browse files Browse the repository at this point in the history
## Summary & Motivation
As titled.
  • Loading branch information
salazarm authored Jan 6, 2025
1 parent ed3d48d commit 9dd96cd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const AssetSelectionInput = ({value, onChange, assets}: AssetSelectionInp
return (
<WrapperDiv>
<SelectionAutoCompleteInput
id="asset-selection-input"
nameBase="key"
attributesMap={attributesMap}
placeholder={placeholderTextForItems('Type an asset subset…', assets)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const GanttChartSelectionInput = ({
return (
<Wrapper>
<SelectionAutoCompleteInput
id="run-gantt-chart"
nameBase="name"
attributesMap={attributesMap}
placeholder="Type a step subset"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import {Colors, Icon} from '@dagster-io/ui-components';
import CodeMirror, {Editor, HintFunction} from 'codemirror';
import {Linter} from 'codemirror/addon/lint/lint';
import {useLayoutEffect, useMemo, useRef} from 'react';
import debounce from 'lodash/debounce';
import {useCallback, useLayoutEffect, useMemo, useRef} from 'react';
import styled, {createGlobalStyle, css} from 'styled-components';

import {
SelectionAutoCompleteInputCSS,
applyStaticSyntaxHighlighting,
} from './SelectionAutoCompleteHighlighter';
import {useTrackEvent} from '../app/analytics';
import {useUpdatingRef} from '../hooks/useUpdatingRef';
import {createSelectionHint} from '../selection/SelectionAutoComplete';

Expand All @@ -19,6 +21,7 @@ import 'codemirror/addon/lint/lint.css';
import 'codemirror/addon/display/placeholder';

type SelectionAutoCompleteInputProps<T extends Record<string, string[]>, N extends keyof T> = {
id: string; // Used for logging
nameBase: N;
attributesMap: T;
placeholder: string;
Expand All @@ -29,6 +32,7 @@ type SelectionAutoCompleteInputProps<T extends Record<string, string[]>, N exten
};

export const SelectionAutoCompleteInput = <T extends Record<string, string[]>, N extends keyof T>({
id,
value,
nameBase,
placeholder,
Expand All @@ -37,6 +41,31 @@ export const SelectionAutoCompleteInput = <T extends Record<string, string[]>, N
linter,
attributesMap,
}: SelectionAutoCompleteInputProps<T, N>) => {
const trackEvent = useTrackEvent();

const trackSelection = useMemo(() => {
return debounce((selection: string) => {
const selectionLowerCase = selection.toLowerCase();
const hasBooleanLogic =
selectionLowerCase.includes(' or ') ||
selectionLowerCase.includes(' and ') ||
selectionLowerCase.includes(' not ') ||
selectionLowerCase.startsWith('not ');
trackEvent(`${id}-selection-query`, {
selection,
booleanLogic: hasBooleanLogic,
});
}, 5000);
}, [trackEvent, id]);

const onSelectionChange = useCallback(
(selection: string) => {
onChange(selection);
trackSelection(selection);
},
[onChange, trackSelection],
);

const editorRef = useRef<HTMLDivElement>(null);
const cmInstance = useRef<CodeMirror.Editor | null>(null);

Expand Down Expand Up @@ -88,7 +117,7 @@ export const SelectionAutoCompleteInput = <T extends Record<string, string[]>, N
clearTimeout(setValueTimeoutRef.current);
}
setValueTimeoutRef.current = setTimeout(() => {
onChange(newValue);
onSelectionChange(newValue);
}, 2000);

if (change.origin === 'complete' && change.text[0]?.endsWith('()')) {
Expand All @@ -113,7 +142,7 @@ export const SelectionAutoCompleteInput = <T extends Record<string, string[]>, N

cmInstance.current.on('blur', () => {
if (currentPendingValueRef.current !== currentValueRef.current) {
onChange(currentPendingValueRef.current);
onSelectionChange(currentPendingValueRef.current);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// parser.ts

import {BailErrorStrategy, CharStreams, CommonTokenStream} from 'antlr4ts';
import {ParseTree} from 'antlr4ts/tree/ParseTree';
import memoize from 'lodash/memoize';
Expand Down Expand Up @@ -60,7 +58,7 @@ export const parseInput = memoize((input: string): ParseResult => {
// Advance currentPosition to the end of the parsed input
const lastToken = tokenStream.get(tokenStream.index - 1);
currentPosition += lastToken.stopIndex + 1;
} catch (e) {
} catch {
// Parsing error occurred
const currentErrors = errorListener.getErrors();

Expand Down

1 comment on commit 9dd96cd

@github-actions
Copy link

Choose a reason for hiding this comment

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

Deploy preview for dagit-core-storybook ready!

✅ Preview
https://dagit-core-storybook-n5s6dc48g-elementl.vercel.app

Built with commit 9dd96cd.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.