Skip to content

Commit e3b3a08

Browse files
committed
feat: Added prompt for users to select results to save
1 parent 4ef30c0 commit e3b3a08

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

src/orchestrators/import.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export class ImportOrchestrator {
6969

7070
ctx.processFinished(ProcessName.IMPORT)
7171
reporter.displayImportResult(importResult);
72+
73+
await ImportOrchestrator.saveResults(reporter, importResult, project)
7274
}
7375

7476
static async getImportedConfigs(
@@ -126,4 +128,19 @@ ${JSON.stringify(unsupportedTypeIds)}`);
126128

127129
ctx.subprocessFinished(SubProcessName.VALIDATE)
128130
}
131+
132+
private static async saveResults(reporter: Reporter, importResult: ImportResult, project: Project): Promise<void> {
133+
const projectExists = !project.isEmpty();
134+
135+
const continueSaving = await reporter.promptOptions(
136+
'\nDo you want to save the results?',
137+
[projectExists ? `Update ${project.path}` : undefined, 'Save in a new file', 'No'].filter(Boolean) as string[]
138+
)
139+
if (!continueSaving) {
140+
process.exit(0)
141+
}
142+
143+
144+
145+
}
129146
}

src/ui/components/default-component.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,25 @@ export function DefaultComponent(props: {
5050
renderStatus === RenderStatus.PROMPT_CONFIRMATION && (
5151
<Box flexDirection="column">
5252
<Text>{renderData as string}</Text>
53-
<Select onChange={(value) => emitter.emit(RenderEvent.PROMPT_CONFIRMATION_RESULT, value === 'yes')} options={[
53+
<Select onChange={(value) => emitter.emit(RenderEvent.PROMPT_RESULT, value === 'yes')} options={[
5454
{ label: 'Yes', value: 'yes' },
5555
{ label: 'No', value: 'no' },
5656
]}/>
5757
</Box>
5858
)
5959
}
60+
{
61+
renderStatus === RenderStatus.PROMPT_OPTIONS && (
62+
<Box flexDirection="column">
63+
<Text>{(renderData as any).message}</Text>
64+
<Select onChange={(value) => emitter.emit(RenderEvent.PROMPT_RESULT, value)} options={
65+
(renderData as any).options.map((option) => ({
66+
label: option, value: option
67+
}))
68+
}/>
69+
</Box>
70+
)
71+
}
6072
{
6173
renderStatus === RenderStatus.APPLY_COMPLETE && (
6274
<Box flexDirection="column">

src/ui/reporters/default-reporter.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,27 @@ export class DefaultReporter implements Reporter {
124124
}
125125

126126
async promptConfirmation(message: string): Promise<boolean> {
127-
const continueApply = await this.updateStateAndAwaitEvent<boolean>(
127+
const result = await this.updateStateAndAwaitEvent<boolean>(
128128
() => this.updateRenderState(RenderStatus.PROMPT_CONFIRMATION, message),
129-
RenderEvent.PROMPT_CONFIRMATION_RESULT
129+
RenderEvent.PROMPT_RESULT
130130
)
131131

132-
if (continueApply) {
132+
if (result) {
133133
this.updateRenderState(RenderStatus.PROGRESS)
134134
this.log(`${message} -> "Yes"`)
135135
}
136136

137-
return continueApply;
137+
return result;
138+
}
139+
140+
async promptOptions(message:string, options:string[]): Promise<number> {
141+
const result = await this.updateStateAndAwaitEvent<number>(
142+
() => this.updateRenderState(RenderStatus.PROMPT_OPTIONS, { message, options }),
143+
RenderEvent.PROMPT_RESULT
144+
)
145+
146+
this.log(`${message} -> "${result}"`)
147+
return result
138148
}
139149

140150
async displayApplyComplete(messages: string[]): Promise<void> {

src/ui/reporters/reporter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ResourceConfig } from '../../entities/resource-config.js';
1111
export enum RenderEvent {
1212
LOG = 'log',
1313
PROGRESS_UPDATE = 'progressUpdate',
14-
PROMPT_CONFIRMATION_RESULT = 'promptConfirmation',
14+
PROMPT_RESULT = 'promptConfirmation',
1515
PROMPT_SUDO = 'promptSudo',
1616
DISABLE_SUDO_PROMPT = 'disableSudoPrompt',
1717
PROMPT_IMPORT_PARAMETERS = 'promptImportParameters',
@@ -47,6 +47,8 @@ export interface Reporter {
4747

4848
promptConfirmation(message: string): Promise<boolean>
4949

50+
promptOptions(message: string, options: string[]): Promise<number>;
51+
5052
promptSudo(pluginName: string, data: SudoRequestData, secureMode: boolean): Promise<SudoRequestResponseData>;
5153

5254
promptUserForValues(resources: Array<ResourceInfo>, promptType: PromptType): Promise<ResourceConfig[]>;

src/ui/store/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export enum RenderStatus {
1313
DISPLAY_IMPORT_RESULT,
1414
IMPORT_PROMPT,
1515
PROMPT_CONFIRMATION,
16+
PROMPT_OPTIONS,
1617
APPLY_COMPLETE,
1718
SUDO_PROMPT,
1819
}

0 commit comments

Comments
 (0)