Skip to content

Commit 26ba958

Browse files
committed
Changed the parameterless import to mimic init (auto import everything)
1 parent aad8e5a commit 26ba958

File tree

2 files changed

+44
-28
lines changed

2 files changed

+44
-28
lines changed

src/orchestrators/import.ts

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,51 @@ export class ImportOrchestrator {
4444
}
4545

4646
await (!typeIds || typeIds.length === 0
47-
? ImportOrchestrator.runExistingProject(reporter, initializationResult)
47+
? ImportOrchestrator.autoImportAll(reporter, initializationResult)
4848
: ImportOrchestrator.runNewImport(typeIds, reporter, initializationResult));
4949
}
5050

51+
static async autoImportAll(reporter: Reporter, initializeResult: InitializationResult) {
52+
const { project, pluginManager, typeIdsToDependenciesMap } = initializeResult;
53+
54+
ctx.subprocessStarted(SubProcessName.IMPORT_RESOURCE)
55+
const importResults = await Promise.all([...typeIdsToDependenciesMap.keys()].map(async (typeId) => {
56+
try {
57+
return await pluginManager.importResource({
58+
core: { type: typeId },
59+
parameters: {}
60+
}, true);
61+
} catch {
62+
return null;
63+
}
64+
}))
65+
66+
ctx.subprocessFinished(SubProcessName.IMPORT_RESOURCE);
67+
68+
const flattenedResults = importResults.filter(Boolean).flatMap(p => p?.result).filter(Boolean)
69+
70+
const userSelectedTypes = await reporter.promptInitResultSelection([...new Set(flattenedResults.map((r) => r!.core.type))])
71+
ctx.log('Resource types were chosen to be imported.')
72+
73+
ctx.processFinished(ProcessName.IMPORT);
74+
75+
const importedResources = flattenedResults.filter((r) => r && userSelectedTypes.includes(r.core.type))
76+
.map((r) => ResourceConfig.fromJson(r!));
77+
78+
const resourceInfoList = await pluginManager.getMultipleResourceInfo(
79+
[...project.resourceConfigs, ...importedResources].map((r) => r.type),
80+
);
81+
82+
await ImportOrchestrator.updateExistingFiles(
83+
reporter,
84+
project,
85+
{ result: importedResources, errors: [] },
86+
resourceInfoList,
87+
project.codifyFiles[0],
88+
pluginManager,
89+
);
90+
}
91+
5192
/** Import new resources. Type ids supplied. This will ask for any required parameters */
5293
static async runNewImport(typeIds: string[], reporter: Reporter, initializeResult: InitializationResult): Promise<void> {
5394
const { project, pluginManager, typeIdsToDependenciesMap } = initializeResult;
@@ -71,31 +112,6 @@ export class ImportOrchestrator {
71112
await ImportOrchestrator.saveResults(reporter, importResult, project, resourceInfoList, pluginManager)
72113
}
73114

74-
/** Update an existing project. This will use the existing resources as the parameters (no user input required). */
75-
static async runExistingProject(reporter: Reporter, initializeResult: InitializationResult): Promise<void> {
76-
const { pluginManager, project } = initializeResult;
77-
78-
await pluginManager.validate(project);
79-
const importResult = await ImportOrchestrator.import(pluginManager, project.resourceConfigs);
80-
81-
ctx.processFinished(ProcessName.IMPORT);
82-
83-
reporter.displayImportResult(importResult, false);
84-
85-
const resourceInfoList = await pluginManager.getMultipleResourceInfo(
86-
project.resourceConfigs.map((r) => r.type),
87-
);
88-
89-
await ImportOrchestrator.updateExistingFiles(
90-
reporter,
91-
project,
92-
importResult,
93-
resourceInfoList,
94-
project.codifyFiles[0],
95-
pluginManager,
96-
);
97-
}
98-
99115
static async import(
100116
pluginManager: PluginManager,
101117
resources: ResourceConfig[],

src/ui/components/default-component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ export function DefaultComponent(props: {
141141
{
142142
renderStatus === RenderStatus.PROMPT_INIT_RESULT_SELECTION && (
143143
<Box flexDirection='column'>
144-
<Text>Codify found the following supported resorces on your system.</Text>
144+
<Text>Codify found the following supported resources on your system.</Text>
145145
<Text> </Text>
146-
<Text bold> Select the resources to import:</Text>
146+
<Text bold> Select resources to import:</Text>
147147
<MultiSelect
148148
defaultSelected={(renderData as string[]).map((o) => ({ label: o, value: o }))}
149149
items={(renderData as string[]).map((o) => ({ label: o, value: o })).sort((a, b) => a.label.localeCompare(b.label))}

0 commit comments

Comments
 (0)