Skip to content

Commit

Permalink
fix: 修复字段标记 mapping 函数部分场景缺失第三个参数 & 调整参数类型 (#2927)
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 authored Oct 17, 2024
1 parent 55f1a40 commit 676c1f6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/s2-core/src/cell/data-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ export class DataCell extends BaseCell<ViewMeta> {
})
: CellData.getFieldValue(this.meta.data as ViewMetaData);

return condition.mapping(value, rowDataInfo as RawData, this);
return condition.mapping?.(value, rowDataInfo as RawData, this);
}

public updateByState(stateName: `${InteractionStateName}`) {
Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/src/cell/header-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ export abstract class HeaderCell<
): ConditionMappingResult<Result> {
const value = this.getMeta().value;

return condition.mapping(value, this.meta, this);
return condition.mapping?.(value, this.meta, this);
}

public findFieldCondition<T extends Condition>(
Expand Down
4 changes: 2 additions & 2 deletions packages/s2-core/src/common/interface/condition.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DataCell, HeaderCell } from '../../cell';
import type { S2CellType } from './interaction';
import type { RawData } from './s2DataConfig';
import type { TextTheme } from './theme';

Expand Down Expand Up @@ -40,7 +40,7 @@ export type ConditionMappingResult<T = unknown> = T | undefined | null;
export type ConditionMapping<T = unknown> = (
fieldValue: number | string,
data: RawData,
cell?: DataCell | HeaderCell,
cell: S2CellType,
) => ConditionMappingResult<T>;

/**
Expand Down
31 changes: 21 additions & 10 deletions packages/s2-core/src/utils/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,25 @@ const getCurrentTextStyle = ({
data,
textStyle,
textCondition,
cell,
}: {
rowIndex: number;
colIndex: number;
meta: ViewMeta;
data: string | number;
textStyle?: TextTheme;
textCondition?: TextCondition;
cell: S2CellType;
}): TextTheme => {
const style = textCondition?.mapping?.(data, {
rowIndex,
colIndex,
meta,
});
const style = textCondition?.mapping?.(
data,
{
rowIndex,
colIndex,
meta,
},
cell,
);

return { ...textStyle, ...style };
};
Expand Down Expand Up @@ -340,6 +346,7 @@ export const drawCustomContent = (
data: curText,
textStyle,
textCondition,
cell,
})
: textStyle!;

Expand Down Expand Up @@ -391,11 +398,15 @@ export const drawCustomContent = (

// 绘制条件格式的 icon
if (iconCondition && useCondition) {
const attrs = iconCondition?.mapping?.(curText, {
rowIndex: i,
colIndex: j,
meta: cell?.getMeta(),
});
const attrs = iconCondition?.mapping?.(
curText,
{
rowIndex: i,
colIndex: j,
meta: cell?.getMeta(),
},
cell,
);

const iconX = iconCfg?.position === 'left' ? leftIconX : rightIconX;
const iconY = getVerticalIconPosition(
Expand Down
2 changes: 1 addition & 1 deletion s2-site/docs/common/conditions.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ order: 2
export type ConditionMapping<T = unknown> = (
fieldValue: number | string,
data: RawData,
cell?: DataCell | HeaderCell,
cell: S2CellType,
) => ConditionMappingResult<T>;

```
Expand Down

0 comments on commit 676c1f6

Please sign in to comment.