Repository navigation
Combine conversion task creation and execution into one Convert step #46
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
Shreyansh Gupta (code-scannner)
wants to merge
4
commits into
main
Choose a base branch
from
guptashreyan/combine-create-execute
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5fc3740
Combine conversion task creation and execution into one Convert step
697afa8
Keep conversion as one Home step that creates tasks, then opens them
13f0b91
Name the Home conversion step Execute
226c0b8
Finalize the flow when its last required conversion task completes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import * as assert from 'assert/strict'; | ||
| import { | ||
| ConversionStepState, | ||
| renderConversionStepButton, | ||
| } from '../../views/discovery/ConversionStepButton'; | ||
|
|
||
| const planned: ConversionStepState = { | ||
| flowId: 'order-flow', | ||
| isPlanned: true, | ||
| isTasksCreated: false, | ||
| isConverted: false, | ||
| isCreatingTasks: false, | ||
| isExecuting: false, | ||
| isBlockedByOtherFlow: false, | ||
| }; | ||
|
|
||
| function step(overrides: Partial<ConversionStepState>): { | ||
| label: string; | ||
| action?: string; | ||
| disabled: boolean; | ||
| } { | ||
| const html = renderConversionStepButton({ ...planned, ...overrides }); | ||
| return { | ||
| label: /<strong>([^<]*)<\/strong>/.exec(html)?.[1] ?? '', | ||
| action: /onclick="event\.stopPropagation\(\); (\w+)\('order-flow'\)"/.exec(html)?.[1], | ||
| disabled: /\sdisabled[\s>]/.test(html), | ||
| }; | ||
| } | ||
|
|
||
| describe('Home Execute step', () => { | ||
| it('is named Execute and generates the conversion tasks once the flow is planned', () => { | ||
| assert.deepEqual(step({ isPlanned: false }), { | ||
| label: 'Execute', | ||
| action: undefined, | ||
| disabled: true, | ||
| }); | ||
| assert.deepEqual(step({}), { label: 'Execute', action: 'convertFlow', disabled: false }); | ||
| assert.deepEqual(step({ isCreatingTasks: true }), { | ||
| label: 'Executing...', | ||
| action: undefined, | ||
| disabled: true, | ||
| }); | ||
| }); | ||
|
|
||
| it('opens the generated tasks so they are executed from the task list', () => { | ||
| assert.deepEqual(step({ isTasksCreated: true }), { | ||
| label: 'Execute', | ||
| action: 'viewConversion', | ||
| disabled: false, | ||
| }); | ||
| assert.deepEqual(step({ isTasksCreated: true, isExecuting: true }), { | ||
| label: 'Executing...', | ||
| action: undefined, | ||
| disabled: true, | ||
| }); | ||
| assert.deepEqual(step({ isTasksCreated: true, isConverted: true }), { | ||
| label: '✓ Executed', | ||
| action: 'viewConversion', | ||
| disabled: false, | ||
| }); | ||
| }); | ||
|
|
||
| it('only blocks starting a flow while another flow is busy', () => { | ||
| assert.deepEqual(step({ isBlockedByOtherFlow: true }), { | ||
| label: 'Execute', | ||
| action: undefined, | ||
| disabled: true, | ||
| }); | ||
| assert.deepEqual(step({ isBlockedByOtherFlow: true, isTasksCreated: true }), { | ||
| label: 'Execute', | ||
| action: 'viewConversion', | ||
| disabled: false, | ||
| }); | ||
| }); | ||
|
|
||
| it('never shows Create in any state', () => { | ||
| const flags = [ | ||
| 'isPlanned', | ||
| 'isTasksCreated', | ||
| 'isConverted', | ||
| 'isCreatingTasks', | ||
| 'isExecuting', | ||
| 'isBlockedByOtherFlow', | ||
| ] as const; | ||
| for (let mask = 0; mask < 2 ** flags.length; mask++) { | ||
| const overrides: Partial<Record<(typeof flags)[number], boolean>> = {}; | ||
| flags.forEach((flag, i) => { | ||
| overrides[flag] = Math.floor(mask / 2 ** i) % 2 === 1; | ||
| }); | ||
| const html = renderConversionStepButton({ ...planned, ...overrides }); | ||
| assert.doesNotMatch(html, /creat/i, JSON.stringify(overrides)); | ||
| assert.ok( | ||
| ['Execute', 'Executing...', '✓ Executed'].includes(step(overrides).label), | ||
| JSON.stringify(overrides) | ||
| ); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /** | ||
| * Execute step on the Home flow cards. | ||
| * | ||
| * A single Execute step covers conversion: on a planned flow it generates the | ||
| * conversion tasks and opens the task list, where each task (or Execute All) | ||
| * is executed. | ||
| * | ||
| * @module views/discovery/ConversionStepButton | ||
| */ | ||
|
|
||
| export interface ConversionStepState { | ||
| readonly flowId: string; | ||
| readonly isPlanned: boolean; | ||
| readonly isTasksCreated: boolean; | ||
| readonly isConverted: boolean; | ||
| readonly isCreatingTasks: boolean; | ||
| readonly isExecuting: boolean; | ||
| readonly isBlockedByOtherFlow: boolean; | ||
| } | ||
|
|
||
| function stepLabel(text: string): string { | ||
| return `<span class="step-label"><strong>${text}</strong><small>Conversion Tasks</small></span>`; | ||
| } | ||
|
|
||
| function disabledStep(text: string, title?: string): string { | ||
| const titleAttr = title ? ` title="${title}"` : ''; | ||
| return `<button class="btn btn-step btn-disabled" disabled${titleAttr}>${stepLabel(text)}</button>`; | ||
| } | ||
|
|
||
| function actionStep( | ||
| text: string, | ||
| style: 'btn-primary' | 'btn-done', | ||
| action: 'convertFlow' | 'viewConversion', | ||
| flowId: string, | ||
| title: string | ||
| ): string { | ||
| return `<button class="btn btn-step ${style}" onclick="event.stopPropagation(); ${action}('${flowId}')" title="${title}">${stepLabel(text)}</button>`; | ||
| } | ||
|
|
||
| /** | ||
| * Render the Execute step. It keeps the Execute name in every state, like | ||
| * Analyse → ✓ Analysed and Plan → ✓ Planned. | ||
| */ | ||
| export function renderConversionStepButton(state: ConversionStepState): string { | ||
| if (!state.isPlanned) { | ||
| return disabledStep('Execute', 'Plan first'); | ||
| } | ||
| if (state.isCreatingTasks || state.isExecuting) { | ||
| return disabledStep('Executing...'); | ||
| } | ||
|
code-scannner marked this conversation as resolved.
Resolved
|
||
| if (state.isConverted) { | ||
| return actionStep( | ||
| '✓ Executed', | ||
| 'btn-done', | ||
| 'viewConversion', | ||
| state.flowId, | ||
| 'View conversion tasks' | ||
| ); | ||
| } | ||
| if (state.isTasksCreated) { | ||
| return actionStep( | ||
| 'Execute', | ||
| 'btn-primary', | ||
| 'viewConversion', | ||
| state.flowId, | ||
| 'Open the conversion tasks to execute them' | ||
| ); | ||
| } | ||
| if (state.isBlockedByOtherFlow) { | ||
| return disabledStep('Execute', 'Another flow is in progress'); | ||
| } | ||
| return actionStep( | ||
| 'Execute', | ||
| 'btn-primary', | ||
| 'convertFlow', | ||
|
code-scannner marked this conversation as resolved.
Resolved
|
||
| state.flowId, | ||
| 'Generate the conversion tasks, then execute them from the task list' | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.