Skip to content

Commit 34bf11b

Browse files
committed
fix jest tests
1 parent 415f3ad commit 34bf11b

7 files changed

+791
-504
lines changed

js_modules/dagster-ui/packages/ui-core/src/selection/SelectionAutoComplete.g4

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ incompleteExpr:
4646
| leftParenToken postLogicalOperatorWhitespace expr # UnclosedParenthesizedExpression
4747
| expressionLessParenthesizedExpr # ExpressionlessParenthesizedExpressionWrapper
4848
| leftParenToken postLogicalOperatorWhitespace # UnclosedExpressionlessParenthesizedExpression
49-
| PLUS+ postNeighborTraversalWhitespace # IncompletePlusTraversalExpression
49+
| PLUS postNeighborTraversalWhitespace # IncompletePlusTraversalExpression
5050
| colonToken attributeValue postExpressionWhitespace # IncompleteAttributeExpressionMissingKey;
5151

5252
expressionLessParenthesizedExpr:

js_modules/dagster-ui/packages/ui-core/src/selection/SelectionAutoComplete.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ export type Suggestion =
4343
displayText?: string;
4444
type: 'attribute';
4545
attributeName?: string;
46+
}
47+
| {
48+
text: string;
49+
displayText?: string;
50+
type: 'traversal';
4651
};
4752

4853
type TextCallback = (value: string) => string;
@@ -238,6 +243,7 @@ export class SelectionAutoCompleteVisitor
238243
text: textCallback(substringMatchText),
239244
displayText: substringMatchDisplayText,
240245
type: 'attribute' as const,
246+
attributeName: `${this.nameBase}_substring`,
241247
});
242248
}
243249
this.addAttributeResults(value, textCallback);
@@ -268,13 +274,13 @@ export class SelectionAutoCompleteVisitor
268274
this.list.push({
269275
text: textCallback('+'),
270276
displayText: '+',
271-
type: 'logical_operator' as const,
277+
type: 'traversal' as const,
272278
});
273279
}
274280
this.list.push({
275281
text: textCallback('()'),
276282
displayText: '(',
277-
type: 'function' as const,
283+
type: 'parenthesis' as const,
278284
});
279285
}
280286
}
@@ -313,7 +319,7 @@ export class SelectionAutoCompleteVisitor
313319
);
314320

315321
if (!options.excludePlus) {
316-
this.list.push({text: '+', displayText: '+', type: 'logical_operator' as const});
322+
this.list.push({text: '+', displayText: '+', type: 'traversal' as const});
317323
}
318324

319325
if (isInsideExpressionlessParenthesizedExpression(ctx)) {
@@ -338,16 +344,16 @@ export class SelectionAutoCompleteVisitor
338344

339345
visitUpTraversal(ctx: UpTraversalContext) {
340346
if (ctx.text.includes('+')) {
341-
this.list.push({text: '+', displayText: '+', type: 'logical_operator' as const});
347+
this.list.push({text: '+', displayText: '+', type: 'traversal' as const});
342348
}
343-
this.list.push({text: '()', displayText: '(', type: 'function' as const});
349+
this.list.push({text: '()', displayText: '(', type: 'parenthesis' as const});
344350
}
345351

346352
visitDownTraversal(ctx: DownTraversalContext) {
347353
this.list.push({text: ' and ', displayText: 'and', type: 'logical_operator' as const});
348354
this.list.push({text: ' or ', displayText: 'or', type: 'logical_operator' as const});
349355
if (ctx.text.includes('+')) {
350-
this.list.push({text: '+', displayText: '+', type: 'logical_operator' as const});
356+
this.list.push({text: '+', displayText: '+', type: 'traversal' as const});
351357
}
352358
if (isInsideExpressionlessParenthesizedExpression(ctx)) {
353359
this.list.push({text: ')', displayText: ')', type: 'parenthesis' as const});
@@ -461,6 +467,7 @@ export class SelectionAutoCompleteVisitor
461467
}
462468
this.addUnmatchedValueResults('', DEFAULT_TEXT_CALLBACK, {
463469
excludeNot: true,
470+
excludePlus: true,
464471
});
465472
}
466473

@@ -484,7 +491,9 @@ export class SelectionAutoCompleteVisitor
484491
}
485492

