Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Selection Input] Refactor auto-complete system. #27389

Merged
merged 33 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bce7eae
selection input filter out kind tags
salazarm Jan 25, 2025
042bbfd
selection input filter out kind tags
salazarm Jan 25, 2025
3cbaa36
refactor
salazarm Jan 25, 2025
946b769
refactor
salazarm Jan 25, 2025
3ed99a3
refactor
salazarm Jan 26, 2025
f0b7d89
refactor
salazarm Jan 26, 2025
4b839fc
lint
salazarm Jan 26, 2025
8f77444
lint
salazarm Jan 26, 2025
2480c65
dont use ref
salazarm Jan 26, 2025
b8b7551
refactor yuge
salazarm Jan 28, 2025
3f0cd04
rename yuge
salazarm Jan 28, 2025
80af74c
rename yuge
salazarm Jan 28, 2025
fc93b91
support only strings and tags
salazarm Jan 28, 2025
216592d
nullable
salazarm Jan 28, 2025
c8e91d9
display text
salazarm Jan 28, 2025
b20e281
display text
salazarm Jan 28, 2025
867227e
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Jan 28, 2025
736f70f
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Jan 29, 2025
d14e685
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Jan 29, 2025
e2729f5
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Jan 29, 2025
79f5aaf
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Jan 30, 2025
8533dc8
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Jan 30, 2025
f0fe61b
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Jan 30, 2025
f08ad95
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Jan 31, 2025
65ca476
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Jan 31, 2025
a01bc9e
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Jan 31, 2025
512ea3f
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Jan 31, 2025
e50df39
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Feb 3, 2025
76531c8
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Feb 3, 2025
9960599
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Feb 3, 2025
6a4cbf1
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Feb 3, 2025
358d709
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Feb 3, 2025
d889556
[INTERNAL_BRANCH=salazarm/refactor-internal]
salazarm Feb 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {useCallback, useLayoutEffect, useMemo, useState} from 'react';
import {FeatureFlag} from 'shared/app/FeatureFlags.oss';
import {AssetGraphAssetSelectionInput} from 'shared/asset-graph/AssetGraphAssetSelectionInput.oss';
import {useAssetGraphExplorerFilters} from 'shared/asset-graph/useAssetGraphExplorerFilters.oss';
import {AssetSelectionInput} from 'shared/asset-selection/input/AssetSelectionInput.oss';
import styled from 'styled-components';

