Skip to content

Commit 7699480

Browse files
authored
Fixed autocomplete search inputs.
2 parents 9386430 + de78028 commit 7699480

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

src/interactive.mjs

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ async function selectLagoonInstance() {
135135
message: 'Select a Lagoon instance:',
136136
choices: instances.map(instance => ({
137137
value: instance,
138-
label: instance
138+
name: instance
139139
}))
140140
});
141141

@@ -154,12 +154,16 @@ async function selectProjectWithDetails(instance) {
154154
spinner.stop();
155155

156156
// Use search prompt with autocomplete functionality
157+
const projectChoices = projectsWithDetails.map(project => ({
158+
value: project.projectname,
159+
name: project.projectname
160+
}));
157161
const project = await search({
158162
message: 'Select a project (type to search):',
159-
choices: projectsWithDetails.map(project => ({
160-
value: project.projectname,
161-
label: project.projectname
162-
}))
163+
source: (input) => {
164+
input = input || '';
165+
return projectChoices.filter(choice => choice.name.toLowerCase().includes(input.toLowerCase()));
166+
}
163167
});
164168

165169
const projectDetails = projectsWithDetails.find(p => p.projectname === project);
@@ -180,24 +184,25 @@ async function selectProjectWithDetails(instance) {
180184
async function showMainMenu(instance, project) {
181185
console.log(chalk.blue(`\nCurrent Instance: ${chalk.bold(instance)}`));
182186
console.log(chalk.blue(`Current Project: ${chalk.bold(project)}\n`));
183-
184-
const action = await search({
187+
const actions = [
188+
{ value: 'listEnvironments', name: 'List Environments' },
189+
{ value: 'listUsers', name: 'List Users' },
190+
{ value: 'deleteEnvironment', name: 'Delete Environment' },
191+
{ value: 'generateLoginLink', name: 'Generate Login Link' },
192+
{ value: 'clearCache', name: 'Clear Drupal Cache' },
193+
{ value: 'deployBranch', name: 'Deploy Branch' },
194+
{ value: 'changeProject', name: 'Change Project' },
195+
{ value: 'changeInstance', name: 'Change Instance' },
196+
{ value: 'configureUserSshKey', name: 'Configure User SSH Key' },
197+
{ value: 'exit', name: 'Exit' }
198+
];
199+
return search({
185200
message: 'What would you like to do? (type to search)',
186-
choices: [
187-
{ value: 'listEnvironments', label: 'List Environments' },
188-
{ value: 'listUsers', label: 'List Users' },
189-
{ value: 'deleteEnvironment', label: 'Delete Environment' },
190-
{ value: 'generateLoginLink', label: 'Generate Login Link' },
191-
{ value: 'clearCache', label: 'Clear Drupal Cache' },
192-
{ value: 'deployBranch', label: 'Deploy Branch' },
193-
{ value: 'changeProject', label: 'Change Project' },
194-
{ value: 'changeInstance', label: 'Change Instance' },
195-
{ value: 'configureUserSshKey', label: 'Configure User SSH Key' },
196-
{ value: 'exit', label: 'Exit' }
197-
]
201+
source: (input) => {
202+
input = input || '';
203+
return actions.filter(action => action.name.toLowerCase().includes(input.toLowerCase()));
204+
}
198205
});
199-
200-
return action;
201206
}
202207

203208
async function listEnvironments(instance, project, githubBaseUrl) {
@@ -277,12 +282,12 @@ async function deleteEnvironmentFlow(instance, project, githubBaseUrl) {
277282
const prUrl = `${githubBaseUrl}/pull/${prNumber}`;
278283
return {
279284
value: env,
280-
label: `${env} (PR #${prNumber}: ${prUrl})`
285+
name: `${env} (PR #${prNumber}: ${prUrl})`
281286
};
282287
}
283288
return {
284289
value: env,
285-
label: env
290+
name: env
286291
};
287292
});
288293

@@ -345,12 +350,12 @@ async function generateLoginLinkFlow(instance, project, githubBaseUrl) {
345350
if (prNumber && githubBaseUrl) {
346351
return {
347352
value: env,
348-
label: `${env} (PR #${prNumber})`
353+
name: `${env} (PR #${prNumber})`
349354
};
350355
}
351356
return {
352357
value: env,
353-
label: env
358+
name: env
354359
};
355360
});
356361

@@ -400,12 +405,12 @@ async function clearCacheFlow(instance, project, githubBaseUrl) {
400405
if (prNumber && githubBaseUrl) {
401406
return {
402407
value: env,
403-
label: `${env} (PR #${prNumber})`
408+
name: `${env} (PR #${prNumber})`
404409
};
405410
}
406411
return {
407412
value: env,
408-
label: env
413+
name: env
409414
};
410415
});
411416

@@ -486,7 +491,7 @@ async function deployBranchFlow(instance, project, projectDetails) {
486491
// Create choices array for the select prompt
487492
const choices = sortedBranches.map(branch => ({
488493
value: branch,
489-
label: branch
494+
name: branch
490495
}));
491496

492497
// Allow user to select a branch

src/lagoon-api.mjs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,8 @@ export async function getProjects(instance) {
6464
try {
6565
const command = `lagoon -l ${instance} list projects --output-json`;
6666
const { stdout } = await execLagoonCommand(command, `List Projects for ${instance}`);
67-
68-
// Parse the JSON output
6967
const projectsData = JSON.parse(stdout);
70-
71-
// Extract project names from the JSON data
72-
const projects = projectsData.data.map(project => project.projectname);
73-
74-
return projects;
68+
return projectsData.data.map(project => project.projectname);
7569
} catch (error) {
7670
throw new Error(`Failed to get projects for instance ${instance}: ${error.message}`);
7771
}

0 commit comments

Comments
 (0)