From 04692d1802d49ebc1a87fa2d7c63043ec9441bc2 Mon Sep 17 00:00:00 2001
From: Isaac Hellendag <2823852+hellendag@users.noreply.github.com>
Date: Tue, 19 Sep 2023 15:56:52 -0500
Subject: [PATCH] [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.
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.
---
.../__stories__/useDelayedState.stories.tsx | 23 +++++++++++++++++
.../src/components/useDelayedState.tsx | 12 +++++++++
.../packages/ui-components/src/index.ts | 1 +
.../ui-core/src/overview/OverviewJobsRoot.tsx | 8 +++++-
.../src/overview/OverviewResourcesRoot.tsx | 10 +++++++-
.../src/overview/OverviewSchedulesRoot.tsx | 10 +++++++-
.../src/overview/OverviewSensorsRoot.tsx | 10 +++++++-
.../ui-core/src/ui/SearchInputSpinner.tsx | 25 +++++++++++++++++++
8 files changed, 95 insertions(+), 4 deletions(-)
create mode 100644 js_modules/dagster-ui/packages/ui-components/src/components/__stories__/useDelayedState.stories.tsx
create mode 100644 js_modules/dagster-ui/packages/ui-components/src/components/useDelayedState.tsx
create mode 100644 js_modules/dagster-ui/packages/ui-core/src/ui/SearchInputSpinner.tsx
diff --git a/js_modules/dagster-ui/packages/ui-components/src/components/__stories__/useDelayedState.stories.tsx b/js_modules/dagster-ui/packages/ui-components/src/components/__stories__/useDelayedState.stories.tsx
new file mode 100644
index 0000000000000..c75623a6a0da3
--- /dev/null
+++ b/js_modules/dagster-ui/packages/ui-components/src/components/__stories__/useDelayedState.stories.tsx
@@ -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 (
+
+
The button will become enabled after five seconds.