feat(sprint-5.5): add block version snapshots with switching between versions
- Add BlockSnapshot Prisma model (html, css, version, changelog) + migration - Add API endpoints: POST/GET /blocks/snapshots, GET /blocks/snapshots/:id - BlockMetaBar: version dropdown, HTML capture on save, onSnapshotSelect prop - "Сохранить версию" now captures innerHTML snapshot + CSS and stores in DB - Selecting archived version shows stored HTML snapshot instead of live component - Yellow banner "Архивная версия" with link to return to current - Split all 8 block pages into Server Component (metadata) + Client Component - Add data-block-capture attribute for snapshot capture targeting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "BlockSnapshot" (
|
||||
"id" TEXT NOT NULL,
|
||||
"blockPath" TEXT NOT NULL,
|
||||
"version" TEXT NOT NULL,
|
||||
"changelog" JSONB NOT NULL DEFAULT '[]',
|
||||
"html" TEXT NOT NULL,
|
||||
"css" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "BlockSnapshot_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "BlockSnapshot_blockPath_idx" ON "BlockSnapshot"("blockPath");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "BlockSnapshot_blockPath_version_key" ON "BlockSnapshot"("blockPath", "version");
|
||||
@@ -50,3 +50,16 @@ model Block {
|
||||
updatedAt DateTime @updatedAt
|
||||
createdAt DateTime @default(now())
|
||||
}
|
||||
|
||||
model BlockSnapshot {
|
||||
id String @id @default(uuid())
|
||||
blockPath String
|
||||
version String
|
||||
changelog Json @default("[]")
|
||||
html String @db.Text
|
||||
css String @db.Text
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@unique([blockPath, version])
|
||||
@@index([blockPath])
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Controller, Get, Patch, Query, Body } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Patch, Param, Query, Body } from '@nestjs/common';
|
||||
import { BlocksService } from './blocks.service';
|
||||
|
||||
@Controller('blocks')
|
||||
@@ -22,4 +22,22 @@ export class BlocksController {
|
||||
) {
|
||||
return this.blocks.update(path, body);
|
||||
}
|
||||
|
||||
@Post('snapshots')
|
||||
createSnapshot(
|
||||
@Query('path') path: string,
|
||||
@Body() body: { version: string; changelog: object[]; html: string; css: string },
|
||||
) {
|
||||
return this.blocks.createSnapshot(path, body);
|
||||
}
|
||||
|
||||
@Get('snapshots')
|
||||
listSnapshots(@Query('path') path: string) {
|
||||
return this.blocks.listSnapshots(path);
|
||||
}
|
||||
|
||||
@Get('snapshots/:id')
|
||||
getSnapshot(@Param('id') id: string) {
|
||||
return this.blocks.getSnapshot(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,24 @@ export class BlocksService {
|
||||
update(path: string, data: { version?: string; isInPreview?: boolean; changelog?: object[] }) {
|
||||
return this.prisma.block.update({ where: { path }, data });
|
||||
}
|
||||
|
||||
createSnapshot(blockPath: string, data: { version: string; changelog: object[]; html: string; css: string }) {
|
||||
return this.prisma.blockSnapshot.upsert({
|
||||
where: { blockPath_version: { blockPath, version: data.version } },
|
||||
update: { html: data.html, css: data.css, changelog: data.changelog },
|
||||
create: { blockPath, ...data },
|
||||
});
|
||||
}
|
||||
|
||||
listSnapshots(blockPath: string) {
|
||||
return this.prisma.blockSnapshot.findMany({
|
||||
where: { blockPath },
|
||||
select: { id: true, version: true, createdAt: true },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
}
|
||||
|
||||
getSnapshot(id: string) {
|
||||
return this.prisma.blockSnapshot.findUniqueOrThrow({ where: { id } });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user