-
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
- 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> | ||
); | ||
}; |