|
| 1 | +import { ConnectError } from '@connectrpc/connect'; |
1 | 2 | import { |
2 | 3 | type ComponentList, |
3 | 4 | type ComponentSpec, |
4 | 5 | ComponentStatus, |
5 | 6 | } from 'protogen/redpanda/api/dataplane/v1/pipeline_pb'; |
| 7 | +import { toast } from 'sonner'; |
6 | 8 | import { onboardingWizardStore } from 'state/onboarding-wizard-store'; |
| 9 | +import { formatToastErrorMessageGRPC } from 'utils/toast.utils'; |
7 | 10 |
|
8 | 11 | import { |
9 | 12 | hasWizardRelevantFields, |
@@ -74,15 +77,28 @@ const typeToYamlConfigKey: Record<Exclude<ConnectComponentType, 'custom'>, Conne |
74 | 77 | /** |
75 | 78 | * Parses ComponentList from API response into ConnectComponentSpec array. |
76 | 79 | * Converts proto ComponentSpec to strongly-typed ConnectComponentSpec by overriding the type field. |
| 80 | + * Returns empty array and shows toast notification on error. |
77 | 81 | */ |
78 | | -export const parseSchema = (componentList: ComponentList): ConnectComponentSpec[] => |
79 | | - Object.entries(COMPONENT_TYPE_MAPPINGS).flatMap(([componentType, { listKey }]) => |
80 | | - ((componentList[listKey] as ComponentSpec[]) || []).map((comp) => ({ |
81 | | - ...comp, |
82 | | - type: componentType as Exclude<ConnectComponentType, 'custom'>, |
83 | | - config: comp.config, |
84 | | - })) |
85 | | - ); |
| 82 | +export function parseSchema(componentList: ComponentList): ConnectComponentSpec[] { |
| 83 | + try { |
| 84 | + return Object.entries(COMPONENT_TYPE_MAPPINGS).flatMap(([componentType, { listKey }]) => |
| 85 | + ((componentList[listKey] as ComponentSpec[]) || []).map((comp) => ({ |
| 86 | + ...comp, |
| 87 | + type: componentType as Exclude<ConnectComponentType, 'custom'>, |
| 88 | + config: comp.config, |
| 89 | + })) |
| 90 | + ); |
| 91 | + } catch (error) { |
| 92 | + toast.error( |
| 93 | + formatToastErrorMessageGRPC({ |
| 94 | + error: ConnectError.from(error), |
| 95 | + action: 'Parse component schema', |
| 96 | + entity: 'Component list', |
| 97 | + }) |
| 98 | + ); |
| 99 | + return []; |
| 100 | + } |
| 101 | +} |
86 | 102 |
|
87 | 103 | const generateRedpandaTopLevelConfig = (): Record<string, unknown> => { |
88 | 104 | const userData = onboardingWizardStore.getUserData(); |
|
0 commit comments