Skip to content

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

Open
wants to merge 1 commit into
base: shauns/06-02-add_useexitonctrlc_hook
Choose a base branch
from

Conversation

shauns
Copy link
Contributor

@shauns shauns commented Jun 2, 2025

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?

  • Adds a new SingleTask React component that shows a loading bar while a promise is in progress
  • Implements renderSingleTask public API function that wraps the component for easy use
  • Includes comprehensive test coverage for both the component and public API

The 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:

const result = await renderSingleTask({
  title: 'Uploading files',
  taskPromise: uploadFilesToServer()
});

How to test your changes?

  1. Run the test suite: pnpm test packages/cli-kit/src/private/node/ui/components/SingleTask.test.tsx
  2. Create a simple CLI command that uses renderSingleTask with a delayed promise to see the loading bar in action

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

@shauns shauns mentioned this pull request Jun 2, 2025
3 tasks
Copy link
Contributor Author

shauns commented Jun 2, 2025

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.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@shauns shauns marked this pull request as ready for review June 2, 2025 14:08
@shauns shauns requested a review from a team as a code owner June 2, 2025 14:08
Copy link
Contributor

github-actions bot commented Jun 2, 2025

We detected some changes at packages/*/src and there are no updates in the .changeset.
If the changes are user-facing, run pnpm changeset add to track your changes and include them in the next release CHANGELOG.

Caution

DO NOT create changesets for features which you do not wish to be included in the public changelog of the next CLI release.

@shauns shauns force-pushed the shauns/06-02-introduce_singletask_component branch from a1e1149 to b4acbdb Compare June 2, 2025 14:58
Copy link
Contributor

github-actions bot commented Jun 2, 2025

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
78.11% (+0.02% 🔼)
12543/16058
🟡 Branches
72.29% (+0.02% 🔼)
6081/8412
🟡 Functions
78.26% (+0.03% 🔼)
3286/4199
🟡 Lines
78.55% (+0.02% 🔼)
11871/15113
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / SingleTask.tsx
100% 100% 100% 100%

Test suite run success

2917 tests passing in 1263 suites.

Report generated by 🧪jest coverage report action from 0b86195

@shauns shauns force-pushed the shauns/06-02-introduce_singletask_component branch 3 times, most recently from 9089fc1 to 75ace80 Compare June 4, 2025 11:16
@shauns shauns force-pushed the shauns/06-02-add_useexitonctrlc_hook branch 2 times, most recently from 72137d9 to d4750fa Compare June 5, 2025 11:28
@shauns shauns force-pushed the shauns/06-02-introduce_singletask_component branch from 75ace80 to 03fea54 Compare June 5, 2025 11:28
@shauns shauns force-pushed the shauns/06-02-introduce_singletask_component branch from 03fea54 to 0b86195 Compare June 5, 2025 12:09
@shauns shauns force-pushed the shauns/06-02-add_useexitonctrlc_hook branch from d4750fa to 1f9a01f Compare June 5, 2025 12:09
Copy link
Contributor

github-actions bot commented Jun 5, 2025

Differences in type declarations

We 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:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

packages/cli-kit/dist/private/node/ui/components/LoadingBar.d.ts
import 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.ts
import 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 declarations

packages/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
Copy link
Contributor

github-actions bot commented Jun 5, 2025

Differences in type declarations

We 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:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

packages/cli-kit/dist/private/node/ui/components/LoadingBar.d.ts
import 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.ts
import 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 declarations

packages/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;
 }

Copy link
Contributor

@gonzaloriestra gonzaloriestra left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants