-
Notifications
You must be signed in to change notification settings - Fork 181
Introduce SingleTask component #5925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: shauns/06-02-add_useexitonctrlc_hook
Are you sure you want to change the base?
Introduce SingleTask component #5925
Conversation
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
We detected some changes at Caution DO NOT create changesets for features which you do not wish to be included in the public changelog of the next CLI release. |
a1e1149
to
b4acbdb
Compare
Coverage report
Show new covered files 🐣
Test suite run success2917 tests passing in 1263 suites. Report generated by 🧪jest coverage report action from 0b86195 |
9089fc1
to
75ace80
Compare
72137d9
to
d4750fa
Compare
75ace80
to
03fea54
Compare
03fea54
to
0b86195
Compare
d4750fa
to
1f9a01f
Compare
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationspackages/cli-kit/dist/private/node/ui/components/LoadingBar.d.tsimport React from 'react';
interface LoadingBarProps {
title: string;
noColor?: boolean;
}
declare const LoadingBar: ({ title, noColor }: React.PropsWithChildren<LoadingBarProps>) => JSX.Element;
export { LoadingBar };
packages/cli-kit/dist/private/node/ui/components/SingleTask.d.tsimport React from 'react';
interface SingleTaskProps {
title: string;
taskPromise: Promise<unknown>;
noColor?: boolean;
}
declare const SingleTask: ({ taskPromise, title, noColor }: React.PropsWithChildren<SingleTaskProps>) => JSX.Element | null;
export { SingleTask };
packages/cli-kit/dist/private/node/ui/hooks/use-exit-on-ctrl-c.d.ts/**
* This hook will cause the process to exit when the user presses Ctrl+C.
*/
export declare function useExitOnCtrlC(): void;
Existing type declarationspackages/cli-kit/dist/public/node/ui.d.ts@@ -330,6 +330,21 @@ interface RenderTasksOptions {
* Installing dependencies ...
*/
export declare function renderTasks<TContext>(tasks: Task<TContext>[], { renderOptions }?: RenderTasksOptions): Promise<TContext>;
+/**
+ * Awaits a single promise and displays a loading bar while it's in progress. The promise's result is returned.
+ * @param options - Configuration object
+ * @param options.title - The title to display with the loading bar
+ * @param options.taskPromise - The promise to track
+ * @param renderOptions - Optional render configuration
+ * @returns The result of the promise
+ * @example
+ * ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+ * Loading app ...
+ */
+export declare function renderSingleTask<T>({ title, taskPromise }: {
+ title: string;
+ taskPromise: Promise<T> | (() => Promise<T>);
+}, { renderOptions }?: RenderTasksOptions): Promise<T>;
export interface RenderTextPromptOptions extends Omit<TextPromptProps, 'onSubmit'> {
renderOptions?: RenderOptions;
}
|
1 similar comment
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationspackages/cli-kit/dist/private/node/ui/components/LoadingBar.d.tsimport React from 'react';
interface LoadingBarProps {
title: string;
noColor?: boolean;
}
declare const LoadingBar: ({ title, noColor }: React.PropsWithChildren<LoadingBarProps>) => JSX.Element;
export { LoadingBar };
packages/cli-kit/dist/private/node/ui/components/SingleTask.d.tsimport React from 'react';
interface SingleTaskProps {
title: string;
taskPromise: Promise<unknown>;
noColor?: boolean;
}
declare const SingleTask: ({ taskPromise, title, noColor }: React.PropsWithChildren<SingleTaskProps>) => JSX.Element | null;
export { SingleTask };
packages/cli-kit/dist/private/node/ui/hooks/use-exit-on-ctrl-c.d.ts/**
* This hook will cause the process to exit when the user presses Ctrl+C.
*/
export declare function useExitOnCtrlC(): void;
Existing type declarationspackages/cli-kit/dist/public/node/ui.d.ts@@ -330,6 +330,21 @@ interface RenderTasksOptions {
* Installing dependencies ...
*/
export declare function renderTasks<TContext>(tasks: Task<TContext>[], { renderOptions }?: RenderTasksOptions): Promise<TContext>;
+/**
+ * Awaits a single promise and displays a loading bar while it's in progress. The promise's result is returned.
+ * @param options - Configuration object
+ * @param options.title - The title to display with the loading bar
+ * @param options.taskPromise - The promise to track
+ * @param renderOptions - Optional render configuration
+ * @returns The result of the promise
+ * @example
+ * ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
+ * Loading app ...
+ */
+export declare function renderSingleTask<T>({ title, taskPromise }: {
+ title: string;
+ taskPromise: Promise<T> | (() => Promise<T>);
+}, { renderOptions }?: RenderTasksOptions): Promise<T>;
export interface RenderTextPromptOptions extends Omit<TextPromptProps, 'onSubmit'> {
renderOptions?: RenderOptions;
}
|
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.
I think we should add an example to kitchen-sink
WHY are these changes introduced?
This PR introduces a new UI component to simplify displaying loading indicators while awaiting promise resolution. See example usage below.
By using this component when "slow" asynchronous functions are run, we can present a more responsive experience: rather than being greeted by a blank screen or a pause in feedback, the loading bar reassures the developer that something is happening.
WHAT is this pull request doing?
SingleTask
React component that shows a loading bar while a promise is in progressrenderSingleTask
public API function that wraps the component for easy useThe
renderSingleTask
function provides a simple way to display a loading indicator while awaiting a promise, and returns the promise's result when complete.Example usage:
How to test your changes?
pnpm test packages/cli-kit/src/private/node/ui/components/SingleTask.test.tsx
renderSingleTask
with a delayed promise to see the loading bar in actionMeasuring impact
How do we know this change was effective? Please choose one:
Checklist