Skip to content

Commit fd34d60

Browse files
committed
(web) address change requests for console
1 parent 9ec7d4f commit fd34d60

File tree

11 files changed

+41
-33
lines changed

11 files changed

+41
-33
lines changed

package-lock.json

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/store/src/api/defs.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { randomUUID } from "crypto";
22
import { type Database } from "@tableland/sdk";
3+
import { restrictedDefSlugs } from "@tableland/studio-validators";
34
import { and, eq, ne } from "drizzle-orm";
45
import { type DrizzleD1Database } from "drizzle-orm/d1";
56
import { type Schema } from "../custom-types/index.js";
@@ -20,14 +21,17 @@ export function initDefs(db: DrizzleD1Database<typeof schema>, tbl: Database) {
2021
name: string,
2122
defId?: string,
2223
) {
24+
const slug = slugify(name);
25+
if (restrictedDefSlugs.includes(slug)) return false;
26+
2327
const res = await db
2428
.select()
2529
.from(projectDefs)
2630
.innerJoin(defs, eq(projectDefs.defId, defs.id))
2731
.where(
2832
and(
2933
eq(projectDefs.projectId, projectId),
30-
eq(defs.name, slugify(name)),
34+
eq(defs.name, slug),
3135
defId ? ne(defs.id, defId) : undefined,
3236
),
3337
)

packages/store/src/api/environments.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { randomUUID } from "crypto";
22
import { type Database } from "@tableland/sdk";
3+
import { restrictedEnvSlugs } from "@tableland/studio-validators";
34
import { eq, and, ne } from "drizzle-orm";
45
import { type DrizzleD1Database } from "drizzle-orm/d1";
56
import * as schema from "../schema/index.js";
@@ -22,13 +23,16 @@ export function initEnvironments(
2223
name: string,
2324
envId?: string,
2425
) {
26+
const slug = slugify(name);
27+
if (restrictedEnvSlugs.includes(slug)) return false;
28+
2529
const res = await db
2630
.select()
2731
.from(environments)
2832
.where(
2933
and(
3034
eq(environments.projectId, projectId),
31-
eq(environments.slug, slugify(name)),
35+
eq(environments.slug, slug),
3236
envId ? ne(environments.id, envId) : undefined,
3337
),
3438
)

packages/store/src/api/projects.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { randomUUID } from "crypto";
22
import { type Database } from "@tableland/sdk";
3+
import { restrictedProjectSlugs } from "@tableland/studio-validators";
34
import { and, desc, eq, inArray, isNotNull, ne } from "drizzle-orm";
45
import { type DrizzleD1Database } from "drizzle-orm/d1";
56
import * as schema from "../schema/index.js";
@@ -24,14 +25,17 @@ export function initProjects(
2425
name: string,
2526
projectId?: string,
2627
) {
28+
const slug = slugify(name);
29+
if (restrictedProjectSlugs.includes(slug)) return false;
30+
2731
const res = await db
2832
.select()
2933
.from(projects)
3034
.innerJoin(teamProjects, eq(projects.id, teamProjects.projectId))
3135
.where(
3236
and(
3337
eq(teamProjects.teamId, teamId),
34-
eq(projects.slug, slugify(name)),
38+
eq(projects.slug, slug),
3539
projectId ? ne(projects.id, projectId) : undefined,
3640
),
3741
)

packages/store/src/api/teams.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { randomUUID } from "crypto";
22
import { type Database } from "@tableland/sdk";
3+
import { restrictedTeamSlugs } from "@tableland/studio-validators";
34
import { and, asc, eq, ne, inArray } from "drizzle-orm";
45
import { type DrizzleD1Database } from "drizzle-orm/d1";
56
import { sealData } from "iron-session";
@@ -27,6 +28,9 @@ export function initTeams(
2728
) {
2829
return {
2930
nameAvailable: async function (name: string, teamId?: string) {
31+
const slug = slugify(name);
32+
if (restrictedTeamSlugs.includes(slug)) return false;
33+
3034
const res = await db
3135
.select()
3236
.from(teams)

packages/validators/src/common.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@ export const defNameSchema = z
3030
{ message: "Definition name is invalid." },
3131
);
3232

33-
export const envNameSchema = z.object({ name: z.string().trim().min(1) });
33+
export const envNameSchema = z.object({
34+
name: z
35+
.string()
36+
.trim()
37+
.min(1)
38+
.refine((val) => !restrictedDefSlugs.includes(slugify(val)), {
39+
message: "You can't use a restricted word as an environment name.",
40+
}),
41+
});

packages/validators/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from "./validators/teams.js";
44
export * from "./validators/projects.js";
55
export * from "./validators/auth.js";
66
export * from "./validators/tables.js";
7+
export * from "./restricted-slugs.js";

packages/validators/src/restricted-slugs.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ export const restrictedTeamSlugs = [
1010

1111
export const restrictedProjectSlugs = ["people", "settings"];
1212

13-
export const restrictedDefSlugs = ["settings", "tables"];
13+
export const restrictedDefSlugs = ["settings", "tables", "console"];
14+
15+
export const restrictedEnvSlugs = ["settings"];
1416

1517
export const allRestrictedSlugs = [
1618
...restrictedTeamSlugs,
1719
...restrictedProjectSlugs,
1820
...restrictedDefSlugs,
21+
...restrictedEnvSlugs,
1922
];

packages/web/app/[team]/[project]/[env]/console/page.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { TRPCError } from "@trpc/server";
21
import { Console } from "@/components/console";
32
import {
43
environmentBySlug,
@@ -15,12 +14,6 @@ export default async function ConsolePage({
1514
const project = await projectBySlug(params.project, team.id);
1615
const environment = await environmentBySlug(project.id, params.env);
1716

18-
if (!environment) {
19-
throw new TRPCError({
20-
code: "NOT_FOUND",
21-
});
22-
}
23-
2417
return (
2518
<main className="flex-1 p-4">
2619
<Console environmentId={environment.id} />

packages/web/app/[team]/[project]/_components/sidebar.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
useParams,
1313
useRouter,
1414
useSelectedLayoutSegment,
15-
usePathname,
15+
useSelectedLayoutSegments,
1616
} from "next/navigation";
1717
import { skipToken } from "@tanstack/react-query";
1818
import { useState } from "react";
@@ -42,15 +42,14 @@ export function Sidebar() {
4242
}>();
4343

4444
const router = useRouter();
45-
// TODO: not sure how we are supposed to distinguish between an environment
46-
// named "console" and the console for an environment. inspecting the url
47-
// length like this seems wrong.
48-
const pathParts = usePathname().split("/");
49-
50-
// splitting on "/" means there is always an empty string as the first
51-
// element in the Array since pathname always starts with /
52-
const isConsole = pathParts.length === 5 && pathParts.pop() === "console";
45+
5346
const selectedLayoutSegment = useSelectedLayoutSegment();
47+
const selectedLayoutSegments = useSelectedLayoutSegments();
48+
const isConsole =
49+
!!envSlug &&
50+
!defSlug &&
51+
selectedLayoutSegments.slice(-1).pop() === "console";
52+
5453
const [newDefOpen, setNewDefOpen] = useState(false);
5554
const [importTableOpen, setImportTableOpen] = useState(false);
5655

@@ -146,8 +145,6 @@ export function Sidebar() {
146145
!defSlug && !!envSlug && !isConsole && envSlug === env?.slug
147146
}
148147
/>
149-
</SidebarSection>
150-
<SidebarSection>
151148
<SidebarLink
152149
icon={Terminal}
153150
title="Console"

packages/web/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"keccak": "^3.0.3",
5858
"lucide-react": "^0.354.0",
5959
"next": "^14.2.3",
60-
"prismjs": "^1.28.0",
6160
"react": "^18.3.1",
6261
"react-simple-code-editor": "0.13.1",
6362
"react-dom": "^18.3.1",

0 commit comments

Comments
 (0)