Skip to content

Commit

Permalink
chore: shift page.list to resource
Browse files Browse the repository at this point in the history
we want ot shift to resource as this returns pages + folders

also removed references to `page.list` in our codebase (as given by lsp)
  • Loading branch information
seaerchin committed Aug 6, 2024
1 parent 5c50214 commit 8ecb5e1
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { trpc } from "~/utils/trpc"
import { ResourceTableMenu } from "./ResourceTableMenu"
import { TitleCell } from "./TitleCell"

type ResourceTableData = RouterOutput["page"]["list"][number]
type ResourceTableData = RouterOutput["resource"]["list"][number]

const columnsHelper = createColumnHelper<ResourceTableData>()

Expand Down Expand Up @@ -61,7 +61,7 @@ export const ResourceTable = ({
() => getColumns({ siteId, resourceId }),
[siteId, resourceId],
)
const { data: resources } = trpc.page.list.useQuery(
const { data: resources } = trpc.resource.list.useQuery(
{
siteId,
resourceId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type { RouterOutput } from "~/utils/trpc"

export type ResourceTableData = RouterOutput["page"]["list"][number]
export type ResourceTableData = RouterOutput["resource"]["list"][number]
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const CreateFolderModal = ({
onSettled: onClose,
onSuccess: () => {
void utils.site.list.invalidate()
void utils.page.list.invalidate()
void utils.resource.list.invalidate()
toast({ title: "Folder created!", status: "success" })
},
onError: (err) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const useCreatePageWizardContext = ({

const { mutate, isLoading } = trpc.page.createPage.useMutation({
onSuccess: async () => {
await utils.page.list.invalidate()
await utils.resource.list.invalidate()
onClose()
},
// TOOD: Error handling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const MoveResourceContent = withSuspense(
},
onSuccess: () => {
void utils.page.readPageAndBlob.invalidate()
void utils.page.list.invalidate({
void utils.resource.list.invalidate({
// TODO: Update backend `list` to use the proper schema
resourceId: movedItem?.resourceId
? Number(movedItem.resourceId)
Expand Down
5 changes: 5 additions & 0 deletions apps/studio/src/schemas/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ export const moveSchema = z.object({
movedResourceId: bigIntSchema,
destinationResourceId: bigIntSchema,
})

export const listResourceSchema = z.object({
siteId: z.number(),
resourceId: z.number().optional(),
})
29 changes: 0 additions & 29 deletions apps/studio/src/server/modules/page/page.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,6 @@ const validatedPageProcedure = protectedProcedure.use(
)

export const pageRouter = router({
list: protectedProcedure
.input(
z.object({
siteId: z.number(),
resourceId: z.number().optional(),
}),
)
.query(async ({ input: { siteId, resourceId } }) => {
let query = db
.selectFrom("Resource")
.where("Resource.siteId", "=", siteId)

if (resourceId) {
query = query.where("Resource.parentId", "=", String(resourceId))
} else {
query = query.where("Resource.parentId", "is", null)
}

return query
.select([
"Resource.id",
"Resource.permalink",
"Resource.title",
"Resource.publishedVersionId",
"Resource.draftBlobId",
"Resource.type",
])
.execute()
}),
readPageAndBlob: protectedProcedure
.input(getEditPageSchema)
.query(async ({ input: { pageId, siteId } }) => {
Expand Down
25 changes: 25 additions & 0 deletions apps/studio/src/server/modules/resource/resource.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TRPCError } from "@trpc/server"
import {
getChildrenSchema,
getMetadataSchema,
listResourceSchema,
moveSchema,
} from "~/schemas/resource"
import { protectedProcedure, router } from "~/server/trpc"
Expand Down Expand Up @@ -66,4 +67,28 @@ export const resourceRouter = router({
])
.executeTakeFirst()
}),
list: protectedProcedure
.input(listResourceSchema)
.query(async ({ input: { siteId, resourceId } }) => {
let query = db
.selectFrom("Resource")
.where("Resource.siteId", "=", siteId)

if (resourceId) {
query = query.where("Resource.parentId", "=", String(resourceId))
} else {
query = query.where("Resource.parentId", "is", null)
}

return query
.select([
"Resource.id",
"Resource.permalink",
"Resource.title",
"Resource.publishedVersionId",
"Resource.draftBlobId",
"Resource.type",
])
.execute()
}),
})
2 changes: 1 addition & 1 deletion apps/studio/tests/msw/handlers/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { delay } from "msw"
import { trpcMsw } from "../mockTrpc"

const pageListQuery = (wait?: DelayMode | number) => {
return trpcMsw.page.list.query(async () => {
return trpcMsw.resource.list.query(async () => {
if (wait !== undefined) {
await delay(wait)
}
Expand Down

0 comments on commit 8ecb5e1

Please sign in to comment.