-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix: 修复编辑表的输入框未回填格式化后的数据 close #2528 * fix: 修复循环引用 * fix: 编辑后不应该再次格式化 * fix: 移除定义 * test: 修复单测 * test: 增加单测
- Loading branch information
1 parent
3a7803b
commit 95d67ca
Showing
16 changed files
with
384 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* @description spec for issue #2528 | ||
* https://github.com/antvis/S2/issues/2528 | ||
*/ | ||
|
||
import * as mockDataConfig from '../data/simple-table-data.json'; | ||
import { getContainer } from '../util/helpers'; | ||
import type { SpreadSheet, S2DataConfig, S2Options } from '@/index'; | ||
import { TableSheet } from '@/sheet-type'; | ||
|
||
const s2DataConfig: S2DataConfig = { | ||
...mockDataConfig, | ||
meta: [{ field: 'cost', formatter: (v) => `${v}-@` }], | ||
}; | ||
|
||
const s2Options: S2Options = { | ||
width: 800, | ||
height: 400, | ||
}; | ||
|
||
describe('Table Sheet Editable Formatter Tests', () => { | ||
let s2: SpreadSheet; | ||
|
||
beforeEach(() => { | ||
s2 = new TableSheet(getContainer(), s2DataConfig, s2Options); | ||
|
||
s2.render(); | ||
}); | ||
|
||
test('should get formatted data', () => { | ||
const costValues = s2.interaction | ||
.getPanelGroupAllDataCells() | ||
.filter((cell) => cell.getMeta().valueField === 'cost') | ||
.map((cell) => cell.getFieldValue()); | ||
|
||
expect(costValues).toEqual(['2-@', '2-@', '2-@']); | ||
}); | ||
|
||
test('should only format data once after data edited', () => { | ||
const id = '0-root[&]cost'; | ||
const inputValue = 'test'; | ||
|
||
// 模拟一次编辑 (更新第一行的 cost) | ||
const displayData = s2.dataSet.getDisplayDataSet(); | ||
|
||
displayData[0].cost = inputValue; | ||
s2.dataSet.displayFormattedValueMap?.set(id, inputValue); | ||
|
||
s2.render(); | ||
|
||
const costValues = s2.interaction | ||
.getPanelGroupAllDataCells() | ||
.filter((cell) => cell.getMeta().valueField === 'cost') | ||
.map((cell) => cell.getFieldValue()); | ||
|
||
expect(costValues).toEqual([inputValue, '2-@', '2-@']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
import { isUpDataValue, type Columns, customMerge } from '@antv/s2'; | ||
import type { S2DataConfig, ThemeCfg } from '@antv/s2'; | ||
import { getBaseSheetComponentOptions } from '@antv/s2-shared'; | ||
import type { SliderSingleProps } from 'antd'; | ||
import { | ||
data, | ||
totalData, | ||
meta, | ||
fields, | ||
} from '../__tests__/data/mock-dataset.json'; | ||
import type { SheetComponentOptions } from '../src/components'; | ||
|
||
export const tableSheetSingleColumns: Columns = [ | ||
'province', | ||
'city', | ||
'type', | ||
'sub_type', | ||
'number', | ||
]; | ||
|
||
export const tableSheetMultipleColumns: Columns = [ | ||
{ | ||
key: 'area', | ||
children: ['province', 'city'], | ||
}, | ||
'type', | ||
{ | ||
key: 'money', | ||
children: [{ key: 'price' }, 'number'], | ||
}, | ||
]; | ||
|
||
export const tableSheetDataCfg: S2DataConfig = { | ||
data, | ||
totalData, | ||
meta: [{ field: 'number', formatter: (v) => `${v}-@` }, ...meta], | ||
fields: { | ||
columns: tableSheetSingleColumns, | ||
}, | ||
}; | ||
|
||
export const pivotSheetDataCfg: S2DataConfig = { | ||
data, | ||
totalData, | ||
meta, | ||
fields, | ||
}; | ||
|
||
export const pivotSheetDataCfgForCompactMode = customMerge(pivotSheetDataCfg, { | ||
data: [ | ||
...pivotSheetDataCfg.data, | ||
{ | ||
province: '浙江', | ||
city: '杭州', | ||
type: '笔', | ||
price: '11111111', | ||
}, | ||
{ | ||
province: '浙江', | ||
city: '杭州', | ||
type: '纸张', | ||
price: '2', | ||
}, | ||
{ | ||
province: '浙江', | ||
city: '舟山', | ||
type: '笔', | ||
price: '2', | ||
}, | ||
{ | ||
province: '浙江', | ||
city: '舟山', | ||
type: '纸张', | ||
price: '133.333', | ||
}, | ||
], | ||
}); | ||
|
||
export const s2Options: SheetComponentOptions = { | ||
debug: true, | ||
width: 600, | ||
height: 400, | ||
frozenFirstRow: false, | ||
showSeriesNumber: false, | ||
interaction: { | ||
enableCopy: true, | ||
copyWithHeader: true, | ||
copyWithFormat: true, | ||
// 防止 mac 触摸板横向滚动触发浏览器返回, 和移动端下拉刷新 | ||
overscrollBehavior: 'none', | ||
brushSelection: { | ||
data: true, | ||
col: true, | ||
row: true, | ||
}, | ||
}, | ||
tooltip: { | ||
showTooltip: true, | ||
operation: { | ||
trend: true, | ||
}, | ||
}, | ||
conditions: { | ||
text: [], | ||
interval: [ | ||
{ | ||
field: 'number', | ||
mapping() { | ||
return { | ||
fill: '#80BFFF', | ||
// 自定义柱状图范围 | ||
isCompare: true, | ||
maxValue: 8000, | ||
minValue: 300, | ||
}; | ||
}, | ||
}, | ||
], | ||
}, | ||
headerActionIcons: [ | ||
{ | ||
iconNames: ['SortDown'], | ||
belongsCell: 'colCell', | ||
defaultHide: true, | ||
}, | ||
{ | ||
iconNames: ['SortDown'], | ||
belongsCell: 'rowCell', | ||
defaultHide: true, | ||
}, | ||
{ | ||
iconNames: ['SortDown'], | ||
belongsCell: 'cornerCell', | ||
defaultHide: true, | ||
}, | ||
], | ||
hierarchyType: 'grid', | ||
style: { | ||
colCfg: { | ||
hideMeasureColumn: false, | ||
}, | ||
rowCfg: { | ||
width: 100, | ||
}, | ||
cellCfg: { | ||
height: 50, | ||
width: 100, | ||
}, | ||
}, | ||
}; | ||
|
||
export const s2ThemeConfig: ThemeCfg = { | ||
name: 'default', | ||
theme: {}, | ||
}; | ||
|
||
export const sliderOptions: SliderSingleProps = { | ||
min: 0, | ||
max: 10, | ||
step: 0.1, | ||
marks: { | ||
0.2: '0.2', | ||
1: '1 (默认)', | ||
2: '2', | ||
10: '10', | ||
}, | ||
}; | ||
|
||
export const mockGridAnalysisOptions: SheetComponentOptions = { | ||
width: 1600, | ||
height: 600, | ||
style: { | ||
layoutWidthType: 'colAdaptive', | ||
cellCfg: { | ||
width: 400, | ||
height: 100, | ||
valuesCfg: { | ||
widthPercent: [40, 0.2, 0.2, 0.2], | ||
}, | ||
}, | ||
}, | ||
tooltip: { showTooltip: false }, | ||
interaction: { | ||
selectedCellsSpotlight: true, | ||
}, | ||
conditions: { | ||
text: [ | ||
{ | ||
mapping: (value, cellInfo) => { | ||
const { colIndex } = cellInfo; | ||
|
||
if (colIndex <= 1) { | ||
return { | ||
fill: '#000', | ||
}; | ||
} | ||
|
||
return { | ||
fill: isUpDataValue(value) ? '#FF4D4F' : '#29A294', | ||
}; | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export const defaultOptions = | ||
getBaseSheetComponentOptions<SheetComponentOptions>(s2Options); |
Oops, something went wrong.