Skip to content

Commit 240c210

Browse files
committed
feat: Added import prompt to help improve ux of imports and updated to the latest ink-form with improved import ux
1 parent 3b1b632 commit 240c210

File tree

9 files changed

+112
-14
lines changed

9 files changed

+112
-14
lines changed

codify.json

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@
9595
"passphrase": "",
9696
"keyType": "ed25519"
9797
},
98-
{
99-
"type": "alias",
100-
"alias": "gcc",
101-
"value": "git commit -v"
102-
},
10398
{
10499
"type": "alias",
105100
"alias": "gc",
@@ -187,5 +182,40 @@
187182
"awsSecretAccessKey": "NnKvlKV5vbbUmvJGDRf040VlbQhD1zdCo5b8/QwS",
188183
"profile": "codify",
189184
"region": "us-east-1"
185+
},
186+
{
187+
"type": "git-clone",
188+
"directory": "~/Projects/codify-homebrew-plugin",
189+
"repository": "git@github.com:kevinwang5658/codify-homebrew-plugin.git"
190+
},
191+
{
192+
"type": "git-clone",
193+
"directory": "~/Projects/codify-homebrew-plugin",
194+
"repository": "git@github.com:kevinwang5658/codify-homebrew-plugin.git"
195+
},
196+
{
197+
"type": "git-clone",
198+
"directory": "~/Projects/codify-homebrew-plugin",
199+
"repository": "git@github.com:kevinwang5658/codify-homebrew-plugin.git"
200+
},
201+
{
202+
"type": "git-clone",
203+
"directory": "~/Projects/codify-homebrew-plugin",
204+
"repository": "git@github.com:kevinwang5658/codify-homebrew-plugin.git"
205+
},
206+
{
207+
"type": "git-clone",
208+
"directory": "~/Projects/codify-homebrew-plugin",
209+
"repository": "git@github.com:kevinwang5658/codify-homebrew-plugin.git"
210+
},
211+
{
212+
"type": "git-clone",
213+
"directory": "~/Projects/codify-homebrew-plugin",
214+
"repository": "git@github.com:kevinwang5658/codify-homebrew-plugin.git"
215+
},
216+
{
217+
"type": "git-clone",
218+
"directory": "~/Projects/codify-homebrew-plugin",
219+
"repository": "git@github.com:kevinwang5658/codify-homebrew-plugin.git"
190220
}
191221
]

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"codify": "./bin/run.js"
55
},
66
"dependencies": {
7-
"@codifycli/ink-form": "0.0.5",
7+
"@codifycli/ink-form": "0.0.10",
88
"ink-select-input": "^6.0.0",
99
"@homebridge/node-pty-prebuilt-multiarch": "^0.12.0-beta.5",
1010
"@inkjs/ui": "^2",

src/orchestrators/import.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ ${JSON.stringify(unsupportedTypeIds)}`);
213213
}
214214
})
215215

216+
if (askPrompt.length > 0) {
217+
await reporter.displayImportWarning(askPrompt.map((r) => r.type), noPrompt.map((r) => r.type));
218+
}
219+
216220
const userSupplied = await reporter.promptUserForValues(askPrompt, PromptType.IMPORT);
217221

218222
return [

src/ui/components/default-component.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Form, FormProps } from '@codifycli/ink-form';
2-
import { PasswordInput, Select } from '@inkjs/ui';
2+
import { PasswordInput } from '@inkjs/ui';
33
import chalk from 'chalk';
44
import { Box, Static, Text } from 'ink';
55
import SelectInput from 'ink-select-input';
@@ -14,6 +14,7 @@ import { RenderEvent } from '../reporters/reporter.js';
1414
import { RenderStatus, store } from '../store/index.js';
1515
import { FileModificationDisplay } from './file-modification/FileModification.js';
1616
import { ImportResultComponent } from './import/import-result.js';
17+
import { ImportWarning } from './import/import-warning.js';
1718
import { PlanComponent } from './plan/plan.js';
1819
import { ProgressDisplay } from './progress/progress-display.js';
1920

@@ -119,5 +120,10 @@ export function DefaultComponent(props: {
119120
}</Static>
120121
)
121122
}
123+
{
124+
renderStatus === RenderStatus.IMPORT_PROMPT_WARNING && (
125+
<ImportWarning emitter={emitter} renderData={renderData as any} />
126+
)
127+
}
122128
</Box>
123129
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Box, Static, Text } from 'ink';
2+
import React from 'react';
3+
import { RenderEvent } from '../../reporters/reporter.js';
4+
import SelectInput from 'ink-select-input';
5+
import EventEmitter from 'node:events';
6+
7+
8+
export function ImportWarning({
9+
renderData,
10+
emitter,
11+
}: {
12+
renderData: { noParametersRequired: string[], requiresParameters: string[] };
13+
emitter: EventEmitter
14+
}) {
15+
return <Box flexDirection="column">
16+
<Static items={[renderData]}>{
17+
(data, idx) => <Box flexDirection='column' key={idx}>
18+
<Text> </Text>
19+
<Text bold>Additional information is required to continue import</Text>
20+
<Text>Some of the resources specified in the import support multiple instances. Additional information is required to identify the specific instance to import. If importing multiple instances is desired (for ex: multiple git clones) additional imports can be added in the prompt.</Text>
21+
{
22+
data.noParametersRequired.length > 0 && (<Box flexDirection='column'>
23+
<Text> </Text>
24+
<Text bold color='green'>Resources that can be imported automatically:</Text>
25+
<Text color='green'>{data.noParametersRequired.join(', ')}</Text>
26+
</Box>)
27+
}
28+
<Text> </Text>
29+
<Text bold color='yellow'>Resources that require additional information:</Text>
30+
<Text color='yellow'>{data.requiresParameters.join(', ')}</Text>
31+
</Box>
32+
}</Static>
33+
<Box marginTop={1}>
34+
<SelectInput items={[
35+
{ label: 'Continue to prompt', value: '' },
36+
]} onSelect={() => emitter.emit(RenderEvent.PROMPT_RESULT, true)}/>
37+
</Box>
38+
</Box>
39+
40+
}

src/ui/reporters/default-reporter.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ export class DefaultReporter implements Reporter {
4848
ctx.on(Event.SUB_PROCESS_FINISH, (name, additionalName) => this.onSubprocessFinishEvent(name, additionalName));
4949
}
5050

51+
async displayImportWarning(requiresParameters: string[], noParametersRequired: string[]): Promise<void> {
52+
await this.updateStateAndAwaitEvent<boolean>(
53+
() => this.updateRenderState(RenderStatus.IMPORT_PROMPT_WARNING, { requiresParameters, noParametersRequired }),
54+
RenderEvent.PROMPT_RESULT
55+
)
56+
}
57+
5158
async promptUserForValues(resources: Array<ResourceInfo>, promptType: PromptType): Promise<ResourceConfig[]> {
5259
if (resources.length === 0) {
5360
return [];
@@ -58,8 +65,8 @@ export class DefaultReporter implements Reporter {
5865

5966
const formProps: FormProps = {
6067
form: {
61-
title: 'codify import',
62-
description: 'specify the resource to import',
68+
title: 'Identify which instance to import',
69+
description: 'fill out the required information to submit',
6370
sections: resources.map((info) => ({
6471
title: info.type,
6572
description: info.description,
@@ -137,9 +144,16 @@ export class DefaultReporter implements Reporter {
137144
RenderEvent.PROMPT_RESULT
138145
)
139146

147+
this.log(result ? `${message} -> "Yes"` : `${message} -> "No"`)
148+
149+
// This was added because there was a very hard to debug memory bug with Yoga (ink.js layout engine). Could not
150+
// identify the root cause of the problem but this alleviates it.
151+
await sleep(50)
152+
this.updateRenderState(RenderStatus.NOTHING, null);
153+
await sleep(50);
154+
140155
if (result) {
141156
this.updateRenderState(RenderStatus.PROGRESS)
142-
this.log(`${message} -> "Yes"`)
143157
}
144158

145159
return result;
@@ -155,6 +169,7 @@ export class DefaultReporter implements Reporter {
155169

156170
// This was added because there was a very hard to debug memory bug with Yoga (ink.js layout engine). Could not
157171
// identify the root cause of the problem but this alleviates it.
172+
await sleep(50)
158173
this.updateRenderState(RenderStatus.NOTHING, null);
159174
await sleep(50);
160175

src/ui/reporters/reporter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export interface Reporter {
5757
displayFileModifications(diff: Array<{ file: string, modification: FileModificationResult }>): void
5858

5959
displayMessage(message: string): void
60+
61+
displayImportWarning(requiresParameters: string[], noParametersRequired: string[]): Promise<void>
6062
}
6163

6264
export enum ReporterType {

src/ui/store/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export enum RenderStatus {
1414
DISPLAY_IMPORT_RESULT,
1515
DISPLAY_FILE_MODIFICATION,
1616
IMPORT_PROMPT,
17+
IMPORT_PROMPT_WARNING,
1718
PROMPT_CONFIRMATION,
1819
PROMPT_OPTIONS,
1920
SUDO_PROMPT,

0 commit comments

Comments
 (0)