From fe655792f371d1dd736cdf5ad8172ffe10f84e35 Mon Sep 17 00:00:00 2001 From: zhangw Date: Tue, 11 Jun 2024 15:40:07 +0800 Subject: [PATCH] fix(sheets-hyper-link): skip error on ref-range mutation (#2446) * feat: skip error on ref-range mutation * feat: i18n * feat: update * fix: intersets * feat: style * feat: remove skip error --- .../sheets/demo/default-workbook-data-demo.ts | 31 ++++++++++++++----- .../src/locale/en-US.ts | 2 +- .../src/locale/ru-RU.ts | 2 +- .../src/widgets/dropdown-widget.ts | 2 +- .../mutations/update-hyper-link.mutation.ts | 2 +- .../src/controllers/ref-range.controller.ts | 5 ++- .../src/models/hyper-link.model.ts | 20 +++++++----- .../sheets/src/services/ref-range/util.ts | 6 ++-- 8 files changed, 48 insertions(+), 22 deletions(-) diff --git a/examples/src/data/sheets/demo/default-workbook-data-demo.ts b/examples/src/data/sheets/demo/default-workbook-data-demo.ts index 7a2ddd397a5..728344a060f 100644 --- a/examples/src/data/sheets/demo/default-workbook-data-demo.ts +++ b/examples/src/data/sheets/demo/default-workbook-data-demo.ts @@ -178,13 +178,30 @@ const dataValidation = [ const dv2 = [ { uid: 'xxx-2', - type: DataValidationType.CHECKBOX, - ranges: [{ - startRow: 1, - endRow: 2, - startColumn: 1, - endColumn: 2, - }], + type: 'checkbox', + ranges: [ + { + startRow: 1, + endRow: 2, + startColumn: 1, + endColumn: 2, + }, + ], + }, + { + uid: 'adN9-O', + type: 'list', + formula1: "='sheet-0005'!F4:F8", + ranges: [ + { + startRow: 4, + startColumn: 5, + endRow: 14, + endColumn: 8, + rangeType: 0, + }, + ], + formula2: '', }, ]; diff --git a/packages/sheets-data-validation/src/locale/en-US.ts b/packages/sheets-data-validation/src/locale/en-US.ts index 8115717f287..62e2bcc0369 100644 --- a/packages/sheets-data-validation/src/locale/en-US.ts +++ b/packages/sheets-data-validation/src/locale/en-US.ts @@ -35,7 +35,7 @@ const locale: typeof zhCN = { title: 'Data validation management', addTitle: 'Create new data validation', removeAll: 'Remove All', - add: 'Create Data validation', + add: 'Add Rule', range: 'Ranges', type: 'Type', options: 'Advance options', diff --git a/packages/sheets-data-validation/src/locale/ru-RU.ts b/packages/sheets-data-validation/src/locale/ru-RU.ts index a0fe9f8ac36..d6c96453534 100644 --- a/packages/sheets-data-validation/src/locale/ru-RU.ts +++ b/packages/sheets-data-validation/src/locale/ru-RU.ts @@ -35,7 +35,7 @@ const locale: typeof zhCN = { title: 'Управление проверкой данных', addTitle: 'Создать новую проверку данных', removeAll: 'Удалить все', - add: 'Создать проверку данных', + add: 'добавить правило', range: 'Диапазоны', type: 'Тип', options: 'Дополнительные параметры', diff --git a/packages/sheets-data-validation/src/widgets/dropdown-widget.ts b/packages/sheets-data-validation/src/widgets/dropdown-widget.ts index 5fe3d680b95..373dbdee2d9 100644 --- a/packages/sheets-data-validation/src/widgets/dropdown-widget.ts +++ b/packages/sheets-data-validation/src/widgets/dropdown-widget.ts @@ -29,7 +29,7 @@ const PADDING_H = 4; const ICON_SIZE = 6; const ICON_PLACE = 14; const MARGIN_H = 6; -const MARGIN_V = 2; +const MARGIN_V = 4; const DROP_DOWN_ICON_COLOR = '#565656'; const downPath = new Path2D('M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z'); diff --git a/packages/sheets-hyper-link/src/commands/mutations/update-hyper-link.mutation.ts b/packages/sheets-hyper-link/src/commands/mutations/update-hyper-link.mutation.ts index 0da2ba1ecf2..ec9d85aed92 100644 --- a/packages/sheets-hyper-link/src/commands/mutations/update-hyper-link.mutation.ts +++ b/packages/sheets-hyper-link/src/commands/mutations/update-hyper-link.mutation.ts @@ -36,7 +36,7 @@ export const UpdateHyperLinkMutation: ICommand = const model = accessor.get(HyperLinkModel); const { unitId, subUnitId, payload, id } = params; - return model.updateHyperLink(unitId, subUnitId, id, payload); + return model.updateHyperLink(unitId, subUnitId, id, payload, false); }, }; diff --git a/packages/sheets-hyper-link/src/controllers/ref-range.controller.ts b/packages/sheets-hyper-link/src/controllers/ref-range.controller.ts index 57c9d7577e1..f2f9cf25be2 100644 --- a/packages/sheets-hyper-link/src/controllers/ref-range.controller.ts +++ b/packages/sheets-hyper-link/src/controllers/ref-range.controller.ts @@ -199,6 +199,7 @@ export class SheetsHyperLinkRefRangeController extends Disposable { }; }; this._rangeDisableMap.set(id, this._refRangeService.registerRefRange(range, handleRangeChange, unitId, subUnitId)); + if (!silent) { this._rangeWatcherMap.set(id, this._refRangeService.watchRange(unitId, subUnitId, range, (before, after) => { this._hyperLinkModel.updateHyperLink(unitId, subUnitId, id, { @@ -253,6 +254,7 @@ export class SheetsHyperLinkRefRangeController extends Disposable { this._unregisterPosition(option.payload.id); this._unwatchPosition(option.payload.id); this._unregisterRange(option.payload.id); + this._unwatchRange(option.payload.id); break; } case 'updateRef': { @@ -261,7 +263,6 @@ export class SheetsHyperLinkRefRangeController extends Disposable { if (!link) { return; } - this._unregisterPosition(id); this._registerPosition(unitId, subUnitId, link); if (!silent) { @@ -276,7 +277,9 @@ export class SheetsHyperLinkRefRangeController extends Disposable { const { links } = subUnitData; links.forEach((link) => { this._unregisterPosition(link.id); + this._unwatchPosition(link.id); this._unregisterRange(link.id); + this._unwatchRange(link.id); }); }); break; diff --git a/packages/sheets-hyper-link/src/models/hyper-link.model.ts b/packages/sheets-hyper-link/src/models/hyper-link.model.ts index 67409ecee32..1cf7574a0d1 100644 --- a/packages/sheets-hyper-link/src/models/hyper-link.model.ts +++ b/packages/sheets-hyper-link/src/models/hyper-link.model.ts @@ -117,16 +117,22 @@ export class HyperLinkModel extends Disposable { return true; } - updateHyperLink(unitId: string, subUnitId: string, id: string, payload: Partial, silent?: boolean) { + updateHyperLink( + unitId: string, + subUnitId: string, + id: string, + payload: Partial, + silent = false + ) { const { matrix, positionMap } = this._ensureMap(unitId, subUnitId); - // const current = matrix.getValue(); const position = positionMap.get(id); if (!position) { - return false; + return true; } + const link = matrix.getValue(position.row, position.column); if (!link) { - return false; + return true; } Object.assign(link, payload); @@ -146,10 +152,9 @@ export class HyperLinkModel extends Disposable { updateHyperLinkRef(unitId: string, subUnitId: string, id: string, payload: { row: number; column: number }, silent = false) { const { matrix, positionMap } = this._ensureMap(unitId, subUnitId); - // const current = matrix.getValue(); const position = positionMap.get(id); if (!position) { - return false; + return true; } let link = matrix.getValue(position.row, position.column); @@ -187,9 +192,10 @@ export class HyperLinkModel extends Disposable { this._linkUpdate$.next({ unitId, subUnitId, - payload: link, + payload: position.link, type: 'remove', }); + return true; } diff --git a/packages/sheets/src/services/ref-range/util.ts b/packages/sheets/src/services/ref-range/util.ts index 39dbc9094d9..64408268373 100644 --- a/packages/sheets/src/services/ref-range/util.ts +++ b/packages/sheets/src/services/ref-range/util.ts @@ -1148,7 +1148,7 @@ export function getEffectedRangesOnMutation(mutation: IMutationInfo