fix: add diff x,y (#928)

This commit is contained in:
Guy Ben-Aharon
2025-09-21 12:12:20 +03:00
committed by GitHub
parent 1b8d51b73c
commit e4c4a3b354
3 changed files with 92 additions and 10 deletions

View File

@@ -1,11 +1,13 @@
import { z } from 'zod';
import type { Area } from '../area';
export type AreaDiffAttribute = keyof Pick<Area, 'name' | 'color'>;
export type AreaDiffAttribute = keyof Pick<Area, 'name' | 'color' | 'x' | 'y'>;
const areaDiffAttributeSchema: z.ZodType<AreaDiffAttribute> = z.union([
z.literal('name'),
z.literal('color'),
z.literal('x'),
z.literal('y'),
]);
export interface AreaDiffChanged {
@@ -13,8 +15,8 @@ export interface AreaDiffChanged {
type: 'changed';
areaId: string;
attribute: AreaDiffAttribute;
oldValue?: string | null;
newValue?: string | null;
oldValue?: string | number | null;
newValue?: string | number | null;
}
export const AreaDiffChangedSchema: z.ZodType<AreaDiffChanged> = z.object({
@@ -22,8 +24,8 @@ export const AreaDiffChangedSchema: z.ZodType<AreaDiffChanged> = z.object({
type: z.literal('changed'),
areaId: z.string(),
attribute: areaDiffAttributeSchema,
oldValue: z.string().or(z.null()).optional(),
newValue: z.string().or(z.null()).optional(),
oldValue: z.union([z.string(), z.number(), z.null()]).optional(),
newValue: z.union([z.string(), z.number(), z.null()]).optional(),
});
export interface AreaDiffRemoved {

View File

@@ -269,6 +269,46 @@ function compareTables({
changedTables.set(oldTable.id, true);
}
if (attributesToCheck.includes('x') && oldTable.x !== newTable.x) {
diffMap.set(
getDiffMapKey({
diffObject: 'table',
objectId: oldTable.id,
attribute: 'x',
}),
{
object: 'table',
type: 'changed',
tableId: oldTable.id,
attribute: 'x',
newValue: newTable.x,
oldValue: oldTable.x,
}
);
changedTables.set(oldTable.id, true);
}
if (attributesToCheck.includes('y') && oldTable.y !== newTable.y) {
diffMap.set(
getDiffMapKey({
diffObject: 'table',
objectId: oldTable.id,
attribute: 'y',
}),
{
object: 'table',
type: 'changed',
tableId: oldTable.id,
attribute: 'y',
newValue: newTable.y,
oldValue: oldTable.y,
}
);
changedTables.set(oldTable.id, true);
}
}
}
}
@@ -788,6 +828,44 @@ function compareAreas({
);
changedAreas.set(oldArea.id, true);
}
if (attributesToCheck.includes('x') && oldArea.x !== newArea.x) {
diffMap.set(
getDiffMapKey({
diffObject: 'area',
objectId: oldArea.id,
attribute: 'x',
}),
{
object: 'area',
type: 'changed',
areaId: oldArea.id,
attribute: 'x',
newValue: newArea.x,
oldValue: oldArea.x,
}
);
changedAreas.set(oldArea.id, true);
}
if (attributesToCheck.includes('y') && oldArea.y !== newArea.y) {
diffMap.set(
getDiffMapKey({
diffObject: 'area',
objectId: oldArea.id,
attribute: 'y',
}),
{
object: 'area',
type: 'changed',
areaId: oldArea.id,
attribute: 'y',
newValue: newArea.y,
oldValue: oldArea.y,
}
);
changedAreas.set(oldArea.id, true);
}
}
}
}

View File

@@ -3,13 +3,15 @@ import type { DBTable } from '../db-table';
export type TableDiffAttribute = keyof Pick<
DBTable,
'name' | 'comments' | 'color'
'name' | 'comments' | 'color' | 'x' | 'y'
>;
const tableDiffAttributeSchema: z.ZodType<TableDiffAttribute> = z.union([
z.literal('name'),
z.literal('comments'),
z.literal('color'),
z.literal('x'),
z.literal('y'),
]);
export interface TableDiffChanged {
@@ -17,8 +19,8 @@ export interface TableDiffChanged {
type: 'changed';
tableId: string;
attribute: TableDiffAttribute;
oldValue?: string | null;
newValue?: string | null;
oldValue?: string | number | null;
newValue?: string | number | null;
}
export const TableDiffChangedSchema: z.ZodType<TableDiffChanged> = z.object({
@@ -26,8 +28,8 @@ export const TableDiffChangedSchema: z.ZodType<TableDiffChanged> = z.object({
type: z.literal('changed'),
tableId: z.string(),
attribute: tableDiffAttributeSchema,
oldValue: z.string().or(z.null()).optional(),
newValue: z.string().or(z.null()).optional(),
oldValue: z.union([z.string(), z.number(), z.null()]).optional(),
newValue: z.union([z.string(), z.number(), z.null()]).optional(),
});
export interface TableDiffRemoved {