mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-07 03:16:42 +00:00
fleet create: Reduce the amount of org fields fetched
Halves the amount of org data retrieved to show the list of orgs to select from. Change-type: patch
This commit is contained in:
parent
ecbc660bf5
commit
025c4ef7f2
@ -130,7 +130,9 @@ export default class FleetCreateCmd extends Command {
|
||||
|
||||
async getOrganization() {
|
||||
const { getOwnOrganizations } = await import('../../utils/sdk');
|
||||
const organizations = await getOwnOrganizations(getBalenaSdk());
|
||||
const organizations = await getOwnOrganizations(getBalenaSdk(), {
|
||||
$select: ['name', 'handle'],
|
||||
});
|
||||
|
||||
if (organizations.length === 0) {
|
||||
// User is not a member of any organizations (should not happen).
|
||||
|
@ -193,7 +193,9 @@ export async function selectOrganization(
|
||||
organizations?: Array<Pick<Organization, 'handle' | 'name'>>,
|
||||
) {
|
||||
// Use either provided orgs (if e.g. already loaded) or load from cloud
|
||||
organizations ??= await getBalenaSdk().models.organization.getAll();
|
||||
organizations ??= await getBalenaSdk().models.organization.getAll({
|
||||
$select: ['name', 'handle'],
|
||||
});
|
||||
return getCliForm().ask({
|
||||
message: 'Select an organization',
|
||||
type: 'list',
|
||||
|
@ -81,26 +81,39 @@ export async function getFleetSlug(
|
||||
return nameOrSlug.toLowerCase();
|
||||
}
|
||||
|
||||
export async function getOwnOrganizations(
|
||||
sdk: BalenaSDK,
|
||||
): Promise<Organization[]>;
|
||||
export async function getOwnOrganizations<TP extends PineOptions<Organization>>(
|
||||
sdk: BalenaSDK,
|
||||
options: TP,
|
||||
): Promise<Array<PineTypedResult<Organization, TP>>>;
|
||||
/**
|
||||
* Wraps the sdk organization.getAll method,
|
||||
* restricting to those orgs user is a member of
|
||||
*/
|
||||
export async function getOwnOrganizations(
|
||||
sdk: BalenaSDK,
|
||||
options?: PineOptions<Organization>,
|
||||
): Promise<Organization[]> {
|
||||
return await sdk.models.organization.getAll({
|
||||
$filter: {
|
||||
organization_membership: {
|
||||
$any: {
|
||||
$alias: 'orm',
|
||||
$expr: {
|
||||
orm: {
|
||||
user: await sdk.auth.getUserId(),
|
||||
return await sdk.models.organization.getAll(
|
||||
sdk.utils.mergePineOptions(
|
||||
{
|
||||
$filter: {
|
||||
organization_membership: {
|
||||
$any: {
|
||||
$alias: 'orm',
|
||||
$expr: {
|
||||
orm: {
|
||||
user: await sdk.auth.getUserId(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
$orderby: 'name asc',
|
||||
},
|
||||
},
|
||||
$orderby: 'name asc',
|
||||
});
|
||||
options,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user