-
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.
- Loading branch information
Showing
5 changed files
with
163 additions
and
20 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
73 changes: 73 additions & 0 deletions
73
js_modules/dagster-ui/packages/ui-core/src/asset-data/AssetDataRefreshButton.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,73 @@ | ||
import {Box, Button, Colors, Icon, RefreshButton, Tooltip} from '@dagster-io/ui-components'; | ||
import dayjs from 'dayjs'; | ||
import relativeTime from 'dayjs/plugin/relativeTime'; | ||
import updateLocale from 'dayjs/plugin/updateLocale'; | ||
import React from 'react'; | ||
|
||
dayjs.extend(relativeTime); | ||
dayjs.extend(updateLocale); | ||
|
||
dayjs.updateLocale('en', { | ||
relativeTime: { | ||
future: 'in %s', | ||
past: '%s ago', | ||
s: '%d seconds', | ||
m: 'a minute', | ||
mm: '%d minutes', | ||
h: 'an hour', | ||
hh: '%d hours', | ||
d: 'a day', | ||
dd: '%d days', | ||
M: 'a month', | ||
MM: '%d months', | ||
y: 'a year', | ||
yy: '%d years', | ||
}, | ||
}); | ||
|
||
export const AssetDataRefreshButton = ({ | ||
isRefreshing, | ||
onRefresh, | ||
oldestDataTimestamp, | ||
}: { | ||
isRefreshing: boolean; | ||
onRefresh: () => void; | ||
oldestDataTimestamp: number; | ||
}) => { | ||
return ( | ||
<Tooltip | ||
content={ | ||
isRefreshing ? ( | ||
'Refreshing asset data…' | ||
) : ( | ||
<Box flex={{direction: 'column', gap: 4}}> | ||
<TimeFromNowWithSeconds timestamp={oldestDataTimestamp} /> | ||
<div>Click to refresh now</div> | ||
</Box> | ||
) | ||
} | ||
> | ||
<Button | ||
icon={<Icon name="refresh" color={Colors.Gray400} />} | ||
onClick={() => { | ||
if (!isRefreshing) { | ||
onRefresh(); | ||
} | ||
}} | ||
/> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
const TimeFromNowWithSeconds: React.FC<{timestamp: number}> = ({timestamp}) => { | ||
const [text, setText] = React.useState(dayjs(timestamp).fromNow(true)); | ||
React.useEffect(() => { | ||
const interval = setInterval(() => { | ||
setText(dayjs(timestamp).fromNow(true)); | ||
}, 1000); | ||
return () => { | ||
clearInterval(interval); | ||
}; | ||
}, [timestamp]); | ||
return <>{text === '0s' ? 'Refreshing asset data…' : `Data is at most ${text} old`}</>; | ||
}; |
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