mirror of
https://github.com/docmost/docmost.git
synced 2026-07-26 11:34:42 +10:00
feat(bases): allow updateRow to set position atomically
This commit is contained in:
@@ -150,6 +150,9 @@ export function useUpdateRowMutation() {
|
|||||||
? {
|
? {
|
||||||
...row,
|
...row,
|
||||||
cells: { ...row.cells, ...variables.cells },
|
cells: { ...row.cells, ...variables.cells },
|
||||||
|
...(variables.position !== undefined && {
|
||||||
|
position: variables.position,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
: row,
|
: row,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -272,6 +272,7 @@ export type UpdateRowInput = {
|
|||||||
rowId: string;
|
rowId: string;
|
||||||
pageId: string;
|
pageId: string;
|
||||||
cells: Record<string, unknown>;
|
cells: Record<string, unknown>;
|
||||||
|
position?: string;
|
||||||
requestId?: string;
|
requestId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ export class UpdateRowDto {
|
|||||||
@IsObject()
|
@IsObject()
|
||||||
cells: Record<string, unknown>;
|
cells: Record<string, unknown>;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
position?: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
requestId?: string;
|
requestId?: string;
|
||||||
|
|||||||
@@ -135,6 +135,15 @@ export class BaseRowService {
|
|||||||
const properties = await this.basePropertyRepo.findByPageId(dto.pageId);
|
const properties = await this.basePropertyRepo.findByPageId(dto.pageId);
|
||||||
const validatedCells = this.validateCells(dto.cells, properties);
|
const validatedCells = this.validateCells(dto.cells, properties);
|
||||||
|
|
||||||
|
// Smoke-check the position (same guard as `reorder`).
|
||||||
|
if (dto.position !== undefined) {
|
||||||
|
try {
|
||||||
|
generateJitteredKeyBetween(dto.position, null);
|
||||||
|
} catch {
|
||||||
|
throw new BadRequestException('Invalid position value');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const existing = await this.baseRowRepo.findById(dto.rowId, { workspaceId });
|
const existing = await this.baseRowRepo.findById(dto.rowId, { workspaceId });
|
||||||
const mergedRow = {
|
const mergedRow = {
|
||||||
...((existing?.cells as Record<string, unknown>) ?? {}),
|
...((existing?.cells as Record<string, unknown>) ?? {}),
|
||||||
@@ -154,6 +163,7 @@ export class BaseRowService {
|
|||||||
pageId: dto.pageId,
|
pageId: dto.pageId,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
actorId: userId,
|
actorId: userId,
|
||||||
|
position: dto.position,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -275,6 +275,7 @@ export class BaseRowRepo {
|
|||||||
pageId: string;
|
pageId: string;
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
actorId?: string;
|
actorId?: string;
|
||||||
|
position?: string;
|
||||||
trx?: KyselyTransaction;
|
trx?: KyselyTransaction;
|
||||||
},
|
},
|
||||||
): Promise<BaseRow | undefined> {
|
): Promise<BaseRow | undefined> {
|
||||||
@@ -287,6 +288,7 @@ export class BaseRowRepo {
|
|||||||
.updateTable('baseRows')
|
.updateTable('baseRows')
|
||||||
.set({
|
.set({
|
||||||
cells: sql`jsonb_set_many(cells, ${patchJson}::text::jsonb)`,
|
cells: sql`jsonb_set_many(cells, ${patchJson}::text::jsonb)`,
|
||||||
|
...(opts.position !== undefined && { position: opts.position }),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
lastUpdatedById: opts.actorId ?? null,
|
lastUpdatedById: opts.actorId ?? null,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user