Skip to content

Commit 7b00ac2

Browse files
committed
feat: Additional refactoring. Cleaned up dead APPLY_VALIDATION_ERROR dead code. Moved rendering logic to the ApplyComplete component instead.
1 parent ed0d323 commit 7b00ac2

4 files changed

Lines changed: 44 additions & 47 deletions

File tree

src/ui/components/default-component.tsx

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,6 @@ export function DefaultComponent(props: {
5959
(plan, idx) => <PlanComponent key={idx} plan={plan}/>
6060
}</Static>
6161
}
62-
{
63-
renderStatus === RenderStatus.APPLY_VALIDATION_ERROR && (
64-
<Static items={[renderData as ResourcePlan[]]}>{
65-
(resourcePlans, idx) => (
66-
<Box key={idx} flexDirection="column" marginTop={1}>
67-
{resourcePlans.map((resourcePlan) => (
68-
<Box key={resourcePlan.id} flexDirection="column">
69-
<Text color="red" bold>
70-
{`Apply failed: resource "${resourcePlan.id}" did not reach its desired state.`}
71-
</Text>
72-
<Text> </Text>
73-
<Text bold backgroundColor={'red'}>Changes still needed:</Text>
74-
<Text>{prettyFormatResourcePlan(resourcePlan)}</Text>
75-
<Text> </Text>
76-
</Box>
77-
))}
78-
<Text color="red" bold>Exiting...</Text>
79-
<Text> </Text>
80-
<Text color="red" bold>Potential fixes:</Text>
81-
<Text color="red" bold>{' 1. Re-run the command again'}</Text>
82-
<Text color="red" bold>{' 2. Manually install the resource and retry'}</Text>
83-
<Text color="red" bold>{' 3. Reach out to support at https://github.com/codifycli/default-plugin/issues'}</Text>
84-
</Box>
85-
)
86-
}</Static>
87-
)
88-
}
8962
{
9063
renderStatus === RenderStatus.PLUGIN_ERROR && (
9164
<Static items={[renderData as string[]]}>{

src/ui/components/widgets/ApplyComplete.tsx

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1-
import { Box, Text } from 'ink';
1+
import { Box, Static, Text } from 'ink';
22
import React from 'react';
33

44
import { ApplyResult } from '../../../entities/apply-result.js';
5+
import { ResourcePlan } from '../../../entities/plan.js';
56
import { applyEntryInkColor, applyEntryLabel } from '../../apply-result-formatter.js';
7+
import { prettyFormatResourcePlan } from '../../plan-pretty-printer.js';
68

79
export function ApplyComplete({ result }: { result: ApplyResult }) {
810
const isPartial = result.isPartialFailure();
11+
12+
const validationErrors = isPartial
13+
? result.errors
14+
.filter((e) => e.errorData.errorType === 'apply_validation')
15+
.map((e) => new ResourcePlan((e.errorData.data as any).plan))
16+
: [];
17+
18+
const genericErrors = isPartial
19+
? result.errors
20+
.filter((e) => e.errorData.errorType !== 'apply_validation')
21+
.map((e) => e.message)
22+
: [];
23+
924
return (
1025
<Box flexDirection="column" marginTop={1}>
1126
<Text bold color={isPartial ? 'red' : 'green'}>
1227
{isPartial ? '⚠ Apply completed with errors' : '🎉 Finished applying 🎉'}
1328
</Text>
29+
1430
{result.entries.length > 0 && (
1531
<Box flexDirection="column" marginTop={1}>
1632
{result.entries.map((entry) => (
@@ -21,6 +37,33 @@ export function ApplyComplete({ result }: { result: ApplyResult }) {
2137
))}
2238
</Box>
2339
)}
40+
41+
{validationErrors.length > 0 && (
42+
<Box flexDirection="column" marginTop={1}>
43+
{validationErrors.map((resourcePlan) => (
44+
<Box key={resourcePlan.id} flexDirection="column">
45+
<Text color="red" bold>
46+
{`Apply failed: resource "${resourcePlan.id}" did not reach its desired state.`}
47+
</Text>
48+
<Text> </Text>
49+
<Text bold backgroundColor={'red'}>Changes still needed:</Text>
50+
<Text>{prettyFormatResourcePlan(resourcePlan)}</Text>
51+
<Text> </Text>
52+
</Box>
53+
))}
54+
<Text color="red" bold>Potential fixes:</Text>
55+
<Text color="red" bold>{' 1. Re-run the command again'}</Text>
56+
<Text color="red" bold>{' 2. Manually install the resource and retry'}</Text>
57+
<Text color="red" bold>{' 3. Reach out to support at https://github.com/codifycli/default-plugin/issues'}</Text>
58+
</Box>
59+
)}
60+
61+
{genericErrors.length > 0 && (
62+
<Box flexDirection="column" marginTop={1}>
63+
{genericErrors.map((msg, i) => <Text key={i} color="red">{msg}</Text>)}
64+
</Box>
65+
)}
66+
2467
{!isPartial && (
2568
<Box marginTop={1}>
2669
<Text dimColor>Open a new terminal or source &apos;.zshrc&apos; for the new changes to be reflected</Text>

src/ui/reporters/default-reporter.tsx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -271,27 +271,9 @@ export class DefaultReporter implements Reporter {
271271

272272
async displayApplyComplete(result: ApplyResult): Promise<void> {
273273
await this.updateRenderState(RenderStatus.APPLY_COMPLETE, result);
274-
275-
if (result.isPartialFailure()) {
276-
const validationErrors = result.errors.filter((e) => e.errorData.errorType === 'apply_validation');
277-
const genericErrors = result.errors.filter((e) => e.errorData.errorType !== 'apply_validation');
278-
279-
if (validationErrors.length > 0) {
280-
const resourcePlans = validationErrors.map((e) => new ResourcePlan((e.errorData.data as any).plan));
281-
await this.updateRenderState(RenderStatus.APPLY_VALIDATION_ERROR, resourcePlans);
282-
}
283-
if (genericErrors.length > 0) {
284-
await this.updateRenderState(RenderStatus.PLUGIN_ERROR, genericErrors.map((e) => e.message));
285-
}
286-
}
287274
}
288275

289276
async displayPluginError(error: PluginError): Promise<void> {
290-
if (error.errorData.errorType === 'apply_validation') {
291-
const resourcePlan = new ResourcePlan((error.errorData.data as any).plan);
292-
await this.updateRenderState(RenderStatus.APPLY_VALIDATION_ERROR, [resourcePlan]);
293-
return;
294-
}
295277
await this.updateRenderState(RenderStatus.PLUGIN_ERROR, [error.message]);
296278
}
297279

src/ui/store/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export enum RenderStatus {
2323
PROMPT_PRESS_KEY_TO_CONTINUE,
2424
SUDO_PROMPT,
2525
DISPLAY_MESSAGE,
26-
APPLY_VALIDATION_ERROR,
2726
PLUGIN_ERROR,
2827
APPLY_COMPLETE,
2928
}

0 commit comments

Comments
 (0)