-
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.
[ui] Show a delayed loading spinner on Overview search inputs (#16607)
## Summary & Motivation Show a delayed loading spinner on Overview search inputs to inform the user that the workspace is still loading. This way, when they attempt a search that comes up empty, there will be an obvious reason for it: the workspace isn't ready yet. <img width="562" alt="Screenshot 2023-09-18 at 4 59 43 PM" src="https://github.com/dagster-io/dagster/assets/2823852/8aec765c-7ed3-4430-b623-c7a105bd2052"> I added a utility hook to `ui-components` for a delayed state update, which will allow us to wait briefly before showing the spinner. This prevents a quick flash of the spinner in cases where the workspace loads fairly quickly. I'll use the utility in a couple of places in Cloud that I've done this in recently. ## How I Tested These Changes View Overview, verify that spinners appear after a brief delay when the loading state is forced to be true. Storybook example for the utility hook.
- Loading branch information
Showing
8 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
.../dagster-ui/packages/ui-components/src/components/__stories__/useDelayedState.stories.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,23 @@ | ||
import {Meta} from '@storybook/react'; | ||
import * as React from 'react'; | ||
|
||
import {Box} from '../Box'; | ||
import {Button} from '../Button'; | ||
import {useDelayedState} from '../useDelayedState'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default { | ||
title: 'useDelayedState', | ||
} as Meta; | ||
|
||
export const Default = () => { | ||
const notDisabled = useDelayedState(5000); | ||
return ( | ||
<Box flex={{direction: 'column', gap: 12}}> | ||
<div>The button will become enabled after five seconds.</div> | ||
<div> | ||
<Button disabled={!notDisabled}>Wait for it</Button> | ||
</div> | ||
</Box> | ||
); | ||
}; |
12 changes: 12 additions & 0 deletions
12
js_modules/dagster-ui/packages/ui-components/src/components/useDelayedState.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,12 @@ | ||
import * as React from 'react'; | ||
|
||
export const useDelayedState = (delayMsec: number) => { | ||
const [value, setValue] = React.useState(false); | ||
|
||
React.useEffect(() => { | ||
const timer = setTimeout(() => setValue(true), delayMsec); | ||
return () => clearTimeout(timer); | ||
}, [delayMsec]); | ||
|
||
return value; | ||
}; |
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
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
25 changes: 25 additions & 0 deletions
25
js_modules/dagster-ui/packages/ui-core/src/ui/SearchInputSpinner.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,25 @@ | ||
import {Box, Spinner, Tooltip, useDelayedState} from '@dagster-io/ui-components'; | ||
import * as React from 'react'; | ||
|
||
interface Props { | ||
tooltipContent: string | React.ReactElement | null; | ||
} | ||
|
||
const SPINNER_WAIT_MSEC = 2000; | ||
|
||
export const SearchInputSpinner = (props: Props) => { | ||
const {tooltipContent} = props; | ||
const canShowSpinner = useDelayedState(SPINNER_WAIT_MSEC); | ||
|
||
if (!canShowSpinner) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Box margin={{top: 1}}> | ||
<Tooltip placement="top" canShow={!!tooltipContent} content={tooltipContent || ''}> | ||
<Spinner purpose="body-text" /> | ||
</Tooltip> | ||
</Box> | ||
); | ||
}; |
04692d1
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-storybook ready!
✅ Preview
https://dagit-storybook-pdo7a4cs7-elementl.vercel.app
Built with commit 04692d1.
This pull request is being automatically deployed with vercel-action
04692d1
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-382sp4lxj-elementl.vercel.app
Built with commit 04692d1.
This pull request is being automatically deployed with vercel-action