Allow updating the `title` while a task is running
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:
Requested data ...Receiving data (2/10 20%) ...Receiving data (6/10 60%) ...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
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
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.
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
mainyou might see odd diffs, rebasemaininto 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[];
This is not needed any more.