Skip to content

Commit

Permalink
chore: setDataCfg 函数类型优化 (#2286)
Browse files Browse the repository at this point in the history
  • Loading branch information
1wkk authored Jul 28, 2023
1 parent a06560d commit da1a5ab
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/s2-core/src/common/interface/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface StoreKey {
// interaction state
interactionStateInfo: InteractionStateInfo;

originalDataCfg: S2DataConfig;
originalDataCfg: Partial<S2DataConfig>;

panelBBox: BBox;
// resize area group
Expand Down
12 changes: 8 additions & 4 deletions packages/s2-core/src/sheet-type/spread-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
get,
includes,
isEmpty,
isEqual,
isFunction,
isString,
memoize,
Expand Down Expand Up @@ -61,6 +60,7 @@ import { RootInteraction } from '../interaction/root';
import { getTheme } from '../theme';
import { HdAdapter } from '../ui/hd-adapter';
import { BaseTooltip } from '../ui/tooltip';
import { removeOffscreenCanvas } from '../utils/canvas';
import { clearValueRangeState } from '../utils/condition/state-controller';
import { hideColumnsByThunkGroup } from '../utils/hide-columns';
import {
Expand All @@ -69,7 +69,6 @@ import {
getSafetyOptions,
} from '../utils/merge';
import { getTooltipData, getTooltipOptions } from '../utils/tooltip';
import { removeOffscreenCanvas } from '../utils/canvas';

export abstract class SpreadSheet extends EE {
// theme config
Expand Down Expand Up @@ -364,9 +363,14 @@ export abstract class SpreadSheet extends EE {
* Group sort params kept in {@see store} and
* Priority: group sort > advanced sort
* @param dataCfg
* @param reset reset: true, 直接使用用户传入的 DataCfg ,不再与上次数据进行合并
* @param reset 是否使用传入的 dataCfg 重置已保存的 dataCfg
*
* @example setDataCfg(dataCfg, true) 直接使用传入的 DataCfg,不再与上次数据进行合并
*/
public setDataCfg(dataCfg: S2DataConfig, reset?: boolean) {
public setDataCfg<T extends boolean = false>(
dataCfg: T extends true ? S2DataConfig : Partial<S2DataConfig>,
reset?: T,
) {
this.store.set('originalDataCfg', dataCfg);
if (reset) {
this.dataCfg = getSafetyDataConfig(dataCfg);
Expand Down
2 changes: 1 addition & 1 deletion s2-site/docs/api/basic-class/base-data-set.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ s2.dataSet.xx()
| getFieldName | get field name | `() => string` | |
| getFieldFormatter | Get the field formatting function | `() => (v: string) => unknown` | |
| getFieldDescription | Get field description | `() => string` | |
| setDataCfg | Set data configuration | (dataCfg: [S2DataConfig](/docs/api/general/S2DataConfig) , reset?: boolean) => void | The `reset` parameter needs to be used in `@antv/s2-v1.34.0` version |
| setDataCfg | Set data configuration | `<T extends boolean = false>(dataCfg: T extends true ?` [`S2DataConfig`](/docs/api/general/S2DataConfig) `: Partial<`[`S2DataConfig`](/docs/api/general/S2DataConfig)`>, reset?: T) => void` | The `reset` parameter needs to be used in `@antv/s2-v1.34.0` version |
| getDisplayDataSet | Get the currently displayed dataset | () => [DataType\[\]](#datatype) | |
| getDimensionValues | get dimension value | (filed: string, query?: [DataType](#datatype) ) => string\[] | |
| getCellData | Get a single cell data | (params: [CellDataParams](#celldataparams) ) => [DataType\[\]](#datatype) | |
Expand Down
2 changes: 1 addition & 1 deletion s2-site/docs/api/basic-class/base-data-set.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ s2.dataSet.getFieldName('type')
| getFieldName | 获取字段名 | `() => string` | |
| getFieldFormatter | 获取字段格式化函数 | `() => (v: string) => unknown` | |
| getFieldDescription | 获取字段描述 | `() => string` | |
| setDataCfg | 设置数据配置 | (dataCfg: [S2DataConfig](/docs/api/general/S2DataConfig), reset?: boolean) => void | `reset` 参数需在 `@antv/s2-v1.34.0`版本使用 |
| setDataCfg | 设置数据配置 | `<T extends boolean = false>(dataCfg: T extends true ?` [`S2DataConfig`](/docs/api/general/S2DataConfig) `: Partial<`[`S2DataConfig`](/docs/api/general/S2DataConfig)`>, reset?: T) => void` | `reset` 参数需在 `@antv/s2-v1.34.0`版本使用 |
| getDisplayDataSet | 获取当前显示的数据集 | () => [DataType[]](#datatype) | |
| getDimensionValues | 获取维值 | (filed: string, query?: [DataType](#datatype) ) => string[] | |
| getCellData | 获取单个的单元格数据 | (params: [CellDataParams](#celldataparams)) => [DataType[]](#datatype) | |
Expand Down
2 changes: 1 addition & 1 deletion s2-site/docs/api/basic-class/spreadsheet.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ s2.xx()
| hideTooltip | hide tooltip | `() => void` | |
| destroyTooltip | destroy tooltip | `() => void` | |
| registerIcons | Register custom svg icons (according to `options.customSVGIcons` ) | `() => void` | |
| setDataCfg | Update data configuration | (dataCfg: [S2DataConfig](/docs/api/general/S2DataConfig) , reset?: boolean ) => void | The `reset` parameter needs to be used in `@antv/s2-v1.34.0` version |
| setDataCfg | Update data configuration | `<T extends boolean = false>(dataCfg: T extends true ?` [`S2DataConfig`](/docs/api/general/S2DataConfig) `: Partial<`[`S2DataConfig`](/docs/api/general/S2DataConfig)`>, reset?: T) => void` | The `reset` parameter needs to be used in `@antv/s2-v1.34.0` version |
| setOptions | Update table configuration | (options: [S2Options](/docs/api/general/S2Options) , reset?: boolean) => void | The `reset` parameter needs to be used in `@antv/s2-v1.34.0` version |
| render | Re-render the table, if `reloadData` = true, the data will be recalculated, `reBuildDataSet` = true, rebuild the data set, `reBuildHiddenColumnsDetail` = true rebuild hidden column information | `(reloadData?: boolean, { reBuildDataSet?: boolean; reBuildHiddenColumnsDetail?: boolean }) => void` | |
| destroy | destroy form | `() => void` | |
Expand Down
2 changes: 1 addition & 1 deletion s2-site/docs/api/basic-class/spreadsheet.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ s2.isPivotMode()
| hideTooltip | 隐藏 tooltip | `() => void` | |
| destroyTooltip | 销毁 tooltip | `() => void` | |
| registerIcons | 注册 自定义 svg 图标 (根据 `options.customSVGIcons`) | `() => void` | |
| setDataCfg | 更新数据配置 | (dataCfg: [S2DataConfig](/docs/api/general/S2DataConfig), reset?: boolean ) => void | `reset` 参数需在 `@antv/s2-v1.34.0`版本使用 |
| setDataCfg | 更新数据配置 | `<T extends boolean = false>(dataCfg: T extends true ?` [`S2DataConfig`](/docs/api/general/S2DataConfig) `: Partial<`[`S2DataConfig`](/docs/api/general/S2DataConfig)`>, reset?: T) => void` | `reset` 参数需在 `@antv/s2-v1.34.0`版本使用 |
| setOptions | 更新表格配置 | (options: [S2Options](/docs/api/general/S2Options), reset?: boolean) => void | `reset` 参数需在 `@antv/s2-v1.34.0`版本使用 |
| render | 重新渲染表格,如果 `reloadData` = true, 则会重新计算数据,`reBuildDataSet` = true, 重新构建数据集,`reBuildHiddenColumnsDetail` = true 重新构建隐藏列信息 | `(reloadData?: boolean, { reBuildDataSet?: boolean; reBuildHiddenColumnsDetail?: boolean }) => void` | |
| destroy | 销毁表格 | `() => void` | |
Expand Down

1 comment on commit da1a5ab

@vercel
Copy link

@vercel vercel bot commented on da1a5ab Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

antvis-s2 – ./

antvis-s2.vercel.app
antvis-s2-git-master-antv-s2.vercel.app
antvis-s2-antv-s2.vercel.app

Please sign in to comment.