Skip to content

Commit ec968cf

Browse files
committed
Task list supports TokenizedString title
1 parent 9dc2eb8 commit ec968cf

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

packages/cli-kit/src/private/node/ui/components/Tasks.test.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Task, Tasks} from './Tasks.js'
22
import {getLastFrameAfterUnmount, render} from '../../testing/ui.js'
3-
import {unstyled} from '../../../../public/node/output.js'
3+
import {unstyled, TokenizedString} from '../../../../public/node/output.js'
44
import {AbortController} from '../../../../public/node/abort.js'
55
import {Stdout} from '../../ui.js'
66
import React from 'react'
@@ -392,6 +392,31 @@ describe('Tasks', () => {
392392
expect(unstyled(getLastFrameAfterUnmount(renderInstance)!)).toEqual('')
393393
await expect(promise).resolves.toEqual(undefined)
394394
})
395+
396+
test('supports TokenizedString as title', async () => {
397+
// Given
398+
const firstTaskFunction = vi.fn(async () => {})
399+
const secondTaskFunction = vi.fn(async () => {})
400+
401+
const firstTask: Task = {
402+
title: new TokenizedString('tokenized task 1'),
403+
task: firstTaskFunction,
404+
}
405+
406+
const secondTask: Task = {
407+
title: 'string task 2',
408+
task: secondTaskFunction,
409+
}
410+
411+
// When
412+
const renderInstance = render(<Tasks tasks={[firstTask, secondTask]} silent={false} />)
413+
await renderInstance.waitUntilExit()
414+
415+
// Then
416+
expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot('""')
417+
expect(firstTaskFunction).toHaveBeenCalled()
418+
expect(secondTaskFunction).toHaveBeenCalled()
419+
})
395420
})
396421

397422
async function taskHasRendered() {

packages/cli-kit/src/private/node/ui/components/Tasks.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import {isUnitTest} from '../../../../public/node/context/local.js'
44
import {AbortSignal} from '../../../../public/node/abort.js'
55
import useAbortSignal from '../hooks/use-abort-signal.js'
66
import {useExitOnCtrlC} from '../hooks/use-exit-on-ctrl-c.js'
7+
import {TokenizedString} from '../../../../public/node/output.js'
78
import React, {useRef, useState} from 'react'
89

910
export interface Task<TContext = unknown> {
10-
title: string
11+
title: string | TokenizedString
1112
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
1213
task: (ctx: TContext, task: Task<TContext>) => Promise<void | Task<TContext>[]>
1314
retry?: number
@@ -107,8 +108,10 @@ function Tasks<TContext>({
107108
return null
108109
}
109110

111+
const title = typeof currentTask.title === 'string' ? currentTask.title : currentTask.title.value
112+
110113
return state === TasksState.Loading && !isAborted ? (
111-
<LoadingBar title={currentTask.title} noColor={noColor} noProgressBar={noProgressBar} />
114+
<LoadingBar title={title} noColor={noColor} noProgressBar={noProgressBar} />
112115
) : null
113116
}
114117

0 commit comments

Comments
 (0)