import {AssetEdges} from './AssetEdges';
Expand Down Expand Up @@ -53,7 +54,6 @@ import {
import {AssetLocation, useFindAssetLocation} from './useFindAssetLocation';
import {featureEnabled} from '../app/Flags';
import {AssetLiveDataRefreshButton} from '../asset-data/AssetLiveDataProvider';
import {AssetSelectionInput} from '../asset-selection/input/AssetSelectionInput';
import {LaunchAssetExecutionButton} from '../assets/LaunchAssetExecutionButton';
import {AssetKey} from '../assets/types';
import {DEFAULT_MAX_ZOOM, SVGViewport} from '../graph/SVGViewport';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type {Linter} from 'codemirror/addon/lint/lint';
import {useMemo} from 'react';
import {
AssetSelectionLexer,
AssetSelectionParser,
} from 'shared/asset-selection/AssetSelectionAntlr.oss';
import {createUseAssetSelectionAutoComplete as defaultCreateUseAssetSelectionAutoComplete} from 'shared/asset-selection/input/useAssetSelectionAutoComplete.oss';
import {useAssetSelectionAutoCompleteProvider as defaultUseAssetSelectionAutoCompleteProvider} from 'shared/asset-selection/input/useAssetSelectionAutoCompleteProvider.oss';

import {AssetGraphQueryItem} from '../../asset-graph/useAssetGraphData';
import {SelectionAutoCompleteProvider} from '../../selection/SelectionAutoCompleteProvider';
import {SelectionAutoCompleteInput} from '../../selection/SelectionInput';
import {createSelectionLinter} from '../../selection/createSelectionLinter';

Expand All @@ -15,7 +15,9 @@ interface AssetSelectionInputProps {
value: string;
onChange: (value: string) => void;
linter?: Linter<any>;
createUseAssetSelectionAutoComplete?: typeof defaultCreateUseAssetSelectionAutoComplete;
useAssetSelectionAutoCompleteProvider?: (
assets: AssetGraphQueryItem[],
) => SelectionAutoCompleteProvider;
}

const defaultLinter = createSelectionLinter({
Expand All @@ -28,17 +30,14 @@ export const AssetSelectionInput = ({
onChange,
assets,
linter = defaultLinter,
createUseAssetSelectionAutoComplete = defaultCreateUseAssetSelectionAutoComplete,
useAssetSelectionAutoCompleteProvider = defaultUseAssetSelectionAutoCompleteProvider,
}: AssetSelectionInputProps) => {
const useAssetSelectionAutoComplete = useMemo(
() => createUseAssetSelectionAutoComplete(assets),
[assets, createUseAssetSelectionAutoComplete],
);
const SelectionAutoCompleteProvider = useAssetSelectionAutoCompleteProvider(assets);

return (
<SelectionAutoCompleteInput
id="asset-selection-input"
useAutoComplete={useAssetSelectionAutoComplete}
SelectionAutoCompleteProvider={SelectionAutoCompleteProvider}
placeholder="Search and filter assets"
linter={linter}
value={value}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {useMemo} from 'react';

import {attributeToIcon, getAttributesMap} from './util';
import {AssetGraphQueryItem} from '../../asset-graph/useAssetGraphData';
import {createSelectionAutoComplete} from '../../selection/SelectionAutoComplete';
import {
SelectionAutoCompleteProvider,
createProvider,
} from '../../selection/SelectionAutoCompleteProvider';

export function useAssetSelectionAutoCompleteProvider(
assets: AssetGraphQueryItem[],
): SelectionAutoCompleteProvider {
const attributesMap = useMemo(() => getAttributesMap(assets), [assets]);

const baseProvider = useMemo(
() =>
createProvider({
attributesMap,
primaryAttributeKey: 'key',
attributeToIcon,
}),
[attributesMap],
);
const selectionHint = useMemo(() => createSelectionAutoComplete(baseProvider), [baseProvider]);

return {
...baseProvider,
useAutoComplete: ({line, cursorIndex}) => {
const autoCompleteResults = useMemo(
() => selectionHint(line, cursorIndex),
[line, cursorIndex],
);
return {
autoCompleteResults,
loading: false,
};
},
};
salazarm marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {FeatureFlag} from 'shared/app/FeatureFlags.oss';
import {AssetGraphAssetSelectionInput} from 'shared/asset-graph/AssetGraphAssetSelectionInput.oss';
import {AssetSelectionInput} from 'shared/asset-selection/input/AssetSelectionInput.oss';
import {useAssetSelectionState} from 'shared/asset-selection/useAssetSelectionState.oss';
import {FilterableAssetDefinition} from 'shared/assets/useAssetDefinitionFilterState.oss';

import {AssetSelectionInput} from './AssetSelectionInput';
import {featureEnabled} from '../../app/Flags';
import {useAssetSelectionFiltering} from '../useAssetSelectionFiltering';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import {IconName} from '@dagster-io/ui-components';

import {assertUnreachable} from '../../app/Util';
import {AssetGraphQueryItem} from '../../asset-graph/useAssetGraphData';
import {isKindTag} from '../../graph/KindTags';
import {weakMapMemoize} from '../../util/weakMapMemoize';
import {buildRepoPathForHuman} from '../../workspace/buildRepoAddress';

export const getAttributesMap = (assets: AssetGraphQueryItem[]) => {
const assetNamesSet: Set<string> = new Set();
const tagNamesSet: Set<string> = new Set();
const tagNamesSet: Set<{key: string; value: string}> = new Set();
const ownersSet: Set<string> = new Set();
const groupsSet: Set<string> = new Set();
const kindsSet: Set<string> = new Set();
Expand All @@ -13,13 +17,10 @@ export const getAttributesMap = (assets: AssetGraphQueryItem[]) => {
assets.forEach((asset) => {
assetNamesSet.add(asset.name);
asset.node.tags.forEach((tag) => {
if (tag.key && tag.value) {
// We add quotes around the equal sign here because the auto-complete suggestion already wraps the entire value in quotes.
// So wer end up with tag:"key"="value" as the final suggestion
tagNamesSet.add(`${tag.key}"="${tag.value}`);
} else {
tagNamesSet.add(tag.key);
if (isKindTag(tag)) {
return;
}
tagNamesSet.add(memoizedTag(tag.key, tag.value));
salazarm marked this conversation as resolved.
Show resolved Hide resolved
});
asset.node.owners.forEach((owner) => {
switch (owner.__typename) {
Expand Down Expand Up @@ -62,3 +63,20 @@ export const getAttributesMap = (assets: AssetGraphQueryItem[]) => {
code_location: codeLocations,
};
};

const memoizedTag = weakMapMemoize((key: string, value: string) => ({
key,
value,
}));
salazarm marked this conversation as resolved.
Show resolved Hide resolved

export type Attribute = 'kind' | 'code_location' | 'group' | 'owner' | 'tag' | 'status' | 'key';
salazarm marked this conversation as resolved.
Show resolved Hide resolved

export const attributeToIcon: Record<Attribute, IconName> = {
key: 'magnify_glass',
kind: 'compute_kind',
code_location: 'code_location',
group: 'asset_group',
owner: 'owner',
tag: 'tag',
status: 'status',
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {useMemo} from 'react';
import styled from 'styled-components';

import {RunGraphQueryItem} from './toGraphQueryItems';
import {NO_STATE} from '../run-selection/AntlrRunSelectionVisitor';
import {useGanttChartSelectionAutoCompleteProvider} from './useGanttChartSelectionAutoCompleteProvider';
import {RunSelectionLexer} from '../run-selection/generated/RunSelectionLexer';
import {RunSelectionParser} from '../run-selection/generated/RunSelectionParser';
import {InputDiv, SelectionAutoCompleteInput} from '../selection/SelectionInput';
import {createSelectionLinter} from '../selection/createSelectionLinter';
import {useSelectionInputAutoComplete} from '../selection/useSelectionInputAutoComplete';
import {weakMapMemoize} from '../util/weakMapMemoize';

export const GanttChartSelectionInput = ({
Expand All @@ -19,12 +17,11 @@ export const GanttChartSelectionInput = ({
value: string;
onChange: (value: string) => void;
}) => {
const useAutoComplete = useMemo(() => createAutoComplete(items), [items]);
return (
<Wrapper>
<SelectionAutoCompleteInput
id="run-gantt-chart"
useAutoComplete={useAutoComplete}
SelectionAutoCompleteProvider={useGanttChartSelectionAutoCompleteProvider(items)}
placeholder="Search and filter steps"
linter={getLinter()}
value={value}
Expand All @@ -33,43 +30,10 @@ export const GanttChartSelectionInput = ({
</Wrapper>
);
};

function createAutoComplete(items: RunGraphQueryItem[]) {
return function useAutoComplete(value: string, cursor: number) {
const attributesMap = useMemo(() => {
const statuses = new Set<string>();
const names = new Set<string>();

items.forEach((item) => {
if (item.metadata?.state) {
statuses.add(item.metadata.state);
} else {
statuses.add(NO_STATE);
}
names.add(item.name);
});
return {name: Array.from(names), status: Array.from(statuses)};
}, []);

return {
autoCompleteResults: useSelectionInputAutoComplete({
nameBase: 'name',
attributesMap,
functions: FUNCTIONS,
value,
cursor,
}),
loading: false,
};
};
}

const getLinter = weakMapMemoize(() =>
createSelectionLinter({Lexer: RunSelectionLexer, Parser: RunSelectionParser}),
);

const FUNCTIONS = ['sinks', 'roots'];

const Wrapper = styled.div`
${InputDiv} {
width: 24vw;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {useMemo} from 'react';

import {RunGraphQueryItem} from './toGraphQueryItems';
import {NO_STATE} from '../run-selection/AntlrRunSelectionVisitor';
import {createSelectionAutoComplete} from '../selection/SelectionAutoComplete';
import {
SelectionAutoCompleteProvider,
createProvider,
} from '../selection/SelectionAutoCompleteProvider';

export function useGanttChartSelectionAutoCompleteProvider(
items: RunGraphQueryItem[],
): SelectionAutoCompleteProvider {
const attributesMap = useMemo(() => {
const statuses = new Set<string>();
const names = new Set<string>();

items.forEach((item) => {
if (item.metadata?.state) {
statuses.add(item.metadata.state);
} else {
statuses.add(NO_STATE);
}
names.add(item.name);
});
return {name: Array.from(names), status: Array.from(statuses)};
}, [items]);

const baseProvider = useMemo(
() =>
createProvider({
attributesMap,
primaryAttributeKey: 'name',
attributeToIcon: iconMap,
}),
[attributesMap],
);
const selectionHint = useMemo(() => createSelectionAutoComplete(baseProvider), [baseProvider]);

return {
...baseProvider,
useAutoComplete: ({line, cursorIndex}) => {
const autoCompleteResults = useMemo(
() => selectionHint(line, cursorIndex),
[line, cursorIndex],
);
return {
autoCompleteResults,
loading: false,
};
},
};
}

export const iconMap = {
name: 'magnify_glass',
status: 'status',
} as const;
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {useMemo} from 'react';
import styled from 'styled-components';

import {useOpGraphSelectionAutoCompleteProvider} from './useOpGraphSelectionAutoCompleteProvider';
import {GraphQueryItem} from '../app/GraphQueryImpl';
import {OpSelectionLexer} from '../op-selection/generated/OpSelectionLexer';
import {OpSelectionParser} from '../op-selection/generated/OpSelectionParser';
import {InputDiv, SelectionAutoCompleteInput} from '../selection/SelectionInput';
import {createSelectionLinter} from '../selection/createSelectionLinter';
import {useSelectionInputAutoComplete} from '../selection/useSelectionInputAutoComplete';
import {weakMapMemoize} from '../util/weakMapMemoize';

export const OpGraphSelectionInput = ({
Expand All @@ -18,12 +17,11 @@ export const OpGraphSelectionInput = ({
value: string;
onChange: (value: string) => void;
}) => {
const useAutoComplete = useMemo(() => createAutoComplete(items), [items]);
return (
<Wrapper>
<SelectionAutoCompleteInput
id="op-graph"
useAutoComplete={useAutoComplete}
SelectionAutoCompleteProvider={useOpGraphSelectionAutoCompleteProvider(items)}
placeholder="Search and filter ops"
linter={getLinter()}
value={value}
Expand All @@ -33,35 +31,10 @@ export const OpGraphSelectionInput = ({
);
};

function createAutoComplete(items: GraphQueryItem[]) {
return function useAutoComplete(value: string, cursor: number) {
const attributesMap = useMemo(() => {
const names = new Set<string>();
items.forEach((item) => {
names.add(item.name);
});
return {name: Array.from(names)};
}, []);

return {
autoCompleteResults: useSelectionInputAutoComplete({
nameBase: 'name',
attributesMap,
functions: FUNCTIONS,
value,
cursor,
}),
loading: false,
};
};
}

const getLinter = weakMapMemoize(() =>
createSelectionLinter({Lexer: OpSelectionLexer, Parser: OpSelectionParser}),
);

const FUNCTIONS = ['sinks', 'roots'];

const Wrapper = styled.div`
${InputDiv} {
width: 24vw;
Expand Down
Loading