Skip to content

Commit

Permalink
fix(sheets-hyper-link): skip error on ref-range mutation (#2446)
Browse files Browse the repository at this point in the history
* feat: skip error on ref-range mutation

* feat: i18n

* feat: update

* fix: intersets

* feat: style

* feat: remove skip error
  • Loading branch information
weird94 authored and lumixraku committed Jun 17, 2024
1 parent 696000d commit fe65579
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 22 deletions.
31 changes: 24 additions & 7 deletions examples/src/data/sheets/demo/default-workbook-data-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
},
];

Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-data-validation/src/locale/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-data-validation/src/locale/ru-RU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const locale: typeof zhCN = {
title: 'Управление проверкой данных',
addTitle: 'Создать новую проверку данных',
removeAll: 'Удалить все',
add: 'Создать проверку данных',
add: 'добавить правило',
range: 'Диапазоны',
type: 'Тип',
options: 'Дополнительные параметры',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const UpdateHyperLinkMutation: ICommand<IUpdateHyperLinkMutationParams> =

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);
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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': {
Expand All @@ -261,7 +263,6 @@ export class SheetsHyperLinkRefRangeController extends Disposable {
if (!link) {
return;
}

this._unregisterPosition(id);
this._registerPosition(unitId, subUnitId, link);
if (!silent) {
Expand All @@ -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;
Expand Down
20 changes: 13 additions & 7 deletions packages/sheets-hyper-link/src/models/hyper-link.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,22 @@ export class HyperLinkModel extends Disposable {
return true;
}

updateHyperLink(unitId: string, subUnitId: string, id: string, payload: Partial<ICellLinkContent>, silent?: boolean) {
updateHyperLink(
unitId: string,
subUnitId: string,
id: string,
payload: Partial<ICellLinkContent>,
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);

Expand All @@ -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);
Expand Down Expand Up @@ -187,9 +192,10 @@ export class HyperLinkModel extends Disposable {
this._linkUpdate$.next({
unitId,
subUnitId,
payload: link,
payload: position.link,
type: 'remove',
});

return true;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/sheets/src/services/ref-range/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ export function getEffectedRangesOnMutation(mutation: IMutationInfo<MutationsAff
{
...params.targetRange,
startColumn: params.targetRange.startColumn - 0.5,
endColumn: params.targetRange.endColumn - 0.5,
endColumn: params.targetRange.startColumn - 0.5,
},
];
}
Expand All @@ -1175,7 +1175,7 @@ export function getEffectedRangesOnMutation(mutation: IMutationInfo<MutationsAff
{
...range,
startColumn: range.startColumn - 0.5,
endColumn: range.endColumn - 0.5,
endColumn: range.startColumn - 0.5,
},
];
}
Expand All @@ -1186,7 +1186,7 @@ export function getEffectedRangesOnMutation(mutation: IMutationInfo<MutationsAff
{
...range,
startRow: range.startRow - 0.5,
endRow: range.endRow - 0.5,
endRow: range.startRow - 0.5,
},
];
}
Expand Down

0 comments on commit fe65579

Please sign in to comment.