Skip to content

Commit 170cbf0

Browse files
FilSylvestre
andauthored
sort workspaces by owner (vs member) first, then alphabetical order (#790)
* sort workspaces by owner (vs member) first, then alphabetical order of the name to be consistent with the order displayed on the site * be smarter * Filter workspace list by tier and order by role (#789) * filter tier and order by role * no sort * fix parens * pattern --------- Co-authored-by: Sylvestre <[email protected]>
1 parent 4a75582 commit 170cbf0

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/deploy.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,12 @@ export async function deploy(
104104
let authError: null | "unauthenticated" | "forbidden" = null;
105105
try {
106106
if (apiKey) {
107+
const memberTiers = new Set(["starter_2024", "pro_2024", "enterprise_2024"]);
107108
currentUser = await apiClient.getCurrentUser();
108109
// List of valid workspaces that can be used to create projects.
109-
currentUser.workspaces = currentUser.workspaces.filter((w) => w.role === "owner" || w.role === "member");
110+
currentUser.workspaces = currentUser.workspaces.filter(
111+
(w) => (w.role === "owner" || w.role === "member") && memberTiers.has(w.tier)
112+
);
110113
}
111114
} catch (error) {
112115
if (isHttpError(error)) {
@@ -391,7 +394,7 @@ export async function promptDeployTarget(
391394
message: "Which Observable workspace do you want to use?",
392395
options: currentUser.workspaces
393396
.map((w) => ({value: w, label: formatUser(w)}))
394-
.sort((a, b) => a.label.localeCompare(b.label)),
397+
.sort((a, b) => b.value.role.localeCompare(a.value.role) || a.label.localeCompare(b.label)),
395398
initialValue: currentUser.workspaces[0] // the oldest workspace, maybe?
396399
});
397400
if (clack.isCancel(chosenWorkspace)) {

test/deploy-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ describe("deploy", () => {
531531
assert.ok(err instanceof Error);
532532
assert.match(err.message, /out of inputs for select.*Which Observable workspace do you want to use/);
533533
assert.ok("options" in err && Array.isArray(err.options) && err.options.length === 2);
534+
assert.ok("options" in err && Array.isArray(err.options) && err.options[0].value.role === "owner");
535+
assert.ok("options" in err && Array.isArray(err.options) && err.options[1].value.role === "member");
534536
}
535537
});
536538

test/mocks/observableApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ const workspaces = [
342342
name: "Mock User's Workspace",
343343
tier: "pro_2024",
344344
type: "team",
345-
role: "owner"
345+
role: "member"
346346
},
347347
{
348348
id: "0000000000000002",

0 commit comments

Comments
 (0)