Skip to content

Commit

Permalink
feat: 适配链接跳转的判断方式 (#1983)
Browse files Browse the repository at this point in the history
* fix: 适配链接跳转的判断方式

* fix: 增加点击链接返回参数 id

* test: 完善链接跳转测试

* fix: 透传整个cellData

* docs: 补充链接跳转文档

* test: 修复链接跳转单测

* test: 修复链接跳转单测

Co-authored-by: gaofuhong.gfh <[email protected]>
  • Loading branch information
GaoFuhong and GaoFuhong authored Dec 9, 2022
1 parent fcb13ab commit 8f40e22
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/s2-core/__tests__/spreadsheet/row-link-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ describe('Row Text Link Tests', () => {

expect(linkFieldJump).toBeCalledWith({
key: 'province',
cellData: rowNode,
record: {
province: '浙江',
type: '笔',
Expand Down Expand Up @@ -124,6 +125,7 @@ describe('Row Text Link Tests', () => {

expect(linkFieldJump).toBeCalledWith({
key: 'city',
cellData: rowNode,
record: {
province: '浙江',
city: '义乌1',
Expand Down Expand Up @@ -152,6 +154,7 @@ describe('Row Text Link Tests', () => {

expect(linkFieldJump).toBeCalledWith({
key: 'province',
cellData: rowNode,
record: {
province: '四川',
type: '笔',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ describe('Interaction Data Cell Click Tests', () => {

expect(linkFieldJump).toHaveBeenCalledWith({
key: mockCellData.valueField,
cellData: mockCellData,
record: mockCellData.data,
});
expect(s2.showTooltipWithInfo).not.toHaveBeenCalled();
Expand Down
6 changes: 4 additions & 2 deletions packages/s2-core/src/cell/row-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,10 @@ export class RowCell extends HeaderCell {
protected drawLinkFieldShape() {
const { linkFields = [] } = this.headerConfig;
const { linkTextFill } = this.getTextStyle();

super.drawLinkFieldShape(linkFields.includes(this.meta.key), linkTextFill);
const isLinkField = linkFields.some(
(field) => field === this.meta.key || field === this.meta.id,
);
super.drawLinkFieldShape(isLinkField, linkTextFill);
}

protected drawRectBorder() {
Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/src/common/interface/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface EmitterType {
/** ================ Cell ================ */
[S2Event.GLOBAL_LINK_FIELD_JUMP]: (data: {
key: string;
cellData: Node;
record: Data;
}) => void;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class DataCellClick extends BaseEvent implements BaseEventImplement {

this.spreadsheet.emit(S2Event.GLOBAL_LINK_FIELD_JUMP, {
key,
cellData,
record: Object.assign({ rowIndex: cellData.rowIndex }, record),
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class RowTextClick extends BaseEvent implements BaseEventImplement {

this.spreadsheet.emit(S2Event.GLOBAL_LINK_FIELD_JUMP, {
key,
cellData,
record: rowData,
});
});
Expand Down
4 changes: 2 additions & 2 deletions s2-site/docs/api/components/sheet-component.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ order: 0
| onMouseUp | 表格鼠标松开事件 | (event: CanvasEvent) => void | | |
| onSelected | 单元格选中事件 | (cells: ( [Cell](/docs/api/basic-class/base-cell)[] ) => void | | |
| onReset | 交互状态重置事件 | (event: KeyboardEvent) => void | | |
| onLinkFieldJump | 链接字段跳转事件 | (data: { key: string; record: [Data](/docs/api/general/S2DataConfig#data) }) => void | | |
| onLinkFieldJump | 链接字段跳转事件 (cellData: @antv/s2 1.37.0 新增) | (data: { key: string; cellData: [Node](/docs/api/basic-class/node); record: [Data](/docs/api/general/S2DataConfig#data) }) => void | | |
| onScroll | 单元格滚动事件 (含行头和数值单元格) | ({position: [CellScrollPosition](#cellscrollposition)} ) => void; | | |
| onColCellBrushSelection | 批量选中刷选范围内的列头单元格,刷选过程中,显示刷选范围提示蒙层,刷选完成后,弹出 tooltip, 展示被刷选单元格信息(仅支持透视表) | (cells: [ColCell](/docs/api/basic-class/base-cell)[]) => void; | | |
| onRowCellBrushSelection | 批量选中刷选范围内的行头单元格,刷选过程中,显示刷选范围提示蒙层,刷选完成后,弹出 tooltip, 展示被刷选单元格信息(仅支持透视表) | (cells: [RowCell](/docs/api/basic-class/base-cell)[]) => void; | | |
Expand Down Expand Up @@ -217,7 +217,7 @@ type SheetComponentOptions = S2Options<
| mouseUp | 表格鼠标松开事件 | (event: CanvasEvent) => void | | |
| selected | 单元格选中事件 | ( cells: ([Cell](/docs/api/basic-class/base-cell)[] ) => void | | |
| reset | 交互状态重置事件 | (event: KeyboardEvent) => void | | |
| linkFieldJump | 链接字段跳转事件 | (data: { key: string; record: [Data](/docs/api/general/S2DataConfig#data) }) => void | | |
| linkFieldJump | 链接字段跳转事件 (cellData: @antv/s2 1.37.0 新增) | (data: { key: string; cellData: [Node](/docs/api/basic-class/node); record: [Data](/docs/api/general/S2DataConfig#data) }) => void | | |
| scroll | 单元格滚动事件 (含行头和数值单元格) | ({position: [CellScrollPosition](#cellscrollposition)} ) => void; | | |
| colCellBrushSelection | 批量选中刷选范围内的列头单元格,刷选过程中,显示刷选范围提示蒙层,刷选完成后,弹出 tooltip, 展示被刷选单元格信息(仅支持透视表) | (cells: ColCell[]) => void; | | |
| rowCellBrushSelection | 批量选中刷选范围内的行头单元格,刷选过程中,显示刷选范围提示蒙层,刷选完成后,弹出 tooltip, 展示被刷选单元格信息(仅支持透视表) | (cells: RowCell[]) => void; | | |
Expand Down

0 comments on commit 8f40e22

Please sign in to comment.