cli icon indicating copy to clipboard operation
cli copied to clipboard

Allow updating the `title` while a task is running

Open stephen-last opened this issue 7 months ago β€’ 3 comments

WHY are these changes introduced?

With renderTasks, we'd like to update the title while the task is running, so we can provide better feedback to the user on the task progress.

The indented usage is to provide a count and percentage update on a longer running task, something like these titles:

  1. Requested data ...
  2. Receiving data (2/10 20%) ...
  3. Receiving data (6/10 60%) ...
  4. Receiving data (10/10 100%) ...

All using only one task, when the running time and number of HTTP calls needed is not known up front when the task is created.

WHAT is this pull request doing?

Update to the Tasks component.

The const [currentTask, setCurrentTask] = useState(...) state was only being used to hold the current task in order to show the title.

This is changed to const [title, setTitle] = useState(...) instead, and setTitle passed to runTask so it can then be passed directly to the caller of the task function, as updateTitle, along with the ctx and task object itself.

This allows us to call updateTitle in a task function like:

{
  title: 'Receiving data',
  task: async (_ctx, _task, updateTitle) => {
    let fulfilled = false

    while (!fulfilled) {
      const response = await getData()
      updateTitle(response.progress)
      fulfilled = response.fulfilled
    }
  }
}

How to test your changes?

Post-release steps

Measuring impact

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

  • [x] n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • [ ] Existing analytics will cater for this addition
  • [ ] PR includes analytics changes to measure impact

Checklist

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

stephen-last avatar May 08 '25 09:05 stephen-last

Coverage report

St.:grey_question:
Category Percentage Covered / Total
🟑 Statements
76.6% (-0.04% πŸ”»)
9612/12548
🟑 Branches
71.96% (+0.02% πŸ”Ό)
4756/6609
🟑 Functions
76.52% (-0.05% πŸ”»)
2487/3250
🟑 Lines
77.12% (-0.03% πŸ”»)
9083/11778
Show files with reduced coverage πŸ”»
St.:grey_question:
File Statements Branches Functions Lines
🟒
... / Tasks.tsx
94%
90.32% (-2.78% πŸ”»)
88.89% 93.62%

Test suite run success

2277 tests passing in 986 suites.

Report generated by πŸ§ͺjest coverage report action from 1d554f769fee71c63a64fe2914b18aa4badfe04b

github-actions[bot] avatar May 08 '25 09:05 github-actions[bot]

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.

github-actions[bot] avatar May 08 '25 09:05 github-actions[bot]

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

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/private/node/ui/components/Tasks.d.ts
@@ -1,8 +1,9 @@
 import { AbortSignal } from '../../../../public/node/abort.js';
 import React from 'react';
+type UpdateTitle = (title: string) => void;
 export interface Task<TContext = unknown> {
     title: string;
-    task: (ctx: TContext, task: Task<TContext>) => Promise<void | Task<TContext>[]>;
+    task: (ctx: TContext, task: Task<TContext>, updateTitle: UpdateTitle) => Promise<void | Task<TContext>[]>;
     retry?: number;
     retryCount?: number;
     errors?: Error[];

github-actions[bot] avatar May 13 '25 07:05 github-actions[bot]

This is not needed any more.

stephen-last avatar May 14 '25 07:05 stephen-last