-
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.
[rfc] Add back "materialize changed and missing" as a dialog (#17115)
## Summary & Motivation We no longer fetch all of the asset status information in the graph up front so we can't show a number on the option, instead we will lazily fetch the stale status on click in a dialog: <img width="300" alt="Screenshot 2023-10-10 at 10 11 42 AM" src="https://github.com/dagster-io/dagster/assets/2286579/06a7e2c0-1115-4a45-a595-a3ae71035163"> <img width="606" alt="Screenshot 2023-10-10 at 9 00 10 AM" src="https://github.com/dagster-io/dagster/assets/2286579/bd3091bc-597d-4f60-8cd5-972a954832b6"> <img width="545" alt="Screenshot 2023-10-10 at 10 19 22 AM" src="https://github.com/dagster-io/dagster/assets/2286579/638c7550-a96c-4f2f-8f49-1ec8c4b6fc78"> <img width="560" alt="Screenshot 2023-10-10 at 8 50 23 AM" src="https://github.com/dagster-io/dagster/assets/2286579/070016cd-cdb4-4819-9780-78de49fb3229"> ## How I Tested These Changes Locally
- Loading branch information
Showing
6 changed files
with
264 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
219 changes: 219 additions & 0 deletions
219
js_modules/dagster-ui/packages/ui-core/src/assets/CalculateChangedAndMissingDialog.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,219 @@ | ||
import {useQuery, gql} from '@apollo/client'; | ||
import { | ||
Spinner, | ||
Dialog, | ||
DialogBody, | ||
DialogFooter, | ||
Button, | ||
Box, | ||
Icon, | ||
Colors, | ||
Checkbox, | ||
MiddleTruncate, | ||
} from '@dagster-io/ui-components'; | ||
import {useVirtualizer} from '@tanstack/react-virtual'; | ||
import React from 'react'; | ||
import {Link} from 'react-router-dom'; | ||
import styled from 'styled-components'; | ||
|
||
import {showCustomAlert} from '../app/CustomAlertProvider'; | ||
import {displayNameForAssetKey} from '../asset-graph/Utils'; | ||
import {Container, Inner, Row} from '../ui/VirtualizedTable'; | ||
|
||
import {isAssetStale, isAssetMissing} from './Stale'; | ||
import {asAssetKeyInput} from './asInput'; | ||
import {assetDetailsPathForKey} from './assetDetailsPathForKey'; | ||
import {AssetKey} from './types'; | ||
import { | ||
AssetStaleStatusQuery, | ||
AssetStaleStatusQueryVariables, | ||
} from './types/CalculateChangedAndMissingDialog.types'; | ||
|
||
export const CalculateChangedAndMissingDialog = React.memo( | ||
({ | ||
isOpen, | ||
onClose, | ||
assets, | ||
onMaterializeAssets, | ||
}: { | ||
isOpen: boolean; | ||
assets: { | ||
assetKey: AssetKey; | ||
}[]; | ||
onClose: () => void; | ||
onMaterializeAssets: (assets: AssetKey[], e: React.MouseEvent<any>) => void; | ||
}) => { | ||
const {data, loading, error} = useQuery<AssetStaleStatusQuery, AssetStaleStatusQueryVariables>( | ||
ASSET_STALE_STATUS_QUERY, | ||
{ | ||
variables: { | ||
assetKeys: assets.map(asAssetKeyInput), | ||
}, | ||
skip: !isOpen, | ||
}, | ||
); | ||
|
||
const staleOrMissing = React.useMemo( | ||
() => | ||
data?.assetNodes | ||
.filter((node) => isAssetStale(node) || isAssetMissing(node)) | ||
.map(asAssetKeyInput), | ||
[data], | ||
); | ||
|
||
React.useEffect(() => { | ||
if (isOpen && !loading && (!data || error)) { | ||
showCustomAlert({ | ||
title: 'Could not fetch stale status for assets', | ||
body: 'An unknown error occurred.', | ||
}); | ||
onClose(); | ||
} | ||
}, [data, error, isOpen, loading, onClose]); | ||
|
||
const containerRef = React.useRef<HTMLDivElement | null>(null); | ||
const virtualizer = useVirtualizer({ | ||
count: staleOrMissing?.length ?? 0, | ||
getScrollElement: () => containerRef.current, | ||
estimateSize: () => 28, | ||
}); | ||
const totalHeight = virtualizer.getTotalSize(); | ||
const items = virtualizer.getVirtualItems(); | ||
|
||
const [checked, setChecked] = React.useState<Set<AssetKey>>(new Set()); | ||
React.useLayoutEffect(() => { | ||
setChecked(new Set(staleOrMissing)); | ||
}, [staleOrMissing]); | ||
|
||
const content = () => { | ||
if (!isOpen) { | ||
return null; | ||
} | ||
if (loading) { | ||
return ( | ||
<Box flex={{alignItems: 'center', gap: 8}}> | ||
<Spinner purpose="body-text" /> Fetching asset statuses | ||
</Box> | ||
); | ||
} | ||
if (staleOrMissing?.length) { | ||
return ( | ||
<> | ||
<RowGrid border="bottom" padding={{bottom: 8}}> | ||
<Checkbox | ||
id="check-all" | ||
checked={checked.size === staleOrMissing.length} | ||
onChange={() => { | ||
setChecked((checked) => { | ||
if (checked.size === staleOrMissing.length) { | ||
return new Set(); | ||
} else { | ||
return new Set(staleOrMissing); | ||
} | ||
}); | ||
}} | ||
/> | ||
<label htmlFor="check-all" style={{color: Colors.Gray500, cursor: 'pointer'}}> | ||
Asset Name | ||
</label> | ||
</RowGrid> | ||
<Container ref={containerRef} style={{maxHeight: '400px'}}> | ||
<Inner $totalHeight={totalHeight}> | ||
{items.map(({index, key, size, start, measureElement}) => { | ||
const item = staleOrMissing[index]!; | ||
return ( | ||
<Row $height={size} $start={start} key={key} ref={measureElement}> | ||
<RowGrid border="bottom"> | ||
<Checkbox | ||
id={`checkbox-${key}`} | ||
checked={checked.has(item)} | ||
onChange={() => { | ||
setChecked((checked) => { | ||
const copy = new Set(checked); | ||
if (copy.has(item)) { | ||
copy.delete(item); | ||
} else { | ||
copy.add(item); | ||
} | ||
return copy; | ||
}); | ||
}} | ||
/> | ||
<Box | ||
as="label" | ||
htmlFor={`checkbox-${key}`} | ||
flex={{alignItems: 'center', gap: 4}} | ||
style={{cursor: 'pointer'}} | ||
> | ||
<Box flex={{shrink: 1}}> | ||
<MiddleTruncate text={displayNameForAssetKey(item)} /> | ||
</Box> | ||
<Link to={assetDetailsPathForKey(item)} target="_blank"> | ||
<Icon name="open_in_new" color={Colors.Link} /> | ||
</Link> | ||
</Box> | ||
</RowGrid> | ||
</Row> | ||
); | ||
})} | ||
</Inner> | ||
</Container> | ||
</> | ||
); | ||
} | ||
return ( | ||
<Box flex={{alignItems: 'center', gap: 8}}> | ||
<Icon name="check_circle" color={Colors.Green500} /> | ||
<div>All assets are up to date</div> | ||
</Box> | ||
); | ||
}; | ||
return ( | ||
<> | ||
<Dialog isOpen={isOpen} onClose={onClose} title="Materialize changed and missing assets"> | ||
<DialogBody>{content()}</DialogBody> | ||
<DialogFooter topBorder> | ||
{loading ? ( | ||
<Button onClick={onClose}>Cancel</Button> | ||
) : staleOrMissing?.length ? ( | ||
<Button | ||
intent="primary" | ||
onClick={(e) => { | ||
onMaterializeAssets(Array.from(checked), e); | ||
onClose(); | ||
}} | ||
disabled={checked.size === 0} | ||
> | ||
Materialize {checked.size} assets | ||
</Button> | ||
) : ( | ||
<Button onClick={onClose}>Dismiss</Button> | ||
)} | ||
</DialogFooter> | ||
</Dialog> | ||
</> | ||
); | ||
}, | ||
); | ||
|
||
const ASSET_STALE_STATUS_QUERY = gql` | ||
query AssetStaleStatusQuery($assetKeys: [AssetKeyInput!]!) { | ||
assetNodes(assetKeys: $assetKeys) { | ||
id | ||
assetKey { | ||
path | ||
} | ||
staleStatus | ||
} | ||
} | ||
`; | ||
|
||
const TEMPLATE_COLUMNS = '20px minmax(0, 1fr)'; | ||
|
||
const RowGrid = styled(Box)` | ||
display: grid; | ||
grid-template-columns: ${TEMPLATE_COLUMNS}; | ||
gap: 8px; | ||
height: 100%; | ||
align-items: center; | ||
`; |
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.
ffda9b1
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-kp3apl2fv-elementl.vercel.app
Built with commit ffda9b1.
This pull request is being automatically deployed with vercel-action