mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 05:37:51 +00:00
Remove extra request when filling the application selection list
Saves one request of about 450ms on the init and move commands. Change-type: patch
This commit is contained in:
parent
b6c7fb82c3
commit
46aa08c953
@ -157,18 +157,11 @@ export async function confirm(
|
||||
}
|
||||
}
|
||||
|
||||
export function selectApplication(
|
||||
export async function selectApplication(
|
||||
filter?: (app: ApplicationWithDeviceType) => boolean,
|
||||
errorOnEmptySelection = false,
|
||||
) {
|
||||
const balena = getBalenaSdk();
|
||||
return balena.models.application
|
||||
.hasAny()
|
||||
.then(async (hasAnyApplications) => {
|
||||
if (!hasAnyApplications) {
|
||||
throw new ExpectedError('No fleets found');
|
||||
}
|
||||
|
||||
const apps = (await balena.models.application.getAllDirectlyAccessible({
|
||||
$expand: {
|
||||
is_for__device_type: {
|
||||
@ -176,9 +169,13 @@ export function selectApplication(
|
||||
},
|
||||
},
|
||||
})) as ApplicationWithDeviceType[];
|
||||
return apps.filter(filter || _.constant(true));
|
||||
})
|
||||
.then((applications) => {
|
||||
|
||||
if (!apps.length) {
|
||||
throw new ExpectedError('No fleets found');
|
||||
}
|
||||
|
||||
const applications = filter ? apps.filter(filter) : apps;
|
||||
|
||||
if (errorOnEmptySelection && applications.length === 0) {
|
||||
throw new ExpectedError('No suitable fleets found for selection');
|
||||
}
|
||||
@ -190,7 +187,6 @@ export function selectApplication(
|
||||
value: application,
|
||||
})),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function selectOrganization(
|
||||
|
Loading…
Reference in New Issue
Block a user