-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2/4] Add asset selection filtering to asset catalog table. (#25970)
## Summary & Motivation Add asset selection filtering to asset catalog table. ## How I Tested These Changes Manually tested <img width="1718" alt="Screenshot 2024-11-16 at 7 54 23 PM" src="https://github.com/user-attachments/assets/df535d76-2ce5-431b-a89c-34f59dc79173"> ## Changelog [ui] The asset catalog now supports filtering using the asset selection syntax.
- Loading branch information
Showing
11 changed files
with
188 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
js_modules/dagster-ui/packages/ui-core/src/asset-selection/useAssetSelectionFiltering.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {useMemo} from 'react'; | ||
import {FilterableAssetDefinition} from 'shared/assets/useAssetDefinitionFilterState.oss'; | ||
|
||
import {COMMON_COLLATOR} from '../app/Util'; | ||
import {tokenForAssetKey} from '../asset-graph/Utils'; | ||
import {AssetNodeForGraphQueryFragment} from '../asset-graph/types/useAssetGraphData.types'; | ||
import {useAssetGraphData} from '../asset-graph/useAssetGraphData'; | ||
|
||
export const useAssetSelectionFiltering = < | ||
T extends { | ||
id: string; | ||
key: {path: Array<string>}; | ||
definition?: FilterableAssetDefinition | null; | ||
}, | ||
>({ | ||
assetSelection, | ||
assets, | ||
}: { | ||
assetSelection: string; | ||
|
||
assets: T[]; | ||
}) => { | ||
const assetsByKey = useMemo( | ||
() => Object.fromEntries(assets.map((asset) => [tokenForAssetKey(asset.key), asset])), | ||
[assets], | ||
); | ||
|
||
const {fetchResult, graphQueryItems, graphAssetKeys} = useAssetGraphData( | ||
assetSelection, | ||
useMemo( | ||
() => ({ | ||
hideEdgesToNodesOutsideQuery: true, | ||
hideNodesMatching: (node: AssetNodeForGraphQueryFragment) => { | ||
return !assetsByKey[tokenForAssetKey(node.assetKey)]; | ||
}, | ||
}), | ||
[assetsByKey], | ||
), | ||
); | ||
|
||
const filtered = useMemo(() => { | ||
return ( | ||
graphAssetKeys | ||
.map((key) => assetsByKey[tokenForAssetKey(key)]!) | ||
.sort((a, b) => COMMON_COLLATOR.compare(a.key.path.join(''), b.key.path.join(''))) ?? [] | ||
); | ||
}, [graphAssetKeys, assetsByKey]); | ||
|
||
const filteredByKey = useMemo( | ||
() => Object.fromEntries(filtered.map((asset) => [tokenForAssetKey(asset.key), asset])), | ||
[filtered], | ||
); | ||
|
||
return {filtered, filteredByKey, fetchResult, graphAssetKeys, graphQueryItems}; | ||
}; |
34 changes: 34 additions & 0 deletions
34
js_modules/dagster-ui/packages/ui-core/src/asset-selection/useAssetSelectionInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {AssetGraphAssetSelectionInput} from 'shared/asset-graph/AssetGraphAssetSelectionInput.oss'; | ||
import {useAssetSelectionState} from 'shared/asset-selection/useAssetSelectionState.oss'; | ||
import {FilterableAssetDefinition} from 'shared/assets/useAssetDefinitionFilterState.oss'; | ||
|
||
import {useAssetSelectionFiltering} from './useAssetSelectionFiltering'; | ||
|
||
export const useAssetSelectionInput = < | ||
T extends { | ||
id: string; | ||
key: {path: Array<string>}; | ||
definition?: FilterableAssetDefinition | null; | ||
}, | ||
>( | ||
assets: T[], | ||
) => { | ||
const [assetSelection, setAssetSelection] = useAssetSelectionState(); | ||
|
||
const {graphQueryItems, fetchResult, filtered} = useAssetSelectionFiltering({ | ||
assetSelection, | ||
assets, | ||
}); | ||
|
||
const filterInput = ( | ||
<AssetGraphAssetSelectionInput | ||
items={graphQueryItems} | ||
value={assetSelection} | ||
placeholder="Type an asset subset…" | ||
onChange={setAssetSelection} | ||
popoverPosition="bottom-left" | ||
/> | ||
); | ||
|
||
return {filterInput, fetchResult, filtered, assetSelection, setAssetSelection}; | ||
}; |
8 changes: 8 additions & 0 deletions
8
js_modules/dagster-ui/packages/ui-core/src/asset-selection/useAssetSelectionState.oss.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {useQueryPersistedState} from '../hooks/useQueryPersistedState'; | ||
|
||
export function useAssetSelectionState() { | ||
return useQueryPersistedState<string>({ | ||
queryKey: 'asset-selection', | ||
defaults: {['asset-selection']: ''}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
ec82b0e
There was a problem hiding this comment.
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-drnr0lr2w-elementl.vercel.app
Built with commit ec82b0e.
This pull request is being automatically deployed with vercel-action