feat(pages): explicit position ordering + sectioned space view
Add position column to pages (migration 020), update listBySpace to ORDER BY position, title, expose position in update(), add to patchSchema, and replace the space view flat table with a tree renderer grouping pages by parent_id under h4 section headers. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,8 @@ const patchSchema = z.object({
|
||||
title: z.string().min(1).max(500).optional(),
|
||||
body_md: z.string().optional(),
|
||||
body_html: z.string().nullable().optional(),
|
||||
parent_id: z.string().uuid().nullable().optional()
|
||||
parent_id: z.string().uuid().nullable().optional(),
|
||||
position: z.number().int().optional()
|
||||
});
|
||||
|
||||
const idParams = z.object({ id: z.string().uuid() });
|
||||
|
||||
3
lib/db/migrations/020_page_position.sql
Normal file
3
lib/db/migrations/020_page_position.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
-- 020: explicit page ordering within a space (and within a parent).
|
||||
ALTER TABLE pages ADD COLUMN IF NOT EXISTS position integer NOT NULL DEFAULT 0;
|
||||
CREATE INDEX IF NOT EXISTS idx_pages_space_position ON pages (space_id, position, title);
|
||||
@@ -45,8 +45,8 @@ export async function getBySlug(space_id, slug) {
|
||||
|
||||
export async function listBySpace(space_id) {
|
||||
const { rows } = await pool.query(
|
||||
`SELECT id, space_id, slug, title, parent_id, updated_at
|
||||
FROM pages WHERE space_id=$1 ORDER BY title`, [space_id]
|
||||
`SELECT id, space_id, slug, title, parent_id, position, updated_at
|
||||
FROM pages WHERE space_id=$1 ORDER BY position, title`, [space_id]
|
||||
);
|
||||
return rows;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ export async function update(id, patch, actor) {
|
||||
const client = await pool.connect();
|
||||
try {
|
||||
await client.query('BEGIN');
|
||||
const fields = ['slug','title','body_md','body_html','parent_id','embedding'];
|
||||
const fields = ['slug','title','body_md','body_html','parent_id','position','embedding'];
|
||||
const sets = [], vals = [];
|
||||
let i = 1;
|
||||
for (const f of fields) {
|
||||
|
||||
Reference in New Issue
Block a user