-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[2/n][Asset Graph Sidebar] - Consolidate filtering #16536
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import {Box, Icon} from '@dagster-io/ui-components'; | ||
import React from 'react'; | ||
|
||
import {AssetGroupSelector} from '../graphql/types'; | ||
import {TruncatedTextWithFullTextOnHover} from '../nav/getLeftNavItemsForOption'; | ||
import {useFilters} from '../ui/Filters'; | ||
import {FilterObject} from '../ui/Filters/useFilter'; | ||
import {useStaticSetFilter} from '../ui/Filters/useStaticSetFilter'; | ||
import {DagsterRepoOption, WorkspaceContext} from '../workspace/WorkspaceContext'; | ||
import {buildRepoAddress, buildRepoPathForHuman} from '../workspace/buildRepoAddress'; | ||
|
||
export const AssetGraphExplorerFilters = React.memo( | ||
({ | ||
assetGroups, | ||
visibleAssetGroups, | ||
setGroupFilters, | ||
}: | ||
| { | ||
assetGroups: AssetGroupSelector[]; | ||
visibleAssetGroups: AssetGroupSelector[]; | ||
setGroupFilters: (groups: AssetGroupSelector[]) => void; | ||
} | ||
| {assetGroups?: null; setGroupFilters?: null; visibleAssetGroups?: null}) => { | ||
const {allRepos, visibleRepos, toggleVisible} = React.useContext(WorkspaceContext); | ||
|
||
const visibleReposSet = React.useMemo(() => new Set(visibleRepos), [visibleRepos]); | ||
|
||
const reposFilter = useStaticSetFilter<DagsterRepoOption>({ | ||
name: 'Repository', | ||
icon: 'repo', | ||
allValues: allRepos.map((repo) => ({ | ||
key: repo.repository.id, | ||
value: repo, | ||
match: [buildRepoPathForHuman(repo.repository.name, repo.repositoryLocation.name)], | ||
})), | ||
menuWidth: '300px', | ||
renderLabel: ({value}) => ( | ||
<Box flex={{direction: 'row', gap: 4, alignItems: 'center'}}> | ||
<Icon name="repo" /> | ||
<TruncatedTextWithFullTextOnHover | ||
text={buildRepoPathForHuman(value.repository.name, value.repositoryLocation.name)} | ||
/> | ||
</Box> | ||
), | ||
getStringValue: (value) => | ||
buildRepoPathForHuman(value.repository.name, value.repositoryLocation.name), | ||
initialState: visibleReposSet, | ||
onStateChanged: (values) => { | ||
allRepos.forEach((repo) => { | ||
if (visibleReposSet.has(repo) !== values.has(repo)) { | ||
toggleVisible([buildRepoAddress(repo.repository.name, repo.repositoryLocation.name)]); | ||
} | ||
}); | ||
}, | ||
}); | ||
|
||
const groupsFilter = useStaticSetFilter<AssetGroupSelector>({ | ||
name: 'Asset Groups', | ||
icon: 'asset_group', | ||
allValues: (assetGroups || []).map((group) => ({ | ||
key: group.groupName, | ||
value: | ||
visibleAssetGroups?.find( | ||
(visibleGroup) => | ||
visibleGroup.groupName === group.groupName && | ||
visibleGroup.repositoryName === group.repositoryName && | ||
visibleGroup.repositoryLocationName === group.repositoryLocationName, | ||
) ?? group, | ||
match: [group.groupName], | ||
})), | ||
menuWidth: '300px', | ||
renderLabel: ({value}) => ( | ||
<Box flex={{direction: 'row', gap: 4, alignItems: 'center'}}> | ||
<Icon name="repo" /> | ||
<TruncatedTextWithFullTextOnHover | ||
tooltipText={ | ||
value.groupName + | ||
' - ' + | ||
buildRepoPathForHuman(value.repositoryName, value.repositoryLocationName) | ||
} | ||
text={ | ||
<> | ||
{value.groupName} | ||
<span style={{opacity: 0.5, paddingLeft: '4px'}}> | ||
{buildRepoPathForHuman(value.repositoryName, value.repositoryLocationName)} | ||
</span> | ||
</> | ||
} | ||
/> | ||
</Box> | ||
), | ||
getStringValue: (group) => group.groupName, | ||
initialState: React.useMemo(() => new Set(visibleAssetGroups ?? []), [visibleAssetGroups]), | ||
onStateChanged: (values) => { | ||
if (setGroupFilters) { | ||
setGroupFilters(Array.from(values)); | ||
} | ||
}, | ||
}); | ||
|
||
const filters: FilterObject[] = []; | ||
if (allRepos.length > 1) { | ||
filters.push(reposFilter); | ||
} | ||
if (assetGroups) { | ||
filters.push(groupsFilter); | ||
} | ||
const {button} = useFilters({filters}); | ||
if (allRepos.length <= 1 && !assetGroups) { | ||
return null; | ||
} | ||
return button; | ||
}, | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,17 +4,17 @@ import * as React from 'react'; | |
import {useHistory, useParams} from 'react-router-dom'; | ||
|
||
import {AssetGraphExplorer} from '../asset-graph/AssetGraphExplorer'; | ||
import {AssetGraphExplorerFilters} from '../asset-graph/AssetGraphExplorerFilters'; | ||
import {AssetGraphFetchScope} from '../asset-graph/useAssetGraphData'; | ||
import {AssetLocation} from '../asset-graph/useFindAssetLocation'; | ||
import {AssetGroupSelector} from '../graphql/types'; | ||
import {useDocumentTitle} from '../hooks/useDocumentTitle'; | ||
import {useQueryPersistedState} from '../hooks/useQueryPersistedState'; | ||
import {RepoFilterButton} from '../instance/RepoFilterButton'; | ||
import {ExplorerPath} from '../pipelines/PipelinePathUtils'; | ||
import {ReloadAllButton} from '../workspace/ReloadAllButton'; | ||
import {WorkspaceContext} from '../workspace/WorkspaceContext'; | ||
|
||
import {AssetGroupSuggest, buildAssetGroupSelector} from './AssetGroupSuggest'; | ||
import {buildAssetGroupSelector} from './AssetGroupSuggest'; | ||
import {assetDetailsPathForKey} from './assetDetailsPathForKey'; | ||
import { | ||
globalAssetGraphPathFromString, | ||
|
@@ -27,7 +27,7 @@ interface AssetGroupRootParams { | |
|
||
export const AssetsGroupsGlobalGraphRoot: React.FC = () => { | ||
const {0: path} = useParams<AssetGroupRootParams>(); | ||
const {allRepos, visibleRepos} = React.useContext(WorkspaceContext); | ||
const {visibleRepos} = React.useContext(WorkspaceContext); | ||
const history = useHistory(); | ||
|
||
const [filters, setFilters] = useQueryPersistedState<{groups: AssetGroupSelector[]}>({ | ||
|
@@ -103,14 +103,14 @@ export const AssetsGroupsGlobalGraphRoot: React.FC = () => { | |
<AssetGraphExplorer | ||
fetchOptions={fetchOptions} | ||
fetchOptionFilters={ | ||
<> | ||
{allRepos.length > 1 && <RepoFilterButton />} | ||
<AssetGroupSuggest | ||
assetGroups={assetGroups} | ||
value={filters.groups || []} | ||
onChange={(groups) => setFilters({...filters, groups})} | ||
/> | ||
</> | ||
<AssetGraphExplorerFilters | ||
assetGroups={assetGroups} | ||
visibleAssetGroups={React.useMemo(() => filters.groups || [], [filters.groups])} | ||
setGroupFilters={React.useCallback((groups) => setFilters({...filters, groups}), [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still not a fan of inlining hooks into the rendered content because it can break with early returns / refactoring (eg: if you moved this into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like inlining because of code co-colocation but yeah I can definitely see refactoring being a bit more work although not very challenging work |
||
filters, | ||
setFilters, | ||
])} | ||
/> | ||
} | ||
options={{preferAssetRendering: true, explodeComposites: true}} | ||
explorerPath={globalAssetGraphPathFromString(path)} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,7 +250,7 @@ export const FilterDropdown = ({filters, setIsOpen, setPortaledElements}: Filter | |
<Container | ||
ref={parentRef} | ||
style={{ | ||
maxHeight: '500px', | ||
maxHeight: `min(500px, 50vh)`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stupid question I think but does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes it does |
||
overflowY: 'auto', | ||
width: selectedFilter?.menuWidth || 'auto', | ||
}} | ||
|
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.
I think the
decode
in theuseQueryPersistedState
on line 35 achieves this and you don't need the memo here?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.
ah okay wasn't sure