Skip to content

Commit b9055d4

Browse files
committed
[FIX] borders: import is too long for large border amount
Migrate borders to reduce number of borders to import
1 parent 25ba514 commit b9055d4

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/migrations/migration_steps.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { BACKGROUND_CHART_COLOR, FORMULA_REF_IDENTIFIER } from "../constants";
2-
import { getItemId, getUniqueText, sanitizeSheetName } from "../helpers";
2+
import { getItemId, getUniqueText, recomputeZones, sanitizeSheetName } from "../helpers";
33
import { toXC } from "../helpers/coordinates";
44
import { getMaxObjectId } from "../helpers/pivot/pivot_helpers";
55
import { DEFAULT_TABLE_CONFIG } from "../helpers/table_presets";
66
import { overlap, toZone, zoneToXc } from "../helpers/zones";
77
import { Registry } from "../registries/registry";
8-
import { CustomizedDataSet, DEFAULT_LOCALE, Format, WorkbookData, Zone } from "../types";
8+
import { CustomizedDataSet, DEFAULT_LOCALE, Format, UID, WorkbookData, Zone } from "../types";
99
import { normalizeV9 } from "./legacy_tools";
1010
import { WEEK_START } from "./locale";
1111

@@ -548,6 +548,32 @@ migrationStepRegistry
548548
}
549549
return data;
550550
},
551+
})
552+
.add("19.0", {
553+
migrate(data: WorkbookData): any {
554+
for (const sheet of data.sheets || []) {
555+
const borderType: Record<UID, Zone[]> = {};
556+
for (const zoneXc in sheet.borders) {
557+
const borderId = sheet.borders[zoneXc];
558+
if (!borderId) continue;
559+
if (!(borderId in borderType)) borderType[borderId] = [];
560+
borderType[borderId].push(toZone(zoneXc));
561+
}
562+
const borders = {};
563+
for (const borderId in borderType) {
564+
const border = data.borders[borderId];
565+
if (!border) continue;
566+
const zones = recomputeZones(borderType[borderId]);
567+
if (border.left || border.right) border.vertical = border.left || border.right;
568+
if (border.top || border.bottom) border.horizontal = border.top || border.bottom;
569+
for (const zone of zones) {
570+
borders[zoneToXc(zone)] = borderId;
571+
}
572+
}
573+
sheet.borders = borders;
574+
}
575+
return data;
576+
},
551577
});
552578

553579
function fixOverlappingFilters(data: any): any {

src/plugins/core/borders.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,17 @@ export class BordersPlugin extends CorePlugin<BordersPluginState> implements Bor
462462
import(data: WorkbookData) {
463463
if (Object.keys(data.borders || {}).length) {
464464
for (const sheet of data.sheets) {
465+
const borderType: Record<UID, Zone[]> = {};
465466
for (const zoneXc in sheet.borders) {
466467
const borderId = sheet.borders[zoneXc];
467-
this.addBorder(sheet.id, toZone(zoneXc), data.borders[borderId]);
468+
if (!borderId) continue;
469+
if (!(borderId in borderType)) borderType[borderId] = [];
470+
borderType[borderId].push(toZone(zoneXc));
471+
}
472+
for (const borderId in borderType) {
473+
const zones = recomputeZones(borderType[borderId]);
474+
const border = data.borders[borderId];
475+
this.addBorders(sheet.id, zones, border);
468476
}
469477
}
470478
}

0 commit comments

Comments
 (0)