486493
visitPostNeighborTraversalWhitespace(_ctx: PostNeighborTraversalWhitespaceContext) {
487-
this.addUnmatchedValueResults('', DEFAULT_TEXT_CALLBACK);
494+
this.addUnmatchedValueResults('', DEFAULT_TEXT_CALLBACK, {
495+
excludePlus: true,
496+
});
488497
}
489498

490499
visitPostUpwardTraversalWhitespace(_ctx: PostUpwardTraversalWhitespaceContext) {

js_modules/dagster-ui/packages/ui-core/src/selection/SelectionAutoCompleteInput.tsx

+5-13
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,15 @@ export const SelectionAutoCompleteInput = <T extends Record<string, string[]>, N
9090

9191
const [selectedIndexRef, setSelectedIndex] = useState({current: 0});
9292

93+
const scrollToSelectionRef = useRef(false);
94+
9395
useDangerousRenderEffect(() => {
9496
// Rather then using a useEffect + setState (extra render), we just set the current value directly
9597
selectedIndexRef.current = 0;
9698
if (!autocompleteResults?.list.length) {
9799
showResults.current = false;
98100
}
101+
scrollToSelectionRef.current = true;
99102
}, [autocompleteResults]);
100103

101104
const scheduleUpdateValue = useCallback(() => {
@@ -188,15 +191,6 @@ export const SelectionAutoCompleteInput = <T extends Record<string, string[]>, N
188191
applyStaticSyntaxHighlighting(cmInstance.current);
189192
});
190193
}
191-
192-
return () => {
193-
const cm = cmInstance.current;
194-
if (cm) {
195-
// Clean up the instance...
196-
cm.closeHint();
197-
cm.getWrapperElement()?.parentNode?.removeChild(cm.getWrapperElement());
198-
}
199-
};
200194
// eslint-disable-next-line react-hooks/exhaustive-deps
201195
}, []);
202196

@@ -265,8 +259,6 @@ export const SelectionAutoCompleteInput = <T extends Record<string, string[]>, N
265259
[autocompleteResults],
266260
);
267261

268-
const navigationTriggeredByKeyboard = useRef(false);
269-
270262
const handleKeyDown = useCallback(
271263
(e: KeyboardEvent<HTMLDivElement>) => {
272264
if (!showResults) {
@@ -275,7 +267,7 @@ export const SelectionAutoCompleteInput = <T extends Record<string, string[]>, N
275267
scheduleUpdateValue();
276268

277269
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
278-
navigationTriggeredByKeyboard.current = true;
270+
scrollToSelectionRef.current = true;
279271
}
280272

281273
if (e.key === 'ArrowDown') {
@@ -311,7 +303,7 @@ export const SelectionAutoCompleteInput = <T extends Record<string, string[]>, N
311303
results={autocompleteResults}
312304
width={width}
313305
selectedIndex={selectedIndexRef.current}
314-
scrollOnNavigate={navigationTriggeredByKeyboard}
306+
scrollToSelection={scrollToSelectionRef}
315307
onSelect={onSelect}
316308
scheduleUpdateValue={scheduleUpdateValue}
317309
setSelectedIndex={setSelectedIndex}

js_modules/dagster-ui/packages/ui-core/src/selection/SelectionAutoCompleteResults.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type SelectionAutoCompleteResultsProps = {
1414
selectedIndex: number;
1515
setSelectedIndex: React.Dispatch<React.SetStateAction<{current: number}>>;
1616
scheduleUpdateValue: () => void;
17-
scrollOnNavigate: MutableRefObject<boolean>;
17+
scrollToSelection: MutableRefObject<boolean>;
1818
};
1919

2020
export const SelectionAutoCompleteResults = ({
@@ -24,7 +24,7 @@ export const SelectionAutoCompleteResults = ({
2424
selectedIndex,
2525
scheduleUpdateValue,
2626
setSelectedIndex,
27-
scrollOnNavigate,
27+
scrollToSelection,
2828
}: SelectionAutoCompleteResultsProps) => {
2929
if (!results) {
3030
return null;
@@ -40,9 +40,9 @@ export const SelectionAutoCompleteResults = ({
4040
text={
4141
<div
4242
ref={
43-
index === selectedIndex && scrollOnNavigate.current
43+
index === selectedIndex && scrollToSelection.current
4444
? (el) => {
45-
scrollOnNavigate.current = false;
45+
scrollToSelection.current = false;
4646
if (el) {
4747
el.scrollIntoView({
4848
behavior: 'instant',

0 commit comments

Comments
 (0)