Skip to content

Commit

Permalink
[INTERNAL_BRANCH=salazarm/refactor-internal]
Browse files Browse the repository at this point in the history
  • Loading branch information
salazarm committed Jan 31, 2025
1 parent f0fe61b commit f08ad95
Showing 1 changed file with 31 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export interface SelectionAutoCompleteProvider {
createOperatorSuggestion: (prop: {
text: string;
displayText: string;
type: 'and' | 'or' | 'not' | 'parenthesis' | 'up-traversal' | 'down-traversal';
type: OperatorType;
}) => Suggestion;

useAutoComplete: (prop: {line: string; cursorIndex: number}) => {
Expand All @@ -94,38 +94,37 @@ export type Suggestion = {
jsx: React.ReactNode;
};

export const Operator = ({
displayText,
type,
}: {
displayText: string;
type: 'and' | 'or' | 'not' | 'parenthesis' | 'up-traversal' | 'down-traversal';
}) => {
const icon: IconName | null = 'curly_braces';
let label: string | null = null;
type OperatorType = 'and' | 'or' | 'not' | 'parenthesis' | 'up-traversal' | 'down-traversal';

switch (type) {
case 'or':
case 'not':
case 'and': {
label = displayText.toUpperCase();
break;
}
case 'parenthesis': {
label = 'Parenthesis';
break;
}
case 'up-traversal': {
label = 'Include upstream dependencies';
break;
}
case 'down-traversal': {
label = 'Include downstream dependencies';
break;
}
default:
assertUnreachable(type);
}
const operatorToIconAndLabel: Record<OperatorType, {icon: IconName; label: string}> = {
and: {
icon: 'curly_braces',
label: 'And',
},
or: {
icon: 'curly_braces',
label: 'Or',
},
not: {
icon: 'curly_braces',
label: 'Not',
},
parenthesis: {
icon: 'curly_braces',
label: 'Parenthesis',
},
'up-traversal': {
icon: 'curly_braces',
label: 'Include upstream dependencies',
},
'down-traversal': {
icon: 'curly_braces',
label: 'Include downstream dependencies',
},
};

export const Operator = ({displayText, type}: {displayText: string; type: OperatorType}) => {
const {icon, label} = operatorToIconAndLabel[type];
return <SuggestionJSXBase label={label} icon={icon} rightLabel={displayText} />;
};

Expand Down

0 comments on commit f08ad95

Please sign in to comment.